overtype 2.3.10 → 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.10
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 OverTypeEditor=(()=>{var ke=Object.defineProperty;var xn=Object.getOwnPropertyDescriptor;var kn=Object.getOwnPropertyNames;var Ln=Object.prototype.hasOwnProperty;var Sn=(n,e,t)=>e in n?ke(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var lt=(n,e)=>{for(var t in e)ke(n,t,{get:e[t],enumerable:!0})},_n=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of kn(e))!Ln.call(n,o)&&o!==t&&ke(n,o,{get:()=>e[o],enumerable:!(i=xn(e,o))||i.enumerable});return n};var En=n=>_n(ke({},"__esModule",{value:!0}),n);var C=(n,e,t)=>(Sn(n,typeof e!="symbol"?e+"":e,t),t);var xi={};lt(xi,{default:()=>bi});var E=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 t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,i=>t[i])}static preserveIndentation(e,t){let o=t.match(/^(\s*)/)[1].replace(/ /g,"&nbsp;");return e.replace(/^\s*/,o)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,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; (.+)$/,(t,i)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${i}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*+])\s(.+)$/,(t,i,o,r)=>(r=this.parseInlineElements(r),`${i}<li class="bullet-list"><span class="syntax-marker">${o} </span>${r}</li>`))}static parseTaskList(e,t=!1){return e.replace(/^((?:&nbsp;)*)-(\s+)\[([ xX])\](\s*)(.*)$/,(i,o,r,s,a,l)=>{if(l=this.parseInlineElements(l),t){let p=s.toLowerCase()==="x";return`${o}<li class="task-list"><input type="checkbox" ${p?"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(.+)$/,(t,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 t=e.trim(),i=t.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>i.startsWith(a)),s=t.startsWith("/")||t.startsWith("#")||t.startsWith("?")||t.startsWith(".")||!t.includes(":")&&!t.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(t,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 t=new Map,i=0,o=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let h=a.index+a[0].indexOf("](")+2,u=h+a[2].length;r.push({start:h,end:u})}let l=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),p,c=[];for(;(p=l.exec(e))!==null;){let d=p.index,h=p.index+p[0].length;r.some(f=>d>=f.start&&h<=f.end)||c.push({match:p[0],index:p.index,openTicks:p[1],content:p[2],closeTicks:p[3]})}return c.sort((d,h)=>h.index-d.index),c.forEach(d=>{let h=`\uE000${i++}\uE001`;t.set(h,{type:"code",original:d.match,openTicks:d.openTicks,content:d.content,closeTicks:d.closeTicks}),o=o.substring(0,d.index)+h+o.substring(d.index+d.match.length)}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(d,h,u)=>{let f=`\uE000${i++}\uE001`;return t.set(f,{type:"link",original:d,linkText:h,url:u}),f}),{protectedText:o,sanctuaries:t}}static restoreAndTransformSanctuaries(e,t){return Array.from(t.keys()).sort((o,r)=>{let s=e.indexOf(o),a=e.indexOf(r);return s-a}).forEach(o=>{let r=t.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;t.forEach((c,d)=>{if(a.includes(d)&&c.type==="code"){let h=`<code><span class="syntax-marker">${c.openTicks}</span>${c.content}<span class="syntax-marker">${c.closeTicks}</span></code>`;a=a.replace(d,h)}}),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:t,sanctuaries:i}=this.identifyAndProtectSanctuaries(e),o=t;return o=this.parseStrikethrough(o),o=this.parseBold(o),o=this.parseItalic(o),o=this.restoreAndTransformSanctuaries(o,i),o}static parseLine(e,t=!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,t),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,t=-1,i=!1,o,r=!1){this.resetLinkIndex();let s=e.split(`
9
- `),a=!1,p=s.map((c,d)=>{if(i&&d===t)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 u=this.escapeHtml(c);return`<div>${this.preserveIndentation(u,c)||"&nbsp;"}</div>`}return this.applyCustomSyntax(this.parseLine(c,r))}).join("");return this.postProcessHTML(p,o)}static postProcessHTML(e,t){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,t);let i=document.createElement("div");i.innerHTML=e;let o=null,r=null,s=null,a=!1,l=Array.from(i.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 u=d.textContent;if(u.startsWith("```"))if(a){let f=t||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=u.slice(3).trim();m&&(f.className=`language-${m}`),i.insertBefore(s,c.nextSibling),s._codeElement=f,s._language=m,s._codeContent="";continue}}if(a&&s&&c.tagName==="DIV"&&!c.querySelector(".code-fence")){let u=s._codeElement||s.querySelector("code");s._codeContent.length>0&&(s._codeContent+=`
10
- `);let f=c.textContent.replace(/\u00A0/g," ");s._codeContent+=f,u.textContent.length>0&&(u.textContent+=`
11
- `),u.textContent+=f,c.remove();continue}let h=null;if(c.tagName==="DIV"&&(h=c.querySelector("li")),h){let u=h.classList.contains("bullet-list"),f=h.classList.contains("ordered-list");if(!u&&!f){o=null,r=null;continue}let m=u?"ul":"ol";(!o||r!==m)&&(o=document.createElement(m),i.insertBefore(o,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===h)break;g.forEach(y=>{h.insertBefore(y,h.firstChild)}),o.appendChild(h),c.remove()}else o=null,r=null}return i.innerHTML}static postProcessHTMLManual(e,t){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 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}),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 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 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 c=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(g=>g.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
12
- `),d=s.slice(3).trim(),h=d?` class="language-${d}"`:"",u=c,f=t||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()&&(u=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${h}>${u}</code></pre>`,m+=`<div><span class="code-fence">${l}</span></div>`,m}),i}static getListContext(e,t){let i=e.split(`
13
- `),o=0,r=0,s=0;for(let h=0;h<i.length;h++){let u=i[h].length;if(o+u>=t){r=h,s=o;break}o+=u+1}let a=i[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 t=e.split(`
14
- `),i=new Map,o=!1;return t.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let l=a[1],p=l.length,c=a[3];o||i.clear();let d=(i.get(p)||0)+1;i.set(p,d);for(let[h]of i)h>p&&i.delete(h);return o=!0,`${l}${d}. ${c}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,i.clear()),s}).join(`
15
- `)}};C(E,"linkIndex",0),C(E,"codeHighlighter",null),C(E,"customSyntax",null),C(E,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;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 z={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"}},ct={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"}},pt={solar:z,cave:ct,auto:z,light:z,dark:ct};function R(n){return typeof n=="string"?{...pt[n]||pt.solar,name:n}:n}function Ze(n){if(n!=="auto")return n;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(n,e){let t=[];for(let[i,o]of Object.entries(n)){let r=i.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`--${r}: ${o};`)}if(e)for(let[i,o]of Object.entries(e)){let r=i.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`--preview-${r}-default: ${o};`)}return t.join(`
16
- `)}function dt(n,e={},t={}){return{...n,colors:{...n.colors,...e},previewColors:{...n.previewColors,...t}}}function Le(n={}){let{fontSize:e="14px",lineHeight:t=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={}}=n,a=Object.keys(s).length>0?`
8
+ var OverTypeEditor=(()=>{var Se=Object.defineProperty;var xi=Object.getOwnPropertyDescriptor;var ki=Object.getOwnPropertyNames;var Si=Object.prototype.hasOwnProperty;var Li=(i,e,t)=>e in i?Se(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var ct=(i,e)=>{for(var t in e)Se(i,t,{get:e[t],enumerable:!0})},_i=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ki(e))!Si.call(i,o)&&o!==t&&Se(i,o,{get:()=>e[o],enumerable:!(n=xi(e,o))||n.enumerable});return i};var Ei=i=>_i(Se({},"__esModule",{value:!0}),i);var A=(i,e,t)=>(Li(i,typeof e!="symbol"?e+"":e,t),t);var Sn={};ct(Sn,{default:()=>kn});var E=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 t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,n=>t[n])}static preserveIndentation(e,t){let o=t.match(/^(\s*)/)[1].replace(/ /g,"&nbsp;");return e.replace(/^\s*/,o)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,n,o)=>{let r=n.length;return o=this.parseInlineElements(o),`<h${r}><span class="syntax-marker">${n} </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; (.+)$/,(t,n)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${n}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*+])\s(.+)$/,(t,n,o,r)=>(r=this.parseInlineElements(r),`${n}<li class="bullet-list"><span class="syntax-marker">${o} </span>${r}</li>`))}static parseTaskList(e,t=!1){return e.replace(/^((?:&nbsp;)*)-(\s+)\[([ xX])\](\s*)(.*)$/,(n,o,r,s,a,l)=>{if(l=this.parseInlineElements(l),t){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(.+)$/,(t,n,o,r)=>(r=this.parseInlineElements(r),`${n}<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 t=e.trim(),n=t.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>n.startsWith(a)),s=t.startsWith("/")||t.startsWith("#")||t.startsWith("?")||t.startsWith(".")||!t.includes(":")&&!t.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(t,n,o)=>{let r=`--link-${this.linkIndex++}`;return`<a href="${this.sanitizeUrl(o)}" style="anchor-name: ${r}"><span class="syntax-marker">[</span>${n}<span class="syntax-marker url-part">](${o})</span></a>`})}static identifyAndProtectSanctuaries(e){let t=new Map,n=0,o=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let h=a.index+a[0].indexOf("](")+2,u=h+a[2].length;r.push({start:h,end:u})}let l=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),c,d=[];for(;(c=l.exec(e))!==null;){let p=c.index,h=c.index+c[0].length;r.some(f=>p>=f.start&&h<=f.end)||d.push({match:c[0],index:c.index,openTicks:c[1],content:c[2],closeTicks:c[3]})}return d.sort((p,h)=>h.index-p.index),d.forEach(p=>{let h=`\uE000${n++}\uE001`;t.set(h,{type:"code",original:p.match,openTicks:p.openTicks,content:p.content,closeTicks:p.closeTicks}),o=o.substring(0,p.index)+h+o.substring(p.index+p.match.length)}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(p,h,u)=>{let f=`\uE000${n++}\uE001`;return t.set(f,{type:"link",original:p,linkText:h,url:u}),f}),{protectedText:o,sanctuaries:t}}static restoreAndTransformSanctuaries(e,t){return Array.from(t.keys()).sort((o,r)=>{let s=e.indexOf(o),a=e.indexOf(r);return s-a}).forEach(o=>{let r=t.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;t.forEach((d,p)=>{if(a.includes(p)&&d.type==="code"){let h=`<code><span class="syntax-marker">${d.openTicks}</span>${d.content}<span class="syntax-marker">${d.closeTicks}</span></code>`;a=a.replace(p,h)}}),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:t,sanctuaries:n}=this.identifyAndProtectSanctuaries(e),o=t;return o=this.parseStrikethrough(o),o=this.parseBold(o),o=this.parseItalic(o),o=this.restoreAndTransformSanctuaries(o,n),o}static parseLine(e,t=!1){let n=this.escapeHtml(e);n=this.preserveIndentation(n,e);let o=this.parseHorizontalRule(n);if(o)return o;let r=this.parseCodeBlock(n);return r||(n=this.parseHeader(n),n=this.parseBlockquote(n),n=this.parseTaskList(n,t),n=this.parseBulletList(n),n=this.parseNumberedList(n),!n.includes("<li")&&!n.includes("<h")&&(n=this.parseInlineElements(n)),n.trim()===""?"<div>&nbsp;</div>":`<div>${n}</div>`)}static parse(e,t=-1,n=!1,o,r=!1){this.resetLinkIndex();let s=e.split(`
9
+ `),a=!1,c=s.map((d,p)=>{if(n&&p===t)return`<div class="raw-line">${this.escapeHtml(d)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(d))return a=!a,this.applyCustomSyntax(this.parseLine(d,r));if(a){let u=this.escapeHtml(d);return`<div>${this.preserveIndentation(u,d)||"&nbsp;"}</div>`}return this.applyCustomSyntax(this.parseLine(d,r))}).join("");return this.postProcessHTML(c,o)}static postProcessHTML(e,t){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,t);let n=document.createElement("div");n.innerHTML=e;let o=null,r=null,s=null,a=!1,l=Array.from(n.children);for(let c=0;c<l.length;c++){let d=l[c];if(!d.parentNode)continue;let p=d.querySelector(".code-fence");if(p){let u=p.textContent;if(u.startsWith("```"))if(a){let f=t||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=u.slice(3).trim();m&&(f.className=`language-${m}`),n.insertBefore(s,d.nextSibling),s._codeElement=f,s._language=m,s._codeContent="";continue}}if(a&&s&&d.tagName==="DIV"&&!d.querySelector(".code-fence")){let u=s._codeElement||s.querySelector("code");s._codeContent.length>0&&(s._codeContent+=`
10
+ `);let f=d.textContent.replace(/\u00A0/g," ");s._codeContent+=f,u.textContent.length>0&&(u.textContent+=`
11
+ `),u.textContent+=f,d.remove();continue}let h=null;if(d.tagName==="DIV"&&(h=d.querySelector("li")),h){let u=h.classList.contains("bullet-list"),f=h.classList.contains("ordered-list");if(!u&&!f){o=null,r=null;continue}let m=u?"ul":"ol";(!o||r!==m)&&(o=document.createElement(m),n.insertBefore(o,d),r=m);let v=[];for(let y of d.childNodes)if(y.nodeType===3&&y.textContent.match(/^\u00A0+$/))v.push(y.cloneNode(!0));else if(y===h)break;v.forEach(y=>{h.insertBefore(y,h.firstChild)}),o.appendChild(h),d.remove()}else o=null,r=null}return n.innerHTML}static postProcessHTMLManual(e,t){let n=e;n=n.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/),d=l.match(/<li class="bullet-list">.*?<\/li>/);if(c&&d){let p=c[1];return d[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${p}`)}return d?d[0]:""}).filter(Boolean).join("")+"</ul>":r}),n=n.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/),d=l.match(/<li class="ordered-list">.*?<\/li>/);if(c&&d){let p=c[1];return d[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${p}`)}return d?d[0]:""}).filter(Boolean).join("")+"</ol>":r});let o=/<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;return n=n.replace(o,(r,s,a,l)=>{let d=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(v=>v.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
12
+ `),p=s.slice(3).trim(),h=p?` class="language-${p}"`:"",u=d,f=t||this.codeHighlighter;if(f)try{let v=d.replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),y=f(v,p);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()&&(u=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${h}>${u}</code></pre>`,m+=`<div><span class="code-fence">${l}</span></div>`,m}),n}static getListContext(e,t){let n=e.split(`
13
+ `),o=0,r=0,s=0;for(let h=0;h<n.length;h++){let u=n[h].length;if(o+u>=t){r=h,s=o;break}o+=u+1}let a=n[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 d=a.match(this.LIST_PATTERNS.bullet);if(d)return{inList:!0,listType:"bullet",indent:d[1],marker:d[2],content:d[3],lineStart:s,lineEnd:l,markerEndPos:s+d[1].length+d[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:l,markerEndPos:s+p[1].length+p[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 t=e.split(`
14
+ `),n=new Map,o=!1;return t.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let l=a[1],c=l.length,d=a[3];o||n.clear();let p=(n.get(c)||0)+1;n.set(c,p);for(let[h]of n)h>c&&n.delete(h);return o=!0,`${l}${p}. ${d}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,n.clear()),s}).join(`
15
+ `)}};A(E,"linkIndex",0),A(E,"codeHighlighter",null),A(E,"customSyntax",null),A(E,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=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 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"}},dt={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"}},pt={solar:F,cave:dt,auto:F,light:F,dark:dt};function O(i){return typeof i=="string"?{...pt[i]||pt.solar,name:i}:i}function Qe(i){if(i!=="auto")return i;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(i,e){let t=[];for(let[n,o]of Object.entries(i)){let r=n.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`--${r}: ${o};`)}if(e)for(let[n,o]of Object.entries(e)){let r=n.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`--preview-${r}-default: ${o};`)}return t.join(`
16
+ `)}function ht(i,e={},t={}){return{...i,colors:{...i.colors,...e},previewColors:{...i.previewColors,...t}}}function Le(i={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:n='"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={}}=i,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,d])=>`${c.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${d} !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,${i}) !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,${n}) !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, ${t}) !important;
@@ -35,33 +35,33 @@ var OverTypeEditor=(()=>{var ke=Object.defineProperty;var xn=Object.getOwnProper
35
35
  font-feature-settings: normal !important;
36
36
 
37
37
  /* Box model - must match exactly */
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;
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,${n}) !important;
39
39
  font-size: var(--instance-font-size, ${e}) !important;
40
40
  line-height: var(--instance-line-height, ${t}) !important;
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 pe={};lt(pe,{applyCustomFormat:()=>Et,default:()=>Fn,expandSelection:()=>_t,getActiveFormats:()=>Ie,getDebugMode:()=>Je,hasFormat:()=>St,insertHeader:()=>ce,insertLink:()=>Te,preserveSelection:()=>xt,setDebugMode:()=>vt,setUndoMethod:()=>wt,toggleBold:()=>Ee,toggleBulletList:()=>He,toggleCode:()=>Ae,toggleH1:()=>Pe,toggleH2:()=>$e,toggleH3:()=>Re,toggleItalic:()=>Ce,toggleNumberedList:()=>Me,toggleQuote:()=>Oe,toggleTaskList:()=>le});var Cn=Object.defineProperty,ht=Object.getOwnPropertySymbols,An=Object.prototype.hasOwnProperty,Tn=Object.prototype.propertyIsEnumerable,ut=(n,e,t)=>e in n?Cn(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ft=(n,e)=>{for(var t in e||(e={}))An.call(e,t)&&ut(n,t,e[t]);if(ht)for(var t of ht(e))Tn.call(e,t)&&ut(n,t,e[t]);return n},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 Hn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function B(n){return ft(ft({},Hn()),n)}var ae=!1;function vt(n){ae=n}function Je(){return ae}function x(n,e,t){ae&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function Se(n,e){if(!ae)return;let t=n.value.slice(n.selectionStart,n.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let i=n.value.slice(Math.max(0,n.selectionStart-10),n.selectionStart),o=n.value.slice(n.selectionEnd,Math.min(n.value.length,n.selectionEnd+10));console.log("Context:",JSON.stringify(i)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function yt(n){ae&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(n.text)),console.log("New selection:",`${n.selectionStart}-${n.selectionEnd}`),console.groupEnd())}var T=null;function N(n,{text:e,selectionStart:t,selectionEnd:i}){let o=Je();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",i)),n.focus();let r=n.selectionStart,s=n.selectionEnd,a=n.value.slice(0,r),l=n.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(n.value.slice(r,s))));let p=n.value,c=r!==s;if(T===null||T===!0){n.contentEditable="true";try{T=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",T,"for text with",e.split(`
43
- `).length,"lines")}catch(d){T=!1,o&&console.log("execCommand threw error:",d)}n.contentEditable="false"}if(o&&(console.log("canInsertText before:",T),console.log("execCommand result:",T)),T){let d=a+e+l,h=n.value;o&&(console.log("Expected length:",d.length),console.log("Actual length:",h.length)),h!==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(h.slice(0,100))))}if(!T)if(o&&console.log("Using manual insertion"),n.value===p){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(d){}n.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(d){}n.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:",t,i),t!=null&&i!=null?n.setSelectionRange(t,i):n.setSelectionRange(r,n.selectionEnd),o&&(console.log("Final value length:",n.value.length),console.groupEnd())}function wt(n){switch(n){case"native":T=!0;break;case"manual":T=!1;break;case"auto":T=null;break}}function Qe(n){return n.trim().split(`
44
- `).length>1}function Mn(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function On(n,e,t){let i=e,o=t?/\n/:/\s/;for(;n[i]&&!n[i].match(o);)i++;return i}function bt(n){let e=n.value.split(`
45
- `),t=0;for(let i=0;i<e.length;i++){let o=e[i].length+1;n.selectionStart>=t&&n.selectionStart<t+o&&(n.selectionStart=t),n.selectionEnd>=t&&n.selectionEnd<t+o&&(i===e.length-1?n.selectionEnd=Math.min(t+e[i].length,n.value.length):n.selectionEnd=t+o-1),t+=o}}function Pn(n,e,t,i=!1){if(n.selectionStart===n.selectionEnd)n.selectionStart=Mn(n.value,n.selectionStart),n.selectionEnd=On(n.value,n.selectionEnd,i);else{let o=n.selectionStart-e.length,r=n.selectionEnd+t.length,s=n.value.slice(o,n.selectionStart)===e,a=n.value.slice(n.selectionEnd,r)===t;s&&a&&(n.selectionStart=o,n.selectionEnd=r)}return n.value.slice(n.selectionStart,n.selectionEnd)}function Xe(n){let e=n.value.slice(0,n.selectionStart),t=n.value.slice(n.selectionEnd),i=e.match(/\n*$/),o=t.match(/^\n*/),r=i?i[0].length:0,s=o?o[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,${n}) !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:${n}!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:${n}!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 de={};ct(de,{applyCustomFormat:()=>At,default:()=>Di,expandSelection:()=>Et,getActiveFormats:()=>Be,getDebugMode:()=>Ge,hasFormat:()=>_t,insertHeader:()=>ce,insertLink:()=>Ie,preserveSelection:()=>kt,setDebugMode:()=>yt,setUndoMethod:()=>bt,toggleBold:()=>Ae,toggleBulletList:()=>Me,toggleCode:()=>Ce,toggleH1:()=>Re,toggleH2:()=>Oe,toggleH3:()=>$e,toggleItalic:()=>Te,toggleNumberedList:()=>He,toggleQuote:()=>Pe,toggleTaskList:()=>le});var Ai=Object.defineProperty,ut=Object.getOwnPropertySymbols,Ti=Object.prototype.hasOwnProperty,Ci=Object.prototype.propertyIsEnumerable,ft=(i,e,t)=>e in i?Ai(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,mt=(i,e)=>{for(var t in e||(e={}))Ti.call(e,t)&&ft(i,t,e[t]);if(ut)for(var t of ut(e))Ci.call(e,t)&&ft(i,t,e[t]);return 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 Ii(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function B(i){return mt(mt({},Ii()),i)}var ae=!1;function yt(i){ae=i}function Ge(){return ae}function x(i,e,t){ae&&(console.group(`\u{1F50D} ${i}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function _e(i,e){if(!ae)return;let t=i.value.slice(i.selectionStart,i.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${i.selectionStart}-${i.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let n=i.value.slice(Math.max(0,i.selectionStart-10),i.selectionStart),o=i.value.slice(i.selectionEnd,Math.min(i.value.length,i.selectionEnd+10));console.log("Context:",JSON.stringify(n)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function wt(i){ae&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(i.text)),console.log("New selection:",`${i.selectionStart}-${i.selectionEnd}`),console.groupEnd())}var C=null;function z(i,{text:e,selectionStart:t,selectionEnd:n}){let o=Ge();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${i.selectionStart}-${i.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",n)),i.focus();let r=i.selectionStart,s=i.selectionEnd,a=i.value.slice(0,r),l=i.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(i.value.slice(r,s))));let c=i.value,d=r!==s;if(C===null||C===!0){i.contentEditable="true";try{C=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",C,"for text with",e.split(`
43
+ `).length,"lines")}catch(p){C=!1,o&&console.log("execCommand threw error:",p)}i.contentEditable="false"}if(o&&(console.log("canInsertText before:",C),console.log("execCommand result:",C)),C){let p=a+e+l,h=i.value;o&&(console.log("Expected length:",p.length),console.log("Actual length:",h.length)),h!==p&&o&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(p.slice(0,100))),console.log("Actual:",JSON.stringify(h.slice(0,100))))}if(!C)if(o&&console.log("Using manual insertion"),i.value===c){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}i.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(p){}i.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:",t,n),t!=null&&n!=null?i.setSelectionRange(t,n):i.setSelectionRange(r,i.selectionEnd),o&&(console.log("Final value length:",i.value.length),console.groupEnd())}function bt(i){switch(i){case"native":C=!0;break;case"manual":C=!1;break;case"auto":C=null;break}}function Je(i){return i.trim().split(`
44
+ `).length>1}function Mi(i,e){let t=e;for(;i[t]&&i[t-1]!=null&&!i[t-1].match(/\s/);)t--;return t}function Hi(i,e,t){let n=e,o=t?/\n/:/\s/;for(;i[n]&&!i[n].match(o);)n++;return n}function xt(i){let e=i.value.split(`
45
+ `),t=0;for(let n=0;n<e.length;n++){let o=e[n].length+1;i.selectionStart>=t&&i.selectionStart<t+o&&(i.selectionStart=t),i.selectionEnd>=t&&i.selectionEnd<t+o&&(n===e.length-1?i.selectionEnd=Math.min(t+e[n].length,i.value.length):i.selectionEnd=t+o-1),t+=o}}function Pi(i,e,t,n=!1){if(i.selectionStart===i.selectionEnd)i.selectionStart=Mi(i.value,i.selectionStart),i.selectionEnd=Hi(i.value,i.selectionEnd,n);else{let o=i.selectionStart-e.length,r=i.selectionEnd+t.length,s=i.value.slice(o,i.selectionStart)===e,a=i.value.slice(i.selectionEnd,r)===t;s&&a&&(i.selectionStart=o,i.selectionEnd=r)}return i.value.slice(i.selectionStart,i.selectionEnd)}function Xe(i){let e=i.value.slice(0,i.selectionStart),t=i.value.slice(i.selectionEnd),n=e.match(/\n*$/),o=t.match(/^\n*/),r=n?n[0].length:0,s=o?o[0].length:0,a="",l="";return e.match(/\S/)&&r<2&&(a=`
46
46
  `.repeat(2-r)),t.match(/\S/)&&s<2&&(l=`
47
- `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function xt(n,e){let t=n.selectionStart,i=n.selectionEnd,o=n.scrollTop;e(),n.selectionStart=t,n.selectionEnd=i,n.scrollTop=o}function _e(n,e,t={}){let i=n.selectionStart,o=n.selectionEnd,r=i===o,s=n.value,a=i;for(;a>0&&s[a-1]!==`
48
- `;)a--;if(r){let p=i;for(;p<s.length&&s[p]!==`
49
- `;)p++;n.selectionStart=a,n.selectionEnd=p}else bt(n);let l=e(n);if(t.adjustSelection){let c=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix),d=t.adjustSelection(c,i,o,a);l.selectionStart=d.start,l.selectionEnd=d.end}else if(t.prefix){let c=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix);r?c?(l.selectionStart=Math.max(i-t.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=i+t.prefix.length,l.selectionEnd=l.selectionStart):c?(l.selectionStart=Math.max(i-t.prefix.length,a),l.selectionEnd=Math.max(o-t.prefix.length,a)):(l.selectionStart=i+t.prefix.length,l.selectionEnd=o+t.prefix.length)}return l}function te(n,e){let t,i,{prefix:o,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:p,scanFor:c,surroundWithNewlines:d,trimFirst:h}=e,u=n.selectionStart,f=n.selectionEnd,m=n.value.slice(n.selectionStart,n.selectionEnd),g=Qe(m)&&s&&s.length>0?`${s}
50
- `:o,y=Qe(m)&&a&&a.length>0?`
51
- ${a}`:r;if(p){let k=n.value[n.selectionStart-1];n.selectionStart!==0&&k!=null&&!k.match(/\s/)&&(g=` ${g}`)}m=Pn(n,g,y,e.multiline);let w=n.selectionStart,b=n.selectionEnd,L=l&&l.length>0&&y.indexOf(l)>-1&&m.length>0;if(d){let k=Xe(n);t=k.newlinesToAppend,i=k.newlinesToPrepend,g=t+o,y+=i}if(m.startsWith(g)&&m.endsWith(y)){let k=m.slice(g.length,m.length-y.length);if(u===f){let _=u-g.length;_=Math.max(_,w),_=Math.min(_,w+k.length),w=b=_}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=u+g.length,b=f+g.length;let _=m.match(/^\s*|\s*$/g);if(h&&_){let be=_[0]||"",Y=_[1]||"";k=be+g+m.trim()+y+Y,w+=be.length,b-=Y.length}return{text:k,selectionStart:w,selectionEnd:b}}}function Ge(n,e){let{prefix:t,suffix:i,surroundWithNewlines:o}=e,r=n.value.slice(n.selectionStart,n.selectionEnd),s=n.selectionStart,a=n.selectionEnd,l=r.split(`
52
- `);if(l.every(c=>c.startsWith(t)&&(!i||c.endsWith(i))))r=l.map(c=>{let d=c.slice(t.length);return i&&(d=d.slice(0,d.length-i.length)),d}).join(`
53
- `),a=s+r.length;else if(r=l.map(c=>t+c+(i||"")).join(`
54
- `),o){let{newlinesToAppend:c,newlinesToPrepend:d}=Xe(n);s+=c.length,a=s+r.length,r=c+r+d}return{text:r,selectionStart:s,selectionEnd:a}}function mt(n){let e=n.split(`
55
- `),t=/^\d+\.\s+/,i=e.every(r=>t.test(r)),o=e;return i&&(o=e.map(r=>r.replace(t,""))),{text:o.join(`
56
- `),processed:i}}function gt(n){let e=n.split(`
57
- `),t="- ",i=e.every(r=>r.startsWith(t)),o=e;return i&&(o=e.map(r=>r.slice(t.length))),{text:o.join(`
58
- `),processed:i}}function se(n,e){return e?"- ":`${n+1}. `}function $n(n,e){let t,i,o;return n.orderedList?(t=mt(e),i=gt(t.text),o=i.text):(t=gt(e),i=mt(t.text),o=i.text),[t,i,o]}function Rn(n,e){let t=n.selectionStart===n.selectionEnd,i=n.selectionStart,o=n.selectionEnd;bt(n);let r=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,l]=$n(e,r),p=l.split(`
59
- `).map((m,g)=>`${se(g,e.unorderedList)}${m}`),c=p.reduce((m,g,y)=>m+se(y,e.unorderedList).length,0),d=p.reduce((m,g,y)=>m+se(y,!e.unorderedList).length,0);if(s.processed)return t?(i=Math.max(i-se(0,e.unorderedList).length,0),o=i):(i=n.selectionStart,o=n.selectionEnd-c),{text:l,selectionStart:i,selectionEnd:o};let{newlinesToAppend:h,newlinesToPrepend:u}=Xe(n),f=h+p.join(`
60
- `)+u;return t?(i=Math.max(i+se(0,e.unorderedList).length+h.length,0),o=i):a.processed?(i=Math.max(n.selectionStart+h.length,0),o=n.selectionEnd+h.length+c-d):(i=Math.max(n.selectionStart+h.length,0),o=n.selectionEnd+h.length+c),{text:f,selectionStart:i,selectionEnd:o}}function kt(n,e){let t=_e(n,i=>Rn(i,e),{adjustSelection:(i,o,r,s)=>{let a=n.value.slice(s,n.selectionEnd),l=/^\d+\.\s+/,p=/^- /,c=l.test(a),d=p.test(a),h=e.orderedList&&c||e.unorderedList&&d;if(o===r)if(h){let u=a.match(e.orderedList?l:p),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(c||d){let u=a.match(c?l:p),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:o+u}}else if(h){let u=a.match(e.orderedList?l:p),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(c||d){let u=a.match(c?l:p),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:r+u}}}});N(n,t)}function Lt(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:i,value:o}=n,r=o.split(`
61
- `),s=0,a="";for(let d of r){if(t>=s&&t<=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,t-10),p=Math.min(o.length,i+10),c=o.slice(l,p);if(c.includes("**")){let d=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(c.includes("_")){let d=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(c.includes("`")){let d=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100));d.includes("`")&&h.includes("`")&&e.push("code")}if(c.includes("[")&&c.includes("]")){let d=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&o.slice(i+f+1,i+f+10).startsWith("(")&&e.push("link")}return e}function In(n,e){return Lt(n).includes(e)}function Bn(n,e={}){if(!n)return;let{toWord:t,toLine:i,toFormat:o}=e,{selectionStart:r,selectionEnd:s,value:a}=n;if(i){let l=a.split(`
62
- `),p=0,c=0,d=0;for(let h of l){if(r>=d&&r<=d+h.length){p=d,c=d+h.length;break}d+=h.length+1}n.selectionStart=p,n.selectionEnd=c}else if(t&&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++;n.selectionStart=l,n.selectionEnd=p}}function Ee(n){if(!n||n.disabled||n.readOnly)return;x("toggleBold","Starting"),Se(n,"Before");let e=B(I.bold),t=te(n,e);yt(t),N(n,t),Se(n,"After")}function Ce(n){if(!n||n.disabled||n.readOnly)return;let e=B(I.italic),t=te(n,e);N(n,t)}function Ae(n){if(!n||n.disabled||n.readOnly)return;let e=B(I.code),t=te(n,e);N(n,t)}function Te(n,e={}){if(!n||n.disabled||n.readOnly)return;let t=n.value.slice(n.selectionStart,n.selectionEnd),i=B(I.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(i.suffix=`](${t})`,i.replaceNext=""):e.url&&(i.suffix=`](${e.url})`,i.replaceNext=""),e.text&&!t){let s=n.selectionStart;n.value=n.value.slice(0,s)+e.text+n.value.slice(s),n.selectionStart=s,n.selectionEnd=s+e.text.length}let r=te(n,i);N(n,r)}function He(n){if(!n||n.disabled||n.readOnly)return;let e=B(I.bulletList);kt(n,e)}function Me(n){if(!n||n.disabled||n.readOnly)return;let e=B(I.numberedList);kt(n,e)}function Oe(n){if(!n||n.disabled||n.readOnly)return;x("toggleQuote","Starting"),Se(n,"Initial");let e=B(I.quote),t=_e(n,i=>Ge(i,e),{prefix:e.prefix});yt(t),N(n,t),Se(n,"Final")}function le(n){if(!n||n.disabled||n.readOnly)return;let e=B(I.taskList),t=_e(n,i=>Ge(i,e),{prefix:e.prefix});N(n,t)}function ce(n,e=1,t=!1){if(!n||n.disabled||n.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${t}`),x("insertHeader",`Initial cursor: ${n.selectionStart}-${n.selectionEnd}`);let i=`header${e===1?"1":e}`,o=B(I[i]||I.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=n.value,s=n.selectionStart,a=n.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*/),h=d?d[1].length:0,u=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${h}`),x("insertHeader",` - Existing prefix length: ${u}`),x("insertHeader",` - Target level: ${e}`);let f=t&&h===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${h}, level=${e})`);let m=_e(n,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):h>0?(x("insertHeader",`ACTION: Replacing H${h} 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:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.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-u,b);return x("insertHeader",` - Removing header, adjusting by -${u}`),{start:L,end:y===w?L:Math.max(w-u,b)}}else if(u>0){let L=o.prefix.length-u;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 ============"),N(n,m)}function Pe(n){ce(n,1,!0)}function $e(n){ce(n,2,!0)}function Re(n){ce(n,3,!0)}function Ie(n){return Lt(n)}function St(n,e){return In(n,e)}function _t(n,e={}){Bn(n,e)}function Et(n,e){if(!n||n.disabled||n.readOnly)return;let t=B(e),i;if(t.multiline){let o=n.value.slice(n.selectionStart,n.selectionEnd);Qe(o)?i=Ge(n,t):i=te(n,t)}else i=te(n,t);N(n,i)}var Fn={toggleBold:Ee,toggleItalic:Ce,toggleCode:Ae,insertLink:Te,toggleBulletList:He,toggleNumberedList:Me,toggleQuote:Oe,toggleTaskList:le,insertHeader:ce,toggleH1:Pe,toggleH2:$e,toggleH3:Re,getActiveFormats:Ie,hasFormat:St,expandSelection:_t,applyCustomFormat:Et,preserveSelection:xt,setUndoMethod:wt,setDebugMode:vt,getDebugMode:Je};var Be=class{constructor(e,t={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=t.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 t=this.createSeparator();this.container.appendChild(t)}else{let t=this.createButton(e);this.buttons[e.name]=t,this.container.appendChild(t)}}),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 t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.setAttribute("data-button",e.name),t.title=e.title||"",t.setAttribute("aria-label",e.title||e.name),t.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(t.classList.add("has-dropdown"),t.dataset.dropdown="true",t.addEventListener("click",i=>{i.preventDefault(),this.toggleViewModeDropdown(t)}),t):(t._clickHandler=i=>{i.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,i)},t.addEventListener("click",t._clickHandler),t)}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:t=>this.editor.setValue(t),event:null}),!0}catch(t){return console.error(`Action "${e.name}" error:`,t),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:t}})),!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 t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active");return}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.handleDocumentClick=r=>{!i.contains(r.target)&&!e.contains(r.target)&&(i.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let t=document.createElement("div");t.className="overtype-dropdown-menu";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.textContent=r.label,r.id===o){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}t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),t.appendChild(s)}),t}updateButtonStates(){var e;try{let t=((e=Ie)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([i,o])=>{if(i==="viewMode")return;let r=!1;switch(i){case"bold":r=t.includes("bold");break;case"italic":r=t.includes("italic");break;case"code":r=!1;break;case"bulletList":r=t.includes("bullet-list");break;case"orderedList":r=t.includes("numbered-list");break;case"taskList":r=t.includes("task-list");break;case"quote":r=t.includes("quote");break;case"h1":r=t.includes("header");break;case"h2":r=t.includes("header-2");break;case"h3":r=t.includes("header-3");break}o.classList.toggle("active",r),o.setAttribute("aria-pressed",r.toString())})}catch(t){}}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,U=Math.max,ue=Math.round;var P=n=>({x:n,y:n}),zn={left:"right",right:"left",bottom:"top",top:"bottom"},Nn={start:"end",end:"start"};function Ye(n,e,t){return U(n,he(e,t))}function fe(n,e){return typeof n=="function"?n(e):n}function W(n){return n.split("-")[0]}function me(n){return n.split("-")[1]}function et(n){return n==="x"?"y":"x"}function tt(n){return n==="y"?"height":"width"}var Dn=new Set(["top","bottom"]);function D(n){return Dn.has(W(n))?"y":"x"}function nt(n){return et(D(n))}function Tt(n,e,t){t===void 0&&(t=!1);let i=me(n),o=nt(n),r=tt(o),s=o==="x"?i===(t?"end":"start")?"right":"left":i==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=de(s)),[s,de(s)]}function Ht(n){let e=de(n);return[Fe(n),e,Fe(e)]}function Fe(n){return n.replace(/start|end/g,e=>Nn[e])}var Ct=["left","right"],At=["right","left"],jn=["top","bottom"],Vn=["bottom","top"];function Un(n,e,t){switch(n){case"top":case"bottom":return t?e?At:Ct:e?Ct:At;case"left":case"right":return e?jn:Vn;default:return[]}}function Mt(n,e,t,i){let o=me(n),r=Un(W(n),t==="start",i);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Fe)))),r}function de(n){return n.replace(/left|right|bottom|top/g,e=>zn[e])}function Wn(n){return{top:0,right:0,bottom:0,left:0,...n}}function Ot(n){return typeof n!="number"?Wn(n):{top:n,right:n,bottom:n,left:n}}function J(n){let{x:e,y:t,width:i,height:o}=n;return{width:i,height:o,top:t,left:e,right:e+i,bottom:t+o,x:e,y:t}}function Pt(n,e,t){let{reference:i,floating:o}=n,r=D(e),s=nt(e),a=tt(s),l=W(e),p=r==="y",c=i.x+i.width/2-o.width/2,d=i.y+i.height/2-o.height/2,h=i[a]/2-o[a]/2,u;switch(l){case"top":u={x:c,y:i.y-o.height};break;case"bottom":u={x:c,y:i.y+i.height};break;case"right":u={x:i.x+i.width,y:d};break;case"left":u={x:i.x-o.width,y:d};break;default:u={x:i.x,y:i.y}}switch(me(e)){case"start":u[s]-=h*(t&&p?-1:1);break;case"end":u[s]+=h*(t&&p?-1:1);break}return u}async function $t(n,e){var t;e===void 0&&(e={});let{x:i,y:o,platform:r,rects:s,elements:a,strategy:l}=n,{boundary:p="clippingAncestors",rootBoundary:c="viewport",elementContext:d="floating",altBoundary:h=!1,padding:u=0}=fe(e,n),f=Ot(u),g=a[h?d==="floating"?"reference":"floating":d],y=J(await r.getClippingRect({element:(t=await(r.isElement==null?void 0:r.isElement(g)))==null||t?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:p,rootBoundary:c,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 Rt=async(n,e,t)=>{let{placement:i="bottom",strategy:o="absolute",middleware:r=[],platform:s}=t,a=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:n,floating:e,strategy:o}),{x:c,y:d}=Pt(p,i,l),h=i,u={},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:_}=await w({x:c,y:d,initialPlacement:i,placement:h,strategy:o,middlewareData:u,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:$t},elements:{reference:n,floating:e}});c=b!=null?b:c,d=L!=null?L:d,u={...u,[y]:{...u[y],...k}},_&&f<=50&&(f++,typeof _=="object"&&(_.placement&&(h=_.placement),_.rects&&(p=_.rects===!0?await s.getElementRects({reference:n,floating:e,strategy:o}):_.rects),{x:c,y:d}=Pt(p,h,l)),g=-1)}return{x:c,y:d,placement:h,strategy:o,middlewareData:u}};var It=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,i;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:l,elements:p}=e,{mainAxis:c=!0,crossAxis:d=!0,fallbackPlacements:h,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=fe(n,e);if((t=r.arrow)!=null&&t.alignmentOffset)return{};let y=W(o),w=D(a),b=W(a)===a,L=await(l.isRTL==null?void 0:l.isRTL(p.floating)),k=h||(b||!m?[de(a)]:Ht(a)),_=f!=="none";!h&&_&&k.push(...Mt(a,m,f,L));let be=[a,...k],Y=await l.detectOverflow(e,g),xe=[],ee=((i=r.flip)==null?void 0:i.overflows)||[];if(c&&xe.push(Y[y]),d){let K=Tt(o,s,L);xe.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:xe}],!xe.every(K=>K<=0)){var rt,st;let K=(((rt=r.flip)==null?void 0:rt.index)||0)+1,Ke=be[K];if(Ke&&(!(d==="alignment"?w!==D(Ke):!1)||ee.every(O=>D(O.placement)===w?O.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Ke}};let oe=(st=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,O)=>Z.overflows[1]-O.overflows[1])[0])==null?void 0:st.placement;if(!oe)switch(u){case"bestFit":{var at;let Z=(at=ee.filter(O=>{if(_){let V=D(O.placement);return V===w||V==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(V=>V>0).reduce((V,bn)=>V+bn,0)]).sort((O,V)=>O[1]-V[1])[0])==null?void 0:at[0];Z&&(oe=Z);break}case"initialPlacement":oe=a;break}if(o!==oe)return{reset:{placement:oe}}}return{}}}};var qn=new Set(["left","top"]);async function Kn(n,e){let{placement:t,platform:i,elements:o}=n,r=await(i.isRTL==null?void 0:i.isRTL(o.floating)),s=W(t),a=me(t),l=D(t)==="y",p=qn.has(s)?-1:1,c=r&&l?-1:1,d=fe(e,n),{mainAxis:h,crossAxis:u,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"&&(u=a==="end"?f*-1:f),l?{x:u*c,y:h*p}:{x:h*p,y:u*c}}var Bt=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,i;let{x:o,y:r,placement:s,middlewareData:a}=e,l=await Kn(e,n);return s===((t=a.offset)==null?void 0:t.placement)&&(i=a.arrow)!=null&&i.alignmentOffset?{}:{x:o+l.x,y:r+l.y,data:{...l,placement:s}}}}},Ft=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){let{x:t,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}}},...p}=fe(n,e),c={x:t,y:i},d=await r.detectOverflow(e,p),h=D(W(o)),u=et(h),f=c[u],m=c[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=Ye(b,f,L)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=Ye(b,m,L)}let g=l.fn({...e,[u]:f,[h]:m});return{...g,data:{x:g.x-t,y:g.y-i,enabled:{[u]:s,[h]:a}}}}}};function Ne(){return typeof window<"u"}function X(n){return Nt(n)?(n.nodeName||"").toLowerCase():"#document"}function A(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function F(n){var e;return(e=(Nt(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function Nt(n){return Ne()?n instanceof Node||n instanceof A(n).Node:!1}function H(n){return Ne()?n instanceof Element||n instanceof A(n).Element:!1}function $(n){return Ne()?n instanceof HTMLElement||n instanceof A(n).HTMLElement:!1}function zt(n){return!Ne()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof A(n).ShadowRoot}var Zn=new Set(["inline","contents"]);function ne(n){let{overflow:e,overflowX:t,overflowY:i,display:o}=M(n);return/auto|scroll|overlay|hidden|clip/.test(e+i+t)&&!Zn.has(o)}var Qn=new Set(["table","td","th"]);function Dt(n){return Qn.has(X(n))}var Jn=[":popover-open",":modal"];function ge(n){return Jn.some(e=>{try{return n.matches(e)}catch(t){return!1}})}var Xn=["transform","translate","scale","rotate","perspective"],Gn=["transform","translate","scale","rotate","perspective","filter"],Yn=["paint","layout","strict","content"];function De(n){let e=je(),t=H(n)?M(n):n;return Xn.some(i=>t[i]?t[i]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||Gn.some(i=>(t.willChange||"").includes(i))||Yn.some(i=>(t.contain||"").includes(i))}function jt(n){let e=j(n);for(;$(e)&&!G(e);){if(De(e))return e;if(ge(e))return null;e=j(e)}return null}function je(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var ei=new Set(["html","body","#document"]);function G(n){return ei.has(X(n))}function M(n){return A(n).getComputedStyle(n)}function ve(n){return H(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function j(n){if(X(n)==="html")return n;let e=n.assignedSlot||n.parentNode||zt(n)&&n.host||F(n);return zt(e)?e.host:e}function Vt(n){let e=j(n);return G(e)?n.ownerDocument?n.ownerDocument.body:n.body:$(e)&&ne(e)?e:Vt(e)}function ze(n,e,t){var i;e===void 0&&(e=[]),t===void 0&&(t=!0);let o=Vt(n),r=o===((i=n.ownerDocument)==null?void 0:i.body),s=A(o);if(r){let a=Ve(s);return e.concat(s,s.visualViewport||[],ne(o)?o:[],a&&t?ze(a):[])}return e.concat(o,ze(o,[],t))}function Ve(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function Kt(n){let e=M(n),t=parseFloat(e.width)||0,i=parseFloat(e.height)||0,o=$(n),r=o?n.offsetWidth:t,s=o?n.offsetHeight:i,a=ue(t)!==r||ue(i)!==s;return a&&(t=r,i=s),{width:t,height:i,$:a}}function Zt(n){return H(n)?n:n.contextElement}function ie(n){let e=Zt(n);if(!$(e))return P(1);let t=e.getBoundingClientRect(),{width:i,height:o,$:r}=Kt(e),s=(r?ue(t.width):t.width)/i,a=(r?ue(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var ti=P(0);function Qt(n){let e=A(n);return!je()||!e.visualViewport?ti:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ni(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==A(n)?!1:e}function ye(n,e,t,i){e===void 0&&(e=!1),t===void 0&&(t=!1);let o=n.getBoundingClientRect(),r=Zt(n),s=P(1);e&&(i?H(i)&&(s=ie(i)):s=ie(n));let a=ni(r,t,i)?Qt(r):P(0),l=(o.left+a.x)/s.x,p=(o.top+a.y)/s.y,c=o.width/s.x,d=o.height/s.y;if(r){let h=A(r),u=i&&H(i)?A(i):i,f=h,m=Ve(f);for(;m&&i&&u!==f;){let g=ie(m),y=m.getBoundingClientRect(),w=M(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=Ve(f)}}return J({width:c,height:d,x:l,y:p})}function Ue(n,e){let t=ve(n).scrollLeft;return e?e.left+t:ye(F(n)).left+t}function Jt(n,e){let t=n.getBoundingClientRect(),i=t.left+e.scrollLeft-Ue(n,t),o=t.top+e.scrollTop;return{x:i,y:o}}function ii(n){let{elements:e,rect:t,offsetParent:i,strategy:o}=n,r=o==="fixed",s=F(i),a=e?ge(e.floating):!1;if(i===s||a&&r)return t;let l={scrollLeft:0,scrollTop:0},p=P(1),c=P(0),d=$(i);if((d||!d&&!r)&&((X(i)!=="body"||ne(s))&&(l=ve(i)),$(i))){let u=ye(i);p=ie(i),c.x=u.x+i.clientLeft,c.y=u.y+i.clientTop}let h=s&&!d&&!r?Jt(s,l):P(0);return{width:t.width*p.x,height:t.height*p.y,x:t.x*p.x-l.scrollLeft*p.x+c.x+h.x,y:t.y*p.y-l.scrollTop*p.y+c.y+h.y}}function oi(n){return Array.from(n.getClientRects())}function ri(n){let e=F(n),t=ve(n),i=n.ownerDocument.body,o=U(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),r=U(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight),s=-t.scrollLeft+Ue(n),a=-t.scrollTop;return M(i).direction==="rtl"&&(s+=U(e.clientWidth,i.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Ut=25;function si(n,e){let t=A(n),i=F(n),o=t.visualViewport,r=i.clientWidth,s=i.clientHeight,a=0,l=0;if(o){r=o.width,s=o.height;let c=je();(!c||c&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}let p=Ue(i);if(p<=0){let c=i.ownerDocument,d=c.body,h=getComputedStyle(d),u=c.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(i.clientWidth-d.clientWidth-u);f<=Ut&&(r-=f)}else p<=Ut&&(r+=p);return{width:r,height:s,x:a,y:l}}var ai=new Set(["absolute","fixed"]);function li(n,e){let t=ye(n,!0,e==="fixed"),i=t.top+n.clientTop,o=t.left+n.clientLeft,r=$(n)?ie(n):P(1),s=n.clientWidth*r.x,a=n.clientHeight*r.y,l=o*r.x,p=i*r.y;return{width:s,height:a,x:l,y:p}}function Wt(n,e,t){let i;if(e==="viewport")i=si(n,t);else if(e==="document")i=ri(F(n));else if(H(e))i=li(e,t);else{let o=Qt(n);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return J(i)}function Xt(n,e){let t=j(n);return t===e||!H(t)||G(t)?!1:M(t).position==="fixed"||Xt(t,e)}function ci(n,e){let t=e.get(n);if(t)return t;let i=ze(n,[],!1).filter(a=>H(a)&&X(a)!=="body"),o=null,r=M(n).position==="fixed",s=r?j(n):n;for(;H(s)&&!G(s);){let a=M(s),l=De(s);!l&&a.position==="fixed"&&(o=null),(r?!l&&!o:!l&&a.position==="static"&&!!o&&ai.has(o.position)||ne(s)&&!l&&Xt(n,s))?i=i.filter(c=>c!==s):o=a,s=j(s)}return e.set(n,i),i}function pi(n){let{element:e,boundary:t,rootBoundary:i,strategy:o}=n,s=[...t==="clippingAncestors"?ge(e)?[]:ci(e,this._c):[].concat(t),i],a=s[0],l=s.reduce((p,c)=>{let d=Wt(e,c,o);return p.top=U(d.top,p.top),p.right=he(d.right,p.right),p.bottom=he(d.bottom,p.bottom),p.left=U(d.left,p.left),p},Wt(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function di(n){let{width:e,height:t}=Kt(n);return{width:e,height:t}}function hi(n,e,t){let i=$(e),o=F(e),r=t==="fixed",s=ye(n,!0,r,e),a={scrollLeft:0,scrollTop:0},l=P(0);function p(){l.x=Ue(o)}if(i||!i&&!r)if((X(e)!=="body"||ne(o))&&(a=ve(e)),i){let u=ye(e,!0,r,e);l.x=u.x+e.clientLeft,l.y=u.y+e.clientTop}else o&&p();r&&!i&&o&&p();let c=o&&!i&&!r?Jt(o,a):P(0),d=s.left+a.scrollLeft-l.x-c.x,h=s.top+a.scrollTop-l.y-c.y;return{x:d,y:h,width:s.width,height:s.height}}function it(n){return M(n).position==="static"}function qt(n,e){if(!$(n)||M(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return F(n)===t&&(t=t.ownerDocument.body),t}function Gt(n,e){let t=A(n);if(ge(n))return t;if(!$(n)){let o=j(n);for(;o&&!G(o);){if(H(o)&&!it(o))return o;o=j(o)}return t}let i=qt(n,e);for(;i&&Dt(i)&&it(i);)i=qt(i,e);return i&&G(i)&&it(i)&&!De(i)?t:i||jt(n)||t}var ui=async function(n){let e=this.getOffsetParent||Gt,t=this.getDimensions,i=await t(n.floating);return{reference:hi(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function fi(n){return M(n).direction==="rtl"}var mi={convertOffsetParentRelativeRectToViewportRelativeRect:ii,getDocumentElement:F,getClippingRect:pi,getOffsetParent:Gt,getElementRects:ui,getClientRects:oi,getDimensions:di,getScale:ie,isElement:H,isRTL:fi};var Yt=Bt;var en=Ft,tn=It;var nn=(n,e,t)=>{let i=new Map,o={platform:mi,...t},r={...o.platform,_c:i};return Rt(n,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=`
47
+ `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function kt(i,e){let t=i.selectionStart,n=i.selectionEnd,o=i.scrollTop;e(),i.selectionStart=t,i.selectionEnd=n,i.scrollTop=o}function Ee(i,e,t={}){let n=i.selectionStart,o=i.selectionEnd,r=n===o,s=i.value,a=n;for(;a>0&&s[a-1]!==`
48
+ `;)a--;if(r){let c=n;for(;c<s.length&&s[c]!==`
49
+ `;)c++;i.selectionStart=a,i.selectionEnd=c}else xt(i);let l=e(i);if(t.adjustSelection){let d=i.value.slice(i.selectionStart,i.selectionEnd).startsWith(t.prefix),p=t.adjustSelection(d,n,o,a);l.selectionStart=p.start,l.selectionEnd=p.end}else if(t.prefix){let d=i.value.slice(i.selectionStart,i.selectionEnd).startsWith(t.prefix);r?d?(l.selectionStart=Math.max(n-t.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=n+t.prefix.length,l.selectionEnd=l.selectionStart):d?(l.selectionStart=Math.max(n-t.prefix.length,a),l.selectionEnd=Math.max(o-t.prefix.length,a)):(l.selectionStart=n+t.prefix.length,l.selectionEnd=o+t.prefix.length)}return l}function te(i,e){let t,n,{prefix:o,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:c,scanFor:d,surroundWithNewlines:p,trimFirst:h}=e,u=i.selectionStart,f=i.selectionEnd,m=i.value.slice(i.selectionStart,i.selectionEnd),v=Je(m)&&s&&s.length>0?`${s}
50
+ `:o,y=Je(m)&&a&&a.length>0?`
51
+ ${a}`:r;if(c){let k=i.value[i.selectionStart-1];i.selectionStart!==0&&k!=null&&!k.match(/\s/)&&(v=` ${v}`)}m=Pi(i,v,y,e.multiline);let w=i.selectionStart,b=i.selectionEnd,S=l&&l.length>0&&y.indexOf(l)>-1&&m.length>0;if(p){let k=Xe(i);t=k.newlinesToAppend,n=k.newlinesToPrepend,v=t+o,y+=n}if(m.startsWith(v)&&m.endsWith(y)){let k=m.slice(v.length,m.length-y.length);if(u===f){let _=u-v.length;_=Math.max(_,w),_=Math.min(_,w+k.length),w=b=_}else b=w+k.length;return{text:k,selectionStart:w,selectionEnd:b}}else if(S)if(d&&d.length>0&&m.match(d)){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=u+v.length,b=f+v.length;let _=m.match(/^\s*|\s*$/g);if(h&&_){let xe=_[0]||"",Y=_[1]||"";k=xe+v+m.trim()+y+Y,w+=xe.length,b-=Y.length}return{text:k,selectionStart:w,selectionEnd:b}}}function Ye(i,e){let{prefix:t,suffix:n,surroundWithNewlines:o}=e,r=i.value.slice(i.selectionStart,i.selectionEnd),s=i.selectionStart,a=i.selectionEnd,l=r.split(`
52
+ `);if(l.every(d=>d.startsWith(t)&&(!n||d.endsWith(n))))r=l.map(d=>{let p=d.slice(t.length);return n&&(p=p.slice(0,p.length-n.length)),p}).join(`
53
+ `),a=s+r.length;else if(r=l.map(d=>t+d+(n||"")).join(`
54
+ `),o){let{newlinesToAppend:d,newlinesToPrepend:p}=Xe(i);s+=d.length,a=s+r.length,r=d+r+p}return{text:r,selectionStart:s,selectionEnd:a}}function gt(i){let e=i.split(`
55
+ `),t=/^\d+\.\s+/,n=e.every(r=>t.test(r)),o=e;return n&&(o=e.map(r=>r.replace(t,""))),{text:o.join(`
56
+ `),processed:n}}function vt(i){let e=i.split(`
57
+ `),t="- ",n=e.every(r=>r.startsWith(t)),o=e;return n&&(o=e.map(r=>r.slice(t.length))),{text:o.join(`
58
+ `),processed:n}}function se(i,e){return e?"- ":`${i+1}. `}function Ri(i,e){let t,n,o;return i.orderedList?(t=gt(e),n=vt(t.text),o=n.text):(t=vt(e),n=gt(t.text),o=n.text),[t,n,o]}function Oi(i,e){let t=i.selectionStart===i.selectionEnd,n=i.selectionStart,o=i.selectionEnd;xt(i);let r=i.value.slice(i.selectionStart,i.selectionEnd),[s,a,l]=Ri(e,r),c=l.split(`
59
+ `).map((m,v)=>`${se(v,e.unorderedList)}${m}`),d=c.reduce((m,v,y)=>m+se(y,e.unorderedList).length,0),p=c.reduce((m,v,y)=>m+se(y,!e.unorderedList).length,0);if(s.processed)return t?(n=Math.max(n-se(0,e.unorderedList).length,0),o=n):(n=i.selectionStart,o=i.selectionEnd-d),{text:l,selectionStart:n,selectionEnd:o};let{newlinesToAppend:h,newlinesToPrepend:u}=Xe(i),f=h+c.join(`
60
+ `)+u;return t?(n=Math.max(n+se(0,e.unorderedList).length+h.length,0),o=n):a.processed?(n=Math.max(i.selectionStart+h.length,0),o=i.selectionEnd+h.length+d-p):(n=Math.max(i.selectionStart+h.length,0),o=i.selectionEnd+h.length+d),{text:f,selectionStart:n,selectionEnd:o}}function St(i,e){let t=Ee(i,n=>Oi(n,e),{adjustSelection:(n,o,r,s)=>{let a=i.value.slice(s,i.selectionEnd),l=/^\d+\.\s+/,c=/^- /,d=l.test(a),p=c.test(a),h=e.orderedList&&d||e.unorderedList&&p;if(o===r)if(h){let u=a.match(e.orderedList?l:c),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(d||p){let u=a.match(d?l:c),f=u?u[0].length:0,v=(e.unorderedList?2:3)-f;return{start:o+v,end:o+v}}else{let u=e.unorderedList?2:3;return{start:o+u,end:o+u}}else if(h){let u=a.match(e.orderedList?l:c),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(d||p){let u=a.match(d?l:c),f=u?u[0].length:0,v=(e.unorderedList?2:3)-f;return{start:o+v,end:r+v}}else{let u=e.unorderedList?2:3;return{start:o+u,end:r+u}}}});z(i,t)}function Lt(i){if(!i)return[];let e=[],{selectionStart:t,selectionEnd:n,value:o}=i,r=o.split(`
61
+ `),s=0,a="";for(let p of r){if(t>=s&&t<=s+p.length){a=p;break}s+=p.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,t-10),c=Math.min(o.length,n+10),d=o.slice(l,c);if(d.includes("**")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(n,Math.min(o.length,n+100)),u=p.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(d.includes("_")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(n,Math.min(o.length,n+100)),u=p.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(d.includes("`")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(n,Math.min(o.length,n+100));p.includes("`")&&h.includes("`")&&e.push("code")}if(d.includes("[")&&d.includes("]")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(n,Math.min(o.length,n+100)),u=p.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&o.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function $i(i,e){return Lt(i).includes(e)}function Bi(i,e={}){if(!i)return;let{toWord:t,toLine:n,toFormat:o}=e,{selectionStart:r,selectionEnd:s,value:a}=i;if(n){let l=a.split(`
62
+ `),c=0,d=0,p=0;for(let h of l){if(r>=p&&r<=p+h.length){c=p,d=p+h.length;break}p+=h.length+1}i.selectionStart=c,i.selectionEnd=d}else if(t&&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++;i.selectionStart=l,i.selectionEnd=c}}function Ae(i){if(!i||i.disabled||i.readOnly)return;x("toggleBold","Starting"),_e(i,"Before");let e=B($.bold),t=te(i,e);wt(t),z(i,t),_e(i,"After")}function Te(i){if(!i||i.disabled||i.readOnly)return;let e=B($.italic),t=te(i,e);z(i,t)}function Ce(i){if(!i||i.disabled||i.readOnly)return;let e=B($.code),t=te(i,e);z(i,t)}function Ie(i,e={}){if(!i||i.disabled||i.readOnly)return;let t=i.value.slice(i.selectionStart,i.selectionEnd),n=B($.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(n.suffix=`](${t})`,n.replaceNext=""):e.url&&(n.suffix=`](${e.url})`,n.replaceNext=""),e.text&&!t){let s=i.selectionStart;i.value=i.value.slice(0,s)+e.text+i.value.slice(s),i.selectionStart=s,i.selectionEnd=s+e.text.length}let r=te(i,n);z(i,r)}function Me(i){if(!i||i.disabled||i.readOnly)return;let e=B($.bulletList);St(i,e)}function He(i){if(!i||i.disabled||i.readOnly)return;let e=B($.numberedList);St(i,e)}function Pe(i){if(!i||i.disabled||i.readOnly)return;x("toggleQuote","Starting"),_e(i,"Initial");let e=B($.quote),t=Ee(i,n=>Ye(n,e),{prefix:e.prefix});wt(t),z(i,t),_e(i,"Final")}function le(i){if(!i||i.disabled||i.readOnly)return;let e=B($.taskList),t=Ee(i,n=>Ye(n,e),{prefix:e.prefix});z(i,t)}function ce(i,e=1,t=!1){if(!i||i.disabled||i.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${t}`),x("insertHeader",`Initial cursor: ${i.selectionStart}-${i.selectionEnd}`);let n=`header${e===1?"1":e}`,o=B($[n]||$.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=i.value,s=i.selectionStart,a=i.selectionEnd,l=s;for(;l>0&&r[l-1]!==`
63
+ `;)l--;let c=a;for(;c<r.length&&r[c]!==`
64
+ `;)c++;let d=r.slice(l,c);x("insertHeader",`Current line (before): "${d}"`);let p=d.match(/^(#{1,6})\s*/),h=p?p[1].length:0,u=p?p[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${h}`),x("insertHeader",` - Existing prefix length: ${u}`),x("insertHeader",` - Target level: ${e}`);let f=t&&h===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${h}, level=${e})`);let m=Ee(i,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):h>0?(x("insertHeader",`ACTION: Replacing H${h} 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 S=Math.max(y-u,b);return x("insertHeader",` - Removing header, adjusting by -${u}`),{start:S,end:y===w?S:Math.max(w-u,b)}}else if(u>0){let S=o.prefix.length-u;return x("insertHeader",` - Replacing header, adjusting by ${S}`),{start:y+S,end:w+S}}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 ============"),z(i,m)}function Re(i){ce(i,1,!0)}function Oe(i){ce(i,2,!0)}function $e(i){ce(i,3,!0)}function Be(i){return Lt(i)}function _t(i,e){return $i(i,e)}function Et(i,e={}){Bi(i,e)}function At(i,e){if(!i||i.disabled||i.readOnly)return;let t=B(e),n;if(t.multiline){let o=i.value.slice(i.selectionStart,i.selectionEnd);Je(o)?n=Ye(i,t):n=te(i,t)}else n=te(i,t);z(i,n)}var Di={toggleBold:Ae,toggleItalic:Te,toggleCode:Ce,insertLink:Ie,toggleBulletList:Me,toggleNumberedList:He,toggleQuote:Pe,toggleTaskList:le,insertHeader:ce,toggleH1:Re,toggleH2:Oe,toggleH3:$e,getActiveFormats:Be,hasFormat:_t,expandSelection:Et,applyCustomFormat:At,preserveSelection:kt,setUndoMethod:bt,setDebugMode:yt,getDebugMode:Ge};var De=class{constructor(e,t={}){this.editor=e,this.container=null,this.buttons={},this.currentItemIndex=0,this.handleDocumentClick=null,this.activeDropdown=null,this.activeDropdownButton=null,this.toolbarButtons=t.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 t=this.createSeparator();this.container.appendChild(t)}else{let t=this.createButton(e);this.buttons[e.name]=t,this.container.appendChild(t)}}),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",t=>{this.onToolbarKeydown(t)}),this.container.addEventListener("focusin",t=>{this.onToolbarFocusin(t)}))}getToolbarItems(){return this.container?Array.from(this.container.querySelectorAll(".overtype-toolbar-button")):[]}onToolbarKeydown(e){let t=this.getToolbarItems();if(t.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(t.length-1);break}}onToolbarFocusin(e){let t=this.getToolbarItems().indexOf(e.target);t!==-1&&(this.currentItemIndex=t,this.updateTabIndexes())}focusItem(e){let t=this.getToolbarItems();t.length!==0&&(this.currentItemIndex=this.getValidItemIndex(e,t),this.updateTabIndexes(),t[this.currentItemIndex].focus())}getValidItemIndex(e,t=this.getToolbarItems()){let n=t.length;return n===0?0:e<0?n-1:e>=n?0:e}updateTabIndexes(){this.getToolbarItems().forEach((e,t)=>{e.tabIndex=t===this.currentItemIndex?0:-1})}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.setAttribute("data-button",e.name),t.title=e.title||"",t.setAttribute("aria-label",e.title||e.name),t.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(t.classList.add("has-dropdown"),t.dataset.dropdown="true",t.setAttribute("aria-haspopup","menu"),t.setAttribute("aria-expanded","false"),t._clickHandler=n=>{n.preventDefault(),this.toggleViewModeDropdown(t)},t._keydownHandler=n=>{if(!["ArrowDown","ArrowUp","Enter"," "].includes(n.key))return;n.preventDefault();let o=n.key==="ArrowUp"?"last":"current";this.openViewModeDropdown(t,o)},t.addEventListener("click",t._clickHandler),t.addEventListener("keydown",t._keydownHandler),t):(t._clickHandler=n=>{n.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,n)},t.addEventListener("click",t._clickHandler),t)}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:t=>this.editor.setValue(t),event:null}),!0}catch(t){return console.error(`Action "${e.name}" error:`,t),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:t}})),!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,t=null){this.closeViewModeDropdown(e),e.classList.add("dropdown-active");let n=this.createViewModeDropdown(e),o=e.getBoundingClientRect();n.style.position="absolute",n.style.top=`${o.bottom+5}px`,n.style.left=`${o.left}px`,document.body.appendChild(n),this.activeDropdown=n,this.activeDropdownButton=e,e.setAttribute("aria-controls",n.id),e.setAttribute("aria-expanded","true"),this.handleDocumentClick=r=>{!n.contains(r.target)&&!e.contains(r.target)&&this.closeViewModeDropdown(e)},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0),t&&this.focusViewModeMenuItem(n,t)}closeViewModeDropdown(e=this.activeDropdownButton,t=!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,t&&e&&e.focus()}createViewModeDropdown(e){let t=document.createElement("div");t.className="overtype-dropdown-menu",t.id=this.getInstanceElementId("toolbar-view-mode-menu"),t.setAttribute("role","menu"),t.setAttribute("aria-label","View mode"),t.addEventListener("keydown",r=>{this.onViewModeMenuKeydown(r,e)});let n=[{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 n.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)}),t.appendChild(s)}),t}onViewModeMenuKeydown(e,t){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(t,!0);break}}focusViewModeMenuItem(e,t){let n=this.getViewModeMenuItems(e);if(n.length===0)return;let o=t;t==="first"?o=0:t==="last"?o=n.length-1:t==="current"&&(o=n.findIndex(r=>r.getAttribute("aria-checked")==="true")),o<0&&(o=n.length-1),o>=n.length&&(o=0),n[o].focus()}getViewModeMenuItems(e=this.activeDropdown){return e?Array.from(e.querySelectorAll('[role="menuitemradio"]')):[]}updateButtonStates(){var e;try{let t=((e=Be)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,o])=>{if(n==="viewMode")return;let r=this.toolbarButtons.find(a=>a.name===n);if(!(r!=null&&r.isActive))return;let s=!!r.isActive({editor:this.editor,activeFormats:t});o.classList.toggle("active",s),o.setAttribute("aria-pressed",s.toString())})}catch(t){}}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,U=Math.max,ue=Math.round;var P=i=>({x:i,y:i}),Fi={left:"right",right:"left",bottom:"top",top:"bottom"},zi={start:"end",end:"start"};function et(i,e,t){return U(i,he(e,t))}function fe(i,e){return typeof i=="function"?i(e):i}function W(i){return i.split("-")[0]}function me(i){return i.split("-")[1]}function tt(i){return i==="x"?"y":"x"}function it(i){return i==="y"?"height":"width"}var Ni=new Set(["top","bottom"]);function N(i){return Ni.has(W(i))?"y":"x"}function nt(i){return tt(N(i))}function It(i,e,t){t===void 0&&(t=!1);let n=me(i),o=nt(i),r=it(o),s=o==="x"?n===(t?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=pe(s)),[s,pe(s)]}function Mt(i){let e=pe(i);return[Fe(i),e,Fe(e)]}function Fe(i){return i.replace(/start|end/g,e=>zi[e])}var Tt=["left","right"],Ct=["right","left"],Vi=["top","bottom"],ji=["bottom","top"];function Ui(i,e,t){switch(i){case"top":case"bottom":return t?e?Ct:Tt:e?Tt:Ct;case"left":case"right":return e?Vi:ji;default:return[]}}function Ht(i,e,t,n){let o=me(i),r=Ui(W(i),t==="start",n);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Fe)))),r}function pe(i){return i.replace(/left|right|bottom|top/g,e=>Fi[e])}function Wi(i){return{top:0,right:0,bottom:0,left:0,...i}}function Pt(i){return typeof i!="number"?Wi(i):{top:i,right:i,bottom:i,left:i}}function J(i){let{x:e,y:t,width:n,height:o}=i;return{width:n,height:o,top:t,left:e,right:e+n,bottom:t+o,x:e,y:t}}function Rt(i,e,t){let{reference:n,floating:o}=i,r=N(e),s=nt(e),a=it(s),l=W(e),c=r==="y",d=n.x+n.width/2-o.width/2,p=n.y+n.height/2-o.height/2,h=n[a]/2-o[a]/2,u;switch(l){case"top":u={x:d,y:n.y-o.height};break;case"bottom":u={x:d,y:n.y+n.height};break;case"right":u={x:n.x+n.width,y:p};break;case"left":u={x:n.x-o.width,y:p};break;default:u={x:n.x,y:n.y}}switch(me(e)){case"start":u[s]-=h*(t&&c?-1:1);break;case"end":u[s]+=h*(t&&c?-1:1);break}return u}async function Ot(i,e){var t;e===void 0&&(e={});let{x:n,y:o,platform:r,rects:s,elements:a,strategy:l}=i,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:p="floating",altBoundary:h=!1,padding:u=0}=fe(e,i),f=Pt(u),v=a[h?p==="floating"?"reference":"floating":p],y=J(await r.getClippingRect({element:(t=await(r.isElement==null?void 0:r.isElement(v)))==null||t?v:v.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=p==="floating"?{x:n,y:o,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),S=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)/S.y,bottom:(k.bottom-y.bottom+f.bottom)/S.y,left:(y.left-k.left+f.left)/S.x,right:(k.right-y.right+f.right)/S.x}}var $t=async(i,e,t)=>{let{placement:n="bottom",strategy:o="absolute",middleware:r=[],platform:s}=t,a=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),c=await s.getElementRects({reference:i,floating:e,strategy:o}),{x:d,y:p}=Rt(c,n,l),h=n,u={},f=0;for(let v=0;v<a.length;v++){var m;let{name:y,fn:w}=a[v],{x:b,y:S,data:k,reset:_}=await w({x:d,y:p,initialPlacement:n,placement:h,strategy:o,middlewareData:u,rects:c,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Ot},elements:{reference:i,floating:e}});d=b!=null?b:d,p=S!=null?S:p,u={...u,[y]:{...u[y],...k}},_&&f<=50&&(f++,typeof _=="object"&&(_.placement&&(h=_.placement),_.rects&&(c=_.rects===!0?await s.getElementRects({reference:i,floating:e,strategy:o}):_.rects),{x:d,y:p}=Rt(c,h,l)),v=-1)}return{x:d,y:p,placement:h,strategy:o,middlewareData:u}};var Bt=function(i){return i===void 0&&(i={}),{name:"flip",options:i,async fn(e){var t,n;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:d=!0,crossAxis:p=!0,fallbackPlacements:h,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...v}=fe(i,e);if((t=r.arrow)!=null&&t.alignmentOffset)return{};let y=W(o),w=N(a),b=W(a)===a,S=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(b||!m?[pe(a)]:Mt(a)),_=f!=="none";!h&&_&&k.push(...Ht(a,m,f,S));let xe=[a,...k],Y=await l.detectOverflow(e,v),ke=[],ee=((n=r.flip)==null?void 0:n.overflows)||[];if(d&&ke.push(Y[y]),p){let K=It(o,s,S);ke.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ke}],!ke.every(K=>K<=0)){var st,at;let K=(((st=r.flip)==null?void 0:st.index)||0)+1,Ze=xe[K];if(Ze&&(!(p==="alignment"?w!==N(Ze):!1)||ee.every(H=>N(H.placement)===w?H.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Ze}};let oe=(at=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,H)=>Z.overflows[1]-H.overflows[1])[0])==null?void 0:at.placement;if(!oe)switch(u){case"bestFit":{var lt;let Z=(lt=ee.filter(H=>{if(_){let j=N(H.placement);return j===w||j==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(j=>j>0).reduce((j,bi)=>j+bi,0)]).sort((H,j)=>H[1]-j[1])[0])==null?void 0:lt[0];Z&&(oe=Z);break}case"initialPlacement":oe=a;break}if(o!==oe)return{reset:{placement:oe}}}return{}}}};var qi=new Set(["left","top"]);async function Ki(i,e){let{placement:t,platform:n,elements:o}=i,r=await(n.isRTL==null?void 0:n.isRTL(o.floating)),s=W(t),a=me(t),l=N(t)==="y",c=qi.has(s)?-1:1,d=r&&l?-1:1,p=fe(e,i),{mainAxis:h,crossAxis:u,alignmentAxis:f}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return a&&typeof f=="number"&&(u=a==="end"?f*-1:f),l?{x:u*d,y:h*c}:{x:h*c,y:u*d}}var Dt=function(i){return i===void 0&&(i=0),{name:"offset",options:i,async fn(e){var t,n;let{x:o,y:r,placement:s,middlewareData:a}=e,l=await Ki(e,i);return s===((t=a.offset)==null?void 0:t.placement)&&(n=a.arrow)!=null&&n.alignmentOffset?{}:{x:o+l.x,y:r+l.y,data:{...l,placement:s}}}}},Ft=function(i){return i===void 0&&(i={}),{name:"shift",options:i,async fn(e){let{x:t,y:n,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}=fe(i,e),d={x:t,y:n},p=await r.detectOverflow(e,c),h=N(W(o)),u=tt(h),f=d[u],m=d[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+p[y],S=f-p[w];f=et(b,f,S)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+p[y],S=m-p[w];m=et(b,m,S)}let v=l.fn({...e,[u]:f,[h]:m});return{...v,data:{x:v.x-t,y:v.y-n,enabled:{[u]:s,[h]:a}}}}}};function Ne(){return typeof window<"u"}function G(i){return Nt(i)?(i.nodeName||"").toLowerCase():"#document"}function T(i){var e;return(i==null||(e=i.ownerDocument)==null?void 0:e.defaultView)||window}function D(i){var e;return(e=(Nt(i)?i.ownerDocument:i.document)||window.document)==null?void 0:e.documentElement}function Nt(i){return Ne()?i instanceof Node||i instanceof T(i).Node:!1}function I(i){return Ne()?i instanceof Element||i instanceof T(i).Element:!1}function R(i){return Ne()?i instanceof HTMLElement||i instanceof T(i).HTMLElement:!1}function zt(i){return!Ne()||typeof ShadowRoot>"u"?!1:i instanceof ShadowRoot||i instanceof T(i).ShadowRoot}var Zi=new Set(["inline","contents"]);function ie(i){let{overflow:e,overflowX:t,overflowY:n,display:o}=M(i);return/auto|scroll|overlay|hidden|clip/.test(e+n+t)&&!Zi.has(o)}var Qi=new Set(["table","td","th"]);function Vt(i){return Qi.has(G(i))}var Ji=[":popover-open",":modal"];function ge(i){return Ji.some(e=>{try{return i.matches(e)}catch(t){return!1}})}var Gi=["transform","translate","scale","rotate","perspective"],Xi=["transform","translate","scale","rotate","perspective","filter"],Yi=["paint","layout","strict","content"];function Ve(i){let e=je(),t=I(i)?M(i):i;return Gi.some(n=>t[n]?t[n]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||Xi.some(n=>(t.willChange||"").includes(n))||Yi.some(n=>(t.contain||"").includes(n))}function jt(i){let e=V(i);for(;R(e)&&!X(e);){if(Ve(e))return e;if(ge(e))return null;e=V(e)}return null}function je(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var en=new Set(["html","body","#document"]);function X(i){return en.has(G(i))}function M(i){return T(i).getComputedStyle(i)}function ve(i){return I(i)?{scrollLeft:i.scrollLeft,scrollTop:i.scrollTop}:{scrollLeft:i.scrollX,scrollTop:i.scrollY}}function V(i){if(G(i)==="html")return i;let e=i.assignedSlot||i.parentNode||zt(i)&&i.host||D(i);return zt(e)?e.host:e}function Ut(i){let e=V(i);return X(e)?i.ownerDocument?i.ownerDocument.body:i.body:R(e)&&ie(e)?e:Ut(e)}function ze(i,e,t){var n;e===void 0&&(e=[]),t===void 0&&(t=!0);let o=Ut(i),r=o===((n=i.ownerDocument)==null?void 0:n.body),s=T(o);if(r){let a=Ue(s);return e.concat(s,s.visualViewport||[],ie(o)?o:[],a&&t?ze(a):[])}return e.concat(o,ze(o,[],t))}function Ue(i){return i.parent&&Object.getPrototypeOf(i.parent)?i.frameElement:null}function Zt(i){let e=M(i),t=parseFloat(e.width)||0,n=parseFloat(e.height)||0,o=R(i),r=o?i.offsetWidth:t,s=o?i.offsetHeight:n,a=ue(t)!==r||ue(n)!==s;return a&&(t=r,n=s),{width:t,height:n,$:a}}function Qt(i){return I(i)?i:i.contextElement}function ne(i){let e=Qt(i);if(!R(e))return P(1);let t=e.getBoundingClientRect(),{width:n,height:o,$:r}=Zt(e),s=(r?ue(t.width):t.width)/n,a=(r?ue(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var tn=P(0);function Jt(i){let e=T(i);return!je()||!e.visualViewport?tn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function nn(i,e,t){return e===void 0&&(e=!1),!t||e&&t!==T(i)?!1:e}function ye(i,e,t,n){e===void 0&&(e=!1),t===void 0&&(t=!1);let o=i.getBoundingClientRect(),r=Qt(i),s=P(1);e&&(n?I(n)&&(s=ne(n)):s=ne(i));let a=nn(r,t,n)?Jt(r):P(0),l=(o.left+a.x)/s.x,c=(o.top+a.y)/s.y,d=o.width/s.x,p=o.height/s.y;if(r){let h=T(r),u=n&&I(n)?T(n):n,f=h,m=Ue(f);for(;m&&n&&u!==f;){let v=ne(m),y=m.getBoundingClientRect(),w=M(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*v.x,S=y.top+(m.clientTop+parseFloat(w.paddingTop))*v.y;l*=v.x,c*=v.y,d*=v.x,p*=v.y,l+=b,c+=S,f=T(m),m=Ue(f)}}return J({width:d,height:p,x:l,y:c})}function We(i,e){let t=ve(i).scrollLeft;return e?e.left+t:ye(D(i)).left+t}function Gt(i,e){let t=i.getBoundingClientRect(),n=t.left+e.scrollLeft-We(i,t),o=t.top+e.scrollTop;return{x:n,y:o}}function on(i){let{elements:e,rect:t,offsetParent:n,strategy:o}=i,r=o==="fixed",s=D(n),a=e?ge(e.floating):!1;if(n===s||a&&r)return t;let l={scrollLeft:0,scrollTop:0},c=P(1),d=P(0),p=R(n);if((p||!p&&!r)&&((G(n)!=="body"||ie(s))&&(l=ve(n)),R(n))){let u=ye(n);c=ne(n),d.x=u.x+n.clientLeft,d.y=u.y+n.clientTop}let h=s&&!p&&!r?Gt(s,l):P(0);return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:t.y*c.y-l.scrollTop*c.y+d.y+h.y}}function rn(i){return Array.from(i.getClientRects())}function sn(i){let e=D(i),t=ve(i),n=i.ownerDocument.body,o=U(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),r=U(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),s=-t.scrollLeft+We(i),a=-t.scrollTop;return M(n).direction==="rtl"&&(s+=U(e.clientWidth,n.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Wt=25;function an(i,e){let t=T(i),n=D(i),o=t.visualViewport,r=n.clientWidth,s=n.clientHeight,a=0,l=0;if(o){r=o.width,s=o.height;let d=je();(!d||d&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}let c=We(n);if(c<=0){let d=n.ownerDocument,p=d.body,h=getComputedStyle(p),u=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(n.clientWidth-p.clientWidth-u);f<=Wt&&(r-=f)}else c<=Wt&&(r+=c);return{width:r,height:s,x:a,y:l}}var ln=new Set(["absolute","fixed"]);function cn(i,e){let t=ye(i,!0,e==="fixed"),n=t.top+i.clientTop,o=t.left+i.clientLeft,r=R(i)?ne(i):P(1),s=i.clientWidth*r.x,a=i.clientHeight*r.y,l=o*r.x,c=n*r.y;return{width:s,height:a,x:l,y:c}}function qt(i,e,t){let n;if(e==="viewport")n=an(i,t);else if(e==="document")n=sn(D(i));else if(I(e))n=cn(e,t);else{let o=Jt(i);n={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return J(n)}function Xt(i,e){let t=V(i);return t===e||!I(t)||X(t)?!1:M(t).position==="fixed"||Xt(t,e)}function dn(i,e){let t=e.get(i);if(t)return t;let n=ze(i,[],!1).filter(a=>I(a)&&G(a)!=="body"),o=null,r=M(i).position==="fixed",s=r?V(i):i;for(;I(s)&&!X(s);){let a=M(s),l=Ve(s);!l&&a.position==="fixed"&&(o=null),(r?!l&&!o:!l&&a.position==="static"&&!!o&&ln.has(o.position)||ie(s)&&!l&&Xt(i,s))?n=n.filter(d=>d!==s):o=a,s=V(s)}return e.set(i,n),n}function pn(i){let{element:e,boundary:t,rootBoundary:n,strategy:o}=i,s=[...t==="clippingAncestors"?ge(e)?[]:dn(e,this._c):[].concat(t),n],a=s[0],l=s.reduce((c,d)=>{let p=qt(e,d,o);return c.top=U(p.top,c.top),c.right=he(p.right,c.right),c.bottom=he(p.bottom,c.bottom),c.left=U(p.left,c.left),c},qt(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function hn(i){let{width:e,height:t}=Zt(i);return{width:e,height:t}}function un(i,e,t){let n=R(e),o=D(e),r=t==="fixed",s=ye(i,!0,r,e),a={scrollLeft:0,scrollTop:0},l=P(0);function c(){l.x=We(o)}if(n||!n&&!r)if((G(e)!=="body"||ie(o))&&(a=ve(e)),n){let u=ye(e,!0,r,e);l.x=u.x+e.clientLeft,l.y=u.y+e.clientTop}else o&&c();r&&!n&&o&&c();let d=o&&!n&&!r?Gt(o,a):P(0),p=s.left+a.scrollLeft-l.x-d.x,h=s.top+a.scrollTop-l.y-d.y;return{x:p,y:h,width:s.width,height:s.height}}function ot(i){return M(i).position==="static"}function Kt(i,e){if(!R(i)||M(i).position==="fixed")return null;if(e)return e(i);let t=i.offsetParent;return D(i)===t&&(t=t.ownerDocument.body),t}function Yt(i,e){let t=T(i);if(ge(i))return t;if(!R(i)){let o=V(i);for(;o&&!X(o);){if(I(o)&&!ot(o))return o;o=V(o)}return t}let n=Kt(i,e);for(;n&&Vt(n)&&ot(n);)n=Kt(n,e);return n&&X(n)&&ot(n)&&!Ve(n)?t:n||jt(i)||t}var fn=async function(i){let e=this.getOffsetParent||Yt,t=this.getDimensions,n=await t(i.floating);return{reference:un(i.reference,await e(i.floating),i.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function mn(i){return M(i).direction==="rtl"}var gn={convertOffsetParentRelativeRectToViewportRelativeRect:on,getDocumentElement:D,getClippingRect:pn,getOffsetParent:Yt,getElementRects:fn,getClientRects:rn,getDimensions:hn,getScale:ne,isElement:I,isRTL:mn};var ei=Dt;var ti=Ft,ii=Bt;var ni=(i,e,t)=>{let n=new Map,o={platform:gn,...t},r={...o.platform,_c:n};return $t(i,e,{...o,platform:r})};var qe=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,26 +69,27 @@ ${a}`:r;if(p){let k=n.value[n.selectionStart-1];n.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,t=this.editor.textarea.value,i=this.findLinkAtPosition(t,e);i?(!this.currentLink||this.currentLink.url!==i.url||this.currentLink.index!==i.index)&&this.show(i):this.scheduleHide()}findLinkAtPosition(e,t){let i=/\[([^\]]+)\]\(([^)]+)\)/g,o,r=0;for(;(o=i.exec(e))!==null;){let s=o.index,a=o.index+o[0].length;if(t>=s&&t<=a)return{text:o[1],url:o[2],index:r,start:s,end:a};r++}return null}async show(e){this.currentLink=e,this.cancelHide();let t=this.tooltip.querySelector(".overtype-link-tooltip-url");t.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let t=this.findAnchorElement(e.index);if(!t)return;let i=t.getBoundingClientRect();if(!(i.width===0||i.height===0))try{let{x:o,y:r}=await nn(t,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>',hn='<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>',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)",action:({editor:n})=>{Ee(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:rn,title:"Italic (Ctrl+I)",action:({editor:n})=>{Ce(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:pn,title:"Inline Code",action:({editor:n})=>{Ae(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:cn,title:"Insert Link",action:({editor:n})=>{Te(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:sn,title:"Heading 1",action:({editor:n})=>{Pe(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:an,title:"Heading 2",action:({editor:n})=>{$e(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:ln,title:"Heading 3",action:({editor:n})=>{Re(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:dn,title:"Bullet List",action:({editor:n})=>{He(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:hn,title:"Numbered List",action:({editor:n})=>{Me(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:fn,title:"Task List",action:({editor:n})=>{le&&(le(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:un,title:"Quote",action:({editor:n})=>{Oe(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:mn,title:"Upload File",action:({editor:n})=>{var t,i;if(!((t=n.options.fileUpload)!=null&&t.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((i=n.options.fileUpload.mimeTypes)==null?void 0:i.length)>0&&(e.accept=n.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);n._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:gn,title:"View mode"}},we=[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 ot(n){let e={};return(n||[]).forEach(t=>{if(!t||t.name==="separator")return;let i=t.actionId||t.name;t.action&&(e[i]=t.action)}),e}function vn(n){let e=n||we;return Array.isArray(e)?e.map(t=>({name:(t==null?void 0:t.name)||null,actionId:(t==null?void 0:t.actionId)||(t==null?void 0:t.name)||null,icon:(t==null?void 0:t.icon)||null,title:(t==null?void 0:t.title)||null})):null}function vi(n,e){let t=vn(n),i=vn(e);if(t===null||i===null)return t!==i;if(t.length!==i.length)return!0;for(let o=0;o<t.length;o++){let r=t[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 v=class v{constructor(e,t={}){let i=v._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(t),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,t),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.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 re(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 t={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:i,colors:o,...r}=e;return{...t,...r}}_recoverFromDOM(e,t){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(t){this.wrapper=t,this.container=document.createElement("div"),this.container.className="overtype-container";let i=this.instanceTheme||v.currentTheme||z,o=typeof i=="string"?i:i.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?R(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}t.parentNode.insertBefore(this.container,t),this.container.appendChild(t)}if(!this.wrapper){e&&e.remove(),t&&t.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||z,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let i=typeof this.instanceTheme=="string"?R(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.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 t;let e=this.options.toolbarButtons||we;if((t=this.options.fileUpload)!=null&&t.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=ot(we),this.options.toolbarButtons&&Object.assign(this.actionsById,ot(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,ot([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 t=[],i=/!?\[[^\]]*\]\(([^)\s]+)/g,o;for(;(o=i.exec(e))!==null;)t.push(o[1]);return t}_trackInsertedUrls(e,t){if(!(!this._uploadedFiles||!t||!e))for(let i of this._extractMarkdownUrls(e))this._uploadedFiles.set(i,{filename:t.name,file:t})}_checkForRemovedUploads(){var o;if(!this._uploadedFiles||this._uploadedFiles.size===0)return;let e=(o=this.options.fileUpload)==null?void 0:o.onRemoveFile,t=this.textarea.value,i=[];for(let[r,s]of this._uploadedFiles)t.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 t,i;(i=(t=e==null?void 0:e.clipboardData)==null?void 0:t.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var t,i;(i=(t=e==null?void 0:e.dataTransfer)==null?void 0:t.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let t=[];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){t.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&&t.length>0&&this.options.fileUpload.onInsertFile(t.map(i=>i.file)).then(i=>{(Array.isArray(i)?i:[i]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(t[s].placeholder,r),this._trackInsertedUrls(r,t[s].file)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},i=>{console.error("OverType: File upload failed",i),t.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 t=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,t),s=this.textarea.value.slice(i);this.textarea.value=r+e+s,this.textarea.setSelectionRange(t+e.length,t+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,i=this._getCurrentLine(e,t),o=this.container.dataset.mode==="preview",r=E.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 t=0;t<e.length-1;t+=2){let i=e[t],o=e[t+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,t){return e.substring(0,t).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 i=this.textarea.selectionStart,o=this.textarea.selectionEnd,r=this.textarea.value;if(e.shiftKey&&i===o)return;if(e.preventDefault(),i!==o&&e.shiftKey){let s=r.substring(0,i),a=r.substring(i,o),l=r.substring(o),c=a.split(`
75
- `).map(d=>d.replace(/^ /,"")).join(`
76
- `);document.execCommand?(this.textarea.setSelectionRange(i,o),document.execCommand("insertText",!1,c)):(this.textarea.value=s+c+l,this.textarea.selectionStart=i,this.textarea.selectionEnd=i+c.length)}else if(i!==o){let s=r.substring(0,i),a=r.substring(i,o),l=r.substring(o),c=a.split(`
77
- `).map(d=>" "+d).join(`
78
- `);document.execCommand?(this.textarea.setSelectionRange(i,o),document.execCommand("insertText",!1,c)):(this.textarea.value=s+c+l,this.textarea.selectionStart=i,this.textarea.selectionEnd=i+c.length)}else document.execCommand?document.execCommand("insertText",!1," "):(this.textarea.value=r.substring(0,i)+" "+r.substring(o),this.textarea.selectionStart=this.textarea.selectionEnd=i+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,t=e.selectionStart,i=E.getListContext(e.value,t);return!i||!i.inList?!1:i.content.trim()===""&&t>=i.markerEndPos?(this.deleteListMarker(i),!0):(t>i.markerEndPos&&t<i.lineEnd?this.splitListItem(i,t):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 t=E.createNewListItem(e);document.execCommand("insertText",!1,`
79
- `+t),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}splitListItem(e,t){let i=e.content.substring(t-e.markerEndPos);this.textarea.setSelectionRange(t,e.lineEnd),document.execCommand("delete");let o=E.createNewListItem(e);document.execCommand("insertText",!1,`
80
- `+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,t=this.textarea.selectionStart,i=E.renumberLists(e);if(i!==e){let o=0,r=e.split(`
81
- `),s=i.split(`
82
- `),a=0;for(let p=0;p<r.length&&a<t;p++){if(r[p]!==s[p]){let c=s[p].length-r[p].length;a+r[p].length<t&&(o+=c)}a+=r[p].length+1}this.textarea.value=i;let l=t+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 t=this.textarea.value!==e;this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight(),t&&this._notifyChange()}async performAction(e,t=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:t}),!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 t=this.getValue(),i=E.parse(t,-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}getCleanHTML(){return this.getRenderedHTML({cleanHTML:!0})}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){var o;let t=(o=this.options)==null?void 0:o.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let i=this.toolbar&&this.options.toolbar&&vi(t,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(v._autoInstances.delete(this),this.instanceTheme=e,e==="auto")v._autoInstances.add(this),v._startAutoListener(),this._applyResolvedTheme(Ze("auto"));else{let t=typeof e=="string"?R(e):e,i=typeof t=="string"?t:t.name;if(i&&this.container.setAttribute("data-theme",i),t&&t.colors){let o=Q(t.colors,t.previewColors);this.container.style.cssText+=o}this.updatePreview()}return v._stopAutoListener(),this}_applyResolvedTheme(e){let t=R(e);this.container.setAttribute("data-theme",e),t&&t.colors&&(this.container.style.cssText=Q(t.colors,t.previewColors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,t=e.split(`
83
- `),i=e.length,o=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:i,words:o,lines:t.length,line:l,column:p}):this.statsBar.innerHTML=`
72
+ `,this.tooltip.addEventListener("click",e=>{if(e.preventDefault(),e.stopPropagation(),this.currentLink){let t=E.sanitizeUrl(this.currentLink.url);t!=="#"&&window.open(t,"_blank"),this.hide()}}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,t=this.editor.textarea.value,n=this.findLinkAtPosition(t,e);n?(!this.currentLink||this.currentLink.url!==n.url||this.currentLink.index!==n.index)&&this.show(n):this.scheduleHide()}findLinkAtPosition(e,t){let n=/\[([^\]]+)\]\(([^)]+)\)/g,o,r=0;for(;(o=n.exec(e))!==null;){let s=o.index,a=o.index+o[0].length;if(t>=s&&t<=a)return{text:o[1],url:this.transformUrl(o[2]),index:r,start:s,end:a};r++}return null}transformUrl(e){let t=this.editor.options.transformLinkUrl;if(typeof t!="function")return e;try{let n=t(e);return typeof n=="string"?n:e}catch(n){return console.warn("transformLinkUrl threw:",n),e}}async show(e){this.currentLink=e,this.cancelHide();let t=this.tooltip.querySelector(".overtype-link-tooltip-url");t.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let t=this.findAnchorElement(e.index);if(!t)return;let n=t.getBoundingClientRect();if(!(n.width===0||n.height===0))try{let{x:o,y:r}=await ni(t,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[ei(8),ti({padding:8}),ii()]});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 oi='<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>',ri='<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>',si='<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>',ai='<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>',li='<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>',ci='<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>',di='<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>',pi='<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>',hi='<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>',ui='<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>',fi='<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>',mi='<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>',gi='<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 L={bold:{name:"bold",actionId:"toggleBold",icon:oi,title:"Bold (Ctrl+B)",isActive:({activeFormats:i})=>i.includes("bold"),action:({editor:i})=>{Ae(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:ri,title:"Italic (Ctrl+I)",isActive:({activeFormats:i})=>i.includes("italic"),action:({editor:i})=>{Te(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:di,title:"Inline Code",isActive:()=>!1,action:({editor:i})=>{Ce(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:ci,title:"Insert Link",action:({editor:i})=>{Ie(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:si,title:"Heading 1",isActive:({activeFormats:i})=>i.includes("header"),action:({editor:i})=>{Re(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:ai,title:"Heading 2",isActive:({activeFormats:i})=>i.includes("header-2"),action:({editor:i})=>{Oe(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:li,title:"Heading 3",isActive:({activeFormats:i})=>i.includes("header-3"),action:({editor:i})=>{$e(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:pi,title:"Bullet List",isActive:({activeFormats:i})=>i.includes("bullet-list"),action:({editor:i})=>{Me(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:hi,title:"Numbered List",isActive:({activeFormats:i})=>i.includes("numbered-list"),action:({editor:i})=>{He(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:fi,title:"Task List",isActive:({activeFormats:i})=>i.includes("task-list"),action:({editor:i})=>{le&&(le(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:ui,title:"Quote",isActive:({activeFormats:i})=>i.includes("quote"),action:({editor:i})=>{Pe(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:mi,title:"Upload File",action:({editor:i})=>{var t,n;if(!((t=i.options.fileUpload)!=null&&t.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((n=i.options.fileUpload.mimeTypes)==null?void 0:n.length)>0&&(e.accept=i.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);i._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:gi,title:"View mode"}},we=[L.bold,L.italic,L.code,L.separator,L.link,L.separator,L.h1,L.h2,L.h3,L.separator,L.bulletList,L.orderedList,L.taskList,L.separator,L.quote,L.separator,L.viewMode];var be;function yn(){if(be!==void 0)return be;if(be=!1,typeof navigator<"u"){let i=navigator.userAgent||"";be=/^((?!chrome|android|crios|fxios|edg|opr).)*safari/i.test(i)||/iPad|iPhone|iPod/.test(i)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1&&/Safari/.test(i)}return be}function rt(i){let e={};return(i||[]).forEach(t=>{if(!t||t.name==="separator")return;let n=t.actionId||t.name;t.action&&(e[n]=t.action)}),e}function vi(i){let e=i||we;return Array.isArray(e)?e.map(t=>({name:(t==null?void 0:t.name)||null,actionId:(t==null?void 0:t.actionId)||(t==null?void 0:t.name)||null,icon:(t==null?void 0:t.icon)||null,title:(t==null?void 0:t.title)||null})):null}function wn(i,e){let t=vi(i),n=vi(e);if(t===null||n===null)return t!==n;if(t.length!==n.length)return!0;for(let o=0;o<t.length;o++){let r=t[o],s=n[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,t={}){let n=g._resolveTargets(e);if(typeof e=="string"&&n.length===0)throw new Error(`No elements found for selector: ${e}`);return n.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(t),r.overTypeInstance;let s=Object.create(g.prototype);return s._init(r,t),r.overTypeInstance=s,g.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++g.instanceCount,this.initialized=!1,this._isSafari=yn(),this._safariReflowRaf=null,g.injectStyles(),g.initGlobalListeners();let n=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");n||o?this._recoverFromDOM(n,o):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new re(this),this._rebuildActionsMap(),this.linkTooltip=new qe(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 t={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:n,colors:o,...r}=e;return{...t,...r}}_recoverFromDOM(e,t){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(t){this.wrapper=t,this.container=document.createElement("div"),this.container.className="overtype-container";let n=this.instanceTheme||g.currentTheme||F,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?O(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}t.parentNode.insertBefore(this.container,t),this.container.appendChild(t)}if(!this.wrapper){e&&e.remove(),t&&t.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||F,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let n=typeof this.instanceTheme=="string"?O(this.instanceTheme):this.instanceTheme;if(n&&n.colors){let o=Q(n.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(([n,o])=>{n==="className"||n==="class"?this.textarea.className+=" "+o:n==="style"&&typeof o=="object"?Object.assign(this.textarea.style,o):this.textarea.setAttribute(n,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 t;let e=this.options.toolbarButtons||we;if((t=this.options.fileUpload)!=null&&t.enabled&&!e.some(n=>(n==null?void 0:n.name)==="upload")){let n=e.findIndex(o=>(o==null?void 0:o.name)==="viewMode");n!==-1?(e=[...e],e.splice(n,0,L.separator,L.upload)):e=[...e,L.separator,L.upload]}this.toolbar=new De(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=rt(we),this.options.toolbarButtons&&Object.assign(this.actionsById,rt(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,rt([L.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 t=[],n=/!?\[[^\]]*\]\(([^)\s]+)/g,o;for(;(o=n.exec(e))!==null;)t.push(o[1]);return t}_trackInsertedUrls(e,t){if(!(!this._uploadedFiles||!t||!e))for(let n of this._extractMarkdownUrls(e))this._uploadedFiles.set(n,{filename:t.name,file:t})}_checkForRemovedUploads(){var o;if(!this._uploadedFiles||this._uploadedFiles.size===0)return;let e=(o=this.options.fileUpload)==null?void 0:o.onRemoveFile,t=this.textarea.value,n=[];for(let[r,s]of this._uploadedFiles)t.includes(r)||n.push({url:r,info:s});for(let{url:r,info:s}of n)this._uploadedFiles.delete(r),e&&e({url:r,filename:s.filename,file:s.file})}_handleFilePaste(e){var t,n;(n=(t=e==null?void 0:e.clipboardData)==null?void 0:t.files)!=null&&n.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var t,n;(n=(t=e==null?void 0:e.dataTransfer)==null?void 0:t.files)!=null&&n.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let t=[];for(let n of e.files){if(n.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(n.type))continue;let o=++this._fileUploadCounter,s=`${n.type.startsWith("image/")?"!":""}[Uploading ${n.name} (#${o})...]()`;if(this.insertAtCursor(`${s}
73
+ `),this.options.fileUpload.batch){t.push({file:n,placeholder:s});continue}this.options.fileUpload.onInsertFile(n).then(a=>{this.textarea.value=this.textarea.value.replace(s,a),this._trackInsertedUrls(a,n),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&&t.length>0&&this.options.fileUpload.onInsertFile(t.map(n=>n.file)).then(n=>{(Array.isArray(n)?n:[n]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(t[s].placeholder,r),this._trackInsertedUrls(r,t[s].file)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},n=>{console.error("OverType: File upload failed",n),t.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 t=this.textarea.selectionStart,n=this.textarea.selectionEnd,o=!1;try{o=document.execCommand("insertText",!1,e)}catch(r){}if(!o){let r=this.textarea.value.slice(0,t),s=this.textarea.value.slice(n);this.textarea.value=r+e+s,this.textarea.setSelectionRange(t+e.length,t+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,n=this._getCurrentLine(e,t),o=this.container.dataset.mode==="preview",r=E.parse(e,n,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 t=0;t<e.length-1;t+=2){let n=e[t],o=e[t+1],r=n.parentElement,s=o.parentElement;!r||!s||(n.style.display="block",o.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,t){return e.substring(0,t).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 n=this.textarea.selectionStart,o=this.textarea.selectionEnd;if(n!==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,t=e.selectionStart,n=E.getListContext(e.value,t);return!n||!n.inList?!1:n.content.trim()===""&&t>=n.markerEndPos?(this.deleteListMarker(n),!0):(t>n.markerEndPos&&t<n.lineEnd?this.splitListItem(n,t):this.insertNewListItem(n),n.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 t=E.createNewListItem(e);document.execCommand("insertText",!1,`
75
+ `+t),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}splitListItem(e,t){let n=e.content.substring(t-e.markerEndPos);this.textarea.setSelectionRange(t,e.lineEnd),document.execCommand("delete");let o=E.createNewListItem(e);document.execCommand("insertText",!1,`
76
+ `+o+n);let r=this.textarea.selectionStart-n.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,t=this.textarea.selectionStart,n=E.renumberLists(e);if(n!==e){let o=0,r=e.split(`
77
+ `),s=n.split(`
78
+ `),a=0;for(let c=0;c<r.length&&a<t;c++){if(r[c]!==s[c]){let d=s[c].length-r[c].length;a+r[c].length<t&&(o+=d)}a+=r[c].length+1}this.textarea.value=n;let l=t+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 t=this.textarea.value!==e;this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight(),t&&(this._notifyChange(),this._scheduleSafariReflow())}async performAction(e,t=null){var r;let n=this.textarea;if(!n)return!1;let o=(r=this.actionsById)==null?void 0:r[e];if(!o)return console.warn(`OverType: Unknown action "${e}"`),!1;n.focus();try{return await o({editor:this,getValue:()=>this.getValue(),setValue:s=>this.setValue(s),event:t}),!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 t=this.getValue(),n=E.parse(t,-1,!1,this.options.codeHighlighter);return e.cleanHTML&&(n=n.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g,""),n=n.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g,""),n=n.replace(/\sclass=""/g,"")),n}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 t=this.textarea,{selectionStart:n,selectionEnd:o,value:r}=t,s=r.lastIndexOf(`
79
+ `,n-1)+1,a=this._effectiveSelectionEnd(r,n,o),l=r.indexOf(`
80
+ `,a),c=l===-1?r.length:l,d=r.slice(s,c),p=d.split(`
81
+ `).map(e).join(`
82
+ `);if(p===d)return!1;t.setSelectionRange(s,c);let h=!1;try{h=document.execCommand("insertText",!1,p)}catch(u){}return h||t.setRangeText(p,s,c,"preserve"),t.setSelectionRange(s,s+p.length),t.dispatchEvent(new Event("input",{bubbles:!0})),!0}_effectiveSelectionEnd(e,t,n){return n>t&&e[n-1]===`
83
+ `?n-1:n}_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 t=(o=this.options)==null?void 0:o.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let n=this.toolbar&&this.options.toolbar&&wn(t,this.options.toolbarButtons);this._rebuildActionsMap(),n&&(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(Qe("auto"));else{let t=typeof e=="string"?O(e):e,n=typeof t=="string"?t:t.name;if(n&&this.container.setAttribute("data-theme",n),t&&t.colors){let o=Q(t.colors,t.previewColors);this.container.style.cssText+=o}this.updatePreview()}return g._stopAutoListener(),this}_applyResolvedTheme(e){let t=O(e);this.container.setAttribute("data-theme",e),t&&t.colors&&(this.container.style.cssText=Q(t.colors,t.previewColors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,t=e.split(`
84
+ `),n=e.length,o=e.split(/\s+/).filter(d=>d.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:n,words:o,lines:t.length,line:l,column:c}):this.statsBar.innerHTML=`
85
86
  <div class="overtype-stat">
86
87
  <span class="live-dot"></span>
87
- <span>${i} chars, ${o} words, ${t.length} lines</span>
88
+ <span>${n} chars, ${o} words, ${t.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,t=this.preview,i=this.wrapper;if(this.container.dataset.mode==="preview"){i.style.removeProperty("height"),t.style.removeProperty("height"),t.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 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"),t.style.setProperty("height",l,"important"),t.style.setProperty("overflow-y",a,"important"),i.style.setProperty("height",l,"important"),e.scrollTop=r,t.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,t={}){return new v(e,t)}static initFromData(e,t={}){return v._resolveTargets(e).map(o=>{let r={...t};for(let s of o.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(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){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){let t;return e instanceof Element?t=e:t=v._resolveTargets(e)[0],t&&(t.overTypeInstance||v.instances.get(t))||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let i=v.getInstance(t);i&&i.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let i=v.currentTheme||z,o=Le({theme:i}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,t=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=t,v._startAutoListener(),v._applyGlobalTheme(Ze("auto"),t);return}v._stopAutoListener(),v._applyGlobalTheme(e,t)}static _applyGlobalTheme(e,t=null){let i=typeof e=="string"?R(e):e;t&&(i=dt(i,t)),v.currentTheme=i,v.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(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let t=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(t,v._globalAutoCustomColors),v._autoInstances.forEach(i=>i._applyResolvedTheme(t))},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){E.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let i=t._instance;i&&i.updatePreview&&i.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let i=t.getEditor();i&&i.updatePreview&&i.updatePreview()}})}static setCustomSyntax(e){E.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let i=t._instance;i&&i.updatePreview&&i.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let i=t.getEditor();i&&i.updatePreview&&i.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),i=t==null?void 0:t._instance;i&&i.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),i=t==null?void 0:t._instance;i&&i.handleKeydown(e)}}),document.addEventListener("focus",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),i=t==null?void 0:t._instance;i&&i.handleFocus(e)}},!0),document.addEventListener("blur",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),i=t==null?void 0:t._instance;i&&i.handleBlur(e)}},!0),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),i=t==null?void 0:t._instance;i&&i.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let i=t.closest(".overtype-wrapper"),o=i==null?void 0:i._instance;o&&(o.options.showStats&&o.statsBar&&o._updateStats(),clearTimeout(o._selectionTimeout),o._selectionTimeout=setTimeout(()=>{o.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};C(v,"instances",new WeakMap),C(v,"stylesInjected",!1),C(v,"globalListenersInitialized",!1),C(v,"instanceCount",0),C(v,"_autoMediaQuery",null),C(v,"_autoMediaListener",null),C(v,"_autoInstances",new Set),C(v,"_globalAutoTheme",!1),C(v,"_globalAutoCustomColors",null);var q=v;q.MarkdownParser=E;q.ShortcutsManager=re;q.themes={solar:z,cave:R("cave")};q.getTheme=R;q.currentTheme=z;var yn=q;var wn="overtype-webcomponent-container",yi="Start typing...",wi=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly","spellcheck"],qe=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._editor=null,this._initialized=!1,this._pendingOptions={},this._styleVersion=0,this._baseStyleElement=null,this._selectionChangeHandler=null,this._isConnected=!1,this._handleChange=this._handleChange.bind(this),this._handleKeydown=this._handleKeydown.bind(this),this._handleRender=this._handleRender.bind(this)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
91
- `).replace(/\\t/g," ")}static get observedAttributes(){return wi}connectedCallback(){this._isConnected=!0,this._initializeEditor()}disconnectedCallback(){this._isConnected=!1,this._cleanup()}attributeChangedCallback(e,t,i){if(t!==i&&!this._silentUpdate){if(!this._initialized){this._pendingOptions[e]=i;return}this._updateOption(e,i)}}_initializeEditor(){if(!(this._initialized||!this._isConnected))try{let e=document.createElement("div");e.className=wn;let t=this.getAttribute("height"),i=this.getAttribute("min-height"),o=this.getAttribute("max-height");t&&(e.style.height=t),i&&(e.style.minHeight=i),o&&(e.style.maxHeight=o),this._injectStyles(),this.shadowRoot.appendChild(e);let r=this._getOptionsFromAttributes(),s=new yn(e,r);this._editor=s[0],this._initialized=!0,this._editor&&this._editor.textarea&&(this._editor.textarea.addEventListener("scroll",()=>{this._editor&&this._editor.preview&&this._editor.textarea&&(this._editor.preview.scrollTop=this._editor.textarea.scrollTop,this._editor.preview.scrollLeft=this._editor.textarea.scrollLeft)}),this._editor.textarea.addEventListener("input",a=>{this._editor&&this._editor.handleInput&&this._editor.handleInput(a)}),this._editor.textarea.addEventListener("keydown",a=>{this._editor&&this._editor.handleKeydown&&this._editor.handleKeydown(a)}),this._selectionChangeHandler=()=>{if(document.activeElement===this){let a=this.shadowRoot.activeElement;a&&a===this._editor.textarea&&(this._editor.options.showStats&&this._editor.statsBar&&this._editor._updateStats(),this._editor.linkTooltip&&this._editor.linkTooltip.checkCursorPosition&&this._editor.linkTooltip.checkCursorPosition())}},document.addEventListener("selectionchange",this._selectionChangeHandler)),this._applyPendingOptions(),this._dispatchEvent("ready",{editor:this._editor})}catch(e){let t=e&&e.message?e.message:String(e);console.warn("OverType Web Component initialization failed:",t),this._dispatchEvent("error",{error:{message:t}})}}_injectStyles(){let e=document.createElement("style"),t=this.getAttribute("theme")||"solar",i=R(t),o=this._getOptionsFromAttributes(),r=Le({...o,theme:i}),s=`
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,t=this.preview,n=this.wrapper;if(this.container.dataset.mode==="preview"){n.style.removeProperty("height"),t.style.removeProperty("height"),t.style.removeProperty("overflow-y"),e.style.removeProperty("height"),e.style.removeProperty("overflow-y");return}let r=e.scrollTop;n.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"),t.style.setProperty("height",l,"important"),t.style.setProperty("overflow-y",a,"important"),n.style.setProperty("height",l,"important"),e.scrollTop=r,t.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,t={}){return new g(e,t)}static initFromData(e,t={}){return g._resolveTargets(e).map(o=>{let r={...t};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,(d,p)=>p.toUpperCase());r.textareaProps={...r.textareaProps||{},[c]:g._parseDataValue(s.value)};continue}let l=a.replace(/-([a-z])/g,(c,d)=>d.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 t=e.trim();if(t[0]==="{"||t[0]==="[")try{return JSON.parse(t)}catch(n){return e}return e}static getInstance(e){let t;return e instanceof Element?t=e:t=g._resolveTargets(e)[0],t&&(t.overTypeInstance||g.instances.get(t))||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let n=g.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(g.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=g.currentTheme||F,o=Le({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),g.stylesInjected=!0}static setTheme(e,t=null){if(g._globalAutoTheme=!1,g._globalAutoCustomColors=null,e==="auto"){g._globalAutoTheme=!0,g._globalAutoCustomColors=t,g._startAutoListener(),g._applyGlobalTheme(Qe("auto"),t);return}g._stopAutoListener(),g._applyGlobalTheme(e,t)}static _applyGlobalTheme(e,t=null){let n=typeof e=="string"?O(e):e;t&&(n=ht(n,t)),g.currentTheme=n,g.injectStyles(!0);let o=typeof n=="string"?n:n.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 t=e.matches?"cave":"solar";g._globalAutoTheme&&g._applyGlobalTheme(t,g._globalAutoCustomColors),g._autoInstances.forEach(n=>n._applyResolvedTheme(t))},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){E.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static setCustomSyntax(e){E.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static initGlobalListeners(){let e=typeof window<"u"?window:globalThis,t="__overtypeGlobalListenersInitialized";if(g.globalListenersInitialized||e[t]){g.globalListenersInitialized=!0;return}e[t]=!0,document.addEventListener("input",n=>{if(n.target&&n.target.classList&&n.target.classList.contains("overtype-input")){let o=n.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleInput(n)}}),document.addEventListener("keydown",n=>{if(n.target&&n.target.classList&&n.target.classList.contains("overtype-input")){let o=n.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleKeydown(n)}}),document.addEventListener("focus",n=>{if(n.target&&n.target.classList&&n.target.classList.contains("overtype-input")){let o=n.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleFocus(n)}},!0),document.addEventListener("blur",n=>{if(n.target&&n.target.classList&&n.target.classList.contains("overtype-input")){let o=n.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleBlur(n)}},!0),document.addEventListener("scroll",n=>{if(n.target&&n.target.classList&&n.target.classList.contains("overtype-input")){let o=n.target.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&r.handleScroll(n)}},!0),document.addEventListener("selectionchange",n=>{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 q=g;q.MarkdownParser=E;q.ShortcutsManager=re;q.themes={solar:F,cave:O("cave")};q.getTheme=O;q.currentTheme=F;var yi=q;var wi="overtype-webcomponent-container",bn="Start typing...",xn=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly","spellcheck"],Ke=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._editor=null,this._initialized=!1,this._pendingOptions={},this._styleVersion=0,this._baseStyleElement=null,this._selectionChangeHandler=null,this._isConnected=!1,this._handleChange=this._handleChange.bind(this),this._handleKeydown=this._handleKeydown.bind(this),this._handleRender=this._handleRender.bind(this)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
92
+ `).replace(/\\t/g," ")}static get observedAttributes(){return xn}connectedCallback(){this._isConnected=!0,this._initializeEditor()}disconnectedCallback(){this._isConnected=!1,this._cleanup()}attributeChangedCallback(e,t,n){if(t!==n&&!this._silentUpdate){if(!this._initialized){this._pendingOptions[e]=n;return}this._updateOption(e,n)}}_initializeEditor(){if(!(this._initialized||!this._isConnected))try{let e=document.createElement("div");e.className=wi;let t=this.getAttribute("height"),n=this.getAttribute("min-height"),o=this.getAttribute("max-height");t&&(e.style.height=t),n&&(e.style.minHeight=n),o&&(e.style.maxHeight=o),this._injectStyles(),this.shadowRoot.appendChild(e);let r=this._getOptionsFromAttributes(),s=new yi(e,r);this._editor=s[0],this._initialized=!0,this._editor&&this._editor.textarea&&(this._editor.textarea.addEventListener("scroll",()=>{this._editor&&this._editor.preview&&this._editor.textarea&&(this._editor.preview.scrollTop=this._editor.textarea.scrollTop,this._editor.preview.scrollLeft=this._editor.textarea.scrollLeft)}),this._editor.textarea.addEventListener("input",a=>{this._editor&&this._editor.handleInput&&this._editor.handleInput(a)}),this._editor.textarea.addEventListener("keydown",a=>{this._editor&&this._editor.handleKeydown&&this._editor.handleKeydown(a)}),this._selectionChangeHandler=()=>{if(document.activeElement===this){let a=this.shadowRoot.activeElement;a&&a===this._editor.textarea&&(this._editor.options.showStats&&this._editor.statsBar&&this._editor._updateStats(),this._editor.linkTooltip&&this._editor.linkTooltip.checkCursorPosition&&this._editor.linkTooltip.checkCursorPosition())}},document.addEventListener("selectionchange",this._selectionChangeHandler)),this._applyPendingOptions(),this._dispatchEvent("ready",{editor:this._editor})}catch(e){let t=e&&e.message?e.message:String(e);console.warn("OverType Web Component initialization failed:",t),this._dispatchEvent("error",{error:{message:t}})}}_injectStyles(){let e=document.createElement("style"),t=this.getAttribute("theme")||"solar",n=O(t),o=this._getOptionsFromAttributes(),r=Le({...o,theme:n}),s=`
92
93
  /* Web Component Host Styles */
93
94
  :host {
94
95
  display: block;
@@ -110,9 +111,9 @@ ${a}`:r;if(p){let k=n.value[n.selectionStart-1];n.selectionStart!==0&&k!=null&&!
110
111
  }
111
112
  `;this._styleVersion+=1;let a=`
112
113
  /* overtype-webcomponent styles v${this._styleVersion} */
113
- `;e.textContent=a+r+s,this._baseStyleElement=e,this.shadowRoot.appendChild(e)}_getOptionsFromAttributes(){let e={value:this.getAttribute("value")!==null?this._decodeValue(this.getAttribute("value")):(this.textContent||"").trim(),placeholder:this.getAttribute("placeholder")||yi,toolbar:this.hasAttribute("toolbar"),autofocus:this.hasAttribute("autofocus"),autoResize:this.hasAttribute("auto-resize"),showStats:this.hasAttribute("show-stats"),smartLists:!this.hasAttribute("smart-lists")||this.getAttribute("smart-lists")!=="false",spellcheck:this.hasAttribute("spellcheck")&&this.getAttribute("spellcheck")!=="false",onChange:this._handleChange,onKeydown:this._handleKeydown,onRender:this._handleRender},t=this.getAttribute("font-size");t&&(e.fontSize=t);let i=this.getAttribute("line-height");i&&(e.lineHeight=parseFloat(i)||1.6);let o=this.getAttribute("padding");o&&(e.padding=o);let r=this.getAttribute("min-height");r&&(e.minHeight=r);let s=this.getAttribute("max-height");return s&&(e.maxHeight=s),e}_applyPendingOptions(){for(let[e,t]of Object.entries(this._pendingOptions))this._updateOption(e,t);this._pendingOptions={}}_updateOption(e,t){if(this._editor)switch(e){case"value":{let i=this._decodeValue(t);this._editor.getValue()!==i&&this._editor.setValue(i||"")}break;case"theme":this._reinjectStyles(),this._editor&&this._editor.setTheme&&this._editor.setTheme(t||"solar");break;case"placeholder":this._editor&&(this._editor.options.placeholder=t||"",this._editor.textarea&&(this._editor.textarea.placeholder=t||""),this._editor.placeholderEl&&(this._editor.placeholderEl.textContent=t||""));break;case"readonly":this._editor.textarea&&(this._editor.textarea.readOnly=this.hasAttribute("readonly"));break;case"height":case"min-height":case"max-height":this._updateContainerHeight();break;case"toolbar":if(!!this.hasAttribute("toolbar")==!!this._editor.options.toolbar)return;this._reinitializeEditor();break;case"auto-resize":if(!!this.hasAttribute("auto-resize")==!!this._editor.options.autoResize)return;this._reinitializeEditor();break;case"show-stats":if(!!this.hasAttribute("show-stats")==!!this._editor.options.showStats)return;this._reinitializeEditor();break;case"font-size":{this._updateFontSize(t)&&this._reinjectStyles();break}case"line-height":{this._updateLineHeight(t)&&this._reinjectStyles();break}case"padding":this._reinjectStyles();break;case"smart-lists":{let i=!this.hasAttribute("smart-lists")||this.getAttribute("smart-lists")!=="false";if(!!this._editor.options.smartLists==!!i)return;this._reinitializeEditor();break}case"spellcheck":if(this._editor){let i=this.hasAttribute("spellcheck")&&this.getAttribute("spellcheck")!=="false";this._editor.options.spellcheck=i,this._editor.textarea&&this._editor.textarea.setAttribute("spellcheck",String(i))}break}}_updateContainerHeight(){let e=this.shadowRoot.querySelector(`.${wn}`);if(!e)return;let t=this.getAttribute("height"),i=this.getAttribute("min-height"),o=this.getAttribute("max-height");e.style.height=t||"",e.style.minHeight=i||"",e.style.maxHeight=o||""}_updateFontSize(e){return this._editor&&this._editor.wrapper?(this._editor.options.fontSize=e||"",this._editor.wrapper.style.setProperty("--instance-font-size",this._editor.options.fontSize),this._editor.updatePreview(),!0):!1}_updateLineHeight(e){if(this._editor&&this._editor.wrapper){let t=parseFloat(e),i=Number.isFinite(t)?t:this._editor.options.lineHeight;return this._editor.options.lineHeight=i,this._editor.wrapper.style.setProperty("--instance-line-height",String(i)),this._editor.updatePreview(),!0}return!1}_reinjectStyles(){this._baseStyleElement&&this._baseStyleElement.parentNode&&this._baseStyleElement.remove(),this._injectStyles()}_reinitializeEditor(){let e=this._editor?this._editor.getValue():"";this._cleanup(),this._initialized=!1,this.shadowRoot.innerHTML="",e&&!this.getAttribute("value")&&this.setAttribute("value",e),this._initializeEditor()}_handleChange(e){this._updateValueAttribute(e),!(!this._initialized||!this._editor)&&this._dispatchEvent("change",{value:e,editor:this._editor})}_handleKeydown(e){this._dispatchEvent("keydown",{event:e,editor:this._editor})}_handleRender(e,t){this._dispatchEvent("render",{preview:e,mode:t,editor:this._editor})}_updateValueAttribute(e){this.getAttribute("value")!==e&&(this._silentUpdate=!0,this.setAttribute("value",e),this._silentUpdate=!1)}_dispatchEvent(e,t={}){let i=new CustomEvent(e,{detail:t,bubbles:!0,composed:!0});this.dispatchEvent(i)}_cleanup(){this._selectionChangeHandler&&(document.removeEventListener("selectionchange",this._selectionChangeHandler),this._selectionChangeHandler=null),this._editor&&typeof this._editor.destroy=="function"&&this._editor.destroy(),this._editor=null,this._initialized=!1,this.shadowRoot&&(this.shadowRoot.innerHTML="")}refreshTheme(){this._initialized&&this._reinjectStyles()}getValue(){return this._editor?this._editor.getValue():this.getAttribute("value")||""}setValue(e){this._editor?this._editor.setValue(e):this.setAttribute("value",e)}getHTML(){return this._editor?this._editor.getRenderedHTML(!1):""}insertText(e){!this._editor||typeof e!="string"||this._editor.insertText(e)}focus(){this._editor&&this._editor.textarea&&this._editor.textarea.focus()}blur(){this._editor&&this._editor.textarea&&this._editor.textarea.blur()}getStats(){if(!this._editor||!this._editor.textarea)return null;let e=this._editor.textarea.value,t=e.split(`
114
- `),i=e.length,o=e.split(/\s+/).filter(c=>c.length>0).length,r=this._editor.textarea.selectionStart,a=e.substring(0,r).split(`
115
- `),l=a.length,p=a[a.length-1].length+1;return{characters:i,words:o,lines:t.length,line:l,column:p}}isReady(){return this._initialized&&this._editor!==null}getEditor(){return this._editor}showToolbar(){this._editor&&this._editor.showToolbar()}hideToolbar(){this._editor&&this._editor.hideToolbar()}};customElements.get("overtype-editor")||customElements.define("overtype-editor",qe);var bi=qe;return En(xi);})();
114
+ `;e.textContent=a+r+s,this._baseStyleElement=e,this.shadowRoot.appendChild(e)}_getOptionsFromAttributes(){let e={value:this.getAttribute("value")!==null?this._decodeValue(this.getAttribute("value")):(this.textContent||"").trim(),placeholder:this.getAttribute("placeholder")||bn,toolbar:this.hasAttribute("toolbar"),autofocus:this.hasAttribute("autofocus"),autoResize:this.hasAttribute("auto-resize"),showStats:this.hasAttribute("show-stats"),smartLists:!this.hasAttribute("smart-lists")||this.getAttribute("smart-lists")!=="false",spellcheck:this.hasAttribute("spellcheck")&&this.getAttribute("spellcheck")!=="false",onChange:this._handleChange,onKeydown:this._handleKeydown,onRender:this._handleRender},t=this.getAttribute("font-size");t&&(e.fontSize=t);let n=this.getAttribute("line-height");n&&(e.lineHeight=parseFloat(n)||1.6);let o=this.getAttribute("padding");o&&(e.padding=o);let r=this.getAttribute("min-height");r&&(e.minHeight=r);let s=this.getAttribute("max-height");return s&&(e.maxHeight=s),e}_applyPendingOptions(){for(let[e,t]of Object.entries(this._pendingOptions))this._updateOption(e,t);this._pendingOptions={}}_updateOption(e,t){if(this._editor)switch(e){case"value":{let n=this._decodeValue(t);this._editor.getValue()!==n&&this._editor.setValue(n||"")}break;case"theme":this._reinjectStyles(),this._editor&&this._editor.setTheme&&this._editor.setTheme(t||"solar");break;case"placeholder":this._editor&&(this._editor.options.placeholder=t||"",this._editor.textarea&&(this._editor.textarea.placeholder=t||""),this._editor.placeholderEl&&(this._editor.placeholderEl.textContent=t||""));break;case"readonly":this._editor.textarea&&(this._editor.textarea.readOnly=this.hasAttribute("readonly"));break;case"height":case"min-height":case"max-height":this._updateContainerHeight();break;case"toolbar":if(!!this.hasAttribute("toolbar")==!!this._editor.options.toolbar)return;this._reinitializeEditor();break;case"auto-resize":if(!!this.hasAttribute("auto-resize")==!!this._editor.options.autoResize)return;this._reinitializeEditor();break;case"show-stats":if(!!this.hasAttribute("show-stats")==!!this._editor.options.showStats)return;this._reinitializeEditor();break;case"font-size":{this._updateFontSize(t)&&this._reinjectStyles();break}case"line-height":{this._updateLineHeight(t)&&this._reinjectStyles();break}case"padding":this._reinjectStyles();break;case"smart-lists":{let n=!this.hasAttribute("smart-lists")||this.getAttribute("smart-lists")!=="false";if(!!this._editor.options.smartLists==!!n)return;this._reinitializeEditor();break}case"spellcheck":if(this._editor){let n=this.hasAttribute("spellcheck")&&this.getAttribute("spellcheck")!=="false";this._editor.options.spellcheck=n,this._editor.textarea&&this._editor.textarea.setAttribute("spellcheck",String(n))}break}}_updateContainerHeight(){let e=this.shadowRoot.querySelector(`.${wi}`);if(!e)return;let t=this.getAttribute("height"),n=this.getAttribute("min-height"),o=this.getAttribute("max-height");e.style.height=t||"",e.style.minHeight=n||"",e.style.maxHeight=o||""}_updateFontSize(e){return this._editor&&this._editor.wrapper?(this._editor.options.fontSize=e||"",this._editor.wrapper.style.setProperty("--instance-font-size",this._editor.options.fontSize),this._editor.updatePreview(),!0):!1}_updateLineHeight(e){if(this._editor&&this._editor.wrapper){let t=parseFloat(e),n=Number.isFinite(t)?t:this._editor.options.lineHeight;return this._editor.options.lineHeight=n,this._editor.wrapper.style.setProperty("--instance-line-height",String(n)),this._editor.updatePreview(),!0}return!1}_reinjectStyles(){this._baseStyleElement&&this._baseStyleElement.parentNode&&this._baseStyleElement.remove(),this._injectStyles()}_reinitializeEditor(){let e=this._editor?this._editor.getValue():"";this._cleanup(),this._initialized=!1,this.shadowRoot.innerHTML="",e&&!this.getAttribute("value")&&this.setAttribute("value",e),this._initializeEditor()}_handleChange(e){this._updateValueAttribute(e),!(!this._initialized||!this._editor)&&this._dispatchEvent("change",{value:e,editor:this._editor})}_handleKeydown(e){this._dispatchEvent("keydown",{event:e,editor:this._editor})}_handleRender(e,t){this._dispatchEvent("render",{preview:e,mode:t,editor:this._editor})}_updateValueAttribute(e){this.getAttribute("value")!==e&&(this._silentUpdate=!0,this.setAttribute("value",e),this._silentUpdate=!1)}_dispatchEvent(e,t={}){let n=new CustomEvent(e,{detail:t,bubbles:!0,composed:!0});this.dispatchEvent(n)}_cleanup(){this._selectionChangeHandler&&(document.removeEventListener("selectionchange",this._selectionChangeHandler),this._selectionChangeHandler=null),this._editor&&typeof this._editor.destroy=="function"&&this._editor.destroy(),this._editor=null,this._initialized=!1,this.shadowRoot&&(this.shadowRoot.innerHTML="")}refreshTheme(){this._initialized&&this._reinjectStyles()}getValue(){return this._editor?this._editor.getValue():this.getAttribute("value")||""}setValue(e){this._editor?this._editor.setValue(e):this.setAttribute("value",e)}getHTML(){return this._editor?this._editor.getRenderedHTML(!1):""}insertText(e){!this._editor||typeof e!="string"||this._editor.insertText(e)}focus(){this._editor&&this._editor.textarea&&this._editor.textarea.focus()}blur(){this._editor&&this._editor.textarea&&this._editor.textarea.blur()}getStats(){if(!this._editor||!this._editor.textarea)return null;let e=this._editor.textarea.value,t=e.split(`
115
+ `),n=e.length,o=e.split(/\s+/).filter(d=>d.length>0).length,r=this._editor.textarea.selectionStart,a=e.substring(0,r).split(`
116
+ `),l=a.length,c=a[a.length-1].length+1;return{characters:n,words:o,lines:t.length,line:l,column:c}}isReady(){return this._initialized&&this._editor!==null}getEditor(){return this._editor}showToolbar(){this._editor&&this._editor.showToolbar()}hideToolbar(){this._editor&&this._editor.hideToolbar()}};customElements.get("overtype-editor")||customElements.define("overtype-editor",Ke);var kn=Ke;return Ei(Sn);})();
116
117
  /**
117
118
  * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
118
119
  * @version 1.0.0