overtype 2.1.1 → 2.3.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,19 +1,19 @@
1
1
  /**
2
- * OverType v2.1.0
2
+ * OverType v2.3.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 j=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var Ue=(n,e,t)=>e in n?j(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var De=(n,e)=>{for(var t in e)j(n,t,{get:e[t],enumerable:!0})},qe=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Re(e))!Ve.call(n,o)&&o!==t&&j(n,o,{get:()=>e[o],enumerable:!(i=Fe(e,o))||i.enumerable});return n};var We=n=>qe(j({},"__esModule",{value:!0}),n);var E=(n,e,t)=>(Ue(n,typeof e!="symbol"?e+"":e,t),t);var ct={};De(ct,{default:()=>lt});var L=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`<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)=>`${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)=>{if(t){let a=r.toLowerCase()==="x";return`${o}<li class="task-list"><input type="checkbox" ${a?"checked":""}> ${s}</li>`}else return`${o}<li class="task-list"><span class="syntax-marker">- [${r}] </span>${s}</li>`})}static parseNumberedList(e){return e.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/,(t,i,o,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 c=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),d,l=[];for(;(d=c.exec(e))!==null;){let p=d.index,h=d.index+d[0].length;r.some(f=>p>=f.start&&h<=f.end)||l.push({match:d[0],index:d.index,openTicks:d[1],content:d[2],closeTicks:d[3]})}return l.sort((p,h)=>h.index-p.index),l.forEach(p=>{let h=`\uE000${i++}\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${i++}\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((l,p)=>{if(a.includes(p)&&l.type==="code"){let h=`<code><span class="syntax-marker">${l.openTicks}</span>${l.content}<span class="syntax-marker">${l.closeTicks}</span></code>`;a=a.replace(p,h)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let c=`--link-${this.linkIndex++}`;s=`<a href="${this.sanitizeUrl(r.url)}" style="anchor-name: ${c}"><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=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,d=s.map((l,p)=>{if(i&&p===t)return`<div class="raw-line">${this.escapeHtml(l)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(l))return a=!a,this.applyCustomSyntax(this.parseLine(l,r));if(a){let u=this.escapeHtml(l);return`<div>${this.preserveIndentation(u,l)||"&nbsp;"}</div>`}return this.applyCustomSyntax(this.parseLine(l,r))}).join("");return this.postProcessHTML(d,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,c=Array.from(i.children);for(let d=0;d<c.length;d++){let l=c[d];if(!l.parentNode)continue;let p=l.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}`),i.insertBefore(s,l.nextSibling),s._codeElement=f,s._language=m,s._codeContent="";continue}}if(a&&s&&l.tagName==="DIV"&&!l.querySelector(".code-fence")){let u=s._codeElement||s.querySelector("code");s._codeContent.length>0&&(s._codeContent+=`
10
- `);let f=l.textContent.replace(/\u00A0/g," ");s._codeContent+=f,u.textContent.length>0&&(u.textContent+=`
11
- `),u.textContent+=f,l.remove();continue}let h=null;if(l.tagName==="DIV"&&(h=l.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,l),r=m);let g=[];for(let v of l.childNodes)if(v.nodeType===3&&v.textContent.match(/^\u00A0+$/))g.push(v.cloneNode(!0));else if(v===h)break;g.forEach(v=>{h.insertBefore(v,h.firstChild)}),o.appendChild(h),l.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(c=>{let d=c.match(/<div>((?:&nbsp;)*)<li/),l=c.match(/<li class="bullet-list">.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${p}`)}return l?l[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(c=>{let d=c.match(/<div>((?:&nbsp;)*)<li/),l=c.match(/<li class="ordered-list">.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${p}`)}return l?l[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,c)=>{let l=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(g=>g.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
12
- `),p=s.slice(3).trim(),h=p?` class="language-${p}"`:"",u=l,f=t||this.codeHighlighter;if(f)try{let g=l.replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),v=f(g,p);v&&typeof v.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):v&&typeof v=="string"&&v.trim()&&(u=v)}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">${c}</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],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[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:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,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 c=a[1],d=c.length,l=a[3];o||i.clear();let p=(i.get(d)||0)+1;i.set(d,p);for(let[h]of i)h>d&&i.delete(h);return o=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,i.clear()),s}).join(`
15
- `)}};E(L,"linkIndex",0),E(L,"codeHighlighter",null),E(L,"customSyntax",null),E(L,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var z=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 M={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"}},Y={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"}},ee={solar:M,cave:Y,light:M,dark:Y};function T(n){return typeof n=="string"?{...ee[n]||ee.solar,name:n}:n}function B(n){let e=[];for(let[t,i]of Object.entries(n)){let o=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${o}: ${i};`)}return e.join(`
16
- `)}function te(n,e={}){return{...n,colors:{...n.colors,...e}}}function F(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 ve=Object.defineProperty;var di=Object.getOwnPropertyDescriptor;var hi=Object.getOwnPropertyNames;var ui=Object.prototype.hasOwnProperty;var fi=(i,e,t)=>e in i?ve(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var mi=(i,e)=>{for(var t in e)ve(i,t,{get:e[t],enumerable:!0})},gi=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of hi(e))!ui.call(i,o)&&o!==t&&ve(i,o,{get:()=>e[o],enumerable:!(n=di(e,o))||n.enumerable});return i};var vi=i=>gi(ve({},"__esModule",{value:!0}),i);var T=(i,e,t)=>(fi(i,typeof e!="symbol"?e+"":e,t),t);var hn={};mi(hn,{default:()=>dn});var C=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static setCustomSyntax(e){this.customSyntax=e}static applyCustomSyntax(e){return this.customSyntax?this.customSyntax(e):e}static escapeHtml(e){let 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)=>{if(s=this.parseInlineElements(s),t){let a=r.toLowerCase()==="x";return`${o}<li class="task-list"><input type="checkbox" ${a?"checked":""}> ${s}</li>`}else return`${o}<li class="task-list"><span class="syntax-marker">- [${r}] </span>${s}</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 u=a.index+a[0].indexOf("](")+2,h=u+a[2].length;r.push({start:u,end:h})}let c=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),d,l=[];for(;(d=c.exec(e))!==null;){let p=d.index,u=d.index+d[0].length;r.some(f=>p>=f.start&&u<=f.end)||l.push({match:d[0],index:d.index,openTicks:d[1],content:d[2],closeTicks:d[3]})}return l.sort((p,u)=>u.index-p.index),l.forEach(p=>{let u=`\uE000${n++}\uE001`;t.set(u,{type:"code",original:p.match,openTicks:p.openTicks,content:p.content,closeTicks:p.closeTicks}),o=o.substring(0,p.index)+u+o.substring(p.index+p.match.length)}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(p,u,h)=>{let f=`\uE000${n++}\uE001`;return t.set(f,{type:"link",original:p,linkText:u,url:h}),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((l,p)=>{if(a.includes(p)&&l.type==="code"){let u=`<code><span class="syntax-marker">${l.openTicks}</span>${l.content}<span class="syntax-marker">${l.closeTicks}</span></code>`;a=a.replace(p,u)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let c=`--link-${this.linkIndex++}`;s=`<a href="${this.sanitizeUrl(r.url)}" style="anchor-name: ${c}"><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,d=s.map((l,p)=>{if(n&&p===t)return`<div class="raw-line">${this.escapeHtml(l)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(l))return a=!a,this.applyCustomSyntax(this.parseLine(l,r));if(a){let h=this.escapeHtml(l);return`<div>${this.preserveIndentation(h,l)||"&nbsp;"}</div>`}return this.applyCustomSyntax(this.parseLine(l,r))}).join("");return this.postProcessHTML(d,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,c=Array.from(n.children);for(let d=0;d<c.length;d++){let l=c[d];if(!l.parentNode)continue;let p=l.querySelector(".code-fence");if(p){let h=p.textContent;if(h.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=h.slice(3).trim();m&&(f.className=`language-${m}`),n.insertBefore(s,l.nextSibling),s._codeElement=f,s._language=m,s._codeContent="";continue}}if(a&&s&&l.tagName==="DIV"&&!l.querySelector(".code-fence")){let h=s._codeElement||s.querySelector("code");s._codeContent.length>0&&(s._codeContent+=`
10
+ `);let f=l.textContent.replace(/\u00A0/g," ");s._codeContent+=f,h.textContent.length>0&&(h.textContent+=`
11
+ `),h.textContent+=f,l.remove();continue}let u=null;if(l.tagName==="DIV"&&(u=l.querySelector("li")),u){let h=u.classList.contains("bullet-list"),f=u.classList.contains("ordered-list");if(!h&&!f){o=null,r=null;continue}let m=h?"ul":"ol";(!o||r!==m)&&(o=document.createElement(m),n.insertBefore(o,l),r=m);let g=[];for(let y of l.childNodes)if(y.nodeType===3&&y.textContent.match(/^\u00A0+$/))g.push(y.cloneNode(!0));else if(y===u)break;g.forEach(y=>{u.insertBefore(y,u.firstChild)}),o.appendChild(u),l.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(c=>{let d=c.match(/<div>((?:&nbsp;)*)<li/),l=c.match(/<li class="bullet-list">.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${p}`)}return l?l[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(c=>{let d=c.match(/<div>((?:&nbsp;)*)<li/),l=c.match(/<li class="ordered-list">.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${p}`)}return l?l[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,c)=>{let l=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(g=>g.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
12
+ `),p=s.slice(3).trim(),u=p?` class="language-${p}"`:"",h=l,f=t||this.codeHighlighter;if(f)try{let g=l.replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),y=f(g,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()&&(h=y)}catch(g){console.warn("Code highlighting failed:",g)}let m=`<div><span class="code-fence">${s}</span></div>`;return m+=`<pre class="code-block"><code${u}>${h}</code></pre>`,m+=`<div><span class="code-fence">${c}</span></div>`,m}),n}static getListContext(e,t){let n=e.split(`
13
+ `),o=0,r=0,s=0;for(let u=0;u<n.length;u++){let h=n[u].length;if(o+h>=t){r=u,s=o;break}o+=h+1}let a=n[r],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[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:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,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 c=a[1],d=c.length,l=a[3];o||n.clear();let p=(n.get(d)||0)+1;n.set(d,p);for(let[u]of n)u>d&&n.delete(u);return o=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,n.clear()),s}).join(`
15
+ `)}};T(C,"linkIndex",0),T(C,"codeHighlighter",null),T(C,"customSyntax",null),T(C,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var oe=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 B={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:"#1a1a1a",h1:"#1a1a1a",h2:"#2a2a2a",h3:"#3a3a3a",strong:"inherit",em:"inherit",link:"#0066cc",code:"#1a1a1a",codeBg:"rgba(135, 131, 120, 0.15)",blockquote:"#555",hr:"#ddd",bg:"transparent"}},Ke={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:"#e0e0e0",h2:"#d0d0d0",h3:"#c0c0c0",strong:"inherit",em:"inherit",link:"#6cb6e0",code:"#c5dde8",codeBg:"rgba(255, 255, 255, 0.08)",blockquote:"#9aa8b4",hr:"rgba(255, 255, 255, 0.15)",bg:"transparent"}},Ze={solar:B,cave:Ke,auto:B,light:B,dark:Ke};function $(i){return typeof i=="string"?{...Ze[i]||Ze.solar,name:i}:i}function $e(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}: ${o};`)}return t.join(`
16
+ `)}function Qe(i,e={},t={}){return{...i,colors:{...i.colors,...e},previewColors:{...i.previewColors,...t}}}function ye(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 {
@@ -21,7 +21,7 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
21
21
  `)}
22
22
  }
23
23
  }
24
- `:"",c=r&&r.colors?B(r.colors):"";return`
24
+ `:"",c=r&&r.colors?Q(r.colors,r.previewColors):"";return`
25
25
  /* OverType Editor Styles */
