overtype 1.0.6 → 1.1.1

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,34 +1,34 @@
1
1
  /**
2
- * OverType v1.0.6
2
+ * OverType v1.1.0
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 _=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Me=Object.prototype.hasOwnProperty;var Oe=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var je=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},Ne=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ie(e))!Me.call(n,r)&&r!==t&&_(n,r,{get:()=>e[r],enumerable:!(o=He(e,r))||o.enumerable});return n};var _e=n=>Ne(_({},"__esModule",{value:!0}),n);var I=(n,e,t)=>(Oe(n,typeof e!="symbol"?e+"":e,t),t);var Ge={};je(Ge,{OverType:()=>A,default:()=>Qe});var M=class{static escapeHtml(e){let t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,o=>t[o])}static preserveIndentation(e,t){let r=t.match(/^(\s*)/)[1].replace(/ /g,"&nbsp;");return e.replace(/^\s*/,r)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,o,r)=>{let i=o.length;return`<span class="header ${["h1","h2","h3"][i-1]}"><span class="syntax-marker">${o}</span> ${r}</span>`})}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,o)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${o}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*])\s(.+)$/,(t,o,r,i)=>`${o}<span class="syntax-marker">${r}</span> ${i}`)}static parseNumberedList(e){return e.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/,(t,o,r,i)=>`${o}<span class="syntax-marker">${r}</span> ${i}`)}static parseCodeBlock(e){return e.startsWith("```")?`<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(/`(.+?)`/g,'<code><span class="syntax-marker">`</span>$1<span class="syntax-marker">`</span></code>')}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,'<a href="$2"><span class="syntax-marker">[</span>$1<span class="syntax-marker">](</span><span class="syntax-marker">$2</span><span class="syntax-marker">)</span></a>')}static parseInlineElements(e){let t=e;return t=this.parseInlineCode(t),t=this.parseLinks(t),t=this.parseBold(t),t=this.parseItalic(t),t}static parseLine(e){let t=this.escapeHtml(e);t=this.preserveIndentation(t,e);let o=this.parseHorizontalRule(t);if(o)return o;let r=this.parseCodeBlock(t);return r||(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,o=!1){return e.split(`
9
- `).map((s,a)=>o&&a===t?`<div class="raw-line">${this.escapeHtml(s)||"&nbsp;"}</div>`:this.parseLine(s)).join("")}};var Pe=Object.defineProperty,X=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,Y=(n,e,t)=>e in n?Pe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ee=(n,e)=>{for(var t in e||(e={}))Fe.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))Ve.call(e,t)&&Y(n,t,e[t]);return n},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 ze(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function E(n){return ee(ee({},ze()),n)}var F=!1;function Re(){return F}function g(n,e,t){F&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function P(n,e){if(!F)return;let t=n.value.slice(n.selectionStart,n.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let o=n.value.slice(Math.max(0,n.selectionStart-10),n.selectionStart),r=n.value.slice(n.selectionEnd,Math.min(n.value.length,n.selectionEnd+10));console.log("Context:",JSON.stringify(o)+"[SELECTION]"+JSON.stringify(r)),console.groupEnd()}function re(n){F&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(n.text)),console.log("New selection:",`${n.selectionStart}-${n.selectionEnd}`),console.groupEnd())}var C=null;function $(n,{text:e,selectionStart:t,selectionEnd:o}){let r=Re();r&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",o)),n.focus();let i=n.selectionStart,s=n.selectionEnd,a=n.value.slice(0,i),l=n.value.slice(s);r&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(l.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(n.value.slice(i,s))));let u=n.value,p=i!==s;if(C===null||C===!0){n.contentEditable="true";try{C=document.execCommand("insertText",!1,e),r&&console.log("execCommand returned:",C,"for text with",e.split(`
10
- `).length,"lines")}catch(c){C=!1,r&&console.log("execCommand threw error:",c)}n.contentEditable="false"}if(r&&(console.log("canInsertText before:",C),console.log("execCommand result:",C)),C){let c=a+e+l,f=n.value;r&&(console.log("Expected length:",c.length),console.log("Actual length:",f.length)),f!==c&&r&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(c.slice(0,100))),console.log("Actual:",JSON.stringify(f.slice(0,100))))}if(!C)if(r&&console.log("Using manual insertion"),n.value===u){r&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(c){}n.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(c){}n.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else r&&console.log("Value was changed by execCommand, skipping manual insertion");r&&console.log("Setting selection range:",t,o),t!=null&&o!=null?n.setSelectionRange(t,o):n.setSelectionRange(i,n.selectionEnd),r&&(console.log("Final value length:",n.value.length),console.groupEnd())}function te(n){return n.trim().split(`
11
- `).length>1}function qe(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function De(n,e,t){let o=e,r=t?/\n/:/\s/;for(;n[o]&&!n[o].match(r);)o++;return o}function ie(n){let e=n.value.split(`
12
- `),t=0;for(let o=0;o<e.length;o++){let r=e[o].length+1;n.selectionStart>=t&&n.selectionStart<t+r&&(n.selectionStart=t),n.selectionEnd>=t&&n.selectionEnd<t+r&&(o===e.length-1?n.selectionEnd=Math.min(t+e[o].length,n.value.length):n.selectionEnd=t+r-1),t+=r}}function We(n,e,t,o=!1){if(n.selectionStart===n.selectionEnd)n.selectionStart=qe(n.value,n.selectionStart),n.selectionEnd=De(n.value,n.selectionEnd,o);else{let r=n.selectionStart-e.length,i=n.selectionEnd+t.length,s=n.value.slice(r,n.selectionStart)===e,a=n.value.slice(n.selectionEnd,i)===t;s&&a&&(n.selectionStart=r,n.selectionEnd=i)}return n.value.slice(n.selectionStart,n.selectionEnd)}function Z(n){let e=n.value.slice(0,n.selectionStart),t=n.value.slice(n.selectionEnd),o=e.match(/\n*$/),r=t.match(/^\n*/),i=o?o[0].length:0,s=r?r[0].length:0,a="",l="";return e.match(/\S/)&&i<2&&(a=`
13
- `.repeat(2-i)),t.match(/\S/)&&s<2&&(l=`
14
- `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function V(n,e,t={}){let o=n.selectionStart,r=n.selectionEnd,i=o===r,s=n.value,a=o;for(;a>0&&s[a-1]!==`
15
- `;)a--;if(i){let u=o;for(;u<s.length&&s[u]!==`
16
- `;)u++;n.selectionStart=a,n.selectionEnd=u}else ie(n);let l=e(n);if(t.adjustSelection){let p=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix),c=t.adjustSelection(p,o,r,a);l.selectionStart=c.start,l.selectionEnd=c.end}else if(t.prefix){let p=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix);i?p?(l.selectionStart=Math.max(o-t.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=o+t.prefix.length,l.selectionEnd=l.selectionStart):p?(l.selectionStart=Math.max(o-t.prefix.length,a),l.selectionEnd=Math.max(r-t.prefix.length,a)):(l.selectionStart=o+t.prefix.length,l.selectionEnd=r+t.prefix.length)}return l}function z(n,e){let t,o,{prefix:r,suffix:i,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:u,scanFor:p,surroundWithNewlines:c,trimFirst:f}=e,d=n.selectionStart,v=n.selectionEnd,m=n.value.slice(n.selectionStart,n.selectionEnd),h=te(m)&&s&&s.length>0?`${s}
17
- `:r,b=te(m)&&a&&a.length>0?`
18
- ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!x.match(/\s/)&&(h=` ${h}`)}m=We(n,h,b,e.multiline);let y=n.selectionStart,w=n.selectionEnd,T=l&&l.length>0&&b.indexOf(l)>-1&&m.length>0;if(c){let x=Z(n);t=x.newlinesToAppend,o=x.newlinesToPrepend,h=t+r,b+=o}if(m.startsWith(h)&&m.endsWith(b)){let x=m.slice(h.length,m.length-b.length);if(d===v){let L=d-h.length;L=Math.max(L,y),L=Math.min(L,y+x.length),y=w=L}else w=y+x.length;return{text:x,selectionStart:y,selectionEnd:w}}else if(T)if(p&&p.length>0&&m.match(p)){b=b.replace(l,m);let x=h+b;return y=w=y+h.length,{text:x,selectionStart:y,selectionEnd:w}}else{let x=h+m+b;return y=y+h.length+m.length+b.indexOf(l),w=y+l.length,{text:x,selectionStart:y,selectionEnd:w}}else{let x=h+m+b;y=d+h.length,w=v+h.length;let L=m.match(/^\s*|\s*$/g);if(f&&L){let Q=L[0]||"",G=L[1]||"";x=Q+h+m.trim()+b+G,y+=Q.length,w-=G.length}return{text:x,selectionStart:y,selectionEnd:w}}}function se(n,e){let{prefix:t,suffix:o,surroundWithNewlines:r}=e,i=n.value.slice(n.selectionStart,n.selectionEnd),s=n.selectionStart,a=n.selectionEnd,l=i.split(`
19
- `);if(l.every(p=>p.startsWith(t)&&(!o||p.endsWith(o))))i=l.map(p=>{let c=p.slice(t.length);return o&&(c=c.slice(0,c.length-o.length)),c}).join(`
20
- `),a=s+i.length;else if(i=l.map(p=>t+p+(o||"")).join(`
21
- `),r){let{newlinesToAppend:p,newlinesToPrepend:c}=Z(n);s+=p.length,a=s+i.length,i=p+i+c}return{text:i,selectionStart:s,selectionEnd:a}}function ne(n){let e=n.split(`
22
- `),t=/^\d+\.\s+/,o=e.every(i=>t.test(i)),r=e;return o&&(r=e.map(i=>i.replace(t,""))),{text:r.join(`
23
- `),processed:o}}function oe(n){let e=n.split(`
24
- `),t="- ",o=e.every(i=>i.startsWith(t)),r=e;return o&&(r=e.map(i=>i.slice(t.length))),{text:r.join(`
25
- `),processed:o}}function O(n,e){return e?"- ":`${n+1}. `}function Ke(n,e){let t,o,r;return n.orderedList?(t=ne(e),o=oe(t.text),r=o.text):(t=oe(e),o=ne(t.text),r=o.text),[t,o,r]}function Ue(n,e){let t=n.selectionStart===n.selectionEnd,o=n.selectionStart,r=n.selectionEnd;ie(n);let i=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,l]=Ke(e,i),u=l.split(`
26
- `).map((m,h)=>`${O(h,e.unorderedList)}${m}`),p=u.reduce((m,h,b)=>m+O(b,e.unorderedList).length,0),c=u.reduce((m,h,b)=>m+O(b,!e.unorderedList).length,0);if(s.processed)return t?(o=Math.max(o-O(0,e.unorderedList).length,0),r=o):(o=n.selectionStart,r=n.selectionEnd-p),{text:l,selectionStart:o,selectionEnd:r};let{newlinesToAppend:f,newlinesToPrepend:d}=Z(n),v=f+u.join(`
27
- `)+d;return t?(o=Math.max(o+O(0,e.unorderedList).length+f.length,0),r=o):a.processed?(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+p-c):(o=Math.max(n.selectionStart+f.length,0),r=n.selectionEnd+f.length+p),{text:v,selectionStart:o,selectionEnd:r}}function ae(n,e){let t=V(n,o=>Ue(o,e),{adjustSelection:(o,r,i,s)=>{let a=n.value.slice(s,n.selectionEnd),l=/^\d+\.\s+/,u=/^- /,p=l.test(a),c=u.test(a),f=e.orderedList&&p||e.unorderedList&&c;if(r===i)if(f){let d=a.match(e.orderedList?l:u),v=d?d[0].length:0;return{start:Math.max(r-v,s),end:Math.max(r-v,s)}}else if(p||c){let d=a.match(p?l:u),v=d?d[0].length:0,h=(e.unorderedList?2:3)-v;return{start:r+h,end:r+h}}else{let d=e.unorderedList?2:3;return{start:r+d,end:r+d}}else if(f){let d=a.match(e.orderedList?l:u),v=d?d[0].length:0;return{start:Math.max(r-v,s),end:Math.max(i-v,s)}}else if(p||c){let d=a.match(p?l:u),v=d?d[0].length:0,h=(e.unorderedList?2:3)-v;return{start:r+h,end:i+h}}else{let d=e.unorderedList?2:3;return{start:r+d,end:i+d}}}});$(n,t)}function Ze(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:o,value:r}=n,i=r.split(`
28
- `),s=0,a="";for(let c of i){if(t>=s&&t<=s+c.length){a=c;break}s+=c.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let l=Math.max(0,t-10),u=Math.min(r.length,o+10),p=r.slice(l,u);if(p.includes("**")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=c.lastIndexOf("**"),v=f.indexOf("**");d!==-1&&v!==-1&&e.push("bold")}if(p.includes("_")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=c.lastIndexOf("_"),v=f.indexOf("_");d!==-1&&v!==-1&&e.push("italic")}if(p.includes("`")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100));c.includes("`")&&f.includes("`")&&e.push("code")}if(p.includes("[")&&p.includes("]")){let c=r.slice(Math.max(0,t-100),t),f=r.slice(o,Math.min(r.length,o+100)),d=c.lastIndexOf("["),v=f.indexOf("]");d!==-1&&v!==-1&&r.slice(o+v+1,o+v+10).startsWith("(")&&e.push("link")}return e}function R(n){if(!n||n.disabled||n.readOnly)return;g("toggleBold","Starting"),P(n,"Before");let e=E(S.bold),t=z(n,e);re(t),$(n,t),P(n,"After")}function q(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.italic),t=z(n,e);$(n,t)}function le(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.code),t=z(n,e);$(n,t)}function D(n,e={}){if(!n||n.disabled||n.readOnly)return;let t=n.value.slice(n.selectionStart,n.selectionEnd),o=E(S.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${t})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!t){let s=n.selectionStart;n.value=n.value.slice(0,s)+e.text+n.value.slice(s),n.selectionStart=s,n.selectionEnd=s+e.text.length}let i=z(n,o);$(n,i)}function W(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.bulletList);ae(n,e)}function K(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.numberedList);ae(n,e)}function ce(n){if(!n||n.disabled||n.readOnly)return;g("toggleQuote","Starting"),P(n,"Initial");let e=E(S.quote),t=V(n,o=>se(o,e),{prefix:e.prefix});re(t),$(n,t),P(n,"Final")}function pe(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.taskList),t=V(n,o=>se(o,e),{prefix:e.prefix});$(n,t)}function J(n,e=1,t=!1){if(!n||n.disabled||n.readOnly)return;(e<1||e>6)&&(e=1),g("insertHeader","============ START ============"),g("insertHeader",`Level: ${e}, Toggle: ${t}`),g("insertHeader",`Initial cursor: ${n.selectionStart}-${n.selectionEnd}`);let o=`header${e===1?"1":e}`,r=E(S[o]||S.header1);g("insertHeader",`Style prefix: "${r.prefix}"`);let i=n.value,s=n.selectionStart,a=n.selectionEnd,l=s;for(;l>0&&i[l-1]!==`
29
- `;)l--;let u=a;for(;u<i.length&&i[u]!==`
30
- `;)u++;let p=i.slice(l,u);g("insertHeader",`Current line (before): "${p}"`);let c=p.match(/^(#{1,6})\s*/),f=c?c[1].length:0,d=c?c[0].length:0;g("insertHeader","Existing header check:"),g("insertHeader",` - Match: ${c?`"${c[0]}"`:"none"}`),g("insertHeader",` - Existing level: ${f}`),g("insertHeader",` - Existing prefix length: ${d}`),g("insertHeader",` - Target level: ${e}`);let v=t&&f===e;g("insertHeader",`Should toggle OFF: ${v} (toggle=${t}, existingLevel=${f}, level=${e})`);let m=V(n,h=>{let b=h.value.slice(h.selectionStart,h.selectionEnd);g("insertHeader",`Line in operation: "${b}"`);let y=b.replace(/^#{1,6}\s*/,"");g("insertHeader",`Cleaned line: "${y}"`);let w;return v?(g("insertHeader","ACTION: Toggling OFF - removing header"),w=y):f>0?(g("insertHeader",`ACTION: Replacing H${f} with H${e}`),w=r.prefix+y):(g("insertHeader","ACTION: Adding new header"),w=r.prefix+y),g("insertHeader",`New line: "${w}"`),{text:w,selectionStart:h.selectionStart,selectionEnd:h.selectionEnd}},{prefix:r.prefix,adjustSelection:(h,b,y,w)=>{if(g("insertHeader","Adjusting selection:"),g("insertHeader",` - isRemoving param: ${h}`),g("insertHeader",` - shouldToggleOff: ${v}`),g("insertHeader",` - selStart: ${b}, selEnd: ${y}`),g("insertHeader",` - lineStartPos: ${w}`),v){let T=Math.max(b-d,w);return g("insertHeader",` - Removing header, adjusting by -${d}`),{start:T,end:b===y?T:Math.max(y-d,w)}}else if(d>0){let T=r.prefix.length-d;return g("insertHeader",` - Replacing header, adjusting by ${T}`),{start:b+T,end:y+T}}else return g("insertHeader",` - Adding header, adjusting by +${r.prefix.length}`),{start:b+r.prefix.length,end:y+r.prefix.length}}});g("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),g("insertHeader","============ END ============"),$(n,m)}function de(n){J(n,1,!0)}function ue(n){J(n,2,!0)}function he(n){J(n,3,!0)}function fe(n){return Ze(n)}var j=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 r=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(r="toggleBold");break;case"i":e.shiftKey||(r="toggleItalic");break;case"k":e.shiftKey||(r="insertLink");break;case"7":e.shiftKey&&(r="toggleNumberedList");break;case"8":e.shiftKey&&(r="toggleBulletList");break}return r?(e.preventDefault(),this.editor.toolbar?this.editor.toolbar.handleAction(r):this.handleAction(r),!0):!1}async handleAction(e){let t=this.textarea;if(t){t.focus();try{switch(e){case"toggleBold":R(t);break;case"toggleItalic":q(t);break;case"insertLink":D(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(o){console.error("Error in markdown action:",o)}}}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",toolbarBg:"#ffffff",toolbarBorder:"rgba(13, 59, 102, 0.15)",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca"}},ge={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"}},ve={solar:B,cave:ge,light:B,dark:ge};function H(n){return typeof n=="string"?{...ve[n]||ve.solar,name:n}:n}function N(n){let e=[];for(let[t,o]of Object.entries(n)){let r=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${r}: ${o};`)}return e.join(`
31
- `)}function ye(n,e={}){return{...n,colors:{...n.colors,...e}}}function be(n={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:o="ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace",padding:r="20px",theme:i=null,mobile:s={}}=n,a=Object.keys(s).length>0?`
8
+ var OverType=(()=>{var P=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var Oe=(n,e,t)=>e in n?P(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Ne=(n,e)=>{for(var t in e)P(n,t,{get:e[t],enumerable:!0})},Pe=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Me(e))!je.call(n,i)&&i!==t&&P(n,i,{get:()=>e[i],enumerable:!(o=Be(e,i))||o.enumerable});return n};var _e=n=>Pe(P({},"__esModule",{value:!0}),n);var I=(n,e,t)=>(Oe(n,typeof e!="symbol"?e+"":e,t),t);var Xe={};Ne(Xe,{OverType:()=>A,default:()=>Ge});var B=class{static resetLinkIndex(){this.linkIndex=0}static escapeHtml(e){let t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,o=>t[o])}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,o,i)=>{let r=o.length;return`<span class="header ${["h1","h2","h3"][r-1]}"><span class="syntax-marker">${o}</span> ${i}</span>`})}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,o)=>`<span class="blockquote"><span class="syntax-marker">&gt;</span> ${o}</span>`)}static parseBulletList(e){return e.replace(/^((?:&nbsp;)*)([-*])\s(.+)$/,(t,o,i,r)=>`${o}<span class="syntax-marker">${i}</span> ${r}`)}static parseNumberedList(e){return e.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/,(t,o,i,r)=>`${o}<span class="syntax-marker">${i}</span> ${r}`)}static parseCodeBlock(e){return e.startsWith("```")?`<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(/`(.+?)`/g,'<code><span class="syntax-marker">`</span>$1<span class="syntax-marker">`</span></code>')}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(t,o,i)=>{let r=`--link-${this.linkIndex++}`;return`<a href="${i}" style="anchor-name: ${r}"><span class="syntax-marker">[</span>${o}<span class="syntax-marker">](</span><span class="syntax-marker">${i}</span><span class="syntax-marker">)</span></a>`})}static parseInlineElements(e){let t=e;t=this.parseInlineCode(t);let o=new Map;return t=t.replace(/(<code>.*?<\/code>)/g,i=>{let r=`\uE000${o.size}\uE001`;return o.set(r,i),r}),t=this.parseLinks(t),t=this.parseBold(t),t=this.parseItalic(t),o.forEach((i,r)=>{t=t.replace(r,i)}),t}static parseLine(e){let t=this.escapeHtml(e);t=this.preserveIndentation(t,e);let o=this.parseHorizontalRule(t);if(o)return o;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,o=!1){return this.resetLinkIndex(),e.split(`
9
+ `).map((s,a)=>o&&a===t?`<div class="raw-line">${this.escapeHtml(s)||"&nbsp;"}</div>`:this.parseLine(s)).join("")}};I(B,"linkIndex",0);var Fe=Object.defineProperty,Y=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,ee=(n,e,t)=>e in n?Fe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,te=(n,e)=>{for(var t in e||(e={}))ze.call(e,t)&&ee(n,t,e[t]);if(Y)for(var t of Y(e))Ve.call(e,t)&&ee(n,t,e[t]);return n},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 Re(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function E(n){return te(te({},Re()),n)}var F=!1;function qe(){return F}function g(n,e,t){F&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function _(n,e){if(!F)return;let t=n.value.slice(n.selectionStart,n.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let o=n.value.slice(Math.max(0,n.selectionStart-10),n.selectionStart),i=n.value.slice(n.selectionEnd,Math.min(n.value.length,n.selectionEnd+10));console.log("Context:",JSON.stringify(o)+"[SELECTION]"+JSON.stringify(i)),console.groupEnd()}function re(n){F&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(n.text)),console.log("New selection:",`${n.selectionStart}-${n.selectionEnd}`),console.groupEnd())}var C=null;function $(n,{text:e,selectionStart:t,selectionEnd:o}){let i=qe();i&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",o)),n.focus();let r=n.selectionStart,s=n.selectionEnd,a=n.value.slice(0,r),l=n.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(n.value.slice(r,s))));let u=n.value,p=r!==s;if(C===null||C===!0){n.contentEditable="true";try{C=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",C,"for text with",e.split(`
10
+ `).length,"lines")}catch(c){C=!1,i&&console.log("execCommand threw error:",c)}n.contentEditable="false"}if(i&&(console.log("canInsertText before:",C),console.log("execCommand result:",C)),C){let c=a+e+l,f=n.value;i&&(console.log("Expected length:",c.length),console.log("Actual length:",f.length)),f!==c&&i&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(c.slice(0,100))),console.log("Actual:",JSON.stringify(f.slice(0,100))))}if(!C)if(i&&console.log("Using manual insertion"),n.value===u){i&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(c){}n.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(c){}n.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,o),t!=null&&o!=null?n.setSelectionRange(t,o):n.setSelectionRange(r,n.selectionEnd),i&&(console.log("Final value length:",n.value.length),console.groupEnd())}function ne(n){return n.trim().split(`
11
+ `).length>1}function De(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function We(n,e,t){let o=e,i=t?/\n/:/\s/;for(;n[o]&&!n[o].match(i);)o++;return o}function se(n){let e=n.value.split(`
12
+ `),t=0;for(let o=0;o<e.length;o++){let i=e[o].length+1;n.selectionStart>=t&&n.selectionStart<t+i&&(n.selectionStart=t),n.selectionEnd>=t&&n.selectionEnd<t+i&&(o===e.length-1?n.selectionEnd=Math.min(t+e[o].length,n.value.length):n.selectionEnd=t+i-1),t+=i}}function Ke(n,e,t,o=!1){if(n.selectionStart===n.selectionEnd)n.selectionStart=De(n.value,n.selectionStart),n.selectionEnd=We(n.value,n.selectionEnd,o);else{let i=n.selectionStart-e.length,r=n.selectionEnd+t.length,s=n.value.slice(i,n.selectionStart)===e,a=n.value.slice(n.selectionEnd,r)===t;s&&a&&(n.selectionStart=i,n.selectionEnd=r)}return n.value.slice(n.selectionStart,n.selectionEnd)}function J(n){let e=n.value.slice(0,n.selectionStart),t=n.value.slice(n.selectionEnd),o=e.match(/\n*$/),i=t.match(/^\n*/),r=o?o[0].length:0,s=i?i[0].length:0,a="",l="";return e.match(/\S/)&&r<2&&(a=`
13
+ `.repeat(2-r)),t.match(/\S/)&&s<2&&(l=`
14
+ `.repeat(2-s)),{newlinesToAppend:a,newlinesToPrepend:l}}function z(n,e,t={}){let o=n.selectionStart,i=n.selectionEnd,r=o===i,s=n.value,a=o;for(;a>0&&s[a-1]!==`
15
+ `;)a--;if(r){let u=o;for(;u<s.length&&s[u]!==`
16
+ `;)u++;n.selectionStart=a,n.selectionEnd=u}else se(n);let l=e(n);if(t.adjustSelection){let p=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix),c=t.adjustSelection(p,o,i,a);l.selectionStart=c.start,l.selectionEnd=c.end}else if(t.prefix){let p=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix);r?p?(l.selectionStart=Math.max(o-t.prefix.length,a),l.selectionEnd=l.selectionStart):(l.selectionStart=o+t.prefix.length,l.selectionEnd=l.selectionStart):p?(l.selectionStart=Math.max(o-t.prefix.length,a),l.selectionEnd=Math.max(i-t.prefix.length,a)):(l.selectionStart=o+t.prefix.length,l.selectionEnd=i+t.prefix.length)}return l}function V(n,e){let t,o,{prefix:i,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:l,prefixSpace:u,scanFor:p,surroundWithNewlines:c,trimFirst:f}=e,d=n.selectionStart,v=n.selectionEnd,m=n.value.slice(n.selectionStart,n.selectionEnd),h=ne(m)&&s&&s.length>0?`${s}
17
+ `:i,b=ne(m)&&a&&a.length>0?`
18
+ ${a}`:r;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!x.match(/\s/)&&(h=` ${h}`)}m=Ke(n,h,b,e.multiline);let y=n.selectionStart,w=n.selectionEnd,T=l&&l.length>0&&b.indexOf(l)>-1&&m.length>0;if(c){let x=J(n);t=x.newlinesToAppend,o=x.newlinesToPrepend,h=t+i,b+=o}if(m.startsWith(h)&&m.endsWith(b)){let x=m.slice(h.length,m.length-b.length);if(d===v){let L=d-h.length;L=Math.max(L,y),L=Math.min(L,y+x.length),y=w=L}else w=y+x.length;return{text:x,selectionStart:y,selectionEnd:w}}else if(T)if(p&&p.length>0&&m.match(p)){b=b.replace(l,m);let x=h+b;return y=w=y+h.length,{text:x,selectionStart:y,selectionEnd:w}}else{let x=h+m+b;return y=y+h.length+m.length+b.indexOf(l),w=y+l.length,{text:x,selectionStart:y,selectionEnd:w}}else{let x=h+m+b;y=d+h.length,w=v+h.length;let L=m.match(/^\s*|\s*$/g);if(f&&L){let G=L[0]||"",X=L[1]||"";x=G+h+m.trim()+b+X,y+=G.length,w-=X.length}return{text:x,selectionStart:y,selectionEnd:w}}}function ae(n,e){let{prefix:t,suffix:o,surroundWithNewlines:i}=e,r=n.value.slice(n.selectionStart,n.selectionEnd),s=n.selectionStart,a=n.selectionEnd,l=r.split(`
19
+ `);if(l.every(p=>p.startsWith(t)&&(!o||p.endsWith(o))))r=l.map(p=>{let c=p.slice(t.length);return o&&(c=c.slice(0,c.length-o.length)),c}).join(`
20
+ `),a=s+r.length;else if(r=l.map(p=>t+p+(o||"")).join(`
21
+ `),i){let{newlinesToAppend:p,newlinesToPrepend:c}=J(n);s+=p.length,a=s+r.length,r=p+r+c}return{text:r,selectionStart:s,selectionEnd:a}}function oe(n){let e=n.split(`
22
+ `),t=/^\d+\.\s+/,o=e.every(r=>t.test(r)),i=e;return o&&(i=e.map(r=>r.replace(t,""))),{text:i.join(`
23
+ `),processed:o}}function ie(n){let e=n.split(`
24
+ `),t="- ",o=e.every(r=>r.startsWith(t)),i=e;return o&&(i=e.map(r=>r.slice(t.length))),{text:i.join(`
25
+ `),processed:o}}function j(n,e){return e?"- ":`${n+1}. `}function Ue(n,e){let t,o,i;return n.orderedList?(t=oe(e),o=ie(t.text),i=o.text):(t=ie(e),o=oe(t.text),i=o.text),[t,o,i]}function Ze(n,e){let t=n.selectionStart===n.selectionEnd,o=n.selectionStart,i=n.selectionEnd;se(n);let r=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,l]=Ue(e,r),u=l.split(`
26
+ `).map((m,h)=>`${j(h,e.unorderedList)}${m}`),p=u.reduce((m,h,b)=>m+j(b,e.unorderedList).length,0),c=u.reduce((m,h,b)=>m+j(b,!e.unorderedList).length,0);if(s.processed)return t?(o=Math.max(o-j(0,e.unorderedList).length,0),i=o):(o=n.selectionStart,i=n.selectionEnd-p),{text:l,selectionStart:o,selectionEnd:i};let{newlinesToAppend:f,newlinesToPrepend:d}=J(n),v=f+u.join(`
27
+ `)+d;return t?(o=Math.max(o+j(0,e.unorderedList).length+f.length,0),i=o):a.processed?(o=Math.max(n.selectionStart+f.length,0),i=n.selectionEnd+f.length+p-c):(o=Math.max(n.selectionStart+f.length,0),i=n.selectionEnd+f.length+p),{text:v,selectionStart:o,selectionEnd:i}}function le(n,e){let t=z(n,o=>Ze(o,e),{adjustSelection:(o,i,r,s)=>{let a=n.value.slice(s,n.selectionEnd),l=/^\d+\.\s+/,u=/^- /,p=l.test(a),c=u.test(a),f=e.orderedList&&p||e.unorderedList&&c;if(i===r)if(f){let d=a.match(e.orderedList?l:u),v=d?d[0].length:0;return{start:Math.max(i-v,s),end:Math.max(i-v,s)}}else if(p||c){let d=a.match(p?l:u),v=d?d[0].length:0,h=(e.unorderedList?2:3)-v;return{start:i+h,end:i+h}}else{let d=e.unorderedList?2:3;return{start:i+d,end:i+d}}else if(f){let d=a.match(e.orderedList?l:u),v=d?d[0].length:0;return{start:Math.max(i-v,s),end:Math.max(r-v,s)}}else if(p||c){let d=a.match(p?l:u),v=d?d[0].length:0,h=(e.unorderedList?2:3)-v;return{start:i+h,end:r+h}}else{let d=e.unorderedList?2:3;return{start:i+d,end:r+d}}}});$(n,t)}function Je(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:o,value:i}=n,r=i.split(`
28
+ `),s=0,a="";for(let c of r){if(t>=s&&t<=s+c.length){a=c;break}s+=c.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let l=Math.max(0,t-10),u=Math.min(i.length,o+10),p=i.slice(l,u);if(p.includes("**")){let c=i.slice(Math.max(0,t-100),t),f=i.slice(o,Math.min(i.length,o+100)),d=c.lastIndexOf("**"),v=f.indexOf("**");d!==-1&&v!==-1&&e.push("bold")}if(p.includes("_")){let c=i.slice(Math.max(0,t-100),t),f=i.slice(o,Math.min(i.length,o+100)),d=c.lastIndexOf("_"),v=f.indexOf("_");d!==-1&&v!==-1&&e.push("italic")}if(p.includes("`")){let c=i.slice(Math.max(0,t-100),t),f=i.slice(o,Math.min(i.length,o+100));c.includes("`")&&f.includes("`")&&e.push("code")}if(p.includes("[")&&p.includes("]")){let c=i.slice(Math.max(0,t-100),t),f=i.slice(o,Math.min(i.length,o+100)),d=c.lastIndexOf("["),v=f.indexOf("]");d!==-1&&v!==-1&&i.slice(o+v+1,o+v+10).startsWith("(")&&e.push("link")}return e}function R(n){if(!n||n.disabled||n.readOnly)return;g("toggleBold","Starting"),_(n,"Before");let e=E(S.bold),t=V(n,e);re(t),$(n,t),_(n,"After")}function q(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.italic),t=V(n,e);$(n,t)}function ce(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.code),t=V(n,e);$(n,t)}function D(n,e={}){if(!n||n.disabled||n.readOnly)return;let t=n.value.slice(n.selectionStart,n.selectionEnd),o=E(S.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${t})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!t){let s=n.selectionStart;n.value=n.value.slice(0,s)+e.text+n.value.slice(s),n.selectionStart=s,n.selectionEnd=s+e.text.length}let r=V(n,o);$(n,r)}function W(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.bulletList);le(n,e)}function K(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.numberedList);le(n,e)}function pe(n){if(!n||n.disabled||n.readOnly)return;g("toggleQuote","Starting"),_(n,"Initial");let e=E(S.quote),t=z(n,o=>ae(o,e),{prefix:e.prefix});re(t),$(n,t),_(n,"Final")}function de(n){if(!n||n.disabled||n.readOnly)return;let e=E(S.taskList),t=z(n,o=>ae(o,e),{prefix:e.prefix});$(n,t)}function Q(n,e=1,t=!1){if(!n||n.disabled||n.readOnly)return;(e<1||e>6)&&(e=1),g("insertHeader","============ START ============"),g("insertHeader",`Level: ${e}, Toggle: ${t}`),g("insertHeader",`Initial cursor: ${n.selectionStart}-${n.selectionEnd}`);let o=`header${e===1?"1":e}`,i=E(S[o]||S.header1);g("insertHeader",`Style prefix: "${i.prefix}"`);let r=n.value,s=n.selectionStart,a=n.selectionEnd,l=s;for(;l>0&&r[l-1]!==`
29
+ `;)l--;let u=a;for(;u<r.length&&r[u]!==`
30
+ `;)u++;let p=r.slice(l,u);g("insertHeader",`Current line (before): "${p}"`);let c=p.match(/^(#{1,6})\s*/),f=c?c[1].length:0,d=c?c[0].length:0;g("insertHeader","Existing header check:"),g("insertHeader",` - Match: ${c?`"${c[0]}"`:"none"}`),g("insertHeader",` - Existing level: ${f}`),g("insertHeader",` - Existing prefix length: ${d}`),g("insertHeader",` - Target level: ${e}`);let v=t&&f===e;g("insertHeader",`Should toggle OFF: ${v} (toggle=${t}, existingLevel=${f}, level=${e})`);let m=z(n,h=>{let b=h.value.slice(h.selectionStart,h.selectionEnd);g("insertHeader",`Line in operation: "${b}"`);let y=b.replace(/^#{1,6}\s*/,"");g("insertHeader",`Cleaned line: "${y}"`);let w;return v?(g("insertHeader","ACTION: Toggling OFF - removing header"),w=y):f>0?(g("insertHeader",`ACTION: Replacing H${f} with H${e}`),w=i.prefix+y):(g("insertHeader","ACTION: Adding new header"),w=i.prefix+y),g("insertHeader",`New line: "${w}"`),{text:w,selectionStart:h.selectionStart,selectionEnd:h.selectionEnd}},{prefix:i.prefix,adjustSelection:(h,b,y,w)=>{if(g("insertHeader","Adjusting selection:"),g("insertHeader",` - isRemoving param: ${h}`),g("insertHeader",` - shouldToggleOff: ${v}`),g("insertHeader",` - selStart: ${b}, selEnd: ${y}`),g("insertHeader",` - lineStartPos: ${w}`),v){let T=Math.max(b-d,w);return g("insertHeader",` - Removing header, adjusting by -${d}`),{start:T,end:b===y?T:Math.max(y-d,w)}}else if(d>0){let T=i.prefix.length-d;return g("insertHeader",` - Replacing header, adjusting by ${T}`),{start:b+T,end:y+T}}else return g("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:b+i.prefix.length,end:y+i.prefix.length}}});g("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),g("insertHeader","============ END ============"),$(n,m)}function ue(n){Q(n,1,!0)}function he(n){Q(n,2,!0)}function fe(n){Q(n,3,!0)}function me(n){return Je(n)}var O=class{constructor(e){this.editor=e,this.textarea=e.textarea}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.toolbar?this.editor.toolbar.handleAction(i):this.handleAction(i),!0):!1}async handleAction(e){let t=this.textarea;if(t){t.focus();try{switch(e){case"toggleBold":R(t);break;case"toggleItalic":q(t);break;case"insertLink":D(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(o){console.error("Error in markdown action:",o)}}}destroy(){}};var H={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:H,cave:ve,light:H,dark:ve};function M(n){return typeof n=="string"?{...ye[n]||ye.solar,name:n}:n}function N(n){let e=[];for(let[t,o]of Object.entries(n)){let i=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${i}: ${o};`)}return e.join(`
31
+ `)}function be(n,e={}){return{...n,colors:{...n.colors,...e}}}function ke(n={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:o="ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace",padding:i="20px",theme:r=null,mobile:s={}}=n,a=Object.keys(s).length>0?`
32
32
  @media (max-width: 640px) {
33
33
  .overtype-wrapper .overtype-input,
34
34
  .overtype-wrapper .overtype-preview {
@@ -36,7 +36,7 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
36
36
  `)}
