overtype 2.3.4 → 2.3.5
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.
- package/README.md +3 -3
- package/dist/overtype-webcomponent.esm.js +31 -2
- package/dist/overtype-webcomponent.esm.js.map +2 -2
- package/dist/overtype-webcomponent.js +31 -2
- package/dist/overtype-webcomponent.js.map +2 -2
- package/dist/overtype-webcomponent.min.js +20 -10
- package/dist/overtype.cjs +15 -1
- package/dist/overtype.cjs.map +2 -2
- package/dist/overtype.esm.js +15 -1
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +15 -1
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +16 -6
- package/package.json +3 -2
- package/src/overtype-webcomponent.js +17 -1
- package/src/overtype.js +6 -0
- package/src/styles.js +10 -0
package/dist/overtype.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.3.
|
|
2
|
+
* OverType v2.3.5
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -238,6 +238,16 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
238
238
|
-ms-user-select: none !important;
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
/* Prevent external resets (Tailwind, Bootstrap, etc.) from breaking alignment.
|
|
242
|
+
Any element whose font metrics differ from the textarea causes the CSS "strut"
|
|
243
|
+
to inflate line boxes, drifting the overlay. Force inheritance so every element
|
|
244
|
+
inside the preview matches the textarea exactly. */
|
|
245
|
+
.overtype-wrapper .overtype-preview * {
|
|
246
|
+
font-family: inherit !important;
|
|
247
|
+
font-size: inherit !important;
|
|
248
|
+
line-height: inherit !important;
|
|
249
|
+
}
|
|
250
|
+
|
|
241
251
|
/* Defensive styles for preview child divs */
|
|
242
252
|
.overtype-wrapper .overtype-preview div {
|
|
243
253
|
/* Reset any inherited styles */
|
|
@@ -879,7 +889,7 @@ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDesc
|
|
|
879
889
|
}
|
|
880
890
|
|
|
881
891
|
${a}
|
|
882
|
-
`}var gn=Object.defineProperty,Qe=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,Ge=(t,e,n)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Je=(t,e)=>{for(var n in e||(e={}))vn.call(e,n)&&Ge(t,n,e[n]);if(Qe)for(var n of Qe(e))yn.call(e,n)&&Ge(t,n,e[n]);return t},I={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 wn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function
|
|
892
|
+
`}var gn=Object.defineProperty,Qe=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,Ge=(t,e,n)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Je=(t,e)=>{for(var n in e||(e={}))vn.call(e,n)&&Ge(t,n,e[n]);if(Qe)for(var n of Qe(e))yn.call(e,n)&&Ge(t,n,e[n]);return t},I={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 wn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function F(t){return Je(Je({},wn()),t)}var we=!1;function bn(){return we}function x(t,e,n){we&&(console.group(`\u{1F50D} ${t}`),console.log(e),n&&console.log("Data:",n),console.groupEnd())}function ye(t,e){if(!we)return;let n=t.value.slice(t.selectionStart,t.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Selected text:",JSON.stringify(n)),console.log("Length:",n.length);let i=t.value.slice(Math.max(0,t.selectionStart-10),t.selectionStart),o=t.value.slice(t.selectionEnd,Math.min(t.value.length,t.selectionEnd+10));console.log("Context:",JSON.stringify(i)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function tt(t){we&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(t.text)),console.log("New selection:",`${t.selectionStart}-${t.selectionEnd}`),console.groupEnd())}var B=null;function U(t,{text:e,selectionStart:n,selectionEnd:i}){let o=bn();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",n,"-",i)),t.focus();let r=t.selectionStart,s=t.selectionEnd,a=t.value.slice(0,r),c=t.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(t.value.slice(r,s))));let p=t.value,l=r!==s;if(B===null||B===!0){t.contentEditable="true";try{B=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",B,"for text with",e.split(`
|
|
883
893
|
`).length,"lines")}catch(d){B=!1,o&&console.log("execCommand threw error:",d)}t.contentEditable="false"}if(o&&(console.log("canInsertText before:",B),console.log("execCommand result:",B)),B){let d=a+e+c,h=t.value;o&&(console.log("Expected length:",d.length),console.log("Actual length:",h.length)),h!==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(h.slice(0,100))))}if(!B)if(o&&console.log("Using manual insertion"),t.value===p){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(d){}t.value=a+e+c;try{document.execCommand("ms-endUndoUnit")}catch(d){}t.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:",n,i),n!=null&&i!=null?t.setSelectionRange(n,i):t.setSelectionRange(r,t.selectionEnd),o&&(console.log("Final value length:",t.value.length),console.groupEnd())}function Xe(t){return t.trim().split(`
|
|
884
894
|
`).length>1}function xn(t,e){let n=e;for(;t[n]&&t[n-1]!=null&&!t[n-1].match(/\s/);)n--;return n}function kn(t,e,n){let i=e,o=n?/\n/:/\s/;for(;t[i]&&!t[i].match(o);)i++;return i}function nt(t){let e=t.value.split(`
|
|
885
895
|
`),n=0;for(let i=0;i<e.length;i++){let o=e[i].length+1;t.selectionStart>=n&&t.selectionStart<n+o&&(t.selectionStart=n),t.selectionEnd>=n&&t.selectionEnd<n+o&&(i===e.length-1?t.selectionEnd=Math.min(n+e[i].length,t.value.length):t.selectionEnd=n+o-1),n+=o}}function Ln(t,e,n,i=!1){if(t.selectionStart===t.selectionEnd)t.selectionStart=xn(t.value,t.selectionStart),t.selectionEnd=kn(t.value,t.selectionEnd,i);else{let o=t.selectionStart-e.length,r=t.selectionEnd+n.length,s=t.value.slice(o,t.selectionStart)===e,a=t.value.slice(t.selectionEnd,r)===n;s&&a&&(t.selectionStart=o,t.selectionEnd=r)}return t.value.slice(t.selectionStart,t.selectionEnd)}function $e(t){let e=t.value.slice(0,t.selectionStart),n=t.value.slice(t.selectionEnd),i=e.match(/\n*$/),o=n.match(/^\n*/),r=i?i[0].length:0,s=o?o[0].length:0,a="",c="";return e.match(/\S/)&&r<2&&(a=`
|
|
@@ -898,9 +908,9 @@ ${a}`:r;if(p){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
|
|
|
898
908
|
`),processed:i}}function se(t,e){return e?"- ":`${t+1}. `}function Sn(t,e){let n,i,o;return t.orderedList?(n=Ye(e),i=et(n.text),o=i.text):(n=et(e),i=Ye(n.text),o=i.text),[n,i,o]}function En(t,e){let n=t.selectionStart===t.selectionEnd,i=t.selectionStart,o=t.selectionEnd;nt(t);let r=t.value.slice(t.selectionStart,t.selectionEnd),[s,a,c]=Sn(e,r),p=c.split(`
|
|
899
909
|
`).map((m,g)=>`${se(g,e.unorderedList)}${m}`),l=p.reduce((m,g,y)=>m+se(y,e.unorderedList).length,0),d=p.reduce((m,g,y)=>m+se(y,!e.unorderedList).length,0);if(s.processed)return n?(i=Math.max(i-se(0,e.unorderedList).length,0),o=i):(i=t.selectionStart,o=t.selectionEnd-l),{text:c,selectionStart:i,selectionEnd:o};let{newlinesToAppend:h,newlinesToPrepend:u}=$e(t),f=h+p.join(`
|
|
900
910
|
`)+u;return n?(i=Math.max(i+se(0,e.unorderedList).length+h.length,0),o=i):a.processed?(i=Math.max(t.selectionStart+h.length,0),o=t.selectionEnd+h.length+l-d):(i=Math.max(t.selectionStart+h.length,0),o=t.selectionEnd+h.length+l),{text:f,selectionStart:i,selectionEnd:o}}function ot(t,e){let n=be(t,i=>En(i,e),{adjustSelection:(i,o,r,s)=>{let a=t.value.slice(s,t.selectionEnd),c=/^\d+\.\s+/,p=/^- /,l=c.test(a),d=p.test(a),h=e.orderedList&&l||e.unorderedList&&d;if(o===r)if(h){let u=a.match(e.orderedList?c:p),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||d){let u=a.match(l?c:p),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:o+u}}else if(h){let u=a.match(e.orderedList?c:p),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||d){let u=a.match(l?c:p),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:r+u}}}});U(t,n)}function Tn(t){if(!t)return[];let e=[],{selectionStart:n,selectionEnd:i,value:o}=t,r=o.split(`
|
|
901
|
-
`),s=0,a="";for(let d of r){if(n>=s&&n<=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,n-10),p=Math.min(o.length,i+10),l=o.slice(c,p);if(l.includes("**")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100));d.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&o.slice(i+f+1,i+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=
|
|
911
|
+
`),s=0,a="";for(let d of r){if(n>=s&&n<=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,n-10),p=Math.min(o.length,i+10),l=o.slice(c,p);if(l.includes("**")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100));d.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&o.slice(i+f+1,i+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),i=F(I.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(i.suffix=`](${n})`,i.replaceNext=""):e.url&&(i.suffix=`](${e.url})`,i.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,i);U(t,r)}function ct(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.bulletList);ot(t,e)}function pt(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.numberedList);ot(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,i=>it(i,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,i=>it(i,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 i=`header${e===1?"1":e}`,o=F(I[i]||I.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=t.value,s=t.selectionStart,a=t.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
|
|
902
912
|
`;)c--;let p=a;for(;p<r.length&&r[p]!==`
|
|
903
|
-
`;)p++;let l=r.slice(c,p);x("insertHeader",`Current line (before): "${l}"`);let d=l.match(/^(#{1,6})\s*/),h=d?d[1].length:0,u=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[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=o.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=o.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.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=o.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 +${o.prefix.length}`),{start:y+o.prefix.length,end:w+o.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",i=>{i.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=i=>{i.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,i)},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 i=this.createViewModeDropdown(e),o=e.getBoundingClientRect();i.style.position="absolute",i.style.top=`${o.bottom+5}px`,i.style.left=`${o.left}px`,document.body.appendChild(i),this.handleDocumentClick=r=>{!i.contains(r.target)&&!e.contains(r.target)&&(i.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 i=[{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 i.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}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(([i,o])=>{if(i==="viewMode")return;let r=!1;switch(i){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}o.classList.toggle("active",r),o.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 O=t=>({x:t,y:t}),Cn={left:"right",right:"left",bottom:"top",top:"bottom"},An={start:"end",end:"start"};function _e(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 Be(t){return t==="x"?"y":"x"}function Ne(t){return t==="y"?"height":"width"}var Mn=new Set(["top","bottom"]);function F(t){return Mn.has(W(t))?"y":"x"}function Fe(t){return Be(F(t))}function wt(t,e,n){n===void 0&&(n=!1);let i=de(t),o=Fe(t),r=Ne(o),s=o==="x"?i===(n?"end":"start")?"right":"left":i==="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"],Pn=["bottom","top"];function On(t,e,n){switch(t){case"top":case"bottom":return n?e?yt:vt:e?vt:yt;case"left":case"right":return e?Hn:Pn;default:return[]}}function xt(t,e,n,i){let o=de(t),r=On(W(t),n==="start",i);return o&&(r=r.map(s=>s+"-"+o),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:i,height:o}=t;return{width:i,height:o,top:n,left:e,right:e+i,bottom:n+o,x:e,y:n}}function Lt(t,e,n){let{reference:i,floating:o}=t,r=F(e),s=Fe(e),a=Ne(s),c=W(e),p=r==="y",l=i.x+i.width/2-o.width/2,d=i.y+i.height/2-o.height/2,h=i[a]/2-o[a]/2,u;switch(c){case"top":u={x:l,y:i.y-o.height};break;case"bottom":u={x:l,y:i.y+i.height};break;case"right":u={x:i.x+i.width,y:d};break;case"left":u={x:i.x-o.width,y:d};break;default:u={x:i.x,y:i.y}}switch(de(e)){case"start":u[s]-=h*(n&&p?-1:1);break;case"end":u[s]+=h*(n&&p?-1:1);break}return u}async function St(t,e){var n;e===void 0&&(e={});let{x:i,y:o,platform:r,rects:s,elements:a,strategy:c}=t,{boundary:p="clippingAncestors",rootBoundary:l="viewport",elementContext:d="floating",altBoundary:h=!1,padding:u=0}=pe(e,t),f=kt(u),g=a[h?d==="floating"?"reference":"floating":d],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:p,rootBoundary:l,strategy:c})),w=d==="floating"?{x:i,y:o,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:i="bottom",strategy:o="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:t,floating:e,strategy:o}),{x:l,y:d}=Lt(p,i,c),h=i,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:d,initialPlacement:i,placement:h,strategy:o,middlewareData:u,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:St},elements:{reference:t,floating:e}});l=b!=null?b:l,d=L!=null?L:d,u={...u,[y]:{...u[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(h=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:o}):E.rects),{x:l,y:d}=Lt(p,h,c)),g=-1)}return{x:l,y:d,placement:h,strategy:o,middlewareData:u}};var Tt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,i;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:p}=e,{mainAxis:l=!0,crossAxis:d=!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(o),w=F(a),b=W(a)===a,L=await(c.isRTL==null?void 0:c.isRTL(p.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=((i=r.flip)==null?void 0:i.overflows)||[];if(l&&ge.push(Y[y]),d){let K=wt(o,s,L);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ge}],!ge.every(K=>K<=0)){var je,Ve;let K=(((je=r.flip)==null?void 0:je.index)||0)+1,Pe=me[K];if(Pe&&(!(d==="alignment"?w!==F(Pe):!1)||ee.every(P=>F(P.placement)===w?P.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let oe=(Ve=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,P)=>Z.overflows[1]-P.overflows[1])[0])==null?void 0:Ve.placement;if(!oe)switch(u){case"bestFit":{var Ue;let Z=(Ue=ee.filter(P=>{if(E){let j=F(P.placement);return j===w||j==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(j=>j>0).reduce((j,ln)=>j+ln,0)]).sort((P,j)=>P[1]-j[1])[0])==null?void 0:Ue[0];Z&&(oe=Z);break}case"initialPlacement":oe=a;break}if(o!==oe)return{reset:{placement:oe}}}return{}}}};var In=new Set(["left","top"]);async function Rn(t,e){let{placement:n,platform:i,elements:o}=t,r=await(i.isRTL==null?void 0:i.isRTL(o.floating)),s=W(n),a=de(n),c=F(n)==="y",p=In.has(s)?-1:1,l=r&&c?-1:1,d=pe(e,t),{mainAxis:h,crossAxis:u,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"&&(u=a==="end"?f*-1:f),c?{x:u*l,y:h*p}:{x:h*p,y:u*l}}var Ct=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,i;let{x:o,y:r,placement:s,middlewareData:a}=e,c=await Rn(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(i=a.arrow)!=null&&i.alignmentOffset?{}:{x:o+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:i,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...p}=pe(t,e),l={x:n,y:i},d=await r.detectOverflow(e,p),h=F(W(o)),u=Be(h),f=l[u],m=l[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=_e(b,f,L)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=_e(b,m,L)}let g=c.fn({...e,[u]:f,[h]:m});return{...g,data:{x:g.x-n,y:g.y-i,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 _n=new Set(["inline","contents"]);function te(t){let{overflow:e,overflowX:n,overflowY:i,display:o}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!_n.has(o)}var Bn=new Set(["table","td","th"]);function Pt(t){return Bn.has(J(t))}var Nn=[":popover-open",":modal"];function ue(t){return Nn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Fn=["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 Fn.some(i=>n[i]?n[i]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Dn.some(i=>(n.willChange||"").includes(i))||zn.some(i=>(n.contain||"").includes(i))}function Ot(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 i;e===void 0&&(e=[]),n===void 0&&(n=!0);let o=$t(t),r=o===((i=t.ownerDocument)==null?void 0:i.body),s=A(o);if(r){let a=Ae(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&n?Se(a):[])}return e.concat(o,Se(o,[],n))}function Ae(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Bt(t){let e=H(t),n=parseFloat(e.width)||0,i=parseFloat(e.height)||0,o=$(t),r=o?t.offsetWidth:n,s=o?t.offsetHeight:i,a=ce(n)!==r||ce(i)!==s;return a&&(n=r,i=s),{width:n,height:i,$:a}}function Nt(t){return M(t)?t:t.contextElement}function ne(t){let e=Nt(t);if(!$(e))return O(1);let n=e.getBoundingClientRect(),{width:i,height:o,$:r}=Bt(e),s=(r?ce(n.width):n.width)/i,a=(r?ce(n.height):n.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Vn=O(0);function Ft(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,i){e===void 0&&(e=!1),n===void 0&&(n=!1);let o=t.getBoundingClientRect(),r=Nt(t),s=O(1);e&&(i?M(i)&&(s=ne(i)):s=ne(t));let a=Un(r,n,i)?Ft(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 h=A(r),u=i&&M(i)?A(i):i,f=h,m=Ae(f);for(;m&&i&&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,p*=g.y,l*=g.x,d*=g.y,c+=b,p+=L,f=A(m),m=Ae(f)}}return G({width:l,height:d,x:c,y:p})}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(),i=n.left+e.scrollLeft-Me(t,n),o=n.top+e.scrollTop;return{x:i,y:o}}function qn(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t,r=o==="fixed",s=R(i),a=e?ue(e.floating):!1;if(i===s||a&&r)return n;let c={scrollLeft:0,scrollTop:0},p=O(1),l=O(0),d=$(i);if((d||!d&&!r)&&((J(i)!=="body"||te(s))&&(c=he(i)),$(i))){let u=fe(i);p=ne(i),l.x=u.x+i.clientLeft,l.y=u.y+i.clientTop}let h=s&&!d&&!r?Dt(s,c):O(0);return{width:n.width*p.x,height:n.height*p.y,x:n.x*p.x-c.scrollLeft*p.x+l.x+h.x,y:n.y*p.y-c.scrollTop*p.y+l.y+h.y}}function Wn(t){return Array.from(t.getClientRects())}function Kn(t){let e=R(t),n=he(t),i=t.ownerDocument.body,o=q(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),r=q(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight),s=-n.scrollLeft+Me(t),a=-n.scrollTop;return H(i).direction==="rtl"&&(s+=q(e.clientWidth,i.clientWidth)-o),{width:o,height:r,x:s,y:a}}var It=25;function Zn(t,e){let n=A(t),i=R(t),o=n.visualViewport,r=i.clientWidth,s=i.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=Ce();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let p=Me(i);if(p<=0){let l=i.ownerDocument,d=l.body,h=getComputedStyle(d),u=l.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(i.clientWidth-d.clientWidth-u);f<=It&&(r-=f)}else p<=It&&(r+=p);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"),i=n.top+t.clientTop,o=n.left+t.clientLeft,r=$(t)?ne(t):O(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,c=o*r.x,p=i*r.y;return{width:s,height:a,x:c,y:p}}function Rt(t,e,n){let i;if(e==="viewport")i=Zn(t,n);else if(e==="document")i=Kn(R(t));else if(M(e))i=Gn(e,n);else{let o=Ft(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(i)}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 i=Se(t,[],!1).filter(a=>M(a)&&J(a)!=="body"),o=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"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Qn.has(o.position)||te(s)&&!c&&zt(t,s))?i=i.filter(l=>l!==s):o=a,s=D(s)}return e.set(t,i),i}function Xn(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t,s=[...n==="clippingAncestors"?ue(e)?[]:Jn(e,this._c):[].concat(n),i],a=s[0],c=s.reduce((p,l)=>{let d=Rt(e,l,o);return p.top=q(d.top,p.top),p.right=le(d.right,p.right),p.bottom=le(d.bottom,p.bottom),p.left=q(d.left,p.left),p},Rt(e,a,o));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}=Bt(t);return{width:e,height:n}}function ei(t,e,n){let i=$(e),o=R(e),r=n==="fixed",s=fe(t,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function p(){c.x=Me(o)}if(i||!i&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),i){let u=fe(e,!0,r,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else o&&p();r&&!i&&o&&p();let l=o&&!i&&!r?Dt(o,a):O(0),d=s.left+a.scrollLeft-c.x-l.x,h=s.top+a.scrollTop-c.y-l.y;return{x:d,y:h,width:s.width,height:s.height}}function De(t){return H(t).position==="static"}function _t(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 o=D(t);for(;o&&!X(o);){if(M(o)&&!De(o))return o;o=D(o)}return n}let i=_t(t,e);for(;i&&Pt(i)&&De(i);)i=_t(i,e);return i&&X(i)&&De(i)&&!Te(i)?n:i||Ot(t)||n}var ti=async function(t){let e=this.getOffsetParent||jt,n=this.getDimensions,i=await n(t.floating);return{reference:ei(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function ni(t){return H(t).direction==="rtl"}var ii={convertOffsetParentRelativeRectToViewportRelativeRect:qn,getDocumentElement:R,getClippingRect:Xn,getOffsetParent:jt,getElementRects:ti,getClientRects:Wn,getDimensions:Yn,getScale:ne,isElement:M,isRTL:ni};var Vt=Ct;var Ut=At,qt=Tt;var Wt=(t,e,n)=>{let i=new Map,o={platform:ii,...n},r={...o.platform,_c:i};return Et(t,e,{...o,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=`
|
|
913
|
+
`;)p++;let l=r.slice(c,p);x("insertHeader",`Current line (before): "${l}"`);let d=l.match(/^(#{1,6})\s*/),h=d?d[1].length:0,u=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[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=o.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=o.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.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=o.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 +${o.prefix.length}`),{start:y+o.prefix.length,end:w+o.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",i=>{i.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=i=>{i.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,i)},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 i=this.createViewModeDropdown(e),o=e.getBoundingClientRect();i.style.position="absolute",i.style.top=`${o.bottom+5}px`,i.style.left=`${o.left}px`,document.body.appendChild(i),this.handleDocumentClick=r=>{!i.contains(r.target)&&!e.contains(r.target)&&(i.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 i=[{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 i.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}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(([i,o])=>{if(i==="viewMode")return;let r=!1;switch(i){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}o.classList.toggle("active",r),o.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 O=t=>({x:t,y:t}),Cn={left:"right",right:"left",bottom:"top",top:"bottom"},An={start:"end",end:"start"};function _e(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 Be(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 Be(N(t))}function wt(t,e,n){n===void 0&&(n=!1);let i=de(t),o=Ne(t),r=Fe(o),s=o==="x"?i===(n?"end":"start")?"right":"left":i==="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"],Pn=["bottom","top"];function On(t,e,n){switch(t){case"top":case"bottom":return n?e?yt:vt:e?vt:yt;case"left":case"right":return e?Hn:Pn;default:return[]}}function xt(t,e,n,i){let o=de(t),r=On(W(t),n==="start",i);return o&&(r=r.map(s=>s+"-"+o),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:i,height:o}=t;return{width:i,height:o,top:n,left:e,right:e+i,bottom:n+o,x:e,y:n}}function Lt(t,e,n){let{reference:i,floating:o}=t,r=N(e),s=Ne(e),a=Fe(s),c=W(e),p=r==="y",l=i.x+i.width/2-o.width/2,d=i.y+i.height/2-o.height/2,h=i[a]/2-o[a]/2,u;switch(c){case"top":u={x:l,y:i.y-o.height};break;case"bottom":u={x:l,y:i.y+i.height};break;case"right":u={x:i.x+i.width,y:d};break;case"left":u={x:i.x-o.width,y:d};break;default:u={x:i.x,y:i.y}}switch(de(e)){case"start":u[s]-=h*(n&&p?-1:1);break;case"end":u[s]+=h*(n&&p?-1:1);break}return u}async function St(t,e){var n;e===void 0&&(e={});let{x:i,y:o,platform:r,rects:s,elements:a,strategy:c}=t,{boundary:p="clippingAncestors",rootBoundary:l="viewport",elementContext:d="floating",altBoundary:h=!1,padding:u=0}=pe(e,t),f=kt(u),g=a[h?d==="floating"?"reference":"floating":d],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:p,rootBoundary:l,strategy:c})),w=d==="floating"?{x:i,y:o,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:i="bottom",strategy:o="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:t,floating:e,strategy:o}),{x:l,y:d}=Lt(p,i,c),h=i,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:d,initialPlacement:i,placement:h,strategy:o,middlewareData:u,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:St},elements:{reference:t,floating:e}});l=b!=null?b:l,d=L!=null?L:d,u={...u,[y]:{...u[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(h=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:o}):E.rects),{x:l,y:d}=Lt(p,h,c)),g=-1)}return{x:l,y:d,placement:h,strategy:o,middlewareData:u}};var Tt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,i;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:p}=e,{mainAxis:l=!0,crossAxis:d=!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(o),w=N(a),b=W(a)===a,L=await(c.isRTL==null?void 0:c.isRTL(p.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=((i=r.flip)==null?void 0:i.overflows)||[];if(l&&ge.push(Y[y]),d){let K=wt(o,s,L);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ge}],!ge.every(K=>K<=0)){var je,Ve;let K=(((je=r.flip)==null?void 0:je.index)||0)+1,Pe=me[K];if(Pe&&(!(d==="alignment"?w!==N(Pe):!1)||ee.every(P=>N(P.placement)===w?P.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let oe=(Ve=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,P)=>Z.overflows[1]-P.overflows[1])[0])==null?void 0:Ve.placement;if(!oe)switch(u){case"bestFit":{var Ue;let Z=(Ue=ee.filter(P=>{if(E){let j=N(P.placement);return j===w||j==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(j=>j>0).reduce((j,ln)=>j+ln,0)]).sort((P,j)=>P[1]-j[1])[0])==null?void 0:Ue[0];Z&&(oe=Z);break}case"initialPlacement":oe=a;break}if(o!==oe)return{reset:{placement:oe}}}return{}}}};var In=new Set(["left","top"]);async function Rn(t,e){let{placement:n,platform:i,elements:o}=t,r=await(i.isRTL==null?void 0:i.isRTL(o.floating)),s=W(n),a=de(n),c=N(n)==="y",p=In.has(s)?-1:1,l=r&&c?-1:1,d=pe(e,t),{mainAxis:h,crossAxis:u,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"&&(u=a==="end"?f*-1:f),c?{x:u*l,y:h*p}:{x:h*p,y:u*l}}var Ct=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,i;let{x:o,y:r,placement:s,middlewareData:a}=e,c=await Rn(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(i=a.arrow)!=null&&i.alignmentOffset?{}:{x:o+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:i,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...p}=pe(t,e),l={x:n,y:i},d=await r.detectOverflow(e,p),h=N(W(o)),u=Be(h),f=l[u],m=l[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=_e(b,f,L)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=_e(b,m,L)}let g=c.fn({...e,[u]:f,[h]:m});return{...g,data:{x:g.x-n,y:g.y-i,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 _n=new Set(["inline","contents"]);function te(t){let{overflow:e,overflowX:n,overflowY:i,display:o}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!_n.has(o)}var Bn=new Set(["table","td","th"]);function Pt(t){return Bn.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(i=>n[i]?n[i]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Dn.some(i=>(n.willChange||"").includes(i))||zn.some(i=>(n.contain||"").includes(i))}function Ot(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 i;e===void 0&&(e=[]),n===void 0&&(n=!0);let o=$t(t),r=o===((i=t.ownerDocument)==null?void 0:i.body),s=A(o);if(r){let a=Ae(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&n?Se(a):[])}return e.concat(o,Se(o,[],n))}function Ae(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Bt(t){let e=H(t),n=parseFloat(e.width)||0,i=parseFloat(e.height)||0,o=$(t),r=o?t.offsetWidth:n,s=o?t.offsetHeight:i,a=ce(n)!==r||ce(i)!==s;return a&&(n=r,i=s),{width:n,height:i,$:a}}function Ft(t){return M(t)?t:t.contextElement}function ne(t){let e=Ft(t);if(!$(e))return O(1);let n=e.getBoundingClientRect(),{width:i,height:o,$:r}=Bt(e),s=(r?ce(n.width):n.width)/i,a=(r?ce(n.height):n.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Vn=O(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,i){e===void 0&&(e=!1),n===void 0&&(n=!1);let o=t.getBoundingClientRect(),r=Ft(t),s=O(1);e&&(i?M(i)&&(s=ne(i)):s=ne(t));let a=Un(r,n,i)?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 h=A(r),u=i&&M(i)?A(i):i,f=h,m=Ae(f);for(;m&&i&&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,p*=g.y,l*=g.x,d*=g.y,c+=b,p+=L,f=A(m),m=Ae(f)}}return G({width:l,height:d,x:c,y:p})}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(),i=n.left+e.scrollLeft-Me(t,n),o=n.top+e.scrollTop;return{x:i,y:o}}function qn(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t,r=o==="fixed",s=R(i),a=e?ue(e.floating):!1;if(i===s||a&&r)return n;let c={scrollLeft:0,scrollTop:0},p=O(1),l=O(0),d=$(i);if((d||!d&&!r)&&((J(i)!=="body"||te(s))&&(c=he(i)),$(i))){let u=fe(i);p=ne(i),l.x=u.x+i.clientLeft,l.y=u.y+i.clientTop}let h=s&&!d&&!r?Dt(s,c):O(0);return{width:n.width*p.x,height:n.height*p.y,x:n.x*p.x-c.scrollLeft*p.x+l.x+h.x,y:n.y*p.y-c.scrollTop*p.y+l.y+h.y}}function Wn(t){return Array.from(t.getClientRects())}function Kn(t){let e=R(t),n=he(t),i=t.ownerDocument.body,o=q(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),r=q(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight),s=-n.scrollLeft+Me(t),a=-n.scrollTop;return H(i).direction==="rtl"&&(s+=q(e.clientWidth,i.clientWidth)-o),{width:o,height:r,x:s,y:a}}var It=25;function Zn(t,e){let n=A(t),i=R(t),o=n.visualViewport,r=i.clientWidth,s=i.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=Ce();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let p=Me(i);if(p<=0){let l=i.ownerDocument,d=l.body,h=getComputedStyle(d),u=l.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(i.clientWidth-d.clientWidth-u);f<=It&&(r-=f)}else p<=It&&(r+=p);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"),i=n.top+t.clientTop,o=n.left+t.clientLeft,r=$(t)?ne(t):O(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,c=o*r.x,p=i*r.y;return{width:s,height:a,x:c,y:p}}function Rt(t,e,n){let i;if(e==="viewport")i=Zn(t,n);else if(e==="document")i=Kn(R(t));else if(M(e))i=Gn(e,n);else{let o=Nt(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(i)}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 i=Se(t,[],!1).filter(a=>M(a)&&J(a)!=="body"),o=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"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Qn.has(o.position)||te(s)&&!c&&zt(t,s))?i=i.filter(l=>l!==s):o=a,s=D(s)}return e.set(t,i),i}function Xn(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t,s=[...n==="clippingAncestors"?ue(e)?[]:Jn(e,this._c):[].concat(n),i],a=s[0],c=s.reduce((p,l)=>{let d=Rt(e,l,o);return p.top=q(d.top,p.top),p.right=le(d.right,p.right),p.bottom=le(d.bottom,p.bottom),p.left=q(d.left,p.left),p},Rt(e,a,o));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}=Bt(t);return{width:e,height:n}}function ei(t,e,n){let i=$(e),o=R(e),r=n==="fixed",s=fe(t,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function p(){c.x=Me(o)}if(i||!i&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),i){let u=fe(e,!0,r,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else o&&p();r&&!i&&o&&p();let l=o&&!i&&!r?Dt(o,a):O(0),d=s.left+a.scrollLeft-c.x-l.x,h=s.top+a.scrollTop-c.y-l.y;return{x:d,y:h,width:s.width,height:s.height}}function De(t){return H(t).position==="static"}function _t(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 o=D(t);for(;o&&!X(o);){if(M(o)&&!De(o))return o;o=D(o)}return n}let i=_t(t,e);for(;i&&Pt(i)&&De(i);)i=_t(i,e);return i&&X(i)&&De(i)&&!Te(i)?n:i||Ot(t)||n}var ti=async function(t){let e=this.getOffsetParent||jt,n=this.getDimensions,i=await n(t.floating);return{reference:ei(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function ni(t){return H(t).direction==="rtl"}var ii={convertOffsetParentRelativeRectToViewportRelativeRect:qn,getDocumentElement:R,getClippingRect:Xn,getOffsetParent:jt,getElementRects:ti,getClientRects:Wn,getDimensions:Yn,getScale:ne,isElement:M,isRTL:ni};var Vt=Ct;var Ut=At,qt=Tt;var Wt=(t,e,n)=>{let i=new Map,o={platform:ii,...n},r={...o.platform,_c:i};return Et(t,e,{...o,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=`
|
|
904
914
|
<span style="display: flex; align-items: center; gap: 6px;">
|
|
905
915
|
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
|
|
906
916
|
<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>
|
|
@@ -961,8 +971,8 @@ ${a}`:r;if(p){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
|
|
|
961
971
|
</svg>`,sn=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
962
972
|
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path>
|
|
963
973
|
<circle cx="12" cy="12" r="3" fill="none"></circle>
|
|
964
|
-
</svg>`;var S={bold:{name:"bold",actionId:"toggleBold",icon:Kt,title:"Bold (Ctrl+B)",action:({editor:t})=>{rt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Zt,title:"Italic (Ctrl+I)",action:({editor:t})=>{st(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:Yt,title:"Inline Code",action:({editor:t})=>{at(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Xt,title:"Insert Link",action:({editor:t})=>{lt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:Qt,title:"Heading 1",action:({editor:t})=>{ut(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Gt,title:"Heading 2",action:({editor:t})=>{ht(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Jt,title:"Heading 3",action:({editor:t})=>{ft(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:en,title:"Bullet List",action:({editor:t})=>{ct(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:tn,title:"Numbered List",action:({editor:t})=>{pt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:on,title:"Task List",action:({editor:t})=>{Ie&&(Ie(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:nn,title:"Quote",action:({editor:t})=>{dt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:rn,title:"Upload File",action:({editor:t})=>{var n,i;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((i=t.options.fileUpload.mimeTypes)==null?void 0:i.length)>0&&(e.accept=t.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);t._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:sn,title:"View mode"}},ie=[S.bold,S.italic,S.code,S.separator,S.link,S.separator,S.h1,S.h2,S.h3,S.separator,S.bulletList,S.orderedList,S.taskList,S.separator,S.quote,S.separator,S.viewMode];function ze(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let i=n.actionId||n.name;n.action&&(e[i]=n.action)}),e}function an(t){let e=t||ie;return Array.isArray(e)?e.map(n=>({name:(n==null?void 0:n.name)||null,actionId:(n==null?void 0:n.actionId)||(n==null?void 0:n.name)||null,icon:(n==null?void 0:n.icon)||null,title:(n==null?void 0:n.title)||null})):null}function ri(t,e){let n=an(t),i=an(e);if(n===null||i===null)return n!==i;if(n.length!==i.length)return!0;for(let o=0;o<n.length;o++){let r=n[o],s=i[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,n={}){let i;if(typeof e=="string"){if(i=document.querySelectorAll(e),i.length===0)throw new Error(`No elements found for selector: ${e}`);i=Array.from(i)}else if(e instanceof Element)i=[e];else if(e instanceof NodeList)i=Array.from(e);else if(Array.isArray(e))i=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return i.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(n),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,n),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,n={}){this.element=e,this.instanceTheme=n.theme||null,this.options=this._mergeOptions(n),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.initGlobalListeners();let i=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");i||o?this._recoverFromDOM(i,o):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new re(this),this._rebuildActionsMap(),this.linkTooltip=new He(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 n={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:i,colors:o,...r}=e;return{...n,...r}}_recoverFromDOM(e,n){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(n){this.wrapper=n,this.container=document.createElement("div"),this.container.className="overtype-container";let i=this.instanceTheme||v.currentTheme||_,o=typeof i=="string"?i:i.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}n.parentNode.insertBefore(this.container,n),this.container.appendChild(n)}if(!this.wrapper){e&&e.remove(),n&&n.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||_,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let i=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(i&&i.colors){let o=Q(i.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(([i,o])=>{i==="className"||i==="class"?this.textarea.className+=" "+o:i==="style"&&typeof o=="object"?Object.assign(this.textarea.style,o):this.textarea.setAttribute(i,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 n;let e=this.options.toolbarButtons||ie;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(i=>(i==null?void 0:i.name)==="upload")){let i=e.findIndex(o=>(o==null?void 0:o.name)==="viewMode");i!==-1?(e=[...e],e.splice(i,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new ke(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=ze(ie),this.options.toolbarButtons&&Object.assign(this.actionsById,ze(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,ze([S.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 n,i;(i=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,i;(i=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let i of e.files){if(i.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(i.type))continue;let o=++this._fileUploadCounter,s=`${i.type.startsWith("image/")?"!":""}[Uploading ${i.name} (#${o})...]()`;if(this.insertAtCursor(`${s}
|
|
965
|
-
`),this.options.fileUpload.batch){n.push({file:i,placeholder:s});continue}this.options.fileUpload.onInsertFile(i).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&&n.length>0&&this.options.fileUpload.onInsertFile(n.map(i=>i.file)).then(i=>{(Array.isArray(i)?i:[i]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},i=>{console.error("OverType: File upload failed",i),n.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 n=this.textarea.selectionStart,i=this.textarea.selectionEnd,o=!1;try{o=document.execCommand("insertText",!1,e)}catch(r){}if(!o){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(i);this.textarea.value=r+e+s,this.textarea.setSelectionRange(n+e.length,n+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,n=this.textarea.selectionStart,i=this._getCurrentLine(e,n),o=this.container.dataset.mode==="preview",r=T.parse(e,i,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)}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let n=0;n<e.length-1;n+=2){let i=e[n],o=e[n+1],r=i.parentElement,s=o.parentElement;!r||!s||(i.style.display="block",o.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,n){return e.substring(0,n).split(`
|
|
974
|
+
</svg>`;var S={bold:{name:"bold",actionId:"toggleBold",icon:Kt,title:"Bold (Ctrl+B)",action:({editor:t})=>{rt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Zt,title:"Italic (Ctrl+I)",action:({editor:t})=>{st(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:Yt,title:"Inline Code",action:({editor:t})=>{at(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Xt,title:"Insert Link",action:({editor:t})=>{lt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:Qt,title:"Heading 1",action:({editor:t})=>{ut(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Gt,title:"Heading 2",action:({editor:t})=>{ht(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Jt,title:"Heading 3",action:({editor:t})=>{ft(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:en,title:"Bullet List",action:({editor:t})=>{ct(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:tn,title:"Numbered List",action:({editor:t})=>{pt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:on,title:"Task List",action:({editor:t})=>{Ie&&(Ie(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:nn,title:"Quote",action:({editor:t})=>{dt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:rn,title:"Upload File",action:({editor:t})=>{var n,i;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((i=t.options.fileUpload.mimeTypes)==null?void 0:i.length)>0&&(e.accept=t.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);t._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:sn,title:"View mode"}},ie=[S.bold,S.italic,S.code,S.separator,S.link,S.separator,S.h1,S.h2,S.h3,S.separator,S.bulletList,S.orderedList,S.taskList,S.separator,S.quote,S.separator,S.viewMode];function ze(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let i=n.actionId||n.name;n.action&&(e[i]=n.action)}),e}function an(t){let e=t||ie;return Array.isArray(e)?e.map(n=>({name:(n==null?void 0:n.name)||null,actionId:(n==null?void 0:n.actionId)||(n==null?void 0:n.name)||null,icon:(n==null?void 0:n.icon)||null,title:(n==null?void 0:n.title)||null})):null}function ri(t,e){let n=an(t),i=an(e);if(n===null||i===null)return n!==i;if(n.length!==i.length)return!0;for(let o=0;o<n.length;o++){let r=n[o],s=i[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,n={}){let i;if(typeof e=="string"){if(i=document.querySelectorAll(e),i.length===0)throw new Error(`No elements found for selector: ${e}`);i=Array.from(i)}else if(e instanceof Element)i=[e];else if(e instanceof NodeList)i=Array.from(e);else if(Array.isArray(e))i=e;else throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");return i.map(r=>{if(r.overTypeInstance)return r.overTypeInstance.reinit(n),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,n),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,n={}){this.element=e,this.instanceTheme=n.theme||null,this.options=this._mergeOptions(n),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.initGlobalListeners();let i=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");i||o?this._recoverFromDOM(i,o):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new re(this),this._rebuildActionsMap(),this.linkTooltip=new He(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 n={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:i,colors:o,...r}=e;return{...n,...r}}_recoverFromDOM(e,n){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(n){this.wrapper=n,this.container=document.createElement("div"),this.container.className="overtype-container";let i=this.instanceTheme||v.currentTheme||_,o=typeof i=="string"?i:i.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}n.parentNode.insertBefore(this.container,n),this.container.appendChild(n)}if(!this.wrapper){e&&e.remove(),n&&n.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||_,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let i=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(i&&i.colors){let o=Q(i.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(([i,o])=>{i==="className"||i==="class"?this.textarea.className+=" "+o:i==="style"&&typeof o=="object"?Object.assign(this.textarea.style,o):this.textarea.setAttribute(i,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 n;let e=this.options.toolbarButtons||ie;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(i=>(i==null?void 0:i.name)==="upload")){let i=e.findIndex(o=>(o==null?void 0:o.name)==="viewMode");i!==-1?(e=[...e],e.splice(i,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new ke(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=ze(ie),this.options.toolbarButtons&&Object.assign(this.actionsById,ze(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,ze([S.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 n,i;(i=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,i;(i=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let i of e.files){if(i.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(i.type))continue;let o=++this._fileUploadCounter,s=`${i.type.startsWith("image/")?"!":""}[Uploading ${i.name} (#${o})...]()`;if(this.insertAtCursor(`${s}
|
|
975
|
+
`),this.options.fileUpload.batch){n.push({file:i,placeholder:s});continue}this.options.fileUpload.onInsertFile(i).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&&n.length>0&&this.options.fileUpload.onInsertFile(n.map(i=>i.file)).then(i=>{(Array.isArray(i)?i:[i]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},i=>{console.error("OverType: File upload failed",i),n.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 n=this.textarea.selectionStart,i=this.textarea.selectionEnd,o=!1;try{o=document.execCommand("insertText",!1,e)}catch(r){}if(!o){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(i);this.textarea.value=r+e+s,this.textarea.setSelectionRange(n+e.length,n+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,n=this.textarea.selectionStart,i=this._getCurrentLine(e,n),o=this.container.dataset.mode==="preview",r=T.parse(e,i,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 n=0;n<e.length-1;n+=2){let i=e[n],o=e[n+1],r=i.parentElement,s=o.parentElement;!r||!s||(i.style.display="block",o.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,n){return e.substring(0,n).split(`
|
|
966
976
|
`).length-1}handleInput(e){this.updatePreview()}handleKeydown(e){if(e.key==="Tab"){let i=this.textarea.selectionStart,o=this.textarea.selectionEnd,r=this.textarea.value;if(e.shiftKey&&i===o)return;if(e.preventDefault(),i!==o&&e.shiftKey){let s=r.substring(0,i),a=r.substring(i,o),c=r.substring(o),l=a.split(`
|
|
967
977
|
`).map(d=>d.replace(/^ /,"")).join(`
|
|
968
978
|
`);document.execCommand?(this.textarea.setSelectionRange(i,o),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=i,this.textarea.selectionEnd=i+l.length)}else if(i!==o){let s=r.substring(0,i),a=r.substring(i,o),c=r.substring(o),l=a.split(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "overtype",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.5",
|
|
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",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"preversion": "npm test",
|
|
46
46
|
"size": "gzip-size dist/overtype.min.js",
|
|
47
47
|
"serve": "http-server -p 8080 -c-1",
|
|
48
|
-
"deploy:website": "npm run build"
|
|
48
|
+
"deploy:website": "npm run build",
|
|
49
|
+
"postpublish": "bash scripts/purge-cdn-cache.sh"
|
|
49
50
|
},
|
|
50
51
|
"keywords": [
|
|
51
52
|
"markdown",
|
|
@@ -43,6 +43,7 @@ class OverTypeEditor extends HTMLElement {
|
|
|
43
43
|
// Bind methods to maintain context
|
|
44
44
|
this._handleChange = this._handleChange.bind(this);
|
|
45
45
|
this._handleKeydown = this._handleKeydown.bind(this);
|
|
46
|
+
this._handleRender = this._handleRender.bind(this);
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/**
|
|
@@ -263,7 +264,8 @@ class OverTypeEditor extends HTMLElement {
|
|
|
263
264
|
smartLists: !this.hasAttribute('smart-lists') || this.getAttribute('smart-lists') !== 'false',
|
|
264
265
|
spellcheck: this.hasAttribute('spellcheck') && this.getAttribute('spellcheck') !== 'false',
|
|
265
266
|
onChange: this._handleChange,
|
|
266
|
-
onKeydown: this._handleKeydown
|
|
267
|
+
onKeydown: this._handleKeydown,
|
|
268
|
+
onRender: this._handleRender
|
|
267
269
|
};
|
|
268
270
|
|
|
269
271
|
// Font and layout options
|
|
@@ -519,6 +521,20 @@ class OverTypeEditor extends HTMLElement {
|
|
|
519
521
|
});
|
|
520
522
|
}
|
|
521
523
|
|
|
524
|
+
/**
|
|
525
|
+
* Handle render events from OverType
|
|
526
|
+
* @private
|
|
527
|
+
* @param {HTMLElement} preview - The preview DOM element
|
|
528
|
+
* @param {string} mode - Current mode ('normal' or 'preview')
|
|
529
|
+
*/
|
|
530
|
+
_handleRender(preview, mode) {
|
|
531
|
+
this._dispatchEvent('render', {
|
|
532
|
+
preview,
|
|
533
|
+
mode,
|
|
534
|
+
editor: this._editor
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
522
538
|
/**
|
|
523
539
|
* Update value attribute without triggering observer
|
|
524
540
|
* @private
|
package/src/overtype.js
CHANGED
|
@@ -227,6 +227,7 @@ class OverType {
|
|
|
227
227
|
// Callbacks
|
|
228
228
|
onChange: null,
|
|
229
229
|
onKeydown: null,
|
|
230
|
+
onRender: null,
|
|
230
231
|
|
|
231
232
|
// Features
|
|
232
233
|
showActiveLineRaw: false,
|
|
@@ -743,6 +744,11 @@ class OverType {
|
|
|
743
744
|
if (this.options.onChange && this.initialized) {
|
|
744
745
|
this.options.onChange(text, this);
|
|
745
746
|
}
|
|
747
|
+
|
|
748
|
+
// Trigger onRender callback
|
|
749
|
+
if (this.options.onRender) {
|
|
750
|
+
this.options.onRender(this.preview, isPreviewMode ? 'preview' : 'normal', this);
|
|
751
|
+
}
|
|
746
752
|
}
|
|
747
753
|
|
|
748
754
|
/**
|
package/src/styles.js
CHANGED
|
@@ -256,6 +256,16 @@ export function generateStyles(options = {}) {
|
|
|
256
256
|
-ms-user-select: none !important;
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
/* Prevent external resets (Tailwind, Bootstrap, etc.) from breaking alignment.
|
|
260
|
+
Any element whose font metrics differ from the textarea causes the CSS "strut"
|
|
261
|
+
to inflate line boxes, drifting the overlay. Force inheritance so every element
|
|
262
|
+
inside the preview matches the textarea exactly. */
|
|
263
|
+
.overtype-wrapper .overtype-preview * {
|
|
264
|
+
font-family: inherit !important;
|
|
265
|
+
font-size: inherit !important;
|
|
266
|
+
line-height: inherit !important;
|
|
267
|
+
}
|
|
268
|
+
|
|
259
269
|
/* Defensive styles for preview child divs */
|
|
260
270
|
.overtype-wrapper .overtype-preview div {
|
|
261
271
|
/* Reset any inherited styles */
|