overtype 2.3.5 → 2.3.6

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,5 +1,5 @@
1
1
  /**
2
- * OverType v2.3.5
2
+ * OverType v2.3.6
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -103,9 +103,9 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
103
103
  left: 0 !important;
104
104
  width: 100% !important;
105
105
  height: 100% !important;
106
-
106
+
107
107
  /* Font properties - any difference breaks alignment */
108
- font-family: ${n} !important;
108
+ font-family: var(--instance-font-family, ${n}) !important;
109
109
  font-variant-ligatures: none !important; /* keep metrics stable for code */
110
110
  font-size: var(--instance-font-size, ${e}) !important;
111
111
  line-height: var(--instance-line-height, ${t}) !important;
@@ -212,15 +212,12 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
212
212
  z-index: 0 !important;
213
213
  pointer-events: none !important;
214
214
  user-select: none !important;
215
- font-family: ${n} !important;
215
+ font-family: var(--instance-font-family, ${n}) !important;
216
216
  font-size: var(--instance-font-size, ${e}) !important;
217
217
  line-height: var(--instance-line-height, ${t}) !important;
218
218
  padding: var(--instance-padding, ${o}) !important;
219
219
  box-sizing: border-box !important;
220
220
  color: var(--placeholder, #999) !important;
221
- overflow: hidden !important;
222
- white-space: nowrap !important;
223
- text-overflow: ellipsis !important;
224
221
  }
225
222
 
226
223
  /* Preview layer styles */