37
37
  }
38
38
  }
39
- `:"",l=i&&i.colors?N(i.colors):"";return`
39
+ `:"",l=r&&r.colors?N(r.colors):"";return`
40
40
  /* OverType Editor Styles */
41
41
  .overtype-container {
42
42
  position: relative !important;
@@ -77,7 +77,7 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
77
77
  font-feature-settings: normal !important;
78
78
 
79
79
  /* Box model - must match exactly */
80
- padding: var(--instance-padding, ${r}) !important;
80
+ padding: var(--instance-padding, ${i}) !important;
81
81
  margin: 0 !important;
82
82
  border: none !important;
83
83
  outline: none !important;
@@ -233,6 +233,8 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
233
233
  padding: 0 !important;
234
234
  border-radius: 2px !important;
235
235
  font-family: inherit !important;
236
+ font-size: inherit !important;
237
+ line-height: inherit !important;
236
238
  font-weight: normal !important;
237
239
  }
238
240
 
@@ -468,35 +470,35 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
468
470
  }
469
471
 
470
472
  ${a}
471
- `}var ke=`<svg viewBox="0 0 18 18">
473
+ `}var we=`<svg viewBox="0 0 18 18">
472
474
  <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>
473
475
  <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>
474
- </svg>`,we=`<svg viewBox="0 0 18 18">
476
+ </svg>`,xe=`<svg viewBox="0 0 18 18">
475
477
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line>
476
478
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line>
477
479
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line>
478
- </svg>`,xe=`<svg viewBox="0 0 18 18">
479
- <path fill="currentColor" d="M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z"></path>
480
480
  </svg>`,Se=`<svg viewBox="0 0 18 18">
