mod.jsvar l=e=>e==null,s=e=>typeof e=="string",c=e=>typeof e=="number";var g=(e,t)=>{if(!Array.isArray(e))throw new TypeError(`"${t}" must be an array but actual is "${e}"`)};var x=(e,t)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError(`"${t}" must be HTMLTextAreaElement but actual is "${e}"`)};var i=()=>{let e=document.getElementById("text-input");if(!!e)return x(e,"textarea#text-input"),e};var m=e=>e.match(/^(\s*)/)?.[1]?.length??0;function p(e){if(l(e))return;if(c(e))return M(e)?.id;if(s(e))return e.startsWith("L")?e.slice(1):e;if(e.classList.contains("line"))return e.id.slice(1);let t=e.closest(".line");if(t)return t.id.slice(1)}function M(e){if(l(e))return;if(c(e))return h()[e];let t=p(e);return t?h().find(n=>n.id===t):void 0}function h(){return g(scrapbox.Page.lines,"scrapbox.Page.lines"),scrapbox.Page.lines}function f(){let e=i();if(!e)throw Error("#text-input is not found.");let t=Object.keys(e).find(n=>n.startsWith("__reactFiber"));if(!t)throw Error('div.cursor must has the property whose name starts with "__reactFiber"');return e[t].return.return.stateNode.props}var E=e=>[...e].map((t,n)=>t===" "?"_":!A.includes(t)||n===e.length-1&&D.includes(t)?encodeURIComponent(t):t).join(""),A='@$&+=:;",',D=':;",';var w=(e,t,n)=>{let r=new URL(`/${e}/${E(t)}`,location.href);if(n?.body&&(r.search=`?body=${encodeURIComponent(n.body)}`),n?.id&&(r.hash=`#${n.id}`),n?.newTab!==!1&&(n?.newTab===!0||e!==scrapbox.Project.name)){window.open(r);return}if(n?.reload!==!1&&(n?.reload===!0||e!==scrapbox.Project.name)){window.open(r,"_self");return}let o=document.createElement("a");o.href=r.toString(),document.body.append(o),o.click(),o.remove()};var st=e=>{if(scrapbox.Layout!=="page")return;let t=e?.project??scrapbox.Project.name,{selectedText:n,selectionRange:{start:r,end:o}}=f(),d=p(Math.min(r.line,o.line)),b=`${t!==scrapbox.Project.name?`/${scrapbox.Project.name}/`:""}${scrapbox.Page.title}${d?`#${d}`:""}`,a=n.split(`
`),y=a[0].replaceAll("[","").replaceAll("]","").replaceAll("`",""),T=Math.min(...a.map(u=>m(u))),L=[`from [${b}]`,...a.map(u=>u.slice(T))].join(`
`);w(t,y,{body:L,...e??{}})};export{st as copy};