@@ -373,7 +370,7 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
373
370
  .overtype-wrapper .overtype-preview pre code {
374
371
  background: transparent !important;
375
372
  color: var(--code, #0d3b66) !important;
376
- font-family: ${n} !important; /* Match textarea font exactly for alignment */
373
+ font-family: var(--instance-font-family, ${n}) !important; /* Match textarea font exactly for alignment */
377
374
  }
378
375
 
379
376
  /* Blockquotes */
@@ -458,26 +455,20 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
458
455
  .overtype-stats {
459
456
  height: 40px !important;
460
457
  padding: 0 20px !important;
461
- background: #f8f9fa !important;
462
- border-top: 1px solid #e0e0e0 !important;
458
+ background: var(--bg-secondary, #f8f9fa) !important;
459
+ border-top: 1px solid var(--border, #e0e0e0) !important;
463
460
  display: flex !important;
464
461
  justify-content: space-between !important;
465
462
  align-items: center !important;
466
463
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
467
464
  font-size: 0.85rem !important;
468
- color: #666 !important;
465
+ color: var(--text-secondary, #666) !important;
469
466
  flex-shrink: 0 !important; /* Don't shrink */
470
467
  z-index: 10001 !important; /* Above link tooltip */
471
468
  position: relative !important; /* Enable z-index */
472
469
  }
473
-
474
- /* Dark theme stats bar */
475
- .overtype-container[data-theme="cave"] .overtype-stats {
476
- background: var(--bg-secondary, #1D2D3E) !important;
477
- border-top: 1px solid rgba(197, 221, 232, 0.1) !important;
478
- color: var(--text, #c5dde8) !important;
479
- }
480
-
470
+
471
+
481
472
  .overtype-stats .overtype-stat {
482
473
  display: flex !important;
483
474
  align-items: center !important;
@@ -889,7 +880,7 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
889
880
  }
890
881
 
891
882
  ${a}
892
- `}var yi=Object.defineProperty,Ge=Object.getOwnPropertySymbols,bi=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,Je=(i,e,t)=>e in i?yi(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,Xe=(i,e)=>{for(var t in e||(e={}))bi.call(e,t)&&Je(i,t,e[t]);if(Ge)for(var t of Ge(e))wi.call(e,t)&&Je(i,t,e[t]);return i},R={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function xi(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function F(i){return Xe(Xe({},xi()),i)}var we=!1;function ki(){return we}function x(i,e,t){we&&(console.group(`\u{1F50D} ${i}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function be(i,e){if(!we)return;let t=i.value.slice(i.selectionStart,i.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${i.selectionStart}-${i.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let n=i.value.slice(Math.max(0,i.selectionStart-10),i.selectionStart),o=i.value.slice(i.selectionEnd,Math.min(i.value.length,i.selectionEnd+10));console.log("Context:",JSON.stringify(n)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function it(i){we&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(i.text)),console.log("New selection:",`${i.selectionStart}-${i.selectionEnd}`),console.groupEnd())}var z=null;function V(i,{text:e,selectionStart:t,selectionEnd:n}){let o=ki();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${i.selectionStart}-${i.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",n)),i.focus();let r=i.selectionStart,s=i.selectionEnd,a=i.value.slice(0,r),c=i.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(i.value.slice(r,s))));let p=i.value,l=r!==s;if(z===null||z===!0){i.contentEditable="true";try{z=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",z,"for text with",e.split(`
883
+ `}var yi=Object.defineProperty,Ge=Object.getOwnPropertySymbols,bi=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,Je=(i,e,t)=>e in i?yi(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,Xe=(i,e)=>{for(var t in e||(e={}))bi.call(e,t)&&Je(i,t,e[t]);if(Ge)for(var t of Ge(e))wi.call(e,t)&&Je(i,t,e[t]);return i},R={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function xi(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function F(i){return Xe(Xe({},xi()),i)}var we=!1;function ki(){return we}function x(i,e,t){we&&(console.group(`\u{1F50D} ${i}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function be(i,e){if(!we)return;let t=i.value.slice(i.selectionStart,i.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${i.selectionStart}-${i.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let n=i.value.slice(Math.max(0,i.selectionStart-10),i.selectionStart),o=i.value.slice(i.selectionEnd,Math.min(i.value.length,i.selectionEnd+10));console.log("Context:",JSON.stringify(n)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function it(i){we&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(i.text)),console.log("New selection:",`${i.selectionStart}-${i.selectionEnd}`),console.groupEnd())}var z=null;function j(i,{text:e,selectionStart:t,selectionEnd:n}){let o=ki();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${i.selectionStart}-${i.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",n)),i.focus();let r=i.selectionStart,s=i.selectionEnd,a=i.value.slice(0,r),c=i.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(i.value.slice(r,s))));let p=i.value,l=r!==s;if(z===null||z===!0){i.contentEditable="true";try{z=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",z,"for text with",e.split(`
893
884
  `).length,"lines")}catch(d){z=!1,o&&console.log("execCommand threw error:",d)}i.contentEditable="false"}if(o&&(console.log("canInsertText before:",z),console.log("execCommand result:",z)),z){let d=a+e+c,u=i.value;o&&(console.log("Expected length:",d.length),console.log("Actual length:",u.length)),u!==d&&o&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(d.slice(0,100))),console.log("Actual:",JSON.stringify(u.slice(0,100))))}if(!z)if(o&&console.log("Using manual insertion"),i.value===p){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(d){}i.value=a+e+c;try{document.execCommand("ms-endUndoUnit")}catch(d){}i.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else o&&console.log("Value was changed by execCommand, skipping manual insertion");o&&console.log("Setting selection range:",t,n),t!=null&&n!=null?i.setSelectionRange(t,n):i.setSelectionRange(r,i.selectionEnd),o&&(console.log("Final value length:",i.value.length),console.groupEnd())}function Ye(i){return i.trim().split(`
894
885
  `).length>1}function Si(i,e){let t=e;for(;i[t]&&i[t-1]!=null&&!i[t-1].match(/\s/);)t--;return t}function Li(i,e,t){let n=e,o=t?/\n/:/\s/;for(;i[n]&&!i[n].match(o);)n++;return n}function nt(i){let e=i.value.split(`
895
886
  `),t=0;for(let n=0;n<e.length;n++){let o=e[n].length+1;i.selectionStart>=t&&i.selectionStart<t+o&&(i.selectionStart=t),i.selectionEnd>=t&&i.selectionEnd<t+o&&(n===e.length-1?i.selectionEnd=Math.min(t+e[n].length,i.value.length):i.selectionEnd=t+o-1),t+=o}}function Ei(i,e,t,n=!1){if(i.selectionStart===i.selectionEnd)i.selectionStart=Si(i.value,i.selectionStart),i.selectionEnd=Li(i.value,i.selectionEnd,n);else{let o=i.selectionStart-e.length,r=i.selectionEnd+t.length,s=i.value.slice(o,i.selectionStart)===e,a=i.value.slice(i.selectionEnd,r)===t;s&&a&&(i.selectionStart=o,i.selectionEnd=r)}return i.value.slice(i.selectionStart,i.selectionEnd)}function Re(i){let e=i.value.slice(0,i.selectionStart),t=i.value.slice(i.selectionEnd),n=e.match(/\n*$/),o=t.match(/^\n*/),r=n?n[0].length:0,s=o?o[0].length:0,a="",c="";return e.match(/\S/)&&r<2&&(a=`
@@ -907,10 +898,10 @@ ${a}`:r;if(p){let k=i.value[i.selectionStart-1];i.selectionStart!==0&&k!=null&&!
907
898
  `),t="- ",n=e.every(r=>r.startsWith(t)),o=e;return n&&(o=e.map(r=>r.slice(t.length))),{text:o.join(`
908
899
  `),processed:n}}function re(i,e){return e?"- ":`${i+1}. `}function Ci(i,e){let t,n,o;return i.orderedList?(t=et(e),n=tt(t.text),o=n.text):(t=tt(e),n=et(t.text),o=n.text),[t,n,o]}function _i(i,e){let t=i.selectionStart===i.selectionEnd,n=i.selectionStart,o=i.selectionEnd;nt(i);let r=i.value.slice(i.selectionStart,i.selectionEnd),[s,a,c]=Ci(e,r),p=c.split(`
909
900
  `).map((m,g)=>`${re(g,e.unorderedList)}${m}`),l=p.reduce((m,g,y)=>m+re(y,e.unorderedList).length,0),d=p.reduce((m,g,y)=>m+re(y,!e.unorderedList).length,0);if(s.processed)return t?(n=Math.max(n-re(0,e.unorderedList).length,0),o=n):(n=i.selectionStart,o=i.selectionEnd-l),{text:c,selectionStart:n,selectionEnd:o};let{newlinesToAppend:u,newlinesToPrepend:h}=Re(i),f=u+p.join(`
910
- `)+h;return t?(n=Math.max(n+re(0,e.unorderedList).length+u.length,0),o=n):a.processed?(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l-d):(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l),{text:f,selectionStart:n,selectionEnd:o}}function rt(i,e){let t=xe(i,n=>_i(n,e),{adjustSelection:(n,o,r,s)=>{let a=i.value.slice(s,i.selectionEnd),c=/^\d+\.\s+/,p=/^- /,l=c.test(a),d=p.test(a),u=e.orderedList&&l||e.unorderedList&&d;if(o===r)if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:o+h}}else if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:r+h}}}});V(i,t)}function Ai(i){if(!i)return[];let e=[],{selectionStart:t,selectionEnd:n,value:o}=i,r=o.split(`
911
- `),s=0,a="";for(let d of r){if(t>=s&&t<=s+d.length){a=d;break}s+=d.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,t-10),p=Math.min(o.length,n+10),l=o.slice(c,p);if(l.includes("**")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100));d.includes("`")&&u.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&o.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function st(i){if(!i||i.disabled||i.readOnly)return;x("toggleBold","Starting"),be(i,"Before");let e=F(R.bold),t=ke(i,e);it(t),V(i,t),be(i,"After")}function at(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.italic),t=ke(i,e);V(i,t)}function lt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.code),t=ke(i,e);V(i,t)}function ct(i,e={}){if(!i||i.disabled||i.readOnly)return;let t=i.value.slice(i.selectionStart,i.selectionEnd),n=F(R.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(n.suffix=`](${t})`,n.replaceNext=""):e.url&&(n.suffix=`](${e.url})`,n.replaceNext=""),e.text&&!t){let s=i.selectionStart;i.value=i.value.slice(0,s)+e.text+i.value.slice(s),i.selectionStart=s,i.selectionEnd=s+e.text.length}let r=ke(i,n);V(i,r)}function pt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.bulletList);rt(i,e)}function dt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.numberedList);rt(i,e)}function ht(i){if(!i||i.disabled||i.readOnly)return;x("toggleQuote","Starting"),be(i,"Initial");let e=F(R.quote),t=xe(i,n=>ot(n,e),{prefix:e.prefix});it(t),V(i,t),be(i,"Final")}function Ie(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.taskList),t=xe(i,n=>ot(n,e),{prefix:e.prefix});V(i,t)}function Be(i,e=1,t=!1){if(!i||i.disabled||i.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${t}`),x("insertHeader",`Initial cursor: ${i.selectionStart}-${i.selectionEnd}`);let n=`header${e===1?"1":e}`,o=F(R[n]||R.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=i.value,s=i.selectionStart,a=i.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
901
+ `)+h;return t?(n=Math.max(n+re(0,e.unorderedList).length+u.length,0),o=n):a.processed?(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l-d):(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l),{text:f,selectionStart:n,selectionEnd:o}}function rt(i,e){let t=xe(i,n=>_i(n,e),{adjustSelection:(n,o,r,s)=>{let a=i.value.slice(s,i.selectionEnd),c=/^\d+\.\s+/,p=/^- /,l=c.test(a),d=p.test(a),u=e.orderedList&&l||e.unorderedList&&d;if(o===r)if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:o+h}}else if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:r+h}}}});j(i,t)}function Ai(i){if(!i)return[];let e=[],{selectionStart:t,selectionEnd:n,value:o}=i,r=o.split(`
902
+ `),s=0,a="";for(let d of r){if(t>=s&&t<=s+d.length){a=d;break}s+=d.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,t-10),p=Math.min(o.length,n+10),l=o.slice(c,p);if(l.includes("**")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100));d.includes("`")&&u.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&o.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function st(i){if(!i||i.disabled||i.readOnly)return;x("toggleBold","Starting"),be(i,"Before");let e=F(R.bold),t=ke(i,e);it(t),j(i,t),be(i,"After")}function at(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.italic),t=ke(i,e);j(i,t)}function lt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.code),t=ke(i,e);j(i,t)}function ct(i,e={}){if(!i||i.disabled||i.readOnly)return;let t=i.value.slice(i.selectionStart,i.selectionEnd),n=F(R.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(n.suffix=`](${t})`,n.replaceNext=""):e.url&&(n.suffix=`](${e.url})`,n.replaceNext=""),e.text&&!t){let s=i.selectionStart;i.value=i.value.slice(0,s)+e.text+i.value.slice(s),i.selectionStart=s,i.selectionEnd=s+e.text.length}let r=ke(i,n);j(i,r)}function pt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.bulletList);rt(i,e)}function dt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.numberedList);rt(i,e)}function ht(i){if(!i||i.disabled||i.readOnly)return;x("toggleQuote","Starting"),be(i,"Initial");let e=F(R.quote),t=xe(i,n=>ot(n,e),{prefix:e.prefix});it(t),j(i,t),be(i,"Final")}function Ie(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.taskList),t=xe(i,n=>ot(n,e),{prefix:e.prefix});j(i,t)}function Be(i,e=1,t=!1){if(!i||i.disabled||i.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${t}`),x("insertHeader",`Initial cursor: ${i.selectionStart}-${i.selectionEnd}`);let n=`header${e===1?"1":e}`,o=F(R[n]||R.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=i.value,s=i.selectionStart,a=i.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
912
903
  `;)c--;let p=a;for(;p<r.length&&r[p]!==`
913
- `;)p++;let l=r.slice(c,p);x("insertHeader",`Current line (before): "${l}"`);let d=l.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=t&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${u}, level=${e})`);let m=xe(i,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let b=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${b}"`);let w;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),w=b):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),w=o.prefix+b):(x("insertHeader","ACTION: Adding new header"),w=o.prefix+b),x("insertHeader",`New line: "${w}"`),{text:w,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,y,b,w)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${b}`),x("insertHeader",` - lineStartPos: ${w}`),f){let S=Math.max(y-h,w);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:S,end:y===b?S:Math.max(b-h,w)}}else if(h>0){let S=o.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${S}`),{start:y+S,end:b+S}}else return x("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:y+o.prefix.length,end:b+o.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),V(i,m)}function ut(i){Be(i,1,!0)}function ft(i){Be(i,2,!0)}function mt(i){Be(i,3,!0)}function gt(i){return Ai(i)}var Se=class{constructor(e,t={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=t.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let t=this.createSeparator();this.container.appendChild(t)}else{let t=this.createButton(e);this.buttons[e.name]=t,this.container.appendChild(t)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.setAttribute("data-button",e.name),t.title=e.title||"",t.setAttribute("aria-label",e.title||e.name),t.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(t.classList.add("has-dropdown"),t.dataset.dropdown="true",t.addEventListener("click",n=>{n.preventDefault(),this.toggleViewModeDropdown(t)}),t):(t._clickHandler=n=>{n.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,n)},t.addEventListener("click",t._clickHandler),t)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:t=>this.editor.setValue(t),event:null}),!0}catch(t){return console.error(`Action "${e.name}" error:`,t),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:t}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let n=this.createViewModeDropdown(e),o=e.getBoundingClientRect();n.style.position="absolute",n.style.top=`${o.bottom+5}px`,n.style.left=`${o.left}px`,document.body.appendChild(n),this.handleDocumentClick=r=>{!n.contains(r.target)&&!e.contains(r.target)&&(n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let t=document.createElement("div");t.className="overtype-dropdown-menu";let n=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],o=this.editor.container.dataset.mode||"normal";return n.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===o){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),t.appendChild(s)}),t}updateButtonStates(){var e;try{let t=((e=gt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,o])=>{if(n==="viewMode")return;let r=!1;switch(n){case"bold":r=t.includes("bold");break;case"italic":r=t.includes("italic");break;case"code":r=!1;break;case"bulletList":r=t.includes("bullet-list");break;case"orderedList":r=t.includes("numbered-list");break;case"taskList":r=t.includes("task-list");break;case"quote":r=t.includes("quote");break;case"h1":r=t.includes("header");break;case"h2":r=t.includes("header-2");break;case"h3":r=t.includes("header-3");break}o.classList.toggle("active",r),o.setAttribute("aria-pressed",r.toString())})}catch(t){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var ae=Math.min,U=Math.max,le=Math.round;var O=i=>({x:i,y:i}),Ti={left:"right",right:"left",bottom:"top",top:"bottom"},Hi={start:"end",end:"start"};function ze(i,e,t){return U(i,ae(e,t))}function ce(i,e){return typeof i=="function"?i(e):i}function W(i){return i.split("-")[0]}function pe(i){return i.split("-")[1]}function Fe(i){return i==="x"?"y":"x"}function Ne(i){return i==="y"?"height":"width"}var Mi=new Set(["top","bottom"]);function N(i){return Mi.has(W(i))?"y":"x"}function De(i){return Fe(N(i))}function wt(i,e,t){t===void 0&&(t=!1);let n=pe(i),o=De(i),r=Ne(o),s=o==="x"?n===(t?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=se(s)),[s,se(s)]}function xt(i){let e=se(i);return[Le(i),e,Le(e)]}function Le(i){return i.replace(/start|end/g,e=>Hi[e])}var yt=["left","right"],bt=["right","left"],Oi=["top","bottom"],Pi=["bottom","top"];function $i(i,e,t){switch(i){case"top":case"bottom":return t?e?bt:yt:e?yt:bt;case"left":case"right":return e?Oi:Pi;default:return[]}}function kt(i,e,t,n){let o=pe(i),r=$i(W(i),t==="start",n);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Le)))),r}function se(i){return i.replace(/left|right|bottom|top/g,e=>Ti[e])}function Ri(i){return{top:0,right:0,bottom:0,left:0,...i}}function St(i){return typeof i!="number"?Ri(i):{top:i,right:i,bottom:i,left:i}}function G(i){let{x:e,y:t,width:n,height:o}=i;return{width:n,height:o,top:t,left:e,right:e+n,bottom:t+o,x:e,y:t}}function Lt(i,e,t){let{reference:n,floating:o}=i,r=N(e),s=De(e),a=Ne(s),c=W(e),p=r==="y",l=n.x+n.width/2-o.width/2,d=n.y+n.height/2-o.height/2,u=n[a]/2-o[a]/2,h;switch(c){case"top":h={x:l,y:n.y-o.height};break;case"bottom":h={x:l,y:n.y+n.height};break;case"right":h={x:n.x+n.width,y:d};break;case"left":h={x:n.x-o.width,y:d};break;default:h={x:n.x,y:n.y}}switch(pe(e)){case"start":h[s]-=u*(t&&p?-1:1);break;case"end":h[s]+=u*(t&&p?-1:1);break}return h}async function Et(i,e){var t;e===void 0&&(e={});let{x:n,y:o,platform:r,rects:s,elements:a,strategy:c}=i,{boundary:p="clippingAncestors",rootBoundary:l="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=ce(e,i),f=St(h),g=a[u?d==="floating"?"reference":"floating":d],y=G(await r.getClippingRect({element:(t=await(r.isElement==null?void 0:r.isElement(g)))==null||t?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:p,rootBoundary:l,strategy:c})),b=d==="floating"?{x:n,y:o,width:s.floating.width,height:s.floating.height}:s.reference,w=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),S=await(r.isElement==null?void 0:r.isElement(w))?await(r.getScale==null?void 0:r.getScale(w))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:w,strategy:c}):b);return{top:(y.top-k.top+f.top)/S.y,bottom:(k.bottom-y.bottom+f.bottom)/S.y,left:(y.left-k.left+f.left)/S.x,right:(k.right-y.right+f.right)/S.x}}var Ct=async(i,e,t)=>{let{placement:n="bottom",strategy:o="absolute",middleware:r=[],platform:s}=t,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:i,floating:e,strategy:o}),{x:l,y:d}=Lt(p,n,c),u=n,h={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:b}=a[g],{x:w,y:S,data:k,reset:E}=await b({x:l,y:d,initialPlacement:n,placement:u,strategy:o,middlewareData:h,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Et},elements:{reference:i,floating:e}});l=w!=null?w:l,d=S!=null?S:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:i,floating:e,strategy:o}):E.rects),{x:l,y:d}=Lt(p,u,c)),g=-1)}return{x:l,y:d,placement:u,strategy:o,middlewareData:h}};var _t=function(i){return i===void 0&&(i={}),{name:"flip",options:i,async fn(e){var t,n;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:p}=e,{mainAxis:l=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=ce(i,e);if((t=r.arrow)!=null&&t.alignmentOffset)return{};let y=W(o),b=N(a),w=W(a)===a,S=await(c.isRTL==null?void 0:c.isRTL(p.floating)),k=u||(w||!m?[se(a)]:xt(a)),E=f!=="none";!u&&E&&k.push(...kt(a,m,f,S));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((n=r.flip)==null?void 0:n.overflows)||[];if(l&&ge.push(Y[y]),d){let K=wt(o,s,S);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ge}],!ge.every(K=>K<=0)){var Ue,We;let K=(((Ue=r.flip)==null?void 0:Ue.index)||0)+1,Pe=me[K];if(Pe&&(!(d==="alignment"?b!==N(Pe):!1)||ee.every(M=>N(M.placement)===b?M.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let ne=(We=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,M)=>Z.overflows[1]-M.overflows[1])[0])==null?void 0:We.placement;if(!ne)switch(h){case"bestFit":{var qe;let Z=(qe=ee.filter(M=>{if(E){let j=N(M.placement);return j===b||j==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(j=>j>0).reduce((j,pi)=>j+pi,0)]).sort((M,j)=>M[1]-j[1])[0])==null?void 0:qe[0];Z&&(ne=Z);break}case"initialPlacement":ne=a;break}if(o!==ne)return{reset:{placement:ne}}}return{}}}};var Ii=new Set(["left","top"]);async function Bi(i,e){let{placement:t,platform:n,elements:o}=i,r=await(n.isRTL==null?void 0:n.isRTL(o.floating)),s=W(t),a=pe(t),c=N(t)==="y",p=Ii.has(s)?-1:1,l=r&&c?-1:1,d=ce(e,i),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),c?{x:h*l,y:u*p}:{x:u*p,y:h*l}}var At=function(i){return i===void 0&&(i=0),{name:"offset",options:i,async fn(e){var t,n;let{x:o,y:r,placement:s,middlewareData:a}=e,c=await Bi(e,i);return s===((t=a.offset)==null?void 0:t.placement)&&(n=a.arrow)!=null&&n.alignmentOffset?{}:{x:o+c.x,y:r+c.y,data:{...c,placement:s}}}}},Tt=function(i){return i===void 0&&(i={}),{name:"shift",options:i,async fn(e){let{x:t,y:n,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:b,y:w}=y;return{x:b,y:w}}},...p}=ce(i,e),l={x:t,y:n},d=await r.detectOverflow(e,p),u=N(W(o)),h=Fe(u),f=l[h],m=l[u];if(s){let y=h==="y"?"top":"left",b=h==="y"?"bottom":"right",w=f+d[y],S=f-d[b];f=ze(w,f,S)}if(a){let y=u==="y"?"top":"left",b=u==="y"?"bottom":"right",w=m+d[y],S=m-d[b];m=ze(w,m,S)}let g=c.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-t,y:g.y-n,enabled:{[h]:s,[u]:a}}}}}};function Ce(){return typeof window<"u"}function J(i){return Mt(i)?(i.nodeName||"").toLowerCase():"#document"}function A(i){var e;return(i==null||(e=i.ownerDocument)==null?void 0:e.defaultView)||window}function I(i){var e;return(e=(Mt(i)?i.ownerDocument:i.document)||window.document)==null?void 0:e.documentElement}function Mt(i){return Ce()?i instanceof Node||i instanceof A(i).Node:!1}function T(i){return Ce()?i instanceof Element||i instanceof A(i).Element:!1}function P(i){return Ce()?i instanceof HTMLElement||i instanceof A(i).HTMLElement:!1}function Ht(i){return!Ce()||typeof ShadowRoot>"u"?!1:i instanceof ShadowRoot||i instanceof A(i).ShadowRoot}var zi=new Set(["inline","contents"]);function te(i){let{overflow:e,overflowX:t,overflowY:n,display:o}=H(i);return/auto|scroll|overlay|hidden|clip/.test(e+n+t)&&!zi.has(o)}var Fi=new Set(["table","td","th"]);function Ot(i){return Fi.has(J(i))}var Ni=[":popover-open",":modal"];function de(i){return Ni.some(e=>{try{return i.matches(e)}catch(t){return!1}})}var Di=["transform","translate","scale","rotate","perspective"],ji=["transform","translate","scale","rotate","perspective","filter"],Vi=["paint","layout","strict","content"];function _e(i){let e=Ae(),t=T(i)?H(i):i;return Di.some(n=>t[n]?t[n]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||ji.some(n=>(t.willChange||"").includes(n))||Vi.some(n=>(t.contain||"").includes(n))}function Pt(i){let e=D(i);for(;P(e)&&!X(e);){if(_e(e))return e;if(de(e))return null;e=D(e)}return null}function Ae(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Ui=new Set(["html","body","#document"]);function X(i){return Ui.has(J(i))}function H(i){return A(i).getComputedStyle(i)}function he(i){return T(i)?{scrollLeft:i.scrollLeft,scrollTop:i.scrollTop}:{scrollLeft:i.scrollX,scrollTop:i.scrollY}}function D(i){if(J(i)==="html")return i;let e=i.assignedSlot||i.parentNode||Ht(i)&&i.host||I(i);return Ht(e)?e.host:e}function $t(i){let e=D(i);return X(e)?i.ownerDocument?i.ownerDocument.body:i.body:P(e)&&te(e)?e:$t(e)}function Ee(i,e,t){var n;e===void 0&&(e=[]),t===void 0&&(t=!0);let o=$t(i),r=o===((n=i.ownerDocument)==null?void 0:n.body),s=A(o);if(r){let a=Te(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&t?Ee(a):[])}return e.concat(o,Ee(o,[],t))}function Te(i){return i.parent&&Object.getPrototypeOf(i.parent)?i.frameElement:null}function zt(i){let e=H(i),t=parseFloat(e.width)||0,n=parseFloat(e.height)||0,o=P(i),r=o?i.offsetWidth:t,s=o?i.offsetHeight:n,a=le(t)!==r||le(n)!==s;return a&&(t=r,n=s),{width:t,height:n,$:a}}function Ft(i){return T(i)?i:i.contextElement}function ie(i){let e=Ft(i);if(!P(e))return O(1);let t=e.getBoundingClientRect(),{width:n,height:o,$:r}=zt(e),s=(r?le(t.width):t.width)/n,a=(r?le(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Wi=O(0);function Nt(i){let e=A(i);return!Ae()||!e.visualViewport?Wi:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function qi(i,e,t){return e===void 0&&(e=!1),!t||e&&t!==A(i)?!1:e}function ue(i,e,t,n){e===void 0&&(e=!1),t===void 0&&(t=!1);let o=i.getBoundingClientRect(),r=Ft(i),s=O(1);e&&(n?T(n)&&(s=ie(n)):s=ie(i));let a=qi(r,t,n)?Nt(r):O(0),c=(o.left+a.x)/s.x,p=(o.top+a.y)/s.y,l=o.width/s.x,d=o.height/s.y;if(r){let u=A(r),h=n&&T(n)?A(n):n,f=u,m=Te(f);for(;m&&n&&h!==f;){let g=ie(m),y=m.getBoundingClientRect(),b=H(m),w=y.left+(m.clientLeft+parseFloat(b.paddingLeft))*g.x,S=y.top+(m.clientTop+parseFloat(b.paddingTop))*g.y;c*=g.x,p*=g.y,l*=g.x,d*=g.y,c+=w,p+=S,f=A(m),m=Te(f)}}return G({width:l,height:d,x:c,y:p})}function He(i,e){let t=he(i).scrollLeft;return e?e.left+t:ue(I(i)).left+t}function Dt(i,e){let t=i.getBoundingClientRect(),n=t.left+e.scrollLeft-He(i,t),o=t.top+e.scrollTop;return{x:n,y:o}}function Ki(i){let{elements:e,rect:t,offsetParent:n,strategy:o}=i,r=o==="fixed",s=I(n),a=e?de(e.floating):!1;if(n===s||a&&r)return t;let c={scrollLeft:0,scrollTop:0},p=O(1),l=O(0),d=P(n);if((d||!d&&!r)&&((J(n)!=="body"||te(s))&&(c=he(n)),P(n))){let h=ue(n);p=ie(n),l.x=h.x+n.clientLeft,l.y=h.y+n.clientTop}let u=s&&!d&&!r?Dt(s,c):O(0);return{width:t.width*p.x,height:t.height*p.y,x:t.x*p.x-c.scrollLeft*p.x+l.x+u.x,y:t.y*p.y-c.scrollTop*p.y+l.y+u.y}}function Zi(i){return Array.from(i.getClientRects())}function Qi(i){let e=I(i),t=he(i),n=i.ownerDocument.body,o=U(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),r=U(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),s=-t.scrollLeft+He(i),a=-t.scrollTop;return H(n).direction==="rtl"&&(s+=U(e.clientWidth,n.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Rt=25;function Gi(i,e){let t=A(i),n=I(i),o=t.visualViewport,r=n.clientWidth,s=n.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=Ae();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let p=He(n);if(p<=0){let l=n.ownerDocument,d=l.body,u=getComputedStyle(d),h=l.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(n.clientWidth-d.clientWidth-h);f<=Rt&&(r-=f)}else p<=Rt&&(r+=p);return{width:r,height:s,x:a,y:c}}var Ji=new Set(["absolute","fixed"]);function Xi(i,e){let t=ue(i,!0,e==="fixed"),n=t.top+i.clientTop,o=t.left+i.clientLeft,r=P(i)?ie(i):O(1),s=i.clientWidth*r.x,a=i.clientHeight*r.y,c=o*r.x,p=n*r.y;return{width:s,height:a,x:c,y:p}}function It(i,e,t){let n;if(e==="viewport")n=Gi(i,t);else if(e==="document")n=Qi(I(i));else if(T(e))n=Xi(e,t);else{let o=Nt(i);n={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(n)}function jt(i,e){let t=D(i);return t===e||!T(t)||X(t)?!1:H(t).position==="fixed"||jt(t,e)}function Yi(i,e){let t=e.get(i);if(t)return t;let n=Ee(i,[],!1).filter(a=>T(a)&&J(a)!=="body"),o=null,r=H(i).position==="fixed",s=r?D(i):i;for(;T(s)&&!X(s);){let a=H(s),c=_e(s);!c&&a.position==="fixed"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Ji.has(o.position)||te(s)&&!c&&jt(i,s))?n=n.filter(l=>l!==s):o=a,s=D(s)}return e.set(i,n),n}function en(i){let{element:e,boundary:t,rootBoundary:n,strategy:o}=i,s=[...t==="clippingAncestors"?de(e)?[]:Yi(e,this._c):[].concat(t),n],a=s[0],c=s.reduce((p,l)=>{let d=It(e,l,o);return p.top=U(d.top,p.top),p.right=ae(d.right,p.right),p.bottom=ae(d.bottom,p.bottom),p.left=U(d.left,p.left),p},It(e,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function tn(i){let{width:e,height:t}=zt(i);return{width:e,height:t}}function nn(i,e,t){let n=P(e),o=I(e),r=t==="fixed",s=ue(i,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function p(){c.x=He(o)}if(n||!n&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),n){let h=ue(e,!0,r,e);c.x=h.x+e.clientLeft,c.y=h.y+e.clientTop}else o&&p();r&&!n&&o&&p();let l=o&&!n&&!r?Dt(o,a):O(0),d=s.left+a.scrollLeft-c.x-l.x,u=s.top+a.scrollTop-c.y-l.y;return{x:d,y:u,width:s.width,height:s.height}}function je(i){return H(i).position==="static"}function Bt(i,e){if(!P(i)||H(i).position==="fixed")return null;if(e)return e(i);let t=i.offsetParent;return I(i)===t&&(t=t.ownerDocument.body),t}function Vt(i,e){let t=A(i);if(de(i))return t;if(!P(i)){let o=D(i);for(;o&&!X(o);){if(T(o)&&!je(o))return o;o=D(o)}return t}let n=Bt(i,e);for(;n&&Ot(n)&&je(n);)n=Bt(n,e);return n&&X(n)&&je(n)&&!_e(n)?t:n||Pt(i)||t}var on=async function(i){let e=this.getOffsetParent||Vt,t=this.getDimensions,n=await t(i.floating);return{reference:nn(i.reference,await e(i.floating),i.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function rn(i){return H(i).direction==="rtl"}var sn={convertOffsetParentRelativeRectToViewportRelativeRect:Ki,getDocumentElement:I,getClippingRect:en,getOffsetParent:Vt,getElementRects:on,getClientRects:Zi,getDimensions:tn,getScale:ie,isElement:T,isRTL:rn};var Ut=At;var Wt=Tt,qt=_t;var Kt=(i,e,t)=>{let n=new Map,o={platform:sn,...t},r={...o.platform,_c:n};return Ct(i,e,{...o,platform:r})};var Me=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
904
+ `;)p++;let l=r.slice(c,p);x("insertHeader",`Current line (before): "${l}"`);let d=l.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=t&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${u}, level=${e})`);let m=xe(i,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let b=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${b}"`);let w;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),w=b):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),w=o.prefix+b):(x("insertHeader","ACTION: Adding new header"),w=o.prefix+b),x("insertHeader",`New line: "${w}"`),{text:w,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,y,b,w)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${b}`),x("insertHeader",` - lineStartPos: ${w}`),f){let S=Math.max(y-h,w);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:S,end:y===b?S:Math.max(b-h,w)}}else if(h>0){let S=o.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${S}`),{start:y+S,end:b+S}}else return x("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:y+o.prefix.length,end:b+o.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),j(i,m)}function ut(i){Be(i,1,!0)}function ft(i){Be(i,2,!0)}function mt(i){Be(i,3,!0)}function gt(i){return Ai(i)}var Se=class{constructor(e,t={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=t.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let t=this.createSeparator();this.container.appendChild(t)}else{let t=this.createButton(e);this.buttons[e.name]=t,this.container.appendChild(t)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.setAttribute("data-button",e.name),t.title=e.title||"",t.setAttribute("aria-label",e.title||e.name),t.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(t.classList.add("has-dropdown"),t.dataset.dropdown="true",t.addEventListener("click",n=>{n.preventDefault(),this.toggleViewModeDropdown(t)}),t):(t._clickHandler=n=>{n.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,n)},t.addEventListener("click",t._clickHandler),t)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:t=>this.editor.setValue(t),event:null}),!0}catch(t){return console.error(`Action "${e.name}" error:`,t),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:t}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let n=this.createViewModeDropdown(e),o=e.getBoundingClientRect();n.style.position="absolute",n.style.top=`${o.bottom+5}px`,n.style.left=`${o.left}px`,document.body.appendChild(n),this.handleDocumentClick=r=>{!n.contains(r.target)&&!e.contains(r.target)&&(n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let t=document.createElement("div");t.className="overtype-dropdown-menu";let n=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],o=this.editor.container.dataset.mode||"normal";return n.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===o){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),t.appendChild(s)}),t}updateButtonStates(){var e;try{let t=((e=gt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,o])=>{if(n==="viewMode")return;let r=!1;switch(n){case"bold":r=t.includes("bold");break;case"italic":r=t.includes("italic");break;case"code":r=!1;break;case"bulletList":r=t.includes("bullet-list");break;case"orderedList":r=t.includes("numbered-list");break;case"taskList":r=t.includes("task-list");break;case"quote":r=t.includes("quote");break;case"h1":r=t.includes("header");break;case"h2":r=t.includes("header-2");break;case"h3":r=t.includes("header-3");break}o.classList.toggle("active",r),o.setAttribute("aria-pressed",r.toString())})}catch(t){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var ae=Math.min,U=Math.max,le=Math.round;var O=i=>({x:i,y:i}),Ti={left:"right",right:"left",bottom:"top",top:"bottom"},Hi={start:"end",end:"start"};function ze(i,e,t){return U(i,ae(e,t))}function ce(i,e){return typeof i=="function"?i(e):i}function W(i){return i.split("-")[0]}function pe(i){return i.split("-")[1]}function Fe(i){return i==="x"?"y":"x"}function Ne(i){return i==="y"?"height":"width"}var Mi=new Set(["top","bottom"]);function N(i){return Mi.has(W(i))?"y":"x"}function De(i){return Fe(N(i))}function wt(i,e,t){t===void 0&&(t=!1);let n=pe(i),o=De(i),r=Ne(o),s=o==="x"?n===(t?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=se(s)),[s,se(s)]}function xt(i){let e=se(i);return[Le(i),e,Le(e)]}function Le(i){return i.replace(/start|end/g,e=>Hi[e])}var yt=["left","right"],bt=["right","left"],Oi=["top","bottom"],Pi=["bottom","top"];function $i(i,e,t){switch(i){case"top":case"bottom":return t?e?bt:yt:e?yt:bt;case"left":case"right":return e?Oi:Pi;default:return[]}}function kt(i,e,t,n){let o=pe(i),r=$i(W(i),t==="start",n);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Le)))),r}function se(i){return i.replace(/left|right|bottom|top/g,e=>Ti[e])}function Ri(i){return{top:0,right:0,bottom:0,left:0,...i}}function St(i){return typeof i!="number"?Ri(i):{top:i,right:i,bottom:i,left:i}}function G(i){let{x:e,y:t,width:n,height:o}=i;return{width:n,height:o,top:t,left:e,right:e+n,bottom:t+o,x:e,y:t}}function Lt(i,e,t){let{reference:n,floating:o}=i,r=N(e),s=De(e),a=Ne(s),c=W(e),p=r==="y",l=n.x+n.width/2-o.width/2,d=n.y+n.height/2-o.height/2,u=n[a]/2-o[a]/2,h;switch(c){case"top":h={x:l,y:n.y-o.height};break;case"bottom":h={x:l,y:n.y+n.height};break;case"right":h={x:n.x+n.width,y:d};break;case"left":h={x:n.x-o.width,y:d};break;default:h={x:n.x,y:n.y}}switch(pe(e)){case"start":h[s]-=u*(t&&p?-1:1);break;case"end":h[s]+=u*(t&&p?-1:1);break}return h}async function Et(i,e){var t;e===void 0&&(e={});let{x:n,y:o,platform:r,rects:s,elements:a,strategy:c}=i,{boundary:p="clippingAncestors",rootBoundary:l="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=ce(e,i),f=St(h),g=a[u?d==="floating"?"reference":"floating":d],y=G(await r.getClippingRect({element:(t=await(r.isElement==null?void 0:r.isElement(g)))==null||t?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:p,rootBoundary:l,strategy:c})),b=d==="floating"?{x:n,y:o,width:s.floating.width,height:s.floating.height}:s.reference,w=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),S=await(r.isElement==null?void 0:r.isElement(w))?await(r.getScale==null?void 0:r.getScale(w))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:w,strategy:c}):b);return{top:(y.top-k.top+f.top)/S.y,bottom:(k.bottom-y.bottom+f.bottom)/S.y,left:(y.left-k.left+f.left)/S.x,right:(k.right-y.right+f.right)/S.x}}var Ct=async(i,e,t)=>{let{placement:n="bottom",strategy:o="absolute",middleware:r=[],platform:s}=t,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:i,floating:e,strategy:o}),{x:l,y:d}=Lt(p,n,c),u=n,h={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:b}=a[g],{x:w,y:S,data:k,reset:E}=await b({x:l,y:d,initialPlacement:n,placement:u,strategy:o,middlewareData:h,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Et},elements:{reference:i,floating:e}});l=w!=null?w:l,d=S!=null?S:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:i,floating:e,strategy:o}):E.rects),{x:l,y:d}=Lt(p,u,c)),g=-1)}return{x:l,y:d,placement:u,strategy:o,middlewareData:h}};var _t=function(i){return i===void 0&&(i={}),{name:"flip",options:i,async fn(e){var t,n;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:p}=e,{mainAxis:l=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=ce(i,e);if((t=r.arrow)!=null&&t.alignmentOffset)return{};let y=W(o),b=N(a),w=W(a)===a,S=await(c.isRTL==null?void 0:c.isRTL(p.floating)),k=u||(w||!m?[se(a)]:xt(a)),E=f!=="none";!u&&E&&k.push(...kt(a,m,f,S));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((n=r.flip)==null?void 0:n.overflows)||[];if(l&&ge.push(Y[y]),d){let K=wt(o,s,S);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ge}],!ge.every(K=>K<=0)){var Ue,We;let K=(((Ue=r.flip)==null?void 0:Ue.index)||0)+1,Pe=me[K];if(Pe&&(!(d==="alignment"?b!==N(Pe):!1)||ee.every(M=>N(M.placement)===b?M.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let ne=(We=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,M)=>Z.overflows[1]-M.overflows[1])[0])==null?void 0:We.placement;if(!ne)switch(h){case"bestFit":{var qe;let Z=(qe=ee.filter(M=>{if(E){let V=N(M.placement);return V===b||V==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(V=>V>0).reduce((V,pi)=>V+pi,0)]).sort((M,V)=>M[1]-V[1])[0])==null?void 0:qe[0];Z&&(ne=Z);break}case"initialPlacement":ne=a;break}if(o!==ne)return{reset:{placement:ne}}}return{}}}};var Ii=new Set(["left","top"]);async function Bi(i,e){let{placement:t,platform:n,elements:o}=i,r=await(n.isRTL==null?void 0:n.isRTL(o.floating)),s=W(t),a=pe(t),c=N(t)==="y",p=Ii.has(s)?-1:1,l=r&&c?-1:1,d=ce(e,i),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),c?{x:h*l,y:u*p}:{x:u*p,y:h*l}}var At=function(i){return i===void 0&&(i=0),{name:"offset",options:i,async fn(e){var t,n;let{x:o,y:r,placement:s,middlewareData:a}=e,c=await Bi(e,i);return s===((t=a.offset)==null?void 0:t.placement)&&(n=a.arrow)!=null&&n.alignmentOffset?{}:{x:o+c.x,y:r+c.y,data:{...c,placement:s}}}}},Tt=function(i){return i===void 0&&(i={}),{name:"shift",options:i,async fn(e){let{x:t,y:n,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:b,y:w}=y;return{x:b,y:w}}},...p}=ce(i,e),l={x:t,y:n},d=await r.detectOverflow(e,p),u=N(W(o)),h=Fe(u),f=l[h],m=l[u];if(s){let y=h==="y"?"top":"left",b=h==="y"?"bottom":"right",w=f+d[y],S=f-d[b];f=ze(w,f,S)}if(a){let y=u==="y"?"top":"left",b=u==="y"?"bottom":"right",w=m+d[y],S=m-d[b];m=ze(w,m,S)}let g=c.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-t,y:g.y-n,enabled:{[h]:s,[u]:a}}}}}};function Ce(){return typeof window<"u"}function J(i){return Mt(i)?(i.nodeName||"").toLowerCase():"#document"}function A(i){var e;return(i==null||(e=i.ownerDocument)==null?void 0:e.defaultView)||window}function I(i){var e;return(e=(Mt(i)?i.ownerDocument:i.document)||window.document)==null?void 0:e.documentElement}function Mt(i){return Ce()?i instanceof Node||i instanceof A(i).Node:!1}function T(i){return Ce()?i instanceof Element||i instanceof A(i).Element:!1}function P(i){return Ce()?i instanceof HTMLElement||i instanceof A(i).HTMLElement:!1}function Ht(i){return!Ce()||typeof ShadowRoot>"u"?!1:i instanceof ShadowRoot||i instanceof A(i).ShadowRoot}var zi=new Set(["inline","contents"]);function te(i){let{overflow:e,overflowX:t,overflowY:n,display:o}=H(i);return/auto|scroll|overlay|hidden|clip/.test(e+n+t)&&!zi.has(o)}var Fi=new Set(["table","td","th"]);function Ot(i){return Fi.has(J(i))}var Ni=[":popover-open",":modal"];function de(i){return Ni.some(e=>{try{return i.matches(e)}catch(t){return!1}})}var Di=["transform","translate","scale","rotate","perspective"],Vi=["transform","translate","scale","rotate","perspective","filter"],ji=["paint","layout","strict","content"];function _e(i){let e=Ae(),t=T(i)?H(i):i;return Di.some(n=>t[n]?t[n]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||Vi.some(n=>(t.willChange||"").includes(n))||ji.some(n=>(t.contain||"").includes(n))}function Pt(i){let e=D(i);for(;P(e)&&!X(e);){if(_e(e))return e;if(de(e))return null;e=D(e)}return null}function Ae(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Ui=new Set(["html","body","#document"]);function X(i){return Ui.has(J(i))}function H(i){return A(i).getComputedStyle(i)}function he(i){return T(i)?{scrollLeft:i.scrollLeft,scrollTop:i.scrollTop}:{scrollLeft:i.scrollX,scrollTop:i.scrollY}}function D(i){if(J(i)==="html")return i;let e=i.assignedSlot||i.parentNode||Ht(i)&&i.host||I(i);return Ht(e)?e.host:e}function $t(i){let e=D(i);return X(e)?i.ownerDocument?i.ownerDocument.body:i.body:P(e)&&te(e)?e:$t(e)}function Ee(i,e,t){var n;e===void 0&&(e=[]),t===void 0&&(t=!0);let o=$t(i),r=o===((n=i.ownerDocument)==null?void 0:n.body),s=A(o);if(r){let a=Te(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&t?Ee(a):[])}return e.concat(o,Ee(o,[],t))}function Te(i){return i.parent&&Object.getPrototypeOf(i.parent)?i.frameElement:null}function zt(i){let e=H(i),t=parseFloat(e.width)||0,n=parseFloat(e.height)||0,o=P(i),r=o?i.offsetWidth:t,s=o?i.offsetHeight:n,a=le(t)!==r||le(n)!==s;return a&&(t=r,n=s),{width:t,height:n,$:a}}function Ft(i){return T(i)?i:i.contextElement}function ie(i){let e=Ft(i);if(!P(e))return O(1);let t=e.getBoundingClientRect(),{width:n,height:o,$:r}=zt(e),s=(r?le(t.width):t.width)/n,a=(r?le(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Wi=O(0);function Nt(i){let e=A(i);return!Ae()||!e.visualViewport?Wi:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function qi(i,e,t){return e===void 0&&(e=!1),!t||e&&t!==A(i)?!1:e}function ue(i,e,t,n){e===void 0&&(e=!1),t===void 0&&(t=!1);let o=i.getBoundingClientRect(),r=Ft(i),s=O(1);e&&(n?T(n)&&(s=ie(n)):s=ie(i));let a=qi(r,t,n)?Nt(r):O(0),c=(o.left+a.x)/s.x,p=(o.top+a.y)/s.y,l=o.width/s.x,d=o.height/s.y;if(r){let u=A(r),h=n&&T(n)?A(n):n,f=u,m=Te(f);for(;m&&n&&h!==f;){let g=ie(m),y=m.getBoundingClientRect(),b=H(m),w=y.left+(m.clientLeft+parseFloat(b.paddingLeft))*g.x,S=y.top+(m.clientTop+parseFloat(b.paddingTop))*g.y;c*=g.x,p*=g.y,l*=g.x,d*=g.y,c+=w,p+=S,f=A(m),m=Te(f)}}return G({width:l,height:d,x:c,y:p})}function He(i,e){let t=he(i).scrollLeft;return e?e.left+t:ue(I(i)).left+t}function Dt(i,e){let t=i.getBoundingClientRect(),n=t.left+e.scrollLeft-He(i,t),o=t.top+e.scrollTop;return{x:n,y:o}}function Ki(i){let{elements:e,rect:t,offsetParent:n,strategy:o}=i,r=o==="fixed",s=I(n),a=e?de(e.floating):!1;if(n===s||a&&r)return t;let c={scrollLeft:0,scrollTop:0},p=O(1),l=O(0),d=P(n);if((d||!d&&!r)&&((J(n)!=="body"||te(s))&&(c=he(n)),P(n))){let h=ue(n);p=ie(n),l.x=h.x+n.clientLeft,l.y=h.y+n.clientTop}let u=s&&!d&&!r?Dt(s,c):O(0);return{width:t.width*p.x,height:t.height*p.y,x:t.x*p.x-c.scrollLeft*p.x+l.x+u.x,y:t.y*p.y-c.scrollTop*p.y+l.y+u.y}}function Zi(i){return Array.from(i.getClientRects())}function Qi(i){let e=I(i),t=he(i),n=i.ownerDocument.body,o=U(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),r=U(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),s=-t.scrollLeft+He(i),a=-t.scrollTop;return H(n).direction==="rtl"&&(s+=U(e.clientWidth,n.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Rt=25;function Gi(i,e){let t=A(i),n=I(i),o=t.visualViewport,r=n.clientWidth,s=n.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=Ae();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let p=He(n);if(p<=0){let l=n.ownerDocument,d=l.body,u=getComputedStyle(d),h=l.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(n.clientWidth-d.clientWidth-h);f<=Rt&&(r-=f)}else p<=Rt&&(r+=p);return{width:r,height:s,x:a,y:c}}var Ji=new Set(["absolute","fixed"]);function Xi(i,e){let t=ue(i,!0,e==="fixed"),n=t.top+i.clientTop,o=t.left+i.clientLeft,r=P(i)?ie(i):O(1),s=i.clientWidth*r.x,a=i.clientHeight*r.y,c=o*r.x,p=n*r.y;return{width:s,height:a,x:c,y:p}}function It(i,e,t){let n;if(e==="viewport")n=Gi(i,t);else if(e==="document")n=Qi(I(i));else if(T(e))n=Xi(e,t);else{let o=Nt(i);n={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(n)}function Vt(i,e){let t=D(i);return t===e||!T(t)||X(t)?!1:H(t).position==="fixed"||Vt(t,e)}function Yi(i,e){let t=e.get(i);if(t)return t;let n=Ee(i,[],!1).filter(a=>T(a)&&J(a)!=="body"),o=null,r=H(i).position==="fixed",s=r?D(i):i;for(;T(s)&&!X(s);){let a=H(s),c=_e(s);!c&&a.position==="fixed"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Ji.has(o.position)||te(s)&&!c&&Vt(i,s))?n=n.filter(l=>l!==s):o=a,s=D(s)}return e.set(i,n),n}function en(i){let{element:e,boundary:t,rootBoundary:n,strategy:o}=i,s=[...t==="clippingAncestors"?de(e)?[]:Yi(e,this._c):[].concat(t),n],a=s[0],c=s.reduce((p,l)=>{let d=It(e,l,o);return p.top=U(d.top,p.top),p.right=ae(d.right,p.right),p.bottom=ae(d.bottom,p.bottom),p.left=U(d.left,p.left),p},It(e,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function tn(i){let{width:e,height:t}=zt(i);return{width:e,height:t}}function nn(i,e,t){let n=P(e),o=I(e),r=t==="fixed",s=ue(i,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function p(){c.x=He(o)}if(n||!n&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),n){let h=ue(e,!0,r,e);c.x=h.x+e.clientLeft,c.y=h.y+e.clientTop}else o&&p();r&&!n&&o&&p();let l=o&&!n&&!r?Dt(o,a):O(0),d=s.left+a.scrollLeft-c.x-l.x,u=s.top+a.scrollTop-c.y-l.y;return{x:d,y:u,width:s.width,height:s.height}}function Ve(i){return H(i).position==="static"}function Bt(i,e){if(!P(i)||H(i).position==="fixed")return null;if(e)return e(i);let t=i.offsetParent;return I(i)===t&&(t=t.ownerDocument.body),t}function jt(i,e){let t=A(i);if(de(i))return t;if(!P(i)){let o=D(i);for(;o&&!X(o);){if(T(o)&&!Ve(o))return o;o=D(o)}return t}let n=Bt(i,e);for(;n&&Ot(n)&&Ve(n);)n=Bt(n,e);return n&&X(n)&&Ve(n)&&!_e(n)?t:n||Pt(i)||t}var on=async function(i){let e=this.getOffsetParent||jt,t=this.getDimensions,n=await t(i.floating);return{reference:nn(i.reference,await e(i.floating),i.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function rn(i){return H(i).direction==="rtl"}var sn={convertOffsetParentRelativeRectToViewportRelativeRect:Ki,getDocumentElement:I,getClippingRect:en,getOffsetParent:jt,getElementRects:on,getClientRects:Zi,getDimensions:tn,getScale:ie,isElement:T,isRTL:rn};var Ut=At;var Wt=Tt,qt=_t;var Kt=(i,e,t)=>{let n=new Map,o={platform:sn,...t},r={...o.platform,_c:n};return Ct(i,e,{...o,platform:r})};var Me=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
914
905
  <span style="display: flex; align-items: center; gap: 6px;">
915
906
  <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
916
907
  <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>
@@ -971,7 +962,7 @@ ${a}`:r;if(p){let k=i.value[i.selectionStart-1];i.selectionStart!==0&&k!=null&&!
971
962
  </svg>`,si=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
972
963
  <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path>
973
964
  <circle cx="12" cy="12" r="3" fill="none"></circle>
974
- </svg>`;var L={bold:{name:"bold",actionId:"toggleBold",icon:Zt,title:"Bold (Ctrl+B)",action:({editor:i})=>{st(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Qt,title:"Italic (Ctrl+I)",action:({editor:i})=>{at(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:ei,title:"Inline Code",action:({editor:i})=>{lt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Yt,title:"Insert Link",action:({editor:i})=>{ct(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:Gt,title:"Heading 1",action:({editor:i})=>{ut(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Jt,title:"Heading 2",action:({editor:i})=>{ft(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Xt,title:"Heading 3",action:({editor:i})=>{mt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:ti,title:"Bullet List",action:({editor:i})=>{pt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:ii,title:"Numbered List",action:({editor:i})=>{dt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:oi,title:"Task List",action:({editor:i})=>{Ie&&(Ie(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:ni,title:"Quote",action:({editor:i})=>{ht(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:ri,title:"Upload File",action:({editor:i})=>{var t,n;if(!((t=i.options.fileUpload)!=null&&t.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((n=i.options.fileUpload.mimeTypes)==null?void 0:n.length)>0&&(e.accept=i.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let o=new DataTransfer;for(let s of e.files)o.items.add(s);i._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:si,title:"View mode"}},fe=[L.bold,L.italic,L.code,L.separator,L.link,L.separator,L.h1,L.h2,L.h3,L.separator,L.bulletList,L.orderedList,L.taskList,L.separator,L.quote,L.separator,L.viewMode];function Ve(i){let e={};return(i||[]).forEach(t=>{if(!t||t.name==="separator")return;let n=t.actionId||t.name;t.action&&(e[n]=t.action)}),e}function ai(i){let e=i||fe;return Array.isArray(e)?e.map(t=>({name:(t==null?void 0:t.name)||null,actionId:(t==null?void 0:t.actionId)||(t==null?void 0:t.name)||null,icon:(t==null?void 0:t.icon)||null,title:(t==null?void 0:t.title)||null})):null}function ln(i,e){let t=ai(i),n=ai(e);if(t===null||n===null)return t!==n;if(t.length!==n.length)return!0;for(let o=0;o<t.length;o++){let r=t[o],s=n[o];if(r.name!==s.name||r.actionId!==s.actionId||r.icon!==s.icon||r.title!==s.title)return!0}return!1}var v=class v{constructor(e,t={}){let n;if(typeof e=="string"){if(n=document.querySelectorAll(e),n.length===0)throw new Error(`No elements found for selector: ${e}`);n=Array.from(n)}else if(e instanceof Element)n=[e];else if(e instanceof NodeList)n=Array.from(e);else if(Array.isArray(e))n=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return n.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(t),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,t),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.initGlobalListeners();let n=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");n||o?this._recoverFromDOM(n,o):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new oe(this),this._rebuildActionsMap(),this.linkTooltip=new Me(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_mergeOptions(e){let t={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,onRender:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:n,colors:o,...r}=e;return{...t,...r}}_recoverFromDOM(e,t){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(t){this.wrapper=t,this.container=document.createElement("div"),this.container.className="overtype-container";let n=this.instanceTheme||v.currentTheme||B,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?$(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}t.parentNode.insertBefore(this.container,t),this.container.appendChild(t)}if(!this.wrapper){e&&e.remove(),t&&t.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||v.currentTheme||B,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let n=typeof this.instanceTheme=="string"?$(this.instanceTheme):this.instanceTheme;if(n&&n.colors){let o=Q(n.colors);this.container.style.cssText+=o}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([n,o])=>{n==="className"||n==="class"?this.textarea.className+=" "+o:n==="style"&&typeof o=="object"?Object.assign(this.textarea.style,o):this.textarea.setAttribute(n,o)}),this.preview=document.createElement("div"),this.preview.className="overtype-preview",this.preview.setAttribute("aria-hidden","true"),this.placeholderEl=document.createElement("div"),this.placeholderEl.className="overtype-placeholder",this.placeholderEl.setAttribute("aria-hidden","true"),this.placeholderEl.textContent=this.options.placeholder,this.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),this.wrapper.appendChild(this.placeholderEl),this.container.appendChild(this.wrapper),this.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()),this.element.appendChild(this.container),this.options.autoResize?this._setupAutoResize():this.container.classList.remove("overtype-auto-resize")}_configureTextarea(){this.textarea.setAttribute("autocomplete","off"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck",String(this.options.spellcheck)),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_createToolbar(){var t;let e=this.options.toolbarButtons||fe;if((t=this.options.fileUpload)!=null&&t.enabled&&!e.some(n=>(n==null?void 0:n.name)==="upload")){let n=e.findIndex(o=>(o==null?void 0:o.name)==="viewMode");n!==-1?(e=[...e],e.splice(n,0,L.separator,L.upload)):e=[...e,L.separator,L.upload]}this.toolbar=new Se(this,{toolbarButtons:e}),this.toolbar.create(),this._toolbarSelectionListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this._toolbarInputListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this.textarea.addEventListener("selectionchange",this._toolbarSelectionListener),this.textarea.addEventListener("input",this._toolbarInputListener)}_cleanupToolbarListeners(){this._toolbarSelectionListener&&(this.textarea.removeEventListener("selectionchange",this._toolbarSelectionListener),this._toolbarSelectionListener=null),this._toolbarInputListener&&(this.textarea.removeEventListener("input",this._toolbarInputListener),this._toolbarInputListener=null)}_rebuildActionsMap(){var e;this.actionsById=Ve(fe),this.options.toolbarButtons&&Object.assign(this.actionsById,Ve(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,Ve([L.upload]))}_applyOptions(){this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_handleFilePaste(e){var t,n;(n=(t=e==null?void 0:e.clipboardData)==null?void 0:t.files)!=null&&n.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var t,n;(n=(t=e==null?void 0:e.dataTransfer)==null?void 0:t.files)!=null&&n.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let t=[];for(let n of e.files){if(n.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(n.type))continue;let o=++this._fileUploadCounter,s=`${n.type.startsWith("image/")?"!":""}[Uploading ${n.name} (#${o})...]()`;if(this.insertAtCursor(`${s}
965
+ </svg>`;var L={bold:{name:"bold",actionId:"toggleBold",icon:Zt,title:"Bold (Ctrl+B)",action:({editor:i})=>{st(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Qt,title:"Italic (Ctrl+I)",action:({editor:i})=>{at(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:ei,title:"Inline Code",action:({editor:i})=>{lt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Yt,title:"Insert Link",action:({editor:i})=>{ct(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:Gt,title:"Heading 1",action:({editor:i})=>{ut(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Jt,title:"Heading 2",action:({editor:i})=>{ft(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Xt,title:"Heading 3",action:({editor:i})=>{mt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:ti,title:"Bullet List",action:({editor:i})=>{pt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:ii,title:"Numbered List",action:({editor:i})=>{dt(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:oi,title:"Task List",action:({editor:i})=>{Ie&&(Ie(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:ni,title:"Quote",action:({editor:i})=>{ht(i.textarea),i.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:ri,title:"Upload File",action:({editor:i})=>{var t,n;if(!((t=i.options.fileUpload)!=null&&t.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((n=i.options.fileUpload.mimeTypes)==null?void 0:n.length)>0&&(e.accept=i.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let o=new DataTransfer;for(let s of e.files)o.items.add(s);i._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:si,title:"View mode"}},fe=[L.bold,L.italic,L.code,L.separator,L.link,L.separator,L.h1,L.h2,L.h3,L.separator,L.bulletList,L.orderedList,L.taskList,L.separator,L.quote,L.separator,L.viewMode];function je(i){let e={};return(i||[]).forEach(t=>{if(!t||t.name==="separator")return;let n=t.actionId||t.name;t.action&&(e[n]=t.action)}),e}function ai(i){let e=i||fe;return Array.isArray(e)?e.map(t=>({name:(t==null?void 0:t.name)||null,actionId:(t==null?void 0:t.actionId)||(t==null?void 0:t.name)||null,icon:(t==null?void 0:t.icon)||null,title:(t==null?void 0:t.title)||null})):null}function ln(i,e){let t=ai(i),n=ai(e);if(t===null||n===null)return t!==n;if(t.length!==n.length)return!0;for(let o=0;o<t.length;o++){let r=t[o],s=n[o];if(r.name!==s.name||r.actionId!==s.actionId||r.icon!==s.icon||r.title!==s.title)return!0}return!1}var v=class v{constructor(e,t={}){let n;if(typeof e=="string"){if(n=document.querySelectorAll(e),n.length===0)throw new Error(`No elements found for selector: ${e}`);n=Array.from(n)}else if(e instanceof Element)n=[e];else if(e instanceof NodeList)n=Array.from(e);else if(Array.isArray(e))n=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return n.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(t),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,t),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,t={}){this.element=e,this.instanceTheme=t.theme||null,this.options=this._mergeOptions(t),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.initGlobalListeners();let n=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");n||o?this._recoverFromDOM(n,o):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new oe(this),this._rebuildActionsMap(),this.linkTooltip=new Me(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_mergeOptions(e){let t={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,onRender:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:n,colors:o,...r}=e;return{...t,...r}}_recoverFromDOM(e,t){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(t){this.wrapper=t,this.container=document.createElement("div"),this.container.className="overtype-container";let n=this.instanceTheme||v.currentTheme||B,o=typeof n=="string"?n:n.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?$(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}t.parentNode.insertBefore(this.container,t),this.container.appendChild(t)}if(!this.wrapper){e&&e.remove(),t&&t.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this._applyInstanceCSSVars(),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||v.currentTheme||B,t=typeof e=="string"?e:e.name;if(t&&this.container.setAttribute("data-theme",t),this.instanceTheme){let n=typeof this.instanceTheme=="string"?$(this.instanceTheme):this.instanceTheme;if(n&&n.colors){let o=Q(n.colors);this.container.style.cssText+=o}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this._applyInstanceCSSVars(),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([n,o])=>{n==="className"||n==="class"?this.textarea.className+=" "+o:n==="style"&&typeof o=="object"?Object.assign(this.textarea.style,o):this.textarea.setAttribute(n,o)}),this.preview=document.createElement("div"),this.preview.className="overtype-preview",this.preview.setAttribute("aria-hidden","true"),this.placeholderEl=document.createElement("div"),this.placeholderEl.className="overtype-placeholder",this.placeholderEl.setAttribute("aria-hidden","true"),this.placeholderEl.textContent=this.options.placeholder,this.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),this.wrapper.appendChild(this.placeholderEl),this.container.appendChild(this.wrapper),this.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()),this.element.appendChild(this.container),this.options.autoResize?this._setupAutoResize():this.container.classList.remove("overtype-auto-resize")}_configureTextarea(){this.textarea.setAttribute("autocomplete","off"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck",String(this.options.spellcheck)),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_createToolbar(){var t;let e=this.options.toolbarButtons||fe;if((t=this.options.fileUpload)!=null&&t.enabled&&!e.some(n=>(n==null?void 0:n.name)==="upload")){let n=e.findIndex(o=>(o==null?void 0:o.name)==="viewMode");n!==-1?(e=[...e],e.splice(n,0,L.separator,L.upload)):e=[...e,L.separator,L.upload]}this.toolbar=new Se(this,{toolbarButtons:e}),this.toolbar.create(),this._toolbarSelectionListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this._toolbarInputListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this.textarea.addEventListener("selectionchange",this._toolbarSelectionListener),this.textarea.addEventListener("input",this._toolbarInputListener)}_cleanupToolbarListeners(){this._toolbarSelectionListener&&(this.textarea.removeEventListener("selectionchange",this._toolbarSelectionListener),this._toolbarSelectionListener=null),this._toolbarInputListener&&(this.textarea.removeEventListener("input",this._toolbarInputListener),this._toolbarInputListener=null)}_rebuildActionsMap(){var e;this.actionsById=je(fe),this.options.toolbarButtons&&Object.assign(this.actionsById,je(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,je([L.upload]))}_applyInstanceCSSVars(){this.wrapper&&(this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.options.fontFamily&&this.wrapper.style.setProperty("--instance-font-family",this.options.fontFamily))}_applyOptions(){this._applyInstanceCSSVars(),this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_handleFilePaste(e){var t,n;(n=(t=e==null?void 0:e.clipboardData)==null?void 0:t.files)!=null&&n.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var t,n;(n=(t=e==null?void 0:e.dataTransfer)==null?void 0:t.files)!=null&&n.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let t=[];for(let n of e.files){if(n.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(n.type))continue;let o=++this._fileUploadCounter,s=`${n.type.startsWith("image/")?"!":""}[Uploading ${n.name} (#${o})...]()`;if(this.insertAtCursor(`${s}
975
966
  `),this.options.fileUpload.batch){t.push({file:n,placeholder:s});continue}this.options.fileUpload.onInsertFile(n).then(a=>{this.textarea.value=this.textarea.value.replace(s,a),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},a=>{console.error("OverType: File upload failed",a),this.textarea.value=this.textarea.value.replace(s,"[Upload failed]()"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}this.options.fileUpload.batch&&t.length>0&&this.options.fileUpload.onInsertFile(t.map(n=>n.file)).then(n=>{(Array.isArray(n)?n:[n]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(t[s].placeholder,r)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},n=>{console.error("OverType: File upload failed",n),t.forEach(({placeholder:o})=>{this.textarea.value=this.textarea.value.replace(o,"[Upload failed]()")}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}_handleDragOver(e){e.preventDefault()}_destroyFileUpload(){this.textarea.removeEventListener("paste",this._boundHandleFilePaste),this.textarea.removeEventListener("drop",this._boundHandleFileDrop),this.textarea.removeEventListener("dragover",this._boundHandleDragOver),this._boundHandleFilePaste=null,this._boundHandleFileDrop=null,this._boundHandleDragOver=null,this.fileUploadInitialized=!1}insertAtCursor(e){let t=this.textarea.selectionStart,n=this.textarea.selectionEnd,o=!1;try{o=document.execCommand("insertText",!1,e)}catch(r){}if(!o){let r=this.textarea.value.slice(0,t),s=this.textarea.value.slice(n);this.textarea.value=r+e+s,this.textarea.setSelectionRange(t+e.length,t+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,t=this.textarea.selectionStart,n=this._getCurrentLine(e,t),o=this.container.dataset.mode==="preview",r=C.parse(e,n,this.options.showActiveLineRaw,this.options.codeHighlighter,o);this.preview.innerHTML=r,this.placeholderEl&&(this.placeholderEl.style.display=e?"none":""),this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onChange&&this.initialized&&this.options.onChange(e,this),this.options.onRender&&this.options.onRender(this.preview,o?"preview":"normal",this)}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let t=0;t<e.length-1;t+=2){let n=e[t],o=e[t+1],r=n.parentElement,s=o.parentElement;!r||!s||(n.style.display="block",o.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,t){return e.substring(0,t).split(`
976
967
  `).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){if(e.key==="Tab"){let n=this.textarea.selectionStart,o=this.textarea.selectionEnd,r=this.textarea.value;if(e.shiftKey&&n===o)return;if(e.preventDefault(),n!==o&&e.shiftKey){let s=r.substring(0,n),a=r.substring(n,o),c=r.substring(o),l=a.split(`
977
968
  `).map(d=>d.replace(/^ /,"")).join(`
package/dist/overtype.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.3.5
2
+ * OverType v2.3.6
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -1132,9 +1132,9 @@ function generateStyles(options = {}) {
1132
1132
  left: 0 !important;
1133
1133
  width: 100% !important;
1134
1134
  height: 100% !important;
1135
-
1135
+
1136
1136
  /* Font properties - any difference breaks alignment */
1137
- font-family: ${fontFamily} !important;
1137
+ font-family: var(--instance-font-family, ${fontFamily}) !important;
1138
1138
  font-variant-ligatures: none !important; /* keep metrics stable for code */
1139
1139
  font-size: var(--instance-font-size, ${fontSize}) !important;
1140
1140
  line-height: var(--instance-line-height, ${lineHeight}) !important;
@@ -1241,15 +1241,12 @@ function generateStyles(options = {}) {
1241
1241
  z-index: 0 !important;
1242
1242
  pointer-events: none !important;
1243
1243
  user-select: none !important;
1244
- font-family: ${fontFamily} !important;
1244
+ font-family: var(--instance-font-family, ${fontFamily}) !important;
1245
1245
  font-size: var(--instance-font-size, ${fontSize}) !important;
1246
1246
  line-height: var(--instance-line-height, ${lineHeight}) !important;
1247
1247
  padding: var(--instance-padding, ${padding}) !important;
1248
1248
  box-sizing: border-box !important;
1249
1249
  color: var(--placeholder, #999) !important;
1250
- overflow: hidden !important;
1251
- white-space: nowrap !important;
1252
- text-overflow: ellipsis !important;
1253
1250
  }
1254
1251
 
1255
1252
  /* Preview layer styles */
@@ -1402,7 +1399,7 @@ function generateStyles(options = {}) {
1402
1399
  .overtype-wrapper .overtype-preview pre code {
1403
1400
  background: transparent !important;
1404
1401
  color: var(--code, #0d3b66) !important;
1405
- font-family: ${fontFamily} !important; /* Match textarea font exactly for alignment */
1402
+ font-family: var(--instance-font-family, ${fontFamily}) !important; /* Match textarea font exactly for alignment */
1406
1403
  }
1407
1404
 
1408
1405
  /* Blockquotes */
@@ -1487,26 +1484,20 @@ function generateStyles(options = {}) {
1487
1484
  .overtype-stats {
1488
1485
  height: 40px !important;
1489
1486
  padding: 0 20px !important;
1490
- background: #f8f9fa !important;
1491
- border-top: 1px solid #e0e0e0 !important;
1487
+ background: var(--bg-secondary, #f8f9fa) !important;
1488
+ border-top: 1px solid var(--border, #e0e0e0) !important;
1492
1489
  display: flex !important;
1493
1490
  justify-content: space-between !important;
1494
1491
  align-items: center !important;
1495
1492
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
1496
1493
  font-size: 0.85rem !important;
1497
- color: #666 !important;
1494
+ color: var(--text-secondary, #666) !important;
1498
1495
  flex-shrink: 0 !important; /* Don't shrink */
1499
1496
  z-index: 10001 !important; /* Above link tooltip */
1500
1497
  position: relative !important; /* Enable z-index */
1501
1498
  }
1502
-
1503
- /* Dark theme stats bar */
1504
- .overtype-container[data-theme="cave"] .overtype-stats {
1505
- background: var(--bg-secondary, #1D2D3E) !important;
1506
- border-top: 1px solid rgba(197, 221, 232, 0.1) !important;
1507
- color: var(--text, #c5dde8) !important;
1508
- }
1509
-
1499
+
1500
+
1510
1501
  .overtype-stats .overtype-stat {
1511
1502
  display: flex !important;
1512
1503
  align-items: center !important;
@@ -4851,15 +4842,7 @@ var _OverType = class _OverType {
4851
4842
  return;
4852
4843
  }
4853
4844
  this.wrapper._instance = this;
4854
- if (this.options.fontSize) {
4855
- this.wrapper.style.setProperty("--instance-font-size", this.options.fontSize);
4856
- }
4857
- if (this.options.lineHeight) {
4858
- this.wrapper.style.setProperty("--instance-line-height", String(this.options.lineHeight));
4859
- }
4860
- if (this.options.padding) {
4861
- this.wrapper.style.setProperty("--instance-padding", this.options.padding);
4862
- }
4845
+ this._applyInstanceCSSVars();
4863
4846
  this._configureTextarea();
4864
4847
  this._applyOptions();
4865
4848
  }
@@ -4907,15 +4890,7 @@ var _OverType = class _OverType {
4907
4890
  }
4908
4891
  this.wrapper = document.createElement("div");
4909
4892
  this.wrapper.className = "overtype-wrapper";
4910
- if (this.options.fontSize) {
4911
- this.wrapper.style.setProperty("--instance-font-size", this.options.fontSize);
4912
- }
4913
- if (this.options.lineHeight) {
4914
- this.wrapper.style.setProperty("--instance-line-height", String(this.options.lineHeight));
4915
- }
4916
- if (this.options.padding) {
4917
- this.wrapper.style.setProperty("--instance-padding", this.options.padding);
4918
- }
4893
+ this._applyInstanceCSSVars();
4919
4894
  this.wrapper._instance = this;
4920
4895
  this.textarea = document.createElement("textarea");
4921
4896
  this.textarea.className = "overtype-input";
@@ -5029,11 +5004,34 @@ var _OverType = class _OverType {
5029
5004
  Object.assign(this.actionsById, buildActionsMap([toolbarButtons.upload]));
5030
5005
  }
5031
5006
  }
5007
+ /**
5008
+ * Apply instance-specific styles via CSS custom properties on the wrapper.
5009
+ * Called from init paths and from _applyOptions so reinit() propagates
5010
+ * font/padding changes.
5011
+ * @private
5012
+ */
5013
+ _applyInstanceCSSVars() {
5014
+ if (!this.wrapper)
5015
+ return;
5016
+ if (this.options.fontSize) {
5017
+ this.wrapper.style.setProperty("--instance-font-size", this.options.fontSize);
5018
+ }
5019
+ if (this.options.lineHeight) {
5020
+ this.wrapper.style.setProperty("--instance-line-height", String(this.options.lineHeight));
5021
+ }
5022
+ if (this.options.padding) {
5023
+ this.wrapper.style.setProperty("--instance-padding", this.options.padding);
5024
+ }
5025
+ if (this.options.fontFamily) {
5026
+ this.wrapper.style.setProperty("--instance-font-family", this.options.fontFamily);
5027
+ }
5028
+ }
5032
5029
  /**
5033
5030
  * Apply options to the editor
5034
5031
  * @private
5035
5032
  */
5036
5033
  _applyOptions() {
5034
+ this._applyInstanceCSSVars();
5037
5035
  if (this.options.autofocus) {
5038
5036
  this.textarea.focus();
5039
5037
  }