overtype 2.3.9 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,29 @@
1
1
  /**
2
- * OverType v2.3.9
2
+ * OverType v2.4.0
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
6
6
  * https://github.com/panphora/overtype
7
7
  */
8
- var OverType=(()=>{var ke=Object.defineProperty;var yn=Object.getOwnPropertyDescriptor;var wn=Object.getOwnPropertyNames;var bn=Object.prototype.hasOwnProperty;var xn=(t,e,n)=>e in t?ke(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var st=(t,e)=>{for(var n in e)ke(t,n,{get:e[n],enumerable:!0})},kn=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of wn(e))!bn.call(t,i)&&i!==n&&ke(t,i,{get:()=>e[i],enumerable:!(o=yn(e,i))||o.enumerable});return t};var Ln=t=>kn(ke({},"__esModule",{value:!0}),t);var T=(t,e,n)=>(xn(t,typeof e!="symbol"?e+"":e,n),n);var vo={};st(vo,{OverType:()=>j,default:()=>go,defaultToolbarButtons:()=>re,markdownActions:()=>ne,toolbarButtons:()=>S});var C=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static setCustomSyntax(e){this.customSyntax=e}static applyCustomSyntax(e){return this.customSyntax?this.customSyntax(e):e}static escapeHtml(e){let n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,o=>n[o])}static preserveIndentation(e,n){let i=n.match(/^(\s*)/)[1].replace(/ /g,"&nbsp;");return e.replace(/^\s*/,i)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(n,o,i)=>{let r=o.length;return i=this.parseInlineElements(i),`<h${r}><span class="syntax-marker">${o} </span>${i}</h${r}>`})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`<div><span class="hr-marker">${e}</span></div>`:null}static parseBlockquote(e){return e.replace(/^&gt; (.+)$/,(n,o)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${o}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*+])\s(.+)$/,(n,o,i,r)=>(r=this.parseInlineElements(r),`${o}<li class="bullet-list"><span class="syntax-marker">${i} </span>${r}</li>`))}static parseTaskList(e,n=!1){return e.replace(/^((?:&nbsp;)*)-(\s+)\[([ xX])\](\s*)(.*)$/,(o,i,r,s,a,l)=>{if(l=this.parseInlineElements(l),n){let p=s.toLowerCase()==="x";return`${i}<li class="task-list"><input type="checkbox" ${p?"checked":""}> ${l}</li>`}else return`${i}<li class="task-list"><span class="syntax-marker">-${r}[${s}]${a}</span>${l}</li>`})}static parseNumberedList(e){return e.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/,(n,o,i,r)=>(r=this.parseInlineElements(r),`${o}<li class="ordered-list"><span class="syntax-marker">${i} </span>${r}</li>`))}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`<div><span class="code-fence">${e}</span></div>`:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'<strong><span class="syntax-marker">**</span>$1<span class="syntax-marker">**</span></strong>'),e=e.replace(/__(.+?)__/g,'<strong><span class="syntax-marker">__</span>$1<span class="syntax-marker">__</span></strong>'),e}static parseItalic(e){return e=e.replace(new RegExp("(?<![\\*>])\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)","g"),'<em><span class="syntax-marker">*</span>$1<span class="syntax-marker">*</span></em>'),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?<!_)_(?!_)(?=\\s|$)","g"),'<em><span class="syntax-marker">_</span>$1<span class="syntax-marker">_</span></em>'),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?<!~)~~(?!~)(.+?)(?<!~)~~(?!~)","g"),'<del><span class="syntax-marker">~~</span>$1<span class="syntax-marker">~~</span></del>'),e=e.replace(new RegExp("(?<!~)~(?!~)(.+?)(?<!~)~(?!~)","g"),'<del><span class="syntax-marker">~</span>$1<span class="syntax-marker">~</span></del>'),e}static parseInlineCode(e){return e.replace(new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),'<code><span class="syntax-marker">$1</span>$2<span class="syntax-marker">$3</span></code>')}static sanitizeUrl(e){let n=e.trim(),o=n.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>o.startsWith(a)),s=n.startsWith("/")||n.startsWith("#")||n.startsWith("?")||n.startsWith(".")||!n.includes(":")&&!n.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(n,o,i)=>{let r=`--link-${this.linkIndex++}`;return`<a href="${this.sanitizeUrl(i)}" style="anchor-name: ${r}"><span class="syntax-marker">[</span>${o}<span class="syntax-marker url-part">](${i})</span></a>`})}static identifyAndProtectSanctuaries(e){let n=new Map,o=0,i=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let u=a.index+a[0].indexOf("](")+2,h=u+a[2].length;r.push({start:u,end:h})}let l=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),p,c=[];for(;(p=l.exec(e))!==null;){let d=p.index,u=p.index+p[0].length;r.some(f=>d>=f.start&&u<=f.end)||c.push({match:p[0],index:p.index,openTicks:p[1],content:p[2],closeTicks:p[3]})}return c.sort((d,u)=>u.index-d.index),c.forEach(d=>{let u=`\uE000${o++}\uE001`;n.set(u,{type:"code",original:d.match,openTicks:d.openTicks,content:d.content,closeTicks:d.closeTicks}),i=i.substring(0,d.index)+u+i.substring(d.index+d.match.length)}),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(d,u,h)=>{let f=`\uE000${o++}\uE001`;return n.set(f,{type:"link",original:d,linkText:u,url:h}),f}),{protectedText:i,sanctuaries:n}}static restoreAndTransformSanctuaries(e,n){return Array.from(n.keys()).sort((i,r)=>{let s=e.indexOf(i),a=e.indexOf(r);return s-a}).forEach(i=>{let r=n.get(i),s;if(r.type==="code")s=`<code><span class="syntax-marker">${r.openTicks}</span>${r.content}<span class="syntax-marker">${r.closeTicks}</span></code>`;else if(r.type==="link"){let a=r.linkText;n.forEach((c,d)=>{if(a.includes(d)&&c.type==="code"){let u=`<code><span class="syntax-marker">${c.openTicks}</span>${c.content}<span class="syntax-marker">${c.closeTicks}</span></code>`;a=a.replace(d,u)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let l=`--link-${this.linkIndex++}`;s=`<a href="${this.sanitizeUrl(r.url)}" style="anchor-name: ${l}"><span class="syntax-marker">[</span>${a}<span class="syntax-marker url-part">](${r.url})</span></a>`}e=e.replace(i,s)}),e}static parseInlineElements(e){let{protectedText:n,sanctuaries:o}=this.identifyAndProtectSanctuaries(e),i=n;return i=this.parseStrikethrough(i),i=this.parseBold(i),i=this.parseItalic(i),i=this.restoreAndTransformSanctuaries(i,o),i}static parseLine(e,n=!1){let o=this.escapeHtml(e);o=this.preserveIndentation(o,e);let i=this.parseHorizontalRule(o);if(i)return i;let r=this.parseCodeBlock(o);return r||(o=this.parseHeader(o),o=this.parseBlockquote(o),o=this.parseTaskList(o,n),o=this.parseBulletList(o),o=this.parseNumberedList(o),!o.includes("<li")&&!o.includes("<h")&&(o=this.parseInlineElements(o)),o.trim()===""?"<div>&nbsp;</div>":`<div>${o}</div>`)}static parse(e,n=-1,o=!1,i,r=!1){this.resetLinkIndex();let s=e.split(`
9
- `),a=!1,p=s.map((c,d)=>{if(o&&d===n)return`<div class="raw-line">${this.escapeHtml(c)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(c))return a=!a,this.applyCustomSyntax(this.parseLine(c,r));if(a){let h=this.escapeHtml(c);return`<div>${this.preserveIndentation(h,c)||"&nbsp;"}</div>`}return this.applyCustomSyntax(this.parseLine(c,r))}).join("");return this.postProcessHTML(p,i)}static postProcessHTML(e,n){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,n);let o=document.createElement("div");o.innerHTML=e;let i=null,r=null,s=null,a=!1,l=Array.from(o.children);for(let p=0;p<l.length;p++){let c=l[p];if(!c.parentNode)continue;let d=c.querySelector(".code-fence");if(d){let h=d.textContent;if(h.startsWith("```"))if(a){let f=n||this.codeHighlighter;if(s&&f&&s._codeContent)try{let m=f(s._codeContent,s._language||"");m&&typeof m.then=="function"?console.warn("Async highlighters are not supported in parse() because it returns an HTML string. The caller creates new DOM elements from that string, breaking references to the elements we would update. Use synchronous highlighters only."):m&&typeof m=="string"&&m.trim()&&(s._codeElement.innerHTML=m)}catch(m){console.warn("Code highlighting failed:",m)}a=!1,s=null;continue}else{a=!0,s=document.createElement("pre");let f=document.createElement("code");s.appendChild(f),s.className="code-block";let m=h.slice(3).trim();m&&(f.className=`language-${m}`),o.insertBefore(s,c.nextSibling),s._codeElement=f,s._language=m,s._codeContent="";continue}}if(a&&s&&c.tagName==="DIV"&&!c.querySelector(".code-fence")){let h=s._codeElement||s.querySelector("code");s._codeContent.length>0&&(s._codeContent+=`
10
- `);let f=c.textContent.replace(/\u00A0/g," ");s._codeContent+=f,h.textContent.length>0&&(h.textContent+=`
11
- `),h.textContent+=f,c.remove();continue}let u=null;if(c.tagName==="DIV"&&(u=c.querySelector("li")),u){let h=u.classList.contains("bullet-list"),f=u.classList.contains("ordered-list");if(!h&&!f){i=null,r=null;continue}let m=h?"ul":"ol";(!i||r!==m)&&(i=document.createElement(m),o.insertBefore(i,c),r=m);let g=[];for(let y of c.childNodes)if(y.nodeType===3&&y.textContent.match(/^\u00A0+$/))g.push(y.cloneNode(!0));else if(y===u)break;g.forEach(y=>{u.insertBefore(y,u.firstChild)}),i.appendChild(u),c.remove()}else i=null,r=null}return o.innerHTML}static postProcessHTMLManual(e,n){let o=e;o=o.replace(/((?:<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>/gs)||[];return s.length>0?"<ul>"+s.map(l=>{let p=l.match(/<div>((?:&nbsp;)*)<li/),c=l.match(/<li class="bullet-list">.*?<\/li>/);if(p&&c){let d=p[1];return c[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${d}`)}return c?c[0]:""}).filter(Boolean).join("")+"</ul>":r}),o=o.replace(/((?:<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>/gs)||[];return s.length>0?"<ol>"+s.map(l=>{let p=l.match(/<div>((?:&nbsp;)*)<li/),c=l.match(/<li class="ordered-list">.*?<\/li>/);if(p&&c){let d=p[1];return c[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${d}`)}return c?c[0]:""}).filter(Boolean).join("")+"</ol>":r});let i=/<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;return o=o.replace(i,(r,s,a,l)=>{let c=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(g=>g.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
12
- `),d=s.slice(3).trim(),u=d?` class="language-${d}"`:"",h=c,f=n||this.codeHighlighter;if(f)try{let g=c.replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),y=f(g,d);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(h=y)}catch(g){console.warn("Code highlighting failed:",g)}let m=`<div><span class="code-fence">${s}</span></div>`;return m+=`<pre class="code-block"><code${u}>${h}</code></pre>`,m+=`<div><span class="code-fence">${l}</span></div>`,m}),o}static getListContext(e,n){let o=e.split(`
13
- `),i=0,r=0,s=0;for(let u=0;u<o.length;u++){let h=o[u].length;if(i+h>=n){r=u,s=i;break}i+=h+1}let a=o[r],l=s+a.length,p=a.match(this.LIST_PATTERNS.checkbox);if(p)return{inList:!0,listType:"checkbox",indent:p[1],marker:"-",checked:p[2]==="x",content:p[3],lineStart:s,lineEnd:l,markerEndPos:s+p[1].length+p[2].length+5};let c=a.match(this.LIST_PATTERNS.bullet);if(c)return{inList:!0,listType:"bullet",indent:c[1],marker:c[2],content:c[3],lineStart:s,lineEnd:l,markerEndPos:s+c[1].length+c[2].length+1};let d=a.match(this.LIST_PATTERNS.numbered);return d?{inList:!0,listType:"numbered",indent:d[1],marker:parseInt(d[2]),content:d[3],lineStart:s,lineEnd:l,markerEndPos:s+d[1].length+d[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:l,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let n=e.split(`
14
- `),o=new Map,i=!1;return n.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let l=a[1],p=l.length,c=a[3];i||o.clear();let d=(o.get(p)||0)+1;o.set(p,d);for(let[u]of o)u>p&&o.delete(u);return i=!0,`${l}${d}. ${c}`}else return(s.trim()===""||!s.match(/^\s/))&&(i=!1,o.clear()),s}).join(`
15
- `)}};T(C,"linkIndex",0),T(C,"codeHighlighter",null),T(C,"customSyntax",null),T(C,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var ae=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.performAction(i,e),!0):!1}destroy(){}};var F={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#0d3b66",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",bg:"transparent"}},at={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"},previewColors:{text:"#c5dde8",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",bg:"transparent"}},lt={solar:F,cave:at,auto:F,light:F,dark:at};function U(t){return typeof t=="string"?{...lt[t]||lt.solar,name:t}:t}function qe(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t,e){let n=[];for(let[o,i]of Object.entries(t)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--${r}: ${i};`)}if(e)for(let[o,i]of Object.entries(e)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--preview-${r}-default: ${i};`)}return n.join(`
16
- `)}function ct(t,e={},n={}){return{...t,colors:{...t.colors,...e},previewColors:{...t.previewColors,...n}}}function pt(t={}){let{fontSize:e="14px",lineHeight:n=1.6,fontFamily:o='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:i="20px",theme:r=null,mobile:s={}}=t,a=Object.keys(s).length>0?`
8
+ var OverType=(()=>{var Le=Object.defineProperty;var wn=Object.getOwnPropertyDescriptor;var bn=Object.getOwnPropertyNames;var xn=Object.prototype.hasOwnProperty;var kn=(t,e,n)=>e in t?Le(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var at=(t,e)=>{for(var n in e)Le(t,n,{get:e[n],enumerable:!0})},Ln=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of bn(e))!xn.call(t,o)&&o!==n&&Le(t,o,{get:()=>e[o],enumerable:!(i=wn(e,o))||i.enumerable});return t};var Sn=t=>Ln(Le({},"__esModule",{value:!0}),t);var A=(t,e,n)=>(kn(t,typeof e!="symbol"?e+"":e,n),n);var yi={};at(yi,{OverType:()=>z,default:()=>vi,defaultToolbarButtons:()=>re,markdownActions:()=>ne,toolbarButtons:()=>S});var T=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static setCustomSyntax(e){this.customSyntax=e}static applyCustomSyntax(e){return this.customSyntax?this.customSyntax(e):e}static escapeHtml(e){let n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,i=>n[i])}static preserveIndentation(e,n){let o=n.match(/^(\s*)/)[1].replace(/ /g,"&nbsp;");return e.replace(/^\s*/,o)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(n,i,o)=>{let r=i.length;return o=this.parseInlineElements(o),`<h${r}><span class="syntax-marker">${i} </span>${o}</h${r}>`})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`<div><span class="hr-marker">${e}</span></div>`:null}static parseBlockquote(e){return e.replace(/^&gt; (.+)$/,(n,i)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${i}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*+])\s(.+)$/,(n,i,o,r)=>(r=this.parseInlineElements(r),`${i}<li class="bullet-list"><span class="syntax-marker">${o} </span>${r}</li>`))}static parseTaskList(e,n=!1){return e.replace(/^((?:&nbsp;)*)-(\s+)\[([ xX])\](\s*)(.*)$/,(i,o,r,s,a,l)=>{if(l=this.parseInlineElements(l),n){let c=s.toLowerCase()==="x";return`${o}<li class="task-list"><input type="checkbox" ${c?"checked":""}> ${l}</li>`}else return`${o}<li class="task-list"><span class="syntax-marker">-${r}[${s}]${a}</span>${l}</li>`})}static parseNumberedList(e){return e.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/,(n,i,o,r)=>(r=this.parseInlineElements(r),`${i}<li class="ordered-list"><span class="syntax-marker">${o} </span>${r}</li>`))}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`<div><span class="code-fence">${e}</span></div>`:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'<strong><span class="syntax-marker">**</span>$1<span class="syntax-marker">**</span></strong>'),e=e.replace(/__(.+?)__/g,'<strong><span class="syntax-marker">__</span>$1<span class="syntax-marker">__</span></strong>'),e}static parseItalic(e){return e=e.replace(new RegExp("(?<![\\*>])\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)","g"),'<em><span class="syntax-marker">*</span>$1<span class="syntax-marker">*</span></em>'),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?<!_)_(?!_)(?=\\s|$)","g"),'<em><span class="syntax-marker">_</span>$1<span class="syntax-marker">_</span></em>'),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?<!~)~~(?!~)(.+?)(?<!~)~~(?!~)","g"),'<del><span class="syntax-marker">~~</span>$1<span class="syntax-marker">~~</span></del>'),e=e.replace(new RegExp("(?<!~)~(?!~)(.+?)(?<!~)~(?!~)","g"),'<del><span class="syntax-marker">~</span>$1<span class="syntax-marker">~</span></del>'),e}static parseInlineCode(e){return e.replace(new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),'<code><span class="syntax-marker">$1</span>$2<span class="syntax-marker">$3</span></code>')}static sanitizeUrl(e){let n=e.trim(),i=n.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>i.startsWith(a)),s=n.startsWith("/")||n.startsWith("#")||n.startsWith("?")||n.startsWith(".")||!n.includes(":")&&!n.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(n,i,o)=>{let r=`--link-${this.linkIndex++}`;return`<a href="${this.sanitizeUrl(o)}" style="anchor-name: ${r}"><span class="syntax-marker">[</span>${i}<span class="syntax-marker url-part">](${o})</span></a>`})}static identifyAndProtectSanctuaries(e){let n=new Map,i=0,o=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let u=a.index+a[0].indexOf("](")+2,h=u+a[2].length;r.push({start:u,end:h})}let l=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),c,p=[];for(;(c=l.exec(e))!==null;){let d=c.index,u=c.index+c[0].length;r.some(f=>d>=f.start&&u<=f.end)||p.push({match:c[0],index:c.index,openTicks:c[1],content:c[2],closeTicks:c[3]})}return p.sort((d,u)=>u.index-d.index),p.forEach(d=>{let u=`\uE000${i++}\uE001`;n.set(u,{type:"code",original:d.match,openTicks:d.openTicks,content:d.content,closeTicks:d.closeTicks}),o=o.substring(0,d.index)+u+o.substring(d.index+d.match.length)}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(d,u,h)=>{let f=`\uE000${i++}\uE001`;return n.set(f,{type:"link",original:d,linkText:u,url:h}),f}),{protectedText:o,sanctuaries:n}}static restoreAndTransformSanctuaries(e,n){return Array.from(n.keys()).sort((o,r)=>{let s=e.indexOf(o),a=e.indexOf(r);return s-a}).forEach(o=>{let r=n.get(o),s;if(r.type==="code")s=`<code><span class="syntax-marker">${r.openTicks}</span>${r.content}<span class="syntax-marker">${r.closeTicks}</span></code>`;else if(r.type==="link"){let a=r.linkText;n.forEach((p,d)=>{if(a.includes(d)&&p.type==="code"){let u=`<code><span class="syntax-marker">${p.openTicks}</span>${p.content}<span class="syntax-marker">${p.closeTicks}</span></code>`;a=a.replace(d,u)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let l=`--link-${this.linkIndex++}`;s=`<a href="${this.sanitizeUrl(r.url)}" style="anchor-name: ${l}"><span class="syntax-marker">[</span>${a}<span class="syntax-marker url-part">](${r.url})</span></a>`}e=e.replace(o,s)}),e}static parseInlineElements(e){let{protectedText:n,sanctuaries:i}=this.identifyAndProtectSanctuaries(e),o=n;return o=this.parseStrikethrough(o),o=this.parseBold(o),o=this.parseItalic(o),o=this.restoreAndTransformSanctuaries(o,i),o}static parseLine(e,n=!1){let i=this.escapeHtml(e);i=this.preserveIndentation(i,e);let o=this.parseHorizontalRule(i);if(o)return o;let r=this.parseCodeBlock(i);return r||(i=this.parseHeader(i),i=this.parseBlockquote(i),i=this.parseTaskList(i,n),i=this.parseBulletList(i),i=this.parseNumberedList(i),!i.includes("<li")&&!i.includes("<h")&&(i=this.parseInlineElements(i)),i.trim()===""?"<div>&nbsp;</div>":`<div>${i}</div>`)}static parse(e,n=-1,i=!1,o,r=!1){this.resetLinkIndex();let s=e.split(`
9
+ `),a=!1,c=s.map((p,d)=>{if(i&&d===n)return`<div class="raw-line">${this.escapeHtml(p)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(p))return a=!a,this.applyCustomSyntax(this.parseLine(p,r));if(a){let h=this.escapeHtml(p);return`<div>${this.preserveIndentation(h,p)||"&nbsp;"}</div>`}return this.applyCustomSyntax(this.parseLine(p,r))}).join("");return this.postProcessHTML(c,o)}static postProcessHTML(e,n){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,n);let i=document.createElement("div");i.innerHTML=e;let o=null,r=null,s=null,a=!1,l=Array.from(i.children);for(let c=0;c<l.length;c++){let p=l[c];if(!p.parentNode)continue;let d=p.querySelector(".code-fence");if(d){let h=d.textContent;if(h.startsWith("```"))if(a){let f=n||this.codeHighlighter;if(s&&f&&s._codeContent)try{let m=f(s._codeContent,s._language||"");m&&typeof m.then=="function"?console.warn("Async highlighters are not supported in parse() because it returns an HTML string. The caller creates new DOM elements from that string, breaking references to the elements we would update. Use synchronous highlighters only."):m&&typeof m=="string"&&m.trim()&&(s._codeElement.innerHTML=m)}catch(m){console.warn("Code highlighting failed:",m)}a=!1,s=null;continue}else{a=!0,s=document.createElement("pre");let f=document.createElement("code");s.appendChild(f),s.className="code-block";let m=h.slice(3).trim();m&&(f.className=`language-${m}`),i.insertBefore(s,p.nextSibling),s._codeElement=f,s._language=m,s._codeContent="";continue}}if(a&&s&&p.tagName==="DIV"&&!p.querySelector(".code-fence")){let h=s._codeElement||s.querySelector("code");s._codeContent.length>0&&(s._codeContent+=`
10
+ `);let f=p.textContent.replace(/\u00A0/g," ");s._codeContent+=f,h.textContent.length>0&&(h.textContent+=`
11
+ `),h.textContent+=f,p.remove();continue}let u=null;if(p.tagName==="DIV"&&(u=p.querySelector("li")),u){let h=u.classList.contains("bullet-list"),f=u.classList.contains("ordered-list");if(!h&&!f){o=null,r=null;continue}let m=h?"ul":"ol";(!o||r!==m)&&(o=document.createElement(m),i.insertBefore(o,p),r=m);let v=[];for(let y of p.childNodes)if(y.nodeType===3&&y.textContent.match(/^\u00A0+$/))v.push(y.cloneNode(!0));else if(y===u)break;v.forEach(y=>{u.insertBefore(y,u.firstChild)}),o.appendChild(u),p.remove()}else o=null,r=null}return i.innerHTML}static postProcessHTMLManual(e,n){let i=e;i=i.replace(/((?:<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>/gs)||[];return s.length>0?"<ul>"+s.map(l=>{let c=l.match(/<div>((?:&nbsp;)*)<li/),p=l.match(/<li class="bullet-list">.*?<\/li>/);if(c&&p){let d=c[1];return p[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${d}`)}return p?p[0]:""}).filter(Boolean).join("")+"</ul>":r}),i=i.replace(/((?:<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>/gs)||[];return s.length>0?"<ol>"+s.map(l=>{let c=l.match(/<div>((?:&nbsp;)*)<li/),p=l.match(/<li class="ordered-list">.*?<\/li>/);if(c&&p){let d=c[1];return p[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${d}`)}return p?p[0]:""}).filter(Boolean).join("")+"</ol>":r});let o=/<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;return i=i.replace(o,(r,s,a,l)=>{let p=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(v=>v.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
12
+ `),d=s.slice(3).trim(),u=d?` class="language-${d}"`:"",h=p,f=n||this.codeHighlighter;if(f)try{let v=p.replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),y=f(v,d);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(h=y)}catch(v){console.warn("Code highlighting failed:",v)}let m=`<div><span class="code-fence">${s}</span></div>`;return m+=`<pre class="code-block"><code${u}>${h}</code></pre>`,m+=`<div><span class="code-fence">${l}</span></div>`,m}),i}static getListContext(e,n){let i=e.split(`
13
+ `),o=0,r=0,s=0;for(let u=0;u<i.length;u++){let h=i[u].length;if(o+h>=n){r=u,s=o;break}o+=h+1}let a=i[r],l=s+a.length,c=a.match(this.LIST_PATTERNS.checkbox);if(c)return{inList:!0,listType:"checkbox",indent:c[1],marker:"-",checked:c[2]==="x",content:c[3],lineStart:s,lineEnd:l,markerEndPos:s+c[1].length+c[2].length+5};let p=a.match(this.LIST_PATTERNS.bullet);if(p)return{inList:!0,listType:"bullet",indent:p[1],marker:p[2],content:p[3],lineStart:s,lineEnd:l,markerEndPos:s+p[1].length+p[2].length+1};let d=a.match(this.LIST_PATTERNS.numbered);return d?{inList:!0,listType:"numbered",indent:d[1],marker:parseInt(d[2]),content:d[3],lineStart:s,lineEnd:l,markerEndPos:s+d[1].length+d[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:l,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let n=e.split(`
14
+ `),i=new Map,o=!1;return n.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let l=a[1],c=l.length,p=a[3];o||i.clear();let d=(i.get(c)||0)+1;i.set(c,d);for(let[u]of i)u>c&&i.delete(u);return o=!0,`${l}${d}. ${p}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,i.clear()),s}).join(`
15
+ `)}};A(T,"linkIndex",0),A(T,"codeHighlighter",null),A(T,"customSyntax",null),A(T,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var ae=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;if(e.key==="]")return e.preventDefault(),this.editor.indentSelection(),!0;if(e.key==="[")return e.preventDefault(),this.editor.outdentSelection(),!0;let o=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(o="toggleBold");break;case"i":e.shiftKey||(o="toggleItalic");break;case"k":e.shiftKey||(o="insertLink");break;case"7":e.shiftKey&&(o="toggleNumberedList");break;case"8":e.shiftKey&&(o="toggleBulletList");break}return o?(e.preventDefault(),this.editor.performAction(o,e),!0):!1}destroy(){}};var D={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#0d3b66",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",bg:"transparent"}},lt={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"},previewColors:{text:"#c5dde8",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",bg:"transparent"}},ct={solar:D,cave:lt,auto:D,light:D,dark:lt};function U(t){return typeof t=="string"?{...ct[t]||ct.solar,name:t}:t}function Ke(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t,e){let n=[];for(let[i,o]of Object.entries(t)){let r=i.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--${r}: ${o};`)}if(e)for(let[i,o]of Object.entries(e)){let r=i.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--preview-${r}-default: ${o};`)}return n.join(`
16
+ `)}function pt(t,e={},n={}){return{...t,colors:{...t.colors,...e},previewColors:{...t.previewColors,...n}}}function dt(t={}){let{fontSize:e="14px",lineHeight:n=1.6,fontFamily:i='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:o="20px",theme:r=null,mobile:s={}}=t,a=Object.keys(s).length>0?`
17
17
  @media (max-width: 640px) {
18
18
  .overtype-wrapper .overtype-input,
19
19
  .overtype-wrapper .overtype-preview {
20
- ${Object.entries(s).map(([p,c])=>`${p.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${c} !important;`).join(`
20
+ ${Object.entries(s).map(([c,p])=>`${c.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${p} !important;`).join(`
21
21
  `)}
22
22
  }
23
23
  }
24
24
  `:"",l=r&&r.colors?Q(r.colors,r.previewColors):"";return`.overtype-container *{margin: 0 !important;padding: 0 !important;border: 0 !important;float: none !important;clear: none !important;text-decoration: none !important;text-transform: none !important;letter-spacing: normal !important;box-shadow: none !important;text-shadow: none !important;box-sizing: border-box !important}.overtype-container{display: flex !important;flex-direction: column !important;width: 100% !important;height: 100% !important;position: relative !important;overflow: visible !important;font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif !important;text-align: left !important;${l?`
25
25
  /* Theme Variables */
26
- ${l}`:""}}.overtype-container .overtype-wrapper *{text-align: left !important}.overtype-container.overtype-auto-resize{height: auto !important}.overtype-container.overtype-auto-resize .overtype-wrapper{flex: 0 0 auto !important;height: auto !important;min-height: 60px !important;overflow: visible !important}.overtype-wrapper{position: relative !important;width: 100% !important;flex: 1 1 0 !important;min-height: 60px !important;overflow: hidden !important;background: var(--bg-secondary,#ffffff) !important;z-index: 1}.overtype-wrapper .overtype-input,.overtype-wrapper .overtype-preview{position: absolute !important;top: 0 !important;left: 0 !important;width: 100% !important;height: 100% !important;font-family: var(--instance-font-family,${o}) !important;
26
+ ${l}`:""}}.overtype-container .overtype-wrapper *{text-align: left !important}.overtype-container.overtype-auto-resize{height: auto !important}.overtype-container.overtype-auto-resize .overtype-wrapper{flex: 0 0 auto !important;height: auto !important;min-height: 60px !important;overflow: visible !important}.overtype-wrapper{position: relative !important;width: 100% !important;flex: 1 1 0 !important;min-height: 60px !important;overflow: hidden !important;background: var(--bg-secondary,#ffffff) !important;z-index: 1}.overtype-wrapper .overtype-input,.overtype-wrapper .overtype-preview{position: absolute !important;top: 0 !important;left: 0 !important;width: 100% !important;height: 100% !important;font-family: var(--instance-font-family,${i}) !important;
27
27
  font-variant-ligatures: none !important; /* keep metrics stable for code */
28
28
  font-size: var(--instance-font-size, ${e}) !important;
29
29
  line-height: var(--instance-line-height, ${n}) !important;
@@ -35,33 +35,33 @@ var OverType=(()=>{var ke=Object.defineProperty;var yn=Object.getOwnPropertyDesc
35
35
  font-feature-settings: normal !important;
36
36
 
37
37
  /* Box model - must match exactly */
38
- padding: var(--instance-padding, ${i}) !important;margin: 0 !important;border: none !important;outline: none !important;box-sizing: border-box !important;white-space: pre-wrap !important;word-wrap: break-word !important;word-break: normal !important;overflow-wrap: break-word !important;tab-size: 2 !important;-moz-tab-size: 2 !important;text-align: left !important;text-indent: 0 !important;letter-spacing: normal !important;word-spacing: normal !important;text-transform: none !important;text-rendering: auto !important;-webkit-font-smoothing: auto !important;-webkit-text-size-adjust: 100% !important;direction: ltr !important;writing-mode: horizontal-tb !important;unicode-bidi: normal !important;text-orientation: mixed !important;text-shadow: none !important;filter: none !important;transform: none !important;zoom: 1 !important;vertical-align: baseline !important;min-width: 0 !important;min-height: 0 !important;max-width: none !important;max-height: none !important;overflow-y: auto !important;overflow-x: auto !important;scrollbar-width: auto !important;scrollbar-gutter: auto !important;animation: none !important;transition: none !important}.overtype-wrapper .overtype-input{z-index: 1 !important;color: transparent !important;caret-color: var(--cursor,#f95738) !important;background-color: transparent !important;resize: none !important;appearance: none !important;-webkit-appearance: none !important;-moz-appearance: none !important;touch-action: manipulation !important;autocomplete: off !important;autocorrect: off !important;autocapitalize: off !important}.overtype-wrapper .overtype-input::selection{background-color: var(--selection,rgba(244,211,94,0.4))}.overtype-wrapper .overtype-placeholder{position: absolute !important;top: 0 !important;left: 0 !important;width: 100% !important;z-index: 0 !important;pointer-events: none !important;user-select: none !important;font-family: var(--instance-font-family,${o}) !important;
38
+ padding: var(--instance-padding, ${o}) !important;margin: 0 !important;border: none !important;outline: none !important;box-sizing: border-box !important;white-space: pre-wrap !important;word-wrap: break-word !important;word-break: normal !important;overflow-wrap: break-word !important;tab-size: 2 !important;-moz-tab-size: 2 !important;text-align: left !important;text-indent: 0 !important;letter-spacing: normal !important;word-spacing: normal !important;text-transform: none !important;text-rendering: auto !important;-webkit-font-smoothing: auto !important;-webkit-text-size-adjust: 100% !important;direction: ltr !important;writing-mode: horizontal-tb !important;unicode-bidi: normal !important;text-orientation: mixed !important;text-shadow: none !important;filter: none !important;transform: none !important;zoom: 1 !important;vertical-align: baseline !important;min-width: 0 !important;min-height: 0 !important;max-width: none !important;max-height: none !important;overflow-y: auto !important;overflow-x: auto !important;scrollbar-width: auto !important;scrollbar-gutter: auto !important;animation: none !important;transition: none !important}.overtype-wrapper .overtype-input{z-index: 1 !important;color: transparent !important;caret-color: var(--cursor,#f95738) !important;background-color: transparent !important;resize: none !important;appearance: none !important;-webkit-appearance: none !important;-moz-appearance: none !important;touch-action: manipulation !important;autocomplete: off !important;autocorrect: off !important;autocapitalize: off !important}.overtype-wrapper .overtype-input::selection{background-color: var(--selection,rgba(244,211,94,0.4))}.overtype-wrapper .overtype-placeholder{position: absolute !important;top: 0 !important;left: 0 !important;width: 100% !important;z-index: 0 !important;pointer-events: none !important;user-select: none !important;font-family: var(--instance-font-family,${i}) !important;
39
39
  font-size: var(--instance-font-size, ${e}) !important;
40
40
  line-height: var(--instance-line-height, ${n}) !important;
41
- padding: var(--instance-padding, ${i}) !important;box-sizing: border-box !important;color: var(--placeholder,#999) !important}.overtype-wrapper .overtype-preview{z-index: 0 !important;pointer-events: none !important;color: var(--text,#0d3b66) !important;background-color: transparent !important;user-select: none !important;-webkit-user-select: none !important;-moz-user-select: none !important;-ms-user-select: none !important}.overtype-wrapper .overtype-preview *{font-family: inherit !important;font-size: inherit !important;line-height: inherit !important}.overtype-wrapper .overtype-preview div{margin: 0 !important;padding: 0 !important;border: none !important;text-align: left !important;text-indent: 0 !important;display: block !important;position: static !important;transform: none !important;min-height: 0 !important;max-height: none !important;line-height: inherit !important;font-size: inherit !important;font-family: inherit !important}.overtype-wrapper .overtype-preview .header{font-weight: bold !important}.overtype-wrapper .overtype-preview .h1{color: var(--h1,#f95738) !important}.overtype-wrapper .overtype-preview .h2{color: var(--h2,#ee964b) !important}.overtype-wrapper .overtype-preview .h3{color: var(--h3,#3d8a51) !important}.overtype-wrapper .overtype-preview h1,.overtype-wrapper .overtype-preview h2,.overtype-wrapper .overtype-preview h3{font-size: inherit !important;font-weight: bold !important;margin: 0 !important;padding: 0 !important;display: inline !important;line-height: inherit !important}.overtype-wrapper .overtype-preview h1{color: var(--h1,#f95738) !important}.overtype-wrapper .overtype-preview h2{color: var(--h2,#ee964b) !important}.overtype-wrapper .overtype-preview h3{color: var(--h3,#3d8a51) !important}.overtype-wrapper .overtype-preview ul,.overtype-wrapper .overtype-preview ol{list-style: none !important;margin: 0 !important;padding: 0 !important;display: block !important}.overtype-wrapper .overtype-preview li{display: block !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview strong{color: var(--strong,#ee964b) !important;font-weight: bold !important}.overtype-wrapper .overtype-preview em{color: var(--em,#f95738) !important;text-decoration-color: var(--em,#f95738) !important;text-decoration-thickness: 1px !important;font-style: italic !important}.overtype-wrapper .overtype-preview del{color: var(--del,#ee964b) !important;text-decoration: line-through !important;text-decoration-color: var(--del,#ee964b) !important;text-decoration-thickness: 1px !important}.overtype-wrapper .overtype-preview code{background: var(--code-bg,rgba(244,211,94,0.4)) !important;color: var(--code,#0d3b66) !important;padding: 0 !important;border-radius: 2px !important;font-family: inherit !important;font-size: inherit !important;line-height: inherit !important;font-weight: normal !important}.overtype-wrapper .overtype-preview pre{padding: 0 !important;margin: 0 !important;border-radius: 4px !important;overflow-x: auto !important}.overtype-wrapper .overtype-preview pre.code-block{background: var(--code-bg,rgba(244,211,94,0.4)) !important;white-space: break-spaces !important}.overtype-wrapper .overtype-preview pre code{background: transparent !important;color: var(--code,#0d3b66) !important;font-family: var(--instance-font-family,${o}) !important}.overtype-wrapper .overtype-preview .blockquote{color: var(--blockquote,#5a7a9b) !important;padding: 0 !important;margin: 0 !important;border: none !important}.overtype-wrapper .overtype-preview a{color: var(--link,#0d3b66) !important;text-decoration: underline !important;font-weight: normal !important}.overtype-wrapper .overtype-preview a:hover{text-decoration: underline !important;color: var(--link,#0d3b66) !important}.overtype-wrapper .overtype-preview ul,.overtype-wrapper .overtype-preview ol{list-style: none !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview hr{border: none !important;color: var(--hr,#5a7a9b) !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview .hr-marker{color: var(--hr,#5a7a9b) !important;opacity: 0.6 !important}.overtype-wrapper .overtype-preview .code-fence{color: var(--code,#0d3b66) !important;background: var(--code-bg,rgba(244,211,94,0.4)) !important}.overtype-wrapper .overtype-preview .code-block-line{background: var(--code-bg,rgba(244,211,94,0.4)) !important}.overtype-wrapper .overtype-preview .code-block-line .code-fence{background: transparent !important}.overtype-wrapper .overtype-preview .raw-line{color: var(--raw-line,#5a7a9b) !important;font-style: normal !important;font-weight: normal !important}.overtype-wrapper .overtype-preview .syntax-marker{color: var(--syntax-marker,rgba(13,59,102,0.52)) !important;opacity: 0.7 !important}.overtype-wrapper .overtype-preview .list-marker{color: var(--list-marker,#ee964b) !important}.overtype-stats{height: 40px !important;padding: 0 20px !important;background: var(--bg-secondary,#f8f9fa) !important;border-top: 1px solid var(--border,#e0e0e0) !important;display: flex !important;justify-content: space-between !important;align-items: center !important;font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif !important;font-size: 0.85rem !important;color: var(--text-secondary,#666) !important;flex-shrink: 0 !important;z-index: 10001 !important;position: relative !important}.overtype-stats .overtype-stat{display: flex !important;align-items: center !important;gap: 5px !important;white-space: nowrap !important}.overtype-stats .live-dot{width: 8px !important;height: 8px !important;background: #4caf50 !important;border-radius: 50% !important;animation: overtype-pulse 2s infinite !important}@keyframes overtype-pulse{0%,100%{opacity: 1;transform: scale(1)}50%{opacity: 0.6;transform: scale(1.2)}}.overtype-toolbar.overtype-toolbar-hidden{display: none !important}.overtype-toolbar{display: flex !important;align-items: center !important;gap: 4px !important;padding: 8px !important;background: var(--toolbar-bg,var(--bg-primary,#f8f9fa)) !important;border-bottom: 1px solid var(--toolbar-border,transparent) !important;overflow-x: auto !important;overflow-y: hidden !important;-webkit-overflow-scrolling: touch !important;flex-shrink: 0 !important;height: auto !important;position: relative !important;z-index: 100 !important;scrollbar-width: thin}.overtype-toolbar::-webkit-scrollbar{height: 4px}.overtype-toolbar::-webkit-scrollbar-track{background: transparent}.overtype-toolbar::-webkit-scrollbar-thumb{background: rgba(0,0,0,0.2);border-radius: 2px}.overtype-toolbar-button{display: flex;align-items: center;justify-content: center;width: 32px;height: 32px;padding: 0;border: none;border-radius: 6px;background: transparent;color: var(--toolbar-icon,var(--text-secondary,#666));cursor: pointer;transition: all 0.2s ease;flex-shrink: 0}.overtype-toolbar-button svg{width: 20px;height: 20px;fill: currentColor}.overtype-toolbar-button:hover{background: var(--toolbar-hover,var(--bg-secondary,#e9ecef));color: var(--toolbar-icon,var(--text-primary,#333))}.overtype-toolbar-button:active{transform: scale(0.95)}.overtype-toolbar-button.active{background: var(--toolbar-active,var(--primary,#007bff));color: var(--toolbar-icon,var(--text-primary,#333))}.overtype-toolbar-button:disabled{opacity: 0.5;cursor: not-allowed}.overtype-toolbar-separator{width: 1px;height: 24px;background: var(--border,#e0e0e0);margin: 0 4px;flex-shrink: 0}@media (max-width: 640px){.overtype-toolbar{padding: 6px;gap: 2px}.overtype-toolbar-button{width: 36px;height: 36px}.overtype-toolbar-separator{margin: 0 2px}}.overtype-container[data-mode="plain"] .overtype-preview{display: none !important}.overtype-container[data-mode="plain"] .overtype-input{color: var(--text,#0d3b66) !important;font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif !important}.overtype-container:not([data-mode="plain"]) .overtype-input{color: transparent !important}.overtype-toolbar-button{position: relative !important}.overtype-toolbar-button.dropdown-active{background: var(--toolbar-active,var(--hover-bg,#f0f0f0))}.overtype-dropdown-menu{position: fixed !important;background: var(--bg-secondary,white) !important;border: 1px solid var(--border,#e0e0e0) !important;border-radius: 6px;box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;z-index: 10000;min-width: 150px;padding: 4px 0 !important}.overtype-dropdown-item{display: flex;align-items: center;width: 100%;padding: 8px 12px;border: none;background: none;text-align: left;cursor: pointer;font-size: 14px;color: var(--text,#333);font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif}.overtype-dropdown-item:hover{background: var(--hover-bg,#f0f0f0)}.overtype-dropdown-item.active{font-weight: 600}.overtype-dropdown-check{width: 16px;margin-right: 8px;color: var(--h1,#007bff)}.overtype-dropdown-icon{width: 20px;margin-right: 8px;text-align: center}.overtype-container[data-mode="preview"] .overtype-input{display: none !important}.overtype-container[data-mode="preview"] .overtype-preview{pointer-events: auto !important;user-select: text !important;cursor: text !important}.overtype-container.overtype-auto-resize[data-mode="preview"] .overtype-preview{position: static !important;height: auto !important}.overtype-container[data-mode="preview"] .syntax-marker{display: none !important}.overtype-container[data-mode="preview"] .syntax-marker.url-part,.overtype-container[data-mode="preview"] .url-part{display: none !important}.overtype-container[data-mode="preview"] a .syntax-marker{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3{font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif !important;font-weight: 600 !important;margin: 0 !important;display: block !important;line-height: 1 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1{font-size: 2em !important;color: var(--preview-h1,var(--preview-h1-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2{font-size: 1.5em !important;color: var(--preview-h2,var(--preview-h2-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3{font-size: 1.17em !important;color: var(--preview-h3,var(--preview-h3-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview ul{display: block !important;list-style: disc !important;padding-left: 2em !important;margin: 1em 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview ol{display: block !important;list-style: decimal !important;padding-left: 2em !important;margin: 1em 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li{display: list-item !important;margin: 0 !important;padding: 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li.task-list{list-style: none !important;position: relative !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li.task-list input[type="checkbox"]{margin-right: 0.5em !important;cursor: default !important;vertical-align: middle !important}.overtype-container:not([data-mode="preview"]) .overtype-wrapper .overtype-preview li.task-list{list-style: none !important}.overtype-container:not([data-mode="preview"]) .overtype-wrapper .overtype-preview li.task-list .syntax-marker{color: var(--syntax,#999999) !important;font-weight: normal !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a{pointer-events: auto !important;cursor: pointer !important;color: var(--preview-link,var(--preview-link-default)) !important;text-decoration: underline !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block{background: var(--preview-code-bg,var(--preview-code-bg-default)) !important;color: var(--preview-code,var(--preview-code-default)) !important;padding: 1.2em !important;border-radius: 3px !important;overflow-x: auto !important;margin: 0 !important;display: block !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block code{background: transparent !important;color: inherit !important;padding: 0 !important;font-family:${o}!important;font-size: 0.9em !important;line-height: 1.4 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .code-block-line{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .code-fence{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote{display: block !important;border-left: 4px solid var(--preview-blockquote,var(--preview-blockquote-default)) !important;color: var(--preview-blockquote,var(--preview-blockquote-default)) !important;padding-left: 1em !important;margin: 1em 0 !important;font-style: italic !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview{font-family: Georgia,'Times New Roman',serif !important;font-size: 16px !important;line-height: 1.8 !important;color: var(--preview-text,var(--preview-text-default)) !important;background: var(--preview-bg,var(--preview-bg-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code{font-family:${o}!important;font-size: 0.9em !important;background: var(--preview-code-bg,var(--preview-code-bg-default)) !important;color: var(--preview-code,var(--preview-code-default)) !important;padding: 0.2em 0.4em !important;border-radius: 3px !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong{font-weight: 700 !important;color: var(--preview-strong,var(--preview-strong-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em{font-style: italic !important;color: var(--preview-em,var(--preview-em-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker{display: block !important;border-top: 2px solid var(--preview-hr,var(--preview-hr-default)) !important;text-indent: -9999px !important;height: 2px !important}.overtype-link-tooltip{background: #333 !important;color: white !important;padding: 6px 10px !important;border-radius: 16px !important;font-size: 12px !important;font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif !important;display: flex !important;visibility: hidden !important;pointer-events: none !important;z-index: 10000 !important;cursor: pointer !important;box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;max-width: 300px !important;white-space: nowrap !important;overflow: hidden !important;text-overflow: ellipsis !important;position: fixed;top: 0;left: 0}.overtype-link-tooltip.visible{visibility: visible !important;pointer-events: auto !important}${a}
42
- `}var ne={};st(ne,{applyCustomFormat:()=>Et,default:()=>In,expandSelection:()=>St,getActiveFormats:()=>Ie,getDebugMode:()=>Ze,hasFormat:()=>Lt,insertHeader:()=>de,insertLink:()=>Ae,preserveSelection:()=>bt,setDebugMode:()=>gt,setUndoMethod:()=>yt,toggleBold:()=>Ee,toggleBulletList:()=>Me,toggleCode:()=>Te,toggleH1:()=>Pe,toggleH2:()=>Oe,toggleH3:()=>_e,toggleItalic:()=>Ce,toggleNumberedList:()=>$e,toggleQuote:()=>He,toggleTaskList:()=>pe});var Sn=Object.defineProperty,dt=Object.getOwnPropertySymbols,En=Object.prototype.hasOwnProperty,Cn=Object.prototype.propertyIsEnumerable,ut=(t,e,n)=>e in t?Sn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ht=(t,e)=>{for(var n in e||(e={}))En.call(e,n)&&ut(t,n,e[n]);if(dt)for(var n of dt(e))Cn.call(e,n)&&ut(t,n,e[n]);return t},I={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function Tn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function R(t){return ht(ht({},Tn()),t)}var ce=!1;function gt(t){ce=t}function Ze(){return ce}function x(t,e,n){ce&&(console.group(`\u{1F50D} ${t}`),console.log(e),n&&console.log("Data:",n),console.groupEnd())}function Le(t,e){if(!ce)return;let n=t.value.slice(t.selectionStart,t.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Selected text:",JSON.stringify(n)),console.log("Length:",n.length);let o=t.value.slice(Math.max(0,t.selectionStart-10),t.selectionStart),i=t.value.slice(t.selectionEnd,Math.min(t.value.length,t.selectionEnd+10));console.log("Context:",JSON.stringify(o)+"[SELECTION]"+JSON.stringify(i)),console.groupEnd()}function vt(t){ce&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(t.text)),console.log("New selection:",`${t.selectionStart}-${t.selectionEnd}`),console.groupEnd())}var M=null;function N(t,{text:e,selectionStart:n,selectionEnd:o}){let i=Ze();i&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",n,"-",o)),t.focus();let r=t.selectionStart,s=t.selectionEnd,a=t.value.slice(0,r),l=t.value.slice(s);i&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(l.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(t.value.slice(r,s))));let p=t.value,c=r!==s;if(M===null||M===!0){t.contentEditable="true";try{M=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",M,"for text with",e.split(`
43
- `).length,"lines")}catch(d){M=!1,i&&console.log("execCommand threw error:",d)}t.contentEditable="false"}if(i&&(console.log("canInsertText before:",M),console.log("execCommand result:",M)),M){let d=a+e+l,u=t.value;i&&(console.log("Expected length:",d.length),console.log("Actual length:",u.length)),u!==d&&i&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(d.slice(0,100))),console.log("Actual:",JSON.stringify(u.slice(0,100))))}if(!M)if(i&&console.log("Using manual insertion"),t.value===p){i&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(d){}t.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(d){}t.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else i&&console.log("Value was changed by execCommand, skipping manual insertion");i&&console.log("Setting selection range:",n,o),n!=null&&o!=null?t.setSelectionRange(n,o):t.setSelectionRange(r,t.selectionEnd),i&&(console.log("Final value length:",t.value.length),console.groupEnd())}function yt(t){switch(t){case"native":M=!0;break;case"manual":M=!1;break;case"auto":M=null;break}}function Ke(t){return t.trim().split(`
44
- `).length>1}function An(t,e){let n=e;for(;t[n]&&t[n-1]!=null&&!t[n-1].match(/\s/);)n--;return n}function Mn(t,e,n){let o=e,i=n?/\n/:/\s/;for(;t[o]&&!t[o].match(i);)o++;return o}function wt(t){let e=t.value.split(`
45
- `),n=0;for(let o=0;o<e.length;o++){let i=e[o].length+1;t.selectionStart>=n&&t.selectionStart<n+i&&(t.selectionStart=n),t.selectionEnd>=n&&t.selectionEnd<n+i&&(o===e.length-1?t.selectionEnd=Math.min(n+e[o].length,t.value.length):t.selectionEnd=n+i-1),n+=i}}function $n(t,e,n,o=!1){if(t.selectionStart===t.selectionEnd)t.selectionStart=An(t.value,t.selectionStart),t.selectionEnd=Mn(t.value,t.selectionEnd,o);else{let i=t.selectionStart-e.length,r=t.selectionEnd+n.length,s=t.value.slice(i,t.selectionStart)===e,a=t.value.slice(t.selectionEnd,r)===n;s&&a&&(t.selectionStart=i,t.selectionEnd=r)}return t.value.slice(t.selectionStart,t.selectionEnd)}function Qe(t){let e=t.value.slice(0,t.selectionStart),n=t.value.slice(t.selectionEnd),o=e.match(/\n*$/),i=n.match(/^\n*/),r=o?o[0].length:0,s=i?i[0].length:0,a="",l="";return e.match(/\S/)&&r<2&&(a=`
41
+ padding: var(--instance-padding, ${o}) !important;box-sizing: border-box !important;color: var(--placeholder,#999) !important}.overtype-wrapper .overtype-preview{z-index: 0 !important;pointer-events: none !important;color: var(--text,#0d3b66) !important;background-color: transparent !important;user-select: none !important;-webkit-user-select: none !important;-moz-user-select: none !important;-ms-user-select: none !important}.overtype-wrapper .overtype-preview *{font-family: inherit !important;font-size: inherit !important;line-height: inherit !important}.overtype-wrapper .overtype-preview div{margin: 0 !important;padding: 0 !important;border: none !important;text-align: left !important;text-indent: 0 !important;display: block !important;position: static !important;transform: none !important;min-height: 0 !important;max-height: none !important;line-height: inherit !important;font-size: inherit !important;font-family: inherit !important}.overtype-wrapper .overtype-preview .header{font-weight: bold !important}.overtype-wrapper .overtype-preview .h1{color: var(--h1,#f95738) !important}.overtype-wrapper .overtype-preview .h2{color: var(--h2,#ee964b) !important}.overtype-wrapper .overtype-preview .h3{color: var(--h3,#3d8a51) !important}.overtype-wrapper .overtype-preview h1,.overtype-wrapper .overtype-preview h2,.overtype-wrapper .overtype-preview h3{font-size: inherit !important;font-weight: bold !important;margin: 0 !important;padding: 0 !important;display: inline !important;line-height: inherit !important}.overtype-wrapper .overtype-preview h1{color: var(--h1,#f95738) !important}.overtype-wrapper .overtype-preview h2{color: var(--h2,#ee964b) !important}.overtype-wrapper .overtype-preview h3{color: var(--h3,#3d8a51) !important}.overtype-wrapper .overtype-preview ul,.overtype-wrapper .overtype-preview ol{list-style: none !important;margin: 0 !important;padding: 0 !important;display: block !important}.overtype-wrapper .overtype-preview li{display: block !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview strong{color: var(--strong,#ee964b) !important;font-weight: bold !important}.overtype-wrapper .overtype-preview em{color: var(--em,#f95738) !important;text-decoration-color: var(--em,#f95738) !important;text-decoration-thickness: 1px !important;font-style: italic !important}.overtype-wrapper .overtype-preview del{color: var(--del,#ee964b) !important;text-decoration: line-through !important;text-decoration-color: var(--del,#ee964b) !important;text-decoration-thickness: 1px !important}.overtype-wrapper .overtype-preview code{background: var(--code-bg,rgba(244,211,94,0.4)) !important;color: var(--code,#0d3b66) !important;padding: 0 !important;border-radius: 2px !important;font-family: inherit !important;font-size: inherit !important;line-height: inherit !important;font-weight: normal !important}.overtype-wrapper .overtype-preview pre{padding: 0 !important;margin: 0 !important;border-radius: 4px !important;overflow-x: auto !important}.overtype-wrapper .overtype-preview pre.code-block{background: var(--code-bg,rgba(244,211,94,0.4)) !important;white-space: break-spaces !important}.overtype-wrapper .overtype-preview pre code{background: transparent !important;color: var(--code,#0d3b66) !important;font-family: var(--instance-font-family,${i}) !important}.overtype-wrapper .overtype-preview .blockquote{color: var(--blockquote,#5a7a9b) !important;padding: 0 !important;margin: 0 !important;border: none !important}.overtype-wrapper .overtype-preview a{color: var(--link,#0d3b66) !important;text-decoration: underline !important;font-weight: normal !important}.overtype-wrapper .overtype-preview a:hover{text-decoration: underline !important;color: var(--link,#0d3b66) !important}.overtype-wrapper .overtype-preview ul,.overtype-wrapper .overtype-preview ol{list-style: none !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview hr{border: none !important;color: var(--hr,#5a7a9b) !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview .hr-marker{color: var(--hr,#5a7a9b) !important;opacity: 0.6 !important}.overtype-wrapper .overtype-preview .code-fence{color: var(--code,#0d3b66) !important;background: var(--code-bg,rgba(244,211,94,0.4)) !important}.overtype-wrapper .overtype-preview .code-block-line{background: var(--code-bg,rgba(244,211,94,0.4)) !important}.overtype-wrapper .overtype-preview .code-block-line .code-fence{background: transparent !important}.overtype-wrapper .overtype-preview .raw-line{color: var(--raw-line,#5a7a9b) !important;font-style: normal !important;font-weight: normal !important}.overtype-wrapper .overtype-preview .syntax-marker{color: var(--syntax-marker,rgba(13,59,102,0.52)) !important;opacity: 0.7 !important}.overtype-wrapper .overtype-preview .list-marker{color: var(--list-marker,#ee964b) !important}.overtype-stats{height: 40px !important;padding: 0 20px !important;background: var(--bg-secondary,#f8f9fa) !important;border-top: 1px solid var(--border,#e0e0e0) !important;display: flex !important;justify-content: space-between !important;align-items: center !important;font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif !important;font-size: 0.85rem !important;color: var(--text-secondary,#666) !important;flex-shrink: 0 !important;z-index: 10001 !important;position: relative !important}.overtype-stats .overtype-stat{display: flex !important;align-items: center !important;gap: 5px !important;white-space: nowrap !important}.overtype-stats .live-dot{width: 8px !important;height: 8px !important;background: #4caf50 !important;border-radius: 50% !important;animation: overtype-pulse 2s infinite !important}@keyframes overtype-pulse{0%,100%{opacity: 1;transform: scale(1)}50%{opacity: 0.6;transform: scale(1.2)}}.overtype-toolbar.overtype-toolbar-hidden{display: none !important}.overtype-toolbar{display: flex !important;align-items: center !important;gap: 4px !important;padding: 8px !important;background: var(--toolbar-bg,var(--bg-primary,#f8f9fa)) !important;border-bottom: 1px solid var(--toolbar-border,transparent) !important;overflow-x: auto !important;overflow-y: hidden !important;-webkit-overflow-scrolling: touch !important;flex-shrink: 0 !important;height: auto !important;position: relative !important;z-index: 100 !important;scrollbar-width: thin}.overtype-toolbar::-webkit-scrollbar{height: 4px}.overtype-toolbar::-webkit-scrollbar-track{background: transparent}.overtype-toolbar::-webkit-scrollbar-thumb{background: rgba(0,0,0,0.2);border-radius: 2px}.overtype-toolbar-button{display: flex;align-items: center;justify-content: center;width: 32px;height: 32px;padding: 0;border: none;border-radius: 6px;background: transparent;color: var(--toolbar-icon,var(--text-secondary,#666));cursor: pointer;transition: all 0.2s ease;flex-shrink: 0}.overtype-toolbar-button svg{width: 20px;height: 20px;fill: currentColor}.overtype-toolbar-button:hover{background: var(--toolbar-hover,var(--bg-secondary,#e9ecef));color: var(--toolbar-icon,var(--text-primary,#333))}.overtype-toolbar-button:active{transform: scale(0.95)}.overtype-toolbar-button.active{background: var(--toolbar-active,var(--primary,#007bff));color: var(--toolbar-icon,var(--text-primary,#333))}.overtype-toolbar-button:disabled{opacity: 0.5;cursor: not-allowed}.overtype-toolbar-separator{width: 1px;height: 24px;background: var(--border,#e0e0e0);margin: 0 4px;flex-shrink: 0}@media (max-width: 640px){.overtype-toolbar{padding: 6px;gap: 2px}.overtype-toolbar-button{width: 36px;height: 36px}.overtype-toolbar-separator{margin: 0 2px}}.overtype-container[data-mode="plain"] .overtype-preview{display: none !important}.overtype-container[data-mode="plain"] .overtype-input{color: var(--text,#0d3b66) !important;font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif !important}.overtype-container:not([data-mode="plain"]) .overtype-input{color: transparent !important}.overtype-toolbar-button{position: relative !important}.overtype-toolbar-button.dropdown-active{background: var(--toolbar-active,var(--hover-bg,#f0f0f0))}.overtype-dropdown-menu{position: fixed !important;background: var(--bg-secondary,white) !important;border: 1px solid var(--border,#e0e0e0) !important;border-radius: 6px;box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;z-index: 10000;min-width: 150px;padding: 4px 0 !important}.overtype-dropdown-item{display: flex;align-items: center;width: 100%;padding: 8px 12px;border: none;background: none;text-align: left;cursor: pointer;font-size: 14px;color: var(--text,#333);font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif}.overtype-dropdown-item:hover{background: var(--hover-bg,#f0f0f0)}.overtype-dropdown-item.active{font-weight: 600}.overtype-dropdown-check{width: 16px;margin-right: 8px;color: var(--h1,#007bff)}.overtype-dropdown-icon{width: 20px;margin-right: 8px;text-align: center}.overtype-container[data-mode="preview"] .overtype-input{display: none !important}.overtype-container[data-mode="preview"] .overtype-preview{pointer-events: auto !important;user-select: text !important;cursor: text !important}.overtype-container.overtype-auto-resize[data-mode="preview"] .overtype-preview{position: static !important;height: auto !important}.overtype-container[data-mode="preview"] .syntax-marker{display: none !important}.overtype-container[data-mode="preview"] .syntax-marker.url-part,.overtype-container[data-mode="preview"] .url-part{display: none !important}.overtype-container[data-mode="preview"] a .syntax-marker{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3{font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif !important;font-weight: 600 !important;margin: 0 !important;display: block !important;line-height: 1 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1{font-size: 2em !important;color: var(--preview-h1,var(--preview-h1-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2{font-size: 1.5em !important;color: var(--preview-h2,var(--preview-h2-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3{font-size: 1.17em !important;color: var(--preview-h3,var(--preview-h3-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview ul{display: block !important;list-style: disc !important;padding-left: 2em !important;margin: 1em 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview ol{display: block !important;list-style: decimal !important;padding-left: 2em !important;margin: 1em 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li{display: list-item !important;margin: 0 !important;padding: 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li.task-list{list-style: none !important;position: relative !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li.task-list input[type="checkbox"]{margin-right: 0.5em !important;cursor: default !important;vertical-align: middle !important}.overtype-container:not([data-mode="preview"]) .overtype-wrapper .overtype-preview li.task-list{list-style: none !important}.overtype-container:not([data-mode="preview"]) .overtype-wrapper .overtype-preview li.task-list .syntax-marker{color: var(--syntax,#999999) !important;font-weight: normal !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a{pointer-events: auto !important;cursor: pointer !important;color: var(--preview-link,var(--preview-link-default)) !important;text-decoration: underline !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block{background: var(--preview-code-bg,var(--preview-code-bg-default)) !important;color: var(--preview-code,var(--preview-code-default)) !important;padding: 1.2em !important;border-radius: 3px !important;overflow-x: auto !important;margin: 0 !important;display: block !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block code{background: transparent !important;color: inherit !important;padding: 0 !important;font-family:${i}!important;font-size: 0.9em !important;line-height: 1.4 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .code-block-line{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .code-fence{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote{display: block !important;border-left: 4px solid var(--preview-blockquote,var(--preview-blockquote-default)) !important;color: var(--preview-blockquote,var(--preview-blockquote-default)) !important;padding-left: 1em !important;margin: 1em 0 !important;font-style: italic !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview{font-family: Georgia,'Times New Roman',serif !important;font-size: 16px !important;line-height: 1.8 !important;color: var(--preview-text,var(--preview-text-default)) !important;background: var(--preview-bg,var(--preview-bg-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code{font-family:${i}!important;font-size: 0.9em !important;background: var(--preview-code-bg,var(--preview-code-bg-default)) !important;color: var(--preview-code,var(--preview-code-default)) !important;padding: 0.2em 0.4em !important;border-radius: 3px !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong{font-weight: 700 !important;color: var(--preview-strong,var(--preview-strong-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em{font-style: italic !important;color: var(--preview-em,var(--preview-em-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker{display: block !important;border-top: 2px solid var(--preview-hr,var(--preview-hr-default)) !important;text-indent: -9999px !important;height: 2px !important}.overtype-link-tooltip{background: #333 !important;color: white !important;padding: 6px 10px !important;border-radius: 16px !important;font-size: 12px !important;font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif !important;display: flex !important;visibility: hidden !important;pointer-events: none !important;z-index: 10000 !important;cursor: pointer !important;box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;max-width: 300px !important;white-space: nowrap !important;overflow: hidden !important;text-overflow: ellipsis !important;position: fixed;top: 0;left: 0}.overtype-link-tooltip.visible{visibility: visible !important;pointer-events: auto !important}${a}
42
+ `}var ne={};at(ne,{applyCustomFormat:()=>Tt,default:()=>Rn,expandSelection:()=>Et,getActiveFormats:()=>Re,getDebugMode:()=>Qe,hasFormat:()=>St,insertHeader:()=>de,insertLink:()=>Ie,preserveSelection:()=>xt,setDebugMode:()=>vt,setUndoMethod:()=>wt,toggleBold:()=>Te,toggleBulletList:()=>Me,toggleCode:()=>Ce,toggleH1:()=>He,toggleH2:()=>$e,toggleH3:()=>Oe,toggleItalic:()=>Ae,toggleNumberedList:()=>_e,toggleQuote:()=>Pe,toggleTaskList:()=>pe});var En=Object.defineProperty,ut=Object.getOwnPropertySymbols,Tn=Object.prototype.hasOwnProperty,An=Object.prototype.propertyIsEnumerable,ht=(t,e,n)=>e in t?En(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ft=(t,e)=>{for(var n in e||(e={}))Tn.call(e,n)&&ht(t,n,e[n]);if(ut)for(var n of ut(e))An.call(e,n)&&ht(t,n,e[n]);return t},O={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function Cn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function R(t){return ft(ft({},Cn()),t)}var ce=!1;function vt(t){ce=t}function Qe(){return ce}function x(t,e,n){ce&&(console.group(`\u{1F50D} ${t}`),console.log(e),n&&console.log("Data:",n),console.groupEnd())}function Se(t,e){if(!ce)return;let n=t.value.slice(t.selectionStart,t.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Selected text:",JSON.stringify(n)),console.log("Length:",n.length);let i=t.value.slice(Math.max(0,t.selectionStart-10),t.selectionStart),o=t.value.slice(t.selectionEnd,Math.min(t.value.length,t.selectionEnd+10));console.log("Context:",JSON.stringify(i)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function yt(t){ce&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(t.text)),console.log("New selection:",`${t.selectionStart}-${t.selectionEnd}`),console.groupEnd())}var I=null;function F(t,{text:e,selectionStart:n,selectionEnd:i}){let o=Qe();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",n,"-",i)),t.focus();let r=t.selectionStart,s=t.selectionEnd,a=t.value.slice(0,r),l=t.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(l.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(t.value.slice(r,s))));let c=t.value,p=r!==s;if(I===null||I===!0){t.contentEditable="true";try{I=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",I,"for text with",e.split(`
43
+ `).length,"lines")}catch(d){I=!1,o&&console.log("execCommand threw error:",d)}t.contentEditable="false"}if(o&&(console.log("canInsertText before:",I),console.log("execCommand result:",I)),I){let d=a+e+l,u=t.value;o&&(console.log("Expected length:",d.length),console.log("Actual length:",u.length)),u!==d&&o&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(d.slice(0,100))),console.log("Actual:",JSON.stringify(u.slice(0,100))))}if(!I)if(o&&console.log("Using manual insertion"),t.value===c){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(d){}t.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(d){}t.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else o&&console.log("Value was changed by execCommand, skipping manual insertion");o&&console.log("Setting selection range:",n,i),n!=null&&i!=null?t.setSelectionRange(n,i):t.setSelectionRange(r,t.selectionEnd),o&&(console.log("Final value length:",t.value.length),console.groupEnd())}function wt(t){switch(t){case"native":I=!0;break;case"manual":I=!1;break;case"auto":I=null;break}}function Ze(t){return t.trim().split(`
44
+ `).length>1}function In(t,e){let n=e;for(;t[n]&&t[n-1]!=null&&!t[n-1].match(/\s/);)n--;return n}function Mn(t,e,n){let i=e,o=n?/\n/:/\s/;for(;t[i]&&!t[i].match(o);)i++;return i}function bt(t){let e=t.value.split(`
45
+ `),n=0;for(let i=0;i<e.length;i++){let o=e[i].length+1;t.selectionStart>=n&&t.selectionStart<n+o&&(t.selectionStart=n),t.selectionEnd>=n&&t.selectionEnd<n+o&&(i===e.length-1?t.selectionEnd=Math.min(n+e[i].length,t.value.length):t.selectionEnd=n+o-1),n+=o}}function _n(t,e,n,i=!1){if(t.selectionStart===t.selectionEnd)t.selectionStart=In(t.value,t.selectionStart),t.selectionEnd=Mn(t.value,t.selectionEnd,i);else{let o=t.selectionStart-e.length,r=t.selectionEnd+n.length,s=t.value.slice(o,t.selectionStart)===e,a=t.value.slice(t.selectionEnd,r)===n;s&&a&&(t.selectionStart=o,t.selectionEnd=r)}return t.value.slice(t.selectionStart,t.selectionEnd)}function Je(t){let e=t.value.slice(0,t.selectionStart),n=t.value.slice(t.selectionEnd),i=e.match(/\n*$/),o=n.match(/^\n*/),r=i?i[0].length:0,s=o?o[0].length:0,a="",l="";return e.match(/\S/)&&r<2&&(a=`
46
46
  `.repeat(2-r)),n.match(/\S/)&&s<2&&(l=`
47
- `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function bt(t,e){let n=t.selectionStart,o=t.selectionEnd,i=t.scrollTop;e(),t.selectionStart=n,t.selectionEnd=o,t.scrollTop=i}function Se(t,e,n={}){let o=t.selectionStart,i=t.selectionEnd,r=o===i,s=t.value,a=o;for(;a>0&&s[a-1]!==`
48
- `;)a--;if(r){let p=o;for(;p<s.length&&s[p]!==`
49
- `;)p++;t.selectionStart=a,t.selectionEnd=p}else wt(t);let l=e(t);if(n.adjustSelection){let c=t.value.slice(t.selectionStart,t.selectionEnd).startsWith(n.prefix),d=n.adjustSelection(c,o,i,a);l.selectionStart=d.start,l.selectionEnd=d.end}else if(n.prefix){let c=t.value.slice(t.selectionStart,t.selectionEnd).startsWith(n.prefix);r?c?(l.selectionStart=Math.max(o-n.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=o+n.prefix.length,l.selectionEnd=l.selectionStart):c?(l.selectionStart=Math.max(o-n.prefix.length,a),l.selectionEnd=Math.max(i-n.prefix.length,a)):(l.selectionStart=o+n.prefix.length,l.selectionEnd=i+n.prefix.length)}return l}function te(t,e){let n,o,{prefix:i,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:p,scanFor:c,surroundWithNewlines:d,trimFirst:u}=e,h=t.selectionStart,f=t.selectionEnd,m=t.value.slice(t.selectionStart,t.selectionEnd),g=Ke(m)&&s&&s.length>0?`${s}
50
- `:i,y=Ke(m)&&a&&a.length>0?`
51
- ${a}`:r;if(p){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!k.match(/\s/)&&(g=` ${g}`)}m=$n(t,g,y,e.multiline);let w=t.selectionStart,b=t.selectionEnd,L=l&&l.length>0&&y.indexOf(l)>-1&&m.length>0;if(d){let k=Qe(t);n=k.newlinesToAppend,o=k.newlinesToPrepend,g=n+i,y+=o}if(m.startsWith(g)&&m.endsWith(y)){let k=m.slice(g.length,m.length-y.length);if(h===f){let E=h-g.length;E=Math.max(E,w),E=Math.min(E,w+k.length),w=b=E}else b=w+k.length;return{text:k,selectionStart:w,selectionEnd:b}}else if(L)if(c&&c.length>0&&m.match(c)){y=y.replace(l,m);let k=g+y;return w=b=w+g.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=g+m+y;return w=w+g.length+m.length+y.indexOf(l),b=w+l.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=g+m+y;w=h+g.length,b=f+g.length;let E=m.match(/^\s*|\s*$/g);if(u&&E){let be=E[0]||"",Y=E[1]||"";k=be+g+m.trim()+y+Y,w+=be.length,b-=Y.length}return{text:k,selectionStart:w,selectionEnd:b}}}function Je(t,e){let{prefix:n,suffix:o,surroundWithNewlines:i}=e,r=t.value.slice(t.selectionStart,t.selectionEnd),s=t.selectionStart,a=t.selectionEnd,l=r.split(`
52
- `);if(l.every(c=>c.startsWith(n)&&(!o||c.endsWith(o))))r=l.map(c=>{let d=c.slice(n.length);return o&&(d=d.slice(0,d.length-o.length)),d}).join(`
53
- `),a=s+r.length;else if(r=l.map(c=>n+c+(o||"")).join(`
54
- `),i){let{newlinesToAppend:c,newlinesToPrepend:d}=Qe(t);s+=c.length,a=s+r.length,r=c+r+d}return{text:r,selectionStart:s,selectionEnd:a}}function ft(t){let e=t.split(`
55
- `),n=/^\d+\.\s+/,o=e.every(r=>n.test(r)),i=e;return o&&(i=e.map(r=>r.replace(n,""))),{text:i.join(`
56
- `),processed:o}}function mt(t){let e=t.split(`
57
- `),n="- ",o=e.every(r=>r.startsWith(n)),i=e;return o&&(i=e.map(r=>r.slice(n.length))),{text:i.join(`
58
- `),processed:o}}function le(t,e){return e?"- ":`${t+1}. `}function Hn(t,e){let n,o,i;return t.orderedList?(n=ft(e),o=mt(n.text),i=o.text):(n=mt(e),o=ft(n.text),i=o.text),[n,o,i]}function Pn(t,e){let n=t.selectionStart===t.selectionEnd,o=t.selectionStart,i=t.selectionEnd;wt(t);let r=t.value.slice(t.selectionStart,t.selectionEnd),[s,a,l]=Hn(e,r),p=l.split(`
59
- `).map((m,g)=>`${le(g,e.unorderedList)}${m}`),c=p.reduce((m,g,y)=>m+le(y,e.unorderedList).length,0),d=p.reduce((m,g,y)=>m+le(y,!e.unorderedList).length,0);if(s.processed)return n?(o=Math.max(o-le(0,e.unorderedList).length,0),i=o):(o=t.selectionStart,i=t.selectionEnd-c),{text:l,selectionStart:o,selectionEnd:i};let{newlinesToAppend:u,newlinesToPrepend:h}=Qe(t),f=u+p.join(`
60
- `)+h;return n?(o=Math.max(o+le(0,e.unorderedList).length+u.length,0),i=o):a.processed?(o=Math.max(t.selectionStart+u.length,0),i=t.selectionEnd+u.length+c-d):(o=Math.max(t.selectionStart+u.length,0),i=t.selectionEnd+u.length+c),{text:f,selectionStart:o,selectionEnd:i}}function xt(t,e){let n=Se(t,o=>Pn(o,e),{adjustSelection:(o,i,r,s)=>{let a=t.value.slice(s,t.selectionEnd),l=/^\d+\.\s+/,p=/^- /,c=l.test(a),d=p.test(a),u=e.orderedList&&c||e.unorderedList&&d;if(i===r)if(u){let h=a.match(e.orderedList?l:p),f=h?h[0].length:0;return{start:Math.max(i-f,s),end:Math.max(i-f,s)}}else if(c||d){let h=a.match(c?l:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:i+g}}else{let h=e.unorderedList?2:3;return{start:i+h,end:i+h}}else if(u){let h=a.match(e.orderedList?l:p),f=h?h[0].length:0;return{start:Math.max(i-f,s),end:Math.max(r-f,s)}}else if(c||d){let h=a.match(c?l:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:r+g}}else{let h=e.unorderedList?2:3;return{start:i+h,end:r+h}}}});N(t,n)}function kt(t){if(!t)return[];let e=[],{selectionStart:n,selectionEnd:o,value:i}=t,r=i.split(`
61
- `),s=0,a="";for(let d of r){if(n>=s&&n<=s+d.length){a=d;break}s+=d.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let l=Math.max(0,n-10),p=Math.min(i.length,o+10),c=i.slice(l,p);if(c.includes("**")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(c.includes("_")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(c.includes("`")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100));d.includes("`")&&u.includes("`")&&e.push("code")}if(c.includes("[")&&c.includes("]")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&i.slice(o+f+1,o+f+10).startsWith("(")&&e.push("link")}return e}function On(t,e){return kt(t).includes(e)}function _n(t,e={}){if(!t)return;let{toWord:n,toLine:o,toFormat:i}=e,{selectionStart:r,selectionEnd:s,value:a}=t;if(o){let l=a.split(`
62
- `),p=0,c=0,d=0;for(let u of l){if(r>=d&&r<=d+u.length){p=d,c=d+u.length;break}d+=u.length+1}t.selectionStart=p,t.selectionEnd=c}else if(n&&r===s){let l=r,p=s;for(;l>0&&!/\s/.test(a[l-1]);)l--;for(;p<a.length&&!/\s/.test(a[p]);)p++;t.selectionStart=l,t.selectionEnd=p}}function Ee(t){if(!t||t.disabled||t.readOnly)return;x("toggleBold","Starting"),Le(t,"Before");let e=R(I.bold),n=te(t,e);vt(n),N(t,n),Le(t,"After")}function Ce(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.italic),n=te(t,e);N(t,n)}function Te(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.code),n=te(t,e);N(t,n)}function Ae(t,e={}){if(!t||t.disabled||t.readOnly)return;let n=t.value.slice(t.selectionStart,t.selectionEnd),o=R(I.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${n})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!n){let s=t.selectionStart;t.value=t.value.slice(0,s)+e.text+t.value.slice(s),t.selectionStart=s,t.selectionEnd=s+e.text.length}let r=te(t,o);N(t,r)}function Me(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.bulletList);xt(t,e)}function $e(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.numberedList);xt(t,e)}function He(t){if(!t||t.disabled||t.readOnly)return;x("toggleQuote","Starting"),Le(t,"Initial");let e=R(I.quote),n=Se(t,o=>Je(o,e),{prefix:e.prefix});vt(n),N(t,n),Le(t,"Final")}function pe(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.taskList),n=Se(t,o=>Je(o,e),{prefix:e.prefix});N(t,n)}function de(t,e=1,n=!1){if(!t||t.disabled||t.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${n}`),x("insertHeader",`Initial cursor: ${t.selectionStart}-${t.selectionEnd}`);let o=`header${e===1?"1":e}`,i=R(I[o]||I.header1);x("insertHeader",`Style prefix: "${i.prefix}"`);let r=t.value,s=t.selectionStart,a=t.selectionEnd,l=s;for(;l>0&&r[l-1]!==`
63
- `;)l--;let p=a;for(;p<r.length&&r[p]!==`
64
- `;)p++;let c=r.slice(l,p);x("insertHeader",`Current line (before): "${c}"`);let d=c.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=n&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${n}, existingLevel=${u}, level=${e})`);let m=Se(t,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let w=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${w}"`);let b;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),b=w):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),b=i.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=i.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-h,b);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:L,end:y===w?L:Math.max(w-h,b)}}else if(h>0){let L=i.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:y+i.prefix.length,end:w+i.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),N(t,m)}function Pe(t){de(t,1,!0)}function Oe(t){de(t,2,!0)}function _e(t){de(t,3,!0)}function Ie(t){return kt(t)}function Lt(t,e){return On(t,e)}function St(t,e={}){_n(t,e)}function Et(t,e){if(!t||t.disabled||t.readOnly)return;let n=R(e),o;if(n.multiline){let i=t.value.slice(t.selectionStart,t.selectionEnd);Ke(i)?o=Je(t,n):o=te(t,n)}else o=te(t,n);N(t,o)}var In={toggleBold:Ee,toggleItalic:Ce,toggleCode:Te,insertLink:Ae,toggleBulletList:Me,toggleNumberedList:$e,toggleQuote:He,toggleTaskList:pe,insertHeader:de,toggleH1:Pe,toggleH2:Oe,toggleH3:_e,getActiveFormats:Ie,hasFormat:Lt,expandSelection:St,applyCustomFormat:Et,preserveSelection:bt,setUndoMethod:yt,setDebugMode:gt,getDebugMode:Ze};var Re=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=n.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.addEventListener("click",o=>{o.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=o=>{o.preventDefault();let i=e.actionId||e.name;this.editor.performAction(i,o)},n.addEventListener("click",n._clickHandler),n)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let n=document.querySelector(".overtype-dropdown-menu");if(n){n.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let o=this.createViewModeDropdown(e),i=e.getBoundingClientRect();o.style.position="absolute",o.style.top=`${i.bottom+5}px`,o.style.left=`${i.left}px`,document.body.appendChild(o),this.handleDocumentClick=r=>{!o.contains(r.target)&&!e.contains(r.target)&&(o.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu";let o=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],i=this.editor.container.dataset.mode||"normal";return o.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),n.appendChild(s)}),n}updateButtonStates(){var e;try{let n=((e=Ie)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([o,i])=>{if(o==="viewMode")return;let r=!1;switch(o){case"bold":r=n.includes("bold");break;case"italic":r=n.includes("italic");break;case"code":r=!1;break;case"bulletList":r=n.includes("bullet-list");break;case"orderedList":r=n.includes("numbered-list");break;case"taskList":r=n.includes("task-list");break;case"quote":r=n.includes("quote");break;case"h1":r=n.includes("header");break;case"h2":r=n.includes("header-2");break;case"h3":r=n.includes("header-3");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(n){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var he=Math.min,W=Math.max,fe=Math.round;var O=t=>({x:t,y:t}),Rn={left:"right",right:"left",bottom:"top",top:"bottom"},Bn={start:"end",end:"start"};function Xe(t,e,n){return W(t,he(e,n))}function me(t,e){return typeof t=="function"?t(e):t}function q(t){return t.split("-")[0]}function ge(t){return t.split("-")[1]}function Ge(t){return t==="x"?"y":"x"}function Ye(t){return t==="y"?"height":"width"}var Fn=new Set(["top","bottom"]);function D(t){return Fn.has(q(t))?"y":"x"}function et(t){return Ge(D(t))}function At(t,e,n){n===void 0&&(n=!1);let o=ge(t),i=et(t),r=Ye(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ue(s)),[s,ue(s)]}function Mt(t){let e=ue(t);return[Be(t),e,Be(e)]}function Be(t){return t.replace(/start|end/g,e=>Bn[e])}var Ct=["left","right"],Tt=["right","left"],Nn=["top","bottom"],Dn=["bottom","top"];function zn(t,e,n){switch(t){case"top":case"bottom":return n?e?Tt:Ct:e?Ct:Tt;case"left":case"right":return e?Nn:Dn;default:return[]}}function $t(t,e,n,o){let i=ge(t),r=zn(q(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(Be)))),r}function ue(t){return t.replace(/left|right|bottom|top/g,e=>Rn[e])}function jn(t){return{top:0,right:0,bottom:0,left:0,...t}}function Ht(t){return typeof t!="number"?jn(t):{top:t,right:t,bottom:t,left:t}}function J(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Pt(t,e,n){let{reference:o,floating:i}=t,r=D(e),s=et(e),a=Ye(s),l=q(e),p=r==="y",c=o.x+o.width/2-i.width/2,d=o.y+o.height/2-i.height/2,u=o[a]/2-i[a]/2,h;switch(l){case"top":h={x:c,y:o.y-i.height};break;case"bottom":h={x:c,y:o.y+o.height};break;case"right":h={x:o.x+o.width,y:d};break;case"left":h={x:o.x-i.width,y:d};break;default:h={x:o.x,y:o.y}}switch(ge(e)){case"start":h[s]-=u*(n&&p?-1:1);break;case"end":h[s]+=u*(n&&p?-1:1);break}return h}async function Ot(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:a,strategy:l}=t,{boundary:p="clippingAncestors",rootBoundary:c="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=me(e,t),f=Ht(h),g=a[u?d==="floating"?"reference":"floating":d],y=J(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(g)))==null||n?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:p,rootBoundary:c,strategy:l})),w=d==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=J(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:l}):w);return{top:(y.top-k.top+f.top)/L.y,bottom:(k.bottom-y.bottom+f.bottom)/L.y,left:(y.left-k.left+f.left)/L.x,right:(k.right-y.right+f.right)/L.x}}var _t=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:c,y:d}=Pt(p,o,l),u=o,h={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:w}=a[g],{x:b,y:L,data:k,reset:E}=await w({x:c,y:d,initialPlacement:o,placement:u,strategy:i,middlewareData:h,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Ot},elements:{reference:t,floating:e}});c=b!=null?b:c,d=L!=null?L:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):E.rects),{x:c,y:d}=Pt(p,u,l)),g=-1)}return{x:c,y:d,placement:u,strategy:i,middlewareData:h}};var It=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:a,platform:l,elements:p}=e,{mainAxis:c=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=me(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let y=q(i),w=D(a),b=q(a)===a,L=await(l.isRTL==null?void 0:l.isRTL(p.floating)),k=u||(b||!m?[ue(a)]:Mt(a)),E=f!=="none";!u&&E&&k.push(...$t(a,m,f,L));let be=[a,...k],Y=await l.detectOverflow(e,g),xe=[],ee=((o=r.flip)==null?void 0:o.overflows)||[];if(c&&xe.push(Y[y]),d){let K=At(i,s,L);xe.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:i,overflows:xe}],!xe.every(K=>K<=0)){var ot,it;let K=(((ot=r.flip)==null?void 0:ot.index)||0)+1,We=be[K];if(We&&(!(d==="alignment"?w!==D(We):!1)||ee.every(P=>D(P.placement)===w?P.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:We}};let se=(it=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,P)=>Z.overflows[1]-P.overflows[1])[0])==null?void 0:it.placement;if(!se)switch(h){case"bestFit":{var rt;let Z=(rt=ee.filter(P=>{if(E){let V=D(P.placement);return V===w||V==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(V=>V>0).reduce((V,vn)=>V+vn,0)]).sort((P,V)=>P[1]-V[1])[0])==null?void 0:rt[0];Z&&(se=Z);break}case"initialPlacement":se=a;break}if(i!==se)return{reset:{placement:se}}}return{}}}};var Vn=new Set(["left","top"]);async function Un(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=q(n),a=ge(n),l=D(n)==="y",p=Vn.has(s)?-1:1,c=r&&l?-1:1,d=me(e,t),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),l?{x:h*c,y:u*p}:{x:u*p,y:h*c}}var Rt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:a}=e,l=await Un(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(o=a.arrow)!=null&&o.alignmentOffset?{}:{x:i+l.x,y:r+l.y,data:{...l,placement:s}}}}},Bt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:l={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...p}=me(t,e),c={x:n,y:o},d=await r.detectOverflow(e,p),u=D(q(i)),h=Ge(u),f=c[h],m=c[u];if(s){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=Xe(b,f,L)}if(a){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=Xe(b,m,L)}let g=l.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-n,y:g.y-o,enabled:{[h]:s,[u]:a}}}}}};function Ne(){return typeof window<"u"}function X(t){return Nt(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function B(t){var e;return(e=(Nt(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Nt(t){return Ne()?t instanceof Node||t instanceof A(t).Node:!1}function $(t){return Ne()?t instanceof Element||t instanceof A(t).Element:!1}function _(t){return Ne()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function Ft(t){return!Ne()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}var Wn=new Set(["inline","contents"]);function oe(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!Wn.has(i)}var qn=new Set(["table","td","th"]);function Dt(t){return qn.has(X(t))}var Kn=[":popover-open",":modal"];function ve(t){return Kn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Zn=["transform","translate","scale","rotate","perspective"],Qn=["transform","translate","scale","rotate","perspective","filter"],Jn=["paint","layout","strict","content"];function De(t){let e=ze(),n=$(t)?H(t):t;return Zn.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Qn.some(o=>(n.willChange||"").includes(o))||Jn.some(o=>(n.contain||"").includes(o))}function zt(t){let e=z(t);for(;_(e)&&!G(e);){if(De(e))return e;if(ve(e))return null;e=z(e)}return null}function ze(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Xn=new Set(["html","body","#document"]);function G(t){return Xn.has(X(t))}function H(t){return A(t).getComputedStyle(t)}function ye(t){return $(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function z(t){if(X(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Ft(t)&&t.host||B(t);return Ft(e)?e.host:e}function jt(t){let e=z(t);return G(e)?t.ownerDocument?t.ownerDocument.body:t.body:_(e)&&oe(e)?e:jt(e)}function Fe(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=jt(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=A(i);if(r){let a=je(s);return e.concat(s,s.visualViewport||[],oe(i)?i:[],a&&n?Fe(a):[])}return e.concat(i,Fe(i,[],n))}function je(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function qt(t){let e=H(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=_(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,a=fe(n)!==r||fe(o)!==s;return a&&(n=r,o=s),{width:n,height:o,$:a}}function Kt(t){return $(t)?t:t.contextElement}function ie(t){let e=Kt(t);if(!_(e))return O(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=qt(e),s=(r?fe(n.width):n.width)/o,a=(r?fe(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Gn=O(0);function Zt(t){let e=A(t);return!ze()||!e.visualViewport?Gn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Yn(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==A(t)?!1:e}function we(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=Kt(t),s=O(1);e&&(o?$(o)&&(s=ie(o)):s=ie(t));let a=Yn(r,n,o)?Zt(r):O(0),l=(i.left+a.x)/s.x,p=(i.top+a.y)/s.y,c=i.width/s.x,d=i.height/s.y;if(r){let u=A(r),h=o&&$(o)?A(o):o,f=u,m=je(f);for(;m&&o&&h!==f;){let g=ie(m),y=m.getBoundingClientRect(),w=H(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*g.x,L=y.top+(m.clientTop+parseFloat(w.paddingTop))*g.y;l*=g.x,p*=g.y,c*=g.x,d*=g.y,l+=b,p+=L,f=A(m),m=je(f)}}return J({width:c,height:d,x:l,y:p})}function Ve(t,e){let n=ye(t).scrollLeft;return e?e.left+n:we(B(t)).left+n}function Qt(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Ve(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function eo(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=B(o),a=e?ve(e.floating):!1;if(o===s||a&&r)return n;let l={scrollLeft:0,scrollTop:0},p=O(1),c=O(0),d=_(o);if((d||!d&&!r)&&((X(o)!=="body"||oe(s))&&(l=ye(o)),_(o))){let h=we(o);p=ie(o),c.x=h.x+o.clientLeft,c.y=h.y+o.clientTop}let u=s&&!d&&!r?Qt(s,l):O(0);return{width:n.width*p.x,height:n.height*p.y,x:n.x*p.x-l.scrollLeft*p.x+c.x+u.x,y:n.y*p.y-l.scrollTop*p.y+c.y+u.y}}function to(t){return Array.from(t.getClientRects())}function no(t){let e=B(t),n=ye(t),o=t.ownerDocument.body,i=W(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=W(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+Ve(t),a=-n.scrollTop;return H(o).direction==="rtl"&&(s+=W(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:a}}var Vt=25;function oo(t,e){let n=A(t),o=B(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,a=0,l=0;if(i){r=i.width,s=i.height;let c=ze();(!c||c&&e==="fixed")&&(a=i.offsetLeft,l=i.offsetTop)}let p=Ve(o);if(p<=0){let c=o.ownerDocument,d=c.body,u=getComputedStyle(d),h=c.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(o.clientWidth-d.clientWidth-h);f<=Vt&&(r-=f)}else p<=Vt&&(r+=p);return{width:r,height:s,x:a,y:l}}var io=new Set(["absolute","fixed"]);function ro(t,e){let n=we(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=_(t)?ie(t):O(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,l=i*r.x,p=o*r.y;return{width:s,height:a,x:l,y:p}}function Ut(t,e,n){let o;if(e==="viewport")o=oo(t,n);else if(e==="document")o=no(B(t));else if($(e))o=ro(e,n);else{let i=Zt(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return J(o)}function Jt(t,e){let n=z(t);return n===e||!$(n)||G(n)?!1:H(n).position==="fixed"||Jt(n,e)}function so(t,e){let n=e.get(t);if(n)return n;let o=Fe(t,[],!1).filter(a=>$(a)&&X(a)!=="body"),i=null,r=H(t).position==="fixed",s=r?z(t):t;for(;$(s)&&!G(s);){let a=H(s),l=De(s);!l&&a.position==="fixed"&&(i=null),(r?!l&&!i:!l&&a.position==="static"&&!!i&&io.has(i.position)||oe(s)&&!l&&Jt(t,s))?o=o.filter(c=>c!==s):i=a,s=z(s)}return e.set(t,o),o}function ao(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?ve(e)?[]:so(e,this._c):[].concat(n),o],a=s[0],l=s.reduce((p,c)=>{let d=Ut(e,c,i);return p.top=W(d.top,p.top),p.right=he(d.right,p.right),p.bottom=he(d.bottom,p.bottom),p.left=W(d.left,p.left),p},Ut(e,a,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function lo(t){let{width:e,height:n}=qt(t);return{width:e,height:n}}function co(t,e,n){let o=_(e),i=B(e),r=n==="fixed",s=we(t,!0,r,e),a={scrollLeft:0,scrollTop:0},l=O(0);function p(){l.x=Ve(i)}if(o||!o&&!r)if((X(e)!=="body"||oe(i))&&(a=ye(e)),o){let h=we(e,!0,r,e);l.x=h.x+e.clientLeft,l.y=h.y+e.clientTop}else i&&p();r&&!o&&i&&p();let c=i&&!o&&!r?Qt(i,a):O(0),d=s.left+a.scrollLeft-l.x-c.x,u=s.top+a.scrollTop-l.y-c.y;return{x:d,y:u,width:s.width,height:s.height}}function tt(t){return H(t).position==="static"}function Wt(t,e){if(!_(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return B(t)===n&&(n=n.ownerDocument.body),n}function Xt(t,e){let n=A(t);if(ve(t))return n;if(!_(t)){let i=z(t);for(;i&&!G(i);){if($(i)&&!tt(i))return i;i=z(i)}return n}let o=Wt(t,e);for(;o&&Dt(o)&&tt(o);)o=Wt(o,e);return o&&G(o)&&tt(o)&&!De(o)?n:o||zt(t)||n}var po=async function(t){let e=this.getOffsetParent||Xt,n=this.getDimensions,o=await n(t.floating);return{reference:co(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function uo(t){return H(t).direction==="rtl"}var ho={convertOffsetParentRelativeRectToViewportRelativeRect:eo,getDocumentElement:B,getClippingRect:ao,getOffsetParent:Xt,getElementRects:po,getClientRects:to,getDimensions:lo,getScale:ie,isElement:$,isRTL:uo};var Gt=Rt;var Yt=Bt,en=It;var tn=(t,e,n)=>{let o=new Map,i={platform:ho,...n},r={...i.platform,_c:o};return _t(t,e,{...i,platform:r})};var Ue=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
47
+ `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function xt(t,e){let n=t.selectionStart,i=t.selectionEnd,o=t.scrollTop;e(),t.selectionStart=n,t.selectionEnd=i,t.scrollTop=o}function Ee(t,e,n={}){let i=t.selectionStart,o=t.selectionEnd,r=i===o,s=t.value,a=i;for(;a>0&&s[a-1]!==`
48
+ `;)a--;if(r){let c=i;for(;c<s.length&&s[c]!==`
49
+ `;)c++;t.selectionStart=a,t.selectionEnd=c}else bt(t);let l=e(t);if(n.adjustSelection){let p=t.value.slice(t.selectionStart,t.selectionEnd).startsWith(n.prefix),d=n.adjustSelection(p,i,o,a);l.selectionStart=d.start,l.selectionEnd=d.end}else if(n.prefix){let p=t.value.slice(t.selectionStart,t.selectionEnd).startsWith(n.prefix);r?p?(l.selectionStart=Math.max(i-n.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=i+n.prefix.length,l.selectionEnd=l.selectionStart):p?(l.selectionStart=Math.max(i-n.prefix.length,a),l.selectionEnd=Math.max(o-n.prefix.length,a)):(l.selectionStart=i+n.prefix.length,l.selectionEnd=o+n.prefix.length)}return l}function te(t,e){let n,i,{prefix:o,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:c,scanFor:p,surroundWithNewlines:d,trimFirst:u}=e,h=t.selectionStart,f=t.selectionEnd,m=t.value.slice(t.selectionStart,t.selectionEnd),v=Ze(m)&&s&&s.length>0?`${s}
50
+ `:o,y=Ze(m)&&a&&a.length>0?`
51
+ ${a}`:r;if(c){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!k.match(/\s/)&&(v=` ${v}`)}m=_n(t,v,y,e.multiline);let w=t.selectionStart,b=t.selectionEnd,L=l&&l.length>0&&y.indexOf(l)>-1&&m.length>0;if(d){let k=Je(t);n=k.newlinesToAppend,i=k.newlinesToPrepend,v=n+o,y+=i}if(m.startsWith(v)&&m.endsWith(y)){let k=m.slice(v.length,m.length-y.length);if(h===f){let E=h-v.length;E=Math.max(E,w),E=Math.min(E,w+k.length),w=b=E}else b=w+k.length;return{text:k,selectionStart:w,selectionEnd:b}}else if(L)if(p&&p.length>0&&m.match(p)){y=y.replace(l,m);let k=v+y;return w=b=w+v.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=v+m+y;return w=w+v.length+m.length+y.indexOf(l),b=w+l.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=v+m+y;w=h+v.length,b=f+v.length;let E=m.match(/^\s*|\s*$/g);if(u&&E){let xe=E[0]||"",Y=E[1]||"";k=xe+v+m.trim()+y+Y,w+=xe.length,b-=Y.length}return{text:k,selectionStart:w,selectionEnd:b}}}function Ge(t,e){let{prefix:n,suffix:i,surroundWithNewlines:o}=e,r=t.value.slice(t.selectionStart,t.selectionEnd),s=t.selectionStart,a=t.selectionEnd,l=r.split(`
52
+ `);if(l.every(p=>p.startsWith(n)&&(!i||p.endsWith(i))))r=l.map(p=>{let d=p.slice(n.length);return i&&(d=d.slice(0,d.length-i.length)),d}).join(`
53
+ `),a=s+r.length;else if(r=l.map(p=>n+p+(i||"")).join(`
54
+ `),o){let{newlinesToAppend:p,newlinesToPrepend:d}=Je(t);s+=p.length,a=s+r.length,r=p+r+d}return{text:r,selectionStart:s,selectionEnd:a}}function mt(t){let e=t.split(`
55
+ `),n=/^\d+\.\s+/,i=e.every(r=>n.test(r)),o=e;return i&&(o=e.map(r=>r.replace(n,""))),{text:o.join(`
56
+ `),processed:i}}function gt(t){let e=t.split(`
57
+ `),n="- ",i=e.every(r=>r.startsWith(n)),o=e;return i&&(o=e.map(r=>r.slice(n.length))),{text:o.join(`
58
+ `),processed:i}}function le(t,e){return e?"- ":`${t+1}. `}function Pn(t,e){let n,i,o;return t.orderedList?(n=mt(e),i=gt(n.text),o=i.text):(n=gt(e),i=mt(n.text),o=i.text),[n,i,o]}function Hn(t,e){let n=t.selectionStart===t.selectionEnd,i=t.selectionStart,o=t.selectionEnd;bt(t);let r=t.value.slice(t.selectionStart,t.selectionEnd),[s,a,l]=Pn(e,r),c=l.split(`
59
+ `).map((m,v)=>`${le(v,e.unorderedList)}${m}`),p=c.reduce((m,v,y)=>m+le(y,e.unorderedList).length,0),d=c.reduce((m,v,y)=>m+le(y,!e.unorderedList).length,0);if(s.processed)return n?(i=Math.max(i-le(0,e.unorderedList).length,0),o=i):(i=t.selectionStart,o=t.selectionEnd-p),{text:l,selectionStart:i,selectionEnd:o};let{newlinesToAppend:u,newlinesToPrepend:h}=Je(t),f=u+c.join(`
60
+ `)+h;return n?(i=Math.max(i+le(0,e.unorderedList).length+u.length,0),o=i):a.processed?(i=Math.max(t.selectionStart+u.length,0),o=t.selectionEnd+u.length+p-d):(i=Math.max(t.selectionStart+u.length,0),o=t.selectionEnd+u.length+p),{text:f,selectionStart:i,selectionEnd:o}}function kt(t,e){let n=Ee(t,i=>Hn(i,e),{adjustSelection:(i,o,r,s)=>{let a=t.value.slice(s,t.selectionEnd),l=/^\d+\.\s+/,c=/^- /,p=l.test(a),d=c.test(a),u=e.orderedList&&p||e.unorderedList&&d;if(o===r)if(u){let h=a.match(e.orderedList?l:c),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(p||d){let h=a.match(p?l:c),f=h?h[0].length:0,v=(e.unorderedList?2:3)-f;return{start:o+v,end:o+v}}else{let h=e.unorderedList?2:3;return{start:o+h,end:o+h}}else if(u){let h=a.match(e.orderedList?l:c),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(p||d){let h=a.match(p?l:c),f=h?h[0].length:0,v=(e.unorderedList?2:3)-f;return{start:o+v,end:r+v}}else{let h=e.unorderedList?2:3;return{start:o+h,end:r+h}}}});F(t,n)}function Lt(t){if(!t)return[];let e=[],{selectionStart:n,selectionEnd:i,value:o}=t,r=o.split(`
61
+ `),s=0,a="";for(let d of r){if(n>=s&&n<=s+d.length){a=d;break}s+=d.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let l=Math.max(0,n-10),c=Math.min(o.length,i+10),p=o.slice(l,c);if(p.includes("**")){let d=o.slice(Math.max(0,n-100),n),u=o.slice(i,Math.min(o.length,i+100)),h=d.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(p.includes("_")){let d=o.slice(Math.max(0,n-100),n),u=o.slice(i,Math.min(o.length,i+100)),h=d.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(p.includes("`")){let d=o.slice(Math.max(0,n-100),n),u=o.slice(i,Math.min(o.length,i+100));d.includes("`")&&u.includes("`")&&e.push("code")}if(p.includes("[")&&p.includes("]")){let d=o.slice(Math.max(0,n-100),n),u=o.slice(i,Math.min(o.length,i+100)),h=d.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&o.slice(i+f+1,i+f+10).startsWith("(")&&e.push("link")}return e}function $n(t,e){return Lt(t).includes(e)}function On(t,e={}){if(!t)return;let{toWord:n,toLine:i,toFormat:o}=e,{selectionStart:r,selectionEnd:s,value:a}=t;if(i){let l=a.split(`
62
+ `),c=0,p=0,d=0;for(let u of l){if(r>=d&&r<=d+u.length){c=d,p=d+u.length;break}d+=u.length+1}t.selectionStart=c,t.selectionEnd=p}else if(n&&r===s){let l=r,c=s;for(;l>0&&!/\s/.test(a[l-1]);)l--;for(;c<a.length&&!/\s/.test(a[c]);)c++;t.selectionStart=l,t.selectionEnd=c}}function Te(t){if(!t||t.disabled||t.readOnly)return;x("toggleBold","Starting"),Se(t,"Before");let e=R(O.bold),n=te(t,e);yt(n),F(t,n),Se(t,"After")}function Ae(t){if(!t||t.disabled||t.readOnly)return;let e=R(O.italic),n=te(t,e);F(t,n)}function Ce(t){if(!t||t.disabled||t.readOnly)return;let e=R(O.code),n=te(t,e);F(t,n)}function Ie(t,e={}){if(!t||t.disabled||t.readOnly)return;let n=t.value.slice(t.selectionStart,t.selectionEnd),i=R(O.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(i.suffix=`](${n})`,i.replaceNext=""):e.url&&(i.suffix=`](${e.url})`,i.replaceNext=""),e.text&&!n){let s=t.selectionStart;t.value=t.value.slice(0,s)+e.text+t.value.slice(s),t.selectionStart=s,t.selectionEnd=s+e.text.length}let r=te(t,i);F(t,r)}function Me(t){if(!t||t.disabled||t.readOnly)return;let e=R(O.bulletList);kt(t,e)}function _e(t){if(!t||t.disabled||t.readOnly)return;let e=R(O.numberedList);kt(t,e)}function Pe(t){if(!t||t.disabled||t.readOnly)return;x("toggleQuote","Starting"),Se(t,"Initial");let e=R(O.quote),n=Ee(t,i=>Ge(i,e),{prefix:e.prefix});yt(n),F(t,n),Se(t,"Final")}function pe(t){if(!t||t.disabled||t.readOnly)return;let e=R(O.taskList),n=Ee(t,i=>Ge(i,e),{prefix:e.prefix});F(t,n)}function de(t,e=1,n=!1){if(!t||t.disabled||t.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${n}`),x("insertHeader",`Initial cursor: ${t.selectionStart}-${t.selectionEnd}`);let i=`header${e===1?"1":e}`,o=R(O[i]||O.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=t.value,s=t.selectionStart,a=t.selectionEnd,l=s;for(;l>0&&r[l-1]!==`
63
+ `;)l--;let c=a;for(;c<r.length&&r[c]!==`
64
+ `;)c++;let p=r.slice(l,c);x("insertHeader",`Current line (before): "${p}"`);let d=p.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=n&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${n}, existingLevel=${u}, level=${e})`);let m=Ee(t,v=>{let y=v.value.slice(v.selectionStart,v.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let w=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${w}"`);let b;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),b=w):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),b=o.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=o.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:v.selectionStart,selectionEnd:v.selectionEnd}},{prefix:o.prefix,adjustSelection:(v,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${v}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-h,b);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:L,end:y===w?L:Math.max(w-h,b)}}else if(h>0){let L=o.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:y+o.prefix.length,end:w+o.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),F(t,m)}function He(t){de(t,1,!0)}function $e(t){de(t,2,!0)}function Oe(t){de(t,3,!0)}function Re(t){return Lt(t)}function St(t,e){return $n(t,e)}function Et(t,e={}){On(t,e)}function Tt(t,e){if(!t||t.disabled||t.readOnly)return;let n=R(e),i;if(n.multiline){let o=t.value.slice(t.selectionStart,t.selectionEnd);Ze(o)?i=Ge(t,n):i=te(t,n)}else i=te(t,n);F(t,i)}var Rn={toggleBold:Te,toggleItalic:Ae,toggleCode:Ce,insertLink:Ie,toggleBulletList:Me,toggleNumberedList:_e,toggleQuote:Pe,toggleTaskList:pe,insertHeader:de,toggleH1:He,toggleH2:$e,toggleH3:Oe,getActiveFormats:Re,hasFormat:St,expandSelection:Et,applyCustomFormat:Tt,preserveSelection:xt,setUndoMethod:wt,setDebugMode:vt,getDebugMode:Qe};var Be=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.currentItemIndex=0,this.handleDocumentClick=null,this.activeDropdown=null,this.activeDropdownButton=null,this.toolbarButtons=n.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.id=this.getInstanceElementId("toolbar"),this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.container.setAttribute("aria-controls",this.editor.textarea.id),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),this.setupRovingTabIndex(),this.updateButtonStates(),this.editor.container.insertBefore(this.container,this.editor.wrapper)}getInstanceElementId(e){return`overtype-${this.editor.instanceId}-${e}`}setupRovingTabIndex(){this.getToolbarItems().length!==0&&(this.currentItemIndex=this.getValidItemIndex(this.currentItemIndex),this.updateTabIndexes(),this.container.addEventListener("keydown",n=>{this.onToolbarKeydown(n)}),this.container.addEventListener("focusin",n=>{this.onToolbarFocusin(n)}))}getToolbarItems(){return this.container?Array.from(this.container.querySelectorAll(".overtype-toolbar-button")):[]}onToolbarKeydown(e){let n=this.getToolbarItems();if(n.includes(e.target))switch(e.key){case"ArrowRight":e.preventDefault(),this.focusItem(this.currentItemIndex+1);break;case"ArrowLeft":e.preventDefault(),this.focusItem(this.currentItemIndex-1);break;case"Home":e.preventDefault(),this.focusItem(0);break;case"End":e.preventDefault(),this.focusItem(n.length-1);break}}onToolbarFocusin(e){let n=this.getToolbarItems().indexOf(e.target);n!==-1&&(this.currentItemIndex=n,this.updateTabIndexes())}focusItem(e){let n=this.getToolbarItems();n.length!==0&&(this.currentItemIndex=this.getValidItemIndex(e,n),this.updateTabIndexes(),n[this.currentItemIndex].focus())}getValidItemIndex(e,n=this.getToolbarItems()){let i=n.length;return i===0?0:e<0?i-1:e>=i?0:e}updateTabIndexes(){this.getToolbarItems().forEach((e,n)=>{e.tabIndex=n===this.currentItemIndex?0:-1})}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.setAttribute("aria-haspopup","menu"),n.setAttribute("aria-expanded","false"),n._clickHandler=i=>{i.preventDefault(),this.toggleViewModeDropdown(n)},n._keydownHandler=i=>{if(!["ArrowDown","ArrowUp","Enter"," "].includes(i.key))return;i.preventDefault();let o=i.key==="ArrowUp"?"last":"current";this.openViewModeDropdown(n,o)},n.addEventListener("click",n._clickHandler),n.addEventListener("keydown",n._keydownHandler),n):(n._clickHandler=i=>{i.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,i)},n.addEventListener("click",n._clickHandler),n)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){if(this.activeDropdown){this.closeViewModeDropdown(e);return}this.openViewModeDropdown(e)}openViewModeDropdown(e,n=null){this.closeViewModeDropdown(e),e.classList.add("dropdown-active");let i=this.createViewModeDropdown(e),o=e.getBoundingClientRect();i.style.position="absolute",i.style.top=`${o.bottom+5}px`,i.style.left=`${o.left}px`,document.body.appendChild(i),this.activeDropdown=i,this.activeDropdownButton=e,e.setAttribute("aria-controls",i.id),e.setAttribute("aria-expanded","true"),this.handleDocumentClick=r=>{!i.contains(r.target)&&!e.contains(r.target)&&this.closeViewModeDropdown(e)},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0),n&&this.focusViewModeMenuItem(i,n)}closeViewModeDropdown(e=this.activeDropdownButton,n=!1){this.activeDropdown&&(this.activeDropdown.remove(),this.activeDropdown=null),e&&(e.classList.remove("dropdown-active"),e.setAttribute("aria-expanded","false")),this.handleDocumentClick&&(document.removeEventListener("click",this.handleDocumentClick),this.handleDocumentClick=null),this.activeDropdownButton=null,n&&e&&e.focus()}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu",n.id=this.getInstanceElementId("toolbar-view-mode-menu"),n.setAttribute("role","menu"),n.setAttribute("aria-label","View mode"),n.addEventListener("keydown",r=>{this.onViewModeMenuKeydown(r,e)});let i=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],o=this.editor.container.dataset.mode||"normal";return i.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.tabIndex=-1,s.setAttribute("role","menuitemradio"),s.setAttribute("aria-checked",String(r.id===o)),s.textContent=r.label,r.id===o){s.classList.add("active");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.setAttribute("aria-hidden","true"),a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}this.closeViewModeDropdown(e,!0)}),n.appendChild(s)}),n}onViewModeMenuKeydown(e,n){let o=this.getViewModeMenuItems().indexOf(e.target);if(o!==-1)switch(e.key){case"ArrowDown":e.preventDefault(),this.focusViewModeMenuItem(this.activeDropdown,o+1);break;case"ArrowUp":e.preventDefault(),this.focusViewModeMenuItem(this.activeDropdown,o-1);break;case"Home":e.preventDefault(),this.focusViewModeMenuItem(this.activeDropdown,"first");break;case"End":e.preventDefault(),this.focusViewModeMenuItem(this.activeDropdown,"last");break;case"Escape":e.preventDefault(),this.closeViewModeDropdown(n,!0);break}}focusViewModeMenuItem(e,n){let i=this.getViewModeMenuItems(e);if(i.length===0)return;let o=n;n==="first"?o=0:n==="last"?o=i.length-1:n==="current"&&(o=i.findIndex(r=>r.getAttribute("aria-checked")==="true")),o<0&&(o=i.length-1),o>=i.length&&(o=0),i[o].focus()}getViewModeMenuItems(e=this.activeDropdown){return e?Array.from(e.querySelectorAll('[role="menuitemradio"]')):[]}updateButtonStates(){var e;try{let n=((e=Re)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([i,o])=>{if(i==="viewMode")return;let r=this.toolbarButtons.find(a=>a.name===i);if(!(r!=null&&r.isActive))return;let s=!!r.isActive({editor:this.editor,activeFormats:n});o.classList.toggle("active",s),o.setAttribute("aria-pressed",s.toString())})}catch(n){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.activeDropdown?this.closeViewModeDropdown():this.handleDocumentClick&&(document.removeEventListener("click",this.handleDocumentClick),this.handleDocumentClick=null),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler),e._keydownHandler&&(e.removeEventListener("keydown",e._keydownHandler),delete e._keydownHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var he=Math.min,W=Math.max,fe=Math.round;var H=t=>({x:t,y:t}),Bn={left:"right",right:"left",bottom:"top",top:"bottom"},Dn={start:"end",end:"start"};function Xe(t,e,n){return W(t,he(e,n))}function me(t,e){return typeof t=="function"?t(e):t}function q(t){return t.split("-")[0]}function ge(t){return t.split("-")[1]}function Ye(t){return t==="x"?"y":"x"}function et(t){return t==="y"?"height":"width"}var Fn=new Set(["top","bottom"]);function N(t){return Fn.has(q(t))?"y":"x"}function tt(t){return Ye(N(t))}function It(t,e,n){n===void 0&&(n=!1);let i=ge(t),o=tt(t),r=et(o),s=o==="x"?i===(n?"end":"start")?"right":"left":i==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ue(s)),[s,ue(s)]}function Mt(t){let e=ue(t);return[De(t),e,De(e)]}function De(t){return t.replace(/start|end/g,e=>Dn[e])}var At=["left","right"],Ct=["right","left"],Nn=["top","bottom"],Vn=["bottom","top"];function zn(t,e,n){switch(t){case"top":case"bottom":return n?e?Ct:At:e?At:Ct;case"left":case"right":return e?Nn:Vn;default:return[]}}function _t(t,e,n,i){let o=ge(t),r=zn(q(t),n==="start",i);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(De)))),r}function ue(t){return t.replace(/left|right|bottom|top/g,e=>Bn[e])}function jn(t){return{top:0,right:0,bottom:0,left:0,...t}}function Pt(t){return typeof t!="number"?jn(t):{top:t,right:t,bottom:t,left:t}}function J(t){let{x:e,y:n,width:i,height:o}=t;return{width:i,height:o,top:n,left:e,right:e+i,bottom:n+o,x:e,y:n}}function Ht(t,e,n){let{reference:i,floating:o}=t,r=N(e),s=tt(e),a=et(s),l=q(e),c=r==="y",p=i.x+i.width/2-o.width/2,d=i.y+i.height/2-o.height/2,u=i[a]/2-o[a]/2,h;switch(l){case"top":h={x:p,y:i.y-o.height};break;case"bottom":h={x:p,y:i.y+i.height};break;case"right":h={x:i.x+i.width,y:d};break;case"left":h={x:i.x-o.width,y:d};break;default:h={x:i.x,y:i.y}}switch(ge(e)){case"start":h[s]-=u*(n&&c?-1:1);break;case"end":h[s]+=u*(n&&c?-1:1);break}return h}async function $t(t,e){var n;e===void 0&&(e={});let{x:i,y:o,platform:r,rects:s,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:p="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=me(e,t),f=Pt(h),v=a[u?d==="floating"?"reference":"floating":d],y=J(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(v)))==null||n?v:v.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:c,rootBoundary:p,strategy:l})),w=d==="floating"?{x:i,y:o,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=J(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:l}):w);return{top:(y.top-k.top+f.top)/L.y,bottom:(k.bottom-y.bottom+f.bottom)/L.y,left:(y.left-k.left+f.left)/L.x,right:(k.right-y.right+f.right)/L.x}}var Ot=async(t,e,n)=>{let{placement:i="bottom",strategy:o="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),c=await s.getElementRects({reference:t,floating:e,strategy:o}),{x:p,y:d}=Ht(c,i,l),u=i,h={},f=0;for(let v=0;v<a.length;v++){var m;let{name:y,fn:w}=a[v],{x:b,y:L,data:k,reset:E}=await w({x:p,y:d,initialPlacement:i,placement:u,strategy:o,middlewareData:h,rects:c,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:$t},elements:{reference:t,floating:e}});p=b!=null?b:p,d=L!=null?L:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(c=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:o}):E.rects),{x:p,y:d}=Ht(c,u,l)),v=-1)}return{x:p,y:d,placement:u,strategy:o,middlewareData:h}};var Rt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,i;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:p=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...v}=me(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let y=q(o),w=N(a),b=q(a)===a,L=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=u||(b||!m?[ue(a)]:Mt(a)),E=f!=="none";!u&&E&&k.push(..._t(a,m,f,L));let xe=[a,...k],Y=await l.detectOverflow(e,v),ke=[],ee=((i=r.flip)==null?void 0:i.overflows)||[];if(p&&ke.push(Y[y]),d){let K=It(o,s,L);ke.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ke}],!ke.every(K=>K<=0)){var ot,rt;let K=(((ot=r.flip)==null?void 0:ot.index)||0)+1,qe=xe[K];if(qe&&(!(d==="alignment"?w!==N(qe):!1)||ee.every(P=>N(P.placement)===w?P.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:qe}};let se=(rt=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,P)=>Z.overflows[1]-P.overflows[1])[0])==null?void 0:rt.placement;if(!se)switch(h){case"bestFit":{var st;let Z=(st=ee.filter(P=>{if(E){let j=N(P.placement);return j===w||j==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(j=>j>0).reduce((j,yn)=>j+yn,0)]).sort((P,j)=>P[1]-j[1])[0])==null?void 0:st[0];Z&&(se=Z);break}case"initialPlacement":se=a;break}if(o!==se)return{reset:{placement:se}}}return{}}}};var Un=new Set(["left","top"]);async function Wn(t,e){let{placement:n,platform:i,elements:o}=t,r=await(i.isRTL==null?void 0:i.isRTL(o.floating)),s=q(n),a=ge(n),l=N(n)==="y",c=Un.has(s)?-1:1,p=r&&l?-1:1,d=me(e,t),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),l?{x:h*p,y:u*c}:{x:u*c,y:h*p}}var Bt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,i;let{x:o,y:r,placement:s,middlewareData:a}=e,l=await Wn(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(i=a.arrow)!=null&&i.alignmentOffset?{}:{x:o+l.x,y:r+l.y,data:{...l,placement:s}}}}},Dt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:i,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:l={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...c}=me(t,e),p={x:n,y:i},d=await r.detectOverflow(e,c),u=N(q(o)),h=Ye(u),f=p[h],m=p[u];if(s){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=Xe(b,f,L)}if(a){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=Xe(b,m,L)}let v=l.fn({...e,[h]:f,[u]:m});return{...v,data:{x:v.x-n,y:v.y-i,enabled:{[h]:s,[u]:a}}}}}};function Ne(){return typeof window<"u"}function G(t){return Nt(t)?(t.nodeName||"").toLowerCase():"#document"}function C(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function B(t){var e;return(e=(Nt(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Nt(t){return Ne()?t instanceof Node||t instanceof C(t).Node:!1}function M(t){return Ne()?t instanceof Element||t instanceof C(t).Element:!1}function $(t){return Ne()?t instanceof HTMLElement||t instanceof C(t).HTMLElement:!1}function Ft(t){return!Ne()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof C(t).ShadowRoot}var qn=new Set(["inline","contents"]);function ie(t){let{overflow:e,overflowX:n,overflowY:i,display:o}=_(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!qn.has(o)}var Kn=new Set(["table","td","th"]);function Vt(t){return Kn.has(G(t))}var Zn=[":popover-open",":modal"];function ve(t){return Zn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Qn=["transform","translate","scale","rotate","perspective"],Jn=["transform","translate","scale","rotate","perspective","filter"],Gn=["paint","layout","strict","content"];function Ve(t){let e=ze(),n=M(t)?_(t):t;return Qn.some(i=>n[i]?n[i]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Jn.some(i=>(n.willChange||"").includes(i))||Gn.some(i=>(n.contain||"").includes(i))}function zt(t){let e=V(t);for(;$(e)&&!X(e);){if(Ve(e))return e;if(ve(e))return null;e=V(e)}return null}function ze(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Xn=new Set(["html","body","#document"]);function X(t){return Xn.has(G(t))}function _(t){return C(t).getComputedStyle(t)}function ye(t){return M(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function V(t){if(G(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Ft(t)&&t.host||B(t);return Ft(e)?e.host:e}function jt(t){let e=V(t);return X(e)?t.ownerDocument?t.ownerDocument.body:t.body:$(e)&&ie(e)?e:jt(e)}function Fe(t,e,n){var i;e===void 0&&(e=[]),n===void 0&&(n=!0);let o=jt(t),r=o===((i=t.ownerDocument)==null?void 0:i.body),s=C(o);if(r){let a=je(s);return e.concat(s,s.visualViewport||[],ie(o)?o:[],a&&n?Fe(a):[])}return e.concat(o,Fe(o,[],n))}function je(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Kt(t){let e=_(t),n=parseFloat(e.width)||0,i=parseFloat(e.height)||0,o=$(t),r=o?t.offsetWidth:n,s=o?t.offsetHeight:i,a=fe(n)!==r||fe(i)!==s;return a&&(n=r,i=s),{width:n,height:i,$:a}}function Zt(t){return M(t)?t:t.contextElement}function oe(t){let e=Zt(t);if(!$(e))return H(1);let n=e.getBoundingClientRect(),{width:i,height:o,$:r}=Kt(e),s=(r?fe(n.width):n.width)/i,a=(r?fe(n.height):n.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Yn=H(0);function Qt(t){let e=C(t);return!ze()||!e.visualViewport?Yn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ei(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==C(t)?!1:e}function we(t,e,n,i){e===void 0&&(e=!1),n===void 0&&(n=!1);let o=t.getBoundingClientRect(),r=Zt(t),s=H(1);e&&(i?M(i)&&(s=oe(i)):s=oe(t));let a=ei(r,n,i)?Qt(r):H(0),l=(o.left+a.x)/s.x,c=(o.top+a.y)/s.y,p=o.width/s.x,d=o.height/s.y;if(r){let u=C(r),h=i&&M(i)?C(i):i,f=u,m=je(f);for(;m&&i&&h!==f;){let v=oe(m),y=m.getBoundingClientRect(),w=_(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*v.x,L=y.top+(m.clientTop+parseFloat(w.paddingTop))*v.y;l*=v.x,c*=v.y,p*=v.x,d*=v.y,l+=b,c+=L,f=C(m),m=je(f)}}return J({width:p,height:d,x:l,y:c})}function Ue(t,e){let n=ye(t).scrollLeft;return e?e.left+n:we(B(t)).left+n}function Jt(t,e){let n=t.getBoundingClientRect(),i=n.left+e.scrollLeft-Ue(t,n),o=n.top+e.scrollTop;return{x:i,y:o}}function ti(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t,r=o==="fixed",s=B(i),a=e?ve(e.floating):!1;if(i===s||a&&r)return n;let l={scrollLeft:0,scrollTop:0},c=H(1),p=H(0),d=$(i);if((d||!d&&!r)&&((G(i)!=="body"||ie(s))&&(l=ye(i)),$(i))){let h=we(i);c=oe(i),p.x=h.x+i.clientLeft,p.y=h.y+i.clientTop}let u=s&&!d&&!r?Jt(s,l):H(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+p.x+u.x,y:n.y*c.y-l.scrollTop*c.y+p.y+u.y}}function ni(t){return Array.from(t.getClientRects())}function ii(t){let e=B(t),n=ye(t),i=t.ownerDocument.body,o=W(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),r=W(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight),s=-n.scrollLeft+Ue(t),a=-n.scrollTop;return _(i).direction==="rtl"&&(s+=W(e.clientWidth,i.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Ut=25;function oi(t,e){let n=C(t),i=B(t),o=n.visualViewport,r=i.clientWidth,s=i.clientHeight,a=0,l=0;if(o){r=o.width,s=o.height;let p=ze();(!p||p&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}let c=Ue(i);if(c<=0){let p=i.ownerDocument,d=p.body,u=getComputedStyle(d),h=p.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(i.clientWidth-d.clientWidth-h);f<=Ut&&(r-=f)}else c<=Ut&&(r+=c);return{width:r,height:s,x:a,y:l}}var ri=new Set(["absolute","fixed"]);function si(t,e){let n=we(t,!0,e==="fixed"),i=n.top+t.clientTop,o=n.left+t.clientLeft,r=$(t)?oe(t):H(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,l=o*r.x,c=i*r.y;return{width:s,height:a,x:l,y:c}}function Wt(t,e,n){let i;if(e==="viewport")i=oi(t,n);else if(e==="document")i=ii(B(t));else if(M(e))i=si(e,n);else{let o=Qt(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return J(i)}function Gt(t,e){let n=V(t);return n===e||!M(n)||X(n)?!1:_(n).position==="fixed"||Gt(n,e)}function ai(t,e){let n=e.get(t);if(n)return n;let i=Fe(t,[],!1).filter(a=>M(a)&&G(a)!=="body"),o=null,r=_(t).position==="fixed",s=r?V(t):t;for(;M(s)&&!X(s);){let a=_(s),l=Ve(s);!l&&a.position==="fixed"&&(o=null),(r?!l&&!o:!l&&a.position==="static"&&!!o&&ri.has(o.position)||ie(s)&&!l&&Gt(t,s))?i=i.filter(p=>p!==s):o=a,s=V(s)}return e.set(t,i),i}function li(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t,s=[...n==="clippingAncestors"?ve(e)?[]:ai(e,this._c):[].concat(n),i],a=s[0],l=s.reduce((c,p)=>{let d=Wt(e,p,o);return c.top=W(d.top,c.top),c.right=he(d.right,c.right),c.bottom=he(d.bottom,c.bottom),c.left=W(d.left,c.left),c},Wt(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function ci(t){let{width:e,height:n}=Kt(t);return{width:e,height:n}}function pi(t,e,n){let i=$(e),o=B(e),r=n==="fixed",s=we(t,!0,r,e),a={scrollLeft:0,scrollTop:0},l=H(0);function c(){l.x=Ue(o)}if(i||!i&&!r)if((G(e)!=="body"||ie(o))&&(a=ye(e)),i){let h=we(e,!0,r,e);l.x=h.x+e.clientLeft,l.y=h.y+e.clientTop}else o&&c();r&&!i&&o&&c();let p=o&&!i&&!r?Jt(o,a):H(0),d=s.left+a.scrollLeft-l.x-p.x,u=s.top+a.scrollTop-l.y-p.y;return{x:d,y:u,width:s.width,height:s.height}}function nt(t){return _(t).position==="static"}function qt(t,e){if(!$(t)||_(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return B(t)===n&&(n=n.ownerDocument.body),n}function Xt(t,e){let n=C(t);if(ve(t))return n;if(!$(t)){let o=V(t);for(;o&&!X(o);){if(M(o)&&!nt(o))return o;o=V(o)}return n}let i=qt(t,e);for(;i&&Vt(i)&&nt(i);)i=qt(i,e);return i&&X(i)&&nt(i)&&!Ve(i)?n:i||zt(t)||n}var di=async function(t){let e=this.getOffsetParent||Xt,n=this.getDimensions,i=await n(t.floating);return{reference:pi(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function ui(t){return _(t).direction==="rtl"}var hi={convertOffsetParentRelativeRectToViewportRelativeRect:ti,getDocumentElement:B,getClippingRect:li,getOffsetParent:Xt,getElementRects:di,getClientRects:ni,getDimensions:ci,getScale:oe,isElement:M,isRTL:ui};var Yt=Bt;var en=Dt,tn=Rt;var nn=(t,e,n)=>{let i=new Map,o={platform:hi,...n},r={...o.platform,_c:i};return Ot(t,e,{...o,platform:r})};var We=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
65
65
  <span style="display: flex; align-items: center; gap: 6px;">
66
66
  <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
67
67
  <path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path>
@@ -69,25 +69,26 @@ ${a}`:r;if(p){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
69
69
  </svg>
70
70
  <span class="overtype-link-tooltip-url"></span>
71
71
  </span>
72
- `,this.tooltip.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.currentLink&&(window.open(this.currentLink.url,"_blank"),this.hide())}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,n=this.editor.textarea.value,o=this.findLinkAtPosition(n,e);o?(!this.currentLink||this.currentLink.url!==o.url||this.currentLink.index!==o.index)&&this.show(o):this.scheduleHide()}findLinkAtPosition(e,n){let o=/\[([^\]]+)\]\(([^)]+)\)/g,i,r=0;for(;(i=o.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(n>=s&&n<=a)return{text:i[1],url:i[2],index:r,start:s,end:a};r++}return null}async show(e){this.currentLink=e,this.cancelHide();let n=this.tooltip.querySelector(".overtype-link-tooltip-url");n.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let n=this.findAnchorElement(e.index);if(!n)return;let o=n.getBoundingClientRect();if(!(o.width===0||o.height===0))try{let{x:i,y:r}=await tn(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Gt(8),Yt({padding:8}),en()]});Object.assign(this.tooltip.style,{left:`${i}px`,top:`${r}px`,position:"fixed"})}catch(i){console.warn("Floating UI positioning failed:",i)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var nn='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z"></path></svg>',on='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line></svg>',rn='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z"></path></svg>',sn='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',an='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.65186,12.30664a2.6742,2.6742,0,0,1-2.915,2.68457,3.96592,3.96592,0,0,1-2.25537-.6709.56007.56007,0,0,1-.13232-.83594L11.64648,13c.209-.34082.48389-.36328.82471-.1543a2.32654,2.32654,0,0,0,1.12256.33008c.71484,0,1.12207-.35156,1.12207-.78125,0-.61523-.61621-.86816-1.46338-.86816H13.2085a.65159.65159,0,0,1-.68213-.41895l-.05518-.10937a.67114.67114,0,0,1,.14307-.78125l.71533-.86914a8.55289,8.55289,0,0,1,.68213-.7373V8.58887a3.93913,3.93913,0,0,1-.748.05469H11.9873a.54085.54085,0,0,1-.605-.60547V7.59863a.54085.54085,0,0,1,.605-.60547h3.75146a.53773.53773,0,0,1,.60547.59375v.17676a1.03723,1.03723,0,0,1-.27539.748L14.74854,10.0293A2.31132,2.31132,0,0,1,16.65186,12.30664ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',ln='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z"></path></svg>',cn='<svg viewBox="0 0 18 18"><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line></svg>',pn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line></svg>',dn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" x1="2.5" x2="4.5" y1="5.5" y2="5.5"></line><path fill="currentColor" d="M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109"></path></svg>',un='<svg viewBox="2 2 20 20"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 10.8182L9 10.8182C8.80222 10.8182 8.60888 10.7649 8.44443 10.665C8.27998 10.5651 8.15181 10.4231 8.07612 10.257C8.00043 10.0909 7.98063 9.90808 8.01922 9.73174C8.0578 9.55539 8.15304 9.39341 8.29289 9.26627C8.43275 9.13913 8.61093 9.05255 8.80491 9.01747C8.99889 8.98239 9.19996 9.00039 9.38268 9.0692C9.56541 9.13801 9.72159 9.25453 9.83147 9.40403C9.94135 9.55353 10 9.72929 10 9.90909L10 12.1818C10 12.664 9.78929 13.1265 9.41421 13.4675C9.03914 13.8084 8.53043 14 8 14"></path><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 10.8182L15 10.8182C14.8022 10.8182 14.6089 10.7649 14.4444 10.665C14.28 10.5651 14.1518 10.4231 14.0761 10.257C14.0004 10.0909 13.9806 9.90808 14.0192 9.73174C14.0578 9.55539 14.153 9.39341 14.2929 9.26627C14.4327 9.13913 14.6109 9.05255 14.8049 9.01747C14.9989 8.98239 15.2 9.00039 15.3827 9.0692C15.5654 9.13801 15.7216 9.25453 15.8315 9.40403C15.9414 9.55353 16 9.72929 16 9.90909L16 12.1818C16 12.664 15.7893 13.1265 15.4142 13.4675C15.0391 13.8084 14.5304 14 14 14"></path></svg>',hn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" points="2.65 9.5 3.5 10.5 5 8.5"></polyline></svg>',fn='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.25 12.375v1.688A1.688 1.688 0 0 0 3.938 15.75h10.124a1.688 1.688 0 0 0 1.688-1.688V12.375"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.063 6.188L9 2.25l3.938 3.938"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 2.25v10.125"></path></svg>',mn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path><circle cx="12" cy="12" r="3" fill="none"></circle></svg>';var S={bold:{name:"bold",actionId:"toggleBold",icon:nn,title:"Bold (Ctrl+B)",action:({editor:t})=>{Ee(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:on,title:"Italic (Ctrl+I)",action:({editor:t})=>{Ce(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:cn,title:"Inline Code",action:({editor:t})=>{Te(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:ln,title:"Insert Link",action:({editor:t})=>{Ae(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:rn,title:"Heading 1",action:({editor:t})=>{Pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:sn,title:"Heading 2",action:({editor:t})=>{Oe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:an,title:"Heading 3",action:({editor:t})=>{_e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:pn,title:"Bullet List",action:({editor:t})=>{Me(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:dn,title:"Numbered List",action:({editor:t})=>{$e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:hn,title:"Task List",action:({editor:t})=>{pe&&(pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:un,title:"Quote",action:({editor:t})=>{He(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:fn,title:"Upload File",action:({editor:t})=>{var n,o;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((o=t.options.fileUpload.mimeTypes)==null?void 0:o.length)>0&&(e.accept=t.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let i=new DataTransfer;for(let s of e.files)i.items.add(s);t._handleDataTransfer(i)},e.click()}},viewMode:{name:"viewMode",icon:mn,title:"View mode"}},re=[S.bold,S.italic,S.code,S.separator,S.link,S.separator,S.h1,S.h2,S.h3,S.separator,S.bulletList,S.orderedList,S.taskList,S.separator,S.quote,S.separator,S.viewMode];function nt(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let o=n.actionId||n.name;n.action&&(e[o]=n.action)}),e}function gn(t){let e=t||re;return Array.isArray(e)?e.map(n=>({name:(n==null?void 0:n.name)||null,actionId:(n==null?void 0:n.actionId)||(n==null?void 0:n.name)||null,icon:(n==null?void 0:n.icon)||null,title:(n==null?void 0:n.title)||null})):null}function mo(t,e){let n=gn(t),o=gn(e);if(n===null||o===null)return n!==o;if(n.length!==o.length)return!0;for(let i=0;i<n.length;i++){let r=n[i],s=o[i];if(r.name!==s.name||r.actionId!==s.actionId||r.icon!==s.icon||r.title!==s.title)return!0}return!1}var v=class v{constructor(e,n={}){let o=v._resolveTargets(e);if(typeof e=="string"&&o.length===0)throw new Error(`No elements found for selector: ${e}`);return o.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(n),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,n),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,n={}){this.element=e,this.instanceTheme=n.theme||null,this.options=this._mergeOptions(n),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.initGlobalListeners();let o=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");o||i?this._recoverFromDOM(o,i):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new ae(this),this._rebuildActionsMap(),this.linkTooltip=new Ue(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this._notifyChange()}_mergeOptions(e){let n={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,onRender:null,onFocus:null,onBlur:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:o,colors:i,...r}=e;return{...n,...r}}_recoverFromDOM(e,n){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(n){this.wrapper=n,this.container=document.createElement("div"),this.container.className="overtype-container";let o=this.instanceTheme||v.currentTheme||F,i=typeof o=="string"?o:o.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?U(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}n.parentNode.insertBefore(this.container,n),this.container.appendChild(n)}if(!this.wrapper){e&&e.remove(),n&&n.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this._applyInstanceCSSVars(),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||v.currentTheme||F,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let o=typeof this.instanceTheme=="string"?U(this.instanceTheme):this.instanceTheme;if(o&&o.colors){let i=Q(o.colors);this.container.style.cssText+=i}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this._applyInstanceCSSVars(),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([o,i])=>{o==="className"||o==="class"?this.textarea.className+=" "+i:o==="style"&&typeof i=="object"?Object.assign(this.textarea.style,i):this.textarea.setAttribute(o,i)}),this.preview=document.createElement("div"),this.preview.className="overtype-preview",this.preview.setAttribute("aria-hidden","true"),this.placeholderEl=document.createElement("div"),this.placeholderEl.className="overtype-placeholder",this.placeholderEl.setAttribute("aria-hidden","true"),this.placeholderEl.textContent=this.options.placeholder,this.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),this.wrapper.appendChild(this.placeholderEl),this.container.appendChild(this.wrapper),this.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()),this.element.appendChild(this.container),this.options.autoResize?this._setupAutoResize():this.container.classList.remove("overtype-auto-resize")}_configureTextarea(){this.textarea.setAttribute("autocomplete","off"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck",String(this.options.spellcheck)),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_createToolbar(){var n;let e=this.options.toolbarButtons||re;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(o=>(o==null?void 0:o.name)==="upload")){let o=e.findIndex(i=>(i==null?void 0:i.name)==="viewMode");o!==-1?(e=[...e],e.splice(o,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new Re(this,{toolbarButtons:e}),this.toolbar.create(),this._toolbarSelectionListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this._toolbarInputListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this.textarea.addEventListener("selectionchange",this._toolbarSelectionListener),this.textarea.addEventListener("input",this._toolbarInputListener)}_cleanupToolbarListeners(){this._toolbarSelectionListener&&(this.textarea.removeEventListener("selectionchange",this._toolbarSelectionListener),this._toolbarSelectionListener=null),this._toolbarInputListener&&(this.textarea.removeEventListener("input",this._toolbarInputListener),this._toolbarInputListener=null)}_rebuildActionsMap(){var e;this.actionsById=nt(re),this.options.toolbarButtons&&Object.assign(this.actionsById,nt(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,nt([S.upload]))}_applyInstanceCSSVars(){this.wrapper&&(this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.options.fontFamily&&this.wrapper.style.setProperty("--instance-font-family",this.options.fontFamily))}_applyOptions(){this._applyInstanceCSSVars(),this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_handleFilePaste(e){var n,o;(o=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,o;(o=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let o of e.files){if(o.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(o.type))continue;let i=++this._fileUploadCounter,s=`${o.type.startsWith("image/")?"!":""}[Uploading ${o.name} (#${i})...]()`;if(this.insertAtCursor(`${s}
73
- `),this.options.fileUpload.batch){n.push({file:o,placeholder:s});continue}this.options.fileUpload.onInsertFile(o).then(a=>{this.textarea.value=this.textarea.value.replace(s,a),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},a=>{console.error("OverType: File upload failed",a),this.textarea.value=this.textarea.value.replace(s,"[Upload failed]()"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}this.options.fileUpload.batch&&n.length>0&&this.options.fileUpload.onInsertFile(n.map(o=>o.file)).then(o=>{(Array.isArray(o)?o:[o]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},o=>{console.error("OverType: File upload failed",o),n.forEach(({placeholder:i})=>{this.textarea.value=this.textarea.value.replace(i,"[Upload failed]()")}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}_handleDragOver(e){e.preventDefault()}_destroyFileUpload(){this.textarea.removeEventListener("paste",this._boundHandleFilePaste),this.textarea.removeEventListener("drop",this._boundHandleFileDrop),this.textarea.removeEventListener("dragover",this._boundHandleDragOver),this._boundHandleFilePaste=null,this._boundHandleFileDrop=null,this._boundHandleDragOver=null,this.fileUploadInitialized=!1}insertAtCursor(e){let n=this.textarea.selectionStart,o=this.textarea.selectionEnd,i=!1;try{i=document.execCommand("insertText",!1,e)}catch(r){}if(!i){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(o);this.textarea.value=r+e+s,this.textarea.setSelectionRange(n+e.length,n+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,n=this.textarea.selectionStart,o=this._getCurrentLine(e,n),i=this.container.dataset.mode==="preview",r=C.parse(e,o,this.options.showActiveLineRaw,this.options.codeHighlighter,i);this.preview.innerHTML=r,this.placeholderEl&&(this.placeholderEl.style.display=e?"none":""),this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onRender&&this.options.onRender(this.preview,i?"preview":"normal",this)}_notifyChange(){!this.options.onChange||!this.initialized||this.options.onChange(this.textarea.value,this)}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let n=0;n<e.length-1;n+=2){let o=e[n],i=e[n+1],r=o.parentElement,s=i.parentElement;!r||!s||(o.style.display="block",i.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,n){return e.substring(0,n).split(`
74
- `).length-1}handleInput(e){this.updatePreview(),this._notifyChange()}handleFocus(e){this.options.onFocus&&this.options.onFocus(e,this)}handleBlur(e){this.options.onBlur&&this.options.onBlur(e,this)}handleKeydown(e){if(e.key==="Tab"){let o=this.textarea.selectionStart,i=this.textarea.selectionEnd,r=this.textarea.value;if(e.shiftKey&&o===i)return;if(e.preventDefault(),o!==i&&e.shiftKey){let s=r.substring(0,o),a=r.substring(o,i),l=r.substring(i),c=a.split(`
75
- `).map(d=>d.replace(/^ /,"")).join(`
76
- `);document.execCommand?(this.textarea.setSelectionRange(o,i),document.execCommand("insertText",!1,c)):(this.textarea.value=s+c+l,this.textarea.selectionStart=o,this.textarea.selectionEnd=o+c.length)}else if(o!==i){let s=r.substring(0,o),a=r.substring(o,i),l=r.substring(i),c=a.split(`
77
- `).map(d=>" "+d).join(`
78
- `);document.execCommand?(this.textarea.setSelectionRange(o,i),document.execCommand("insertText",!1,c)):(this.textarea.value=s+c+l,this.textarea.selectionStart=o,this.textarea.selectionEnd=o+c.length)}else document.execCommand?document.execCommand("insertText",!1," "):(this.textarea.value=r.substring(0,o)+" "+r.substring(i),this.textarea.selectionStart=this.textarea.selectionEnd=o+2);this.textarea.dispatchEvent(new Event("input",{bubbles:!0}));return}if(e.key==="Enter"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&this.options.smartLists&&this.handleSmartListContinuation()){e.preventDefault();return}!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}handleSmartListContinuation(){let e=this.textarea,n=e.selectionStart,o=C.getListContext(e.value,n);return!o||!o.inList?!1:o.content.trim()===""&&n>=o.markerEndPos?(this.deleteListMarker(o),!0):(n>o.markerEndPos&&n<o.lineEnd?this.splitListItem(o,n):this.insertNewListItem(o),o.listType==="numbered"&&this.scheduleNumberedListUpdate(),!0)}deleteListMarker(e){this.textarea.setSelectionRange(e.lineStart,e.markerEndPos),document.execCommand("delete"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}insertNewListItem(e){let n=C.createNewListItem(e);document.execCommand("insertText",!1,`
79
- `+n),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}splitListItem(e,n){let o=e.content.substring(n-e.markerEndPos);this.textarea.setSelectionRange(n,e.lineEnd),document.execCommand("delete");let i=C.createNewListItem(e);document.execCommand("insertText",!1,`
80
- `+i+o);let r=this.textarea.selectionStart-o.length;this.textarea.setSelectionRange(r,r),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}scheduleNumberedListUpdate(){this.numberUpdateTimeout&&clearTimeout(this.numberUpdateTimeout),this.numberUpdateTimeout=setTimeout(()=>{this.updateNumberedLists()},10)}updateNumberedLists(){let e=this.textarea.value,n=this.textarea.selectionStart,o=C.renumberLists(e);if(o!==e){let i=0,r=e.split(`
81
- `),s=o.split(`
82
- `),a=0;for(let p=0;p<r.length&&a<n;p++){if(r[p]!==s[p]){let c=s[p].length-r[p].length;a+r[p].length<n&&(i+=c)}a+=r[p].length+1}this.textarea.value=o;let l=n+i;this.textarea.setSelectionRange(l,l),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}}handleScroll(e){this.preview.scrollTop=this.textarea.scrollTop,this.preview.scrollLeft=this.textarea.scrollLeft}getValue(){return this.textarea.value}setValue(e){let n=this.textarea.value!==e;this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight(),n&&this._notifyChange()}async performAction(e,n=null){var r;let o=this.textarea;if(!o)return!1;let i=(r=this.actionsById)==null?void 0:r[e];if(!i)return console.warn(`OverType: Unknown action "${e}"`),!1;o.focus();try{return await i({editor:this,getValue:()=>this.getValue(),setValue:s=>this.setValue(s),event:n}),!0}catch(s){return console.error(`OverType: Action "${e}" error:`,s),this.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{actionId:e,error:s}})),!1}}getRenderedHTML(e={}){let n=this.getValue(),o=C.parse(n,-1,!1,this.options.codeHighlighter);return e.cleanHTML&&(o=o.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g,""),o=o.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g,""),o=o.replace(/\sclass=""/g,"")),o}getPreviewHTML(){return this.preview.innerHTML}getCleanHTML(){return this.getRenderedHTML({cleanHTML:!0})}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){var i;let n=(i=this.options)==null?void 0:i.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let o=this.toolbar&&this.options.toolbar&&mo(n,this.options.toolbarButtons);this._rebuildActionsMap(),o&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null,this._createToolbar()),this.fileUploadInitialized&&this._destroyFileUpload(),this.options.fileUpload&&this._initFileUpload(),this._applyOptions(),this.updatePreview()}showToolbar(){this.toolbar?this.toolbar.show():this._createToolbar()}hideToolbar(){this.toolbar&&this.toolbar.hide()}setTheme(e){if(v._autoInstances.delete(this),this.instanceTheme=e,e==="auto")v._autoInstances.add(this),v._startAutoListener(),this._applyResolvedTheme(qe("auto"));else{let n=typeof e=="string"?U(e):e,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),n&&n.colors){let i=Q(n.colors,n.previewColors);this.container.style.cssText+=i}this.updatePreview()}return v._stopAutoListener(),this}_applyResolvedTheme(e){let n=U(e);this.container.setAttribute("data-theme",e),n&&n.colors&&(this.container.style.cssText=Q(n.colors,n.previewColors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,n=e.split(`
83
- `),o=e.length,i=e.split(/\s+/).filter(c=>c.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
84
- `),l=a.length,p=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:o,words:i,lines:n.length,line:l,column:p}):this.statsBar.innerHTML=`
72
+ `,this.tooltip.addEventListener("click",e=>{if(e.preventDefault(),e.stopPropagation(),this.currentLink){let n=T.sanitizeUrl(this.currentLink.url);n!=="#"&&window.open(n,"_blank"),this.hide()}}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,n=this.editor.textarea.value,i=this.findLinkAtPosition(n,e);i?(!this.currentLink||this.currentLink.url!==i.url||this.currentLink.index!==i.index)&&this.show(i):this.scheduleHide()}findLinkAtPosition(e,n){let i=/\[([^\]]+)\]\(([^)]+)\)/g,o,r=0;for(;(o=i.exec(e))!==null;){let s=o.index,a=o.index+o[0].length;if(n>=s&&n<=a)return{text:o[1],url:this.transformUrl(o[2]),index:r,start:s,end:a};r++}return null}transformUrl(e){let n=this.editor.options.transformLinkUrl;if(typeof n!="function")return e;try{let i=n(e);return typeof i=="string"?i:e}catch(i){return console.warn("transformLinkUrl threw:",i),e}}async show(e){this.currentLink=e,this.cancelHide();let n=this.tooltip.querySelector(".overtype-link-tooltip-url");n.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let n=this.findAnchorElement(e.index);if(!n)return;let i=n.getBoundingClientRect();if(!(i.width===0||i.height===0))try{let{x:o,y:r}=await nn(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Yt(8),en({padding:8}),tn()]});Object.assign(this.tooltip.style,{left:`${o}px`,top:`${r}px`,position:"fixed"})}catch(o){console.warn("Floating UI positioning failed:",o)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var on='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z"></path></svg>',rn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line></svg>',sn='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z"></path></svg>',an='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',ln='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.65186,12.30664a2.6742,2.6742,0,0,1-2.915,2.68457,3.96592,3.96592,0,0,1-2.25537-.6709.56007.56007,0,0,1-.13232-.83594L11.64648,13c.209-.34082.48389-.36328.82471-.1543a2.32654,2.32654,0,0,0,1.12256.33008c.71484,0,1.12207-.35156,1.12207-.78125,0-.61523-.61621-.86816-1.46338-.86816H13.2085a.65159.65159,0,0,1-.68213-.41895l-.05518-.10937a.67114.67114,0,0,1,.14307-.78125l.71533-.86914a8.55289,8.55289,0,0,1,.68213-.7373V8.58887a3.93913,3.93913,0,0,1-.748.05469H11.9873a.54085.54085,0,0,1-.605-.60547V7.59863a.54085.54085,0,0,1,.605-.60547h3.75146a.53773.53773,0,0,1,.60547.59375v.17676a1.03723,1.03723,0,0,1-.27539.748L14.74854,10.0293A2.31132,2.31132,0,0,1,16.65186,12.30664ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',cn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z"></path></svg>',pn='<svg viewBox="0 0 18 18"><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line></svg>',dn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line></svg>',un='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" x1="2.5" x2="4.5" y1="5.5" y2="5.5"></line><path fill="currentColor" d="M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109"></path></svg>',hn='<svg viewBox="2 2 20 20"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 10.8182L9 10.8182C8.80222 10.8182 8.60888 10.7649 8.44443 10.665C8.27998 10.5651 8.15181 10.4231 8.07612 10.257C8.00043 10.0909 7.98063 9.90808 8.01922 9.73174C8.0578 9.55539 8.15304 9.39341 8.29289 9.26627C8.43275 9.13913 8.61093 9.05255 8.80491 9.01747C8.99889 8.98239 9.19996 9.00039 9.38268 9.0692C9.56541 9.13801 9.72159 9.25453 9.83147 9.40403C9.94135 9.55353 10 9.72929 10 9.90909L10 12.1818C10 12.664 9.78929 13.1265 9.41421 13.4675C9.03914 13.8084 8.53043 14 8 14"></path><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 10.8182L15 10.8182C14.8022 10.8182 14.6089 10.7649 14.4444 10.665C14.28 10.5651 14.1518 10.4231 14.0761 10.257C14.0004 10.0909 13.9806 9.90808 14.0192 9.73174C14.0578 9.55539 14.153 9.39341 14.2929 9.26627C14.4327 9.13913 14.6109 9.05255 14.8049 9.01747C14.9989 8.98239 15.2 9.00039 15.3827 9.0692C15.5654 9.13801 15.7216 9.25453 15.8315 9.40403C15.9414 9.55353 16 9.72929 16 9.90909L16 12.1818C16 12.664 15.7893 13.1265 15.4142 13.4675C15.0391 13.8084 14.5304 14 14 14"></path></svg>',fn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" points="2.65 9.5 3.5 10.5 5 8.5"></polyline></svg>',mn='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.25 12.375v1.688A1.688 1.688 0 0 0 3.938 15.75h10.124a1.688 1.688 0 0 0 1.688-1.688V12.375"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.063 6.188L9 2.25l3.938 3.938"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 2.25v10.125"></path></svg>',gn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path><circle cx="12" cy="12" r="3" fill="none"></circle></svg>';var S={bold:{name:"bold",actionId:"toggleBold",icon:on,title:"Bold (Ctrl+B)",isActive:({activeFormats:t})=>t.includes("bold"),action:({editor:t})=>{Te(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:rn,title:"Italic (Ctrl+I)",isActive:({activeFormats:t})=>t.includes("italic"),action:({editor:t})=>{Ae(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:pn,title:"Inline Code",isActive:()=>!1,action:({editor:t})=>{Ce(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:cn,title:"Insert Link",action:({editor:t})=>{Ie(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:sn,title:"Heading 1",isActive:({activeFormats:t})=>t.includes("header"),action:({editor:t})=>{He(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:an,title:"Heading 2",isActive:({activeFormats:t})=>t.includes("header-2"),action:({editor:t})=>{$e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:ln,title:"Heading 3",isActive:({activeFormats:t})=>t.includes("header-3"),action:({editor:t})=>{Oe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:dn,title:"Bullet List",isActive:({activeFormats:t})=>t.includes("bullet-list"),action:({editor:t})=>{Me(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:un,title:"Numbered List",isActive:({activeFormats:t})=>t.includes("numbered-list"),action:({editor:t})=>{_e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:fn,title:"Task List",isActive:({activeFormats:t})=>t.includes("task-list"),action:({editor:t})=>{pe&&(pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:hn,title:"Quote",isActive:({activeFormats:t})=>t.includes("quote"),action:({editor:t})=>{Pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:mn,title:"Upload File",action:({editor:t})=>{var n,i;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((i=t.options.fileUpload.mimeTypes)==null?void 0:i.length)>0&&(e.accept=t.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let o=new DataTransfer;for(let s of e.files)o.items.add(s);t._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:gn,title:"View mode"}},re=[S.bold,S.italic,S.code,S.separator,S.link,S.separator,S.h1,S.h2,S.h3,S.separator,S.bulletList,S.orderedList,S.taskList,S.separator,S.quote,S.separator,S.viewMode];var be;function mi(){if(be!==void 0)return be;if(be=!1,typeof navigator<"u"){let t=navigator.userAgent||"";be=/^((?!chrome|android|crios|fxios|edg|opr).)*safari/i.test(t)||/iPad|iPhone|iPod/.test(t)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1&&/Safari/.test(t)}return be}function it(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let i=n.actionId||n.name;n.action&&(e[i]=n.action)}),e}function vn(t){let e=t||re;return Array.isArray(e)?e.map(n=>({name:(n==null?void 0:n.name)||null,actionId:(n==null?void 0:n.actionId)||(n==null?void 0:n.name)||null,icon:(n==null?void 0:n.icon)||null,title:(n==null?void 0:n.title)||null})):null}function gi(t,e){let n=vn(t),i=vn(e);if(n===null||i===null)return n!==i;if(n.length!==i.length)return!0;for(let o=0;o<n.length;o++){let r=n[o],s=i[o];if(r.name!==s.name||r.actionId!==s.actionId||r.icon!==s.icon||r.title!==s.title)return!0}return!1}var g=class g{constructor(e,n={}){let i=g._resolveTargets(e);if(typeof e=="string"&&i.length===0)throw new Error(`No elements found for selector: ${e}`);return i.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(n),r.overTypeInstance;let s=Object.create(g.prototype);return s._init(r,n),r.overTypeInstance=s,g.instances.set(r,s),s})}_init(e,n={}){this.element=e,this.instanceTheme=n.theme||null,this.options=this._mergeOptions(n),this.instanceId=++g.instanceCount,this.initialized=!1,this._isSafari=mi(),this._safariReflowRaf=null,g.injectStyles(),g.initGlobalListeners();let i=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");i||o?this._recoverFromDOM(i,o):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new ae(this),this._rebuildActionsMap(),this.linkTooltip=new We(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this._notifyChange()}_mergeOptions(e){let n={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,onRender:null,onFocus:null,onBlur:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1,transformLinkUrl:null},{theme:i,colors:o,...r}=e;return{...n,...r}}_recoverFromDOM(e,n){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(n){this.wrapper=n,this.container=document.createElement("div"),this.container.className="overtype-container";let i=this.instanceTheme||g.currentTheme||D,o=typeof i=="string"?i:i.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?U(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}n.parentNode.insertBefore(this.container,n),this.container.appendChild(n)}if(!this.wrapper){e&&e.remove(),n&&n.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this._applyInstanceCSSVars(),this._configureTextarea(),this._ensureTextareaId(),this._syncPreviewInteractivity(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||g.currentTheme||D,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let i=typeof this.instanceTheme=="string"?U(this.instanceTheme):this.instanceTheme;if(i&&i.colors){let o=Q(i.colors);this.container.style.cssText+=o}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this._applyInstanceCSSVars(),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([i,o])=>{i==="className"||i==="class"?this.textarea.className+=" "+o:i==="style"&&typeof o=="object"?Object.assign(this.textarea.style,o):this.textarea.setAttribute(i,o)}),this._ensureTextareaId(),this.preview=document.createElement("div"),this.preview.className="overtype-preview",this.preview.setAttribute("aria-hidden","true"),this.placeholderEl=document.createElement("div"),this.placeholderEl.className="overtype-placeholder",this.placeholderEl.setAttribute("aria-hidden","true"),this.placeholderEl.textContent=this.options.placeholder,this.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),this.wrapper.appendChild(this.placeholderEl),this.container.appendChild(this.wrapper),this.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()),this.element.appendChild(this.container),this.options.autoResize?this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this._syncPreviewInteractivity()}_configureTextarea(){this.textarea.setAttribute("autocomplete","off"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck",String(this.options.spellcheck)),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_ensureTextareaId(){this.textarea.id||(this.textarea.id=`overtype-${this.instanceId}-input`)}_syncPreviewInteractivity(){if(!this.preview||!this.container)return;let e=this.container.dataset.mode==="preview";if(this.preview.inert=!e,this.preview.toggleAttribute("inert",!e),e){this.preview.removeAttribute("aria-hidden");return}this.preview.setAttribute("aria-hidden","true")}_createToolbar(){var n;let e=this.options.toolbarButtons||re;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(i=>(i==null?void 0:i.name)==="upload")){let i=e.findIndex(o=>(o==null?void 0:o.name)==="viewMode");i!==-1?(e=[...e],e.splice(i,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new Be(this,{toolbarButtons:e}),this.toolbar.create(),this._toolbarSelectionListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this._toolbarInputListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this.textarea.addEventListener("selectionchange",this._toolbarSelectionListener),this.textarea.addEventListener("input",this._toolbarInputListener)}_cleanupToolbarListeners(){this._toolbarSelectionListener&&(this.textarea.removeEventListener("selectionchange",this._toolbarSelectionListener),this._toolbarSelectionListener=null),this._toolbarInputListener&&(this.textarea.removeEventListener("input",this._toolbarInputListener),this._toolbarInputListener=null)}_rebuildActionsMap(){var e;this.actionsById=it(re),this.options.toolbarButtons&&Object.assign(this.actionsById,it(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,it([S.upload]))}_applyInstanceCSSVars(){this.wrapper&&(this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.options.fontFamily&&this.wrapper.style.setProperty("--instance-font-family",this.options.fontFamily))}_applyOptions(){this._applyInstanceCSSVars(),this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._uploadedFiles=new Map,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_extractMarkdownUrls(e){let n=[],i=/!?\[[^\]]*\]\(([^)\s]+)/g,o;for(;(o=i.exec(e))!==null;)n.push(o[1]);return n}_trackInsertedUrls(e,n){if(!(!this._uploadedFiles||!n||!e))for(let i of this._extractMarkdownUrls(e))this._uploadedFiles.set(i,{filename:n.name,file:n})}_checkForRemovedUploads(){var o;if(!this._uploadedFiles||this._uploadedFiles.size===0)return;let e=(o=this.options.fileUpload)==null?void 0:o.onRemoveFile,n=this.textarea.value,i=[];for(let[r,s]of this._uploadedFiles)n.includes(r)||i.push({url:r,info:s});for(let{url:r,info:s}of i)this._uploadedFiles.delete(r),e&&e({url:r,filename:s.filename,file:s.file})}_handleFilePaste(e){var n,i;(i=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,i;(i=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let i of e.files){if(i.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(i.type))continue;let o=++this._fileUploadCounter,s=`${i.type.startsWith("image/")?"!":""}[Uploading ${i.name} (#${o})...]()`;if(this.insertAtCursor(`${s}
73
+ `),this.options.fileUpload.batch){n.push({file:i,placeholder:s});continue}this.options.fileUpload.onInsertFile(i).then(a=>{this.textarea.value=this.textarea.value.replace(s,a),this._trackInsertedUrls(a,i),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},a=>{console.error("OverType: File upload failed",a),this.textarea.value=this.textarea.value.replace(s,"[Upload failed]()"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}this.options.fileUpload.batch&&n.length>0&&this.options.fileUpload.onInsertFile(n.map(i=>i.file)).then(i=>{(Array.isArray(i)?i:[i]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r),this._trackInsertedUrls(r,n[s].file)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},i=>{console.error("OverType: File upload failed",i),n.forEach(({placeholder:o})=>{this.textarea.value=this.textarea.value.replace(o,"[Upload failed]()")}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}_handleDragOver(e){e.preventDefault()}_destroyFileUpload(){this.textarea.removeEventListener("paste",this._boundHandleFilePaste),this.textarea.removeEventListener("drop",this._boundHandleFileDrop),this.textarea.removeEventListener("dragover",this._boundHandleDragOver),this._boundHandleFilePaste=null,this._boundHandleFileDrop=null,this._boundHandleDragOver=null,this._uploadedFiles=null,this.fileUploadInitialized=!1}insertAtCursor(e){let n=this.textarea.selectionStart,i=this.textarea.selectionEnd,o=!1;try{o=document.execCommand("insertText",!1,e)}catch(r){}if(!o){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(i);this.textarea.value=r+e+s,this.textarea.setSelectionRange(n+e.length,n+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,n=this.textarea.selectionStart,i=this._getCurrentLine(e,n),o=this.container.dataset.mode==="preview",r=T.parse(e,i,this.options.showActiveLineRaw,this.options.codeHighlighter,o);this.preview.innerHTML=r,this.placeholderEl&&(this.placeholderEl.style.display=e?"none":""),this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onRender&&this.options.onRender(this.preview,o?"preview":"normal",this)}_notifyChange(){this.initialized&&(this._checkForRemovedUploads(),this.options.onChange&&this.options.onChange(this.textarea.value,this))}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let n=0;n<e.length-1;n+=2){let i=e[n],o=e[n+1],r=i.parentElement,s=o.parentElement;!r||!s||(i.style.display="block",o.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,n){return e.substring(0,n).split(`
74
+ `).length-1}handleInput(e){this.updatePreview(),this._notifyChange(),this._scheduleSafariReflow()}_scheduleSafariReflow(){!this._isSafari||this._safariReflowRaf||(this._safariReflowRaf=requestAnimationFrame(()=>{this._safariReflowRaf=null;let e=this.textarea;e&&(e.style.setProperty("letter-spacing","-0.001px","important"),e.offsetHeight,e.style.removeProperty("letter-spacing"))}))}handleFocus(e){this.options.onFocus&&this.options.onFocus(e,this)}handleBlur(e){this.options.onBlur&&this.options.onBlur(e,this)}handleKeydown(e){if(e.key==="Tab"){let i=this.textarea.selectionStart,o=this.textarea.selectionEnd;if(i!==o&&this._canEditTextarea()){e.preventDefault(),e.shiftKey?this.outdentSelection():this.indentSelection();return}}if(e.key==="Enter"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&this.options.smartLists&&this.handleSmartListContinuation()){e.preventDefault();return}!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}handleSmartListContinuation(){let e=this.textarea,n=e.selectionStart,i=T.getListContext(e.value,n);return!i||!i.inList?!1:i.content.trim()===""&&n>=i.markerEndPos?(this.deleteListMarker(i),!0):(n>i.markerEndPos&&n<i.lineEnd?this.splitListItem(i,n):this.insertNewListItem(i),i.listType==="numbered"&&this.scheduleNumberedListUpdate(),!0)}deleteListMarker(e){this.textarea.setSelectionRange(e.lineStart,e.markerEndPos),document.execCommand("delete"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}insertNewListItem(e){let n=T.createNewListItem(e);document.execCommand("insertText",!1,`
75
+ `+n),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}splitListItem(e,n){let i=e.content.substring(n-e.markerEndPos);this.textarea.setSelectionRange(n,e.lineEnd),document.execCommand("delete");let o=T.createNewListItem(e);document.execCommand("insertText",!1,`
76
+ `+o+i);let r=this.textarea.selectionStart-i.length;this.textarea.setSelectionRange(r,r),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}scheduleNumberedListUpdate(){this.numberUpdateTimeout&&clearTimeout(this.numberUpdateTimeout),this.numberUpdateTimeout=setTimeout(()=>{this.updateNumberedLists()},10)}updateNumberedLists(){let e=this.textarea.value,n=this.textarea.selectionStart,i=T.renumberLists(e);if(i!==e){let o=0,r=e.split(`
77
+ `),s=i.split(`
78
+ `),a=0;for(let c=0;c<r.length&&a<n;c++){if(r[c]!==s[c]){let p=s[c].length-r[c].length;a+r[c].length<n&&(o+=p)}a+=r[c].length+1}this.textarea.value=i;let l=n+o;this.textarea.setSelectionRange(l,l),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}}handleScroll(e){this.preview.scrollTop=this.textarea.scrollTop,this.preview.scrollLeft=this.textarea.scrollLeft}getValue(){return this.textarea.value}setValue(e){let n=this.textarea.value!==e;this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight(),n&&(this._notifyChange(),this._scheduleSafariReflow())}async performAction(e,n=null){var r;let i=this.textarea;if(!i)return!1;let o=(r=this.actionsById)==null?void 0:r[e];if(!o)return console.warn(`OverType: Unknown action "${e}"`),!1;i.focus();try{return await o({editor:this,getValue:()=>this.getValue(),setValue:s=>this.setValue(s),event:n}),!0}catch(s){return console.error(`OverType: Action "${e}" error:`,s),this.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{actionId:e,error:s}})),!1}}getRenderedHTML(e={}){let n=this.getValue(),i=T.parse(n,-1,!1,this.options.codeHighlighter);return e.cleanHTML&&(i=i.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g,""),i=i.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g,""),i=i.replace(/\sclass=""/g,"")),i}getPreviewHTML(){return this.preview.innerHTML}indentSelection(){this._replaceSelectedLines(e=>` ${e}`)}outdentSelection(){this._replaceSelectedLines(e=>e.replace(/^( {1,2}|\t)/,""))}_replaceSelectedLines(e){if(!this._canEditTextarea())return!1;let n=this.textarea,{selectionStart:i,selectionEnd:o,value:r}=n,s=r.lastIndexOf(`
79
+ `,i-1)+1,a=this._effectiveSelectionEnd(r,i,o),l=r.indexOf(`
80
+ `,a),c=l===-1?r.length:l,p=r.slice(s,c),d=p.split(`
81
+ `).map(e).join(`
82
+ `);if(d===p)return!1;n.setSelectionRange(s,c);let u=!1;try{u=document.execCommand("insertText",!1,d)}catch(h){}return u||n.setRangeText(d,s,c,"preserve"),n.setSelectionRange(s,s+d.length),n.dispatchEvent(new Event("input",{bubbles:!0})),!0}_effectiveSelectionEnd(e,n,i){return i>n&&e[i-1]===`
83
+ `?i-1:i}_canEditTextarea(){return this.textarea&&!this.textarea.disabled&&!this.textarea.readOnly}getCleanHTML(){return this.getRenderedHTML({cleanHTML:!0})}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){var o;let n=(o=this.options)==null?void 0:o.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let i=this.toolbar&&this.options.toolbar&&gi(n,this.options.toolbarButtons);this._rebuildActionsMap(),i&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null,this._createToolbar()),this.fileUploadInitialized&&this._destroyFileUpload(),this.options.fileUpload&&this._initFileUpload(),this._applyOptions(),this.updatePreview()}showToolbar(){this.toolbar?this.toolbar.show():this._createToolbar()}hideToolbar(){this.toolbar&&this.toolbar.hide()}setTheme(e){if(g._autoInstances.delete(this),this.instanceTheme=e,e==="auto")g._autoInstances.add(this),g._startAutoListener(),this._applyResolvedTheme(Ke("auto"));else{let n=typeof e=="string"?U(e):e,i=typeof n=="string"?n:n.name;if(i&&this.container.setAttribute("data-theme",i),n&&n.colors){let o=Q(n.colors,n.previewColors);this.container.style.cssText+=o}this.updatePreview()}return g._stopAutoListener(),this}_applyResolvedTheme(e){let n=U(e);this.container.setAttribute("data-theme",e),n&&n.colors&&(this.container.style.cssText=Q(n.colors,n.previewColors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,n=e.split(`
84
+ `),i=e.length,o=e.split(/\s+/).filter(p=>p.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
85
+ `),l=a.length,c=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:i,words:o,lines:n.length,line:l,column:c}):this.statsBar.innerHTML=`
85
86
  <div class="overtype-stat">
86
87
  <span class="live-dot"></span>
87
- <span>${o} chars, ${i} words, ${n.length} lines</span>
88
+ <span>${i} chars, ${o} words, ${n.length} lines</span>
88
89
  </div>
89
- <div class="overtype-stat">Line ${l}, Col ${p}</div>
90
- `}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,n=this.preview,o=this.wrapper;if(this.container.dataset.mode==="preview"){o.style.removeProperty("height"),n.style.removeProperty("height"),n.style.removeProperty("overflow-y"),e.style.removeProperty("height"),e.style.removeProperty("overflow-y");return}let r=e.scrollTop;o.style.setProperty("height","auto","important"),e.style.setProperty("height","auto","important");let s=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);s=Math.max(s,p)}let a="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);s>p&&(s=p,a="auto")}let l=s+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",a,"important"),n.style.setProperty("height",l,"important"),n.style.setProperty("overflow-y",a,"important"),o.style.setProperty("height",l,"important"),e.scrollTop=r,n.scrollTop=r,this.previousHeight!==s&&(this.previousHeight=s)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this.updatePreview(),this._updateAutoHeight(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this._updateAutoHeight(),this.toolbar){let e=this.container.querySelector('[data-action="toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this.updatePreview(),this._updateAutoHeight(),this}destroy(){if(v._autoInstances.delete(this),v._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,v.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,n={}){return new v(e,n)}static initFromData(e,n={}){return v._resolveTargets(e).map(i=>{let r={...n};for(let s of i.attributes)if(s.name.startsWith("data-ot-")){let l=s.name.slice(8).replace(/-([a-z])/g,(p,c)=>c.toUpperCase());r[l]=v._parseDataValue(s.value)}return new v(i,r)[0]})}static _resolveTargets(e){if(e==null)throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");if(typeof e=="string")return Array.from(document.querySelectorAll(e));if(e instanceof Element)return[e];if(e instanceof NodeList)return Array.from(e);if(Array.isArray(e))return e;if(typeof e.length=="number")return Array.from(e);throw new Error("Invalid target: must be selector string, Element, NodeList, or Array")}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){let n;return e instanceof Element?n=e:n=v._resolveTargets(e)[0],n&&(n.overTypeInstance||v.instances.get(n))||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(n=>{let o=v.getInstance(n);o&&o.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let n=document.querySelector("style.overtype-styles");n&&n.remove();let o=v.currentTheme||F,i=pt({theme:o}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,n=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=n,v._startAutoListener(),v._applyGlobalTheme(qe("auto"),n);return}v._stopAutoListener(),v._applyGlobalTheme(e,n)}static _applyGlobalTheme(e,n=null){let o=typeof e=="string"?U(e):e;n&&(o=ct(o,n)),v.currentTheme=o,v.injectStyles(!0);let i=typeof o=="string"?o:o.name;document.querySelectorAll(".overtype-container").forEach(r=>{i&&r.setAttribute("data-theme",i)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||i&&r.setAttribute("data-theme",i);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{i&&typeof r.setAttribute=="function"&&r.setAttribute("theme",i),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let n=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(n,v._globalAutoCustomColors),v._autoInstances.forEach(o=>o._applyResolvedTheme(n))},v._autoMediaQuery.addEventListener("change",v._autoMediaListener))}static _stopAutoListener(){v._autoInstances.size>0||v._globalAutoTheme||v._autoMediaQuery&&(v._autoMediaQuery.removeEventListener("change",v._autoMediaListener),v._autoMediaQuery=null,v._autoMediaListener=null)}static setCodeHighlighter(e){C.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static setCustomSyntax(e){C.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleKeydown(e)}}),document.addEventListener("focus",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleFocus(e)}},!0),document.addEventListener("blur",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleBlur(e)}},!0),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let n=document.activeElement;if(n&&n.classList.contains("overtype-input")){let o=n.closest(".overtype-wrapper"),i=o==null?void 0:o._instance;i&&(i.options.showStats&&i.statsBar&&i._updateStats(),clearTimeout(i._selectionTimeout),i._selectionTimeout=setTimeout(()=>{i.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};T(v,"instances",new WeakMap),T(v,"stylesInjected",!1),T(v,"globalListenersInitialized",!1),T(v,"instanceCount",0),T(v,"_autoMediaQuery",null),T(v,"_autoMediaListener",null),T(v,"_autoInstances",new Set),T(v,"_globalAutoTheme",!1),T(v,"_globalAutoCustomColors",null);var j=v;j.MarkdownParser=C;j.ShortcutsManager=ae;j.themes={solar:F,cave:U("cave")};j.getTheme=U;j.currentTheme=F;var go=j;return Ln(vo);})();
90
+ <div class="overtype-stat">Line ${l}, Col ${c}</div>
91
+ `}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,n=this.preview,i=this.wrapper;if(this.container.dataset.mode==="preview"){i.style.removeProperty("height"),n.style.removeProperty("height"),n.style.removeProperty("overflow-y"),e.style.removeProperty("height"),e.style.removeProperty("overflow-y");return}let r=e.scrollTop;i.style.setProperty("height","auto","important"),e.style.setProperty("height","auto","important");let s=e.scrollHeight;if(this.options.minHeight){let c=parseInt(this.options.minHeight);s=Math.max(s,c)}let a="hidden";if(this.options.maxHeight){let c=parseInt(this.options.maxHeight);s>c&&(s=c,a="auto")}let l=s+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",a,"important"),n.style.setProperty("height",l,"important"),n.style.setProperty("overflow-y",a,"important"),i.style.setProperty("height",l,"important"),e.scrollTop=r,n.scrollTop=r,this.previousHeight!==s&&(this.previousHeight=s)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this._syncPreviewInteractivity(),this.updatePreview(),this._updateAutoHeight(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this._syncPreviewInteractivity(),this._updateAutoHeight(),this.toolbar){let e=this.container.querySelector('[data-action="toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this._syncPreviewInteractivity(),this.updatePreview(),this._updateAutoHeight(),this}destroy(){if(g._autoInstances.delete(this),g._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,g.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this._safariReflowRaf&&(cancelAnimationFrame(this._safariReflowRaf),this._safariReflowRaf=null),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,n={}){return new g(e,n)}static initFromData(e,n={}){return g._resolveTargets(e).map(o=>{let r={...n};for(let s of o.attributes){if(!s.name.startsWith("data-ot-"))continue;let a=s.name.slice(8);if(a.startsWith("textarea-")&&a!=="textarea-props"){let c=a.slice(9).replace(/-([a-z])/g,(p,d)=>d.toUpperCase());r.textareaProps={...r.textareaProps||{},[c]:g._parseDataValue(s.value)};continue}let l=a.replace(/-([a-z])/g,(c,p)=>p.toUpperCase());r[l]=g._parseDataValue(s.value)}return new g(o,r)[0]})}static _resolveTargets(e){if(e==null)throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");if(typeof e=="string")return Array.from(document.querySelectorAll(e));if(e instanceof Element)return[e];if(e instanceof NodeList)return Array.from(e);if(Array.isArray(e))return e;if(typeof e.length=="number")return Array.from(e);throw new Error("Invalid target: must be selector string, Element, NodeList, or Array")}static _parseDataValue(e){if(e==="true")return!0;if(e==="false")return!1;if(e==="null")return null;if(e!==""&&!isNaN(Number(e)))return Number(e);let n=e.trim();if(n[0]==="{"||n[0]==="[")try{return JSON.parse(n)}catch(i){return e}return e}static getInstance(e){let n;return e instanceof Element?n=e:n=g._resolveTargets(e)[0],n&&(n.overTypeInstance||g.instances.get(n))||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(n=>{let i=g.getInstance(n);i&&i.destroy()})}static injectStyles(e=!1){if(g.stylesInjected&&!e)return;let n=document.querySelector("style.overtype-styles");n&&n.remove();let i=g.currentTheme||D,o=dt({theme:i}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),g.stylesInjected=!0}static setTheme(e,n=null){if(g._globalAutoTheme=!1,g._globalAutoCustomColors=null,e==="auto"){g._globalAutoTheme=!0,g._globalAutoCustomColors=n,g._startAutoListener(),g._applyGlobalTheme(Ke("auto"),n);return}g._stopAutoListener(),g._applyGlobalTheme(e,n)}static _applyGlobalTheme(e,n=null){let i=typeof e=="string"?U(e):e;n&&(i=pt(i,n)),g.currentTheme=i,g.injectStyles(!0);let o=typeof i=="string"?i:i.name;document.querySelectorAll(".overtype-container").forEach(r=>{o&&r.setAttribute("data-theme",o)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||o&&r.setAttribute("data-theme",o);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{o&&typeof r.setAttribute=="function"&&r.setAttribute("theme",o),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){g._autoMediaQuery||window.matchMedia&&(g._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),g._autoMediaListener=e=>{let n=e.matches?"cave":"solar";g._globalAutoTheme&&g._applyGlobalTheme(n,g._globalAutoCustomColors),g._autoInstances.forEach(i=>i._applyResolvedTheme(n))},g._autoMediaQuery.addEventListener("change",g._autoMediaListener))}static _stopAutoListener(){g._autoInstances.size>0||g._globalAutoTheme||g._autoMediaQuery&&(g._autoMediaQuery.removeEventListener("change",g._autoMediaListener),g._autoMediaQuery=null,g._autoMediaListener=null)}static setCodeHighlighter(e){T.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let i=n._instance;i&&i.updatePreview&&i.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let i=n.getEditor();i&&i.updatePreview&&i.updatePreview()}})}static setCustomSyntax(e){T.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let i=n._instance;i&&i.updatePreview&&i.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let i=n.getEditor();i&&i.updatePreview&&i.updatePreview()}})}static initGlobalListeners(){let e=typeof window<"u"?window:globalThis,n="__overtypeGlobalListenersInitialized";if(g.globalListenersInitialized||e[n]){g.globalListenersInitialized=!0;return}e[n]=!0,document.addEventListener("input",i=>{if(i.target&&i.target.classList&&i.target.classList.contains("overtype-input")){let o=i.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleInput(i)}}),document.addEventListener("keydown",i=>{if(i.target&&i.target.classList&&i.target.classList.contains("overtype-input")){let o=i.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleKeydown(i)}}),document.addEventListener("focus",i=>{if(i.target&&i.target.classList&&i.target.classList.contains("overtype-input")){let o=i.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleFocus(i)}},!0),document.addEventListener("blur",i=>{if(i.target&&i.target.classList&&i.target.classList.contains("overtype-input")){let o=i.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleBlur(i)}},!0),document.addEventListener("scroll",i=>{if(i.target&&i.target.classList&&i.target.classList.contains("overtype-input")){let o=i.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleScroll(i)}},!0),document.addEventListener("selectionchange",i=>{let o=document.activeElement;if(o&&o.classList.contains("overtype-input")){let r=o.closest(".overtype-wrapper"),s=r==null?void 0:r._instance;s&&(s.options.showStats&&s.statsBar&&s._updateStats(),clearTimeout(s._selectionTimeout),s._selectionTimeout=setTimeout(()=>{s.updatePreview()},50))}}),g.globalListenersInitialized=!0}};A(g,"instances",new WeakMap),A(g,"stylesInjected",!1),A(g,"globalListenersInitialized",!1),A(g,"instanceCount",0),A(g,"_autoMediaQuery",null),A(g,"_autoMediaListener",null),A(g,"_autoInstances",new Set),A(g,"_globalAutoTheme",!1),A(g,"_globalAutoCustomColors",null);var z=g;z.MarkdownParser=T;z.ShortcutsManager=ae;z.themes={solar:D,cave:U("cave")};z.getTheme=U;z.currentTheme=D;var vi=z;return Sn(yi);})();
91
92
  /**
92
93
  * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
93
94
  * @version 1.0.0