481
- <path fill="currentColor" d="M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path>
481
+ <path fill="currentColor" d="M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z"></path>
482
482
  </svg>`,Le=`<svg viewBox="0 0 18 18">
483
- <path fill="currentColor" d="M16.65186,12.30664a2.6742,2.6742,0,0,1-2.915,2.68457,3.96592,3.96592,0,0,1-2.25537-.6709.56007.56007,0,0,1-.13232-.83594L11.64648,13c.209-.34082.48389-.36328.82471-.1543a2.32654,2.32654,0,0,0,1.12256.33008c.71484,0,1.12207-.35156,1.12207-.78125,0-.61523-.61621-.86816-1.46338-.86816H13.2085a.65159.65159,0,0,1-.68213-.41895l-.05518-.10937a.67114.67114,0,0,1,.14307-.78125l.71533-.86914a8.55289,8.55289,0,0,1,.68213-.7373V8.58887a3.93913,3.93913,0,0,1-.748.05469H11.9873a.54085.54085,0,0,1-.605-.60547V7.59863a.54085.54085,0,0,1,.605-.60547h3.75146a.53773.53773,0,0,1,.60547.59375v.17676a1.03723,1.03723,0,0,1-.27539.748L14.74854,10.0293A2.31132,2.31132,0,0,1,16.65186,12.30664ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path>
483
+ <path fill="currentColor" d="M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path>
484
484
  </svg>`,Ce=`<svg viewBox="0 0 18 18">
