overtype 1.2.3 → 1.2.4

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,47 +1,47 @@
1
1
  /**
2
- * OverType v1.2.2
2
+ * OverType v1.2.4
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 Pe=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var Oe=(o,e,t)=>e in o?z(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var ze=(o,e)=>{for(var t in e)z(o,t,{get:e[t],enumerable:!0})},je=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Be(e))!Ne.call(o,i)&&i!==t&&z(o,i,{get:()=>e[i],enumerable:!(n=Pe(e,i))||n.enumerable});return o};var Re=o=>je(z({},"__esModule",{value:!0}),o);var H=(o,e,t)=>(Oe(o,typeof e!="symbol"?e+"":e,t),t);var Ye={};ze(Ye,{OverType:()=>C,default:()=>Xe});var L=class{static resetLinkIndex(){this.linkIndex=0}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 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("(?<!_)_(?!_)(.+?)(?<!_)_(?!_)","g"),'<em><span class="syntax-marker">_</span>$1<span class="syntax-marker">_</span></em>'),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 parseInlineElements(e){let t=e;t=this.parseInlineCode(t);let n=new Map;return t=t.replace(/(<code>.*?<\/code>)/g,i=>{let r=`\uE000${n.size}\uE001`;return n.set(r,i),r}),t=this.parseLinks(t),t=t.replace(/(<a[^>]*>.*?<\/a>)/g,i=>{let r=`\uE000${n.size}\uE001`;return n.set(r,i),r}),t=this.parseBold(t),t=this.parseItalic(t),n.forEach((i,r)=>{t=t.replace(r,i)}),t}static parseLine(e){let t=this.escapeHtml(e);t=this.preserveIndentation(t,e);let n=this.parseHorizontalRule(t);if(n)return n;let i=this.parseCodeBlock(t);return i||(t=this.parseHeader(t),t=this.parseBlockquote(t),t=this.parseBulletList(t),t=this.parseNumberedList(t),t=this.parseInlineElements(t),t.trim()===""?"<div>&nbsp;</div>":`<div>${t}</div>`)}static parse(e,t=-1,n=!1){this.resetLinkIndex();let i=e.split(`
9
- `),r=!1,a=i.map((l,c)=>{if(n&&c===t)return`<div class="raw-line">${this.escapeHtml(l)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(l))return r=!r,this.parseLine(l);if(r){let p=this.escapeHtml(l);return`<div>${this.preserveIndentation(p,l)||"&nbsp;"}</div>`}return this.parseLine(l)}).join("");return this.postProcessHTML(a)}static postProcessHTML(e){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e);let t=document.createElement("div");t.innerHTML=e;let n=null,i=null,r=null,s=!1,a=Array.from(t.children);for(let l=0;l<a.length;l++){let c=a[l];if(!c.parentNode)continue;let d=c.querySelector(".code-fence");if(d){let u=d.textContent;if(u.startsWith("```"))if(s){s=!1,r=null;continue}else{s=!0,r=document.createElement("pre");let h=document.createElement("code");r.appendChild(h),r.className="code-block";let m=u.slice(3).trim();m&&(h.className=`language-${m}`),t.insertBefore(r,c.nextSibling),r._codeElement=h;continue}}if(s&&r&&c.tagName==="DIV"&&!c.querySelector(".code-fence")){let u=r._codeElement||r.querySelector("code");u.textContent.length>0&&(u.textContent+=`
10
- `);let h=c.textContent.replace(/\u00A0/g," ");u.textContent+=h,c.remove();continue}let p=null;if(c.tagName==="DIV"&&(p=c.querySelector("li")),p){let u=p.classList.contains("bullet-list"),h=p.classList.contains("ordered-list");if(!u&&!h){n=null,i=null;continue}let m=u?"ul":"ol";(!n||i!==m)&&(n=document.createElement(m),t.insertBefore(n,c),i=m),n.appendChild(p),c.remove()}else n=null,i=null}return t.innerHTML}static postProcessHTMLManual(e){let t=e;t=t.replace(/((?:<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>\s*)+)/gs,i=>{let r=i.match(/<li class="bullet-list">.*?<\/li>/gs)||[];return r.length>0?"<ul>"+r.join("")+"</ul>":i}),t=t.replace(/((?:<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>\s*)+)/gs,i=>{let r=i.match(/<li class="ordered-list">.*?<\/li>/gs)||[];return r.length>0?"<ol>"+r.join("")+"</ol>":i});let n=/<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;return t=t.replace(n,(i,r,s,a)=>{let c=(s.match(/<div>(.*?)<\/div>/gs)||[]).map(h=>h.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
11
- `),d=r.slice(3).trim(),p=d?` class="language-${d}"`:"",u=`<div><span class="code-fence">${r}</span></div>`;return u+=`<pre class="code-block"><code${p}>${c}</code></pre>`,u+=`<div><span class="code-fence">${a}</span></div>`,u}),t}static getListContext(e,t){let n=e.split(`
12
- `),i=0,r=0,s=0;for(let u=0;u<n.length;u++){let h=n[u].length;if(i+h>=t){r=u,s=i;break}i+=h+1}let a=n[r],l=s+a.length,c=a.match(this.LIST_PATTERNS.checkbox);if(c)return{inList:!0,listType:"checkbox",indent:c[1],marker:"-",checked:c[2]==="x",content:c[3],lineStart:s,lineEnd:l,markerEndPos:s+c[1].length+c[2].length+5};let d=a.match(this.LIST_PATTERNS.bullet);if(d)return{inList:!0,listType:"bullet",indent:d[1],marker:d[2],content:d[3],lineStart:s,lineEnd:l,markerEndPos:s+d[1].length+d[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:l,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:l,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let t=e.split(`
13
- `),n=new Map,i=!1;return t.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let l=a[1],c=l.length,d=a[3];i||n.clear();let p=(n.get(c)||0)+1;n.set(c,p);for(let[u]of n)u>c&&n.delete(u);return i=!0,`${l}${p}. ${d}`}else return(s.trim()===""||!s.match(/^\s/))&&(i=!1,n.clear()),s}).join(`
14
- `)}};H(L,"linkIndex",0),H(L,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var _e=Object.defineProperty,Y=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,ee=(o,e,t)=>e in o?_e(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,te=(o,e)=>{for(var t in e||(e={}))Fe.call(e,t)&&ee(o,t,e[t]);if(Y)for(var t of Y(e))Ve.call(e,t)&&ee(o,t,e[t]);return o},S={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 De(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function A(o){return te(te({},De()),o)}var R=!1;function qe(){return R}function v(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 re(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 T=null;function $(o,{text:e,selectionStart:t,selectionEnd:n}){let i=qe();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),l=o.value.slice(s);i&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(l.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(o.value.slice(r,s))));let c=o.value,d=r!==s;if(T===null||T===!0){o.contentEditable="true";try{T=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",T,"for text with",e.split(`
15
- `).length,"lines")}catch(p){T=!1,i&&console.log("execCommand threw error:",p)}o.contentEditable="false"}if(i&&(console.log("canInsertText before:",T),console.log("execCommand result:",T)),T){let p=a+e+l,u=o.value;i&&(console.log("Expected length:",p.length),console.log("Actual length:",u.length)),u!==p&&i&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(p.slice(0,100))),console.log("Actual:",JSON.stringify(u.slice(0,100))))}if(!T)if(i&&console.log("Using manual insertion"),o.value===c){i&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}o.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(p){}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 ne(o){return o.trim().split(`
8
+ var OverType=(()=>{var z=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var Oe=(o,e,t)=>e in o?z(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var ze=(o,e)=>{for(var t in e)z(o,t,{get:e[t],enumerable:!0})},je=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Pe(e))!Ne.call(o,i)&&i!==t&&z(o,i,{get:()=>e[i],enumerable:!(n=Be(e,i))||n.enumerable});return o};var Re=o=>je(z({},"__esModule",{value:!0}),o);var H=(o,e,t)=>(Oe(o,typeof e!="symbol"?e+"":e,t),t);var Ye={};ze(Ye,{OverType:()=>M,default:()=>Xe});var L=class{static resetLinkIndex(){this.linkIndex=0}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 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("(?<!_)_(?!_)(.+?)(?<!_)_(?!_)","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(l=>n.startsWith(l)),a=t.startsWith("/")||t.startsWith("#")||t.startsWith("?")||t.startsWith(".")||!t.includes(":")&&!t.includes("//");return r||a?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 parseInlineElements(e){let t=e;t=this.parseInlineCode(t);let n=new Map;return t=t.replace(/(<code>.*?<\/code>)/g,i=>{let r=`\uE000${n.size}\uE001`;return n.set(r,i),r}),t=this.parseLinks(t),t=t.replace(/(<a[^>]*>.*?<\/a>)/g,i=>{let r=`\uE000${n.size}\uE001`;return n.set(r,i),r}),t=this.parseStrikethrough(t),t=this.parseBold(t),t=this.parseItalic(t),n.forEach((i,r)=>{t=t.replace(r,i)}),t}static parseLine(e){let t=this.escapeHtml(e);t=this.preserveIndentation(t,e);let n=this.parseHorizontalRule(t);if(n)return n;let i=this.parseCodeBlock(t);return i||(t=this.parseHeader(t),t=this.parseBlockquote(t),t=this.parseBulletList(t),t=this.parseNumberedList(t),t=this.parseInlineElements(t),t.trim()===""?"<div>&nbsp;</div>":`<div>${t}</div>`)}static parse(e,t=-1,n=!1){this.resetLinkIndex();let i=e.split(`
9
+ `),r=!1,l=i.map((s,c)=>{if(n&&c===t)return`<div class="raw-line">${this.escapeHtml(s)||"&nbsp;"}</div>`;if(/^```[^`]*$/.test(s))return r=!r,this.parseLine(s);if(r){let p=this.escapeHtml(s);return`<div>${this.preserveIndentation(p,s)||"&nbsp;"}</div>`}return this.parseLine(s)}).join("");return this.postProcessHTML(l)}static postProcessHTML(e){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e);let t=document.createElement("div");t.innerHTML=e;let n=null,i=null,r=null,a=!1,l=Array.from(t.children);for(let s=0;s<l.length;s++){let c=l[s];if(!c.parentNode)continue;let d=c.querySelector(".code-fence");if(d){let u=d.textContent;if(u.startsWith("```"))if(a){a=!1,r=null;continue}else{a=!0,r=document.createElement("pre");let h=document.createElement("code");r.appendChild(h),r.className="code-block";let f=u.slice(3).trim();f&&(h.className=`language-${f}`),t.insertBefore(r,c.nextSibling),r._codeElement=h;continue}}if(a&&r&&c.tagName==="DIV"&&!c.querySelector(".code-fence")){let u=r._codeElement||r.querySelector("code");u.textContent.length>0&&(u.textContent+=`
10
+ `);let h=c.textContent.replace(/\u00A0/g," ");u.textContent+=h,c.remove();continue}let p=null;if(c.tagName==="DIV"&&(p=c.querySelector("li")),p){let u=p.classList.contains("bullet-list"),h=p.classList.contains("ordered-list");if(!u&&!h){n=null,i=null;continue}let f=u?"ul":"ol";(!n||i!==f)&&(n=document.createElement(f),t.insertBefore(n,c),i=f);let g=[];for(let m of c.childNodes)if(m.nodeType===3&&m.textContent.match(/^\u00A0+$/))g.push(m.cloneNode(!0));else if(m===p)break;g.forEach(m=>{p.insertBefore(m,p.firstChild)}),n.appendChild(p),c.remove()}else n=null,i=null}return t.innerHTML}static postProcessHTMLManual(e){let t=e;t=t.replace(/((?:<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>\s*)+)/gs,i=>{let r=i.match(/<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>/gs)||[];return r.length>0?"<ul>"+r.map(l=>{let s=l.match(/<div>((?:&nbsp;)*)<li/),c=l.match(/<li class="bullet-list">.*?<\/li>/);if(s&&c){let d=s[1];return c[0].replace(/<li class="bullet-list">/,`<li class="bullet-list">${d}`)}return c?c[0]:""}).filter(Boolean).join("")+"</ul>":i}),t=t.replace(/((?:<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>\s*)+)/gs,i=>{let r=i.match(/<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>/gs)||[];return r.length>0?"<ol>"+r.map(l=>{let s=l.match(/<div>((?:&nbsp;)*)<li/),c=l.match(/<li class="ordered-list">.*?<\/li>/);if(s&&c){let d=s[1];return c[0].replace(/<li class="ordered-list">/,`<li class="ordered-list">${d}`)}return c?c[0]:""}).filter(Boolean).join("")+"</ol>":i});let n=/<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;return t=t.replace(n,(i,r,a,l)=>{let c=(a.match(/<div>(.*?)<\/div>/gs)||[]).map(h=>h.replace(/<div>(.*?)<\/div>/s,"$1").replace(/&nbsp;/g," ")).join(`
11
+ `),d=r.slice(3).trim(),p=d?` class="language-${d}"`:"",u=`<div><span class="code-fence">${r}</span></div>`;return u+=`<pre class="code-block"><code${p}>${c}</code></pre>`,u+=`<div><span class="code-fence">${l}</span></div>`,u}),t}static getListContext(e,t){let n=e.split(`
12
+ `),i=0,r=0,a=0;for(let u=0;u<n.length;u++){let h=n[u].length;if(i+h>=t){r=u,a=i;break}i+=h+1}let l=n[r],s=a+l.length,c=l.match(this.LIST_PATTERNS.checkbox);if(c)return{inList:!0,listType:"checkbox",indent:c[1],marker:"-",checked:c[2]==="x",content:c[3],lineStart:a,lineEnd:s,markerEndPos:a+c[1].length+c[2].length+5};let d=l.match(this.LIST_PATTERNS.bullet);if(d)return{inList:!0,listType:"bullet",indent:d[1],marker:d[2],content:d[3],lineStart:a,lineEnd:s,markerEndPos:a+d[1].length+d[2].length+1};let p=l.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:a,lineEnd:s,markerEndPos:a+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:l,lineStart:a,lineEnd:s,markerEndPos:a}}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(`
13
+ `),n=new Map,i=!1;return t.map(a=>{let l=a.match(this.LIST_PATTERNS.numbered);if(l){let s=l[1],c=s.length,d=l[3];i||n.clear();let p=(n.get(c)||0)+1;n.set(c,p);for(let[u]of n)u>c&&n.delete(u);return i=!0,`${s}${p}. ${d}`}else return(a.trim()===""||!a.match(/^\s/))&&(i=!1,n.clear()),a}).join(`
14
+ `)}};H(L,"linkIndex",0),H(L,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var _e=Object.defineProperty,Y=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,ee=(o,e,t)=>e in o?_e(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,te=(o,e)=>{for(var t in e||(e={}))Fe.call(e,t)&&ee(o,t,e[t]);if(Y)for(var t of Y(e))Ve.call(e,t)&&ee(o,t,e[t]);return o},S={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 De(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function T(o){return te(te({},De()),o)}var R=!1;function qe(){return R}function v(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 re(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 E=null;function $(o,{text:e,selectionStart:t,selectionEnd:n}){let i=qe();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,a=o.selectionEnd,l=o.value.slice(0,r),s=o.value.slice(a);i&&(console.log("Before text (last 20):",JSON.stringify(l.slice(-20))),console.log("After text (first 20):",JSON.stringify(s.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(o.value.slice(r,a))));let c=o.value,d=r!==a;if(E===null||E===!0){o.contentEditable="true";try{E=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",E,"for text with",e.split(`
15
+ `).length,"lines")}catch(p){E=!1,i&&console.log("execCommand threw error:",p)}o.contentEditable="false"}if(i&&(console.log("canInsertText before:",E),console.log("execCommand result:",E)),E){let p=l+e+s,u=o.value;i&&(console.log("Expected length:",p.length),console.log("Actual length:",u.length)),u!==p&&i&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(p.slice(0,100))),console.log("Actual:",JSON.stringify(u.slice(0,100))))}if(!E)if(i&&console.log("Using manual insertion"),o.value===c){i&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}o.value=l+e+s;try{document.execCommand("ms-endUndoUnit")}catch(p){}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 ne(o){return o.trim().split(`
16
16
  `).length>1}function Ue(o,e){let t=e;for(;o[t]&&o[t-1]!=null&&!o[t-1].match(/\s/);)t--;return t}function We(o,e,t){let n=e,i=t?/\n/:/\s/;for(;o[n]&&!o[n].match(i);)n++;return n}function se(o){let e=o.value.split(`
17
- `),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 Ke(o,e,t,n=!1){if(o.selectionStart===o.selectionEnd)o.selectionStart=Ue(o.value,o.selectionStart),o.selectionEnd=We(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 J(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="",l="";return e.match(/\S/)&&r<2&&(a=`
18
- `.repeat(2-r)),t.match(/\S/)&&s<2&&(l=`
19
- `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function _(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
- `;)a--;if(r){let c=n;for(;c<s.length&&s[c]!==`
21
- `;)c++;o.selectionStart=a,o.selectionEnd=c}else se(o);let l=e(o);if(t.adjustSelection){let d=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix),p=t.adjustSelection(d,n,i,a);l.selectionStart=p.start,l.selectionEnd=p.end}else if(t.prefix){let d=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix);r?d?(l.selectionStart=Math.max(n-t.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=n+t.prefix.length,l.selectionEnd=l.selectionStart):d?(l.selectionStart=Math.max(n-t.prefix.length,a),l.selectionEnd=Math.max(i-t.prefix.length,a)):(l.selectionStart=n+t.prefix.length,l.selectionEnd=i+t.prefix.length)}return l}function F(o,e){let t,n,{prefix:i,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:c,scanFor:d,surroundWithNewlines:p,trimFirst:u}=e,h=o.selectionStart,m=o.selectionEnd,g=o.value.slice(o.selectionStart,o.selectionEnd),f=ne(g)&&s&&s.length>0?`${s}
22
- `:i,w=ne(g)&&a&&a.length>0?`
23
- ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!x.match(/\s/)&&(f=` ${f}`)}g=Ke(o,f,w,e.multiline);let y=o.selectionStart,k=o.selectionEnd,M=l&&l.length>0&&w.indexOf(l)>-1&&g.length>0;if(p){let x=J(o);t=x.newlinesToAppend,n=x.newlinesToPrepend,f=t+i,w+=n}if(g.startsWith(f)&&g.endsWith(w)){let x=g.slice(f.length,g.length-w.length);if(h===m){let E=h-f.length;E=Math.max(E,y),E=Math.min(E,y+x.length),y=k=E}else k=y+x.length;return{text:x,selectionStart:y,selectionEnd:k}}else if(M)if(d&&d.length>0&&g.match(d)){w=w.replace(l,g);let x=f+w;return y=k=y+f.length,{text:x,selectionStart:y,selectionEnd:k}}else{let x=f+g+w;return y=y+f.length+g.length+w.indexOf(l),k=y+l.length,{text:x,selectionStart:y,selectionEnd:k}}else{let x=f+g+w;y=h+f.length,k=m+f.length;let E=g.match(/^\s*|\s*$/g);if(u&&E){let G=E[0]||"",X=E[1]||"";x=G+f+g.trim()+w+X,y+=G.length,k-=X.length}return{text:x,selectionStart:y,selectionEnd:k}}}function ae(o,e){let{prefix:t,suffix:n,surroundWithNewlines:i}=e,r=o.value.slice(o.selectionStart,o.selectionEnd),s=o.selectionStart,a=o.selectionEnd,l=r.split(`
24
- `);if(l.every(d=>d.startsWith(t)&&(!n||d.endsWith(n))))r=l.map(d=>{let p=d.slice(t.length);return n&&(p=p.slice(0,p.length-n.length)),p}).join(`
25
- `),a=s+r.length;else if(r=l.map(d=>t+d+(n||"")).join(`
26
- `),i){let{newlinesToAppend:d,newlinesToPrepend:p}=J(o);s+=d.length,a=s+r.length,r=d+r+p}return{text:r,selectionStart:s,selectionEnd:a}}function oe(o){let e=o.split(`
17
+ `),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 Ke(o,e,t,n=!1){if(o.selectionStart===o.selectionEnd)o.selectionStart=Ue(o.value,o.selectionStart),o.selectionEnd=We(o.value,o.selectionEnd,n);else{let i=o.selectionStart-e.length,r=o.selectionEnd+t.length,a=o.value.slice(i,o.selectionStart)===e,l=o.value.slice(o.selectionEnd,r)===t;a&&l&&(o.selectionStart=i,o.selectionEnd=r)}return o.value.slice(o.selectionStart,o.selectionEnd)}function J(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,a=i?i[0].length:0,l="",s="";return e.match(/\S/)&&r<2&&(l=`
18
+ `.repeat(2-r)),t.match(/\S/)&&a<2&&(s=`
19
+ `.repeat(2-a)),{newlinesToAppend:l,newlinesToPrepend:s}}function _(o,e,t={}){let n=o.selectionStart,i=o.selectionEnd,r=n===i,a=o.value,l=n;for(;l>0&&a[l-1]!==`
20
+ `;)l--;if(r){let c=n;for(;c<a.length&&a[c]!==`
21
+ `;)c++;o.selectionStart=l,o.selectionEnd=c}else se(o);let s=e(o);if(t.adjustSelection){let d=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix),p=t.adjustSelection(d,n,i,l);s.selectionStart=p.start,s.selectionEnd=p.end}else if(t.prefix){let d=o.value.slice(o.selectionStart,o.selectionEnd).startsWith(t.prefix);r?d?(s.selectionStart=Math.max(n-t.prefix.length,l),s.selectionEnd=s.selectionStart):(s.selectionStart=n+t.prefix.length,s.selectionEnd=s.selectionStart):d?(s.selectionStart=Math.max(n-t.prefix.length,l),s.selectionEnd=Math.max(i-t.prefix.length,l)):(s.selectionStart=n+t.prefix.length,s.selectionEnd=i+t.prefix.length)}return s}function F(o,e){let t,n,{prefix:i,suffix:r,blockPrefix:a,blockSuffix:l,replaceNext:s,prefixSpace:c,scanFor:d,surroundWithNewlines:p,trimFirst:u}=e,h=o.selectionStart,f=o.selectionEnd,g=o.value.slice(o.selectionStart,o.selectionEnd),m=ne(g)&&a&&a.length>0?`${a}
22
+ `:i,b=ne(g)&&l&&l.length>0?`
23
+ ${l}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!x.match(/\s/)&&(m=` ${m}`)}g=Ke(o,m,b,e.multiline);let y=o.selectionStart,k=o.selectionEnd,A=s&&s.length>0&&b.indexOf(s)>-1&&g.length>0;if(p){let x=J(o);t=x.newlinesToAppend,n=x.newlinesToPrepend,m=t+i,b+=n}if(g.startsWith(m)&&g.endsWith(b)){let x=g.slice(m.length,g.length-b.length);if(h===f){let C=h-m.length;C=Math.max(C,y),C=Math.min(C,y+x.length),y=k=C}else k=y+x.length;return{text:x,selectionStart:y,selectionEnd:k}}else if(A)if(d&&d.length>0&&g.match(d)){b=b.replace(s,g);let x=m+b;return y=k=y+m.length,{text:x,selectionStart:y,selectionEnd:k}}else{let x=m+g+b;return y=y+m.length+g.length+b.indexOf(s),k=y+s.length,{text:x,selectionStart:y,selectionEnd:k}}else{let x=m+g+b;y=h+m.length,k=f+m.length;let C=g.match(/^\s*|\s*$/g);if(u&&C){let G=C[0]||"",X=C[1]||"";x=G+m+g.trim()+b+X,y+=G.length,k-=X.length}return{text:x,selectionStart:y,selectionEnd:k}}}function ae(o,e){let{prefix:t,suffix:n,surroundWithNewlines:i}=e,r=o.value.slice(o.selectionStart,o.selectionEnd),a=o.selectionStart,l=o.selectionEnd,s=r.split(`
24
+ `);if(s.every(d=>d.startsWith(t)&&(!n||d.endsWith(n))))r=s.map(d=>{let p=d.slice(t.length);return n&&(p=p.slice(0,p.length-n.length)),p}).join(`
25
+ `),l=a+r.length;else if(r=s.map(d=>t+d+(n||"")).join(`
26
+ `),i){let{newlinesToAppend:d,newlinesToPrepend:p}=J(o);a+=d.length,l=a+r.length,r=d+r+p}return{text:r,selectionStart:a,selectionEnd:l}}function oe(o){let e=o.split(`
27
27
  `),t=/^\d+\.\s+/,n=e.every(r=>t.test(r)),i=e;return n&&(i=e.map(r=>r.replace(t,""))),{text:i.join(`
28
28
  `),processed:n}}function ie(o){let e=o.split(`
29
29
  `),t="- ",n=e.every(r=>r.startsWith(t)),i=e;return n&&(i=e.map(r=>r.slice(t.length))),{text:i.join(`
30
- `),processed:n}}function B(o,e){return e?"- ":`${o+1}. `}function Ze(o,e){let t,n,i;return o.orderedList?(t=oe(e),n=ie(t.text),i=n.text):(t=ie(e),n=oe(t.text),i=n.text),[t,n,i]}function Je(o,e){let t=o.selectionStart===o.selectionEnd,n=o.selectionStart,i=o.selectionEnd;se(o);let r=o.value.slice(o.selectionStart,o.selectionEnd),[s,a,l]=Ze(e,r),c=l.split(`
31
- `).map((g,f)=>`${B(f,e.unorderedList)}${g}`),d=c.reduce((g,f,w)=>g+B(w,e.unorderedList).length,0),p=c.reduce((g,f,w)=>g+B(w,!e.unorderedList).length,0);if(s.processed)return t?(n=Math.max(n-B(0,e.unorderedList).length,0),i=n):(n=o.selectionStart,i=o.selectionEnd-d),{text:l,selectionStart:n,selectionEnd:i};let{newlinesToAppend:u,newlinesToPrepend:h}=J(o),m=u+c.join(`
32
- `)+h;return t?(n=Math.max(n+B(0,e.unorderedList).length+u.length,0),i=n):a.processed?(n=Math.max(o.selectionStart+u.length,0),i=o.selectionEnd+u.length+d-p):(n=Math.max(o.selectionStart+u.length,0),i=o.selectionEnd+u.length+d),{text:m,selectionStart:n,selectionEnd:i}}function le(o,e){let t=_(o,n=>Je(n,e),{adjustSelection:(n,i,r,s)=>{let a=o.value.slice(s,o.selectionEnd),l=/^\d+\.\s+/,c=/^- /,d=l.test(a),p=c.test(a),u=e.orderedList&&d||e.unorderedList&&p;if(i===r)if(u){let h=a.match(e.orderedList?l:c),m=h?h[0].length:0;return{start:Math.max(i-m,s),end:Math.max(i-m,s)}}else if(d||p){let h=a.match(d?l:c),m=h?h[0].length:0,f=(e.unorderedList?2:3)-m;return{start:i+f,end:i+f}}else{let h=e.unorderedList?2:3;return{start:i+h,end:i+h}}else if(u){let h=a.match(e.orderedList?l:c),m=h?h[0].length:0;return{start:Math.max(i-m,s),end:Math.max(r-m,s)}}else if(d||p){let h=a.match(d?l:c),m=h?h[0].length:0,f=(e.unorderedList?2:3)-m;return{start:i+f,end:r+f}}else{let h=e.unorderedList?2:3;return{start:i+h,end:r+h}}}});$(o,t)}function Qe(o){if(!o)return[];let e=[],{selectionStart:t,selectionEnd:n,value:i}=o,r=i.split(`
33
- `),s=0,a="";for(let p of r){if(t>=s&&t<=s+p.length){a=p;break}s+=p.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let l=Math.max(0,t-10),c=Math.min(i.length,n+10),d=i.slice(l,c);if(d.includes("**")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100)),h=p.lastIndexOf("**"),m=u.indexOf("**");h!==-1&&m!==-1&&e.push("bold")}if(d.includes("_")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100)),h=p.lastIndexOf("_"),m=u.indexOf("_");h!==-1&&m!==-1&&e.push("italic")}if(d.includes("`")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100));p.includes("`")&&u.includes("`")&&e.push("code")}if(d.includes("[")&&d.includes("]")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100)),h=p.lastIndexOf("["),m=u.indexOf("]");h!==-1&&m!==-1&&i.slice(n+m+1,n+m+10).startsWith("(")&&e.push("link")}return e}function V(o){if(!o||o.disabled||o.readOnly)return;v("toggleBold","Starting"),j(o,"Before");let e=A(S.bold),t=F(o,e);re(t),$(o,t),j(o,"After")}function D(o){if(!o||o.disabled||o.readOnly)return;let e=A(S.italic),t=F(o,e);$(o,t)}function ce(o){if(!o||o.disabled||o.readOnly)return;let e=A(S.code),t=F(o,e);$(o,t)}function q(o,e={}){if(!o||o.disabled||o.readOnly)return;let t=o.value.slice(o.selectionStart,o.selectionEnd),n=A(S.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=F(o,n);$(o,r)}function U(o){if(!o||o.disabled||o.readOnly)return;let e=A(S.bulletList);le(o,e)}function W(o){if(!o||o.disabled||o.readOnly)return;let e=A(S.numberedList);le(o,e)}function pe(o){if(!o||o.disabled||o.readOnly)return;v("toggleQuote","Starting"),j(o,"Initial");let e=A(S.quote),t=_(o,n=>ae(n,e),{prefix:e.prefix});re(t),$(o,t),j(o,"Final")}function de(o){if(!o||o.disabled||o.readOnly)return;let e=A(S.taskList),t=_(o,n=>ae(n,e),{prefix:e.prefix});$(o,t)}function Q(o,e=1,t=!1){if(!o||o.disabled||o.readOnly)return;(e<1||e>6)&&(e=1),v("insertHeader","============ START ============"),v("insertHeader",`Level: ${e}, Toggle: ${t}`),v("insertHeader",`Initial cursor: ${o.selectionStart}-${o.selectionEnd}`);let n=`header${e===1?"1":e}`,i=A(S[n]||S.header1);v("insertHeader",`Style prefix: "${i.prefix}"`);let r=o.value,s=o.selectionStart,a=o.selectionEnd,l=s;for(;l>0&&r[l-1]!==`
34
- `;)l--;let c=a;for(;c<r.length&&r[c]!==`
35
- `;)c++;let d=r.slice(l,c);v("insertHeader",`Current line (before): "${d}"`);let p=d.match(/^(#{1,6})\s*/),u=p?p[1].length:0,h=p?p[0].length:0;v("insertHeader","Existing header check:"),v("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),v("insertHeader",` - Existing level: ${u}`),v("insertHeader",` - Existing prefix length: ${h}`),v("insertHeader",` - Target level: ${e}`);let m=t&&u===e;v("insertHeader",`Should toggle OFF: ${m} (toggle=${t}, existingLevel=${u}, level=${e})`);let g=_(o,f=>{let w=f.value.slice(f.selectionStart,f.selectionEnd);v("insertHeader",`Line in operation: "${w}"`);let y=w.replace(/^#{1,6}\s*/,"");v("insertHeader",`Cleaned line: "${y}"`);let k;return m?(v("insertHeader","ACTION: Toggling OFF - removing header"),k=y):u>0?(v("insertHeader",`ACTION: Replacing H${u} with H${e}`),k=i.prefix+y):(v("insertHeader","ACTION: Adding new header"),k=i.prefix+y),v("insertHeader",`New line: "${k}"`),{text:k,selectionStart:f.selectionStart,selectionEnd:f.selectionEnd}},{prefix:i.prefix,adjustSelection:(f,w,y,k)=>{if(v("insertHeader","Adjusting selection:"),v("insertHeader",` - isRemoving param: ${f}`),v("insertHeader",` - shouldToggleOff: ${m}`),v("insertHeader",` - selStart: ${w}, selEnd: ${y}`),v("insertHeader",` - lineStartPos: ${k}`),m){let M=Math.max(w-h,k);return v("insertHeader",` - Removing header, adjusting by -${h}`),{start:M,end:w===y?M:Math.max(y-h,k)}}else if(h>0){let M=i.prefix.length-h;return v("insertHeader",` - Replacing header, adjusting by ${M}`),{start:w+M,end:y+M}}else return v("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:w+i.prefix.length,end:y+i.prefix.length}}});v("insertHeader",`Final result: text="${g.text}", cursor=${g.selectionStart}-${g.selectionEnd}`),v("insertHeader","============ END ============"),$(o,g)}function ue(o){Q(o,1,!0)}function he(o){Q(o,2,!0)}function me(o){Q(o,3,!0)}function fe(o){return Qe(o)}var N=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":V(t);break;case"toggleItalic":D(t);break;case"insertLink":q(t);break;case"toggleBulletList":U(t);break;case"toggleNumberedList":W(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(n){console.error("Error in markdown action:",n)}}}destroy(){}};var I={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"}},ve={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"}},ye={solar:I,cave:ve,light:I,dark:ve};function P(o){return typeof o=="string"?{...ye[o]||ye.solar,name:o}:o}function O(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
- `)}function we(o,e={}){return{...o,colors:{...o.colors,...e}}}function be(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?`
30
+ `),processed:n}}function P(o,e){return e?"- ":`${o+1}. `}function Ze(o,e){let t,n,i;return o.orderedList?(t=oe(e),n=ie(t.text),i=n.text):(t=ie(e),n=oe(t.text),i=n.text),[t,n,i]}function Je(o,e){let t=o.selectionStart===o.selectionEnd,n=o.selectionStart,i=o.selectionEnd;se(o);let r=o.value.slice(o.selectionStart,o.selectionEnd),[a,l,s]=Ze(e,r),c=s.split(`
31
+ `).map((g,m)=>`${P(m,e.unorderedList)}${g}`),d=c.reduce((g,m,b)=>g+P(b,e.unorderedList).length,0),p=c.reduce((g,m,b)=>g+P(b,!e.unorderedList).length,0);if(a.processed)return t?(n=Math.max(n-P(0,e.unorderedList).length,0),i=n):(n=o.selectionStart,i=o.selectionEnd-d),{text:s,selectionStart:n,selectionEnd:i};let{newlinesToAppend:u,newlinesToPrepend:h}=J(o),f=u+c.join(`
32
+ `)+h;return t?(n=Math.max(n+P(0,e.unorderedList).length+u.length,0),i=n):l.processed?(n=Math.max(o.selectionStart+u.length,0),i=o.selectionEnd+u.length+d-p):(n=Math.max(o.selectionStart+u.length,0),i=o.selectionEnd+u.length+d),{text:f,selectionStart:n,selectionEnd:i}}function le(o,e){let t=_(o,n=>Je(n,e),{adjustSelection:(n,i,r,a)=>{let l=o.value.slice(a,o.selectionEnd),s=/^\d+\.\s+/,c=/^- /,d=s.test(l),p=c.test(l),u=e.orderedList&&d||e.unorderedList&&p;if(i===r)if(u){let h=l.match(e.orderedList?s:c),f=h?h[0].length:0;return{start:Math.max(i-f,a),end:Math.max(i-f,a)}}else if(d||p){let h=l.match(d?s:c),f=h?h[0].length:0,m=(e.unorderedList?2:3)-f;return{start:i+m,end:i+m}}else{let h=e.unorderedList?2:3;return{start:i+h,end:i+h}}else if(u){let h=l.match(e.orderedList?s:c),f=h?h[0].length:0;return{start:Math.max(i-f,a),end:Math.max(r-f,a)}}else if(d||p){let h=l.match(d?s:c),f=h?h[0].length:0,m=(e.unorderedList?2:3)-f;return{start:i+m,end:r+m}}else{let h=e.unorderedList?2:3;return{start:i+h,end:r+h}}}});$(o,t)}function Qe(o){if(!o)return[];let e=[],{selectionStart:t,selectionEnd:n,value:i}=o,r=i.split(`
33
+ `),a=0,l="";for(let p of r){if(t>=a&&t<=a+p.length){l=p;break}a+=p.length+1}l.startsWith("- ")&&(l.startsWith("- [ ] ")||l.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(l)&&e.push("numbered-list"),l.startsWith("> ")&&e.push("quote"),l.startsWith("# ")&&e.push("header"),l.startsWith("## ")&&e.push("header-2"),l.startsWith("### ")&&e.push("header-3");let s=Math.max(0,t-10),c=Math.min(i.length,n+10),d=i.slice(s,c);if(d.includes("**")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100)),h=p.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(d.includes("_")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100)),h=p.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(d.includes("`")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100));p.includes("`")&&u.includes("`")&&e.push("code")}if(d.includes("[")&&d.includes("]")){let p=i.slice(Math.max(0,t-100),t),u=i.slice(n,Math.min(i.length,n+100)),h=p.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&i.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function V(o){if(!o||o.disabled||o.readOnly)return;v("toggleBold","Starting"),j(o,"Before");let e=T(S.bold),t=F(o,e);re(t),$(o,t),j(o,"After")}function D(o){if(!o||o.disabled||o.readOnly)return;let e=T(S.italic),t=F(o,e);$(o,t)}function ce(o){if(!o||o.disabled||o.readOnly)return;let e=T(S.code),t=F(o,e);$(o,t)}function q(o,e={}){if(!o||o.disabled||o.readOnly)return;let t=o.value.slice(o.selectionStart,o.selectionEnd),n=T(S.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 a=o.selectionStart;o.value=o.value.slice(0,a)+e.text+o.value.slice(a),o.selectionStart=a,o.selectionEnd=a+e.text.length}let r=F(o,n);$(o,r)}function U(o){if(!o||o.disabled||o.readOnly)return;let e=T(S.bulletList);le(o,e)}function W(o){if(!o||o.disabled||o.readOnly)return;let e=T(S.numberedList);le(o,e)}function pe(o){if(!o||o.disabled||o.readOnly)return;v("toggleQuote","Starting"),j(o,"Initial");let e=T(S.quote),t=_(o,n=>ae(n,e),{prefix:e.prefix});re(t),$(o,t),j(o,"Final")}function de(o){if(!o||o.disabled||o.readOnly)return;let e=T(S.taskList),t=_(o,n=>ae(n,e),{prefix:e.prefix});$(o,t)}function Q(o,e=1,t=!1){if(!o||o.disabled||o.readOnly)return;(e<1||e>6)&&(e=1),v("insertHeader","============ START ============"),v("insertHeader",`Level: ${e}, Toggle: ${t}`),v("insertHeader",`Initial cursor: ${o.selectionStart}-${o.selectionEnd}`);let n=`header${e===1?"1":e}`,i=T(S[n]||S.header1);v("insertHeader",`Style prefix: "${i.prefix}"`);let r=o.value,a=o.selectionStart,l=o.selectionEnd,s=a;for(;s>0&&r[s-1]!==`
34
+ `;)s--;let c=l;for(;c<r.length&&r[c]!==`
35
+ `;)c++;let d=r.slice(s,c);v("insertHeader",`Current line (before): "${d}"`);let p=d.match(/^(#{1,6})\s*/),u=p?p[1].length:0,h=p?p[0].length:0;v("insertHeader","Existing header check:"),v("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),v("insertHeader",` - Existing level: ${u}`),v("insertHeader",` - Existing prefix length: ${h}`),v("insertHeader",` - Target level: ${e}`);let f=t&&u===e;v("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${u}, level=${e})`);let g=_(o,m=>{let b=m.value.slice(m.selectionStart,m.selectionEnd);v("insertHeader",`Line in operation: "${b}"`);let y=b.replace(/^#{1,6}\s*/,"");v("insertHeader",`Cleaned line: "${y}"`);let k;return f?(v("insertHeader","ACTION: Toggling OFF - removing header"),k=y):u>0?(v("insertHeader",`ACTION: Replacing H${u} with H${e}`),k=i.prefix+y):(v("insertHeader","ACTION: Adding new header"),k=i.prefix+y),v("insertHeader",`New line: "${k}"`),{text:k,selectionStart:m.selectionStart,selectionEnd:m.selectionEnd}},{prefix:i.prefix,adjustSelection:(m,b,y,k)=>{if(v("insertHeader","Adjusting selection:"),v("insertHeader",` - isRemoving param: ${m}`),v("insertHeader",` - shouldToggleOff: ${f}`),v("insertHeader",` - selStart: ${b}, selEnd: ${y}`),v("insertHeader",` - lineStartPos: ${k}`),f){let A=Math.max(b-h,k);return v("insertHeader",` - Removing header, adjusting by -${h}`),{start:A,end:b===y?A:Math.max(y-h,k)}}else if(h>0){let A=i.prefix.length-h;return v("insertHeader",` - Replacing header, adjusting by ${A}`),{start:b+A,end:y+A}}else return v("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:b+i.prefix.length,end:y+i.prefix.length}}});v("insertHeader",`Final result: text="${g.text}", cursor=${g.selectionStart}-${g.selectionEnd}`),v("insertHeader","============ END ============"),$(o,g)}function ue(o){Q(o,1,!0)}function he(o){Q(o,2,!0)}function me(o){Q(o,3,!0)}function fe(o){return Qe(o)}var N=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":V(t);break;case"toggleItalic":D(t);break;case"insertLink":q(t);break;case"toggleBulletList":U(t);break;case"toggleNumberedList":W(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(n){console.error("Error in markdown action:",n)}}}destroy(){}};var I={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"}},ve={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"}},ye={solar:I,cave:ve,light:I,dark:ve};function B(o){return typeof o=="string"?{...ye[o]||ye.solar,name:o}:o}function O(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
+ `)}function be(o,e={}){return{...o,colors:{...o.colors,...e}}}function we(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:a={}}=o,l=Object.keys(a).length>0?`
37
37
  @media (max-width: 640px) {
38
38
  .overtype-wrapper .overtype-input,
39
39
  .overtype-wrapper .overtype-preview {
40
- ${Object.entries(s).map(([c,d])=>`${c.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${d} !important;`).join(`
40
+ ${Object.entries(a).map(([c,d])=>`${c.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${d} !important;`).join(`
41
41
  `)}
42
42
  }
43
43
  }
44
- `:"",l=r&&r.colors?O(r.colors):"";return`
44
+ `:"",s=r&&r.colors?O(r.colors):"";return`
45
45
  /* OverType Editor Styles */
46
46
 
47
47
  /* Middle-ground CSS Reset - Prevent parent styles from leaking in */
@@ -82,9 +82,9 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
82
82
  overflow: visible !important; /* Allow dropdown to overflow container */
83
83
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
84
84
  text-align: left !important;
85
- ${l?`
85
+ ${s?`
86
86
  /* Theme Variables */
87
- ${l}`:""}
87
+ ${s}`:""}
88
88
  }
89
89
 
90
90
  /* Force left alignment for all elements in the editor */
@@ -327,6 +327,14 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
327
327
  font-style: italic !important;
328
328
  }
329
329
 
330
+ /* Strikethrough text */
331
+ .overtype-wrapper .overtype-preview del {
332
+ color: var(--del, #ee964b) !important;
333
+ text-decoration: line-through !important;
334
+ text-decoration-color: var(--del, #ee964b) !important;
335
+ text-decoration-thickness: 1px !important;
336
+ }
337
+
330
338
  /* Inline code */
331
339
  .overtype-wrapper .overtype-preview code {
332
340
  background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important;
@@ -470,10 +478,10 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
470
478
  height: 8px !important;
471
479
  background: #4caf50 !important;
472
480
  border-radius: 50% !important;
473
- animation: pulse 2s infinite !important;
481
+ animation: overtype-pulse 2s infinite !important;
474
482
  }
475
483
 
476
- @keyframes pulse {
484
+ @keyframes overtype-pulse {
477
485
  0%, 100% { opacity: 1; transform: scale(1); }
478
486
  50% { opacity: 0.6; transform: scale(1.2); }
479
487
  }
@@ -481,19 +489,19 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
481
489
 
482
490
  /* Toolbar Styles */
483
491
  .overtype-toolbar {
484
- display: flex;
485
- align-items: center;
486
- gap: 4px;
492
+ display: flex !important;
493
+ align-items: center !important;
494
+ gap: 4px !important;
487
495
  padding: 8px !important; /* Override reset */
488
496
  background: var(--toolbar-bg, var(--bg-primary, #f8f9fa)) !important; /* Override reset */
489
497
  overflow-x: auto !important; /* Allow horizontal scrolling */
490
498
  overflow-y: hidden !important; /* Hide vertical overflow */
491
- -webkit-overflow-scrolling: touch;
492
- flex-shrink: 0;
499
+ -webkit-overflow-scrolling: touch !important;
500
+ flex-shrink: 0 !important;
493
501
  height: auto !important;
494
502
  grid-row: 1 !important; /* Always first row in grid */
495
503
  position: relative !important; /* Override reset */
496
- z-index: 100; /* Ensure toolbar is above wrapper */
504
+ z-index: 100 !important; /* Ensure toolbar is above wrapper */
497
505
  scrollbar-width: thin; /* Thin scrollbar on Firefox */
498
506
  }
499
507
 
@@ -806,7 +814,7 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
806
814
  height: 2px !important;
807
815
  }
808
816
 
809
- ${a}
817
+ ${l}
810
818
  `}var ke=`<svg viewBox="0 0 18 18">
811
819
  <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>
812
820
  <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>
@@ -828,14 +836,14 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
828
836
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline>
829
837
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline>
830
838
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
831
- </svg>`,Ae=`<svg viewBox="0 0 18 18">
839
+ </svg>`,Me=`<svg viewBox="0 0 18 18">
832
840
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
833
841
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
834
842
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
835
843
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line>
836
844
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line>
837
845
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line>
838
- </svg>`,Me=`<svg viewBox="0 0 18 18">
846
+ </svg>`,Ae=`<svg viewBox="0 0 18 18">
839
847
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line>
840
848
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line>
841
849
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line>
@@ -856,35 +864,38 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
856
864
  </svg>`,Ie=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
857
865
  <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path>
858
866
  <circle cx="12" cy="12" r="3" fill="none"></circle>
859
- </svg>`;var K=class{constructor(e){this.editor=e,this.container=null,this.buttons={}}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Text formatting"),[{name:"bold",icon:ke,title:"Bold (Ctrl+B)",action:"toggleBold"},{name:"italic",icon:xe,title:"Italic (Ctrl+I)",action:"toggleItalic"},{separator:!0},{name:"h1",icon:Le,title:"Heading 1",action:"insertH1"},{name:"h2",icon:Se,title:"Heading 2",action:"insertH2"},{name:"h3",icon:Ce,title:"Heading 3",action:"insertH3"},{separator:!0},{name:"link",icon:Ee,title:"Insert Link (Ctrl+K)",action:"insertLink"},{name:"code",icon:Te,title:"Code (Ctrl+`)",action:"toggleCode"},{separator:!0},{name:"quote",icon:He,title:"Quote",action:"toggleQuote"},{separator:!0},{name:"bulletList",icon:Ae,title:"Bullet List",action:"toggleBulletList"},{name:"orderedList",icon:Me,title:"Numbered List",action:"toggleNumberedList"},{name:"taskList",icon:$e,title:"Task List",action:"toggleTaskList"},{separator:!0},{name:"viewMode",icon:Ie,title:"View mode",action:"toggle-view-menu",hasDropdown:!0}].forEach(i=>{if(i.separator){let r=document.createElement("div");r.className="overtype-toolbar-separator",r.setAttribute("role","separator"),this.container.appendChild(r)}else{let r=this.createButton(i);this.buttons[i.name]=r,this.container.appendChild(r)}});let t=this.editor.element.querySelector(".overtype-container"),n=this.editor.element.querySelector(".overtype-wrapper");return t&&n&&t.insertBefore(this.container,n),this.container}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.title=e.title,t.setAttribute("aria-label",e.title),t.setAttribute("data-action",e.action),t.innerHTML=e.icon,e.hasDropdown&&(t.classList.add("has-dropdown"),e.name==="viewMode"&&(this.viewModeButton=t)),t.addEventListener("click",n=>{n.preventDefault(),this.handleAction(e.action,t)}),t}async handleAction(e,t){let n=this.editor.textarea;if(n){if(e==="toggle-view-menu"){this.toggleViewDropdown(t);return}n.focus();try{switch(e){case"toggleBold":V(n);break;case"toggleItalic":D(n);break;case"insertH1":ue(n);break;case"insertH2":he(n);break;case"insertH3":me(n);break;case"insertLink":q(n);break;case"toggleCode":ce(n);break;case"toggleBulletList":U(n);break;case"toggleNumberedList":W(n);break;case"toggleQuote":pe(n);break;case"toggleTaskList":de(n);break;case"toggle-plain":let i=this.editor.container.classList.contains("plain-mode");this.editor.showPlainTextarea(!i);break}n.dispatchEvent(new Event("input",{bubbles:!0}))}catch(i){console.error("Error loading markdown-actions:",i)}}}async updateButtonStates(){let e=this.editor.textarea;if(e)try{let t=fe(e);Object.entries(this.buttons).forEach(([n,i])=>{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"quote":r=t.includes("quote");break;case"taskList":r=t.includes("task-list");break;case"h1":r=t.includes("header");break;case"h2":r=t.includes("header-2");break;case"h3":r=t.includes("header-3");break;case"togglePlain":r=!this.editor.container.classList.contains("plain-mode");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(t){}}toggleViewDropdown(e){let t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick);return}let n=this.createViewDropdown(),i=e.getBoundingClientRect();n.style.top=`${i.bottom+4}px`,n.style.left=`${i.left}px`,document.body.appendChild(n),e.classList.add("dropdown-active"),this.handleDocumentClick=r=>{!e.contains(r.target)&&!n.contains(r.target)&&(n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewDropdown(){let e=document.createElement("div");e.className="overtype-dropdown-menu";let t=this.editor.container.classList.contains("plain-mode"),i=this.editor.container.classList.contains("preview-mode")?"preview":t?"plain":"normal";return[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}].forEach(s=>{let a=document.createElement("button");a.className="overtype-dropdown-item",a.type="button";let l=document.createElement("span");l.className="overtype-dropdown-check",l.textContent=i===s.id?s.icon:"";let c=document.createElement("span");c.textContent=s.label,a.appendChild(l),a.appendChild(c),i===s.id&&a.classList.add("active"),a.addEventListener("click",d=>{d.stopPropagation(),this.setViewMode(s.id),e.remove(),this.viewModeButton.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),e.appendChild(a)}),e}setViewMode(e){switch(this.editor.container.classList.remove("plain-mode","preview-mode"),e){case"plain":this.editor.showPlainTextarea(!0);break;case"preview":this.editor.showPreviewMode(!0);break;case"normal":default:this.editor.showPlainTextarea(!1),typeof this.editor.showPreviewMode=="function"&&this.editor.showPreviewMode(!1);break}}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),this.container.remove(),this.container=null,this.buttons={})}};var Z=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.init()}init(){CSS.supports("position-anchor: --x")&&CSS.supports("position-area: center")&&(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.hide()),this.tooltip.addEventListener("mouseenter",()=>this.cancelHide()),this.tooltip.addEventListener("mouseleave",()=>this.scheduleHide()))}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip";let e=document.createElement("style");e.textContent=`
867
+ </svg>`;var K=class{constructor(e,t=null){this.editor=e,this.container=null,this.buttons={},this.buttonConfig=t}isInsideLink(e){let t=e.value,n=e.selectionStart,i=e.selectionEnd,r=!1,a=-1,l=-1;for(let s=n-1;s>=0;s--){if(t[s]==="["){a=s;break}if(t[s]===`
868
+ `)break}if(a>=0)for(let s=i;s<t.length-1;s++){if(t[s]==="]"&&t[s+1]==="("){l=s;break}if(t[s]===`
869
+ `)break}if(a>=0&&l>=0)for(let s=l+2;s<t.length;s++){if(t[s]===")"){r=!0;break}if(t[s]===`
870
+ `||t[s]===" ")break}return r}create(){var i;this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Text formatting"),((i=this.buttonConfig)!=null?i:[{name:"bold",icon:ke,title:"Bold (Ctrl+B)",action:"toggleBold"},{name:"italic",icon:xe,title:"Italic (Ctrl+I)",action:"toggleItalic"},{separator:!0},{name:"h1",icon:Le,title:"Heading 1",action:"insertH1"},{name:"h2",icon:Se,title:"Heading 2",action:"insertH2"},{name:"h3",icon:Ce,title:"Heading 3",action:"insertH3"},{separator:!0},{name:"link",icon:Ee,title:"Insert Link (Ctrl+K)",action:"insertLink"},{name:"code",icon:Te,title:"Code (Ctrl+`)",action:"toggleCode"},{separator:!0},{name:"quote",icon:He,title:"Quote",action:"toggleQuote"},{separator:!0},{name:"bulletList",icon:Me,title:"Bullet List",action:"toggleBulletList"},{name:"orderedList",icon:Ae,title:"Numbered List",action:"toggleNumberedList"},{name:"taskList",icon:$e,title:"Task List",action:"toggleTaskList"},{separator:!0},{name:"viewMode",icon:Ie,title:"View mode",action:"toggle-view-menu",hasDropdown:!0}]).forEach(r=>{if(r.separator){let a=document.createElement("div");a.className="overtype-toolbar-separator",a.setAttribute("role","separator"),this.container.appendChild(a)}else{let a=this.createButton(r);this.buttons[r.name]=a,this.container.appendChild(a)}});let t=this.editor.element.querySelector(".overtype-container"),n=this.editor.element.querySelector(".overtype-wrapper");return t&&n&&t.insertBefore(this.container,n),this.container}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.title=e.title,t.setAttribute("aria-label",e.title),t.setAttribute("data-action",e.action),t.innerHTML=e.icon,e.hasDropdown&&(t.classList.add("has-dropdown"),e.name==="viewMode"&&(this.viewModeButton=t)),t.addEventListener("click",n=>{n.preventDefault(),this.handleAction(e.action,t)}),t}async handleAction(e,t){let n=this.editor.textarea;if(n){if(e==="toggle-view-menu"){this.toggleViewDropdown(t);return}n.focus();try{switch(e){case"toggleBold":V(n);break;case"toggleItalic":D(n);break;case"insertH1":ue(n);break;case"insertH2":he(n);break;case"insertH3":me(n);break;case"insertLink":q(n);break;case"toggleCode":if(this.isInsideLink(n))return;ce(n);break;case"toggleBulletList":U(n);break;case"toggleNumberedList":W(n);break;case"toggleQuote":pe(n);break;case"toggleTaskList":de(n);break;case"toggle-plain":let i=this.editor.container.classList.contains("plain-mode");this.editor.showPlainTextarea(!i);break}n.dispatchEvent(new Event("input",{bubbles:!0}))}catch(i){console.error("Error loading markdown-actions:",i)}}}async updateButtonStates(){let e=this.editor.textarea;if(e)try{let t=fe(e);Object.entries(this.buttons).forEach(([n,i])=>{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"quote":r=t.includes("quote");break;case"taskList":r=t.includes("task-list");break;case"h1":r=t.includes("header");break;case"h2":r=t.includes("header-2");break;case"h3":r=t.includes("header-3");break;case"togglePlain":r=!this.editor.container.classList.contains("plain-mode");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(t){}}toggleViewDropdown(e){let t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick);return}let n=this.createViewDropdown(),i=e.getBoundingClientRect();n.style.top=`${i.bottom+4}px`,n.style.left=`${i.left}px`,document.body.appendChild(n),e.classList.add("dropdown-active"),this.handleDocumentClick=r=>{!e.contains(r.target)&&!n.contains(r.target)&&(n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewDropdown(){let e=document.createElement("div");e.className="overtype-dropdown-menu";let t=this.editor.container.classList.contains("plain-mode"),i=this.editor.container.classList.contains("preview-mode")?"preview":t?"plain":"normal";return[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}].forEach(a=>{let l=document.createElement("button");l.className="overtype-dropdown-item",l.type="button";let s=document.createElement("span");s.className="overtype-dropdown-check",s.textContent=i===a.id?a.icon:"";let c=document.createElement("span");c.textContent=a.label,l.appendChild(s),l.appendChild(c),i===a.id&&l.classList.add("active"),l.addEventListener("click",d=>{d.stopPropagation(),this.setViewMode(a.id),e.remove(),this.viewModeButton.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),e.appendChild(l)}),e}setViewMode(e){switch(this.editor.container.classList.remove("plain-mode","preview-mode"),e){case"plain":this.editor.showPlainTextarea(!0);break;case"preview":this.editor.showPreviewMode(!0);break;case"normal":default:this.editor.showPlainTextarea(!1),typeof this.editor.showPreviewMode=="function"&&this.editor.showPreviewMode(!1);break}}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),this.container.remove(),this.container=null,this.buttons={})}};var Z=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.init()}init(){CSS.supports("position-anchor: --x")&&CSS.supports("position-area: center")&&(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.hide()),this.tooltip.addEventListener("mouseenter",()=>this.cancelHide()),this.tooltip.addEventListener("mouseleave",()=>this.scheduleHide()))}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip";let e=document.createElement("style");e.textContent=`
860
871
  @supports (position-anchor: --x) and (position-area: center) {
861
872
  .overtype-link-tooltip {
862
873
  position: absolute;
863
874
  position-anchor: var(--target-anchor, --link-0);
864
875
  position-area: block-end center;
865
- margin-top: 8px;
876
+ margin-top: 8px !important;
866
877
 
867
- background: #333;
868
- color: white;
869
- padding: 6px 10px;
870
- border-radius: 16px;
871
- font-size: 12px;
872
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
873
- display: none;
874
- z-index: 10000;
875
- cursor: pointer;
876
- box-shadow: 0 2px 8px rgba(0,0,0,0.3);
877
- max-width: 300px;
878
- white-space: nowrap;
879
- overflow: hidden;
880
- text-overflow: ellipsis;
878
+ background: #333 !important;
879
+ color: white !important;
880
+ padding: 6px 10px !important;
881
+ border-radius: 16px !important;
882
+ font-size: 12px !important;
883
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
884
+ display: none !important;
885
+ z-index: 10000 !important;
886
+ cursor: pointer !important;
887
+ box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
888
+ max-width: 300px !important;
889
+ white-space: nowrap !important;
890
+ overflow: hidden !important;
891
+ text-overflow: ellipsis !important;
881
892
 
882
893
  position-try: most-width block-end inline-end, flip-inline, block-start center;
883
894
  position-visibility: anchors-visible;
884
895
  }
885
896
 
886
897
  .overtype-link-tooltip.visible {
887
- display: flex;
898
+ display: flex !important;
888
899
  }
889
900
  }
890
901
  `,document.head.appendChild(e),this.tooltip.innerHTML=`
@@ -895,26 +906,31 @@ ${a}`:r;if(c){let x=o.value[o.selectionStart-1];o.selectionStart!==0&&x!=null&&!
895
906
  </svg>
896
907
  <span class="overtype-link-tooltip-url"></span>
897
908
  </span>
898
- `,this.tooltip.addEventListener("click",t=>{t.preventDefault(),t.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.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null}};var b=class b{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(b.prototype);return s._init(r,t),r.overTypeInstance=s,b.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++b.instanceCount,this.initialized=!1,b.injectStyles(),b.initGlobalListeners();let n=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");n||i?this._recoverFromDOM(n,i):this._buildFromScratch(),this.shortcuts=new N(this),this.linkTooltip=new Z(this),this.options.toolbar&&(this.toolbar=new K(this),this.toolbar.create(),this.textarea.addEventListener("selectionchange",()=>{this.toolbar.updateButtonStates()}),this.textarea.addEventListener("input",()=>{this.toolbar.updateButtonStates()})),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,statsFormatter:null,smartLists:!0},{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||b.currentTheme||I,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=O(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||b.currentTheme||I,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=O(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")}_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.updatePreview()}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,n=this._getCurrentLine(e,t),i=L.parse(e,n,this.options.showActiveLineRaw);this.preview.innerHTML=i||'<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(`
899
- `).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),l=r.substring(i),d=a.split(`
909
+ `,this.tooltip.addEventListener("click",t=>{t.preventDefault(),t.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 a=i.index,l=i.index+i[0].length;if(t>=a&&t<=l)return{text:i[1],url:i[2],index:r,start:a,end:l};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.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null}};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 a=Object.create(w.prototype);return a._init(r,t),r.overTypeInstance=a,w.instances.set(r,a),a})}_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");if(n||i?this._recoverFromDOM(n,i):this._buildFromScratch(),this.shortcuts=new N(this),this.linkTooltip=new Z(this),this.options.toolbar){let r=typeof this.options.toolbar=="object"?this.options.toolbar.buttons:null;this.toolbar=new K(this,r),this.toolbar.create(),this.textarea.addEventListener("selectionchange",()=>{this.toolbar.updateButtonStates()}),this.textarea.addEventListener("input",()=>{this.toolbar.updateButtonStates()})}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,statsFormatter:null,smartLists:!0},{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||I,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 a=O(r.colors);this.container.style.cssText+=a}}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||I,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=O(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")}_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.updatePreview()}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,n=this._getCurrentLine(e,t),i=L.parse(e,n,this.options.showActiveLineRaw);this.preview.innerHTML=i||'<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,a=i.parentElement;!r||!a||(n.style.display="block",i.style.display="block",r.classList.add("code-block-line"),a.classList.add("code-block-line"))}}_getCurrentLine(e,t){return e.substring(0,t).split(`
910
+ `).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 a=r.substring(0,n),l=r.substring(n,i),s=r.substring(i),d=l.split(`
900
911
  `).map(p=>p.replace(/^ /,"")).join(`
901
- `);document.execCommand?(this.textarea.setSelectionRange(n,i),document.execCommand("insertText",!1,d)):(this.textarea.value=s+d+l,this.textarea.selectionStart=n,this.textarea.selectionEnd=n+d.length)}else if(n!==i){let s=r.substring(0,n),a=r.substring(n,i),l=r.substring(i),d=a.split(`
912
+ `);document.execCommand?(this.textarea.setSelectionRange(n,i),document.execCommand("insertText",!1,d)):(this.textarea.value=a+d+s,this.textarea.selectionStart=n,this.textarea.selectionEnd=n+d.length)}else if(n!==i){let a=r.substring(0,n),l=r.substring(n,i),s=r.substring(i),d=l.split(`
902
913
  `).map(p=>" "+p).join(`
903
- `);document.execCommand?(this.textarea.setSelectionRange(n,i),document.execCommand("insertText",!1,d)):(this.textarea.value=s+d+l,this.textarea.selectionStart=n,this.textarea.selectionEnd=n+d.length)}else document.execCommand?document.execCommand("insertText",!1," "):(this.textarea.value=r.substring(0,n)+" "+r.substring(i),this.textarea.selectionStart=this.textarea.selectionEnd=n+2);this.textarea.dispatchEvent(new Event("input",{bubbles:!0}));return}if(e.key==="Enter"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&this.options.smartLists&&this.handleSmartListContinuation()){e.preventDefault();return}!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}handleSmartListContinuation(){let e=this.textarea,t=e.selectionStart,n=L.getListContext(e.value,t);return!n||!n.inList?!1:n.content.trim()===""&&t>=n.markerEndPos?(this.deleteListMarker(n),!0):(t>n.markerEndPos&&t<n.lineEnd?this.splitListItem(n,t):this.insertNewListItem(n),n.listType==="numbered"&&this.scheduleNumberedListUpdate(),!0)}deleteListMarker(e){this.textarea.setSelectionRange(e.lineStart,e.markerEndPos),document.execCommand("delete"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}insertNewListItem(e){let t=L.createNewListItem(e);document.execCommand("insertText",!1,`
914
+ `);document.execCommand?(this.textarea.setSelectionRange(n,i),document.execCommand("insertText",!1,d)):(this.textarea.value=a+d+s,this.textarea.selectionStart=n,this.textarea.selectionEnd=n+d.length)}else document.execCommand?document.execCommand("insertText",!1," "):(this.textarea.value=r.substring(0,n)+" "+r.substring(i),this.textarea.selectionStart=this.textarea.selectionEnd=n+2);this.textarea.dispatchEvent(new Event("input",{bubbles:!0}));return}if(e.key==="Enter"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&this.options.smartLists&&this.handleSmartListContinuation()){e.preventDefault();return}!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}handleSmartListContinuation(){let e=this.textarea,t=e.selectionStart,n=L.getListContext(e.value,t);return!n||!n.inList?!1:n.content.trim()===""&&t>=n.markerEndPos?(this.deleteListMarker(n),!0):(t>n.markerEndPos&&t<n.lineEnd?this.splitListItem(n,t):this.insertNewListItem(n),n.listType==="numbered"&&this.scheduleNumberedListUpdate(),!0)}deleteListMarker(e){this.textarea.setSelectionRange(e.lineStart,e.markerEndPos),document.execCommand("delete"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}insertNewListItem(e){let t=L.createNewListItem(e);document.execCommand("insertText",!1,`
904
915
  `+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=L.createNewListItem(e);document.execCommand("insertText",!1,`
905
916
  `+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=L.renumberLists(e);if(n!==e){let i=0,r=e.split(`
906
- `),s=n.split(`
907
- `),a=0;for(let c=0;c<r.length&&a<t;c++){if(r[c]!==s[c]){let d=s[c].length-r[c].length;a+r[c].length<t&&(i+=d)}a+=r[c].length+1}this.textarea.value=n;let l=t+i;this.textarea.setSelectionRange(l,l),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}}handleScroll(e){this.preview.scrollTop=this.textarea.scrollTop,this.preview.scrollLeft=this.textarea.scrollLeft}getValue(){return this.textarea.value}setValue(e){this.textarea.value=e,this.updatePreview(),this.options.autoResize&&this._updateAutoHeight()}getRenderedHTML(e=!1){let t=this.getValue(),n=L.parse(t);return e&&(n=L.postProcessHTML(n)),n}getPreviewHTML(){return this.preview.innerHTML}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()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,t=e.split(`
908
- `),n=e.length,i=e.split(/\s+/).filter(d=>d.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
909
- `),l=a.length,c=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:n,words:i,lines:t.length,line:l,column:c}):this.statsBar.innerHTML=`
917
+ `),a=n.split(`
918
+ `),l=0;for(let c=0;c<r.length&&l<t;c++){if(r[c]!==a[c]){let d=a[c].length-r[c].length;l+r[c].length<t&&(i+=d)}l+=r[c].length+1}this.textarea.value=n;let s=t+i;this.textarea.setSelectionRange(s,s),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=L.parse(t);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()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,t=e.split(`
919
+ `),n=e.length,i=e.split(/\s+/).filter(d=>d.length>0).length,r=this.textarea.selectionStart,l=e.substring(0,r).split(`
920
+ `),s=l.length,c=l[l.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:n,words:i,lines:t.length,line:s,column:c}):this.statsBar.innerHTML=`
910
921
  <div class="overtype-stat">
911
922
  <span class="live-dot"></span>
912
923
  <span>${n} chars, ${i} words, ${t.length} lines</span>
913
924
  </div>
914
- <div class="overtype-stat">Line ${l}, Col ${c}</div>
915
- `}_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 l=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);l=Math.max(l,p)}let c="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);l>p&&(l=p,c="auto")}let d=l+"px";e.style.setProperty("height",d,"important"),e.style.setProperty("overflow-y",c,"important"),t.style.setProperty("height",d,"important"),t.style.setProperty("overflow-y",c,"important"),n.style.setProperty("height",d,"important"),e.scrollTop=a,t.scrollTop=a,this.previousHeight!==l&&(this.previousHeight=l)}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)}showPlainTextarea(e){if(e?this.container.classList.add("plain-mode"):this.container.classList.remove("plain-mode"),this.toolbar){let t=this.container.querySelector('[data-action="toggle-plain"]');t&&(t.classList.toggle("active",!e),t.title=e?"Show markdown preview":"Show plain textarea")}return e}showPreviewMode(e){return e?this.container.classList.add("preview-mode"):this.container.classList.remove("preview-mode"),e}destroy(){if(this.element.overTypeInstance=null,b.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 b(e,t)}static getInstance(e){return e.overTypeInstance||b.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let n=b.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(b.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=b.currentTheme||I,i=be({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),b.stylesInjected=!0}static setTheme(e,t=null){let n=typeof e=="string"?P(e):e;t&&(n=we(n,t)),b.currentTheme=n,b.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(i=>{let r=typeof n=="string"?n:n.name;r&&i.setAttribute("data-theme",r)}),document.querySelectorAll(".overtype-wrapper").forEach(i=>{if(!i.closest(".overtype-container")){let s=typeof n=="string"?n:n.name;s&&i.setAttribute("data-theme",s)}let r=i._instance;r&&r.updatePreview()})}static initGlobalListeners(){b.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))}}),b.globalListenersInitialized=!0)}};H(b,"instances",new WeakMap),H(b,"stylesInjected",!1),H(b,"globalListenersInitialized",!1),H(b,"instanceCount",0);var C=b;C.MarkdownParser=L;C.ShortcutsManager=N;C.themes={solar:I,cave:P("cave")};C.getTheme=P;C.currentTheme=I;typeof window<"u"&&typeof window.document<"u"&&(window.OverType=C);var Xe=C;return Re(Ye);})();
925
+ <div class="overtype-stat">Line ${s}, Col ${c}</div>
926
+ `}_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),a=parseFloat(i.paddingBottom),l=e.scrollTop;e.style.setProperty("height","auto","important");let s=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);s=Math.max(s,p)}let c="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);s>p&&(s=p,c="auto")}let d=s+"px";e.style.setProperty("height",d,"important"),e.style.setProperty("overflow-y",c,"important"),t.style.setProperty("height",d,"important"),t.style.setProperty("overflow-y",c,"important"),n.style.setProperty("height",d,"important"),e.scrollTop=l,t.scrollTop=l,this.previousHeight!==s&&(this.previousHeight=s)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showPlainTextarea(e){if(e?this.container.classList.add("plain-mode"):this.container.classList.remove("plain-mode"),this.toolbar){let t=this.container.querySelector('[data-action="toggle-plain"]');t&&(t.classList.toggle("active",!e),t.title=e?"Show markdown preview":"Show plain textarea")}return e}showPreviewMode(e){return e?this.container.classList.add("preview-mode"):this.container.classList.remove("preview-mode"),e}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||I,i=we({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=be(n,t)),w.currentTheme=n,w.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(i=>{let r=typeof n=="string"?n:n.name;r&&i.setAttribute("data-theme",r)}),document.querySelectorAll(".overtype-wrapper").forEach(i=>{if(!i.closest(".overtype-container")){let a=typeof n=="string"?n:n.name;a&&i.setAttribute("data-theme",a)}let r=i._instance;r&&r.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)}};H(w,"instances",new WeakMap),H(w,"stylesInjected",!1),H(w,"globalListenersInitialized",!1),H(w,"instanceCount",0);var M=w;M.MarkdownParser=L;M.ShortcutsManager=N;M.themes={solar:I,cave:B("cave")};M.getTheme=B;M.currentTheme=I;var Xe=M;return Re(Ye);})();
916
927
  /**
917
928
  * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
918
929
  * @version 1.0.0
919
930
  * @license MIT
920
931
  */
932
+
933
+ if (typeof window !== "undefined" && typeof window.document !== "undefined") {
934
+ window.OverType = OverType.default ? OverType.default : OverType;
935
+ }
936
+
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "overtype",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
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",
7
7
  "browser": "dist/overtype.min.js",
8
+ "types": "dist/overtype.d.ts",
8
9
  "unpkg": "dist/overtype.min.js",
9
10
  "jsdelivr": "dist/overtype.min.js",
10
11
  "exports": {
@@ -20,12 +21,13 @@
20
21
  "build:prod": "npm test && npm run build",
21
22
  "dev": "http-server -p 8080 -c-1",
22
23
  "watch": "node build.js --watch",
23
- "test": "node test/overtype.test.js && node test/preview-mode.test.js && node test/links.test.js && node test/api-methods.test.js && node test/comprehensive-alignment.test.js",
24
+ "test": "node test/overtype.test.js && node test/preview-mode.test.js && node test/links.test.js && node test/api-methods.test.js && node test/comprehensive-alignment.test.js && npm run test:types",
24
25
  "test:main": "node test/overtype.test.js",
25
26
  "test:preview": "node test/preview-mode.test.js",
26
27
  "test:links": "node test/links.test.js",
27
28
  "test:api": "node test/api-methods.test.js",
28
29
  "test:alignment": "node test/comprehensive-alignment.test.js",
30
+ "test:types": "tsc --noEmit test-types.ts",
29
31
  "preversion": "npm test",
30
32
  "size": "gzip-size dist/overtype.min.js",
31
33
  "serve": "http-server -p 8080 -c-1"
@@ -58,29 +58,29 @@ export class LinkTooltip {
58
58
  position: absolute;
59
59
  position-anchor: var(--target-anchor, --link-0);
60
60
  position-area: block-end center;
61
- margin-top: 8px;
61
+ margin-top: 8px !important;
62
62
 
63
- background: #333;
64
- color: white;
65
- padding: 6px 10px;
66
- border-radius: 16px;
67
- font-size: 12px;
68
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
69
- display: none;
70
- z-index: 10000;
71
- cursor: pointer;
72
- box-shadow: 0 2px 8px rgba(0,0,0,0.3);
73
- max-width: 300px;
74
- white-space: nowrap;
75
- overflow: hidden;
76
- text-overflow: ellipsis;
63
+ background: #333 !important;
64
+ color: white !important;
65
+ padding: 6px 10px !important;
66
+ border-radius: 16px !important;
67
+ font-size: 12px !important;
68
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
69
+ display: none !important;
70
+ z-index: 10000 !important;
71
+ cursor: pointer !important;
72
+ box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
73
+ max-width: 300px !important;
74
+ white-space: nowrap !important;
75
+ overflow: hidden !important;
76
+ text-overflow: ellipsis !important;
77
77
 
78
78
  position-try: most-width block-end inline-end, flip-inline, block-start center;
79
79
  position-visibility: anchors-visible;
80
80
  }
81
81
 
82
82
  .overtype-link-tooltip.visible {
83
- display: flex;
83
+ display: flex !important;
84
84
  }
85
85
  }
86
86
  `;