overtype 2.0.1 → 2.0.2

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,23 +1,23 @@
1
1
  /**
2
- * OverType v2.0.1
2
+ * OverType v2.0.2
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author Demo User
6
6
  * https://github.com/demo/overtype
7
7
  */
8
- var OverType=(()=>{var z=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Oe=Object.prototype.hasOwnProperty;var ze=(o,e,t)=>e in o?z(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var je=(o,e)=>{for(var t in e)z(o,t,{get:e[t],enumerable:!0})},Re=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _e(e))!Oe.call(o,i)&&i!==t&&z(o,i,{get:()=>e[i],enumerable:!(n=Ne(e,i))||n.enumerable});return o};var Fe=o=>Re(z({},"__esModule",{value:!0}),o);var T=(o,e,t)=>(ze(o,typeof e!="symbol"?e+"":e,t),t);var tt={};je(tt,{OverType:()=>$,default:()=>et,defaultToolbarButtons:()=>G,toolbarButtons:()=>x});var S=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static escapeHtml(e){let t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,n=>t[n])}static preserveIndentation(e,t){let i=t.match(/^(\s*)/)[1].replace(/ /g,"&nbsp;");return e.replace(/^\s*/,i)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,n,i)=>{let r=n.length;return`<h${r}><span class="syntax-marker">${n} </span>${i}</h${r}>`})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`<div><span class="hr-marker">${e}</span></div>`:null}static parseBlockquote(e){return e.replace(/^&gt; (.+)$/,(t,n)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${n}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*])\s(.+)$/,(t,n,i,r)=>`${n}<li class="bullet-list"><span class="syntax-marker">${i} </span>${r}</li>`)}static parseTaskList(e,t=!1){return e.replace(/^((?:&nbsp;)*)-\s+\[([ xX])\]\s+(.+)$/,(n,i,r,s)=>{if(t){let a=r.toLowerCase()==="x";return`${i}<li class="task-list"><input type="checkbox" ${a?"checked":""}> ${s}</li>`}else return`${i}<li class="task-list"><span class="syntax-marker">- [${r}] </span>${s}</li>`})}static parseNumberedList(e){return e.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/,(t,n,i,r)=>`${n}<li class="ordered-list"><span class="syntax-marker">${i} </span>${r}</li>`)}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`<div><span class="code-fence">${e}</span></div>`:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'<strong><span class="syntax-marker">**</span>$1<span class="syntax-marker">**</span></strong>'),e=e.replace(/__(.+?)__/g,'<strong><span class="syntax-marker">__</span>$1<span class="syntax-marker">__</span></strong>'),e}static parseItalic(e){return e=e.replace(new RegExp("(?<!\\*)\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)","g"),'<em><span class="syntax-marker">*</span>$1<span class="syntax-marker">*</span></em>'),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?<!_)_(?!_)(?=\\s|$)","g"),'<em><span class="syntax-marker">_</span>$1<span class="syntax-marker">_</span></em>'),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?<!~)~~(?!~)(.+?)(?<!~)~~(?!~)","g"),'<del><span class="syntax-marker">~~</span>$1<span class="syntax-marker">~~</span></del>'),e=e.replace(new RegExp("(?<!~)~(?!~)(.+?)(?<!~)~(?!~)","g"),'<del><span class="syntax-marker">~</span>$1<span class="syntax-marker">~</span></del>'),e}static parseInlineCode(e){return e.replace(new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),'<code><span class="syntax-marker">$1</span>$2<span class="syntax-marker">$3</span></code>')}static sanitizeUrl(e){let 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,i)=>{let r=`--link-${this.linkIndex++}`;return`<a href="${this.sanitizeUrl(i)}" style="anchor-name: ${r}"><span class="syntax-marker">[</span>${n}<span class="syntax-marker url-part">](${i})</span></a>`})}static identifyAndProtectSanctuaries(e){let t=new Map,n=0,i=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 p=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),d,l=[];for(;(d=p.exec(e))!==null;){let c=d.index,h=d.index+d[0].length;r.some(f=>c>=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((c,h)=>h.index-c.index),l.forEach(c=>{let h=`\uE000${n++}\uE001`;t.set(h,{type:"code",original:c.match,openTicks:c.openTicks,content:c.content,closeTicks:c.closeTicks}),i=i.substring(0,c.index)+h+i.substring(c.index+c.match.length)}),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(c,h,u)=>{let f=`\uE000${n++}\uE001`;return t.set(f,{type:"link",original:c,linkText:h,url:u}),f}),{protectedText:i,sanctuaries:t}}static restoreAndTransformSanctuaries(e,t){return Array.from(t.keys()).sort((i,r)=>{let s=e.indexOf(i),a=e.indexOf(r);return s-a}).forEach(i=>{let r=t.get(i),s;if(r.type==="code")s=`<code><span class="syntax-marker">${r.openTicks}</span>${r.content}<span class="syntax-marker">${r.closeTicks}</span></code>`;else if(r.type==="link"){let a=r.linkText;t.forEach((l,c)=>{if(a.includes(c)&&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(c,h)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let p=`--link-${this.linkIndex++}`;s=`<a href="${this.sanitizeUrl(r.url)}" style="anchor-name: ${p}"><span class="syntax-marker">[</span>${a}<span class="syntax-marker url-part">](${r.url})</span></a>`}e=e.replace(i,s)}),e}static parseInlineElements(e){let{protectedText:t,sanctuaries:n}=this.identifyAndProtectSanctuaries(e),i=t;return i=this.parseStrikethrough(i),i=this.parseBold(i),i=this.parseItalic(i),i=this.restoreAndTransformSanctuaries(i,n),i}static parseLine(e,t=!1){let n=this.escapeHtml(e);n=this.preserveIndentation(n,e);let i=this.parseHorizontalRule(n);if(i)return i;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=this.parseInlineElements(n),n.trim()===""?"<div>&nbsp;</div>":`<div>${n}</div>`)}static parse(e,t=-1,n=!1,i,r=!1){this.resetLinkIndex();let s=e.split(`
8
+ var OverType=(()=>{var j=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Oe=Object.prototype.hasOwnProperty;var je=(o,e,t)=>e in o?j(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var ze=(o,e)=>{for(var t in e)j(o,t,{get:e[t],enumerable:!0})},Fe=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _e(e))!Oe.call(o,i)&&i!==t&&j(o,i,{get:()=>e[i],enumerable:!(n=Ne(e,i))||n.enumerable});return o};var Re=o=>Fe(j({},"__esModule",{value:!0}),o);var T=(o,e,t)=>(je(o,typeof e!="symbol"?e+"":e,t),t);var tt={};ze(tt,{OverType:()=>H,default:()=>et,defaultToolbarButtons:()=>G,toolbarButtons:()=>x});var S=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static escapeHtml(e){let t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,n=>t[n])}static preserveIndentation(e,t){let i=t.match(/^(\s*)/)[1].replace(/ /g,"&nbsp;");return e.replace(/^\s*/,i)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,n,i)=>{let r=n.length;return`<h${r}><span class="syntax-marker">${n} </span>${i}</h${r}>`})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`<div><span class="hr-marker">${e}</span></div>`:null}static parseBlockquote(e){return e.replace(/^&gt; (.+)$/,(t,n)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${n}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*])\s(.+)$/,(t,n,i,r)=>`${n}<li class="bullet-list"><span class="syntax-marker">${i} </span>${r}</li>`)}static parseTaskList(e,t=!1){return e.replace(/^((?:&nbsp;)*)-\s+\[([ xX])\]\s+(.+)$/,(n,i,r,s)=>{if(t){let a=r.toLowerCase()==="x";return`${i}<li class="task-list"><input type="checkbox" ${a?"checked":""}> ${s}</li>`}else return`${i}<li class="task-list"><span class="syntax-marker">- [${r}] </span>${s}</li>`})}static parseNumberedList(e){return e.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/,(t,n,i,r)=>`${n}<li class="ordered-list"><span class="syntax-marker">${i} </span>${r}</li>`)}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`<div><span class="code-fence">${e}</span></div>`:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'<strong><span class="syntax-marker">**</span>$1<span class="syntax-marker">**</span></strong>'),e=e.replace(/__(.+?)__/g,'<strong><span class="syntax-marker">__</span>$1<span class="syntax-marker">__</span></strong>'),e}static parseItalic(e){return e=e.replace(new RegExp("(?<!\\*)\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)","g"),'<em><span class="syntax-marker">*</span>$1<span class="syntax-marker">*</span></em>'),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?<!_)_(?!_)(?=\\s|$)","g"),'<em><span class="syntax-marker">_</span>$1<span class="syntax-marker">_</span></em>'),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?<!~)~~(?!~)(.+?)(?<!~)~~(?!~)","g"),'<del><span class="syntax-marker">~~</span>$1<span class="syntax-marker">~~</span></del>'),e=e.replace(new RegExp("(?<!~)~(?!~)(.+?)(?<!~)~(?!~)","g"),'<del><span class="syntax-marker">~</span>$1<span class="syntax-marker">~</span></del>'),e}static parseInlineCode(e){return e.replace(new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),'<code><span class="syntax-marker">$1</span>$2<span class="syntax-marker">$3</span></code>')}static sanitizeUrl(e){let 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,i)=>{let r=`--link-${this.linkIndex++}`;return`<a href="${this.sanitizeUrl(i)}" style="anchor-name: ${r}"><span class="syntax-marker">[</span>${n}<span class="syntax-marker url-part">](${i})</span></a>`})}static identifyAndProtectSanctuaries(e){let t=new Map,n=0,i=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 p=new RegExp("(?<!`)(`+)(?!`)((?:(?!\\1).)+?)(\\1)(?!`)","g"),d,l=[];for(;(d=p.exec(e))!==null;){let c=d.index,h=d.index+d[0].length;r.some(f=>c>=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((c,h)=>h.index-c.index),l.forEach(c=>{let h=`\uE000${n++}\uE001`;t.set(h,{type:"code",original:c.match,openTicks:c.openTicks,content:c.content,closeTicks:c.closeTicks}),i=i.substring(0,c.index)+h+i.substring(c.index+c.match.length)}),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(c,h,u)=>{let f=`\uE000${n++}\uE001`;return t.set(f,{type:"link",original:c,linkText:h,url:u}),f}),{protectedText:i,sanctuaries:t}}static restoreAndTransformSanctuaries(e,t){return Array.from(t.keys()).sort((i,r)=>{let s=e.indexOf(i),a=e.indexOf(r);return s-a}).forEach(i=>{let r=t.get(i),s;if(r.type==="code")s=`<code><span class="syntax-marker">${r.openTicks}</span>${r.content}<span class="syntax-marker">${r.closeTicks}</span></code>`;else if(r.type==="link"){let a=r.linkText;t.forEach((l,c)=>{if(a.includes(c)&&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(c,h)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let p=`--link-${this.linkIndex++}`;s=`<a href="${this.sanitizeUrl(r.url)}" style="anchor-name: ${p}"><span class="syntax-marker">[</span>${a}<span class="syntax-marker url-part">](${r.url})</span></a>`}e=e.replace(i,s)}),e}static parseInlineElements(e){let{protectedText:t,sanctuaries:n}=this.identifyAndProtectSanctuaries(e),i=t;return i=this.parseStrikethrough(i),i=this.parseBold(i),i=this.parseItalic(i),i=this.restoreAndTransformSanctuaries(i,n),i}static parseLine(e,t=!1){let n=this.escapeHtml(e);n=this.preserveIndentation(n,e);let i=this.parseHorizontalRule(n);if(i)return i;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=this.parseInlineElements(n),n.trim()===""?"<div>&nbsp;</div>":`<div>${n}</div>`)}static parse(e,t=-1,n=!1,i,r=!1){this.resetLinkIndex();let s=e.split(`
9
9
  `),a=!1,d=s.map((l,c)=>{if(n&&c===t)return`<div class="raw-line">${this.escapeHtml(l)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(l))return a=!a,this.parseLine(l,r);if(a){let u=this.escapeHtml(l);return`<div>${this.preserveIndentation(u,l)||"&nbsp;"}</div>`}return this.parseLine(l,r)}).join("");return this.postProcessHTML(d,i)}static postProcessHTML(e,t){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,t);let n=document.createElement("div");n.innerHTML=e;let i=null,r=null,s=null,a=!1,p=Array.from(n.children);for(let d=0;d<p.length;d++){let l=p[d];if(!l.parentNode)continue;let c=l.querySelector(".code-fence");if(c){let u=c.textContent;if(u.startsWith("```"))if(a){let f=t||this.codeHighlighter;if(s&&f&&s._codeContent)try{let m=f(s._codeContent,s._language||"");m&&typeof m.then=="function"?console.warn("Async highlighters are not supported in parse() because it returns an HTML string. The caller creates new DOM elements from that string, breaking references to the elements we would update. Use synchronous highlighters only."):m&&typeof m=="string"&&m.trim()&&(s._codeElement.innerHTML=m)}catch(m){console.warn("Code highlighting failed:",m)}a=!1,s=null;continue}else{a=!0,s=document.createElement("pre");let f=document.createElement("code");s.appendChild(f),s.className="code-block";let m=u.slice(3).trim();m&&(f.className=`language-${m}`),n.insertBefore(s,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
10
  `);let f=l.textContent.replace(/\u00A0/g," ");s._codeContent+=f,u.textContent.length>0&&(u.textContent+=`
11
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){i=null,r=null;continue}let m=u?"ul":"ol";(!i||r!==m)&&(i=document.createElement(m),n.insertBefore(i,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)}),i.appendChild(h),l.remove()}else i=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(p=>{let d=p.match(/<div>((?:&nbsp;)*)<li/),l=p.match(/<li class="bullet-list">.*?<\/li>/);if(d&&l){let c=d[1];return l[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${c}`)}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(p=>{let d=p.match(/<div>((?:&nbsp;)*)<li/),l=p.match(/<li class="ordered-list">.*?<\/li>/);if(d&&l){let c=d[1];return l[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${c}`)}return l?l[0]:""}).filter(Boolean).join("")+"</ol>":r});let i=/<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;return n=n.replace(i,(r,s,a,p)=>{let l=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(g=>g.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
12
12
  `),c=s.slice(3).trim(),h=c?` class="language-${c}"`:"",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,c);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">${p}</span></div>`,m}),n}static getListContext(e,t){let n=e.split(`
13
13
  `),i=0,r=0,s=0;for(let h=0;h<n.length;h++){let u=n[h].length;if(i+u>=t){r=h,s=i;break}i+=u+1}let a=n[r],p=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:p,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:p,markerEndPos:s+l[1].length+l[2].length+1};let c=a.match(this.LIST_PATTERNS.numbered);return c?{inList:!0,listType:"numbered",indent:c[1],marker:parseInt(c[2]),content:c[3],lineStart:s,lineEnd:p,markerEndPos:s+c[1].length+c[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:p,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
14
  `),n=new Map,i=!1;return t.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let p=a[1],d=p.length,l=a[3];i||n.clear();let c=(n.get(d)||0)+1;n.set(d,c);for(let[h]of n)h>d&&n.delete(h);return i=!0,`${p}${c}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(i=!1,n.clear()),s}).join(`
15
- `)}};T(S,"linkIndex",0),T(S,"codeHighlighter",null),T(S,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var Ve=Object.defineProperty,oe=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,ie=(o,e,t)=>e in o?Ve(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,re=(o,e)=>{for(var t in e||(e={}))De.call(e,t)&&ie(o,t,e[t]);if(oe)for(var t of oe(e))qe.call(e,t)&&ie(o,t,e[t]);return o},E={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 Ue(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function H(o){return re(re({},Ue()),o)}var R=!1;function We(){return R}function y(o,e,t){R&&(console.group(`\u{1F50D} ${o}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function j(o,e){if(!R)return;let t=o.value.slice(o.selectionStart,o.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${o.selectionStart}-${o.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let n=o.value.slice(Math.max(0,o.selectionStart-10),o.selectionStart),i=o.value.slice(o.selectionEnd,Math.min(o.value.length,o.selectionEnd+10));console.log("Context:",JSON.stringify(n)+"[SELECTION]"+JSON.stringify(i)),console.groupEnd()}function ce(o){R&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(o.text)),console.log("New selection:",`${o.selectionStart}-${o.selectionEnd}`),console.groupEnd())}var A=null;function I(o,{text:e,selectionStart:t,selectionEnd:n}){let i=We();i&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${o.selectionStart}-${o.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",n)),o.focus();let r=o.selectionStart,s=o.selectionEnd,a=o.value.slice(0,r),p=o.value.slice(s);i&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(p.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(o.value.slice(r,s))));let d=o.value,l=r!==s;if(A===null||A===!0){o.contentEditable="true";try{A=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",A,"for text with",e.split(`
15
+ `)}};T(S,"linkIndex",0),T(S,"codeHighlighter",null),T(S,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var Ve=Object.defineProperty,oe=Object.getOwnPropertySymbols,Ue=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable,ie=(o,e,t)=>e in o?Ve(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,re=(o,e)=>{for(var t in e||(e={}))Ue.call(e,t)&&ie(o,t,e[t]);if(oe)for(var t of oe(e))De.call(e,t)&&ie(o,t,e[t]);return o},E={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 qe(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function $(o){return re(re({},qe()),o)}var F=!1;function We(){return F}function y(o,e,t){F&&(console.group(`\u{1F50D} ${o}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function z(o,e){if(!F)return;let t=o.value.slice(o.selectionStart,o.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${o.selectionStart}-${o.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let n=o.value.slice(Math.max(0,o.selectionStart-10),o.selectionStart),i=o.value.slice(o.selectionEnd,Math.min(o.value.length,o.selectionEnd+10));console.log("Context:",JSON.stringify(n)+"[SELECTION]"+JSON.stringify(i)),console.groupEnd()}function ce(o){F&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(o.text)),console.log("New selection:",`${o.selectionStart}-${o.selectionEnd}`),console.groupEnd())}var A=null;function I(o,{text:e,selectionStart:t,selectionEnd:n}){let i=We();i&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${o.selectionStart}-${o.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",n)),o.focus();let r=o.selectionStart,s=o.selectionEnd,a=o.value.slice(0,r),p=o.value.slice(s);i&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(p.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(o.value.slice(r,s))));let d=o.value,l=r!==s;if(A===null||A===!0){o.contentEditable="true";try{A=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",A,"for text with",e.split(`
16
16
  `).length,"lines")}catch(c){A=!1,i&&console.log("execCommand threw error:",c)}o.contentEditable="false"}if(i&&(console.log("canInsertText before:",A),console.log("execCommand result:",A)),A){let c=a+e+p,h=o.value;i&&(console.log("Expected length:",c.length),console.log("Actual length:",h.length)),h!==c&&i&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(c.slice(0,100))),console.log("Actual:",JSON.stringify(h.slice(0,100))))}if(!A)if(i&&console.log("Using manual insertion"),o.value===d){i&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(c){}o.value=a+e+p;try{document.execCommand("ms-endUndoUnit")}catch(c){}o.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else i&&console.log("Value was changed by execCommand, skipping manual insertion");i&&console.log("Setting selection range:",t,n),t!=null&&n!=null?o.setSelectionRange(t,n):o.setSelectionRange(r,o.selectionEnd),i&&(console.log("Final value length:",o.value.length),console.groupEnd())}function se(o){return o.trim().split(`
17
17
  `).length>1}function Ke(o,e){let t=e;for(;o[t]&&o[t-1]!=null&&!o[t-1].match(/\s/);)t--;return t}function Ze(o,e,t){let n=e,i=t?/\n/:/\s/;for(;o[n]&&!o[n].match(i);)n++;return n}function pe(o){let e=o.value.split(`
18
18
  `),t=0;for(let n=0;n<e.length;n++){let i=e[n].length+1;o.selectionStart>=t&&o.selectionStart<t+i&&(o.selectionStart=t),o.selectionEnd>=t&&o.selectionEnd<t+i&&(n===e.length-1?o.selectionEnd=Math.min(t+e[n].length,o.value.length):o.selectionEnd=t+i-1),t+=i}}function Je(o,e,t,n=!1){if(o.selectionStart===o.selectionEnd)o.selectionStart=Ke(o.value,o.selectionStart),o.selectionEnd=Ze(o.value,o.selectionEnd,n);else{let i=o.selectionStart-e.length,r=o.selectionEnd+t.length,s=o.value.slice(i,o.selectionStart)===e,a=o.value.slice(o.selectionEnd,r)===t;s&&a&&(o.selectionStart=i,o.selectionEnd=r)}return o.value.slice(o.selectionStart,o.selectionEnd)}function Q(o){let e=o.value.slice(0,o.selectionStart),t=o.value.slice(o.selectionEnd),n=e.match(/\n*$/),i=t.match(/^\n*/),r=n?n[0].length:0,s=i?i[0].length:0,a="",p="";return e.match(/\S/)&&r<2&&(a=`
19
19
  `.repeat(2-r)),t.match(/\S/)&&s<2&&(p=`
20
- `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:p}}function F(o,e,t={}){let n=o.selectionStart,i=o.selectionEnd,r=n===i,s=o.value,a=n;for(;a>0&&s[a-1]!==`
20
+ `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:p}}function R(o,e,t={}){let n=o.selectionStart,i=o.selectionEnd,r=n===i,s=o.value,a=n;for(;a>0&&s[a-1]!==`
21
21
  `;)a--;if(r){let d=n;for(;d<s.length&&s[d]!==`
22
22
  `;)d++;o.selectionStart=a,o.selectionEnd=d}else pe(o);let p=e(o);if(t.adjustSelection){let l=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix),c=t.adjustSelection(l,n,i,a);p.selectionStart=c.start,p.selectionEnd=c.end}else if(t.prefix){let l=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix);r?l?(p.selectionStart=Math.max(n-t.prefix.length,a),p.selectionEnd=p.selectionStart):(p.selectionStart=n+t.prefix.length,p.selectionEnd=p.selectionStart):l?(p.selectionStart=Math.max(n-t.prefix.length,a),p.selectionEnd=Math.max(i-t.prefix.length,a)):(p.selectionStart=n+t.prefix.length,p.selectionEnd=i+t.prefix.length)}return p}function V(o,e){let t,n,{prefix:i,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:p,prefixSpace:d,scanFor:l,surroundWithNewlines:c,trimFirst:h}=e,u=o.selectionStart,f=o.selectionEnd,m=o.value.slice(o.selectionStart,o.selectionEnd),g=se(m)&&s&&s.length>0?`${s}
23
23
  `:i,v=se(m)&&a&&a.length>0?`
@@ -30,10 +30,10 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
30
30
  `),t="- ",n=e.every(r=>r.startsWith(t)),i=e;return n&&(i=e.map(r=>r.slice(t.length))),{text:i.join(`
31
31
  `),processed:n}}function _(o,e){return e?"- ":`${o+1}. `}function Ge(o,e){let t,n,i;return o.orderedList?(t=ae(e),n=le(t.text),i=n.text):(t=le(e),n=ae(t.text),i=n.text),[t,n,i]}function Qe(o,e){let t=o.selectionStart===o.selectionEnd,n=o.selectionStart,i=o.selectionEnd;pe(o);let r=o.value.slice(o.selectionStart,o.selectionEnd),[s,a,p]=Ge(e,r),d=p.split(`
32
32
  `).map((m,g)=>`${_(g,e.unorderedList)}${m}`),l=d.reduce((m,g,v)=>m+_(v,e.unorderedList).length,0),c=d.reduce((m,g,v)=>m+_(v,!e.unorderedList).length,0);if(s.processed)return t?(n=Math.max(n-_(0,e.unorderedList).length,0),i=n):(n=o.selectionStart,i=o.selectionEnd-l),{text:p,selectionStart:n,selectionEnd:i};let{newlinesToAppend:h,newlinesToPrepend:u}=Q(o),f=h+d.join(`
33
- `)+u;return t?(n=Math.max(n+_(0,e.unorderedList).length+h.length,0),i=n):a.processed?(n=Math.max(o.selectionStart+h.length,0),i=o.selectionEnd+h.length+l-c):(n=Math.max(o.selectionStart+h.length,0),i=o.selectionEnd+h.length+l),{text:f,selectionStart:n,selectionEnd:i}}function he(o,e){let t=F(o,n=>Qe(n,e),{adjustSelection:(n,i,r,s)=>{let a=o.value.slice(s,o.selectionEnd),p=/^\d+\.\s+/,d=/^- /,l=p.test(a),c=d.test(a),h=e.orderedList&&l||e.unorderedList&&c;if(i===r)if(h){let u=a.match(e.orderedList?p:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(i-f,s)}}else if(l||c){let u=a.match(l?p:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:i+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:i+u}}else if(h){let u=a.match(e.orderedList?p:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(r-f,s)}}else if(l||c){let u=a.match(l?p:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:r+u}}}});I(o,t)}function Xe(o){if(!o)return[];let e=[],{selectionStart:t,selectionEnd:n,value:i}=o,r=i.split(`
34
- `),s=0,a="";for(let c of r){if(t>=s&&t<=s+c.length){a=c;break}s+=c.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 p=Math.max(0,t-10),d=Math.min(i.length,n+10),l=i.slice(p,d);if(l.includes("**")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100));c.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&i.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function D(o){if(!o||o.disabled||o.readOnly)return;y("toggleBold","Starting"),j(o,"Before");let e=H(E.bold),t=V(o,e);ce(t),I(o,t),j(o,"After")}function q(o){if(!o||o.disabled||o.readOnly)return;let e=H(E.italic),t=V(o,e);I(o,t)}function ue(o){if(!o||o.disabled||o.readOnly)return;let e=H(E.code),t=V(o,e);I(o,t)}function U(o,e={}){if(!o||o.disabled||o.readOnly)return;let t=o.value.slice(o.selectionStart,o.selectionEnd),n=H(E.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=o.selectionStart;o.value=o.value.slice(0,s)+e.text+o.value.slice(s),o.selectionStart=s,o.selectionEnd=s+e.text.length}let r=V(o,n);I(o,r)}function W(o){if(!o||o.disabled||o.readOnly)return;let e=H(E.bulletList);he(o,e)}function K(o){if(!o||o.disabled||o.readOnly)return;let e=H(E.numberedList);he(o,e)}function me(o){if(!o||o.disabled||o.readOnly)return;y("toggleQuote","Starting"),j(o,"Initial");let e=H(E.quote),t=F(o,n=>de(n,e),{prefix:e.prefix});ce(t),I(o,t),j(o,"Final")}function X(o){if(!o||o.disabled||o.readOnly)return;let e=H(E.taskList),t=F(o,n=>de(n,e),{prefix:e.prefix});I(o,t)}function Y(o,e=1,t=!1){if(!o||o.disabled||o.readOnly)return;(e<1||e>6)&&(e=1),y("insertHeader","============ START ============"),y("insertHeader",`Level: ${e}, Toggle: ${t}`),y("insertHeader",`Initial cursor: ${o.selectionStart}-${o.selectionEnd}`);let n=`header${e===1?"1":e}`,i=H(E[n]||E.header1);y("insertHeader",`Style prefix: "${i.prefix}"`);let r=o.value,s=o.selectionStart,a=o.selectionEnd,p=s;for(;p>0&&r[p-1]!==`
33
+ `)+u;return t?(n=Math.max(n+_(0,e.unorderedList).length+h.length,0),i=n):a.processed?(n=Math.max(o.selectionStart+h.length,0),i=o.selectionEnd+h.length+l-c):(n=Math.max(o.selectionStart+h.length,0),i=o.selectionEnd+h.length+l),{text:f,selectionStart:n,selectionEnd:i}}function he(o,e){let t=R(o,n=>Qe(n,e),{adjustSelection:(n,i,r,s)=>{let a=o.value.slice(s,o.selectionEnd),p=/^\d+\.\s+/,d=/^- /,l=p.test(a),c=d.test(a),h=e.orderedList&&l||e.unorderedList&&c;if(i===r)if(h){let u=a.match(e.orderedList?p:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(i-f,s)}}else if(l||c){let u=a.match(l?p:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:i+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:i+u}}else if(h){let u=a.match(e.orderedList?p:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(r-f,s)}}else if(l||c){let u=a.match(l?p:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:r+u}}}});I(o,t)}function Xe(o){if(!o)return[];let e=[],{selectionStart:t,selectionEnd:n,value:i}=o,r=i.split(`
34
+ `),s=0,a="";for(let c of r){if(t>=s&&t<=s+c.length){a=c;break}s+=c.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 p=Math.max(0,t-10),d=Math.min(i.length,n+10),l=i.slice(p,d);if(l.includes("**")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100));c.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let c=i.slice(Math.max(0,t-100),t),h=i.slice(n,Math.min(i.length,n+100)),u=c.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&i.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function U(o){if(!o||o.disabled||o.readOnly)return;y("toggleBold","Starting"),z(o,"Before");let e=$(E.bold),t=V(o,e);ce(t),I(o,t),z(o,"After")}function D(o){if(!o||o.disabled||o.readOnly)return;let e=$(E.italic),t=V(o,e);I(o,t)}function ue(o){if(!o||o.disabled||o.readOnly)return;let e=$(E.code),t=V(o,e);I(o,t)}function q(o,e={}){if(!o||o.disabled||o.readOnly)return;let t=o.value.slice(o.selectionStart,o.selectionEnd),n=$(E.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=o.selectionStart;o.value=o.value.slice(0,s)+e.text+o.value.slice(s),o.selectionStart=s,o.selectionEnd=s+e.text.length}let r=V(o,n);I(o,r)}function W(o){if(!o||o.disabled||o.readOnly)return;let e=$(E.bulletList);he(o,e)}function K(o){if(!o||o.disabled||o.readOnly)return;let e=$(E.numberedList);he(o,e)}function me(o){if(!o||o.disabled||o.readOnly)return;y("toggleQuote","Starting"),z(o,"Initial");let e=$(E.quote),t=R(o,n=>de(n,e),{prefix:e.prefix});ce(t),I(o,t),z(o,"Final")}function X(o){if(!o||o.disabled||o.readOnly)return;let e=$(E.taskList),t=R(o,n=>de(n,e),{prefix:e.prefix});I(o,t)}function Y(o,e=1,t=!1){if(!o||o.disabled||o.readOnly)return;(e<1||e>6)&&(e=1),y("insertHeader","============ START ============"),y("insertHeader",`Level: ${e}, Toggle: ${t}`),y("insertHeader",`Initial cursor: ${o.selectionStart}-${o.selectionEnd}`);let n=`header${e===1?"1":e}`,i=$(E[n]||E.header1);y("insertHeader",`Style prefix: "${i.prefix}"`);let r=o.value,s=o.selectionStart,a=o.selectionEnd,p=s;for(;p>0&&r[p-1]!==`
35
35
  `;)p--;let d=a;for(;d<r.length&&r[d]!==`
36
- `;)d++;let l=r.slice(p,d);y("insertHeader",`Current line (before): "${l}"`);let c=l.match(/^(#{1,6})\s*/),h=c?c[1].length:0,u=c?c[0].length:0;y("insertHeader","Existing header check:"),y("insertHeader",` - Match: ${c?`"${c[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=F(o,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 k;return f?(y("insertHeader","ACTION: Toggling OFF - removing header"),k=b):h>0?(y("insertHeader",`ACTION: Replacing H${h} with H${e}`),k=i.prefix+b):(y("insertHeader","ACTION: Adding new header"),k=i.prefix+b),y("insertHeader",`New line: "${k}"`),{text:k,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,v,b,k)=>{if(y("insertHeader","Adjusting selection:"),y("insertHeader",` - isRemoving param: ${g}`),y("insertHeader",` - shouldToggleOff: ${f}`),y("insertHeader",` - selStart: ${v}, selEnd: ${b}`),y("insertHeader",` - lineStartPos: ${k}`),f){let M=Math.max(v-u,k);return y("insertHeader",` - Removing header, adjusting by -${u}`),{start:M,end:v===b?M:Math.max(b-u,k)}}else if(u>0){let M=i.prefix.length-u;return y("insertHeader",` - Replacing header, adjusting by ${M}`),{start:v+M,end:b+M}}else return y("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:v+i.prefix.length,end:b+i.prefix.length}}});y("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),y("insertHeader","============ END ============"),I(o,m)}function fe(o){Y(o,1,!0)}function ge(o){Y(o,2,!0)}function ve(o){Y(o,3,!0)}function ye(o){return Xe(o)}var O=class{constructor(e){this.editor=e,this.textarea=e.textarea}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.toolbar?this.editor.toolbar.handleAction(i):this.handleAction(i),!0):!1}async handleAction(e){let t=this.textarea;if(t){t.focus();try{switch(e){case"toggleBold":D(t);break;case"toggleItalic":q(t);break;case"insertLink":U(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(n){console.error("Error in markdown action:",n)}}}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",toolbarBg:"#ffffff",toolbarBorder:"rgba(13, 59, 102, 0.15)",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca"}},be={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",toolbarBg:"#1D2D3E",toolbarBorder:"rgba(197, 221, 232, 0.1)",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52"}},we={solar:B,cave:be,light:B,dark:be};function P(o){return typeof o=="string"?{...we[o]||we.solar,name:o}:o}function N(o){let e=[];for(let[t,n]of Object.entries(o)){let i=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${i}: ${n};`)}return e.join(`
36
+ `;)d++;let l=r.slice(p,d);y("insertHeader",`Current line (before): "${l}"`);let c=l.match(/^(#{1,6})\s*/),h=c?c[1].length:0,u=c?c[0].length:0;y("insertHeader","Existing header check:"),y("insertHeader",` - Match: ${c?`"${c[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=R(o,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 k;return f?(y("insertHeader","ACTION: Toggling OFF - removing header"),k=b):h>0?(y("insertHeader",`ACTION: Replacing H${h} with H${e}`),k=i.prefix+b):(y("insertHeader","ACTION: Adding new header"),k=i.prefix+b),y("insertHeader",`New line: "${k}"`),{text:k,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,v,b,k)=>{if(y("insertHeader","Adjusting selection:"),y("insertHeader",` - isRemoving param: ${g}`),y("insertHeader",` - shouldToggleOff: ${f}`),y("insertHeader",` - selStart: ${v}, selEnd: ${b}`),y("insertHeader",` - lineStartPos: ${k}`),f){let M=Math.max(v-u,k);return y("insertHeader",` - Removing header, adjusting by -${u}`),{start:M,end:v===b?M:Math.max(b-u,k)}}else if(u>0){let M=i.prefix.length-u;return y("insertHeader",` - Replacing header, adjusting by ${M}`),{start:v+M,end:b+M}}else return y("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:v+i.prefix.length,end:b+i.prefix.length}}});y("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),y("insertHeader","============ END ============"),I(o,m)}function fe(o){Y(o,1,!0)}function ge(o){Y(o,2,!0)}function ve(o){Y(o,3,!0)}function ye(o){return Xe(o)}var O=class{constructor(e){this.editor=e,this.textarea=e.textarea}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.toolbar?this.editor.toolbar.handleAction(i):this.handleAction(i),!0):!1}async handleAction(e){let t=this.textarea;if(t){t.focus();try{switch(e){case"toggleBold":U(t);break;case"toggleItalic":D(t);break;case"insertLink":q(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(n){console.error("Error in markdown action:",n)}}}destroy(){}};var P={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",toolbarBg:"#ffffff",toolbarBorder:"rgba(13, 59, 102, 0.15)",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca"}},be={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",toolbarBg:"#1D2D3E",toolbarBorder:"rgba(197, 221, 232, 0.1)",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52"}},we={solar:P,cave:be,light:P,dark:be};function B(o){return typeof o=="string"?{...we[o]||we.solar,name:o}:o}function N(o){let e=[];for(let[t,n]of Object.entries(o)){let i=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${i}: ${n};`)}return e.join(`
37
37
  `)}function ke(o,e={}){return{...o,colors:{...o.colors,...e}}}function xe(o={}){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:i="20px",theme:r=null,mobile:s={}}=o,a=Object.keys(s).length>0?`
38
38
  @media (max-width: 640px) {
39
39
  .overtype-wrapper .overtype-input,
@@ -75,8 +75,8 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
75
75
 
76
76
  /* Container base styles after reset */
77
77
  .overtype-container {
78
- display: grid !important;
79
- grid-template-rows: auto 1fr auto !important;
78
+ display: flex !important;
79
+ flex-direction: column !important;
80
80
  width: 100% !important;
81
81
  height: 100% !important;
82
82
  position: relative !important; /* Override reset - needed for absolute children */
@@ -96,10 +96,10 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
96
96
  /* Auto-resize mode styles */
97
97
  .overtype-container.overtype-auto-resize {
98
98
  height: auto !important;
99
- grid-template-rows: auto auto auto !important;
100
99
  }
101
-
100
+
102
101
  .overtype-container.overtype-auto-resize .overtype-wrapper {
102
+ flex: 0 0 auto !important; /* Don't grow/shrink, use explicit height */
103
103
  height: auto !important;
104
104
  min-height: 60px !important;
105
105
  overflow: visible !important;
@@ -108,11 +108,10 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
108
108
  .overtype-wrapper {
109
109
  position: relative !important; /* Override reset - needed for absolute children */
110
110
  width: 100% !important;
111
- height: 100% !important; /* Take full height of grid cell */
111
+ flex: 1 1 0 !important; /* Grow to fill remaining space, with flex-basis: 0 */
112
112
  min-height: 60px !important; /* Minimum usable height */
113
113
  overflow: hidden !important;
114
114
  background: var(--bg-secondary, #ffffff) !important;
115
- grid-row: 2 !important; /* Always second row in grid */
116
115
  z-index: 1; /* Below toolbar and dropdown */
117
116
  }
118
117
 
@@ -447,7 +446,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
447
446
 
448
447
  /* Stats bar */
449
448
 
450
- /* Stats bar - positioned by grid, not absolute */
449
+ /* Stats bar - positioned by flexbox */
451
450
  .overtype-stats {
452
451
  height: 40px !important;
453
452
  padding: 0 20px !important;
@@ -459,7 +458,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
459
458
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
460
459
  font-size: 0.85rem !important;
461
460
  color: #666 !important;
462
- grid-row: 3 !important; /* Always third row in grid */
461
+ flex-shrink: 0 !important; /* Don't shrink */
463
462
  }
464
463
 
465
464
  /* Dark theme stats bar */
@@ -502,7 +501,6 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
502
501
  -webkit-overflow-scrolling: touch !important;
503
502
  flex-shrink: 0 !important;
504
503
  height: auto !important;
505
- grid-row: 1 !important; /* Always first row in grid */
506
504
  position: relative !important; /* Override reset */
507
505
  z-index: 100 !important; /* Ensure toolbar is above wrapper */
508
506
  scrollbar-width: thin; /* Thin scrollbar on Firefox */
@@ -572,9 +570,6 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
572
570
  }
573
571
 
574
572
  /* Adjust wrapper when toolbar is present */
575
- .overtype-container .overtype-toolbar + .overtype-wrapper {
576
- }
577
-
578
573
  /* Mobile toolbar adjustments */
579
574
  @media (max-width: 640px) {
580
575
  .overtype-toolbar {
@@ -845,40 +840,46 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
845
840
  height: 2px !important;
846
841
  }
847
842
 
848
- /* Link Tooltip - CSS Anchor Positioning */
843
+ /* Link Tooltip - Base styles (all browsers) */
844
+ .overtype-link-tooltip {
845
+ /* Visual styles that work for both positioning methods */
846
+ background: #333 !important;
847
+ color: white !important;
848
+ padding: 6px 10px !important;
849
+ border-radius: 16px !important;
850
+ font-size: 12px !important;
851
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
852
+ display: none !important;
853
+ z-index: 10000 !important;
854
+ cursor: pointer !important;
855
+ box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
856
+ max-width: 300px !important;
857
+ white-space: nowrap !important;
858
+ overflow: hidden !important;
859
+ text-overflow: ellipsis !important;
860
+
861
+ /* Base positioning for Floating UI fallback */
862
+ position: absolute;
863
+ }
864
+
865
+ .overtype-link-tooltip.visible {
866
+ display: flex !important;
867
+ }
868
+
869
+ /* CSS Anchor Positioning (modern browsers only) */
849
870
  @supports (position-anchor: --x) and (position-area: center) {
850
871
  .overtype-link-tooltip {
851
- position: absolute;
872
+ /* Only anchor positioning specific properties */
852
873
  position-anchor: var(--target-anchor, --link-0);
853
874
  position-area: block-end center;
854
875
  margin-top: 8px !important;
855
-
856
- background: #333 !important;
857
- color: white !important;
858
- padding: 6px 10px !important;
859
- border-radius: 16px !important;
860
- font-size: 12px !important;
861
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
862
- display: none !important;
863
- z-index: 10000 !important;
864
- cursor: pointer !important;
865
- box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
866
- max-width: 300px !important;
867
- white-space: nowrap !important;
868
- overflow: hidden !important;
869
- text-overflow: ellipsis !important;
870
-
871
876
  position-try: most-width block-end inline-end, flip-inline, block-start center;
872
877
  position-visibility: anchors-visible;
873
878
  }
874
-
875
- .overtype-link-tooltip.visible {
876
- display: flex !important;
877
- }
878
879
  }
879
880
 
880
881
  ${a}
881
- `}var Z=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.wrapper.insertBefore(this.container,this.editor.wrapper.firstChild)}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=async n=>{n.preventDefault(),this.editor.textarea.focus();try{e.action&&await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:i=>this.editor.setValue(i),event:n})}catch(i){console.error(`Button "${e.name}" error:`,i),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:i}})),t.classList.add("button-error"),t.style.animation="buttonError 0.3s",setTimeout(()=>{t.classList.remove("button-error"),t.style.animation=""},300)}},t.addEventListener("click",t._clickHandler),t)}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),i=e.getBoundingClientRect();n.style.position="absolute",n.style.top=`${i.bottom+5}px`,n.style.left=`${i.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"}],i=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===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),t.appendChild(s)}),t}updateButtonStates(){var e;try{let t=((e=ye)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,i])=>{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}i.classList.toggle("active",r),i.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 J=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,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.hide()),this.editor.textarea.addEventListener("blur",()=>this.hide()),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>this.cancelHide()),this.tooltip.addEventListener("mouseleave",()=>this.scheduleHide())}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
882
+ `}var Z=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=async n=>{n.preventDefault(),this.editor.textarea.focus();try{e.action&&await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:i=>this.editor.setValue(i),event:n})}catch(i){console.error(`Button "${e.name}" error:`,i),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:i}})),t.classList.add("button-error"),t.style.animation="buttonError 0.3s",setTimeout(()=>{t.classList.remove("button-error"),t.style.animation=""},300)}},t.addEventListener("click",t._clickHandler),t)}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),i=e.getBoundingClientRect();n.style.position="absolute",n.style.top=`${i.bottom+5}px`,n.style.left=`${i.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"}],i=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===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),t.appendChild(s)}),t}updateButtonStates(){var e;try{let t=((e=ye)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,i])=>{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}i.classList.toggle("active",r),i.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 J=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.init()}async init(){if(!(CSS.supports("position-anchor: --x")&&CSS.supports("position-area: center")))try{let t=new Function("url","return import(url)"),{computePosition:n,offset:i,shift:r,flip:s}=await t("https://cdn.jsdelivr.net/npm/@floating-ui/dom@1.7.4/+esm");this.floatingUI={computePosition:n,offset:i,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.hide()),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>this.cancelHide())}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
882
883
  <span style="display: flex; align-items: center; gap: 6px;">
883
884
  <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
884
885
  <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>
@@ -886,7 +887,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
886
887
  </svg>
887
888
  <span class="overtype-link-tooltip-url"></span>
888
889
  </span>
889
- `,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,i,r=0;for(;(i=n.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(t>=s&&t<=a)return{text:i[1],url:i[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.tooltip.style.setProperty("--target-anchor",`--link-${e.index}`),this.tooltip.classList.add("visible")}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null}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}};var Le=`<svg viewBox="0 0 18 18">
890
+ `,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,i,r=0;for(;(i=n.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(t>=s&&t<=a)return{text:i[1],url:i[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 n=t.getBoundingClientRect();if(!(n.width===0||n.height===0))try{let{x:i,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:`${i}px`,top:`${r}px`,position:"absolute"})}catch(i){console.warn("Floating UI positioning failed:",i);return}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null}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}};var Le=`<svg viewBox="0 0 18 18">
890
891
  <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>
891
892
  <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>
892
893
  </svg>`,Se=`<svg viewBox="0 0 18 18">
@@ -903,11 +904,11 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
903
904
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line>
904
905
  <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>
905
906
  <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>
906
- </svg>`,He=`<svg viewBox="0 0 18 18">
907
+ </svg>`,$e=`<svg viewBox="0 0 18 18">
907
908
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline>
908
909
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline>
909
910
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
910
- </svg>`,$e=`<svg viewBox="0 0 18 18">
911
+ </svg>`,He=`<svg viewBox="0 0 18 18">
911
912
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
912
913
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
913
914
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
@@ -925,17 +926,17 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
925
926
  </svg>`,Ie=`<svg viewBox="2 2 20 20">
926
927
  <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>
927
928
  <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>
928
- </svg>`,Be=`<svg viewBox="0 0 18 18">
929
+ </svg>`,Pe=`<svg viewBox="0 0 18 18">
929
930
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line>
930
931
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line>
931
932
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line>
932
933
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
933
934
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
934
935
  <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>
935
- </svg>`,Pe=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
936
+ </svg>`,Be=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
936
937
  <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path>
937
938
  <circle cx="12" cy="12" r="3" fill="none"></circle>
938
- </svg>`;var x={bold:{name:"bold",icon:Le,title:"Bold (Ctrl+B)",action:({editor:o,event:e})=>{D(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",icon:Se,title:"Italic (Ctrl+I)",action:({editor:o,event:e})=>{q(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",icon:He,title:"Inline Code",action:({editor:o,event:e})=>{ue(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",icon:Ae,title:"Insert Link",action:({editor:o,event:e})=>{U(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",icon:Ee,title:"Heading 1",action:({editor:o,event:e})=>{fe(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",icon:Ce,title:"Heading 2",action:({editor:o,event:e})=>{ge(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",icon:Te,title:"Heading 3",action:({editor:o,event:e})=>{ve(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",icon:$e,title:"Bullet List",action:({editor:o,event:e})=>{W(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",icon:Me,title:"Numbered List",action:({editor:o,event:e})=>{K(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",icon:Be,title:"Task List",action:({editor:o,event:e})=>{X&&(X(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",icon:Ie,title:"Quote",action:({editor:o,event:e})=>{me(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},viewMode:{name:"viewMode",icon:Pe,title:"View mode"}},G=[x.bold,x.italic,x.code,x.separator,x.link,x.separator,x.h1,x.h2,x.h3,x.separator,x.bulletList,x.orderedList,x.taskList,x.separator,x.quote,x.separator,x.viewMode];var w=class w{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(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 n=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");n||i?this._recoverFromDOM(n,i):this._buildFromScratch(),this.shortcuts=new O(this),this.linkTooltip=new J(this),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:n,colors:i,...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||w.currentTheme||B,i=typeof n=="string"?n:n.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?P(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=N(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||B,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let n=typeof this.instanceTheme=="string"?P(this.instanceTheme):this.instanceTheme;if(n&&n.colors){let i=N(n.colors);this.container.style.cssText+=i}}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,i])=>{n==="className"||n==="class"?this.textarea.className+=" "+i:n==="style"&&typeof i=="object"?Object.assign(this.textarea.style,i):this.textarea.setAttribute(n,i)}),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),window.location.pathname.includes("demo.html")&&console.log("_createDOM completed:",{elementId:this.element.id,autoResize:this.options.autoResize,containerClasses:this.container.className,hasStats:!!this.statsBar,hasToolbar:this.options.toolbar}),this.options.autoResize?this._setupAutoResize():(this.container.classList.remove("overtype-auto-resize"),window.location.pathname.includes("demo.html")&&console.log("Removed auto-resize class from:",this.element.id))}_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||G;this.toolbar=new Z(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)}_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,n=this._getCurrentLine(e,t),i=this.container.dataset.mode==="preview",r=S.parse(e,n,this.options.showActiveLineRaw,this.options.codeHighlighter,i);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 n=e[t],i=e[t+1],r=n.parentElement,s=i.parentElement;!r||!s||(n.style.display="block",i.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,t){return e.substring(0,t).split(`
939
+ </svg>`;var x={bold:{name:"bold",icon:Le,title:"Bold (Ctrl+B)",action:({editor:o,event:e})=>{U(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",icon:Se,title:"Italic (Ctrl+I)",action:({editor:o,event:e})=>{D(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",icon:$e,title:"Inline Code",action:({editor:o,event:e})=>{ue(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",icon:Ae,title:"Insert Link",action:({editor:o,event:e})=>{q(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",icon:Ee,title:"Heading 1",action:({editor:o,event:e})=>{fe(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",icon:Ce,title:"Heading 2",action:({editor:o,event:e})=>{ge(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",icon:Te,title:"Heading 3",action:({editor:o,event:e})=>{ve(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",icon:He,title:"Bullet List",action:({editor:o,event:e})=>{W(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",icon:Me,title:"Numbered List",action:({editor:o,event:e})=>{K(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",icon:Pe,title:"Task List",action:({editor:o,event:e})=>{X&&(X(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",icon:Ie,title:"Quote",action:({editor:o,event:e})=>{me(o.textarea),o.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},viewMode:{name:"viewMode",icon:Be,title:"View mode"}},G=[x.bold,x.italic,x.code,x.separator,x.link,x.separator,x.h1,x.h2,x.h3,x.separator,x.bulletList,x.orderedList,x.taskList,x.separator,x.quote,x.separator,x.viewMode];var w=class w{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(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 n=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");n||i?this._recoverFromDOM(n,i):this._buildFromScratch(),this.shortcuts=new O(this),this.linkTooltip=new J(this),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:n,colors:i,...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||w.currentTheme||P,i=typeof n=="string"?n:n.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?B(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=N(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||P,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let n=typeof this.instanceTheme=="string"?B(this.instanceTheme):this.instanceTheme;if(n&&n.colors){let i=N(n.colors);this.container.style.cssText+=i}}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,i])=>{n==="className"||n==="class"?this.textarea.className+=" "+i:n==="style"&&typeof i=="object"?Object.assign(this.textarea.style,i):this.textarea.setAttribute(n,i)}),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||G;this.toolbar=new Z(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)}_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,n=this._getCurrentLine(e,t),i=this.container.dataset.mode==="preview",r=S.parse(e,n,this.options.showActiveLineRaw,this.options.codeHighlighter,i);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 n=e[t],i=e[t+1],r=n.parentElement,s=i.parentElement;!r||!s||(n.style.display="block",i.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,t){return e.substring(0,t).split(`
939
940
  `).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){if(e.key==="Tab"){e.preventDefault();let n=this.textarea.selectionStart,i=this.textarea.selectionEnd,r=this.textarea.value;if(n!==i&&e.shiftKey){let s=r.substring(0,n),a=r.substring(n,i),p=r.substring(i),l=a.split(`
940
941
  `).map(c=>c.replace(/^ /,"")).join(`
941
942
  `);document.execCommand?(this.textarea.setSelectionRange(n,i),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+p,this.textarea.selectionStart=n,this.textarea.selectionEnd=n+l.length)}else if(n!==i){let s=r.substring(0,n),a=r.substring(n,i),p=r.substring(i),l=a.split(`
@@ -944,7 +945,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
944
945
  `+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 i=S.createNewListItem(e);document.execCommand("insertText",!1,`
945
946
  `+i+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=S.renumberLists(e);if(n!==e){let i=0,r=e.split(`
946
947
  `),s=n.split(`
947
- `),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&&(i+=l)}a+=r[d].length+1}this.textarea.value=n;let p=t+i;this.textarea.setSelectionRange(p,p),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()}getRenderedHTML(e={}){let t=this.getValue(),n=S.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={}){this.options=this._mergeOptions({...this.options,...e}),this._applyOptions(),this.updatePreview()}setTheme(e){this.instanceTheme=e;let t=typeof e=="string"?P(e):e,n=typeof t=="string"?t:t.name;if(n&&this.container.setAttribute("data-theme",n),t&&t.colors){let i=N(t.colors);this.container.style.cssText+=i}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(`
948
+ `),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&&(i+=l)}a+=r[d].length+1}this.textarea.value=n;let p=t+i;this.textarea.setSelectionRange(p,p),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()}getRenderedHTML(e={}){let t=this.getValue(),n=S.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={}){this.options=this._mergeOptions({...this.options,...e}),this._applyOptions(),this.updatePreview()}setTheme(e){this.instanceTheme=e;let t=typeof e=="string"?B(e):e,n=typeof t=="string"?t:t.name;if(n&&this.container.setAttribute("data-theme",n),t&&t.colors){let i=N(t.colors);this.container.style.cssText+=i}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(`
948
949
  `),n=e.length,i=e.split(/\s+/).filter(l=>l.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
949
950
  `),p=a.length,d=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:n,words:i,lines:t.length,line:p,column:d}):this.statsBar.innerHTML=`
950
951
  <div class="overtype-stat">
@@ -952,7 +953,7 @@ ${a}`:r;if(d){let L=o.value[o.selectionStart-1];o.selectionStart!==0&&L!=null&&!
952
953
  <span>${n} chars, ${i} words, ${t.length} lines</span>
953
954
  </div>
954
955
  <div class="overtype-stat">Line ${p}, Col ${d}</div>
955
- `}_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,i=window.getComputedStyle(e),r=parseFloat(i.paddingTop),s=parseFloat(i.paddingBottom),a=e.scrollTop;e.style.setProperty("height","auto","important");let p=e.scrollHeight;if(this.options.minHeight){let c=parseInt(this.options.minHeight);p=Math.max(p,c)}let d="hidden";if(this.options.maxHeight){let c=parseInt(this.options.maxHeight);p>c&&(p=c,d="auto")}let l=p+"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!==p&&(this.previousHeight=p)}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.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 getInstance(e){return e.overTypeInstance||w.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let n=w.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(w.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=w.currentTheme||B,i=xe({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),w.stylesInjected=!0}static setTheme(e,t=null){let n=typeof e=="string"?P(e):e;t&&(n=ke(n,t)),w.currentTheme=n,w.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(r=>{let s=typeof n=="string"?n:n.name;s&&r.setAttribute("data-theme",s)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{if(!r.closest(".overtype-container")){let a=typeof n=="string"?n:n.name;a&&r.setAttribute("data-theme",a)}let s=r._instance;s&&s.updatePreview()});let i=typeof n=="string"?n:n.name;document.querySelectorAll("overtype-editor").forEach(r=>{i&&typeof r.setAttribute=="function"&&r.setAttribute("theme",i),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static setCodeHighlighter(e){S.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 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"),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"),i=n==null?void 0:n._instance;i&&(i.options.showStats&&i.statsBar&&i._updateStats(),clearTimeout(i._selectionTimeout),i._selectionTimeout=setTimeout(()=>{i.updatePreview()},50))}}),w.globalListenersInitialized=!0)}};T(w,"instances",new WeakMap),T(w,"stylesInjected",!1),T(w,"globalListenersInitialized",!1),T(w,"instanceCount",0);var $=w;$.MarkdownParser=S;$.ShortcutsManager=O;$.themes={solar:B,cave:P("cave")};$.getTheme=P;$.currentTheme=B;var et=$;return Fe(tt);})();
956
+ `}_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,i=window.getComputedStyle(e),r=parseFloat(i.paddingTop),s=parseFloat(i.paddingBottom),a=e.scrollTop;e.style.setProperty("height","auto","important");let p=e.scrollHeight;if(this.options.minHeight){let c=parseInt(this.options.minHeight);p=Math.max(p,c)}let d="hidden";if(this.options.maxHeight){let c=parseInt(this.options.maxHeight);p>c&&(p=c,d="auto")}let l=p+"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!==p&&(this.previousHeight=p)}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.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 getInstance(e){return e.overTypeInstance||w.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let n=w.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(w.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=w.currentTheme||P,i=xe({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),w.stylesInjected=!0}static setTheme(e,t=null){let n=typeof e=="string"?B(e):e;t&&(n=ke(n,t)),w.currentTheme=n,w.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(r=>{let s=typeof n=="string"?n:n.name;s&&r.setAttribute("data-theme",s)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{if(!r.closest(".overtype-container")){let a=typeof n=="string"?n:n.name;a&&r.setAttribute("data-theme",a)}let s=r._instance;s&&s.updatePreview()});let i=typeof n=="string"?n:n.name;document.querySelectorAll("overtype-editor").forEach(r=>{i&&typeof r.setAttribute=="function"&&r.setAttribute("theme",i),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static setCodeHighlighter(e){S.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 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"),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"),i=n==null?void 0:n._instance;i&&(i.options.showStats&&i.statsBar&&i._updateStats(),clearTimeout(i._selectionTimeout),i._selectionTimeout=setTimeout(()=>{i.updatePreview()},50))}}),w.globalListenersInitialized=!0)}};T(w,"instances",new WeakMap),T(w,"stylesInjected",!1),T(w,"globalListenersInitialized",!1),T(w,"instanceCount",0);var H=w;H.MarkdownParser=S;H.ShortcutsManager=O;H.themes={solar:P,cave:B("cave")};H.getTheme=B;H.currentTheme=P;var et=H;return Re(tt);})();
956
957
  /**
957
958
  * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
958
959
  * @version 1.0.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtype",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay",
5
5
  "main": "dist/overtype.cjs",
6
6
  "module": "dist/overtype.esm.js",