485
+ <path fill="currentColor" d="M16.65186,12.30664a2.6742,2.6742,0,0,1-2.915,2.68457,3.96592,3.96592,0,0,1-2.25537-.6709.56007.56007,0,0,1-.13232-.83594L11.64648,13c.209-.34082.48389-.36328.82471-.1543a2.32654,2.32654,0,0,0,1.12256.33008c.71484,0,1.12207-.35156,1.12207-.78125,0-.61523-.61621-.86816-1.46338-.86816H13.2085a.65159.65159,0,0,1-.68213-.41895l-.05518-.10937a.67114.67114,0,0,1,.14307-.78125l.71533-.86914a8.55289,8.55289,0,0,1,.68213-.7373V8.58887a3.93913,3.93913,0,0,1-.748.05469H11.9873a.54085.54085,0,0,1-.605-.60547V7.59863a.54085.54085,0,0,1,.605-.60547h3.75146a.53773.53773,0,0,1,.60547.59375v.17676a1.03723,1.03723,0,0,1-.27539.748L14.74854,10.0293A2.31132,2.31132,0,0,1,16.65186,12.30664ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path>
486
+ </svg>`,Ee=`<svg viewBox="0 0 18 18">
485
487
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line>
486
488
  <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z"></path>
487
489
  <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z"></path>
