script
code:script.js
var Zt=Object.defineProperty;var en=(e,t)=>{for(var n in t)Zt(e,n,{get:tn,enumerable:!0})};scrapbox.PopupMenu.addButton({title:e=>{if(!(e.split(`
).length<2))return"✂New Page"},onClick:e=>{let t=e.split(
),n=t[0].replace(/[\[\]\n]/g,"").trim();return t.unshift(✂ from ${scrapbox.Page.title}),window.open(https://scrapbox.io/${scrapbox.Project.name}/${encodeURIComponent(n)}?body=${encodeURIComponent(t.join(`
))}),✂ to [${n}]}});var ze=document.createElement("style");ze.innerText=".popup-menu .button-container .button.split-page-button{display:none;} .popup-menu .button-container .button.copy-plain-button:not(.button.strike-button + .copy-plain-button){border-left:none;}";document.body.appendChild(ze);scrapbox.PopupMenu.addButton({title:"unlink",onClick:e=>{let t=e.split(/\n/).map(n=>n.replace(/\[([^\!"#%&'()\*\+,\-\.\/\{\|\}<>_~[^\\]*)\]/g,"$1")).join(`
);if(e!=t)return t}});var tn=e=>{let t=e.indexOf(
),n=e.substr(0,t).split(
).map(o=>{let[s="",a=""]=o.split(" => ",2);return{before:s,after:a}}),r=e.substr(t+2).split(
);for(let{before:o,after:s}of n){let a=o.match(new RegExp("^/(.*?)/([gimy]*)$")),u=a?new RegExp(a[1],a[2]):o;r=r.map(p=>p.replace(u,s.replace(/\\n/g,
)))}return r.join(
)};scrapbox.PopupMenu.addButton({title:"replace",onClick:tn});setTimeout(()=>{let e=[["⬜","☑️"],["☐","☑"],["□","☑"]],t=e.reduce((c,l)=>c.concat(l),[]),n=new RegExp("^\\s*("+t.join("|")+")"),r=scrapbox.Project.name;class o{constructor(){this.textArea=document.getElementById("text-input"),this.event=document.createEvent("UIEvent"),this.event.initEvent("keydown",!0,!0)}dispatch(l,i=!1,d=!1,f=!1,m=!1){this.event.keyCode=l,this.event.shiftKey=i,this.event.ctrlKey=d,this.event.altKey=f,this.event.metaKey=m,this.textArea.dispatchEvent(this.event)}}$("#app-container").off(click.toggleCheckBox_${r},".lines"),$("#app-container").on(click.toggleCheckBox_${r},".lines",async c=>{if(scrapbox.Project.name!==r){$("#app-container").off(click.toggleCheckBox_${r},".lines");return}let l=c.target;if(!s(l)||!u(l,t))return;await new Promise(y=>setTimeout(y,30));let i;try{i=a()}catch(y){console.log(y);return}if(!n.test(i))return;let d=l.getBoundingClientRect().left,f=document.getElementsByClassName("cursor")[0].getBoundingClientRect().left,m=new o;f<=d&&m.dispatch(39),m.dispatch(8);let b=(()=>{let y=i.trim();for(let h of e)for(let g=0;g<h.length;g++)if(y.startsWith(h[g]))return h[g+1<h.length?g+1:0];return l.textContent})();p(b)}),$("#text-input").off(keydown.autoInsertCheckBox_${r}),$("#text-input").on(keydown.autoInsertCheckBox_${r},async c=>{if(scrapbox.Project.name!==r){$("#text-input").off(keydown.autoInsertCheckBox_${r});return}switch(c.key){case"Enter":{let l;try{l=a()}catch(d){console.log(d);return}if(!n.test(l))return;await new Promise(d=>setTimeout(d,30));let i;try{i=a()}catch(d){console.log(d);return}if(!n.test(i)){let d=l.trim(),f=e.find(m=>m.some(b=>d.startsWith(b)));p(f[0])}return}default:return}});function s(c){return c.parentNode.firstElementChild===c}function a(){return document.querySelector(".lines div.line.cursor-line").textContent}function u(c,l){return c.tagName==="SPAN"&&l.includes(c.textContent)&&c.classList.value.split(" ").some(i=>/^c\-\d+$/.test(i))}function p(c){let l=document.getElementById("text-input");l.value=c,l.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0}))}},1500);var nn=e=>({type:"title",text:e.rows[0].text}),rn=e=>{let{rows:[t,...n]}=e,{indent:r=0,text:o=""}=t??{},s=o.replace(/^\s*code:/,"");return{indent:r,type:"codeBlock",fileName:s,content:n.map(a=>a.text.substring(r+1)).join(
)}},x=(e,{parseOnNested:t,parseOnQuoted:n,patterns:r})=>(o,s,a)=>{var u,p,c,l,i,d;if(!t&&s.nested)return(u=a?.())!==null&&u!==void 0?u:[];if(!n&&s.quoted)return(p=a?.())!==null&&p!==void 0?p:[];for(let f of r){let m=f.exec(o);if(m===null)continue;let b=o.substring(0,m.index),y=o.substring(m.index+((l=(c=m[0])===null||c===void 0?void 0:c.length)!==null&&l!==void 0?l:0)),h=e((i=m[0])!==null&&i!==void 0?i:"",s);return[...A(b,s),...h,...A(y,s)]}return(d=a?.())!==null&&d!==void 0?d:[]},v=e=>[{type:"plain",raw:e,text:e}],on=x(v,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),sn=/^>.*$/,an=(e,t)=>t.context==="table"?v(e,t):[{type:"quote",raw:e,nodes:A(e.substring(1),{...t,quoted:!0})}],cn=x(an,{parseOnNested:!1,parseOnQuoted:!1,patterns:[sn]}),un=/^\? .+$/,ln=(e,t)=>t.context==="table"?v(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],pn=x(ln,{parseOnNested:!1,parseOnQuoted:!1,patterns:[un]}),dn=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,fn=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,mn=(e,t)=>{if(t.context==="table")return v(e,t);let n=e.substring(2,e.length-2),r=/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(n);return[{type:"strongImage",raw:e,src:r?${n}/thumb/1000:n}]},hn=x(mn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[dn,fn]}),gn=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function Ve(e){return(t,n)=>{if(e==="strongIcon"&&n.context==="table")return v(t,n);let r=e==="icon"?t.substring(1,t.length-1):t.substring(2,t.length-2),o=r.lastIndexOf(".icon"),s=r.substring(0,o),a=s.startsWith("/")?"root":"relative",u=r.substring(o+5,r.length),p=u.startsWith("*")?parseInt(u.substring(1),10):1;return new Array(p).fill({}).map(()=>({path:s,pathType:a,type:e,raw:t}))}}var _n=Ve("icon"),yn=x(_n,{parseOnNested:!0,parseOnQuoted:!0,patterns:[gn]}),bn=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,xn=Ve("strongIcon"),vn=x(xn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[bn]}),wn=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,En=(e,t)=>t.context==="table"?v(e,t):[{type:"strong",raw:e,nodes:A(e.substring(2,e.length-2),{...t,nested:!0})}],kn=x(En,{parseOnNested:!1,parseOnQuoted:!0,patterns:[wn]}),Ln=/\[\$ .+? \]/,Sn=/\[\$ [^\]]+\]/,Cn=(e,t)=>t.context==="table"?v(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],Tn=x(Cn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ln,Sn]}),Mn=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,Pn=(e,t)=>{if(t.context==="table")return v(e,t);let n=e.indexOf(" "),r=e.substring(1,n),o=e.substring(n+1,e.length-1),s=new Set(r);if(s.has("*")){let a=r.split("*").length-1;s.delete("*"),s.add(*-${Math.min(a,10)})}return[{type:"decoration",raw:e,rawDecos:r,decos:Array.from(s),nodes:A(o,{...t,nested:!0})}]},On=x(Pn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Mn]}),Rn=/.*?/,In=(e,t)=>t.context==="table"?v(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],Nn=x(In,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Rn]}),Hn=/^[$%] .+$/,$n=(e,t)=>{var n;if(t.context==="table")return v(e,t);let r=(n=e[0])!==null&&n!==void 0?n:"",o=e.substring(2);return[{type:"commandLine",raw:e,symbol:r,text:o}]},An=x($n,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Hn]}),Dn=/\[\s+\]/,jn=(e,t)=>t.context==="table"?v(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],Un=x(jn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Dn]}),Fn=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,Bn=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,Kn=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,Wn=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,zn=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||qn(e),qn=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),Vn=(e,t)=>{if(t.context==="table")return v(e,t);let n=e.search(/\s/),r=n!==-1?e.substring(1,n):e.substring(1,e.length-1),o=n!==-1?e.substring(n,e.length-1).trimLeft():"",[s,a]=zn(o)?[o,r]:[r,o];return[{type:"image",raw:e,src:/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(s)?${s}/thumb/1000:s,link:a}]},Qn=x(Vn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Fn,Bn,Kn,Wn]}),Yn=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,Xn=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,Gn=/\[https?:\/\/[^\s\]]+\]/,Jn=/https?:\/\/[^\s]+/,Zn=(e,t)=>{if(t.context==="table")return v(e,t);let n=e.startsWith("[")&&e.endsWith("]")?e.substring(1,e.length-1):e,r=/^https?:\/\/[^\s\]]/.test(n),o=(r?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(n);if(o?.[0]===void 0)return[];let s=r?n.substring(o[0].length):n.substring(0,o.index-1);return[{type:"link",raw:e,pathType:"absolute",href:o[0],content:s.trim()}]},er=x(Zn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Yn,Xn,Gn,Jn]}),Qe=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,Ye=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,tr=e=>{let[t="",n="",r=""]=e.split(","),o=parseFloat(t.replace(/^N/,"").replace(/^S/,"-")),s=parseFloat(n.replace(/^E/,"").replace(/^W/,"-")),a=/^Z\d+$/.test(r)?parseInt(r.replace(/^Z/,""),10):14;return{latitude:o,longitude:s,zoom:a}},nr=(e,t)=>{var n;if(t.context==="table")return v(e,t);let r=(n=e.match(Qe))!==null&&n!==void 0?n:e.match(Ye);if(r===null)return[];let o=e.startsWith("[N")||e.startsWith("[S"),[,s="",a=""]=o?r:[r[0],r[2],r[1]],{latitude:u,longitude:p,zoom:c}=tr(s),l=a!==""?https://www.google.com/maps/place/${encodeURIComponent(a)}/@${u},${p},${c}z:https://www.google.com/maps/@${u},${p},${c}z;return[{type:"googleMap",raw:e,latitude:u,longitude:p,zoom:c,place:a,url:l}]},rr=x(nr,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Qe,Ye]}),or=/\[\/?[^[\]]+\]/,sr=e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},ir=x(sr,{parseOnNested:!0,parseOnQuoted:!0,patterns:[or]}),ar=/(?:^|\s)#\S+/,cr=(e,t)=>{if(t.context==="table")return v(e,t);if(e.startsWith("#"))return[{type:"hashTag",raw:e,href:e.substring(1)}];let n=e.substring(0,1),r=e.substring(1);return[...v(n,t),{type:"hashTag",raw:r,href:r.substring(1)}]},ur=x(cr,{parseOnNested:!0,parseOnQuoted:!0,patterns:[ar]}),lr=/^[0-9]+\. .*$/,pr=(e,t)=>{if(t.context==="table")return v(e,t);let n=e.indexOf(" "),r=e.substring(0,n-1),o=parseInt(r,10),s=e.substring(n+1,e.length);return[{type:"numberList",raw:e,rawNumber:r,number:o,nodes:A(s,{...t,nested:!0})}]},dr=x(pr,{parseOnNested:!1,parseOnQuoted:!1,patterns:[lr]}),fr=(e,t,n)=>{var r;return e===""?[]:(r=n?.())!==null&&r!==void 0?r:[]},mr=(...e)=>(t,n)=>e.reduceRight((r,o)=>()=>o(t,n,r),()=>on(t,n))(),A=mr(fr,cn,pn,Nn,An,Tn,Un,On,hn,vn,kn,Qn,er,yn,rr,ir,ur,dr),hr=e=>{let{rows:[t,...n]}=e,{indent:r=0,text:o=""}=t??{},s=o.replace(/^\s*table:/,"");return{indent:r,type:"table",fileName:s,cells:n.map(a=>a.text.substring(r+1)).map(a=>a.split(" ").map(u=>A(u,{nested:!1,quoted:!1,context:"table"})))}},gr=e=>{let{indent:t,text:n}=e.rows[0];return{indent:t,type:"line",nodes:A(n.substring(t),{nested:!1,quoted:!1,context:"line"})}},_r=e=>{switch(e.type){case"title":return nn(e);case"codeBlock":return rn(e);case"table":return hr(e);case"line":return gr(e)}},yr=e=>e.split(
).map(t=>{var n,r,o;return{indent:(o=(r=(n=/^\s+/.exec(t))===null||n===void 0?void 0:n[0])===null||r===void 0?void 0:r.length)!==null&&o!==void 0?o:0,text:t}}),br=(e,t)=>{var n,r;return(e.type==="codeBlock"||e.type==="table")&&t.indent>((r=(n=e.rows[0])===null||n===void 0?void 0:n.indent)!==null&&r!==void 0?r:0)},qe=(e,t)=>{let n=e[e.length-1];return n!==void 0&&br(n,t)?(n.rows.push(t),e):(e.push({type:/^\s*code:/.test(t.text)?"codeBlock":/^\s*table:/.test(t.text)?"table":"line",rows:[t]}),e)},xr=(e,t)=>{var n;if(!((n=t.hasTitle)!==null&&n!==void 0)||n){let[r,...o]=e;return r===void 0?[]:[{type:"title",rows:[r]},...o.reduce(qe,[])]}return e.reduce(qe,[])},vr=(e,t)=>{var n;let r=yr(e);return xr(r,{hasTitle:(n=t?.hasTitle)!==null&&n!==void 0?n:!0}).map(_r)},wr=e=>vr(e,{hasTitle:!1}).flatMap(t=>{switch(t.type){case"title":return[];case"codeBlock":return Er(t);case"table":return kr(t);case"line":return Lr(t)}}).map(t=>t).join(
),Er=({fileName:e,content:t,indent:n})=>{let r=" ".repeat(n);return[${r}code:${e},...t.split(
).map(o=>${r} ${o})]},kr=({fileName:e,cells:t,indent:n})=>{let r=" ".repeat(n);return[${r}table:${e},...t.map(o=>${r} ${o.map(s=>s.map(a=>a.raw).join("")).join(" ")})]},Lr=({nodes:e,indent:t})=>[${" ".repeat(t)}${e.map(n=>${oe(n)}).join("")}],oe=e=>{switch(e.type){case"quote":return> ${e.nodes.map(t=>oe(t)).join("")};case"helpfeel":return-? ${e.text};case"commandLine":return-${e.symbol} ${e.text};case"icon":case"strongIcon":case"image":case"strongImage":case"formula":case"code":case"googleMap":return e.raw;case"strong":return${e.nodes.map(t=>oe(t)).join("")};case"decoration":{e.decos.includes("-")||e.decos.push("-");let t=e.decos.map(n=>{let r=parseInt(n.match(/\*-(\d)/)?.[1]??"0");return r>0?"*".repeat(r):n}).join("");return[${t?${t} :""}${e.nodes.map(n=>oe(n)).join("")}]}case"link":switch(e.pathType){case"root":case"relative":return${e.href};case"absolute":return[- ${e.content?${e.content} :""}${e.href}]]}case"hashTag":return#${e.href};case"numberList":return${e.number}. ${e.nodes.map(t=>oe(t)).join("")};case"blank":case"plain":return${e.text}}};scrapbox.PopupMenu.addButton({title:"打消し",onClick:e=>{let t=wr(e);if(e!==t)return t}});var z=document.createElement("div");Me();scrapbox.on("layout:changed",Me);scrapbox.on("lines:changed",Me);function Me(){if(scrapbox.Layout!=="page")z.remove();else{document.querySelector(".status-bar").appendChild(z);let e=scrapbox.Page.metadata.charsCount,t=scrapbox.Page.metadata.linesCount;z.innerText=${t}lines ${e}char,e<4096?z.style.color=null:e<8192?z.style.color="#f80":z.style.color="#f00"}}scrapbox.PopupMenu.addButton({title:function(e){let t=e.replace(/[\r\n]/g,"").length;return${e.split(`
).length}l ${t}c},onClick:()=>null});var Ne,_,et,Sr,D,Xe,tt,nt,Pe,he,se,rt,He,Oe,Re,Cr,ot={},_e=[],Tr=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|inech|zoo|^ord|itera/i,ie=Array.isArray;function I(e,t){for(var n in t)en=tn;return e}function $e(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function ae(e,t,n){var r,o,s,a={};for(s in t)s=="key"?r=ts:s=="ref"?o=ts:as=ts;if(arguments.length>2&&(a.children=arguments.length>3?Ne.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)as===void 0&&(as=e.defaultPropss);return ge(e,a,r,o,null)}function ge(e,t,n,r,o){var s={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++et,__i:-1,__u:0};return o==null&&_.vnode!=null&&_.vnode(s),s}function L(e){return e.children}function M(e,t){this.props=e,this.context=t}function q(e,t){if(t==null)return e.__?q(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__kt)!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?q(e):null}function Mr(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],o=[],s=I({},t);s.__v=t.__v+1,_.vnode&&_.vnode(s),ct(e.__P,s,t,e.__n,e.__P.namespaceURI,32&t.__u?n:null,r,n??q(t),!!(32&t.__u),o),s.__v=t.__v,s.__.__ks.__i=s,Rr(r,s,o),t.__e=t.__=null,s.__e!=n&&st(s)}}function st(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),st(e)}function Ge(e){(!e.__d&&(e.__d=!0)&&D.push(e)&&!ye.__r++||Xe!=_.debounceRendering)&&((Xe=_.debounceRendering)||tt)(ye)}function ye(){try{for(var e,t=1;D.length;)D.length>t&&D.sort(nt),e=D.shift(),t=D.length,Mr(e)}finally{D.length=ye.__r=0}}function it(e,t,n,r,o,s,a,u,p,c,l){var i,d,f,m,b,y,h,g=r&&r.__k||_e,S=t.length;for(p=Pr(n,t,g,p,S),i=0;i<S;i++)(f=n.__ki)!=null&&(d=f.__i!=-1&&gf.__i||ot,f.__i=i,y=ct(e,f,d,o,s,a,u,p,c,l),m=f.__e,f.ref&&d.ref!=f.ref&&(d.ref&&Ae(d.ref,null,f),l.push(f.ref,f.__c||m,f)),b==null&&m!=null&&(b=m),(h=!!(4&f.__u))||d.__k===f.__k?(p=at(f,p,e,h),h&&d.__e&&(d.__e=null)):typeof f.type=="function"&&y!==void 0?p=y:m&&(p=m.nextSibling),f.__u&=-7);return n.__e=b,p}function Pr(e,t,n,r,o){var s,a,u,p,c,l=n.length,i=l,d=0;for(e.__k=new Array(o),s=0;s<o;s++)(a=ts)!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=e.__ks=ge(null,a,null,null,null):ie(a)?a=e.__ks=ge(L,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__ks=ge(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__ks=a,p=s+d,a.__=e,a.__b=e.__b+1,u=null,(c=a.__i=Or(a,n,p,i))!=-1&&(i--,(u=nc)&&(u.__u|=2)),u==null||u.__v==null?(c==-1&&(o>l?d--:o<l&&d++),typeof a.type!="function"&&(a.__u|=4)):c!=p&&(c==p-1?d--:c==p+1?d++:(c>p?d--:d++,a.__u|=4))):e.__ks=null;if(i)for(s=0;s<l;s++)(u=ns)!=null&&!(2&u.__u)&&(u.__e==r&&(r=q(u)),lt(u,u));return r}function at(e,t,n,r){var o,s;if(typeof e.type=="function"){for(o=e.__k,s=0;o&&s<o.length;s++)os&&(os.__=e,t=at(os,t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=q(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function V(e,t){return t=t||[],e==null||typeof e=="boolean"||(ie(e)?e.some(function(n){V(n,t)}):t.push(e)),t}function Or(e,t,n,r){var o,s,a,u=e.key,p=e.type,c=tn,l=c!=null&&(2&c.__u)==0;if(c===null&&u==null||l&&u==c.key&&p==c.type)return n;if(r>(l?1:0)){for(o=n-1,s=n+1;o>=0||s<t.length;)if((c=ta=o>=0?o--:s++)!=null&&!(2&c.__u)&&u==c.key&&p==c.type)return a}return-1}function Je(e,t,n){t0=="-"?e.setProperty(t,n??""):et=n==null?"":typeof n!="number"||Tr.test(t)?n:n+"px"}function me(e,t,n,r,o){var s,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof r=="string"&&(e.style.cssText=r=""),r)for(t in r)n&&t in n||Je(e.style,t,"");if(n)for(t in n)r&&nt==rt||Je(e.style,t,nt)}else if(t0=="o"&&t1=="n")s=t!=(t=t.replace(rt,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.lt+s=n,n?r?nse=rse:(nse=He,e.addEventListener(t,s?Re:Oe,s)):e.removeEventListener(t,s?Re:Oe,s);else{if(o=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{et=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t4!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Ze(e){return function(t){if(this.l){var n=this.lt.type+e;if(the==null)the=He++;else if(the<nse)return;return n(_.event?_.event(t):t)}}}function ct(e,t,n,r,o,s,a,u,p,c){var l,i,d,f,m,b,y,h,g,S,C,P,J,U,B,E=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(p=!!(32&n.__u),s=u=t.__e=n.__e),(l=_.__b)&&l(t);e:if(typeof E=="function")try{if(h=t.props,g=E.prototype&&E.prototype.render,S=(l=E.contextType)&&rl.__c,C=l?S?S.props.value:l.__:r,n.__c?y=(i=t.__c=n.__c).__=i.__E:(g?t.__c=i=new E(h,C):(t.__c=i=new M(h,C),i.constructor=E,i.render=Nr),S&&S.sub(i),i.state||(i.state={}),i.__n=r,d=i.__d=!0,i.__h=[],i._sb=[]),g&&i.__s==null&&(i.__s=i.state),g&&E.getDerivedStateFromProps!=null&&(i.__s==i.state&&(i.__s=I({},i.__s)),I(i.__s,E.getDerivedStateFromProps(h,i.__s))),f=i.props,m=i.state,i.__v=t,d)g&&E.getDerivedStateFromProps==null&&i.componentWillMount!=null&&i.componentWillMount(),g&&i.componentDidMount!=null&&i.__h.push(i.componentDidMount);else{if(g&&E.getDerivedStateFromProps==null&&h!==f&&i.componentWillReceiveProps!=null&&i.componentWillReceiveProps(h,C),t.__v==n.__v||!i.__e&&i.shouldComponentUpdate!=null&&i.shouldComponentUpdate(h,i.__s,C)===!1){t.__v!=n.__v&&(i.props=h,i.state=i.__s,i.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(k){k&&(k.__=t)}),_e.push.apply(i.__h,i._sb),i._sb=[],i.__h.length&&a.push(i);break e}i.componentWillUpdate!=null&&i.componentWillUpdate(h,i.__s,C),g&&i.componentDidUpdate!=null&&i.__h.push(function(){i.componentDidUpdate(f,m,b)})}if(i.context=C,i.props=h,i.__P=e,i.__e=!1,P=_.__r,J=0,g)i.state=i.__s,i.__d=!1,P&&P(t),l=i.render(i.props,i.state,i.context),_e.push.apply(i.__h,i._sb),i._sb=[];else do i.__d=!1,P&&P(t),l=i.render(i.props,i.state,i.context),i.state=i.__s;while(i.__d&&++J<25);i.state=i.__s,i.getChildContext!=null&&(r=I(I({},r),i.getChildContext())),g&&!d&&i.getSnapshotBeforeUpdate!=null&&(b=i.getSnapshotBeforeUpdate(f,m)),U=l!=null&&l.type===L&&l.key==null?ut(l.props.children):l,u=it(e,ie(U)?U:U,t,n,r,o,s,a,u,p,c),i.base=t.__e,t.__u&=-161,i.__h.length&&a.push(i),y&&(i.__E=i.__=null)}catch(k){if(t.__v=null,p||s!=null)if(k.then){for(t.__u|=p?160:128;u&&u.nodeType==8&&u.nextSibling;)u=u.nextSibling;ss.indexOf(u)=null,t.__e=u}else{for(B=s.length;B--;)$e(sB);Ie(t)}else t.__e=n.__e,t.__k=n.__k,k.then||Ie(t);_.__e(k,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):u=t.__e=Ir(n.__e,t,n,r,o,s,a,p,c);return(l=_.diffed)&&l(t),128&t.__u?void 0:u}function Ie(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Ie))}function Rr(e,t,n){for(var r=0;r<n.length;r++)Ae(nr,n++r,n++r);_.__c&&_.__c(t,e),e.some(function(o){try{e=o.__h,o.__h=[],e.some(function(s){s.call(o)})}catch(s){_.__e(s,o.__v)}})}function ut(e){return typeof e!="object"||e==null||e.__b>0?e:ie(e)?e.map(ut):e.constructor!==void 0?null:I({},e)}function Ir(e,t,n,r,o,s,a,u,p){var c,l,i,d,f,m,b,y=n.props||ot,h=t.props,g=t.type;if(g=="svg"?o="http://www.w3.org/2000/svg":g=="math"?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),s!=null){for(c=0;c<s.length;c++)if((f=s[c])&&"setAttribute"in f==!!g&&(g?f.localName==g:f.nodeType==3)){e=f,sc=null;break}}if(e==null){if(g==null)return document.createTextNode(h);e=document.createElementNS(o,g,h.is&&h),u&&(_.__m&&_.__m(t,s),u=!1),s=null}if(g==null)y===h||u&&e.data==h||(e.data=h);else{if(s=g=="textarea"&&h.defaultValue!=null?null:s&&Ne.call(e.childNodes),!u&&s!=null)for(y={},c=0;c<e.attributes.length;c++)y[(f=e.attributesc).name]=f.value;for(c in y)f=yc,c=="dangerouslySetInnerHTML"?i=f:c=="children"||c in h||c=="value"&&"defaultValue"in h||c=="checked"&&"defaultChecked"in h||me(e,c,null,f,o);for(c in h)f=hc,c=="children"?d=f:c=="dangerouslySetInnerHTML"?l=f:c=="value"?m=f:c=="checked"?b=f:u&&typeof f!="function"||yc===f||me(e,c,f,yc,o);if(l)u||i&&(l.__html==i.__html||l.__html==e.innerHTML)||(e.innerHTML=l.__html),t.__k=[];else if(i&&(e.innerHTML=""),it(t.type=="template"?e.content:e,ie(d)?d:d,t,n,r,g=="foreignObject"?"http://www.w3.org/1999/xhtml":o,s,a,s?s[0]:n.__k&&q(n,0),u,p),s!=null)for(c=s.length;c--;)$e(s[c]);u&&g!="textarea"||(c="value",g=="progress"&&m==null?e.removeAttribute("value"):m!=null&&(m!==e[c]||g=="progress"&&!m||g=="option"&&m!=y[c])&&me(e,c,m,y[c],o),c="checked",b!=null&&b!=e[c]&&me(e,c,b,y[c],o))}return e}function Ae(e,t,n){try{if(typeof e=="function"){var r=typeof e.__u=="function";r&&e.__u(),r&&t==null||(e.__u=e(t))}else e.current=t}catch(o){_.__e(o,n)}}function lt(e,t,n){var r,o;if(_.unmount&&_.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||Ae(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(s){_.__e(s,t)}r.base=r.__P=null}if(r=e.__k)for(o=0;o<r.length;o++)ro&&lt(ro,t,n||typeof e.type!="function");n||$e(e.__e),e.__c=e.__=e.__e=void 0}function Nr(e,t,n){return this.constructor(e,n)}Ne=_e.slice,_={__e:function(e,t,n,r){for(var o,s,a;t=t.__;)if((o=t.__c)&&!o.__)try{if((s=o.constructor)&&s.getDerivedStateFromError!=null&&(o.setState(s.getDerivedStateFromError(e)),a=o.__d),o.componentDidCatch!=null&&(o.componentDidCatch(e,r||{}),a=o.__d),a)return o.__E=o}catch(u){e=u}throw e}},et=0,Sr=function(e){return e!=null&&e.constructor===void 0},M.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=I({},this.state),typeof e=="function"&&(e=e(I({},n),this.props)),e&&I(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Ge(this))},M.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Ge(this))},M.prototype.render=L,D=[],tt=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,nt=function(e,t){return e.__v.__b-t.__v.__b},ye.__r=0,Pe=Math.random().toString(8),he="__d"+Pe,se="__a"+Pe,rt=/(PointerCapture)$|Capture$/i,He=0,Oe=Ze(!1),Re=Ze(!0),Cr=0;var pt,O,De,dt;var xt=[],w=_,ft=w.__b,mt=w.__r,ht=w.diffed,gt=w.__c,_t=w.unmount,yt=w.__;function Hr(){for(var e;e=xt.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(be),t.__h.some(je),t.__h=[]}catch(n){t.__h=[],w.__e(n,e.__v)}}}w.__b=function(e){O=null,ft&&ft(e)},w.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),yt&&yt(e,t)},w.__r=function(e){mt&&mt(e),pt=0;var t=(O=e.__c).__H;t&&(De===O?(t.__h=[],O.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(be),t.__h.some(je),t.__h=[],pt=0)),De=O},w.diffed=function(e){ht&&ht(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(xt.push(t)!==1&&dt===w.requestAnimationFrame||((dt=w.requestAnimationFrame)||$r)(Hr)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),De=O=null},w.__c=function(e,t){t.some(function(n){try{n.__h.some(be),n.__h=n.__h.filter(function(r){return!r.__||je(r)})}catch(r){t.some(function(o){o.__h&&(o.__h=[])}),t=[],w.__e(r,n.__v)}}),gt&&gt(e,t)},w.unmount=function(e){_t&&_t(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(r){try{be(r)}catch(o){t=o}}),n.__H=void 0,t&&w.__e(t,n.__v))};var bt=typeof requestAnimationFrame=="function";function $r(e){var t,n=function(){clearTimeout(r),bt&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);bt&&(t=requestAnimationFrame(n))}function be(e){var t=O,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),O=t}function je(e){var t=O;e.__c=e.__(),O=t}function jr(e,t){for(var n in t)en=tn;return e}function vt(e,t){for(var n in e)if(n!=="__source"&&!(n in t))return!0;for(var r in t)if(r!=="__source"&&er!==tr)return!0;return!1}function wt(e,t){this.props=e,this.context=t}(wt.prototype=new M).isPureReactComponent=!0,wt.prototype.shouldComponentUpdate=function(e,t){return vt(this.props,e)||vt(this.state,t)};var Et=_.__b;_.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),Et&&Et(e)};var Zo=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.forward_ref")||3911;var Ur=_.__e;_.__e=function(e,t,n,r){if(e.then){for(var o,s=t;s=s.__;)if((o=s.__c)&&o.__c)return t.__e==null&&(t.__e=n.__e,t.__k=n.__k),o.__c(e,t)}Ur(e,t,n,r)};var kt=_.unmount;function It(e,t,n){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(r){typeof r.__c=="function"&&r.__c()}),e.__c.__H=null),(e=jr({},e)).__c!=null&&(e.__c.__P===n&&(e.__c.__P=t),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(r){return It(r,t,n)})),e}function Nt(e,t,n){return e&&n&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(r){return Nt(r,t,n)}),e.__c&&e.__c.__P===t&&(e.__e&&n.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=n)),e}function Ue(){this.__u=0,this.o=null,this.__b=null}function Ht(e){var t=e.__&&e.__.__c;return t&&t.__a&&t.__a(e)}function xe(){this.i=null,this.l=null}_.unmount=function(e){var t=e.__c;t&&(t.__z=!0),t&&t.__R&&t.__R(),t&&32&e.__u&&(e.type=null),kt&&kt(e)},(Ue.prototype=new M).__c=function(e,t){var n=t.__c,r=this;r.o==null&&(r.o=[]),r.o.push(n);var o=Ht(r.__v),s=!1,a=function(){s||r.__z||(s=!0,n.__R=null,o?o(p):p())};n.__R=a;var u=n.__P;n.__P=null;var p=function(){if(!--r.__u){if(r.state.__a){var c=r.state.__a;r.__v.__k0=Nt(c,c.__c.__P,c.__c.__O)}var l;for(r.setState({__a:r.__b=null});l=r.o.pop();)l.__P=u,l.forceUpdate()}};r.__u++||32&t.__u||r.setState({__a:r.__b=r.__v.__k0}),e.then(a,a)},Ue.prototype.componentWillUnmount=function(){this.o=[]},Ue.prototype.render=function(e,t){if(this.__b){if(this.__v.__k){var n=document.createElement("div"),r=this.__v.__k0.__c;this.__v.__k0=It(this.__b,n,r.__O=r.__P)}this.__b=null}var o=t.__a&&ae(L,null,e.fallback);return o&&(o.__u&=-33),ae(L,null,t.__a?null:e.children),o};var Lt=function(e,t,n){if(++n1===n0&&e.l.delete(t),e.props.revealOrder&&(e.props.revealOrder0!=="t"||!e.l.size))for(n=e.i;n;){for(;n.length>3;)n.pop()();if(n1<n0)break;e.i=n=n2}};(xe.prototype=new M).__a=function(e){var t=this,n=Ht(t.__v),r=t.l.get(e);return r0++,function(o){var s=function(){t.props.revealOrder?(r.push(o),Lt(t,e,r)):o()};n?n(s):s()}},xe.prototype.render=function(e){this.i=null,this.l=new Map;var t=V(e.children);e.revealOrder&&e.revealOrder0==="b"&&t.reverse();for(var n=t.length;n--;)this.l.set(tn,this.i=1,0,this.i);return e.children},xe.prototype.componentDidUpdate=xe.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(t,n){Lt(e,n,t)})};var Fr=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,Br=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))A-Z/,Kr=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,Wr=/A-Z0-9/g,zr=typeof document<"u",qr=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};M.prototype.isReactComponent=!0,"componentWillMount","componentWillReceiveProps","componentWillUpdate".forEach(function(e){Object.defineProperty(M.prototype,e,{configurable:!0,get:function(){return this"UNSAFE_"+e},set:function(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:t})}})});var St=_.event;_.event=function(e){return St&&(e=St(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var $t,Vr={configurable:!0,get:function(){return this.class}},Ct=_.vnode;_.vnode=function(e){typeof e.type=="string"&&function(t){var n=t.props,r=t.type,o={},s=r.indexOf("-")==-1;for(var a in n){var u=na;if(!(a==="value"&&"defaultValue"in n&&u==null||zr&&a==="children"&&r==="noscript"||a==="class"||a==="className")){var p=a.toLowerCase();a==="defaultValue"&&"value"in n&&n.value==null?a="value":a==="download"&&u===!0?u="":p==="translate"&&u==="no"?u=!1:p0==="o"&&p1==="n"?p==="ondoubleclick"?a="ondblclick":p!=="onchange"||r!=="input"&&r!=="textarea"||qr(n.type)?p==="onfocus"?a="onfocusin":p==="onblur"?a="onfocusout":Kr.test(a)&&(a=p):p=a="oninput":s&&Br.test(a)?a=a.replace(Wr,"-$&").toLowerCase():u===null&&(u=void 0),p==="oninput"&&oa=p&&(a="oninputCapture"),oa=u}}r=="select"&&(o.multiple&&Array.isArray(o.value)&&(o.value=V(n.children).forEach(function(c){c.props.selected=o.value.indexOf(c.props.value)!=-1})),o.defaultValue!=null&&(o.value=V(n.children).forEach(function(c){c.props.selected=o.multiple?o.defaultValue.indexOf(c.props.value)!=-1:o.defaultValue==c.props.value}))),n.class&&!n.className?(o.class=n.class,Object.defineProperty(o,"className",Vr)):n.className&&(o.class=o.className=n.className),t.props=o}(e),e.$$typeof=Fr,Ct&&Ct(e)};var Tt=_.__r;_.__r=function(e){Tt&&Tt(e),$t=e.__c};var Mt=_.diffed;_.diffed=function(e){Mt&&Mt(e);var t=e.props,n=e.__e;n!=null&&e.type==="textarea"&&"value"in t&&t.value!==n.value&&(n.value=t.value==null?"":t.value),$t=null};var At=!1;scrapbox.addListener("lines:changed",()=>At=!1);scrapbox.addListener("layout:changed",()=>At=!1);var Dt=(e,t)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError("${t}" must be HTMLTextAreaElement but actual is "${e}")};var F=()=>{let e=document.getElementById("text-input");if(e)return Dt(e,"textarea#text-input"),e};var Vs=2**31-1;var Ft=e=>{if(e===0)return;let t={};return e&1&&(t.capture=!0),e&2&&(t.once=!0),e&4&&(t.passive=!0),t};var oo=new Map;scrapbox.on("layout:changed",()=>{let e=F();if(e)for(lett,nof oo)for(letr,oof n)for(let s of o)e.addEventListener(t,r,Ft(s))});var ka=Array.isArray;var T=!1;var X=e=>Object.fromEntries(...Object.entries(console).map((t,n)=>{if(typeof n!="function")returnt,n;switch(t){case"warn":case"error":return[t,(...r)=>n(%c${e},Fe,...r)];case"log":case"info":case"debug":return[t,(...r)=>{T!==!0&&(!T||!T.has(e))||n(%c${e},Fe,...r)}];case"assert":return[t,(r,...o)=>{T!==!0&&(!T||!T.has(e))||n(r,%c${e},Fe,...o)}];case"time":case"timeEnd":return[t,r=>{T!==!0&&(!T||!T.has(e))||n(${e} ${r})}];default:returnt,(...r)=>{if(!(T!==!0&&(!T||!T.has(e))))return n(...r)}}})),Fe="color: gray";var Ic=X("scrapbox-select-suggestion:useLifecycle.ts");var $c=Symbol("Comlink.proxy"),Ac=Symbol("Comlink.endpoint"),io=Symbol("Comlink.releaseProxy"),Dc=Symbol("Comlink.finalizer"),jc=Symbol("Comlink.thrown");function ao(e){return e.constructor.name==="MessagePort"}function co(e){ao(e)&&e.close()}function uo(e){return lo(e,new Map,{type:"RELEASE"}).then(()=>{co(e)})}var Bt=new WeakMap,Uc="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{let t=(Bt.get(e)||0)-1;Bt.set(e,t),t===0&&uo(e)});function lo(e,t,n,r){return new Promise(o=>{let s=po();t.set(s,o),e.start&&e.start(),e.postMessage(Object.assign({id:s},n),r)})}function po(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var Xc=X("scrapbox-select-suggestion:cancelableSearch.ts");var fu=X("scrapbox-select-suggestion:useSearch.ts");var Be={};en(Be,{default:()=>zt});var fo=Object.create,Wt=Object.defineProperty,mo=Object.getOwnPropertyDescriptor,ho=Object.getOwnPropertyNames,go=Object.getPrototypeOf,_o=Object.prototype.hasOwnProperty,yo=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bo=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ho(t))!_o.call(e,o)&&o!==n&&Wt(e,o,{get:()=>to,enumerable:!(r=mo(t,o))||r.enumerable});return e},xo=(e,t,n)=>(n=e!=null?fo(go(e)):{},bo(t||!e||!e.__esModule?Wt(n,"default",{value:e,enumerable:!0}):n,e)),vo=yo((e,t)=>{(function(){var n;n=function(){var r,o,s;r=2147483648,s=256,o=r,0,0,0,a.prototype.isupper=function(u){return u>=65&&u<=90},a.prototype.islower=function(u){return u>=97&&u<=122},a.prototype.tolower=function(u){return this.isupper(u)?u+32:u},a.prototype.toupper=function(u){return this.islower(u)?u-32:u};function a(u){var p,c,l,i,d,f;for(this.source=u,this.shiftpat=[],this.epsilon=0,this.acceptpat=0,c=r,p=l=0;0<=s?l<s:l>s;p=0<=s?++l:--l)this.shiftpatp=0;for(f=this.unpack(this.source),i=0,d=f.length;i<d;i++)p=fi,p===32?this.epsilon|=c:(this.shiftpatp|=c,this.shiftpatthis.toupper(p)|=c,this.shiftpatthis.tolower(p)|=c,c>>>=1);return this.acceptpat=c,this}return a.prototype.state=function(u,p){var c,l,i,d,f,m,b,y,h;for(u==null&&(u=o),p==null&&(p=""),l=u0,i=u1,d=u2,f=u3,h=this.unpack(p),b=0,y=h.length;b<y;b++)c=hb,m=this.shiftpatc,f=f&this.epsilon|(f&m)>>>1|d>>>1|d,d=d&this.epsilon|(d&m)>>>1|i>>>1|i,i=i&this.epsilon|(i&m)>>>1|l>>>1|l,l=l&this.epsilon|(l&m)>>>1,i|=l>>>1,d|=i>>>1,f|=d>>>1;returnl,i,d,f},a.prototype.match=function(u,p){var c;return p==null&&(p=0),c=this.state(o,u),p<o.length||(p=o.length-1),(cp&this.acceptpat)!==0},a.prototype.unpack=function(u){var p,c,l,i,d,f;for(p=[],f=u.split(""),i=0,d=f.length;i<d;i++)c=fi,l=c.charCodeAt(0),l>255&&p.push((l&65280)>>>8),p.push(l&255);return p},a}(),typeof t<"u"&&t!==null&&t.exports!=null?t.exports=n:typeof window<"u"&&window!==null&&(window.Asearch=n)}).call(e)}),Kt=xo(vo()),zt=Kt.default??Kt;var G=e=>{let t=r=>typeof r.default<"u"?r.default:r,n=r=>Object.assign({__esModule:!0},r);switch(e){case"asearch":return t(Be);default:return console.error('module "'+e+'" not found'),null}},wo=Object.create,Vt=Object.defineProperty,Eo=Object.getOwnPropertyDescriptor,ko=Object.getOwnPropertyNames,Lo=Object.getPrototypeOf,So=Object.prototype.hasOwnProperty,Co=(e=>typeof G<"u"?G:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof G<"u"?G:t)n}):e)(function(e){if(typeof G<"u")return G.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),ve=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),To=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ko(t))!So.call(e,o)&&o!==n&&Vt(e,o,{get:()=>to,enumerable:!(r=Eo(t,o))||r.enumerable});return e},Mo=(e,t,n)=>(n=e!=null?wo(Lo(e)):{},To(t||!e||!e.__esModule?Vt(n,"default",{value:e,enumerable:!0}):n,e)),Qt=ve((e,t)=>{var n;n=function(){function r(o){this.s=o,this.a=o.split(""),this.p=0,this.t="",this.u=""}return r.prototype.gettoken=function(){if(this.u!=="")return this.t=this.u,this.u="",this.t;if(this.p>=this.a.length)return this.t="","";if(this.t=this.athis.p,this.t.match(/^[\(\|\)\*\+\?\\]$/))return this.p+=1,this.t;if(this.t==="\\")return this.t=this.a++this.p,this.t==="n"&&(this.t=`
),this.t==="t"&&(this.t=" "),this.p+=1,this.t;for(this.p+=1;this.p<this.a.length&&!this.a[this.p].match(/^[\(\|\)\*\+\?\[\]\\]$/);)this.t+=this.a[this.p++];return this.t},r.prototype.ungettoken=function(){return this.u===""?this.u=this.t:console.log("Can't ungettoken()")},r.prototype.nexttoken=function(){return this.t},r}(),t.exports=n}),Yt=ve((e,t)=>{var n,r;r=function(){function o(s,a){this.pat=s,this.dest=a}return o.prototype.str=function(){return this.pat.split(/\t/)[0]},o.prototype.arg=function(){var s;return s=this.pat.match(/^(.*)\t(.*)$/),s?s[2]:this.pat},o}(),n=function(){o.id=1,o.nodes={};function o(){this.id=o.id,this.accept=null,this.trans=[],o.nodes[o.id++]=this,this.pars=[]}return o.prototype.addTrans=function(s,a){var u;return u=new r(s,a),this.trans.push(u)},o.node=function(s){return o.nodes[s]},o}(),t.exports=n}),Po=ve((e,t)=>{var n,r,o;n=Yt(),o=Qt(),r=function(){function s(){}return s.prototype.regexp=function(a,u){var p,c,l,i,d,f;for(u==null&&(u=!1),f=new n,p=new n,u&&(this.pars=[],this.parno=0,this.ruleid=0),f.pars=this.pars,p.pars=this.pars,i=this.regcat(a),c=i[0],l=i[1],f.addTrans("",c),u&&(l.accept=this.ruleid),l.addTrans("",p);a.gettoken()==="|"&&a.nexttoken()!=="";)u&&(this.pars=[],this.parno=0,this.ruleid+=1),d=this.regcat(a),c=d[0],l=d[1],f.addTrans("",c),u&&(l.accept=this.ruleid),l.addTrans("",p);return a.ungettoken(),[f,p]},s.prototype.regcat=function(a){var u,p,c,l,i,d;for(l=this.regfactor(a),d=l[0],u=l[1];!a.gettoken().match(/^[\)\]\|]$/)&&a.nexttoken()!=="";)a.ungettoken(),i=this.regfactor(a),p=i[0],c=i[1],u.addTrans("",p),u=c;return a.ungettoken(),[d,u]},s.prototype.regfactor=function(a){var u,p,c,l,i;return c=this.regterm(a),l=c[0],u=c[1],i=a.gettoken(),i.match(/^[\?]$/)?l.addTrans("",u):i.match(/^[\+]$/)?u.addTrans("",l):i.match(/^[\*]$/)?(p=new n,l.addTrans("",u),u.addTrans("",p),p.addTrans("",l)):a.ungettoken(),[l,u]},s.prototype.regterm=function(a){var u,p,c,l,i,d;return d=a.gettoken(),d==="("?(this.parno+=1,this.pars.push(this.parno),l=this.regexp(a),p=l[0],c=l[1],p.pars=this.pars.slice(0),d=a.gettoken(),d===")"?(this.pars.pop(),c.pars=this.pars.slice(0),[p,c]):(console.log("missing )"),null)):(i=new n,i.pars=this.pars.slice(0),u=new n,u.pars=this.pars.slice(0),i.addTrans(d,u),[i,u])},s}(),t.exports=r}),Oo=ve((e,t)=>{var n,r,o,s,a,u;u=Qt(),a=Po(),s=Yt(),n=Co("asearch"),r=function(){function p(c,l,i,d,f){this.id=c,this.state=l??[],this.s=i??"",this.substrings=d??[],this.accept=f??!1}return p}(),o=function(){function p(c,l){c==null&&(c=""),l==null&&(l=""),this.s=[c],this.commands=[l],this.par=0}return p.prototype.add=function(c,l){return this.s[0]===""?this.s=[c]:this.s.push(c),this.commands[0]===""?this.commands=[l]:this.commands.push(l)},p.prototype.delete=function(){return this.s.pop,this.commands.pop},p.prototype.filter=function(c,l,i){var d,f,m,b,y,h,g,S,C,P,J,U,B,E,k,we,ue,le,Ee,pe,de,ke,Z,ee,Gt,te,Le,Se,Ce,ne,re,K,H,fe,R,Te,We,W;for(l==null&&(l=null),this.maxambig=i??2,K=[[],[],[]],Gt=c.split("").map(function(Jt){return Jt.toLowerCase()}),this.asearch=new n(c),this.regexp=new a,this.scanner=new u(this.s.join("|")),Le=this.regexp.regexp(this.scanner,!0),We=Le[0],b=Le[1],ue=[],we=[{},{},{}],h={},k=[],k[0]=new r(We.id,this.asearch.state()),ue[0]=k,E=S=0;S<=1e4;E=++S){for(k=ue[E],de=[],C=0,J=k.length;C<J;C++)if(y=k[C],fe=s.node(y.id),k.length*fe.trans.length<1e5)for(Se=fe.trans,P=0,U=Se.length;P<U;P++){for(W=Se[P],R=y.substrings.slice(0),Ce=fe.pars,pe=0,B=Ce.length;pe<B;pe++)g=Ce[pe],typeof R[g-1]>"u"&&(R[g-1]=""),R[g-1]=R[g-1]+W.arg();if(ke=this.asearch.state(y.state,W.str()),H=y.s+W.str(),d=W.dest.accept,de.push(new r(W.dest.id,ke,H,R,d)),d!==null){for(f=Z=0,ne=this.maxambig;0<=ne?Z<=ne:Z>=ne;f=0<=ne?++Z:--Z)if((l&&!h[H]||!l&&!we[f][H])&&ke[f]&this.asearch.acceptpat){if(we[f][H]=!0,h[H]=!0,Te=R.length,Ee=[],Te>0){for(ee=[],g=te=0,re=Te;0<=re?te<re:te>re;g=0<=re?++te:--te)ee.push("(.*)");ee=ee.join(" "),Ee=R.join(" ").match(ee)}for(m=this.commands[d],m||(m="");le=m.match(/^(.*)(\$(\d+))(.*)$/);)m=""+le[1]+Ee[le[3]]+le[4];l?l([H].concat(R),m):K[f].push([H,m])}}}if(de.length===0||(ue.push(de),K[0].length>100))break}return[K[0],K[1],K[2]]},p}(),String.prototype.expand=function(p,c,l){var i,d,f,m,b,y,h;if(p==null&&(p=" "),c==null&&(c=null),l==null&&(l=0),i=new o,i.add(this,""),h=[],c)return i.filter(p,c);for(m=i.filter(p),b=m[0].length>0?m[0]:m[1].length>0?m[1]:m[2],d=0,f=b.length;d<f;d++)y=b[d],h.push(y[0]);return h},t.exports=o}),qt=Mo(Oo()),Ke=qt.default??qt;var Ro=e=>{let t=new Ke(e);try{return[...new Set(t.filter(" ").flatMap(n=>n.map(([r])=>r)))]}catch(n){if(n instanceof TypeError)return[];throw n}},Xt=/^\s*\[(^\n+)\]/,Io=e=>{let t=e.match(Xt);return t===null?e:\[${t[1]}]\` ${Ro(t[1].replace(/[\[\]]/g,"")).flatMap(n=>n!==""?[(${n})]:[]).join(" ")}};scrapbox.PopupMenu.addButton({title:e=>e.split(`
).some(t=>Xt.test(t.trim()))?"正規表現を展開":"",onClick:e=>e.split(
).map(Io).join(
`)});scrapbox.TimeStamp.addFormat("]YYYY/MM/DD[");
/*! Bundled license information:
comlink/dist/esm/comlink.mjs:
(**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*)
*/