26
26
 
27
27
  /* Middle-ground CSS Reset - Prevent parent styles from leaking in */
@@ -105,7 +105,7 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
105
105
  height: 100% !important;
106
106
 
107
107
  /* Font properties - any difference breaks alignment */
108
- font-family: ${i} !important;
108
+ font-family: ${n} !important;
109
109
  font-variant-ligatures: none !important; /* keep metrics stable for code */
110
110
  font-size: var(--instance-font-size, ${e}) !important;
111
111
  line-height: var(--instance-line-height, ${t}) !important;
@@ -193,17 +193,36 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
193
193
  /* Prevent mobile zoom on focus */
194
194
  touch-action: manipulation !important;
195
195
 
196
- /* Disable autofill and spellcheck */
196
+ /* Disable autofill */
197
197
  autocomplete: off !important;
198
198
  autocorrect: off !important;
199
199
  autocapitalize: off !important;
200
- spellcheck: false !important;
201
200
  }
202
201
 
203
202
  .overtype-wrapper .overtype-input::selection {
204
203
  background-color: var(--selection, rgba(244, 211, 94, 0.4));
205
204
  }
206
205
 
206
+ /* Placeholder shim - visible when textarea is empty */
207
+ .overtype-wrapper .overtype-placeholder {
208
+ position: absolute !important;
209
+ top: 0 !important;
210
+ left: 0 !important;
211
+ width: 100% !important;
212
+ z-index: 0 !important;
213
+ pointer-events: none !important;
214
+ user-select: none !important;
215
+ font-family: ${n} !important;
216
+ font-size: var(--instance-font-size, ${e}) !important;
217
+ line-height: var(--instance-line-height, ${t}) !important;
218
+ padding: var(--instance-padding, ${o}) !important;
219
+ box-sizing: border-box !important;
220
+ color: var(--placeholder, #999) !important;
221
+ overflow: hidden !important;
222
+ white-space: nowrap !important;
223
+ text-overflow: ellipsis !important;
224
+ }
225
+
207
226
  /* Preview layer styles */
208
227
  .overtype-wrapper .overtype-preview {
209
228
  /* Layer positioning */
@@ -344,7 +363,7 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
344
363
  .overtype-wrapper .overtype-preview pre code {
345
364
  background: transparent !important;
346
365
  color: var(--code, #0d3b66) !important;
347
- font-family: ${i} !important; /* Match textarea font exactly for alignment */
366
+ font-family: ${n} !important; /* Match textarea font exactly for alignment */
348
367
  }
349
368
 
350
369
  /* Blockquotes */
@@ -471,6 +490,10 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
471
490
 
472
491
 
473
492
  /* Toolbar Styles */
493
+ .overtype-toolbar.overtype-toolbar-hidden {
494
+ display: none !important;
495
+ }
496
+
474
497
  .overtype-toolbar {
475
498
  display: flex !important;
476
499
  align-items: center !important;
@@ -669,27 +692,29 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
669
692
  }
670
693
 
671
694
  /* Headers - restore proper sizing in preview mode */
672
- .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,
673
- .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,
695
+ .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,
696
+ .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,
674
697
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
675
698
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
676
699
  font-weight: 600 !important;
677
700
  margin: 0 !important;
678
701
  display: block !important;
679
- color: inherit !important; /* Use parent text color */
680
- line-height: 1 !important; /* Tight line height for headings */
702
+ line-height: 1 !important;
681
703
  }
682
-
683
- .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
684
- font-size: 2em !important;
704
+
705
+ .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
706
+ font-size: 2em !important;
707
+ color: var(--preview-h1, #222) !important;
685
708
  }
686
-
687
- .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
688
- font-size: 1.5em !important;
709
+
710
+ .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
711
+ font-size: 1.5em !important;
712
+ color: var(--preview-h2, #333) !important;
689
713
  }
690
-
691
- .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
692
- font-size: 1.17em !important;
714
+
715
+ .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
716
+ font-size: 1.17em !important;
717
+ color: var(--preview-h3, #444) !important;
693
718
  }
694
719
 
695
720
  /* Lists - restore list styling in preview mode */
@@ -739,31 +764,26 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
739
764
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a {
740
765
  pointer-events: auto !important;
741
766
  cursor: pointer !important;
742
- color: var(--link, #0066cc) !important;
767
+ color: var(--preview-link, #0066cc) !important;
743
768
  text-decoration: underline !important;
744
769
  }
745
770
 
746
771
  /* Code blocks - proper pre/code styling in preview mode */
747
772
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
748
- background: #2d2d2d !important;
749
- color: #f8f8f2 !important;
773
+ background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
774
+ color: var(--preview-code, #333) !important;
750
775
  padding: 1.2em !important;
751
776
  border-radius: 3px !important;
752
777
  overflow-x: auto !important;
753
778
  margin: 0 !important;
754
779
  display: block !important;
755
780
  }
756
-
757
- /* Cave theme code block background in preview mode */
758
- .overtype-container[data-theme="cave"][data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
759
- background: #11171F !important;
760
- }
761
781
 
762
782
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block code {
763
783
  background: transparent !important;
764
784
  color: inherit !important;
765
785
  padding: 0 !important;
766
- font-family: ${i} !important;
786
+ font-family: ${n} !important;
767
787
  font-size: 0.9em !important;
768
788
  line-height: 1.4 !important;
769
789
  }
@@ -780,7 +800,8 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
780
800
  /* Blockquotes - enhanced styling in preview mode */
781
801
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote {
782
802
  display: block !important;
783
- border-left: 4px solid var(--blockquote, #ddd) !important;
803
+ border-left: 4px solid var(--preview-blockquote, #666) !important;
804
+ color: var(--preview-blockquote, #666) !important;
784
805
  padding-left: 1em !important;
785
806
  margin: 1em 0 !important;
786
807
  font-style: italic !important;
@@ -791,14 +812,16 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
791
812
  font-family: Georgia, 'Times New Roman', serif !important;
792
813
  font-size: 16px !important;
793
814
  line-height: 1.8 !important;
794
- color: var(--text, #333) !important; /* Consistent text color */
815
+ color: var(--preview-text, #333) !important;
816
+ background: var(--preview-bg, transparent) !important;
795
817
  }
796
818
 
797
819
  /* Inline code in preview mode - keep monospace */
798
820
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
799
- font-family: ${i} !important;
821
+ font-family: ${n} !important;
800
822
  font-size: 0.9em !important;
801
- background: rgba(135, 131, 120, 0.15) !important;
823
+ background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
824
+ color: var(--preview-code, #333) !important;
802
825
  padding: 0.2em 0.4em !important;
803
826
  border-radius: 3px !important;
804
827
  }
@@ -806,32 +829,33 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
806
829
  /* Strong and em elements in preview mode */
807
830
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong {
808
831
  font-weight: 700 !important;
809
- color: inherit !important; /* Use parent text color */
832
+ color: var(--preview-strong, inherit) !important;
810
833
  }
811
834
 
812
835
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em {
813
836
  font-style: italic !important;
814
- color: inherit !important; /* Use parent text color */
837
+ color: var(--preview-em, inherit) !important;
815
838
  }
816
839
 
817
840
  /* HR in preview mode */
818
841
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker {
819
842
  display: block !important;
820
- border-top: 2px solid var(--hr, #ddd) !important;
843
+ border-top: 2px solid var(--preview-hr, #ddd) !important;
821
844
  text-indent: -9999px !important;
822
845
  height: 2px !important;
823
846
  }
824
847
 
825
- /* Link Tooltip - Base styles (all browsers) */
848
+ /* Link Tooltip */
826
849
  .overtype-link-tooltip {
827
- /* Visual styles that work for both positioning methods */
828
850
  background: #333 !important;
829
851
  color: white !important;
830
852
  padding: 6px 10px !important;
831
853
  border-radius: 16px !important;
832
854
  font-size: 12px !important;
833
855
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
834
- display: none !important;
856
+ display: flex !important;
857
+ visibility: hidden !important;
858
+ pointer-events: none !important;
835
859
  z-index: 10000 !important;
836
860
  cursor: pointer !important;
837
861
  box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
@@ -839,50 +863,39 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
839
863
  white-space: nowrap !important;
840
864
  overflow: hidden !important;
841
865
  text-overflow: ellipsis !important;
842
-
843
- /* Base positioning for Floating UI fallback */
844
- position: absolute;
866
+ position: fixed;
867
+ top: 0;
868
+ left: 0;
845
869
  }
846
870
 
847
871
  .overtype-link-tooltip.visible {
848
- display: flex !important;
849
- }
850
-
851
- /* CSS Anchor Positioning (modern browsers only) */
852
- @supports (position-anchor: --x) and (position-area: center) {
853
- .overtype-link-tooltip {
854
- /* Only anchor positioning specific properties */
855
- position-anchor: var(--target-anchor, --link-0);
856
- position-area: block-end center;
857
- margin-top: 8px !important;
858
- position-try: most-width block-end inline-end, flip-inline, block-start center;
859
- position-visibility: anchors-visible;
860
- }
872
+ visibility: visible !important;
873
+ pointer-events: auto !important;
861
874
  }
862
875
 
863
876
  ${a}
864
- `}var Ke=Object.defineProperty,ie=Object.getOwnPropertySymbols,Ze=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable,ne=(n,e,t)=>e in n?Ke(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,oe=(n,e)=>{for(var t in e||(e={}))Ze.call(e,t)&&ne(n,t,e[t]);if(ie)for(var t of ie(e))Je.call(e,t)&&ne(n,t,e[t]);return n},_={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 Ge(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function H(n){return oe(oe({},Ge()),n)}var V=!1;function Qe(){return V}function y(n,e,t){V&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function R(n,e){if(!V)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 le(n){V&&(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 A=null;function I(n,{text:e,selectionStart:t,selectionEnd:i}){let o=Qe();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),c=n.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(n.value.slice(r,s))));let d=n.value,l=r!==s;if(A===null||A===!0){n.contentEditable="true";try{A=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",A,"for text with",e.split(`
865
- `).length,"lines")}catch(p){A=!1,o&&console.log("execCommand threw error:",p)}n.contentEditable="false"}if(o&&(console.log("canInsertText before:",A),console.log("execCommand result:",A)),A){let p=a+e+c,h=n.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(!A)if(o&&console.log("Using manual insertion"),n.value===d){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}n.value=a+e+c;try{document.execCommand("ms-endUndoUnit")}catch(p){}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 re(n){return n.trim().split(`
866
- `).length>1}function Xe(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function Ye(n,e,t){let i=e,o=t?/\n/:/\s/;for(;n[i]&&!n[i].match(o);)i++;return i}function ce(n){let e=n.value.split(`
867
- `),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 et(n,e,t,i=!1){if(n.selectionStart===n.selectionEnd)n.selectionStart=Xe(n.value,n.selectionStart),n.selectionEnd=Ye(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 Z(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="",c="";return e.match(/\S/)&&r<2&&(a=`
877
+ `}var yi=Object.defineProperty,Ge=Object.getOwnPropertySymbols,bi=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,Je=(i,e,t)=>e in i?yi(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,Xe=(i,e)=>{for(var t in e||(e={}))bi.call(e,t)&&Je(i,t,e[t]);if(Ge)for(var t of Ge(e))wi.call(e,t)&&Je(i,t,e[t]);return i},R={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 xi(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function F(i){return Xe(Xe({},xi()),i)}var we=!1;function ki(){return we}function x(i,e,t){we&&(console.group(`\u{1F50D} ${i}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function be(i,e){if(!we)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 it(i){we&&(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 z=null;function V(i,{text:e,selectionStart:t,selectionEnd:n}){let o=ki();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),c=i.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(i.value.slice(r,s))));let d=i.value,l=r!==s;if(z===null||z===!0){i.contentEditable="true";try{z=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",z,"for text with",e.split(`
878
+ `).length,"lines")}catch(p){z=!1,o&&console.log("execCommand threw error:",p)}i.contentEditable="false"}if(o&&(console.log("canInsertText before:",z),console.log("execCommand result:",z)),z){let p=a+e+c,u=i.value;o&&(console.log("Expected length:",p.length),console.log("Actual length:",u.length)),u!==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(u.slice(0,100))))}if(!z)if(o&&console.log("Using manual insertion"),i.value===d){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}i.value=a+e+c;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 Ye(i){return i.trim().split(`
879
+ `).length>1}function Si(i,e){let t=e;for(;i[t]&&i[t-1]!=null&&!i[t-1].match(/\s/);)t--;return t}function Li(i,e,t){let n=e,o=t?/\n/:/\s/;for(;i[n]&&!i[n].match(o);)n++;return n}function nt(i){let e=i.value.split(`
880
+ `),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 Ei(i,e,t,n=!1){if(i.selectionStart===i.selectionEnd)i.selectionStart=Si(i.value,i.selectionStart),i.selectionEnd=Li(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 Re(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="",c="";return e.match(/\S/)&&r<2&&(a=`
868
881
  `.repeat(2-r)),t.match(/\S/)&&s<2&&(c=`
869
- `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:c}}function U(n,e,t={}){let i=n.selectionStart,o=n.selectionEnd,r=i===o,s=n.value,a=i;for(;a>0&&s[a-1]!==`
870
- `;)a--;if(r){let d=i;for(;d<s.length&&s[d]!==`
871
- `;)d++;n.selectionStart=a,n.selectionEnd=d}else ce(n);let c=e(n);if(t.adjustSelection){let l=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix),p=t.adjustSelection(l,i,o,a);c.selectionStart=p.start,c.selectionEnd=p.end}else if(t.prefix){let l=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix);r?l?(c.selectionStart=Math.max(i-t.prefix.length,a),c.selectionEnd=c.selectionStart):(c.selectionStart=i+t.prefix.length,c.selectionEnd=c.selectionStart):l?(c.selectionStart=Math.max(i-t.prefix.length,a),c.selectionEnd=Math.max(o-t.prefix.length,a)):(c.selectionStart=i+t.prefix.length,c.selectionEnd=o+t.prefix.length)}return c}function D(n,e){let t,i,{prefix:o,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:c,prefixSpace:d,scanFor:l,surroundWithNewlines:p,trimFirst:h}=e,u=n.selectionStart,f=n.selectionEnd,m=n.value.slice(n.selectionStart,n.selectionEnd),g=re(m)&&s&&s.length>0?`${s}
872
- `:o,v=re(m)&&a&&a.length>0?`
873
- ${a}`:r;if(d){let S=n.value[n.selectionStart-1];n.selectionStart!==0&&S!=null&&!S.match(/\s/)&&(g=` ${g}`)}m=et(n,g,v,e.multiline);let b=n.selectionStart,x=n.selectionEnd,$=c&&c.length>0&&v.indexOf(c)>-1&&m.length>0;if(p){let S=Z(n);t=S.newlinesToAppend,i=S.newlinesToPrepend,g=t+o,v+=i}if(m.startsWith(g)&&m.endsWith(v)){let S=m.slice(g.length,m.length-v.length);if(u===f){let C=u-g.length;C=Math.max(C,b),C=Math.min(C,b+S.length),b=x=C}else x=b+S.length;return{text:S,selectionStart:b,selectionEnd:x}}else if($)if(l&&l.length>0&&m.match(l)){v=v.replace(c,m);let S=g+v;return b=x=b+g.length,{text:S,selectionStart:b,selectionEnd:x}}else{let S=g+m+v;return b=b+g.length+m.length+v.indexOf(c),x=b+c.length,{text:S,selectionStart:b,selectionEnd:x}}else{let S=g+m+v;b=u+g.length,x=f+g.length;let C=m.match(/^\s*|\s*$/g);if(h&&C){let Q=C[0]||"",X=C[1]||"";S=Q+g+m.trim()+v+X,b+=Q.length,x-=X.length}return{text:S,selectionStart:b,selectionEnd:x}}}function pe(n,e){let{prefix:t,suffix:i,surroundWithNewlines:o}=e,r=n.value.slice(n.selectionStart,n.selectionEnd),s=n.selectionStart,a=n.selectionEnd,c=r.split(`
874
- `);if(c.every(l=>l.startsWith(t)&&(!i||l.endsWith(i))))r=c.map(l=>{let p=l.slice(t.length);return i&&(p=p.slice(0,p.length-i.length)),p}).join(`
875
- `),a=s+r.length;else if(r=c.map(l=>t+l+(i||"")).join(`
876
- `),o){let{newlinesToAppend:l,newlinesToPrepend:p}=Z(n);s+=l.length,a=s+r.length,r=l+r+p}return{text:r,selectionStart:s,selectionEnd:a}}function se(n){let e=n.split(`
877
- `),t=/^\d+\.\s+/,i=e.every(r=>t.test(r)),o=e;return i&&(o=e.map(r=>r.replace(t,""))),{text:o.join(`
878
- `),processed:i}}function ae(n){let e=n.split(`
879
- `),t="- ",i=e.every(r=>r.startsWith(t)),o=e;return i&&(o=e.map(r=>r.slice(t.length))),{text:o.join(`
880
- `),processed:i}}function N(n,e){return e?"- ":`${n+1}. `}function tt(n,e){let t,i,o;return n.orderedList?(t=se(e),i=ae(t.text),o=i.text):(t=ae(e),i=se(t.text),o=i.text),[t,i,o]}function it(n,e){let t=n.selectionStart===n.selectionEnd,i=n.selectionStart,o=n.selectionEnd;ce(n);let r=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,c]=tt(e,r),d=c.split(`
881
- `).map((m,g)=>`${N(g,e.unorderedList)}${m}`),l=d.reduce((m,g,v)=>m+N(v,e.unorderedList).length,0),p=d.reduce((m,g,v)=>m+N(v,!e.unorderedList).length,0);if(s.processed)return t?(i=Math.max(i-N(0,e.unorderedList).length,0),o=i):(i=n.selectionStart,o=n.selectionEnd-l),{text:c,selectionStart:i,selectionEnd:o};let{newlinesToAppend:h,newlinesToPrepend:u}=Z(n),f=h+d.join(`
882
- `)+u;return t?(i=Math.max(i+N(0,e.unorderedList).length+h.length,0),o=i):a.processed?(i=Math.max(n.selectionStart+h.length,0),o=n.selectionEnd+h.length+l-p):(i=Math.max(n.selectionStart+h.length,0),o=n.selectionEnd+h.length+l),{text:f,selectionStart:i,selectionEnd:o}}function de(n,e){let t=U(n,i=>it(i,e),{adjustSelection:(i,o,r,s)=>{let a=n.value.slice(s,n.selectionEnd),c=/^\d+\.\s+/,d=/^- /,l=c.test(a),p=d.test(a),h=e.orderedList&&l||e.unorderedList&&p;if(o===r)if(h){let u=a.match(e.orderedList?c:d),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||p){let u=a.match(l?c:d),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?c:d),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||p){let u=a.match(l?c:d),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}}}});I(n,t)}function nt(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:i,value:o}=n,r=o.split(`
883
- `),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 c=Math.max(0,t-10),d=Math.min(o.length,i+10),l=o.slice(c,d);if(l.includes("**")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=p.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=p.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100));p.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=p.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&o.slice(i+f+1,i+f+10).startsWith("(")&&e.push("link")}return e}function he(n){if(!n||n.disabled||n.readOnly)return;y("toggleBold","Starting"),R(n,"Before");let e=H(_.bold),t=D(n,e);le(t),I(n,t),R(n,"After")}function ue(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.italic),t=D(n,e);I(n,t)}function me(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.code),t=D(n,e);I(n,t)}function fe(n,e={}){if(!n||n.disabled||n.readOnly)return;let t=n.value.slice(n.selectionStart,n.selectionEnd),i=H(_.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=D(n,i);I(n,r)}function ge(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.bulletList);de(n,e)}function ve(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.numberedList);de(n,e)}function ye(n){if(!n||n.disabled||n.readOnly)return;y("toggleQuote","Starting"),R(n,"Initial");let e=H(_.quote),t=U(n,i=>pe(i,e),{prefix:e.prefix});le(t),I(n,t),R(n,"Final")}function J(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.taskList),t=U(n,i=>pe(i,e),{prefix:e.prefix});I(n,t)}function G(n,e=1,t=!1){if(!n||n.disabled||n.readOnly)return;(e<1||e>6)&&(e=1),y("insertHeader","============ START ============"),y("insertHeader",`Level: ${e}, Toggle: ${t}`),y("insertHeader",`Initial cursor: ${n.selectionStart}-${n.selectionEnd}`);let i=`header${e===1?"1":e}`,o=H(_[i]||_.header1);y("insertHeader",`Style prefix: "${o.prefix}"`);let r=n.value,s=n.selectionStart,a=n.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
882
+ `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:c}}function xe(i,e,t={}){let n=i.selectionStart,o=i.selectionEnd,r=n===o,s=i.value,a=n;for(;a>0&&s[a-1]!==`
883
+ `;)a--;if(r){let d=n;for(;d<s.length&&s[d]!==`
884
+ `;)d++;i.selectionStart=a,i.selectionEnd=d}else nt(i);let c=e(i);if(t.adjustSelection){let l=i.value.slice(i.selectionStart,i.selectionEnd).startsWith(t.prefix),p=t.adjustSelection(l,n,o,a);c.selectionStart=p.start,c.selectionEnd=p.end}else if(t.prefix){let l=i.value.slice(i.selectionStart,i.selectionEnd).startsWith(t.prefix);r?l?(c.selectionStart=Math.max(n-t.prefix.length,a),c.selectionEnd=c.selectionStart):(c.selectionStart=n+t.prefix.length,c.selectionEnd=c.selectionStart):l?(c.selectionStart=Math.max(n-t.prefix.length,a),c.selectionEnd=Math.max(o-t.prefix.length,a)):(c.selectionStart=n+t.prefix.length,c.selectionEnd=o+t.prefix.length)}return c}function ke(i,e){let t,n,{prefix:o,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:c,prefixSpace:d,scanFor:l,surroundWithNewlines:p,trimFirst:u}=e,h=i.selectionStart,f=i.selectionEnd,m=i.value.slice(i.selectionStart,i.selectionEnd),g=Ye(m)&&s&&s.length>0?`${s}
885
+ `:o,y=Ye(m)&&a&&a.length>0?`
886
+ ${a}`:r;if(d){let k=i.value[i.selectionStart-1];i.selectionStart!==0&&k!=null&&!k.match(/\s/)&&(g=` ${g}`)}m=Ei(i,g,y,e.multiline);let b=i.selectionStart,w=i.selectionEnd,S=c&&c.length>0&&y.indexOf(c)>-1&&m.length>0;if(p){let k=Re(i);t=k.newlinesToAppend,n=k.newlinesToPrepend,g=t+o,y+=n}if(m.startsWith(g)&&m.endsWith(y)){let k=m.slice(g.length,m.length-y.length);if(h===f){let E=h-g.length;E=Math.max(E,b),E=Math.min(E,b+k.length),b=w=E}else w=b+k.length;return{text:k,selectionStart:b,selectionEnd:w}}else if(S)if(l&&l.length>0&&m.match(l)){y=y.replace(c,m);let k=g+y;return b=w=b+g.length,{text:k,selectionStart:b,selectionEnd:w}}else{let k=g+m+y;return b=b+g.length+m.length+y.indexOf(c),w=b+c.length,{text:k,selectionStart:b,selectionEnd:w}}else{let k=g+m+y;b=h+g.length,w=f+g.length;let E=m.match(/^\s*|\s*$/g);if(u&&E){let me=E[0]||"",Y=E[1]||"";k=me+g+m.trim()+y+Y,b+=me.length,w-=Y.length}return{text:k,selectionStart:b,selectionEnd:w}}}function ot(i,e){let{prefix:t,suffix:n,surroundWithNewlines:o}=e,r=i.value.slice(i.selectionStart,i.selectionEnd),s=i.selectionStart,a=i.selectionEnd,c=r.split(`
887
+ `);if(c.every(l=>l.startsWith(t)&&(!n||l.endsWith(n))))r=c.map(l=>{let p=l.slice(t.length);return n&&(p=p.slice(0,p.length-n.length)),p}).join(`
888
+ `),a=s+r.length;else if(r=c.map(l=>t+l+(n||"")).join(`
889
+ `),o){let{newlinesToAppend:l,newlinesToPrepend:p}=Re(i);s+=l.length,a=s+r.length,r=l+r+p}return{text:r,selectionStart:s,selectionEnd:a}}function et(i){let e=i.split(`
890
+ `),t=/^\d+\.\s+/,n=e.every(r=>t.test(r)),o=e;return n&&(o=e.map(r=>r.replace(t,""))),{text:o.join(`
891
+ `),processed:n}}function tt(i){let e=i.split(`
892
+ `),t="- ",n=e.every(r=>r.startsWith(t)),o=e;return n&&(o=e.map(r=>r.slice(t.length))),{text:o.join(`
893
+ `),processed:n}}function re(i,e){return e?"- ":`${i+1}. `}function Ci(i,e){let t,n,o;return i.orderedList?(t=et(e),n=tt(t.text),o=n.text):(t=tt(e),n=et(t.text),o=n.text),[t,n,o]}function Ti(i,e){let t=i.selectionStart===i.selectionEnd,n=i.selectionStart,o=i.selectionEnd;nt(i);let r=i.value.slice(i.selectionStart,i.selectionEnd),[s,a,c]=Ci(e,r),d=c.split(`
894
+ `).map((m,g)=>`${re(g,e.unorderedList)}${m}`),l=d.reduce((m,g,y)=>m+re(y,e.unorderedList).length,0),p=d.reduce((m,g,y)=>m+re(y,!e.unorderedList).length,0);if(s.processed)return t?(n=Math.max(n-re(0,e.unorderedList).length,0),o=n):(n=i.selectionStart,o=i.selectionEnd-l),{text:c,selectionStart:n,selectionEnd:o};let{newlinesToAppend:u,newlinesToPrepend:h}=Re(i),f=u+d.join(`
895
+ `)+h;return t?(n=Math.max(n+re(0,e.unorderedList).length+u.length,0),o=n):a.processed?(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l-p):(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l),{text:f,selectionStart:n,selectionEnd:o}}function rt(i,e){let t=xe(i,n=>Ti(n,e),{adjustSelection:(n,o,r,s)=>{let a=i.value.slice(s,i.selectionEnd),c=/^\d+\.\s+/,d=/^- /,l=c.test(a),p=d.test(a),u=e.orderedList&&l||e.unorderedList&&p;if(o===r)if(u){let h=a.match(e.orderedList?c:d),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||p){let h=a.match(l?c:d),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:o+h}}else if(u){let h=a.match(e.orderedList?c:d),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||p){let h=a.match(l?c:d),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:r+h}}}});V(i,t)}function Ai(i){if(!i)return[];let e=[],{selectionStart:t,selectionEnd:n,value:o}=i,r=o.split(`
896
+ `),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 c=Math.max(0,t-10),d=Math.min(o.length,n+10),l=o.slice(c,d);if(l.includes("**")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=p.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=p.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100));p.includes("`")&&u.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=p.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&o.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function st(i){if(!i||i.disabled||i.readOnly)return;x("toggleBold","Starting"),be(i,"Before");let e=F(R.bold),t=ke(i,e);it(t),V(i,t),be(i,"After")}function at(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.italic),t=ke(i,e);V(i,t)}function lt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.code),t=ke(i,e);V(i,t)}function ct(i,e={}){if(!i||i.disabled||i.readOnly)return;let t=i.value.slice(i.selectionStart,i.selectionEnd),n=F(R.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=ke(i,n);V(i,r)}function pt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.bulletList);rt(i,e)}function dt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.numberedList);rt(i,e)}function ht(i){if(!i||i.disabled||i.readOnly)return;x("toggleQuote","Starting"),be(i,"Initial");let e=F(R.quote),t=xe(i,n=>ot(n,e),{prefix:e.prefix});it(t),V(i,t),be(i,"Final")}function Ie(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.taskList),t=xe(i,n=>ot(n,e),{prefix:e.prefix});V(i,t)}function Be(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=F(R[n]||R.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=i.value,s=i.selectionStart,a=i.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
884
897
  `;)c--;let d=a;for(;d<r.length&&r[d]!==`
885
- `;)d++;let l=r.slice(c,d);y("insertHeader",`Current line (before): "${l}"`);let p=l.match(/^(#{1,6})\s*/),h=p?p[1].length:0,u=p?p[0].length:0;y("insertHeader","Existing header check:"),y("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),y("insertHeader",` - Existing level: ${h}`),y("insertHeader",` - Existing prefix length: ${u}`),y("insertHeader",` - Target level: ${e}`);let f=t&&h===e;y("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${h}, level=${e})`);let m=U(n,g=>{let v=g.value.slice(g.selectionStart,g.selectionEnd);y("insertHeader",`Line in operation: "${v}"`);let b=v.replace(/^#{1,6}\s*/,"");y("insertHeader",`Cleaned line: "${b}"`);let x;return f?(y("insertHeader","ACTION: Toggling OFF - removing header"),x=b):h>0?(y("insertHeader",`ACTION: Replacing H${h} with H${e}`),x=o.prefix+b):(y("insertHeader","ACTION: Adding new header"),x=o.prefix+b),y("insertHeader",`New line: "${x}"`),{text:x,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,v,b,x)=>{if(y("insertHeader","Adjusting selection:"),y("insertHeader",` - isRemoving param: ${g}`),y("insertHeader",` - shouldToggleOff: ${f}`),y("insertHeader",` - selStart: ${v}, selEnd: ${b}`),y("insertHeader",` - lineStartPos: ${x}`),f){let $=Math.max(v-u,x);return y("insertHeader",` - Removing header, adjusting by -${u}`),{start:$,end:v===b?$:Math.max(b-u,x)}}else if(u>0){let $=o.prefix.length-u;return y("insertHeader",` - Replacing header, adjusting by ${$}`),{start:v+$,end:b+$}}else return y("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:v+o.prefix.length,end:b+o.prefix.length}}});y("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),y("insertHeader","============ END ============"),I(n,m)}function be(n){G(n,1,!0)}function we(n){G(n,2,!0)}function xe(n){G(n,3,!0)}function ke(n){return nt(n)}var q=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=ke)==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){}}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 W=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.useFloatingUI=!1,this.floatingUI=null,this.isTooltipHovered=!1,this.init()}async init(){if(!(CSS.supports("position-anchor: --x")&&CSS.supports("position-area: center")))try{let t=new Function("url","return import(url)"),{computePosition:i,offset:o,shift:r,flip:s}=await t("https://cdn.jsdelivr.net/npm/@floating-ui/dom@1.7.4/+esm");this.floatingUI={computePosition:i,offset:o,shift:r,flip:s},this.useFloatingUI=!0}catch(t){console.warn("Failed to load Floating UI fallback:",t),this.floatingUI=null,this.useFloatingUI=!1}this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",t=>{(t.key.includes("Arrow")||t.key==="Home"||t.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.useFloatingUI&&this.currentLink?this.showWithFloatingUI(this.currentLink):this.hide()}),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=`
898
+ `;)d++;let l=r.slice(c,d);x("insertHeader",`Current line (before): "${l}"`);let p=l.match(/^(#{1,6})\s*/),u=p?p[1].length:0,h=p?p[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=t&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${u}, level=${e})`);let m=xe(i,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let b=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${b}"`);let w;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),w=b):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),w=o.prefix+b):(x("insertHeader","ACTION: Adding new header"),w=o.prefix+b),x("insertHeader",`New line: "${w}"`),{text:w,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,y,b,w)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${b}`),x("insertHeader",` - lineStartPos: ${w}`),f){let S=Math.max(y-h,w);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:S,end:y===b?S:Math.max(b-h,w)}}else if(h>0){let S=o.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${S}`),{start:y+S,end:b+S}}else return x("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:y+o.prefix.length,end:b+o.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),V(i,m)}function ut(i){Be(i,1,!0)}function ft(i){Be(i,2,!0)}function mt(i){Be(i,3,!0)}function gt(i){return Ai(i)}var Se=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",n=>{n.preventDefault(),this.toggleViewModeDropdown(t)}),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){let t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active");return}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.handleDocumentClick=r=>{!n.contains(r.target)&&!e.contains(r.target)&&(n.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 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.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=gt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,o])=>{if(n==="viewMode")return;let r=!1;switch(n){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 ae=Math.min,U=Math.max,le=Math.round;var O=i=>({x:i,y:i}),_i={left:"right",right:"left",bottom:"top",top:"bottom"},Hi={start:"end",end:"start"};function ze(i,e,t){return U(i,ae(e,t))}function ce(i,e){return typeof i=="function"?i(e):i}function W(i){return i.split("-")[0]}function pe(i){return i.split("-")[1]}function Fe(i){return i==="x"?"y":"x"}function Ne(i){return i==="y"?"height":"width"}var Mi=new Set(["top","bottom"]);function N(i){return Mi.has(W(i))?"y":"x"}function De(i){return Fe(N(i))}function wt(i,e,t){t===void 0&&(t=!1);let n=pe(i),o=De(i),r=Ne(o),s=o==="x"?n===(t?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=se(s)),[s,se(s)]}function xt(i){let e=se(i);return[Le(i),e,Le(e)]}function Le(i){return i.replace(/start|end/g,e=>Hi[e])}var yt=["left","right"],bt=["right","left"],Oi=["top","bottom"],Pi=["bottom","top"];function $i(i,e,t){switch(i){case"top":case"bottom":return t?e?bt:yt:e?yt:bt;case"left":case"right":return e?Oi:Pi;default:return[]}}function kt(i,e,t,n){let o=pe(i),r=$i(W(i),t==="start",n);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Le)))),r}function se(i){return i.replace(/left|right|bottom|top/g,e=>_i[e])}function Ri(i){return{top:0,right:0,bottom:0,left:0,...i}}function St(i){return typeof i!="number"?Ri(i):{top:i,right:i,bottom:i,left:i}}function G(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 Lt(i,e,t){let{reference:n,floating:o}=i,r=N(e),s=De(e),a=Ne(s),c=W(e),d=r==="y",l=n.x+n.width/2-o.width/2,p=n.y+n.height/2-o.height/2,u=n[a]/2-o[a]/2,h;switch(c){case"top":h={x:l,y:n.y-o.height};break;case"bottom":h={x:l,y:n.y+n.height};break;case"right":h={x:n.x+n.width,y:p};break;case"left":h={x:n.x-o.width,y:p};break;default:h={x:n.x,y:n.y}}switch(pe(e)){case"start":h[s]-=u*(t&&d?-1:1);break;case"end":h[s]+=u*(t&&d?-1:1);break}return h}async function Et(i,e){var t;e===void 0&&(e={});let{x:n,y:o,platform:r,rects:s,elements:a,strategy:c}=i,{boundary:d="clippingAncestors",rootBoundary:l="viewport",elementContext:p="floating",altBoundary:u=!1,padding:h=0}=ce(e,i),f=St(h),g=a[u?p==="floating"?"reference":"floating":p],y=G(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:d,rootBoundary:l,strategy:c})),b=p==="floating"?{x:n,y:o,width:s.floating.width,height:s.floating.height}:s.reference,w=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),S=await(r.isElement==null?void 0:r.isElement(w))?await(r.getScale==null?void 0:r.getScale(w))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:w,strategy:c}):b);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 Ct=async(i,e,t)=>{let{placement:n="bottom",strategy:o="absolute",middleware:r=[],platform:s}=t,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),d=await s.getElementRects({reference:i,floating:e,strategy:o}),{x:l,y:p}=Lt(d,n,c),u=n,h={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:b}=a[g],{x:w,y:S,data:k,reset:E}=await b({x:l,y:p,initialPlacement:n,placement:u,strategy:o,middlewareData:h,rects:d,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Et},elements:{reference:i,floating:e}});l=w!=null?w:l,p=S!=null?S:p,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(d=E.rects===!0?await s.getElementRects({reference:i,floating:e,strategy:o}):E.rects),{x:l,y:p}=Lt(d,u,c)),g=-1)}return{x:l,y:p,placement:u,strategy:o,middlewareData:h}};var Tt=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:c,elements:d}=e,{mainAxis:l=!0,crossAxis:p=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=ce(i,e);if((t=r.arrow)!=null&&t.alignmentOffset)return{};let y=W(o),b=N(a),w=W(a)===a,S=await(c.isRTL==null?void 0:c.isRTL(d.floating)),k=u||(w||!m?[se(a)]:xt(a)),E=f!=="none";!u&&E&&k.push(...kt(a,m,f,S));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((n=r.flip)==null?void 0:n.overflows)||[];if(l&&ge.push(Y[y]),p){let K=wt(o,s,S);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ge}],!ge.every(K=>K<=0)){var Ue,We;let K=(((Ue=r.flip)==null?void 0:Ue.index)||0)+1,Pe=me[K];if(Pe&&(!(p==="alignment"?b!==N(Pe):!1)||ee.every(M=>N(M.placement)===b?M.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let ne=(We=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,M)=>Z.overflows[1]-M.overflows[1])[0])==null?void 0:We.placement;if(!ne)switch(h){case"bestFit":{var qe;let Z=(qe=ee.filter(M=>{if(E){let j=N(M.placement);return j===b||j==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(j=>j>0).reduce((j,pi)=>j+pi,0)]).sort((M,j)=>M[1]-j[1])[0])==null?void 0:qe[0];Z&&(ne=Z);break}case"initialPlacement":ne=a;break}if(o!==ne)return{reset:{placement:ne}}}return{}}}};var Ii=new Set(["left","top"]);async function Bi(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=pe(t),c=N(t)==="y",d=Ii.has(s)?-1:1,l=r&&c?-1:1,p=ce(e,i),{mainAxis:u,crossAxis:h,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"&&(h=a==="end"?f*-1:f),c?{x:h*l,y:u*d}:{x:u*d,y:h*l}}var At=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,c=await Bi(e,i);return s===((t=a.offset)==null?void 0:t.placement)&&(n=a.arrow)!=null&&n.alignmentOffset?{}:{x:o+c.x,y:r+c.y,data:{...c,placement:s}}}}},_t=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:c={fn:y=>{let{x:b,y:w}=y;return{x:b,y:w}}},...d}=ce(i,e),l={x:t,y:n},p=await r.detectOverflow(e,d),u=N(W(o)),h=Fe(u),f=l[h],m=l[u];if(s){let y=h==="y"?"top":"left",b=h==="y"?"bottom":"right",w=f+p[y],S=f-p[b];f=ze(w,f,S)}if(a){let y=u==="y"?"top":"left",b=u==="y"?"bottom":"right",w=m+p[y],S=m-p[b];m=ze(w,m,S)}let g=c.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-t,y:g.y-n,enabled:{[h]:s,[u]:a}}}}}};function Ce(){return typeof window<"u"}function J(i){return Mt(i)?(i.nodeName||"").toLowerCase():"#document"}function A(i){var e;return(i==null||(e=i.ownerDocument)==null?void 0:e.defaultView)||window}function I(i){var e;return(e=(Mt(i)?i.ownerDocument:i.document)||window.document)==null?void 0:e.documentElement}function Mt(i){return Ce()?i instanceof Node||i instanceof A(i).Node:!1}function _(i){return Ce()?i instanceof Element||i instanceof A(i).Element:!1}function P(i){return Ce()?i instanceof HTMLElement||i instanceof A(i).HTMLElement:!1}function Ht(i){return!Ce()||typeof ShadowRoot>"u"?!1:i instanceof ShadowRoot||i instanceof A(i).ShadowRoot}var zi=new Set(["inline","contents"]);function te(i){let{overflow:e,overflowX:t,overflowY:n,display:o}=H(i);return/auto|scroll|overlay|hidden|clip/.test(e+n+t)&&!zi.has(o)}var Fi=new Set(["table","td","th"]);function Ot(i){return Fi.has(J(i))}var Ni=[":popover-open",":modal"];function de(i){return Ni.some(e=>{try{return i.matches(e)}catch(t){return!1}})}var Di=["transform","translate","scale","rotate","perspective"],ji=["transform","translate","scale","rotate","perspective","filter"],Vi=["paint","layout","strict","content"];function Te(i){let e=Ae(),t=_(i)?H(i):i;return Di.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)||ji.some(n=>(t.willChange||"").includes(n))||Vi.some(n=>(t.contain||"").includes(n))}function Pt(i){let e=D(i);for(;P(e)&&!X(e);){if(Te(e))return e;if(de(e))return null;e=D(e)}return null}function Ae(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Ui=new Set(["html","body","#document"]);function X(i){return Ui.has(J(i))}function H(i){return A(i).getComputedStyle(i)}function he(i){return _(i)?{scrollLeft:i.scrollLeft,scrollTop:i.scrollTop}:{scrollLeft:i.scrollX,scrollTop:i.scrollY}}function D(i){if(J(i)==="html")return i;let e=i.assignedSlot||i.parentNode||Ht(i)&&i.host||I(i);return Ht(e)?e.host:e}function $t(i){let e=D(i);return X(e)?i.ownerDocument?i.ownerDocument.body:i.body:P(e)&&te(e)?e:$t(e)}function Ee(i,e,t){var n;e===void 0&&(e=[]),t===void 0&&(t=!0);let o=$t(i),r=o===((n=i.ownerDocument)==null?void 0:n.body),s=A(o);if(r){let a=_e(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&t?Ee(a):[])}return e.concat(o,Ee(o,[],t))}function _e(i){return i.parent&&Object.getPrototypeOf(i.parent)?i.frameElement:null}function zt(i){let e=H(i),t=parseFloat(e.width)||0,n=parseFloat(e.height)||0,o=P(i),r=o?i.offsetWidth:t,s=o?i.offsetHeight:n,a=le(t)!==r||le(n)!==s;return a&&(t=r,n=s),{width:t,height:n,$:a}}function Ft(i){return _(i)?i:i.contextElement}function ie(i){let e=Ft(i);if(!P(e))return O(1);let t=e.getBoundingClientRect(),{width:n,height:o,$:r}=zt(e),s=(r?le(t.width):t.width)/n,a=(r?le(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Wi=O(0);function Nt(i){let e=A(i);return!Ae()||!e.visualViewport?Wi:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function qi(i,e,t){return e===void 0&&(e=!1),!t||e&&t!==A(i)?!1:e}function ue(i,e,t,n){e===void 0&&(e=!1),t===void 0&&(t=!1);let o=i.getBoundingClientRect(),r=Ft(i),s=O(1);e&&(n?_(n)&&(s=ie(n)):s=ie(i));let a=qi(r,t,n)?Nt(r):O(0),c=(o.left+a.x)/s.x,d=(o.top+a.y)/s.y,l=o.width/s.x,p=o.height/s.y;if(r){let u=A(r),h=n&&_(n)?A(n):n,f=u,m=_e(f);for(;m&&n&&h!==f;){let g=ie(m),y=m.getBoundingClientRect(),b=H(m),w=y.left+(m.clientLeft+parseFloat(b.paddingLeft))*g.x,S=y.top+(m.clientTop+parseFloat(b.paddingTop))*g.y;c*=g.x,d*=g.y,l*=g.x,p*=g.y,c+=w,d+=S,f=A(m),m=_e(f)}}return G({width:l,height:p,x:c,y:d})}function He(i,e){let t=he(i).scrollLeft;return e?e.left+t:ue(I(i)).left+t}function Dt(i,e){let t=i.getBoundingClientRect(),n=t.left+e.scrollLeft-He(i,t),o=t.top+e.scrollTop;return{x:n,y:o}}function Ki(i){let{elements:e,rect:t,offsetParent:n,strategy:o}=i,r=o==="fixed",s=I(n),a=e?de(e.floating):!1;if(n===s||a&&r)return t;let c={scrollLeft:0,scrollTop:0},d=O(1),l=O(0),p=P(n);if((p||!p&&!r)&&((J(n)!=="body"||te(s))&&(c=he(n)),P(n))){let h=ue(n);d=ie(n),l.x=h.x+n.clientLeft,l.y=h.y+n.clientTop}let u=s&&!p&&!r?Dt(s,c):O(0);return{width:t.width*d.x,height:t.height*d.y,x:t.x*d.x-c.scrollLeft*d.x+l.x+u.x,y:t.y*d.y-c.scrollTop*d.y+l.y+u.y}}function Zi(i){return Array.from(i.getClientRects())}function Qi(i){let e=I(i),t=he(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+He(i),a=-t.scrollTop;return H(n).direction==="rtl"&&(s+=U(e.clientWidth,n.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Rt=25;function Gi(i,e){let t=A(i),n=I(i),o=t.visualViewport,r=n.clientWidth,s=n.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=Ae();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let d=He(n);if(d<=0){let l=n.ownerDocument,p=l.body,u=getComputedStyle(p),h=l.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(n.clientWidth-p.clientWidth-h);f<=Rt&&(r-=f)}else d<=Rt&&(r+=d);return{width:r,height:s,x:a,y:c}}var Ji=new Set(["absolute","fixed"]);function Xi(i,e){let t=ue(i,!0,e==="fixed"),n=t.top+i.clientTop,o=t.left+i.clientLeft,r=P(i)?ie(i):O(1),s=i.clientWidth*r.x,a=i.clientHeight*r.y,c=o*r.x,d=n*r.y;return{width:s,height:a,x:c,y:d}}function It(i,e,t){let n;if(e==="viewport")n=Gi(i,t);else if(e==="document")n=Qi(I(i));else if(_(e))n=Xi(e,t);else{let o=Nt(i);n={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(n)}function jt(i,e){let t=D(i);return t===e||!_(t)||X(t)?!1:H(t).position==="fixed"||jt(t,e)}function Yi(i,e){let t=e.get(i);if(t)return t;let n=Ee(i,[],!1).filter(a=>_(a)&&J(a)!=="body"),o=null,r=H(i).position==="fixed",s=r?D(i):i;for(;_(s)&&!X(s);){let a=H(s),c=Te(s);!c&&a.position==="fixed"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Ji.has(o.position)||te(s)&&!c&&jt(i,s))?n=n.filter(l=>l!==s):o=a,s=D(s)}return e.set(i,n),n}function en(i){let{element:e,boundary:t,rootBoundary:n,strategy:o}=i,s=[...t==="clippingAncestors"?de(e)?[]:Yi(e,this._c):[].concat(t),n],a=s[0],c=s.reduce((d,l)=>{let p=It(e,l,o);return d.top=U(p.top,d.top),d.right=ae(p.right,d.right),d.bottom=ae(p.bottom,d.bottom),d.left=U(p.left,d.left),d},It(e,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function tn(i){let{width:e,height:t}=zt(i);return{width:e,height:t}}function nn(i,e,t){let n=P(e),o=I(e),r=t==="fixed",s=ue(i,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function d(){c.x=He(o)}if(n||!n&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),n){let h=ue(e,!0,r,e);c.x=h.x+e.clientLeft,c.y=h.y+e.clientTop}else o&&d();r&&!n&&o&&d();let l=o&&!n&&!r?Dt(o,a):O(0),p=s.left+a.scrollLeft-c.x-l.x,u=s.top+a.scrollTop-c.y-l.y;return{x:p,y:u,width:s.width,height:s.height}}function je(i){return H(i).position==="static"}function Bt(i,e){if(!P(i)||H(i).position==="fixed")return null;if(e)return e(i);let t=i.offsetParent;return I(i)===t&&(t=t.ownerDocument.body),t}function Vt(i,e){let t=A(i);if(de(i))return t;if(!P(i)){let o=D(i);for(;o&&!X(o);){if(_(o)&&!je(o))return o;o=D(o)}return t}let n=Bt(i,e);for(;n&&Ot(n)&&je(n);)n=Bt(n,e);return n&&X(n)&&je(n)&&!Te(n)?t:n||Pt(i)||t}var on=async function(i){let e=this.getOffsetParent||Vt,t=this.getDimensions,n=await t(i.floating);return{reference:nn(i.reference,await e(i.floating),i.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function rn(i){return H(i).direction==="rtl"}var sn={convertOffsetParentRelativeRectToViewportRelativeRect:Ki,getDocumentElement:I,getClippingRect:en,getOffsetParent:Vt,getElementRects:on,getClientRects:Zi,getDimensions:tn,getScale:ie,isElement:_,isRTL:rn};var Ut=At;var Wt=_t,qt=Tt;var Kt=(i,e,t)=>{let n=new Map,o={platform:sn,...t},r={...o.platform,_c:n};return Ct(i,e,{...o,platform:r})};var Me=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=`
886
899
  <span style="display: flex; align-items: center; gap: 6px;">
887
900
  <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
888
901
  <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>
@@ -890,35 +903,35 @@ ${a}`:r;if(d){let S=n.value[n.selectionStart-1];n.selectionStart!==0&&S!=null&&!
890
903
  </svg>
891
904
  <span class="overtype-link-tooltip-url"></span>
892
905
  </span>
893
- `,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}show(e){this.currentLink=e,this.cancelHide();let t=this.tooltip.querySelector(".overtype-link-tooltip-url");t.textContent=e.url,this.useFloatingUI?this.showWithFloatingUI(e):this.showWithAnchorPositioning(e),this.tooltip.classList.add("visible")}showWithAnchorPositioning(e){this.tooltip.style.setProperty("--target-anchor",`--link-${e.index}`)}async showWithFloatingUI(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 this.floatingUI.computePosition(t,this.tooltip,{placement:"bottom",middleware:[this.floatingUI.offset(8),this.floatingUI.shift({padding:8}),this.floatingUI.flip()]});Object.assign(this.tooltip.style,{left:`${o}px`,top:`${r}px`,position:"absolute"})}catch(o){console.warn("Floating UI positioning failed:",o);return}}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.floatingUI=null,this.useFloatingUI=!1,this.isTooltipHovered=!1}};var Le=`<svg viewBox="0 0 18 18">
906
+ `,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,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: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 n=t.getBoundingClientRect();if(!(n.width===0||n.height===0))try{let{x:o,y:r}=await Kt(t,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Ut(8),Wt({padding:8}),qt()]});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 Zt=`<svg viewBox="0 0 18 18">
894
907
  <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>
895
908
  <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>
896
- </svg>`,Ee=`<svg viewBox="0 0 18 18">
909
+ </svg>`,Qt=`<svg viewBox="0 0 18 18">
897
910
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line>
898
911
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line>
899
912
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line>
900
- </svg>`,_e=`<svg viewBox="0 0 18 18">
913
+ </svg>`,Gt=`<svg viewBox="0 0 18 18">
901
914
  <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>
902
- </svg>`,Ce=`<svg viewBox="0 0 18 18">
915
+ </svg>`,Jt=`<svg viewBox="0 0 18 18">
903
916
  <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>
904
- </svg>`,Te=`<svg viewBox="0 0 18 18">
917
+ </svg>`,Xt=`<svg viewBox="0 0 18 18">
905
918
  <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>
906
- </svg>`,Ae=`<svg viewBox="0 0 18 18">
919
+ </svg>`,Yt=`<svg viewBox="0 0 18 18">
907
920
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line>
908
921
  <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>
909
922
  <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>
910
- </svg>`,He=`<svg viewBox="0 0 18 18">
923
+ </svg>`,ei=`<svg viewBox="0 0 18 18">
911
924
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline>
912
925
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline>
913
926
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
914
- </svg>`,$e=`<svg viewBox="0 0 18 18">
927
+ </svg>`,ti=`<svg viewBox="0 0 18 18">
915
928
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
916
929
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
917
930
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
918
931
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line>
919
932
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line>
920
933
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line>
921
- </svg>`,Me=`<svg viewBox="0 0 18 18">
934
+ </svg>`,ii=`<svg viewBox="0 0 18 18">
922
935
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line>
923
936
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line>
924
937
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line>
@@ -926,38 +939,43 @@ ${a}`:r;if(d){let S=n.value[n.selectionStart-1];n.selectionStart!==0&&S!=null&&!
926
939
  <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>
927
940
  <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>
928
941
  <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>
929
- </svg>`,Ie=`<svg viewBox="2 2 20 20">
942
+ </svg>`,ni=`<svg viewBox="2 2 20 20">
930
943
  <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>
931
944
  <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>
932
- </svg>`,Pe=`<svg viewBox="0 0 18 18">
945
+ </svg>`,oi=`<svg viewBox="0 0 18 18">
933
946
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line>
934
947
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line>
935
948
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line>
936
949
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
937
950
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
938
951
  <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>
939
- </svg>`,Be=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
952
+ </svg>`,ri=`<svg viewBox="0 0 18 18">
953
+ <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>
954
+ <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>
955
+ <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 2.25v10.125"></path>
956
+ </svg>`,si=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
940
957
  <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path>
941
958
  <circle cx="12" cy="12" r="3" fill="none"></circle>
942
- </svg>`;var k={bold:{name:"bold",actionId:"toggleBold",icon:Le,title:"Bold (Ctrl+B)",action:({editor:n})=>{he(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Ee,title:"Italic (Ctrl+I)",action:({editor:n})=>{ue(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:He,title:"Inline Code",action:({editor:n})=>{me(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Ae,title:"Insert Link",action:({editor:n})=>{fe(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:_e,title:"Heading 1",action:({editor:n})=>{be(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Ce,title:"Heading 2",action:({editor:n})=>{we(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Te,title:"Heading 3",action:({editor:n})=>{xe(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:$e,title:"Bullet List",action:({editor:n})=>{ge(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:Me,title:"Numbered List",action:({editor:n})=>{ve(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:Pe,title:"Task List",action:({editor:n})=>{J&&(J(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:Ie,title:"Quote",action:({editor:n})=>{ye(n.textarea),n.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},viewMode:{name:"viewMode",icon:Be,title:"View mode"}},O=[k.bold,k.italic,k.code,k.separator,k.link,k.separator,k.h1,k.h2,k.h3,k.separator,k.bulletList,k.orderedList,k.taskList,k.separator,k.quote,k.separator,k.viewMode];function ze(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 Ne(n){let e=n||O;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 rt(n,e){let t=Ne(n),i=Ne(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 w=class w{constructor(e,t={}){let i;if(typeof e=="string"){if(i=document.querySelectorAll(e),i.length===0)throw new Error(`No elements found for selector: ${e}`);i=Array.from(i)}else if(e instanceof Element)i=[e];else if(e instanceof NodeList)i=Array.from(e);else if(Array.isArray(e))i=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return i.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(t),r.overTypeInstance;let s=Object.create(w.prototype);return s._init(r,t),r.overTypeInstance=s,w.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++w.instanceCount,this.initialized=!1,w.injectStyles(),w.initGlobalListeners();let i=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");i||o?this._recoverFromDOM(i,o):this._buildFromScratch(),this.shortcuts=new z(this),this._rebuildActionsMap(),this.linkTooltip=new W(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_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,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null},{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||w.currentTheme||M,o=typeof i=="string"?i:i.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?T(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=B(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.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._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||w.currentTheme||M,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let i=typeof this.instanceTheme=="string"?T(this.instanceTheme):this.instanceTheme;if(i&&i.colors){let o=B(i.colors);this.container.style.cssText+=o}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-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.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.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),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","false"),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_createToolbar(){let e=this.options.toolbarButtons||O;this.toolbar=new q(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(){this.actionsById=ze(O),this.options.toolbarButtons&&Object.assign(this.actionsById,ze(this.options.toolbarButtons))}_applyOptions(){this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")||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.updatePreview()}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,i=this._getCurrentLine(e,t),o=this.container.dataset.mode==="preview",r=L.parse(e,i,this.options.showActiveLineRaw,this.options.codeHighlighter,o);this.preview.innerHTML=r||'<span style="color: #808080;">Start typing...</span>',this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onChange&&this.initialized&&this.options.onChange(e,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(`
943
- `).length-1}handleInput(e){this.updatePreview()}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),c=r.substring(o),l=a.split(`
959
+ </svg>`;var L={bold:{name:"bold",actionId:"toggleBold",icon:Zt,title:"Bold (Ctrl+B)",action:({editor:i})=>{st(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Qt,title:"Italic (Ctrl+I)",action:({editor:i})=>{at(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:ei,title:"Inline Code",action:({editor:i})=>{lt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Yt,title:"Insert Link",action:({editor:i})=>{ct(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:Gt,title:"Heading 1",action:({editor:i})=>{ut(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Jt,title:"Heading 2",action:({editor:i})=>{ft(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Xt,title:"Heading 3",action:({editor:i})=>{mt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:ti,title:"Bullet List",action:({editor:i})=>{pt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:ii,title:"Numbered List",action:({editor:i})=>{dt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:oi,title:"Task List",action:({editor:i})=>{Ie&&(Ie(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:ni,title:"Quote",action:({editor:i})=>{ht(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:ri,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:si,title:"View mode"}},fe=[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];function Ve(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 ai(i){let e=i||fe;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 ln(i,e){let t=ai(i),n=ai(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 v=class v{constructor(e,t={}){let n;if(typeof e=="string"){if(n=document.querySelectorAll(e),n.length===0)throw new Error(`No elements found for selector: ${e}`);n=Array.from(n)}else if(e instanceof Element)n=[e];else if(e instanceof NodeList)n=Array.from(e);else if(Array.isArray(e))n=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return n.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 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 oe(this),this._rebuildActionsMap(),this.linkTooltip=new Me(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_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,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{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||v.currentTheme||B,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?$(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.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._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||B,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let n=typeof this.instanceTheme=="string"?$(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.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.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.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||fe;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 Se(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=Ve(fe),this.options.toolbarButtons&&Object.assign(this.actionsById,Ve(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,Ve([L.upload]))}_applyOptions(){this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_handleFilePaste(e){var 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}
960
+ `),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.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.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.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=C.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.onChange&&this.initialized&&this.options.onChange(e,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(`
961
+ `).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){if(e.key==="Tab"){let n=this.textarea.selectionStart,o=this.textarea.selectionEnd,r=this.textarea.value;if(e.shiftKey&&n===o)return;if(e.preventDefault(),n!==o&&e.shiftKey){let s=r.substring(0,n),a=r.substring(n,o),c=r.substring(o),l=a.split(`
944
962
  `).map(p=>p.replace(/^ /,"")).join(`
945
- `);document.execCommand?(this.textarea.setSelectionRange(i,o),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=i,this.textarea.selectionEnd=i+l.length)}else if(i!==o){let s=r.substring(0,i),a=r.substring(i,o),c=r.substring(o),l=a.split(`
963
+ `);document.execCommand?(this.textarea.setSelectionRange(n,o),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=n,this.textarea.selectionEnd=n+l.length)}else if(n!==o){let s=r.substring(0,n),a=r.substring(n,o),c=r.substring(o),l=a.split(`
946
964
  `).map(p=>" "+p).join(`
947
- `);document.execCommand?(this.textarea.setSelectionRange(i,o),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=i,this.textarea.selectionEnd=i+l.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=L.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=L.createNewListItem(e);document.execCommand("insertText",!1,`
948
- `+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=L.createNewListItem(e);document.execCommand("insertText",!1,`
949
- `+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=L.renumberLists(e);if(i!==e){let o=0,r=e.split(`
950
- `),s=i.split(`
951
- `),a=0;for(let d=0;d<r.length&&a<t;d++){if(r[d]!==s[d]){let l=s[d].length-r[d].length;a+r[d].length<t&&(o+=l)}a+=r[d].length+1}this.textarea.value=i;let c=t+o;this.textarea.setSelectionRange(c,c),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){this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight()}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=L.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&&rt(t,this.options.toolbarButtons);this._rebuildActionsMap(),i&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null,this._createToolbar()),this._applyOptions(),this.updatePreview()}setTheme(e){this.instanceTheme=e;let t=typeof e=="string"?T(e):e,i=typeof t=="string"?t:t.name;if(i&&this.container.setAttribute("data-theme",i),t&&t.colors){let o=B(t.colors);this.container.style.cssText+=o}return this.updatePreview(),this}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,t=e.split(`
952
- `),i=e.length,o=e.split(/\s+/).filter(l=>l.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
953
- `),c=a.length,d=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:i,words:o,lines:t.length,line:c,column:d}):this.statsBar.innerHTML=`
965
+ `);document.execCommand?(this.textarea.setSelectionRange(n,o),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=n,this.textarea.selectionEnd=n+l.length)}else document.execCommand?document.execCommand("insertText",!1," "):(this.textarea.value=r.substring(0,n)+" "+r.substring(o),this.textarea.selectionStart=this.textarea.selectionEnd=n+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,n=C.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=C.createNewListItem(e);document.execCommand("insertText",!1,`
966
+ `+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=C.createNewListItem(e);document.execCommand("insertText",!1,`
967
+ `+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=C.renumberLists(e);if(n!==e){let o=0,r=e.split(`
968
+ `),s=n.split(`
969
+ `),a=0;for(let d=0;d<r.length&&a<t;d++){if(r[d]!==s[d]){let l=s[d].length-r[d].length;a+r[d].length<t&&(o+=l)}a+=r[d].length+1}this.textarea.value=n;let c=t+o;this.textarea.setSelectionRange(c,c),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){this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight()}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=C.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}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&&ln(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(v._autoInstances.delete(this),this.instanceTheme=e,e==="auto")v._autoInstances.add(this),v._startAutoListener(),this._applyResolvedTheme($e("auto"));else{let t=typeof e=="string"?$(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 v._stopAutoListener(),this}_applyResolvedTheme(e){let t=$(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(`
970
+ `),n=e.length,o=e.split(/\s+/).filter(l=>l.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
971
+ `),c=a.length,d=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:n,words:o,lines:t.length,line:c,column:d}):this.statsBar.innerHTML=`
954
972
  <div class="overtype-stat">
955
973
  <span class="live-dot"></span>
956
- <span>${i} chars, ${o} words, ${t.length} lines</span>
974
+ <span>${n} chars, ${o} words, ${t.length} lines</span>
957
975
  </div>
958
976
  <div class="overtype-stat">Line ${c}, Col ${d}</div>
959
- `}_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,o=window.getComputedStyle(e),r=parseFloat(o.paddingTop),s=parseFloat(o.paddingBottom),a=e.scrollTop;e.style.setProperty("height","auto","important");let c=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);c=Math.max(c,p)}let d="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);c>p&&(c=p,d="auto")}let l=c+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",d,"important"),t.style.setProperty("height",l,"important"),t.style.setProperty("overflow-y",d,"important"),i.style.setProperty("height",l,"important"),e.scrollTop=a,t.scrollTop=a,this.previousHeight!==c&&(this.previousHeight=c)}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(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",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}destroy(){if(this.element.overTypeInstance=null,w.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 w(e,t)}static initFromData(e,t={}){let i=document.querySelectorAll(e);return Array.from(i).map(o=>{let r={...t};for(let s of o.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(d,l)=>l.toUpperCase());r[c]=w._parseDataValue(s.value)}return new w(o,r)})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||w.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let i=w.getInstance(t);i&&i.destroy()})}static injectStyles(e=!1){if(w.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let i=w.currentTheme||M,o=F({theme:i}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),w.stylesInjected=!0}static setTheme(e,t=null){let i=typeof e=="string"?T(e):e;t&&(i=te(i,t)),w.currentTheme=i,w.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(r=>{let s=typeof i=="string"?i:i.name;s&&r.setAttribute("data-theme",s)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{if(!r.closest(".overtype-container")){let a=typeof i=="string"?i:i.name;a&&r.setAttribute("data-theme",a)}let s=r._instance;s&&s.updatePreview()});let o=typeof i=="string"?i:i.name;document.querySelectorAll("overtype-editor").forEach(r=>{o&&typeof r.setAttribute=="function"&&r.setAttribute("theme",o),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static setCodeHighlighter(e){L.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){L.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(){w.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("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))}}),w.globalListenersInitialized=!0)}};E(w,"instances",new WeakMap),E(w,"stylesInjected",!1),E(w,"globalListenersInitialized",!1),E(w,"instanceCount",0);var P=w;P.MarkdownParser=L;P.ShortcutsManager=z;P.themes={solar:M,cave:T("cave")};P.getTheme=T;P.currentTheme=M;var Oe=P;var je="overtype-webcomponent-container",st="Start typing...",at=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly"],K=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)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
960
- `).replace(/\\t/g," ")}static get observedAttributes(){return at}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=je;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 Oe(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=T(t),o=this._getOptionsFromAttributes(),r=F({...o,theme:i}),s=`
977
+ `}_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,o=window.getComputedStyle(e),r=parseFloat(o.paddingTop),s=parseFloat(o.paddingBottom),a=e.scrollTop;e.style.setProperty("height","auto","important");let c=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);c=Math.max(c,p)}let d="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);c>p&&(c=p,d="auto")}let l=c+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",d,"important"),t.style.setProperty("height",l,"important"),t.style.setProperty("overflow-y",d,"important"),n.style.setProperty("height",l,"important"),e.scrollTop=a,t.scrollTop=a,this.previousHeight!==c&&(this.previousHeight=c)}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(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",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}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={}){let n=document.querySelectorAll(e);return Array.from(n).map(o=>{let r={...t};for(let s of o.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(d,l)=>l.toUpperCase());r[c]=v._parseDataValue(s.value)}return new v(o,r)[0]})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||v.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let n=v.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=v.currentTheme||B,o=ye({theme:n}),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($e("auto"),t);return}v._stopAutoListener(),v._applyGlobalTheme(e,t)}static _applyGlobalTheme(e,t=null){let n=typeof e=="string"?$(e):e;t&&(n=Qe(n,t)),v.currentTheme=n,v.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(){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(n=>n._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){C.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){C.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(){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"),n=t==null?void 0:t._instance;n&&n.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"),n=t==null?void 0:t._instance;n&&n.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let n=t.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&(o.options.showStats&&o.statsBar&&o._updateStats(),clearTimeout(o._selectionTimeout),o._selectionTimeout=setTimeout(()=>{o.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};T(v,"instances",new WeakMap),T(v,"stylesInjected",!1),T(v,"globalListenersInitialized",!1),T(v,"instanceCount",0),T(v,"_autoMediaQuery",null),T(v,"_autoMediaListener",null),T(v,"_autoInstances",new Set),T(v,"_globalAutoTheme",!1),T(v,"_globalAutoCustomColors",null);var q=v;q.MarkdownParser=C;q.ShortcutsManager=oe;q.themes={solar:B,cave:$("cave")};q.getTheme=$;q.currentTheme=B;var li=q;var ci="overtype-webcomponent-container",cn="Start typing...",pn=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly","spellcheck"],Oe=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)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
978
+ `).replace(/\\t/g," ")}static get observedAttributes(){return pn}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=ci;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 li(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=$(t),o=this._getOptionsFromAttributes(),r=ye({...o,theme:n}),s=`
961
979
  /* Web Component Host Styles */
962
980
  :host {
963
981
  display: block;
@@ -979,9 +997,9 @@ ${a}`:r;if(d){let S=n.value[n.selectionStart-1];n.selectionStart!==0&&S!=null&&!
979
997
  }
980
998
  `;this._styleVersion+=1;let a=`
981
999
  /* overtype-webcomponent styles v${this._styleVersion} */
982
- `;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")||st,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",onChange:this._handleChange,onKeydown:this._handleKeydown},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.textarea&&(this._editor.textarea.placeholder=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}}}_updateContainerHeight(){let e=this.shadowRoot.querySelector(`.${je}`);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})}_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(`
983
- `),i=e.length,o=e.split(/\s+/).filter(l=>l.length>0).length,r=this._editor.textarea.selectionStart,a=e.substring(0,r).split(`
984
- `),c=a.length,d=a[a.length-1].length+1;return{characters:i,words:o,lines:t.length,line:c,column:d}}isReady(){return this._initialized&&this._editor!==null}getEditor(){return this._editor}};customElements.get("overtype-editor")||customElements.define("overtype-editor",K);var lt=K;return We(ct);})();
1000
+ `;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")||cn,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},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(`.${ci}`);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})}_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(`
1001
+ `),n=e.length,o=e.split(/\s+/).filter(l=>l.length>0).length,r=this._editor.textarea.selectionStart,a=e.substring(0,r).split(`
1002
+ `),c=a.length,d=a[a.length-1].length+1;return{characters:n,words:o,lines:t.length,line:c,column:d}}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",Oe);var dn=Oe;return vi(hn);})();
985
1003
  /**
986
1004
  * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
987
1005
  * @version 1.0.0