488
- </svg>`,Ee=`<svg viewBox="0 0 18 18">
490
+ </svg>`,Ae=`<svg viewBox="0 0 18 18">
489
491
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline>
490
492
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline>
491
493
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line>
492
- </svg>`,Ae=`<svg viewBox="0 0 18 18">
494
+ </svg>`,Te=`<svg viewBox="0 0 18 18">
493
495
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line>
494
496
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line>
495
497
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line>
496
498
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line>
497
499
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line>
498
500
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line>
499
- </svg>`,Te=`<svg viewBox="0 0 18 18">
501
+ </svg>`,$e=`<svg viewBox="0 0 18 18">
500
502
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line>
501
503
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line>
502
504
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line>
@@ -504,26 +506,69 @@ ${a}`:i;if(u){let x=n.value[n.selectionStart-1];n.selectionStart!==0&&x!=null&&!
504
506
  <path fill="currentColor" d="M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z"></path>
505
507
  <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156"></path>
506
508
  <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109"></path>
507
- </svg>`,$e=`<svg viewBox="2 2 20 20">
509
+ </svg>`,He=`<svg viewBox="2 2 20 20">
508
510
  <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 10.8182L9 10.8182C8.80222 10.8182 8.60888 10.7649 8.44443 10.665C8.27998 10.5651 8.15181 10.4231 8.07612 10.257C8.00043 10.0909 7.98063 9.90808 8.01922 9.73174C8.0578 9.55539 8.15304 9.39341 8.29289 9.26627C8.43275 9.13913 8.61093 9.05255 8.80491 9.01747C8.99889 8.98239 9.19996 9.00039 9.38268 9.0692C9.56541 9.13801 9.72159 9.25453 9.83147 9.40403C9.94135 9.55353 10 9.72929 10 9.90909L10 12.1818C10 12.664 9.78929 13.1265 9.41421 13.4675C9.03914 13.8084 8.53043 14 8 14"></path>
509
511
  <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 10.8182L15 10.8182C14.8022 10.8182 14.6089 10.7649 14.4444 10.665C14.28 10.5651 14.1518 10.4231 14.0761 10.257C14.0004 10.0909 13.9806 9.90808 14.0192 9.73174C14.0578 9.55539 14.153 9.39341 14.2929 9.26627C14.4327 9.13913 14.6109 9.05255 14.8049 9.01747C14.9989 8.98239 15.2 9.00039 15.3827 9.0692C15.5654 9.13801 15.7216 9.25453 15.8315 9.40403C15.9414 9.55353 16 9.72929 16 9.90909L16 12.1818C16 12.664 15.7893 13.1265 15.4142 13.4675C15.0391 13.8084 14.5304 14 14 14"></path>
510
- </svg>`,Be=`<svg viewBox="0 0 18 18">
512
+ </svg>`,Ie=`<svg viewBox="0 0 18 18">
511
513
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line>
512
514
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line>
513
515
  <line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line>
514
516
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
515
517
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
516
518
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" points="2.65 9.5 3.5 10.5 5 8.5"></polyline>
517
- </svg>`;var U=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:we,title:"Italic (Ctrl+I)",action:"toggleItalic"},{separator:!0},{name:"h1",icon:xe,title:"Heading 1",action:"insertH1"},{name:"h2",icon:Se,title:"Heading 2",action:"insertH2"},{name:"h3",icon:Le,title:"Heading 3",action:"insertH3"},{separator:!0},{name:"link",icon:Ce,title:"Insert Link (Ctrl+K)",action:"insertLink"},{name:"code",icon:Ee,title:"Code (Ctrl+`)",action:"toggleCode"},{separator:!0},{name:"quote",icon:$e,title:"Quote",action:"toggleQuote"},{separator:!0},{name:"bulletList",icon:Ae,title:"Bullet List",action:"toggleBulletList"},{name:"orderedList",icon:Te,title:"Numbered List",action:"toggleNumberedList"},{name:"taskList",icon:Be,title:"Task List",action:"toggleTaskList"}].forEach(r=>{if(r.separator){let i=document.createElement("div");i.className="overtype-toolbar-separator",i.setAttribute("role","separator"),this.container.appendChild(i)}else{let i=this.createButton(r);this.buttons[r.name]=i,this.container.appendChild(i)}});let t=this.editor.element.querySelector(".overtype-container"),o=this.editor.element.querySelector(".overtype-wrapper");return t&&o&&t.insertBefore(this.container,o),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,t.addEventListener("click",o=>{o.preventDefault(),this.handleAction(e.action)}),t}async handleAction(e){let t=this.editor.textarea;if(t){t.focus();try{switch(e){case"toggleBold":R(t);break;case"toggleItalic":q(t);break;case"insertH1":de(t);break;case"insertH2":ue(t);break;case"insertH3":he(t);break;case"insertLink":D(t);break;case"toggleCode":le(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break;case"toggleQuote":ce(t);break;case"toggleTaskList":pe(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(o){console.error("Error loading markdown-actions:",o)}}}async updateButtonStates(){let e=this.editor.textarea;if(e)try{let t=fe(e);Object.entries(this.buttons).forEach(([o,r])=>{let i=!1;switch(o){case"bold":i=t.includes("bold");break;case"italic":i=t.includes("italic");break;case"code":i=!1;break;case"bulletList":i=t.includes("bullet-list");break;case"orderedList":i=t.includes("numbered-list");break;case"quote":i=t.includes("quote");break;case"taskList":i=t.includes("task-list");break;case"h1":i=t.includes("header");break;case"h2":i=t.includes("header-2");break;case"h3":i=t.includes("header-3");break}r.classList.toggle("active",i),r.setAttribute("aria-pressed",i.toString())})}catch(t){}}destroy(){this.container&&(this.container.remove(),this.container=null,this.buttons={})}};var k=class k{constructor(e,t={}){let o;if(typeof e=="string"){if(o=document.querySelectorAll(e),o.length===0)throw new Error(`No elements found for selector: ${e}`);o=Array.from(o)}else if(e instanceof Element)o=[e];else if(e instanceof NodeList)o=Array.from(e);else if(Array.isArray(e))o=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return o.map(i=>{if(i.overTypeInstance)return i.overTypeInstance.reinit(t),i.overTypeInstance;let s=Object.create(k.prototype);return s._init(i,t),i.overTypeInstance=s,k.instances.set(i,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++k.instanceCount,this.initialized=!1,k.injectStyles(),k.initGlobalListeners();let o=e.querySelector(".overtype-container"),r=e.querySelector(".overtype-wrapper");o||r?this._recoverFromDOM(o,r):this._buildFromScratch(),this.shortcuts=new j(this),this.options.toolbar&&(this.toolbar=new U(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:"ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace",padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},autofocus:!1,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,statsFormatter:null},{theme:o,colors:r,...i}=e;return{...t,...i}}_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 o=this.instanceTheme||k.currentTheme||B,r=typeof o=="string"?o:o.name;if(r&&this.container.setAttribute("data-theme",r),this.instanceTheme){let i=typeof this.instanceTheme=="string"?H(this.instanceTheme):this.instanceTheme;if(i&&i.colors){let s=N(i.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||k.currentTheme||B,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let o=typeof this.instanceTheme=="string"?H(this.instanceTheme):this.instanceTheme;if(o&&o.colors){let r=N(o.colors);this.container.style.cssText+=r}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this.options.showStats&&this.wrapper.classList.add("with-stats"),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.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.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.wrapper.appendChild(this.statsBar),this._updateStats()),this.container.appendChild(this.wrapper),this.element.appendChild(this.container)}_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.updatePreview()}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,o=this._getCurrentLine(e,t),r=M.parse(e,o,this.options.showActiveLineRaw);this.preview.innerHTML=r||'<span style="color: #808080;">Start typing...</span>',this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onChange&&this.initialized&&this.options.onChange(e,this)}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let t=0;t<e.length-1;t+=2){let o=e[t],r=e[t+1],i=o.parentElement,s=r.parentElement;if(!i||!s)continue;o.style.display="block",r.style.display="block",i.classList.add("code-block-line"),s.classList.add("code-block-line");let a=i.nextElementSibling;for(;a&&a!==s&&(a.tagName==="DIV"&&a.classList.add("code-block-line"),a=a.nextElementSibling,!!a););}}_getCurrentLine(e,t){return e.substring(0,t).split(`
518
- `).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}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()}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(`
519
- `),o=e.length,r=e.split(/\s+/).filter(p=>p.length>0).length,i=this.textarea.selectionStart,a=e.substring(0,i).split(`
520
- `),l=a.length,u=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:o,words:r,lines:t.length,line:l,column:u}):this.statsBar.innerHTML=`
519
+ </svg>`;var U=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:we,title:"Bold (Ctrl+B)",action:"toggleBold"},{name:"italic",icon:xe,title:"Italic (Ctrl+I)",action:"toggleItalic"},{separator:!0},{name:"h1",icon:Se,title:"Heading 1",action:"insertH1"},{name:"h2",icon:Le,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:Ae,title:"Code (Ctrl+`)",action:"toggleCode"},{separator:!0},{name:"quote",icon:He,title:"Quote",action:"toggleQuote"},{separator:!0},{name:"bulletList",icon:Te,title:"Bullet List",action:"toggleBulletList"},{name:"orderedList",icon:$e,title:"Numbered List",action:"toggleNumberedList"},{name:"taskList",icon:Ie,title:"Task List",action:"toggleTaskList"}].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"),o=this.editor.element.querySelector(".overtype-wrapper");return t&&o&&t.insertBefore(this.container,o),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,t.addEventListener("click",o=>{o.preventDefault(),this.handleAction(e.action)}),t}async handleAction(e){let t=this.editor.textarea;if(t){t.focus();try{switch(e){case"toggleBold":R(t);break;case"toggleItalic":q(t);break;case"insertH1":ue(t);break;case"insertH2":he(t);break;case"insertH3":fe(t);break;case"insertLink":D(t);break;case"toggleCode":ce(t);break;case"toggleBulletList":W(t);break;case"toggleNumberedList":K(t);break;case"toggleQuote":pe(t);break;case"toggleTaskList":de(t);break}t.dispatchEvent(new Event("input",{bubbles:!0}))}catch(o){console.error("Error loading markdown-actions:",o)}}}async updateButtonStates(){let e=this.editor.textarea;if(e)try{let t=me(e);Object.entries(this.buttons).forEach(([o,i])=>{let r=!1;switch(o){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}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(t){}}destroy(){this.container&&(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=`
520
+ @supports (position-anchor: --x) and (position-area: center) {
521
+ .overtype-link-tooltip {
522
+ position: absolute;
523
+ position-anchor: var(--target-anchor, --link-0);
524
+ position-area: block-end center;
525
+ margin-top: 8px;
526
+
527
+ background: #333;
528
+ color: white;
529
+ padding: 6px 10px;
530
+ border-radius: 16px;
531
+ font-size: 12px;
532
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
533
+ display: none;
534
+ z-index: 10000;
535
+ cursor: pointer;
536
+ box-shadow: 0 2px 8px rgba(0,0,0,0.3);
537
+ max-width: 300px;
538
+ white-space: nowrap;
539
+ overflow: hidden;
540
+ text-overflow: ellipsis;
541
+
542
+ position-try: most-width block-end inline-end, flip-inline, block-start center;
543
+ position-visibility: anchors-visible;
544
+ }
545
+
546
+ .overtype-link-tooltip.visible {
547
+ display: flex;
548
+ }
549
+ }
550
+ `,document.head.appendChild(e),this.tooltip.innerHTML=`
551
+ <span style="display: flex; align-items: center; gap: 6px;">
552
+ <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
553
+ <path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path>
554
+ <path d="M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z"></path>
555
+ </svg>
556
+ <span class="overtype-link-tooltip-url"></span>
557
+ </span>
558
+ `,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,o=this.findLinkAtPosition(t,e);o?(!this.currentLink||this.currentLink.url!==o.url||this.currentLink.index!==o.index)&&this.show(o):this.scheduleHide()}findLinkAtPosition(e,t){let o=/\[([^\]]+)\]\(([^)]+)\)/g,i,r=0;for(;(i=o.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 k=class k{constructor(e,t={}){let o;if(typeof e=="string"){if(o=document.querySelectorAll(e),o.length===0)throw new Error(`No elements found for selector: ${e}`);o=Array.from(o)}else if(e instanceof Element)o=[e];else if(e instanceof NodeList)o=Array.from(e);else if(Array.isArray(e))o=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return o.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(t),r.overTypeInstance;let s=Object.create(k.prototype);return s._init(r,t),r.overTypeInstance=s,k.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++k.instanceCount,this.initialized=!1,k.injectStyles(),k.initGlobalListeners();let o=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");o||i?this._recoverFromDOM(o,i):this._buildFromScratch(),this.shortcuts=new O(this),this.linkTooltip=new Z(this),this.options.toolbar&&(this.toolbar=new U(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:"ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace",padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},autofocus:!1,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,statsFormatter:null},{theme:o,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 o=this.instanceTheme||k.currentTheme||H,i=typeof o=="string"?o:o.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?M(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=N(r.colors);this.container.style.cssText+=s}}t.parentNode.insertBefore(this.container,t),this.container.appendChild(t)}if(!this.wrapper){e&&e.remove(),t&&t.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||k.currentTheme||H,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let o=typeof this.instanceTheme=="string"?M(this.instanceTheme):this.instanceTheme;if(o&&o.colors){let i=N(o.colors);this.container.style.cssText+=i}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this.options.showStats&&this.wrapper.classList.add("with-stats"),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.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.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.wrapper.appendChild(this.statsBar),this._updateStats()),this.container.appendChild(this.wrapper),this.element.appendChild(this.container)}_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.updatePreview()}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,o=this._getCurrentLine(e,t),i=B.parse(e,o,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 o=e[t],i=e[t+1],r=o.parentElement,s=i.parentElement;if(!r||!s)continue;o.style.display="block",i.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line");let a=r.nextElementSibling;for(;a&&a!==s&&(a.tagName==="DIV"&&a.classList.add("code-block-line"),a=a.nextElementSibling,!!a););}}_getCurrentLine(e,t){return e.substring(0,t).split(`
559
+ `).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){if(e.key==="Tab"){e.preventDefault();let o=this.textarea.selectionStart,i=this.textarea.selectionEnd,r=this.textarea.value;if(o!==i&&e.shiftKey){let s=r.substring(0,o),a=r.substring(o,i),l=r.substring(i),p=a.split(`
560
+ `).map(c=>c.replace(/^ /,"")).join(`
561
+ `);this.textarea.value=s+p+l,this.textarea.selectionStart=o,this.textarea.selectionEnd=o+p.length}else if(o!==i){let s=r.substring(0,o),a=r.substring(o,i),l=r.substring(i),p=a.split(`
562
+ `).map(c=>" "+c).join(`
563
+ `);this.textarea.value=s+p+l,this.textarea.selectionStart=o,this.textarea.selectionEnd=o+p.length}else this.textarea.value=r.substring(0,o)+" "+r.substring(i),this.textarea.selectionStart=this.textarea.selectionEnd=o+2;this.textarea.dispatchEvent(new Event("input",{bubbles:!0}));return}!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}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()}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(`
564
+ `),o=e.length,i=e.split(/\s+/).filter(p=>p.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(`
565
+ `),l=a.length,u=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:o,words:i,lines:t.length,line:l,column:u}):this.statsBar.innerHTML=`
521
566
  <div class="overtype-stat">
