overtype 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.3.0
2
+ * OverType v2.3.2
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -12,7 +12,7 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
12
12
  `),p=s.slice(3).trim(),h=p?` class="language-${p}"`:"",u=l,f=n||this.codeHighlighter;if(f)try{let g=l.replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),y=f(g,p);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(u=y)}catch(g){console.warn("Code highlighting failed:",g)}let m=`<div><span class="code-fence">${s}</span></div>`;return m+=`<pre class="code-block"><code${h}>${u}</code></pre>`,m+=`<div><span class="code-fence">${c}</span></div>`,m}),o}static getListContext(e,n){let o=e.split(`
13
13
  `),i=0,r=0,s=0;for(let h=0;h<o.length;h++){let u=o[h].length;if(i+u>=n){r=h,s=i;break}i+=u+1}let a=o[r],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let n=e.split(`
14
14
  `),o=new Map,i=!1;return n.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let c=a[1],d=c.length,l=a[3];i||o.clear();let p=(o.get(d)||0)+1;o.set(d,p);for(let[h]of o)h>d&&o.delete(h);return i=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(i=!1,o.clear()),s}).join(`
15
- `)}};C(T,"linkIndex",0),C(T,"codeHighlighter",null),C(T,"customSyntax",null),C(T,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.performAction(i,e),!0):!1}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#1a1a1a",h1:"#1a1a1a",h2:"#2a2a2a",h3:"#3a3a3a",strong:"inherit",em:"inherit",link:"#0066cc",code:"#1a1a1a",codeBg:"rgba(135, 131, 120, 0.15)",blockquote:"#555",hr:"#ddd",bg:"transparent"}},We={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"},previewColors:{text:"#c5dde8",h1:"#e0e0e0",h2:"#d0d0d0",h3:"#c0c0c0",strong:"inherit",em:"inherit",link:"#6cb6e0",code:"#c5dde8",codeBg:"rgba(255, 255, 255, 0.08)",blockquote:"#9aa8b4",hr:"rgba(255, 255, 255, 0.15)",bg:"transparent"}},qe={solar:B,cave:We,auto:B,light:B,dark:We};function V(t){return typeof t=="string"?{...qe[t]||qe.solar,name:t}:t}function Pe(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t,e){let n=[];for(let[o,i]of Object.entries(t)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--${r}: ${i};`)}if(e)for(let[o,i]of Object.entries(e)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--preview-${r}: ${i};`)}return n.join(`
15
+ `)}};C(T,"linkIndex",0),C(T,"codeHighlighter",null),C(T,"customSyntax",null),C(T,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let i=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(i="toggleBold");break;case"i":e.shiftKey||(i="toggleItalic");break;case"k":e.shiftKey||(i="insertLink");break;case"7":e.shiftKey&&(i="toggleNumberedList");break;case"8":e.shiftKey&&(i="toggleBulletList");break}return i?(e.preventDefault(),this.editor.performAction(i,e),!0):!1}destroy(){}};var B={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#0d3b66",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",bg:"transparent"}},qe={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"},previewColors:{text:"#c5dde8",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",bg:"transparent"}},We={solar:B,cave:qe,auto:B,light:B,dark:qe};function V(t){return typeof t=="string"?{...We[t]||We.solar,name:t}:t}function Pe(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t,e){let n=[];for(let[o,i]of Object.entries(t)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--${r}: ${i};`)}if(e)for(let[o,i]of Object.entries(e)){let r=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--preview-${r}-default: ${i};`)}return n.join(`
16
16
  `)}function Ke(t,e={},n={}){return{...t,colors:{...t.colors,...e},previewColors:{...t.previewColors,...n}}}function Ze(t={}){let{fontSize:e="14px",lineHeight:n=1.6,fontFamily:o='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:i="20px",theme:r=null,mobile:s={}}=t,a=Object.keys(s).length>0?`
17
17
  @media (max-width: 640px) {
18
18
  .overtype-wrapper .overtype-input,
@@ -704,17 +704,17 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
704
704
 
705
705
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
706
706
  font-size: 2em !important;
707
- color: var(--preview-h1, #222) !important;
707
+ color: var(--preview-h1, var(--preview-h1-default)) !important;
708
708
  }
709
709
 
710
710
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
711
711
  font-size: 1.5em !important;
712
- color: var(--preview-h2, #333) !important;
712
+ color: var(--preview-h2, var(--preview-h2-default)) !important;
713
713
  }
714
714
 
715
715
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
716
716
  font-size: 1.17em !important;
717
- color: var(--preview-h3, #444) !important;
717
+ color: var(--preview-h3, var(--preview-h3-default)) !important;
718
718
  }
719
719
 
720
720
  /* Lists - restore list styling in preview mode */
@@ -764,14 +764,14 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
764
764
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a {
765
765
  pointer-events: auto !important;
766
766
  cursor: pointer !important;
767
- color: var(--preview-link, #0066cc) !important;
767
+ color: var(--preview-link, var(--preview-link-default)) !important;
768
768
  text-decoration: underline !important;
769
769
  }
770
770
 
771
771
  /* Code blocks - proper pre/code styling in preview mode */
772
772
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
773
- background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
774
- color: var(--preview-code, #333) !important;
773
+ background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
774
+ color: var(--preview-code, var(--preview-code-default)) !important;
775
775
  padding: 1.2em !important;
776
776
  border-radius: 3px !important;
777
777
  overflow-x: auto !important;
@@ -800,8 +800,8 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
800
800
  /* Blockquotes - enhanced styling in preview mode */
801
801
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote {
802
802
  display: block !important;
803
- border-left: 4px solid var(--preview-blockquote, #666) !important;
804
- color: var(--preview-blockquote, #666) !important;
803
+ border-left: 4px solid var(--preview-blockquote, var(--preview-blockquote-default)) !important;
804
+ color: var(--preview-blockquote, var(--preview-blockquote-default)) !important;
805
805
  padding-left: 1em !important;
806
806
  margin: 1em 0 !important;
807
807
  font-style: italic !important;
@@ -812,16 +812,16 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
812
812
  font-family: Georgia, 'Times New Roman', serif !important;
813
813
  font-size: 16px !important;
814
814
  line-height: 1.8 !important;
815
- color: var(--preview-text, #333) !important;
816
- background: var(--preview-bg, transparent) !important;
815
+ color: var(--preview-text, var(--preview-text-default)) !important;
816
+ background: var(--preview-bg, var(--preview-bg-default)) !important;
817
817
  }
818
818
 
819
819
  /* Inline code in preview mode - keep monospace */
820
820
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
821
821
  font-family: ${o} !important;
822
822
  font-size: 0.9em !important;
823
- background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
824
- color: var(--preview-code, #333) !important;
823
+ background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
824
+ color: var(--preview-code, var(--preview-code-default)) !important;
825
825
  padding: 0.2em 0.4em !important;
826
826
  border-radius: 3px !important;
827
827
  }
@@ -829,18 +829,18 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
829
829
  /* Strong and em elements in preview mode */
830
830
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong {
831
831
  font-weight: 700 !important;
832
- color: var(--preview-strong, inherit) !important;
832
+ color: var(--preview-strong, var(--preview-strong-default)) !important;
833
833
  }
834
834
 
835
835
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em {
836
836
  font-style: italic !important;
837
- color: var(--preview-em, inherit) !important;
837
+ color: var(--preview-em, var(--preview-em-default)) !important;
838
838
  }
839
839
 
840
840
  /* HR in preview mode */
841
841
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker {
842
842
  display: block !important;
843
- border-top: 2px solid var(--preview-hr, #ddd) !important;
843
+ border-top: 2px solid var(--preview-hr, var(--preview-hr-default)) !important;
844
844
  text-indent: -9999px !important;
845
845
  height: 2px !important;
846
846
  }
@@ -895,7 +895,7 @@ ${a}`:r;if(d){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
895
895
  `)+u;return n?(o=Math.max(o+se(0,e.unorderedList).length+h.length,0),i=o):a.processed?(o=Math.max(t.selectionStart+h.length,0),i=t.selectionEnd+h.length+l-p):(o=Math.max(t.selectionStart+h.length,0),i=t.selectionEnd+h.length+l),{text:f,selectionStart:o,selectionEnd:i}}function it(t,e){let n=be(t,o=>En(o,e),{adjustSelection:(o,i,r,s)=>{let a=t.value.slice(s,t.selectionEnd),c=/^\d+\.\s+/,d=/^- /,l=c.test(a),p=d.test(a),h=e.orderedList&&l||e.unorderedList&&p;if(i===r)if(h){let u=a.match(e.orderedList?c:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(i-f,s)}}else if(l||p){let u=a.match(l?c:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:i+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:i+u}}else if(h){let u=a.match(e.orderedList?c:d),f=u?u[0].length:0;return{start:Math.max(i-f,s),end:Math.max(r-f,s)}}else if(l||p){let u=a.match(l?c:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:i+u,end:r+u}}}});U(t,n)}function Tn(t){if(!t)return[];let e=[],{selectionStart:n,selectionEnd:o,value:i}=t,r=i.split(`
896
896
  `),s=0,a="";for(let p of r){if(n>=s&&n<=s+p.length){a=p;break}s+=p.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,n-10),d=Math.min(i.length,o+10),l=i.slice(c,d);if(l.includes("**")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100)),u=p.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100)),u=p.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100));p.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let p=i.slice(Math.max(0,n-100),n),h=i.slice(o,Math.min(i.length,o+100)),u=p.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&i.slice(o+f+1,o+f+10).startsWith("(")&&e.push("link")}return e}function rt(t){if(!t||t.disabled||t.readOnly)return;x("toggleBold","Starting"),ye(t,"Before");let e=F(I.bold),n=xe(t,e);tt(n),U(t,n),ye(t,"After")}function st(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.italic),n=xe(t,e);U(t,n)}function at(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.code),n=xe(t,e);U(t,n)}function lt(t,e={}){if(!t||t.disabled||t.readOnly)return;let n=t.value.slice(t.selectionStart,t.selectionEnd),o=F(I.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${n})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!n){let s=t.selectionStart;t.value=t.value.slice(0,s)+e.text+t.value.slice(s),t.selectionStart=s,t.selectionEnd=s+e.text.length}let r=xe(t,o);U(t,r)}function ct(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.bulletList);it(t,e)}function pt(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.numberedList);it(t,e)}function dt(t){if(!t||t.disabled||t.readOnly)return;x("toggleQuote","Starting"),ye(t,"Initial");let e=F(I.quote),n=be(t,o=>ot(o,e),{prefix:e.prefix});tt(n),U(t,n),ye(t,"Final")}function Ie(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.taskList),n=be(t,o=>ot(o,e),{prefix:e.prefix});U(t,n)}function Re(t,e=1,n=!1){if(!t||t.disabled||t.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${n}`),x("insertHeader",`Initial cursor: ${t.selectionStart}-${t.selectionEnd}`);let o=`header${e===1?"1":e}`,i=F(I[o]||I.header1);x("insertHeader",`Style prefix: "${i.prefix}"`);let r=t.value,s=t.selectionStart,a=t.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
897
897
  `;)c--;let d=a;for(;d<r.length&&r[d]!==`
898
- `;)d++;let l=r.slice(c,d);x("insertHeader",`Current line (before): "${l}"`);let p=l.match(/^(#{1,6})\s*/),h=p?p[1].length:0,u=p?p[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${h}`),x("insertHeader",` - Existing prefix length: ${u}`),x("insertHeader",` - Target level: ${e}`);let f=n&&h===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${n}, existingLevel=${h}, level=${e})`);let m=be(t,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let w=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${w}"`);let b;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),b=w):h>0?(x("insertHeader",`ACTION: Replacing H${h} with H${e}`),b=i.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=i.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-u,b);return x("insertHeader",` - Removing header, adjusting by -${u}`),{start:L,end:y===w?L:Math.max(w-u,b)}}else if(u>0){let L=i.prefix.length-u;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:y+i.prefix.length,end:w+i.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),U(t,m)}function ut(t){Re(t,1,!0)}function ht(t){Re(t,2,!0)}function ft(t){Re(t,3,!0)}function mt(t){return Tn(t)}var ke=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=n.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 n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),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 n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.addEventListener("click",o=>{o.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=o=>{o.preventDefault();let i=e.actionId||e.name;this.editor.performAction(i,o)},n.addEventListener("click",n._clickHandler),n)}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:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!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 n=document.querySelector(".overtype-dropdown-menu");if(n){n.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let o=this.createViewModeDropdown(e),i=e.getBoundingClientRect();o.style.position="absolute",o.style.top=`${i.bottom+5}px`,o.style.left=`${i.left}px`,document.body.appendChild(o),this.handleDocumentClick=r=>{!o.contains(r.target)&&!e.contains(r.target)&&(o.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu";let o=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],i=this.editor.container.dataset.mode||"normal";return o.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),n.appendChild(s)}),n}updateButtonStates(){var e;try{let n=((e=mt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([o,i])=>{if(o==="viewMode")return;let r=!1;switch(o){case"bold":r=n.includes("bold");break;case"italic":r=n.includes("italic");break;case"code":r=!1;break;case"bulletList":r=n.includes("bullet-list");break;case"orderedList":r=n.includes("numbered-list");break;case"taskList":r=n.includes("task-list");break;case"quote":r=n.includes("quote");break;case"h1":r=n.includes("header");break;case"h2":r=n.includes("header-2");break;case"h3":r=n.includes("header-3");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(n){}}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 le=Math.min,W=Math.max,ce=Math.round;var P=t=>({x:t,y:t}),Cn={left:"right",right:"left",bottom:"top",top:"bottom"},An={start:"end",end:"start"};function Be(t,e,n){return W(t,le(e,n))}function pe(t,e){return typeof t=="function"?t(e):t}function q(t){return t.split("-")[0]}function de(t){return t.split("-")[1]}function _e(t){return t==="x"?"y":"x"}function Fe(t){return t==="y"?"height":"width"}var Mn=new Set(["top","bottom"]);function N(t){return Mn.has(q(t))?"y":"x"}function Ne(t){return _e(N(t))}function wt(t,e,n){n===void 0&&(n=!1);let o=de(t),i=Ne(t),r=Fe(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ae(s)),[s,ae(s)]}function bt(t){let e=ae(t);return[Le(t),e,Le(e)]}function Le(t){return t.replace(/start|end/g,e=>An[e])}var vt=["left","right"],yt=["right","left"],Hn=["top","bottom"],On=["bottom","top"];function Pn(t,e,n){switch(t){case"top":case"bottom":return n?e?yt:vt:e?vt:yt;case"left":case"right":return e?Hn:On;default:return[]}}function xt(t,e,n,o){let i=de(t),r=Pn(q(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(Le)))),r}function ae(t){return t.replace(/left|right|bottom|top/g,e=>Cn[e])}function $n(t){return{top:0,right:0,bottom:0,left:0,...t}}function kt(t){return typeof t!="number"?$n(t):{top:t,right:t,bottom:t,left:t}}function G(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Lt(t,e,n){let{reference:o,floating:i}=t,r=N(e),s=Ne(e),a=Fe(s),c=q(e),d=r==="y",l=o.x+o.width/2-i.width/2,p=o.y+o.height/2-i.height/2,h=o[a]/2-i[a]/2,u;switch(c){case"top":u={x:l,y:o.y-i.height};break;case"bottom":u={x:l,y:o.y+o.height};break;case"right":u={x:o.x+o.width,y:p};break;case"left":u={x:o.x-i.width,y:p};break;default:u={x:o.x,y:o.y}}switch(de(e)){case"start":u[s]-=h*(n&&d?-1:1);break;case"end":u[s]+=h*(n&&d?-1:1);break}return u}async function St(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:a,strategy:c}=t,{boundary:d="clippingAncestors",rootBoundary:l="viewport",elementContext:p="floating",altBoundary:h=!1,padding:u=0}=pe(e,t),f=kt(u),g=a[h?p==="floating"?"reference":"floating":p],y=G(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(g)))==null||n?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:d,rootBoundary:l,strategy:c})),w=p==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:c}):w);return{top:(y.top-k.top+f.top)/L.y,bottom:(k.bottom-y.bottom+f.bottom)/L.y,left:(y.left-k.left+f.left)/L.x,right:(k.right-y.right+f.right)/L.x}}var Et=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),d=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:l,y:p}=Lt(d,o,c),h=o,u={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:w}=a[g],{x:b,y:L,data:k,reset:E}=await w({x:l,y:p,initialPlacement:o,placement:h,strategy:i,middlewareData:u,rects:d,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:St},elements:{reference:t,floating:e}});l=b!=null?b:l,p=L!=null?L:p,u={...u,[y]:{...u[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(h=E.placement),E.rects&&(d=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):E.rects),{x:l,y:p}=Lt(d,h,c)),g=-1)}return{x:l,y:p,placement:h,strategy:i,middlewareData:u}};var Tt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:d}=e,{mainAxis:l=!0,crossAxis:p=!0,fallbackPlacements:h,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=pe(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let y=q(i),w=N(a),b=q(a)===a,L=await(c.isRTL==null?void 0:c.isRTL(d.floating)),k=h||(b||!m?[ae(a)]:bt(a)),E=f!=="none";!h&&E&&k.push(...xt(a,m,f,L));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((o=r.flip)==null?void 0:o.overflows)||[];if(l&&ge.push(Y[y]),p){let K=wt(i,s,L);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:i,overflows:ge}],!ge.every(K=>K<=0)){var je,Ve;let K=(((je=r.flip)==null?void 0:je.index)||0)+1,Oe=me[K];if(Oe&&(!(p==="alignment"?w!==N(Oe):!1)||ee.every(O=>N(O.placement)===w?O.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Oe}};let ie=(Ve=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,O)=>Z.overflows[1]-O.overflows[1])[0])==null?void 0:Ve.placement;if(!ie)switch(u){case"bestFit":{var Ue;let Z=(Ue=ee.filter(O=>{if(E){let j=N(O.placement);return j===w||j==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(j=>j>0).reduce((j,ln)=>j+ln,0)]).sort((O,j)=>O[1]-j[1])[0])==null?void 0:Ue[0];Z&&(ie=Z);break}case"initialPlacement":ie=a;break}if(i!==ie)return{reset:{placement:ie}}}return{}}}};var In=new Set(["left","top"]);async function Rn(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=q(n),a=de(n),c=N(n)==="y",d=In.has(s)?-1:1,l=r&&c?-1:1,p=pe(e,t),{mainAxis:h,crossAxis:u,alignmentAxis:f}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return a&&typeof f=="number"&&(u=a==="end"?f*-1:f),c?{x:u*l,y:h*d}:{x:h*d,y:u*l}}var Ct=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:a}=e,c=await Rn(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(o=a.arrow)!=null&&o.alignmentOffset?{}:{x:i+c.x,y:r+c.y,data:{...c,placement:s}}}}},At=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...d}=pe(t,e),l={x:n,y:o},p=await r.detectOverflow(e,d),h=N(q(i)),u=_e(h),f=l[u],m=l[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+p[y],L=f-p[w];f=Be(b,f,L)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+p[y],L=m-p[w];m=Be(b,m,L)}let g=c.fn({...e,[u]:f,[h]:m});return{...g,data:{x:g.x-n,y:g.y-o,enabled:{[u]:s,[h]:a}}}}}};function Ee(){return typeof window<"u"}function J(t){return Ht(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function R(t){var e;return(e=(Ht(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ht(t){return Ee()?t instanceof Node||t instanceof A(t).Node:!1}function M(t){return Ee()?t instanceof Element||t instanceof A(t).Element:!1}function $(t){return Ee()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function Mt(t){return!Ee()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}var Bn=new Set(["inline","contents"]);function te(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!Bn.has(i)}var _n=new Set(["table","td","th"]);function Ot(t){return _n.has(J(t))}var Fn=[":popover-open",":modal"];function ue(t){return Fn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Nn=["transform","translate","scale","rotate","perspective"],Dn=["transform","translate","scale","rotate","perspective","filter"],zn=["paint","layout","strict","content"];function Te(t){let e=Ce(),n=M(t)?H(t):t;return Nn.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Dn.some(o=>(n.willChange||"").includes(o))||zn.some(o=>(n.contain||"").includes(o))}function Pt(t){let e=D(t);for(;$(e)&&!X(e);){if(Te(e))return e;if(ue(e))return null;e=D(e)}return null}function Ce(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var jn=new Set(["html","body","#document"]);function X(t){return jn.has(J(t))}function H(t){return A(t).getComputedStyle(t)}function he(t){return M(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function D(t){if(J(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Mt(t)&&t.host||R(t);return Mt(e)?e.host:e}function $t(t){let e=D(t);return X(e)?t.ownerDocument?t.ownerDocument.body:t.body:$(e)&&te(e)?e:$t(e)}function Se(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=$t(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=A(i);if(r){let a=Ae(s);return e.concat(s,s.visualViewport||[],te(i)?i:[],a&&n?Se(a):[])}return e.concat(i,Se(i,[],n))}function Ae(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function _t(t){let e=H(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=$(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,a=ce(n)!==r||ce(o)!==s;return a&&(n=r,o=s),{width:n,height:o,$:a}}function Ft(t){return M(t)?t:t.contextElement}function ne(t){let e=Ft(t);if(!$(e))return P(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=_t(e),s=(r?ce(n.width):n.width)/o,a=(r?ce(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Vn=P(0);function Nt(t){let e=A(t);return!Ce()||!e.visualViewport?Vn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Un(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==A(t)?!1:e}function fe(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=Ft(t),s=P(1);e&&(o?M(o)&&(s=ne(o)):s=ne(t));let a=Un(r,n,o)?Nt(r):P(0),c=(i.left+a.x)/s.x,d=(i.top+a.y)/s.y,l=i.width/s.x,p=i.height/s.y;if(r){let h=A(r),u=o&&M(o)?A(o):o,f=h,m=Ae(f);for(;m&&o&&u!==f;){let g=ne(m),y=m.getBoundingClientRect(),w=H(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*g.x,L=y.top+(m.clientTop+parseFloat(w.paddingTop))*g.y;c*=g.x,d*=g.y,l*=g.x,p*=g.y,c+=b,d+=L,f=A(m),m=Ae(f)}}return G({width:l,height:p,x:c,y:d})}function Me(t,e){let n=he(t).scrollLeft;return e?e.left+n:fe(R(t)).left+n}function Dt(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Me(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function Wn(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=R(o),a=e?ue(e.floating):!1;if(o===s||a&&r)return n;let c={scrollLeft:0,scrollTop:0},d=P(1),l=P(0),p=$(o);if((p||!p&&!r)&&((J(o)!=="body"||te(s))&&(c=he(o)),$(o))){let u=fe(o);d=ne(o),l.x=u.x+o.clientLeft,l.y=u.y+o.clientTop}let h=s&&!p&&!r?Dt(s,c):P(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-c.scrollLeft*d.x+l.x+h.x,y:n.y*d.y-c.scrollTop*d.y+l.y+h.y}}function qn(t){return Array.from(t.getClientRects())}function Kn(t){let e=R(t),n=he(t),o=t.ownerDocument.body,i=W(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=W(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+Me(t),a=-n.scrollTop;return H(o).direction==="rtl"&&(s+=W(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:a}}var It=25;function Zn(t,e){let n=A(t),o=R(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,a=0,c=0;if(i){r=i.width,s=i.height;let l=Ce();(!l||l&&e==="fixed")&&(a=i.offsetLeft,c=i.offsetTop)}let d=Me(o);if(d<=0){let l=o.ownerDocument,p=l.body,h=getComputedStyle(p),u=l.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(o.clientWidth-p.clientWidth-u);f<=It&&(r-=f)}else d<=It&&(r+=d);return{width:r,height:s,x:a,y:c}}var Qn=new Set(["absolute","fixed"]);function Gn(t,e){let n=fe(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=$(t)?ne(t):P(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,c=i*r.x,d=o*r.y;return{width:s,height:a,x:c,y:d}}function Rt(t,e,n){let o;if(e==="viewport")o=Zn(t,n);else if(e==="document")o=Kn(R(t));else if(M(e))o=Gn(e,n);else{let i=Nt(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return G(o)}function zt(t,e){let n=D(t);return n===e||!M(n)||X(n)?!1:H(n).position==="fixed"||zt(n,e)}function Jn(t,e){let n=e.get(t);if(n)return n;let o=Se(t,[],!1).filter(a=>M(a)&&J(a)!=="body"),i=null,r=H(t).position==="fixed",s=r?D(t):t;for(;M(s)&&!X(s);){let a=H(s),c=Te(s);!c&&a.position==="fixed"&&(i=null),(r?!c&&!i:!c&&a.position==="static"&&!!i&&Qn.has(i.position)||te(s)&&!c&&zt(t,s))?o=o.filter(l=>l!==s):i=a,s=D(s)}return e.set(t,o),o}function Xn(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?ue(e)?[]:Jn(e,this._c):[].concat(n),o],a=s[0],c=s.reduce((d,l)=>{let p=Rt(e,l,i);return d.top=W(p.top,d.top),d.right=le(p.right,d.right),d.bottom=le(p.bottom,d.bottom),d.left=W(p.left,d.left),d},Rt(e,a,i));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Yn(t){let{width:e,height:n}=_t(t);return{width:e,height:n}}function eo(t,e,n){let o=$(e),i=R(e),r=n==="fixed",s=fe(t,!0,r,e),a={scrollLeft:0,scrollTop:0},c=P(0);function d(){c.x=Me(i)}if(o||!o&&!r)if((J(e)!=="body"||te(i))&&(a=he(e)),o){let u=fe(e,!0,r,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else i&&d();r&&!o&&i&&d();let l=i&&!o&&!r?Dt(i,a):P(0),p=s.left+a.scrollLeft-c.x-l.x,h=s.top+a.scrollTop-c.y-l.y;return{x:p,y:h,width:s.width,height:s.height}}function De(t){return H(t).position==="static"}function Bt(t,e){if(!$(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return R(t)===n&&(n=n.ownerDocument.body),n}function jt(t,e){let n=A(t);if(ue(t))return n;if(!$(t)){let i=D(t);for(;i&&!X(i);){if(M(i)&&!De(i))return i;i=D(i)}return n}let o=Bt(t,e);for(;o&&Ot(o)&&De(o);)o=Bt(o,e);return o&&X(o)&&De(o)&&!Te(o)?n:o||Pt(t)||n}var to=async function(t){let e=this.getOffsetParent||jt,n=this.getDimensions,o=await n(t.floating);return{reference:eo(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function no(t){return H(t).direction==="rtl"}var oo={convertOffsetParentRelativeRectToViewportRelativeRect:Wn,getDocumentElement:R,getClippingRect:Xn,getOffsetParent:jt,getElementRects:to,getClientRects:qn,getDimensions:Yn,getScale:ne,isElement:M,isRTL:no};var Vt=Ct;var Ut=At,Wt=Tt;var qt=(t,e,n)=>{let o=new Map,i={platform:oo,...n},r={...i.platform,_c:o};return Et(t,e,{...i,platform:r})};var He=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=`
898
+ `;)d++;let l=r.slice(c,d);x("insertHeader",`Current line (before): "${l}"`);let p=l.match(/^(#{1,6})\s*/),h=p?p[1].length:0,u=p?p[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${p?`"${p[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${h}`),x("insertHeader",` - Existing prefix length: ${u}`),x("insertHeader",` - Target level: ${e}`);let f=n&&h===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${n}, existingLevel=${h}, level=${e})`);let m=be(t,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let w=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${w}"`);let b;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),b=w):h>0?(x("insertHeader",`ACTION: Replacing H${h} with H${e}`),b=i.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=i.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-u,b);return x("insertHeader",` - Removing header, adjusting by -${u}`),{start:L,end:y===w?L:Math.max(w-u,b)}}else if(u>0){let L=i.prefix.length-u;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:y+i.prefix.length,end:w+i.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),U(t,m)}function ut(t){Re(t,1,!0)}function ht(t){Re(t,2,!0)}function ft(t){Re(t,3,!0)}function mt(t){return Tn(t)}var ke=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=n.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 n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),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 n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.addEventListener("click",o=>{o.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=o=>{o.preventDefault();let i=e.actionId||e.name;this.editor.performAction(i,o)},n.addEventListener("click",n._clickHandler),n)}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:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!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 n=document.querySelector(".overtype-dropdown-menu");if(n){n.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let o=this.createViewModeDropdown(e),i=e.getBoundingClientRect();o.style.position="absolute",o.style.top=`${i.bottom+5}px`,o.style.left=`${i.left}px`,document.body.appendChild(o),this.handleDocumentClick=r=>{!o.contains(r.target)&&!e.contains(r.target)&&(o.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu";let o=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],i=this.editor.container.dataset.mode||"normal";return o.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),n.appendChild(s)}),n}updateButtonStates(){var e;try{let n=((e=mt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([o,i])=>{if(o==="viewMode")return;let r=!1;switch(o){case"bold":r=n.includes("bold");break;case"italic":r=n.includes("italic");break;case"code":r=!1;break;case"bulletList":r=n.includes("bullet-list");break;case"orderedList":r=n.includes("numbered-list");break;case"taskList":r=n.includes("task-list");break;case"quote":r=n.includes("quote");break;case"h1":r=n.includes("header");break;case"h2":r=n.includes("header-2");break;case"h3":r=n.includes("header-3");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(n){}}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 le=Math.min,q=Math.max,ce=Math.round;var P=t=>({x:t,y:t}),Cn={left:"right",right:"left",bottom:"top",top:"bottom"},An={start:"end",end:"start"};function Be(t,e,n){return q(t,le(e,n))}function pe(t,e){return typeof t=="function"?t(e):t}function W(t){return t.split("-")[0]}function de(t){return t.split("-")[1]}function _e(t){return t==="x"?"y":"x"}function Fe(t){return t==="y"?"height":"width"}var Mn=new Set(["top","bottom"]);function N(t){return Mn.has(W(t))?"y":"x"}function Ne(t){return _e(N(t))}function wt(t,e,n){n===void 0&&(n=!1);let o=de(t),i=Ne(t),r=Fe(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ae(s)),[s,ae(s)]}function bt(t){let e=ae(t);return[Le(t),e,Le(e)]}function Le(t){return t.replace(/start|end/g,e=>An[e])}var vt=["left","right"],yt=["right","left"],Hn=["top","bottom"],On=["bottom","top"];function Pn(t,e,n){switch(t){case"top":case"bottom":return n?e?yt:vt:e?vt:yt;case"left":case"right":return e?Hn:On;default:return[]}}function xt(t,e,n,o){let i=de(t),r=Pn(W(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(Le)))),r}function ae(t){return t.replace(/left|right|bottom|top/g,e=>Cn[e])}function $n(t){return{top:0,right:0,bottom:0,left:0,...t}}function kt(t){return typeof t!="number"?$n(t):{top:t,right:t,bottom:t,left:t}}function G(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Lt(t,e,n){let{reference:o,floating:i}=t,r=N(e),s=Ne(e),a=Fe(s),c=W(e),d=r==="y",l=o.x+o.width/2-i.width/2,p=o.y+o.height/2-i.height/2,h=o[a]/2-i[a]/2,u;switch(c){case"top":u={x:l,y:o.y-i.height};break;case"bottom":u={x:l,y:o.y+o.height};break;case"right":u={x:o.x+o.width,y:p};break;case"left":u={x:o.x-i.width,y:p};break;default:u={x:o.x,y:o.y}}switch(de(e)){case"start":u[s]-=h*(n&&d?-1:1);break;case"end":u[s]+=h*(n&&d?-1:1);break}return u}async function St(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:a,strategy:c}=t,{boundary:d="clippingAncestors",rootBoundary:l="viewport",elementContext:p="floating",altBoundary:h=!1,padding:u=0}=pe(e,t),f=kt(u),g=a[h?p==="floating"?"reference":"floating":p],y=G(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(g)))==null||n?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:d,rootBoundary:l,strategy:c})),w=p==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:c}):w);return{top:(y.top-k.top+f.top)/L.y,bottom:(k.bottom-y.bottom+f.bottom)/L.y,left:(y.left-k.left+f.left)/L.x,right:(k.right-y.right+f.right)/L.x}}var Et=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),d=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:l,y:p}=Lt(d,o,c),h=o,u={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:w}=a[g],{x:b,y:L,data:k,reset:E}=await w({x:l,y:p,initialPlacement:o,placement:h,strategy:i,middlewareData:u,rects:d,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:St},elements:{reference:t,floating:e}});l=b!=null?b:l,p=L!=null?L:p,u={...u,[y]:{...u[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(h=E.placement),E.rects&&(d=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):E.rects),{x:l,y:p}=Lt(d,h,c)),g=-1)}return{x:l,y:p,placement:h,strategy:i,middlewareData:u}};var Tt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:d}=e,{mainAxis:l=!0,crossAxis:p=!0,fallbackPlacements:h,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=pe(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let y=W(i),w=N(a),b=W(a)===a,L=await(c.isRTL==null?void 0:c.isRTL(d.floating)),k=h||(b||!m?[ae(a)]:bt(a)),E=f!=="none";!h&&E&&k.push(...xt(a,m,f,L));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((o=r.flip)==null?void 0:o.overflows)||[];if(l&&ge.push(Y[y]),p){let K=wt(i,s,L);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:i,overflows:ge}],!ge.every(K=>K<=0)){var je,Ve;let K=(((je=r.flip)==null?void 0:je.index)||0)+1,Oe=me[K];if(Oe&&(!(p==="alignment"?w!==N(Oe):!1)||ee.every(O=>N(O.placement)===w?O.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Oe}};let ie=(Ve=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,O)=>Z.overflows[1]-O.overflows[1])[0])==null?void 0:Ve.placement;if(!ie)switch(u){case"bestFit":{var Ue;let Z=(Ue=ee.filter(O=>{if(E){let j=N(O.placement);return j===w||j==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(j=>j>0).reduce((j,ln)=>j+ln,0)]).sort((O,j)=>O[1]-j[1])[0])==null?void 0:Ue[0];Z&&(ie=Z);break}case"initialPlacement":ie=a;break}if(i!==ie)return{reset:{placement:ie}}}return{}}}};var In=new Set(["left","top"]);async function Rn(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=W(n),a=de(n),c=N(n)==="y",d=In.has(s)?-1:1,l=r&&c?-1:1,p=pe(e,t),{mainAxis:h,crossAxis:u,alignmentAxis:f}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return a&&typeof f=="number"&&(u=a==="end"?f*-1:f),c?{x:u*l,y:h*d}:{x:h*d,y:u*l}}var Ct=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:a}=e,c=await Rn(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(o=a.arrow)!=null&&o.alignmentOffset?{}:{x:i+c.x,y:r+c.y,data:{...c,placement:s}}}}},At=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...d}=pe(t,e),l={x:n,y:o},p=await r.detectOverflow(e,d),h=N(W(i)),u=_e(h),f=l[u],m=l[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+p[y],L=f-p[w];f=Be(b,f,L)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+p[y],L=m-p[w];m=Be(b,m,L)}let g=c.fn({...e,[u]:f,[h]:m});return{...g,data:{x:g.x-n,y:g.y-o,enabled:{[u]:s,[h]:a}}}}}};function Ee(){return typeof window<"u"}function J(t){return Ht(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function R(t){var e;return(e=(Ht(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ht(t){return Ee()?t instanceof Node||t instanceof A(t).Node:!1}function M(t){return Ee()?t instanceof Element||t instanceof A(t).Element:!1}function $(t){return Ee()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function Mt(t){return!Ee()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}var Bn=new Set(["inline","contents"]);function te(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!Bn.has(i)}var _n=new Set(["table","td","th"]);function Ot(t){return _n.has(J(t))}var Fn=[":popover-open",":modal"];function ue(t){return Fn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Nn=["transform","translate","scale","rotate","perspective"],Dn=["transform","translate","scale","rotate","perspective","filter"],zn=["paint","layout","strict","content"];function Te(t){let e=Ce(),n=M(t)?H(t):t;return Nn.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Dn.some(o=>(n.willChange||"").includes(o))||zn.some(o=>(n.contain||"").includes(o))}function Pt(t){let e=D(t);for(;$(e)&&!X(e);){if(Te(e))return e;if(ue(e))return null;e=D(e)}return null}function Ce(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var jn=new Set(["html","body","#document"]);function X(t){return jn.has(J(t))}function H(t){return A(t).getComputedStyle(t)}function he(t){return M(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function D(t){if(J(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Mt(t)&&t.host||R(t);return Mt(e)?e.host:e}function $t(t){let e=D(t);return X(e)?t.ownerDocument?t.ownerDocument.body:t.body:$(e)&&te(e)?e:$t(e)}function Se(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=$t(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=A(i);if(r){let a=Ae(s);return e.concat(s,s.visualViewport||[],te(i)?i:[],a&&n?Se(a):[])}return e.concat(i,Se(i,[],n))}function Ae(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function _t(t){let e=H(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=$(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,a=ce(n)!==r||ce(o)!==s;return a&&(n=r,o=s),{width:n,height:o,$:a}}function Ft(t){return M(t)?t:t.contextElement}function ne(t){let e=Ft(t);if(!$(e))return P(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=_t(e),s=(r?ce(n.width):n.width)/o,a=(r?ce(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Vn=P(0);function Nt(t){let e=A(t);return!Ce()||!e.visualViewport?Vn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Un(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==A(t)?!1:e}function fe(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=Ft(t),s=P(1);e&&(o?M(o)&&(s=ne(o)):s=ne(t));let a=Un(r,n,o)?Nt(r):P(0),c=(i.left+a.x)/s.x,d=(i.top+a.y)/s.y,l=i.width/s.x,p=i.height/s.y;if(r){let h=A(r),u=o&&M(o)?A(o):o,f=h,m=Ae(f);for(;m&&o&&u!==f;){let g=ne(m),y=m.getBoundingClientRect(),w=H(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*g.x,L=y.top+(m.clientTop+parseFloat(w.paddingTop))*g.y;c*=g.x,d*=g.y,l*=g.x,p*=g.y,c+=b,d+=L,f=A(m),m=Ae(f)}}return G({width:l,height:p,x:c,y:d})}function Me(t,e){let n=he(t).scrollLeft;return e?e.left+n:fe(R(t)).left+n}function Dt(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Me(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function qn(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=R(o),a=e?ue(e.floating):!1;if(o===s||a&&r)return n;let c={scrollLeft:0,scrollTop:0},d=P(1),l=P(0),p=$(o);if((p||!p&&!r)&&((J(o)!=="body"||te(s))&&(c=he(o)),$(o))){let u=fe(o);d=ne(o),l.x=u.x+o.clientLeft,l.y=u.y+o.clientTop}let h=s&&!p&&!r?Dt(s,c):P(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-c.scrollLeft*d.x+l.x+h.x,y:n.y*d.y-c.scrollTop*d.y+l.y+h.y}}function Wn(t){return Array.from(t.getClientRects())}function Kn(t){let e=R(t),n=he(t),o=t.ownerDocument.body,i=q(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=q(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+Me(t),a=-n.scrollTop;return H(o).direction==="rtl"&&(s+=q(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:a}}var It=25;function Zn(t,e){let n=A(t),o=R(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,a=0,c=0;if(i){r=i.width,s=i.height;let l=Ce();(!l||l&&e==="fixed")&&(a=i.offsetLeft,c=i.offsetTop)}let d=Me(o);if(d<=0){let l=o.ownerDocument,p=l.body,h=getComputedStyle(p),u=l.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(o.clientWidth-p.clientWidth-u);f<=It&&(r-=f)}else d<=It&&(r+=d);return{width:r,height:s,x:a,y:c}}var Qn=new Set(["absolute","fixed"]);function Gn(t,e){let n=fe(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=$(t)?ne(t):P(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,c=i*r.x,d=o*r.y;return{width:s,height:a,x:c,y:d}}function Rt(t,e,n){let o;if(e==="viewport")o=Zn(t,n);else if(e==="document")o=Kn(R(t));else if(M(e))o=Gn(e,n);else{let i=Nt(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return G(o)}function zt(t,e){let n=D(t);return n===e||!M(n)||X(n)?!1:H(n).position==="fixed"||zt(n,e)}function Jn(t,e){let n=e.get(t);if(n)return n;let o=Se(t,[],!1).filter(a=>M(a)&&J(a)!=="body"),i=null,r=H(t).position==="fixed",s=r?D(t):t;for(;M(s)&&!X(s);){let a=H(s),c=Te(s);!c&&a.position==="fixed"&&(i=null),(r?!c&&!i:!c&&a.position==="static"&&!!i&&Qn.has(i.position)||te(s)&&!c&&zt(t,s))?o=o.filter(l=>l!==s):i=a,s=D(s)}return e.set(t,o),o}function Xn(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?ue(e)?[]:Jn(e,this._c):[].concat(n),o],a=s[0],c=s.reduce((d,l)=>{let p=Rt(e,l,i);return d.top=q(p.top,d.top),d.right=le(p.right,d.right),d.bottom=le(p.bottom,d.bottom),d.left=q(p.left,d.left),d},Rt(e,a,i));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Yn(t){let{width:e,height:n}=_t(t);return{width:e,height:n}}function eo(t,e,n){let o=$(e),i=R(e),r=n==="fixed",s=fe(t,!0,r,e),a={scrollLeft:0,scrollTop:0},c=P(0);function d(){c.x=Me(i)}if(o||!o&&!r)if((J(e)!=="body"||te(i))&&(a=he(e)),o){let u=fe(e,!0,r,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else i&&d();r&&!o&&i&&d();let l=i&&!o&&!r?Dt(i,a):P(0),p=s.left+a.scrollLeft-c.x-l.x,h=s.top+a.scrollTop-c.y-l.y;return{x:p,y:h,width:s.width,height:s.height}}function De(t){return H(t).position==="static"}function Bt(t,e){if(!$(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return R(t)===n&&(n=n.ownerDocument.body),n}function jt(t,e){let n=A(t);if(ue(t))return n;if(!$(t)){let i=D(t);for(;i&&!X(i);){if(M(i)&&!De(i))return i;i=D(i)}return n}let o=Bt(t,e);for(;o&&Ot(o)&&De(o);)o=Bt(o,e);return o&&X(o)&&De(o)&&!Te(o)?n:o||Pt(t)||n}var to=async function(t){let e=this.getOffsetParent||jt,n=this.getDimensions,o=await n(t.floating);return{reference:eo(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function no(t){return H(t).direction==="rtl"}var oo={convertOffsetParentRelativeRectToViewportRelativeRect:qn,getDocumentElement:R,getClippingRect:Xn,getOffsetParent:jt,getElementRects:to,getClientRects:Wn,getDimensions:Yn,getScale:ne,isElement:M,isRTL:no};var Vt=Ct;var Ut=At,qt=Tt;var Wt=(t,e,n)=>{let o=new Map,i={platform:oo,...n},r={...i.platform,_c:o};return Et(t,e,{...i,platform:r})};var He=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=`
899
899
  <span style="display: flex; align-items: center; gap: 6px;">
900
900
  <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
901
901
  <path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path>
@@ -903,7 +903,7 @@ ${a}`:r;if(d){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
903
903
  </svg>
904
904
  <span class="overtype-link-tooltip-url"></span>
905
905
  </span>
906
- `,this.tooltip.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.currentLink&&(window.open(this.currentLink.url,"_blank"),this.hide())}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,n=this.editor.textarea.value,o=this.findLinkAtPosition(n,e);o?(!this.currentLink||this.currentLink.url!==o.url||this.currentLink.index!==o.index)&&this.show(o):this.scheduleHide()}findLinkAtPosition(e,n){let o=/\[([^\]]+)\]\(([^)]+)\)/g,i,r=0;for(;(i=o.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(n>=s&&n<=a)return{text:i[1],url:i[2],index:r,start:s,end:a};r++}return null}async show(e){this.currentLink=e,this.cancelHide();let n=this.tooltip.querySelector(".overtype-link-tooltip-url");n.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let n=this.findAnchorElement(e.index);if(!n)return;let o=n.getBoundingClientRect();if(!(o.width===0||o.height===0))try{let{x:i,y:r}=await qt(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Vt(8),Ut({padding:8}),Wt()]});Object.assign(this.tooltip.style,{left:`${i}px`,top:`${r}px`,position:"fixed"})}catch(i){console.warn("Floating UI positioning failed:",i)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var Kt=`<svg viewBox="0 0 18 18">
906
+ `,this.tooltip.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.currentLink&&(window.open(this.currentLink.url,"_blank"),this.hide())}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,n=this.editor.textarea.value,o=this.findLinkAtPosition(n,e);o?(!this.currentLink||this.currentLink.url!==o.url||this.currentLink.index!==o.index)&&this.show(o):this.scheduleHide()}findLinkAtPosition(e,n){let o=/\[([^\]]+)\]\(([^)]+)\)/g,i,r=0;for(;(i=o.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(n>=s&&n<=a)return{text:i[1],url:i[2],index:r,start:s,end:a};r++}return null}async show(e){this.currentLink=e,this.cancelHide();let n=this.tooltip.querySelector(".overtype-link-tooltip-url");n.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let n=this.findAnchorElement(e.index);if(!n)return;let o=n.getBoundingClientRect();if(!(o.width===0||o.height===0))try{let{x:i,y:r}=await Wt(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Vt(8),Ut({padding:8}),qt()]});Object.assign(this.tooltip.style,{left:`${i}px`,top:`${r}px`,position:"fixed"})}catch(i){console.warn("Floating UI positioning failed:",i)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var Kt=`<svg viewBox="0 0 18 18">
907
907
  <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z"></path>
908
908
  <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z"></path>
909
909
  </svg>`,Zt=`<svg viewBox="0 0 18 18">
@@ -974,7 +974,7 @@ ${a}`:r;if(d){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
974
974
  <span>${o} chars, ${i} words, ${n.length} lines</span>
975
975
  </div>
976
976
  <div class="overtype-stat">Line ${c}, Col ${d}</div>
977
- `}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,n=this.preview,o=this.wrapper,i=window.getComputedStyle(e),r=parseFloat(i.paddingTop),s=parseFloat(i.paddingBottom),a=e.scrollTop;e.style.setProperty("height","auto","important");let c=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);c=Math.max(c,p)}let d="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);c>p&&(c=p,d="auto")}let l=c+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",d,"important"),n.style.setProperty("height",l,"important"),n.style.setProperty("overflow-y",d,"important"),o.style.setProperty("height",l,"important"),e.scrollTop=a,n.scrollTop=a,this.previousHeight!==c&&(this.previousHeight=c)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this.updatePreview(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this.toolbar){let e=this.container.querySelector('[data-action="toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this.updatePreview(),this}destroy(){if(v._autoInstances.delete(this),v._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,v.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,n={}){return new v(e,n)}static initFromData(e,n={}){let o=document.querySelectorAll(e);return Array.from(o).map(i=>{let r={...n};for(let s of i.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(d,l)=>l.toUpperCase());r[c]=v._parseDataValue(s.value)}return new v(i,r)[0]})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||v.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(n=>{let o=v.getInstance(n);o&&o.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let n=document.querySelector("style.overtype-styles");n&&n.remove();let o=v.currentTheme||B,i=Ze({theme:o}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,n=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=n,v._startAutoListener(),v._applyGlobalTheme(Pe("auto"),n);return}v._stopAutoListener(),v._applyGlobalTheme(e,n)}static _applyGlobalTheme(e,n=null){let o=typeof e=="string"?V(e):e;n&&(o=Ke(o,n)),v.currentTheme=o,v.injectStyles(!0);let i=typeof o=="string"?o:o.name;document.querySelectorAll(".overtype-container").forEach(r=>{i&&r.setAttribute("data-theme",i)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||i&&r.setAttribute("data-theme",i);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{i&&typeof r.setAttribute=="function"&&r.setAttribute("theme",i),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let n=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(n,v._globalAutoCustomColors),v._autoInstances.forEach(o=>o._applyResolvedTheme(n))},v._autoMediaQuery.addEventListener("change",v._autoMediaListener))}static _stopAutoListener(){v._autoInstances.size>0||v._globalAutoTheme||v._autoMediaQuery&&(v._autoMediaQuery.removeEventListener("change",v._autoMediaListener),v._autoMediaQuery=null,v._autoMediaListener=null)}static setCodeHighlighter(e){T.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static setCustomSyntax(e){T.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let n=document.activeElement;if(n&&n.classList.contains("overtype-input")){let o=n.closest(".overtype-wrapper"),i=o==null?void 0:o._instance;i&&(i.options.showStats&&i.statsBar&&i._updateStats(),clearTimeout(i._selectionTimeout),i._selectionTimeout=setTimeout(()=>{i.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};C(v,"instances",new WeakMap),C(v,"stylesInjected",!1),C(v,"globalListenersInitialized",!1),C(v,"instanceCount",0),C(v,"_autoMediaQuery",null),C(v,"_autoMediaListener",null),C(v,"_autoInstances",new Set),C(v,"_globalAutoTheme",!1),C(v,"_globalAutoCustomColors",null);var z=v;z.MarkdownParser=T;z.ShortcutsManager=re;z.themes={solar:B,cave:V("cave")};z.getTheme=V;z.currentTheme=B;var so=z;return mn(ao);})();
977
+ `}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,n=this.preview,o=this.wrapper,i=window.getComputedStyle(e),r=parseFloat(i.paddingTop),s=parseFloat(i.paddingBottom),a=e.scrollTop;o.style.setProperty("height","auto","important"),e.style.setProperty("height","auto","important");let c=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);c=Math.max(c,p)}let d="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);c>p&&(c=p,d="auto")}let l=c+"px";e.style.setProperty("height",l,"important"),e.style.setProperty("overflow-y",d,"important"),n.style.setProperty("height",l,"important"),n.style.setProperty("overflow-y",d,"important"),o.style.setProperty("height",l,"important"),e.scrollTop=a,n.scrollTop=a,this.previousHeight!==c&&(this.previousHeight=c)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this.updatePreview(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this.toolbar){let e=this.container.querySelector('[data-action="toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this.updatePreview(),this}destroy(){if(v._autoInstances.delete(this),v._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,v.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,n={}){return new v(e,n)}static initFromData(e,n={}){let o=document.querySelectorAll(e);return Array.from(o).map(i=>{let r={...n};for(let s of i.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(d,l)=>l.toUpperCase());r[c]=v._parseDataValue(s.value)}return new v(i,r)[0]})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||v.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(n=>{let o=v.getInstance(n);o&&o.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let n=document.querySelector("style.overtype-styles");n&&n.remove();let o=v.currentTheme||B,i=Ze({theme:o}),r=document.createElement("style");r.className="overtype-styles",r.textContent=i,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,n=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=n,v._startAutoListener(),v._applyGlobalTheme(Pe("auto"),n);return}v._stopAutoListener(),v._applyGlobalTheme(e,n)}static _applyGlobalTheme(e,n=null){let o=typeof e=="string"?V(e):e;n&&(o=Ke(o,n)),v.currentTheme=o,v.injectStyles(!0);let i=typeof o=="string"?o:o.name;document.querySelectorAll(".overtype-container").forEach(r=>{i&&r.setAttribute("data-theme",i)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||i&&r.setAttribute("data-theme",i);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{i&&typeof r.setAttribute=="function"&&r.setAttribute("theme",i),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let n=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(n,v._globalAutoCustomColors),v._autoInstances.forEach(o=>o._applyResolvedTheme(n))},v._autoMediaQuery.addEventListener("change",v._autoMediaListener))}static _stopAutoListener(){v._autoInstances.size>0||v._globalAutoTheme||v._autoMediaQuery&&(v._autoMediaQuery.removeEventListener("change",v._autoMediaListener),v._autoMediaQuery=null,v._autoMediaListener=null)}static setCodeHighlighter(e){T.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static setCustomSyntax(e){T.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let o=n._instance;o&&o.updatePreview&&o.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let o=n.getEditor();o&&o.updatePreview&&o.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&o.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let n=document.activeElement;if(n&&n.classList.contains("overtype-input")){let o=n.closest(".overtype-wrapper"),i=o==null?void 0:o._instance;i&&(i.options.showStats&&i.statsBar&&i._updateStats(),clearTimeout(i._selectionTimeout),i._selectionTimeout=setTimeout(()=>{i.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};C(v,"instances",new WeakMap),C(v,"stylesInjected",!1),C(v,"globalListenersInitialized",!1),C(v,"instanceCount",0),C(v,"_autoMediaQuery",null),C(v,"_autoMediaListener",null),C(v,"_autoInstances",new Set),C(v,"_globalAutoTheme",!1),C(v,"_globalAutoCustomColors",null);var z=v;z.MarkdownParser=T;z.ShortcutsManager=re;z.themes={solar:B,cave:V("cave")};z.getTheme=V;z.currentTheme=B;var so=z;return mn(ao);})();
978
978
  /**
979
979
  * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment
980
980
  * @version 1.0.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtype",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay",
5
5
  "main": "dist/overtype.cjs",
6
6
  "module": "dist/overtype.esm.js",
package/src/overtype.js CHANGED
@@ -1334,9 +1334,11 @@ class OverType {
1334
1334
  // Store scroll positions
1335
1335
  const scrollTop = textarea.scrollTop;
1336
1336
 
1337
- // Reset height to get accurate scrollHeight
1337
+ // Reset heights to get accurate scrollHeight
1338
+ // Wrapper must also reset so the absolute-positioned textarea isn't constrained
1339
+ wrapper.style.setProperty('height', 'auto', 'important');
1338
1340
  textarea.style.setProperty('height', 'auto', 'important');
1339
-
1341
+
1340
1342
  // Calculate new height based on scrollHeight
1341
1343
  let newHeight = textarea.scrollHeight;
1342
1344
 
package/src/styles.js CHANGED
@@ -722,17 +722,17 @@ export function generateStyles(options = {}) {
722
722
 
723
723
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1 {
724
724
  font-size: 2em !important;
725
- color: var(--preview-h1, #222) !important;
725
+ color: var(--preview-h1, var(--preview-h1-default)) !important;
726
726
  }
727
727
 
728
728
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2 {
729
729
  font-size: 1.5em !important;
730
- color: var(--preview-h2, #333) !important;
730
+ color: var(--preview-h2, var(--preview-h2-default)) !important;
731
731
  }
732
732
 
733
733
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3 {
734
734
  font-size: 1.17em !important;
735
- color: var(--preview-h3, #444) !important;
735
+ color: var(--preview-h3, var(--preview-h3-default)) !important;
736
736
  }
737
737
 
738
738
  /* Lists - restore list styling in preview mode */
@@ -782,14 +782,14 @@ export function generateStyles(options = {}) {
782
782
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a {
783
783
  pointer-events: auto !important;
784
784
  cursor: pointer !important;
785
- color: var(--preview-link, #0066cc) !important;
785
+ color: var(--preview-link, var(--preview-link-default)) !important;
786
786
  text-decoration: underline !important;
787
787
  }
788
788
 
789
789
  /* Code blocks - proper pre/code styling in preview mode */
790
790
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
791
- background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
792
- color: var(--preview-code, #333) !important;
791
+ background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
792
+ color: var(--preview-code, var(--preview-code-default)) !important;
793
793
  padding: 1.2em !important;
794
794
  border-radius: 3px !important;
795
795
  overflow-x: auto !important;
@@ -818,8 +818,8 @@ export function generateStyles(options = {}) {
818
818
  /* Blockquotes - enhanced styling in preview mode */
819
819
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote {
820
820
  display: block !important;
821
- border-left: 4px solid var(--preview-blockquote, #666) !important;
822
- color: var(--preview-blockquote, #666) !important;
821
+ border-left: 4px solid var(--preview-blockquote, var(--preview-blockquote-default)) !important;
822
+ color: var(--preview-blockquote, var(--preview-blockquote-default)) !important;
823
823
  padding-left: 1em !important;
824
824
  margin: 1em 0 !important;
825
825
  font-style: italic !important;
@@ -830,16 +830,16 @@ export function generateStyles(options = {}) {
830
830
  font-family: Georgia, 'Times New Roman', serif !important;
831
831
  font-size: 16px !important;
832
832
  line-height: 1.8 !important;
833
- color: var(--preview-text, #333) !important;
834
- background: var(--preview-bg, transparent) !important;
833
+ color: var(--preview-text, var(--preview-text-default)) !important;
834
+ background: var(--preview-bg, var(--preview-bg-default)) !important;
835
835
  }
836
836
 
837
837
  /* Inline code in preview mode - keep monospace */
838
838
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code {
839
839
  font-family: ${fontFamily} !important;
840
840
  font-size: 0.9em !important;
841
- background: var(--preview-code-bg, rgba(135, 131, 120, 0.15)) !important;
842
- color: var(--preview-code, #333) !important;
841
+ background: var(--preview-code-bg, var(--preview-code-bg-default)) !important;
842
+ color: var(--preview-code, var(--preview-code-default)) !important;
843
843
  padding: 0.2em 0.4em !important;
844
844
  border-radius: 3px !important;
845
845
  }
@@ -847,18 +847,18 @@ export function generateStyles(options = {}) {
847
847
  /* Strong and em elements in preview mode */
848
848
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong {
849
849
  font-weight: 700 !important;
850
- color: var(--preview-strong, inherit) !important;
850
+ color: var(--preview-strong, var(--preview-strong-default)) !important;
851
851
  }
852
852
 
853
853
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em {
854
854
  font-style: italic !important;
855
- color: var(--preview-em, inherit) !important;
855
+ color: var(--preview-em, var(--preview-em-default)) !important;
856
856
  }
857
857
 
858
858
  /* HR in preview mode */
859
859
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker {
860
860
  display: block !important;
861
- border-top: 2px solid var(--preview-hr, #ddd) !important;
861
+ border-top: 2px solid var(--preview-hr, var(--preview-hr-default)) !important;
862
862
  text-indent: -9999px !important;
863
863
  height: 2px !important;
864
864
  }
package/src/themes.js CHANGED
@@ -42,17 +42,17 @@ export const solar = {
42
42
  placeholder: '#999999', // Gray - placeholder text
43
43
  },
44
44
  previewColors: {
45
- text: '#1a1a1a',
46
- h1: '#1a1a1a',
47
- h2: '#2a2a2a',
48
- h3: '#3a3a3a',
45
+ text: '#0d3b66',
46
+ h1: 'inherit',
47
+ h2: 'inherit',
48
+ h3: 'inherit',
49
49
  strong: 'inherit',
50
50
  em: 'inherit',
51
- link: '#0066cc',
52
- code: '#1a1a1a',
53
- codeBg: 'rgba(135, 131, 120, 0.15)',
54
- blockquote: '#555',
55
- hr: '#ddd',
51
+ link: '#0d3b66',
52
+ code: '#0d3b66',
53
+ codeBg: 'rgba(244, 211, 94, 0.4)',
54
+ blockquote: '#5a7a9b',
55
+ hr: '#5a7a9b',
56
56
  bg: 'transparent',
57
57
  }
58
58
  };
@@ -97,16 +97,16 @@ export const cave = {
97
97
  },
98
98
  previewColors: {
99
99
  text: '#c5dde8',
100
- h1: '#e0e0e0',
101
- h2: '#d0d0d0',
102
- h3: '#c0c0c0',
100
+ h1: 'inherit',
101
+ h2: 'inherit',
102
+ h3: 'inherit',
103
103
  strong: 'inherit',
104
104
  em: 'inherit',
105
- link: '#6cb6e0',
105
+ link: '#9fcfec',
106
106
  code: '#c5dde8',
107
- codeBg: 'rgba(255, 255, 255, 0.08)',
108
- blockquote: '#9aa8b4',
109
- hr: 'rgba(255, 255, 255, 0.15)',
107
+ codeBg: '#1a232b',
108
+ blockquote: '#9fcfec',
109
+ hr: '#c5dde8',
110
110
  bg: 'transparent',
111
111
  }
112
112
  };
@@ -162,7 +162,7 @@ export function themeToCSSVars(colors, previewColors) {
162
162
  if (previewColors) {
163
163
  for (const [key, value] of Object.entries(previewColors)) {
164
164
  const varName = key.replace(/([A-Z])/g, '-$1').toLowerCase();
165
- vars.push(`--preview-${varName}: ${value};`);
165
+ vars.push(`--preview-${varName}-default: ${value};`);
166
166
  }
167
167
  }
168
168
  return vars.join('\n');