522
567
  <span class="live-dot"></span>
523
- <span>${o} chars, ${r} words, ${t.length} lines</span>
568
+ <span>${o} chars, ${i} words, ${t.length} lines</span>
524
569
  </div>
525
570
  <div class="overtype-stat">Line ${l}, Col ${u}</div>
526
- `}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.wrapper.appendChild(this.statsBar),this.wrapper.classList.add("with-stats"),this._updateStats()):!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null,this.wrapper.classList.remove("with-stats"))}destroy(){if(this.element.overTypeInstance=null,k.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 k(e,t)}static getInstance(e){return e.overTypeInstance||k.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let o=k.getInstance(t);o&&o.destroy()})}static injectStyles(e=!1){if(k.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let o=k.currentTheme||B,r=be({theme:o}),i=document.createElement("style");i.className="overtype-styles",i.textContent=r,document.head.appendChild(i),k.stylesInjected=!0}static setTheme(e,t=null){let o=typeof e=="string"?H(e):e;t&&(o=ye(o,t)),k.currentTheme=o,k.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(r=>{let i=typeof o=="string"?o:o.name;i&&r.setAttribute("data-theme",i)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{if(!r.closest(".overtype-container")){let s=typeof o=="string"?o:o.name;s&&r.setAttribute("data-theme",s)}let i=r._instance;i&&i.updatePreview()})}static initGlobalListeners(){k.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),o=t==null?void 0:t._instance;o&&o.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"),o=t==null?void 0:t._instance;o&&o.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"),o=t==null?void 0:t._instance;o&&o.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let o=t.closest(".overtype-wrapper"),r=o==null?void 0:o._instance;r&&(r.options.showStats&&r.statsBar&&r._updateStats(),clearTimeout(r._selectionTimeout),r._selectionTimeout=setTimeout(()=>{r.updatePreview()},50))}}),k.globalListenersInitialized=!0)}};I(k,"instances",new WeakMap),I(k,"stylesInjected",!1),I(k,"globalListenersInitialized",!1),I(k,"instanceCount",0);var A=k;A.MarkdownParser=M;A.ShortcutsManager=j;A.themes={solar:B,cave:H("cave")};A.getTheme=H;A.currentTheme=B;var Qe=A;return _e(Ge);})();
571
+ `}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.wrapper.appendChild(this.statsBar),this.wrapper.classList.add("with-stats"),this._updateStats()):!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null,this.wrapper.classList.remove("with-stats"))}destroy(){if(this.element.overTypeInstance=null,k.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 k(e,t)}static getInstance(e){return e.overTypeInstance||k.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(t=>{let o=k.getInstance(t);o&&o.destroy()})}static injectStyles(e=!1){if(k.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let o=k.currentTheme||H,i=ke({theme:o}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),k.stylesInjected=!0}static setTheme(e,t=null){let o=typeof e=="string"?M(e):e;t&&(o=be(o,t)),k.currentTheme=o,k.injectStyles(!0),document.querySelectorAll(".overtype-container").forEach(i=>{let r=typeof o=="string"?o:o.name;r&&i.setAttribute("data-theme",r)}),document.querySelectorAll(".overtype-wrapper").forEach(i=>{if(!i.closest(".overtype-container")){let s=typeof o=="string"?o:o.name;s&&i.setAttribute("data-theme",s)}let r=i._instance;r&&r.updatePreview()})}static initGlobalListeners(){k.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),o=t==null?void 0:t._instance;o&&o.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"),o=t==null?void 0:t._instance;o&&o.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"),o=t==null?void 0:t._instance;o&&o.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let o=t.closest(".overtype-wrapper"),i=o==null?void 0:o._instance;i&&(i.options.showStats&&i.statsBar&&i._updateStats(),clearTimeout(i._selectionTimeout),i._selectionTimeout=setTimeout(()=>{i.updatePreview()},50))}}),k.globalListenersInitialized=!0)}};I(k,"instances",new WeakMap),I(k,"stylesInjected",!1),I(k,"globalListenersInitialized",!1),I(k,"instanceCount",0);var A=k;A.MarkdownParser=B;A.ShortcutsManager=O;A.themes={solar:H,cave:M("cave")};A.getTheme=M;A.currentTheme=H;var Ge=A;return _e(Xe);})();
527
572
  /**
528
573
  * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
529
574
  * @version 1.0.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtype",
3
- "version": "1.0.6",
3
+ "version": "1.1.1",
4
4
  "description": "A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay",
5
5
  "main": "dist/overtype.js",
6
6
  "module": "dist/overtype.esm.js",