overtype 2.3.9 → 2.3.10
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 +72 -8
- package/dist/overtype-webcomponent.esm.js +57 -3
- package/dist/overtype-webcomponent.esm.js.map +2 -2
- package/dist/overtype-webcomponent.js +57 -3
- package/dist/overtype-webcomponent.js.map +2 -2
- package/dist/overtype-webcomponent.min.js +17 -17
- package/dist/overtype.cjs +57 -3
- package/dist/overtype.cjs.map +2 -2
- package/dist/overtype.d.ts +1 -0
- package/dist/overtype.esm.js +57 -3
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +57 -3
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +9 -9
- package/package.json +1 -1
- package/src/overtype.d.ts +1 -0
- package/src/overtype.js +53 -2
package/dist/overtype.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.3.
|
|
2
|
+
* OverType v2.3.10
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -39,7 +39,7 @@ var OverType=(()=>{var ke=Object.defineProperty;var yn=Object.getOwnPropertyDesc
|
|
|
39
39
|
font-size: var(--instance-font-size, ${e}) !important;
|
|
40
40
|
line-height: var(--instance-line-height, ${n}) !important;
|
|
41
41
|
padding: var(--instance-padding, ${i}) !important;box-sizing: border-box !important;color: var(--placeholder,#999) !important}.overtype-wrapper .overtype-preview{z-index: 0 !important;pointer-events: none !important;color: var(--text,#0d3b66) !important;background-color: transparent !important;user-select: none !important;-webkit-user-select: none !important;-moz-user-select: none !important;-ms-user-select: none !important}.overtype-wrapper .overtype-preview *{font-family: inherit !important;font-size: inherit !important;line-height: inherit !important}.overtype-wrapper .overtype-preview div{margin: 0 !important;padding: 0 !important;border: none !important;text-align: left !important;text-indent: 0 !important;display: block !important;position: static !important;transform: none !important;min-height: 0 !important;max-height: none !important;line-height: inherit !important;font-size: inherit !important;font-family: inherit !important}.overtype-wrapper .overtype-preview .header{font-weight: bold !important}.overtype-wrapper .overtype-preview .h1{color: var(--h1,#f95738) !important}.overtype-wrapper .overtype-preview .h2{color: var(--h2,#ee964b) !important}.overtype-wrapper .overtype-preview .h3{color: var(--h3,#3d8a51) !important}.overtype-wrapper .overtype-preview h1,.overtype-wrapper .overtype-preview h2,.overtype-wrapper .overtype-preview h3{font-size: inherit !important;font-weight: bold !important;margin: 0 !important;padding: 0 !important;display: inline !important;line-height: inherit !important}.overtype-wrapper .overtype-preview h1{color: var(--h1,#f95738) !important}.overtype-wrapper .overtype-preview h2{color: var(--h2,#ee964b) !important}.overtype-wrapper .overtype-preview h3{color: var(--h3,#3d8a51) !important}.overtype-wrapper .overtype-preview ul,.overtype-wrapper .overtype-preview ol{list-style: none !important;margin: 0 !important;padding: 0 !important;display: block !important}.overtype-wrapper .overtype-preview li{display: block !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview strong{color: var(--strong,#ee964b) !important;font-weight: bold !important}.overtype-wrapper .overtype-preview em{color: var(--em,#f95738) !important;text-decoration-color: var(--em,#f95738) !important;text-decoration-thickness: 1px !important;font-style: italic !important}.overtype-wrapper .overtype-preview del{color: var(--del,#ee964b) !important;text-decoration: line-through !important;text-decoration-color: var(--del,#ee964b) !important;text-decoration-thickness: 1px !important}.overtype-wrapper .overtype-preview code{background: var(--code-bg,rgba(244,211,94,0.4)) !important;color: var(--code,#0d3b66) !important;padding: 0 !important;border-radius: 2px !important;font-family: inherit !important;font-size: inherit !important;line-height: inherit !important;font-weight: normal !important}.overtype-wrapper .overtype-preview pre{padding: 0 !important;margin: 0 !important;border-radius: 4px !important;overflow-x: auto !important}.overtype-wrapper .overtype-preview pre.code-block{background: var(--code-bg,rgba(244,211,94,0.4)) !important;white-space: break-spaces !important}.overtype-wrapper .overtype-preview pre code{background: transparent !important;color: var(--code,#0d3b66) !important;font-family: var(--instance-font-family,${o}) !important}.overtype-wrapper .overtype-preview .blockquote{color: var(--blockquote,#5a7a9b) !important;padding: 0 !important;margin: 0 !important;border: none !important}.overtype-wrapper .overtype-preview a{color: var(--link,#0d3b66) !important;text-decoration: underline !important;font-weight: normal !important}.overtype-wrapper .overtype-preview a:hover{text-decoration: underline !important;color: var(--link,#0d3b66) !important}.overtype-wrapper .overtype-preview ul,.overtype-wrapper .overtype-preview ol{list-style: none !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview hr{border: none !important;color: var(--hr,#5a7a9b) !important;margin: 0 !important;padding: 0 !important}.overtype-wrapper .overtype-preview .hr-marker{color: var(--hr,#5a7a9b) !important;opacity: 0.6 !important}.overtype-wrapper .overtype-preview .code-fence{color: var(--code,#0d3b66) !important;background: var(--code-bg,rgba(244,211,94,0.4)) !important}.overtype-wrapper .overtype-preview .code-block-line{background: var(--code-bg,rgba(244,211,94,0.4)) !important}.overtype-wrapper .overtype-preview .code-block-line .code-fence{background: transparent !important}.overtype-wrapper .overtype-preview .raw-line{color: var(--raw-line,#5a7a9b) !important;font-style: normal !important;font-weight: normal !important}.overtype-wrapper .overtype-preview .syntax-marker{color: var(--syntax-marker,rgba(13,59,102,0.52)) !important;opacity: 0.7 !important}.overtype-wrapper .overtype-preview .list-marker{color: var(--list-marker,#ee964b) !important}.overtype-stats{height: 40px !important;padding: 0 20px !important;background: var(--bg-secondary,#f8f9fa) !important;border-top: 1px solid var(--border,#e0e0e0) !important;display: flex !important;justify-content: space-between !important;align-items: center !important;font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif !important;font-size: 0.85rem !important;color: var(--text-secondary,#666) !important;flex-shrink: 0 !important;z-index: 10001 !important;position: relative !important}.overtype-stats .overtype-stat{display: flex !important;align-items: center !important;gap: 5px !important;white-space: nowrap !important}.overtype-stats .live-dot{width: 8px !important;height: 8px !important;background: #4caf50 !important;border-radius: 50% !important;animation: overtype-pulse 2s infinite !important}@keyframes overtype-pulse{0%,100%{opacity: 1;transform: scale(1)}50%{opacity: 0.6;transform: scale(1.2)}}.overtype-toolbar.overtype-toolbar-hidden{display: none !important}.overtype-toolbar{display: flex !important;align-items: center !important;gap: 4px !important;padding: 8px !important;background: var(--toolbar-bg,var(--bg-primary,#f8f9fa)) !important;border-bottom: 1px solid var(--toolbar-border,transparent) !important;overflow-x: auto !important;overflow-y: hidden !important;-webkit-overflow-scrolling: touch !important;flex-shrink: 0 !important;height: auto !important;position: relative !important;z-index: 100 !important;scrollbar-width: thin}.overtype-toolbar::-webkit-scrollbar{height: 4px}.overtype-toolbar::-webkit-scrollbar-track{background: transparent}.overtype-toolbar::-webkit-scrollbar-thumb{background: rgba(0,0,0,0.2);border-radius: 2px}.overtype-toolbar-button{display: flex;align-items: center;justify-content: center;width: 32px;height: 32px;padding: 0;border: none;border-radius: 6px;background: transparent;color: var(--toolbar-icon,var(--text-secondary,#666));cursor: pointer;transition: all 0.2s ease;flex-shrink: 0}.overtype-toolbar-button svg{width: 20px;height: 20px;fill: currentColor}.overtype-toolbar-button:hover{background: var(--toolbar-hover,var(--bg-secondary,#e9ecef));color: var(--toolbar-icon,var(--text-primary,#333))}.overtype-toolbar-button:active{transform: scale(0.95)}.overtype-toolbar-button.active{background: var(--toolbar-active,var(--primary,#007bff));color: var(--toolbar-icon,var(--text-primary,#333))}.overtype-toolbar-button:disabled{opacity: 0.5;cursor: not-allowed}.overtype-toolbar-separator{width: 1px;height: 24px;background: var(--border,#e0e0e0);margin: 0 4px;flex-shrink: 0}@media (max-width: 640px){.overtype-toolbar{padding: 6px;gap: 2px}.overtype-toolbar-button{width: 36px;height: 36px}.overtype-toolbar-separator{margin: 0 2px}}.overtype-container[data-mode="plain"] .overtype-preview{display: none !important}.overtype-container[data-mode="plain"] .overtype-input{color: var(--text,#0d3b66) !important;font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif !important}.overtype-container:not([data-mode="plain"]) .overtype-input{color: transparent !important}.overtype-toolbar-button{position: relative !important}.overtype-toolbar-button.dropdown-active{background: var(--toolbar-active,var(--hover-bg,#f0f0f0))}.overtype-dropdown-menu{position: fixed !important;background: var(--bg-secondary,white) !important;border: 1px solid var(--border,#e0e0e0) !important;border-radius: 6px;box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;z-index: 10000;min-width: 150px;padding: 4px 0 !important}.overtype-dropdown-item{display: flex;align-items: center;width: 100%;padding: 8px 12px;border: none;background: none;text-align: left;cursor: pointer;font-size: 14px;color: var(--text,#333);font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif}.overtype-dropdown-item:hover{background: var(--hover-bg,#f0f0f0)}.overtype-dropdown-item.active{font-weight: 600}.overtype-dropdown-check{width: 16px;margin-right: 8px;color: var(--h1,#007bff)}.overtype-dropdown-icon{width: 20px;margin-right: 8px;text-align: center}.overtype-container[data-mode="preview"] .overtype-input{display: none !important}.overtype-container[data-mode="preview"] .overtype-preview{pointer-events: auto !important;user-select: text !important;cursor: text !important}.overtype-container.overtype-auto-resize[data-mode="preview"] .overtype-preview{position: static !important;height: auto !important}.overtype-container[data-mode="preview"] .syntax-marker{display: none !important}.overtype-container[data-mode="preview"] .syntax-marker.url-part,.overtype-container[data-mode="preview"] .url-part{display: none !important}.overtype-container[data-mode="preview"] a .syntax-marker{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1,.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2,.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3{font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif !important;font-weight: 600 !important;margin: 0 !important;display: block !important;line-height: 1 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h1{font-size: 2em !important;color: var(--preview-h1,var(--preview-h1-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h2{font-size: 1.5em !important;color: var(--preview-h2,var(--preview-h2-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview h3{font-size: 1.17em !important;color: var(--preview-h3,var(--preview-h3-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview ul{display: block !important;list-style: disc !important;padding-left: 2em !important;margin: 1em 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview ol{display: block !important;list-style: decimal !important;padding-left: 2em !important;margin: 1em 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li{display: list-item !important;margin: 0 !important;padding: 0 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li.task-list{list-style: none !important;position: relative !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview li.task-list input[type="checkbox"]{margin-right: 0.5em !important;cursor: default !important;vertical-align: middle !important}.overtype-container:not([data-mode="preview"]) .overtype-wrapper .overtype-preview li.task-list{list-style: none !important}.overtype-container:not([data-mode="preview"]) .overtype-wrapper .overtype-preview li.task-list .syntax-marker{color: var(--syntax,#999999) !important;font-weight: normal !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview a{pointer-events: auto !important;cursor: pointer !important;color: var(--preview-link,var(--preview-link-default)) !important;text-decoration: underline !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block{background: var(--preview-code-bg,var(--preview-code-bg-default)) !important;color: var(--preview-code,var(--preview-code-default)) !important;padding: 1.2em !important;border-radius: 3px !important;overflow-x: auto !important;margin: 0 !important;display: block !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block code{background: transparent !important;color: inherit !important;padding: 0 !important;font-family:${o}!important;font-size: 0.9em !important;line-height: 1.4 !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .code-block-line{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .code-fence{display: none !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .blockquote{display: block !important;border-left: 4px solid var(--preview-blockquote,var(--preview-blockquote-default)) !important;color: var(--preview-blockquote,var(--preview-blockquote-default)) !important;padding-left: 1em !important;margin: 1em 0 !important;font-style: italic !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview{font-family: Georgia,'Times New Roman',serif !important;font-size: 16px !important;line-height: 1.8 !important;color: var(--preview-text,var(--preview-text-default)) !important;background: var(--preview-bg,var(--preview-bg-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code{font-family:${o}!important;font-size: 0.9em !important;background: var(--preview-code-bg,var(--preview-code-bg-default)) !important;color: var(--preview-code,var(--preview-code-default)) !important;padding: 0.2em 0.4em !important;border-radius: 3px !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview strong{font-weight: 700 !important;color: var(--preview-strong,var(--preview-strong-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview em{font-style: italic !important;color: var(--preview-em,var(--preview-em-default)) !important}.overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview .hr-marker{display: block !important;border-top: 2px solid var(--preview-hr,var(--preview-hr-default)) !important;text-indent: -9999px !important;height: 2px !important}.overtype-link-tooltip{background: #333 !important;color: white !important;padding: 6px 10px !important;border-radius: 16px !important;font-size: 12px !important;font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif !important;display: flex !important;visibility: hidden !important;pointer-events: none !important;z-index: 10000 !important;cursor: pointer !important;box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;max-width: 300px !important;white-space: nowrap !important;overflow: hidden !important;text-overflow: ellipsis !important;position: fixed;top: 0;left: 0}.overtype-link-tooltip.visible{visibility: visible !important;pointer-events: auto !important}${a}
|
|
42
|
-
`}var ne={};st(ne,{applyCustomFormat:()=>Et,default:()=>In,expandSelection:()=>St,getActiveFormats:()=>Ie,getDebugMode:()=>Ze,hasFormat:()=>Lt,insertHeader:()=>de,insertLink:()=>Ae,preserveSelection:()=>bt,setDebugMode:()=>gt,setUndoMethod:()=>yt,toggleBold:()=>Ee,toggleBulletList:()=>Me,toggleCode:()=>Te,toggleH1:()=>
|
|
42
|
+
`}var ne={};st(ne,{applyCustomFormat:()=>Et,default:()=>In,expandSelection:()=>St,getActiveFormats:()=>Ie,getDebugMode:()=>Ze,hasFormat:()=>Lt,insertHeader:()=>de,insertLink:()=>Ae,preserveSelection:()=>bt,setDebugMode:()=>gt,setUndoMethod:()=>yt,toggleBold:()=>Ee,toggleBulletList:()=>Me,toggleCode:()=>Te,toggleH1:()=>He,toggleH2:()=>Pe,toggleH3:()=>Oe,toggleItalic:()=>Ce,toggleNumberedList:()=>$e,toggleQuote:()=>_e,toggleTaskList:()=>pe});var Sn=Object.defineProperty,dt=Object.getOwnPropertySymbols,En=Object.prototype.hasOwnProperty,Cn=Object.prototype.propertyIsEnumerable,ut=(t,e,n)=>e in t?Sn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ht=(t,e)=>{for(var n in e||(e={}))En.call(e,n)&&ut(t,n,e[n]);if(dt)for(var n of dt(e))Cn.call(e,n)&&ut(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 Tn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function R(t){return ht(ht({},Tn()),t)}var ce=!1;function gt(t){ce=t}function Ze(){return ce}function x(t,e,n){ce&&(console.group(`\u{1F50D} ${t}`),console.log(e),n&&console.log("Data:",n),console.groupEnd())}function Le(t,e){if(!ce)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 o=t.value.slice(Math.max(0,t.selectionStart-10),t.selectionStart),i=t.value.slice(t.selectionEnd,Math.min(t.value.length,t.selectionEnd+10));console.log("Context:",JSON.stringify(o)+"[SELECTION]"+JSON.stringify(i)),console.groupEnd()}function vt(t){ce&&(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 M=null;function N(t,{text:e,selectionStart:n,selectionEnd:o}){let i=Ze();i&&(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,"-",o)),t.focus();let r=t.selectionStart,s=t.selectionEnd,a=t.value.slice(0,r),l=t.value.slice(s);i&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(l.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(t.value.slice(r,s))));let p=t.value,c=r!==s;if(M===null||M===!0){t.contentEditable="true";try{M=document.execCommand("insertText",!1,e),i&&console.log("execCommand returned:",M,"for text with",e.split(`
|
|
43
43
|
`).length,"lines")}catch(d){M=!1,i&&console.log("execCommand threw error:",d)}t.contentEditable="false"}if(i&&(console.log("canInsertText before:",M),console.log("execCommand result:",M)),M){let d=a+e+l,u=t.value;i&&(console.log("Expected length:",d.length),console.log("Actual length:",u.length)),u!==d&&i&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(d.slice(0,100))),console.log("Actual:",JSON.stringify(u.slice(0,100))))}if(!M)if(i&&console.log("Using manual insertion"),t.value===p){i&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(d){}t.value=a+e+l;try{document.execCommand("ms-endUndoUnit")}catch(d){}t.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else i&&console.log("Value was changed by execCommand, skipping manual insertion");i&&console.log("Setting selection range:",n,o),n!=null&&o!=null?t.setSelectionRange(n,o):t.setSelectionRange(r,t.selectionEnd),i&&(console.log("Final value length:",t.value.length),console.groupEnd())}function yt(t){switch(t){case"native":M=!0;break;case"manual":M=!1;break;case"auto":M=null;break}}function Ke(t){return t.trim().split(`
|
|
44
44
|
`).length>1}function An(t,e){let n=e;for(;t[n]&&t[n-1]!=null&&!t[n-1].match(/\s/);)n--;return n}function Mn(t,e,n){let o=e,i=n?/\n/:/\s/;for(;t[o]&&!t[o].match(i);)o++;return o}function wt(t){let e=t.value.split(`
|
|
45
45
|
`),n=0;for(let o=0;o<e.length;o++){let i=e[o].length+1;t.selectionStart>=n&&t.selectionStart<n+i&&(t.selectionStart=n),t.selectionEnd>=n&&t.selectionEnd<n+i&&(o===e.length-1?t.selectionEnd=Math.min(n+e[o].length,t.value.length):t.selectionEnd=n+i-1),n+=i}}function $n(t,e,n,o=!1){if(t.selectionStart===t.selectionEnd)t.selectionStart=An(t.value,t.selectionStart),t.selectionEnd=Mn(t.value,t.selectionEnd,o);else{let i=t.selectionStart-e.length,r=t.selectionEnd+n.length,s=t.value.slice(i,t.selectionStart)===e,a=t.value.slice(t.selectionEnd,r)===n;s&&a&&(t.selectionStart=i,t.selectionEnd=r)}return t.value.slice(t.selectionStart,t.selectionEnd)}function Qe(t){let e=t.value.slice(0,t.selectionStart),n=t.value.slice(t.selectionEnd),o=e.match(/\n*$/),i=n.match(/^\n*/),r=o?o[0].length:0,s=i?i[0].length:0,a="",l="";return e.match(/\S/)&&r<2&&(a=`
|
|
@@ -55,13 +55,13 @@ ${a}`:r;if(p){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
|
|
|
55
55
|
`),n=/^\d+\.\s+/,o=e.every(r=>n.test(r)),i=e;return o&&(i=e.map(r=>r.replace(n,""))),{text:i.join(`
|
|
56
56
|
`),processed:o}}function mt(t){let e=t.split(`
|
|
57
57
|
`),n="- ",o=e.every(r=>r.startsWith(n)),i=e;return o&&(i=e.map(r=>r.slice(n.length))),{text:i.join(`
|
|
58
|
-
`),processed:o}}function le(t,e){return e?"- ":`${t+1}. `}function
|
|
58
|
+
`),processed:o}}function le(t,e){return e?"- ":`${t+1}. `}function _n(t,e){let n,o,i;return t.orderedList?(n=ft(e),o=mt(n.text),i=o.text):(n=mt(e),o=ft(n.text),i=o.text),[n,o,i]}function Hn(t,e){let n=t.selectionStart===t.selectionEnd,o=t.selectionStart,i=t.selectionEnd;wt(t);let r=t.value.slice(t.selectionStart,t.selectionEnd),[s,a,l]=_n(e,r),p=l.split(`
|
|
59
59
|
`).map((m,g)=>`${le(g,e.unorderedList)}${m}`),c=p.reduce((m,g,y)=>m+le(y,e.unorderedList).length,0),d=p.reduce((m,g,y)=>m+le(y,!e.unorderedList).length,0);if(s.processed)return n?(o=Math.max(o-le(0,e.unorderedList).length,0),i=o):(o=t.selectionStart,i=t.selectionEnd-c),{text:l,selectionStart:o,selectionEnd:i};let{newlinesToAppend:u,newlinesToPrepend:h}=Qe(t),f=u+p.join(`
|
|
60
|
-
`)+h;return n?(o=Math.max(o+le(0,e.unorderedList).length+u.length,0),i=o):a.processed?(o=Math.max(t.selectionStart+u.length,0),i=t.selectionEnd+u.length+c-d):(o=Math.max(t.selectionStart+u.length,0),i=t.selectionEnd+u.length+c),{text:f,selectionStart:o,selectionEnd:i}}function xt(t,e){let n=Se(t,o=>
|
|
61
|
-
`),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 l=Math.max(0,n-10),p=Math.min(i.length,o+10),c=i.slice(l,p);if(c.includes("**")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(c.includes("_")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(c.includes("`")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100));d.includes("`")&&u.includes("`")&&e.push("code")}if(c.includes("[")&&c.includes("]")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&i.slice(o+f+1,o+f+10).startsWith("(")&&e.push("link")}return e}function
|
|
62
|
-
`),p=0,c=0,d=0;for(let u of l){if(r>=d&&r<=d+u.length){p=d,c=d+u.length;break}d+=u.length+1}t.selectionStart=p,t.selectionEnd=c}else if(n&&r===s){let l=r,p=s;for(;l>0&&!/\s/.test(a[l-1]);)l--;for(;p<a.length&&!/\s/.test(a[p]);)p++;t.selectionStart=l,t.selectionEnd=p}}function Ee(t){if(!t||t.disabled||t.readOnly)return;x("toggleBold","Starting"),Le(t,"Before");let e=R(I.bold),n=te(t,e);vt(n),N(t,n),Le(t,"After")}function Ce(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.italic),n=te(t,e);N(t,n)}function Te(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.code),n=te(t,e);N(t,n)}function Ae(t,e={}){if(!t||t.disabled||t.readOnly)return;let n=t.value.slice(t.selectionStart,t.selectionEnd),o=R(I.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${n})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!n){let s=t.selectionStart;t.value=t.value.slice(0,s)+e.text+t.value.slice(s),t.selectionStart=s,t.selectionEnd=s+e.text.length}let r=te(t,o);N(t,r)}function Me(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.bulletList);xt(t,e)}function $e(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.numberedList);xt(t,e)}function
|
|
60
|
+
`)+h;return n?(o=Math.max(o+le(0,e.unorderedList).length+u.length,0),i=o):a.processed?(o=Math.max(t.selectionStart+u.length,0),i=t.selectionEnd+u.length+c-d):(o=Math.max(t.selectionStart+u.length,0),i=t.selectionEnd+u.length+c),{text:f,selectionStart:o,selectionEnd:i}}function xt(t,e){let n=Se(t,o=>Hn(o,e),{adjustSelection:(o,i,r,s)=>{let a=t.value.slice(s,t.selectionEnd),l=/^\d+\.\s+/,p=/^- /,c=l.test(a),d=p.test(a),u=e.orderedList&&c||e.unorderedList&&d;if(i===r)if(u){let h=a.match(e.orderedList?l:p),f=h?h[0].length:0;return{start:Math.max(i-f,s),end:Math.max(i-f,s)}}else if(c||d){let h=a.match(c?l:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:i+g}}else{let h=e.unorderedList?2:3;return{start:i+h,end:i+h}}else if(u){let h=a.match(e.orderedList?l:p),f=h?h[0].length:0;return{start:Math.max(i-f,s),end:Math.max(r-f,s)}}else if(c||d){let h=a.match(c?l:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:i+g,end:r+g}}else{let h=e.unorderedList?2:3;return{start:i+h,end:r+h}}}});N(t,n)}function kt(t){if(!t)return[];let e=[],{selectionStart:n,selectionEnd:o,value:i}=t,r=i.split(`
|
|
61
|
+
`),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 l=Math.max(0,n-10),p=Math.min(i.length,o+10),c=i.slice(l,p);if(c.includes("**")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(c.includes("_")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(c.includes("`")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100));d.includes("`")&&u.includes("`")&&e.push("code")}if(c.includes("[")&&c.includes("]")){let d=i.slice(Math.max(0,n-100),n),u=i.slice(o,Math.min(i.length,o+100)),h=d.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&i.slice(o+f+1,o+f+10).startsWith("(")&&e.push("link")}return e}function Pn(t,e){return kt(t).includes(e)}function On(t,e={}){if(!t)return;let{toWord:n,toLine:o,toFormat:i}=e,{selectionStart:r,selectionEnd:s,value:a}=t;if(o){let l=a.split(`
|
|
62
|
+
`),p=0,c=0,d=0;for(let u of l){if(r>=d&&r<=d+u.length){p=d,c=d+u.length;break}d+=u.length+1}t.selectionStart=p,t.selectionEnd=c}else if(n&&r===s){let l=r,p=s;for(;l>0&&!/\s/.test(a[l-1]);)l--;for(;p<a.length&&!/\s/.test(a[p]);)p++;t.selectionStart=l,t.selectionEnd=p}}function Ee(t){if(!t||t.disabled||t.readOnly)return;x("toggleBold","Starting"),Le(t,"Before");let e=R(I.bold),n=te(t,e);vt(n),N(t,n),Le(t,"After")}function Ce(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.italic),n=te(t,e);N(t,n)}function Te(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.code),n=te(t,e);N(t,n)}function Ae(t,e={}){if(!t||t.disabled||t.readOnly)return;let n=t.value.slice(t.selectionStart,t.selectionEnd),o=R(I.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(o.suffix=`](${n})`,o.replaceNext=""):e.url&&(o.suffix=`](${e.url})`,o.replaceNext=""),e.text&&!n){let s=t.selectionStart;t.value=t.value.slice(0,s)+e.text+t.value.slice(s),t.selectionStart=s,t.selectionEnd=s+e.text.length}let r=te(t,o);N(t,r)}function Me(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.bulletList);xt(t,e)}function $e(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.numberedList);xt(t,e)}function _e(t){if(!t||t.disabled||t.readOnly)return;x("toggleQuote","Starting"),Le(t,"Initial");let e=R(I.quote),n=Se(t,o=>Je(o,e),{prefix:e.prefix});vt(n),N(t,n),Le(t,"Final")}function pe(t){if(!t||t.disabled||t.readOnly)return;let e=R(I.taskList),n=Se(t,o=>Je(o,e),{prefix:e.prefix});N(t,n)}function de(t,e=1,n=!1){if(!t||t.disabled||t.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${n}`),x("insertHeader",`Initial cursor: ${t.selectionStart}-${t.selectionEnd}`);let o=`header${e===1?"1":e}`,i=R(I[o]||I.header1);x("insertHeader",`Style prefix: "${i.prefix}"`);let r=t.value,s=t.selectionStart,a=t.selectionEnd,l=s;for(;l>0&&r[l-1]!==`
|
|
63
63
|
`;)l--;let p=a;for(;p<r.length&&r[p]!==`
|
|
64
|
-
`;)p++;let c=r.slice(l,p);x("insertHeader",`Current line (before): "${c}"`);let d=c.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=n&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${n}, existingLevel=${u}, level=${e})`);let m=Se(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):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),b=i.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=i.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-h,b);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:L,end:y===w?L:Math.max(w-h,b)}}else if(h>0){let L=i.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:y+i.prefix.length,end:w+i.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),N(t,m)}function Pe(t){de(t,1,!0)}function Oe(t){de(t,2,!0)}function _e(t){de(t,3,!0)}function Ie(t){return kt(t)}function Lt(t,e){return On(t,e)}function St(t,e={}){_n(t,e)}function Et(t,e){if(!t||t.disabled||t.readOnly)return;let n=R(e),o;if(n.multiline){let i=t.value.slice(t.selectionStart,t.selectionEnd);Ke(i)?o=Je(t,n):o=te(t,n)}else o=te(t,n);N(t,o)}var In={toggleBold:Ee,toggleItalic:Ce,toggleCode:Te,insertLink:Ae,toggleBulletList:Me,toggleNumberedList:$e,toggleQuote:He,toggleTaskList:pe,insertHeader:de,toggleH1:Pe,toggleH2:Oe,toggleH3:_e,getActiveFormats:Ie,hasFormat:Lt,expandSelection:St,applyCustomFormat:Et,preserveSelection:bt,setUndoMethod:yt,setDebugMode:gt,getDebugMode:Ze};var Re=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=n.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.addEventListener("click",o=>{o.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=o=>{o.preventDefault();let i=e.actionId||e.name;this.editor.performAction(i,o)},n.addEventListener("click",n._clickHandler),n)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let n=document.querySelector(".overtype-dropdown-menu");if(n){n.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let o=this.createViewModeDropdown(e),i=e.getBoundingClientRect();o.style.position="absolute",o.style.top=`${i.bottom+5}px`,o.style.left=`${i.left}px`,document.body.appendChild(o),this.handleDocumentClick=r=>{!o.contains(r.target)&&!e.contains(r.target)&&(o.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu";let o=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],i=this.editor.container.dataset.mode||"normal";return o.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),n.appendChild(s)}),n}updateButtonStates(){var e;try{let n=((e=Ie)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([o,i])=>{if(o==="viewMode")return;let r=!1;switch(o){case"bold":r=n.includes("bold");break;case"italic":r=n.includes("italic");break;case"code":r=!1;break;case"bulletList":r=n.includes("bullet-list");break;case"orderedList":r=n.includes("numbered-list");break;case"taskList":r=n.includes("task-list");break;case"quote":r=n.includes("quote");break;case"h1":r=n.includes("header");break;case"h2":r=n.includes("header-2");break;case"h3":r=n.includes("header-3");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(n){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var he=Math.min,W=Math.max,fe=Math.round;var O=t=>({x:t,y:t}),Rn={left:"right",right:"left",bottom:"top",top:"bottom"},Bn={start:"end",end:"start"};function Xe(t,e,n){return W(t,he(e,n))}function me(t,e){return typeof t=="function"?t(e):t}function q(t){return t.split("-")[0]}function ge(t){return t.split("-")[1]}function Ge(t){return t==="x"?"y":"x"}function Ye(t){return t==="y"?"height":"width"}var Fn=new Set(["top","bottom"]);function D(t){return Fn.has(q(t))?"y":"x"}function et(t){return Ge(D(t))}function At(t,e,n){n===void 0&&(n=!1);let o=ge(t),i=et(t),r=Ye(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ue(s)),[s,ue(s)]}function Mt(t){let e=ue(t);return[Be(t),e,Be(e)]}function Be(t){return t.replace(/start|end/g,e=>Bn[e])}var Ct=["left","right"],Tt=["right","left"],Nn=["top","bottom"],Dn=["bottom","top"];function zn(t,e,n){switch(t){case"top":case"bottom":return n?e?Tt:Ct:e?Ct:Tt;case"left":case"right":return e?Nn:Dn;default:return[]}}function $t(t,e,n,o){let i=ge(t),r=zn(q(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(Be)))),r}function ue(t){return t.replace(/left|right|bottom|top/g,e=>Rn[e])}function jn(t){return{top:0,right:0,bottom:0,left:0,...t}}function Ht(t){return typeof t!="number"?jn(t):{top:t,right:t,bottom:t,left:t}}function J(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Pt(t,e,n){let{reference:o,floating:i}=t,r=D(e),s=et(e),a=Ye(s),l=q(e),p=r==="y",c=o.x+o.width/2-i.width/2,d=o.y+o.height/2-i.height/2,u=o[a]/2-i[a]/2,h;switch(l){case"top":h={x:c,y:o.y-i.height};break;case"bottom":h={x:c,y:o.y+o.height};break;case"right":h={x:o.x+o.width,y:d};break;case"left":h={x:o.x-i.width,y:d};break;default:h={x:o.x,y:o.y}}switch(ge(e)){case"start":h[s]-=u*(n&&p?-1:1);break;case"end":h[s]+=u*(n&&p?-1:1);break}return h}async function Ot(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:a,strategy:l}=t,{boundary:p="clippingAncestors",rootBoundary:c="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=me(e,t),f=Ht(h),g=a[u?d==="floating"?"reference":"floating":d],y=J(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:c,strategy:l})),w=d==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=J(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:l}):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 _t=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:c,y:d}=Pt(p,o,l),u=o,h={},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:c,y:d,initialPlacement:o,placement:u,strategy:i,middlewareData:h,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Ot},elements:{reference:t,floating:e}});c=b!=null?b:c,d=L!=null?L:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):E.rects),{x:c,y:d}=Pt(p,u,l)),g=-1)}return{x:c,y:d,placement:u,strategy:i,middlewareData:h}};var It=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:a,platform:l,elements:p}=e,{mainAxis:c=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=me(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let y=q(i),w=D(a),b=q(a)===a,L=await(l.isRTL==null?void 0:l.isRTL(p.floating)),k=u||(b||!m?[ue(a)]:Mt(a)),E=f!=="none";!u&&E&&k.push(...$t(a,m,f,L));let be=[a,...k],Y=await l.detectOverflow(e,g),xe=[],ee=((o=r.flip)==null?void 0:o.overflows)||[];if(c&&xe.push(Y[y]),d){let K=At(i,s,L);xe.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:i,overflows:xe}],!xe.every(K=>K<=0)){var ot,it;let K=(((ot=r.flip)==null?void 0:ot.index)||0)+1,We=be[K];if(We&&(!(d==="alignment"?w!==D(We):!1)||ee.every(P=>D(P.placement)===w?P.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:We}};let se=(it=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,P)=>Z.overflows[1]-P.overflows[1])[0])==null?void 0:it.placement;if(!se)switch(h){case"bestFit":{var rt;let Z=(rt=ee.filter(P=>{if(E){let V=D(P.placement);return V===w||V==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(V=>V>0).reduce((V,vn)=>V+vn,0)]).sort((P,V)=>P[1]-V[1])[0])==null?void 0:rt[0];Z&&(se=Z);break}case"initialPlacement":se=a;break}if(i!==se)return{reset:{placement:se}}}return{}}}};var Vn=new Set(["left","top"]);async function Un(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=q(n),a=ge(n),l=D(n)==="y",p=Vn.has(s)?-1:1,c=r&&l?-1:1,d=me(e,t),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),l?{x:h*c,y:u*p}:{x:u*p,y:h*c}}var Rt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:a}=e,l=await Un(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(o=a.arrow)!=null&&o.alignmentOffset?{}:{x:i+l.x,y:r+l.y,data:{...l,placement:s}}}}},Bt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:l={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...p}=me(t,e),c={x:n,y:o},d=await r.detectOverflow(e,p),u=D(q(i)),h=Ge(u),f=c[h],m=c[u];if(s){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=Xe(b,f,L)}if(a){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=Xe(b,m,L)}let g=l.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-n,y:g.y-o,enabled:{[h]:s,[u]:a}}}}}};function Ne(){return typeof window<"u"}function X(t){return Nt(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function B(t){var e;return(e=(Nt(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Nt(t){return Ne()?t instanceof Node||t instanceof A(t).Node:!1}function $(t){return Ne()?t instanceof Element||t instanceof A(t).Element:!1}function _(t){return Ne()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function Ft(t){return!Ne()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}var Wn=new Set(["inline","contents"]);function oe(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!Wn.has(i)}var qn=new Set(["table","td","th"]);function Dt(t){return qn.has(X(t))}var Kn=[":popover-open",":modal"];function ve(t){return Kn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Zn=["transform","translate","scale","rotate","perspective"],Qn=["transform","translate","scale","rotate","perspective","filter"],Jn=["paint","layout","strict","content"];function De(t){let e=ze(),n=$(t)?H(t):t;return Zn.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Qn.some(o=>(n.willChange||"").includes(o))||Jn.some(o=>(n.contain||"").includes(o))}function zt(t){let e=z(t);for(;_(e)&&!G(e);){if(De(e))return e;if(ve(e))return null;e=z(e)}return null}function ze(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Xn=new Set(["html","body","#document"]);function G(t){return Xn.has(X(t))}function H(t){return A(t).getComputedStyle(t)}function ye(t){return $(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function z(t){if(X(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Ft(t)&&t.host||B(t);return Ft(e)?e.host:e}function jt(t){let e=z(t);return G(e)?t.ownerDocument?t.ownerDocument.body:t.body:_(e)&&oe(e)?e:jt(e)}function Fe(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=jt(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=A(i);if(r){let a=je(s);return e.concat(s,s.visualViewport||[],oe(i)?i:[],a&&n?Fe(a):[])}return e.concat(i,Fe(i,[],n))}function je(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function qt(t){let e=H(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=_(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,a=fe(n)!==r||fe(o)!==s;return a&&(n=r,o=s),{width:n,height:o,$:a}}function Kt(t){return $(t)?t:t.contextElement}function ie(t){let e=Kt(t);if(!_(e))return O(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=qt(e),s=(r?fe(n.width):n.width)/o,a=(r?fe(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Gn=O(0);function Zt(t){let e=A(t);return!ze()||!e.visualViewport?Gn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Yn(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==A(t)?!1:e}function we(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=Kt(t),s=O(1);e&&(o?$(o)&&(s=ie(o)):s=ie(t));let a=Yn(r,n,o)?Zt(r):O(0),l=(i.left+a.x)/s.x,p=(i.top+a.y)/s.y,c=i.width/s.x,d=i.height/s.y;if(r){let u=A(r),h=o&&$(o)?A(o):o,f=u,m=je(f);for(;m&&o&&h!==f;){let g=ie(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;l*=g.x,p*=g.y,c*=g.x,d*=g.y,l+=b,p+=L,f=A(m),m=je(f)}}return J({width:c,height:d,x:l,y:p})}function Ve(t,e){let n=ye(t).scrollLeft;return e?e.left+n:we(B(t)).left+n}function Qt(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Ve(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function eo(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=B(o),a=e?ve(e.floating):!1;if(o===s||a&&r)return n;let l={scrollLeft:0,scrollTop:0},p=O(1),c=O(0),d=_(o);if((d||!d&&!r)&&((X(o)!=="body"||oe(s))&&(l=ye(o)),_(o))){let h=we(o);p=ie(o),c.x=h.x+o.clientLeft,c.y=h.y+o.clientTop}let u=s&&!d&&!r?Qt(s,l):O(0);return{width:n.width*p.x,height:n.height*p.y,x:n.x*p.x-l.scrollLeft*p.x+c.x+u.x,y:n.y*p.y-l.scrollTop*p.y+c.y+u.y}}function to(t){return Array.from(t.getClientRects())}function no(t){let e=B(t),n=ye(t),o=t.ownerDocument.body,i=W(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=W(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+Ve(t),a=-n.scrollTop;return H(o).direction==="rtl"&&(s+=W(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:a}}var Vt=25;function oo(t,e){let n=A(t),o=B(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,a=0,l=0;if(i){r=i.width,s=i.height;let c=ze();(!c||c&&e==="fixed")&&(a=i.offsetLeft,l=i.offsetTop)}let p=Ve(o);if(p<=0){let c=o.ownerDocument,d=c.body,u=getComputedStyle(d),h=c.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(o.clientWidth-d.clientWidth-h);f<=Vt&&(r-=f)}else p<=Vt&&(r+=p);return{width:r,height:s,x:a,y:l}}var io=new Set(["absolute","fixed"]);function ro(t,e){let n=we(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=_(t)?ie(t):O(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,l=i*r.x,p=o*r.y;return{width:s,height:a,x:l,y:p}}function Ut(t,e,n){let o;if(e==="viewport")o=oo(t,n);else if(e==="document")o=no(B(t));else if($(e))o=ro(e,n);else{let i=Zt(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return J(o)}function Jt(t,e){let n=z(t);return n===e||!$(n)||G(n)?!1:H(n).position==="fixed"||Jt(n,e)}function so(t,e){let n=e.get(t);if(n)return n;let o=Fe(t,[],!1).filter(a=>$(a)&&X(a)!=="body"),i=null,r=H(t).position==="fixed",s=r?z(t):t;for(;$(s)&&!G(s);){let a=H(s),l=De(s);!l&&a.position==="fixed"&&(i=null),(r?!l&&!i:!l&&a.position==="static"&&!!i&&io.has(i.position)||oe(s)&&!l&&Jt(t,s))?o=o.filter(c=>c!==s):i=a,s=z(s)}return e.set(t,o),o}function ao(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?ve(e)?[]:so(e,this._c):[].concat(n),o],a=s[0],l=s.reduce((p,c)=>{let d=Ut(e,c,i);return p.top=W(d.top,p.top),p.right=he(d.right,p.right),p.bottom=he(d.bottom,p.bottom),p.left=W(d.left,p.left),p},Ut(e,a,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function lo(t){let{width:e,height:n}=qt(t);return{width:e,height:n}}function co(t,e,n){let o=_(e),i=B(e),r=n==="fixed",s=we(t,!0,r,e),a={scrollLeft:0,scrollTop:0},l=O(0);function p(){l.x=Ve(i)}if(o||!o&&!r)if((X(e)!=="body"||oe(i))&&(a=ye(e)),o){let h=we(e,!0,r,e);l.x=h.x+e.clientLeft,l.y=h.y+e.clientTop}else i&&p();r&&!o&&i&&p();let c=i&&!o&&!r?Qt(i,a):O(0),d=s.left+a.scrollLeft-l.x-c.x,u=s.top+a.scrollTop-l.y-c.y;return{x:d,y:u,width:s.width,height:s.height}}function tt(t){return H(t).position==="static"}function Wt(t,e){if(!_(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return B(t)===n&&(n=n.ownerDocument.body),n}function Xt(t,e){let n=A(t);if(ve(t))return n;if(!_(t)){let i=z(t);for(;i&&!G(i);){if($(i)&&!tt(i))return i;i=z(i)}return n}let o=Wt(t,e);for(;o&&Dt(o)&&tt(o);)o=Wt(o,e);return o&&G(o)&&tt(o)&&!De(o)?n:o||zt(t)||n}var po=async function(t){let e=this.getOffsetParent||Xt,n=this.getDimensions,o=await n(t.floating);return{reference:co(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function uo(t){return H(t).direction==="rtl"}var ho={convertOffsetParentRelativeRectToViewportRelativeRect:eo,getDocumentElement:B,getClippingRect:ao,getOffsetParent:Xt,getElementRects:po,getClientRects:to,getDimensions:lo,getScale:ie,isElement:$,isRTL:uo};var Gt=Rt;var Yt=Bt,en=It;var tn=(t,e,n)=>{let o=new Map,i={platform:ho,...n},r={...i.platform,_c:o};return _t(t,e,{...i,platform:r})};var Ue=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=`
|
|
64
|
+
`;)p++;let c=r.slice(l,p);x("insertHeader",`Current line (before): "${c}"`);let d=c.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=n&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${n}, existingLevel=${u}, level=${e})`);let m=Se(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):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),b=i.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=i.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:i.prefix,adjustSelection:(g,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-h,b);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:L,end:y===w?L:Math.max(w-h,b)}}else if(h>0){let L=i.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${i.prefix.length}`),{start:y+i.prefix.length,end:w+i.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),N(t,m)}function He(t){de(t,1,!0)}function Pe(t){de(t,2,!0)}function Oe(t){de(t,3,!0)}function Ie(t){return kt(t)}function Lt(t,e){return Pn(t,e)}function St(t,e={}){On(t,e)}function Et(t,e){if(!t||t.disabled||t.readOnly)return;let n=R(e),o;if(n.multiline){let i=t.value.slice(t.selectionStart,t.selectionEnd);Ke(i)?o=Je(t,n):o=te(t,n)}else o=te(t,n);N(t,o)}var In={toggleBold:Ee,toggleItalic:Ce,toggleCode:Te,insertLink:Ae,toggleBulletList:Me,toggleNumberedList:$e,toggleQuote:_e,toggleTaskList:pe,insertHeader:de,toggleH1:He,toggleH2:Pe,toggleH3:Oe,getActiveFormats:Ie,hasFormat:Lt,expandSelection:St,applyCustomFormat:Et,preserveSelection:bt,setUndoMethod:yt,setDebugMode:gt,getDebugMode:Ze};var Re=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=n.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.addEventListener("click",o=>{o.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=o=>{o.preventDefault();let i=e.actionId||e.name;this.editor.performAction(i,o)},n.addEventListener("click",n._clickHandler),n)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let n=document.querySelector(".overtype-dropdown-menu");if(n){n.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let o=this.createViewModeDropdown(e),i=e.getBoundingClientRect();o.style.position="absolute",o.style.top=`${i.bottom+5}px`,o.style.left=`${i.left}px`,document.body.appendChild(o),this.handleDocumentClick=r=>{!o.contains(r.target)&&!e.contains(r.target)&&(o.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu";let o=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],i=this.editor.container.dataset.mode||"normal";return o.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===i){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),n.appendChild(s)}),n}updateButtonStates(){var e;try{let n=((e=Ie)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([o,i])=>{if(o==="viewMode")return;let r=!1;switch(o){case"bold":r=n.includes("bold");break;case"italic":r=n.includes("italic");break;case"code":r=!1;break;case"bulletList":r=n.includes("bullet-list");break;case"orderedList":r=n.includes("numbered-list");break;case"taskList":r=n.includes("task-list");break;case"quote":r=n.includes("quote");break;case"h1":r=n.includes("header");break;case"h2":r=n.includes("header-2");break;case"h3":r=n.includes("header-3");break}i.classList.toggle("active",r),i.setAttribute("aria-pressed",r.toString())})}catch(n){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var he=Math.min,W=Math.max,fe=Math.round;var P=t=>({x:t,y:t}),Rn={left:"right",right:"left",bottom:"top",top:"bottom"},Bn={start:"end",end:"start"};function Xe(t,e,n){return W(t,he(e,n))}function me(t,e){return typeof t=="function"?t(e):t}function q(t){return t.split("-")[0]}function ge(t){return t.split("-")[1]}function Ge(t){return t==="x"?"y":"x"}function Ye(t){return t==="y"?"height":"width"}var Fn=new Set(["top","bottom"]);function D(t){return Fn.has(q(t))?"y":"x"}function et(t){return Ge(D(t))}function At(t,e,n){n===void 0&&(n=!1);let o=ge(t),i=et(t),r=Ye(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ue(s)),[s,ue(s)]}function Mt(t){let e=ue(t);return[Be(t),e,Be(e)]}function Be(t){return t.replace(/start|end/g,e=>Bn[e])}var Ct=["left","right"],Tt=["right","left"],Nn=["top","bottom"],Dn=["bottom","top"];function zn(t,e,n){switch(t){case"top":case"bottom":return n?e?Tt:Ct:e?Ct:Tt;case"left":case"right":return e?Nn:Dn;default:return[]}}function $t(t,e,n,o){let i=ge(t),r=zn(q(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(Be)))),r}function ue(t){return t.replace(/left|right|bottom|top/g,e=>Rn[e])}function jn(t){return{top:0,right:0,bottom:0,left:0,...t}}function _t(t){return typeof t!="number"?jn(t):{top:t,right:t,bottom:t,left:t}}function J(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Ht(t,e,n){let{reference:o,floating:i}=t,r=D(e),s=et(e),a=Ye(s),l=q(e),p=r==="y",c=o.x+o.width/2-i.width/2,d=o.y+o.height/2-i.height/2,u=o[a]/2-i[a]/2,h;switch(l){case"top":h={x:c,y:o.y-i.height};break;case"bottom":h={x:c,y:o.y+o.height};break;case"right":h={x:o.x+o.width,y:d};break;case"left":h={x:o.x-i.width,y:d};break;default:h={x:o.x,y:o.y}}switch(ge(e)){case"start":h[s]-=u*(n&&p?-1:1);break;case"end":h[s]+=u*(n&&p?-1:1);break}return h}async function Pt(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:a,strategy:l}=t,{boundary:p="clippingAncestors",rootBoundary:c="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=me(e,t),f=_t(h),g=a[u?d==="floating"?"reference":"floating":d],y=J(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:c,strategy:l})),w=d==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=J(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:l}):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 Ot=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:c,y:d}=Ht(p,o,l),u=o,h={},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:c,y:d,initialPlacement:o,placement:u,strategy:i,middlewareData:h,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Pt},elements:{reference:t,floating:e}});c=b!=null?b:c,d=L!=null?L:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):E.rects),{x:c,y:d}=Ht(p,u,l)),g=-1)}return{x:c,y:d,placement:u,strategy:i,middlewareData:h}};var It=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:a,platform:l,elements:p}=e,{mainAxis:c=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=me(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let y=q(i),w=D(a),b=q(a)===a,L=await(l.isRTL==null?void 0:l.isRTL(p.floating)),k=u||(b||!m?[ue(a)]:Mt(a)),E=f!=="none";!u&&E&&k.push(...$t(a,m,f,L));let be=[a,...k],Y=await l.detectOverflow(e,g),xe=[],ee=((o=r.flip)==null?void 0:o.overflows)||[];if(c&&xe.push(Y[y]),d){let K=At(i,s,L);xe.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:i,overflows:xe}],!xe.every(K=>K<=0)){var ot,it;let K=(((ot=r.flip)==null?void 0:ot.index)||0)+1,We=be[K];if(We&&(!(d==="alignment"?w!==D(We):!1)||ee.every(H=>D(H.placement)===w?H.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:We}};let se=(it=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,H)=>Z.overflows[1]-H.overflows[1])[0])==null?void 0:it.placement;if(!se)switch(h){case"bestFit":{var rt;let Z=(rt=ee.filter(H=>{if(E){let V=D(H.placement);return V===w||V==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(V=>V>0).reduce((V,vn)=>V+vn,0)]).sort((H,V)=>H[1]-V[1])[0])==null?void 0:rt[0];Z&&(se=Z);break}case"initialPlacement":se=a;break}if(i!==se)return{reset:{placement:se}}}return{}}}};var Vn=new Set(["left","top"]);async function Un(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=q(n),a=ge(n),l=D(n)==="y",p=Vn.has(s)?-1:1,c=r&&l?-1:1,d=me(e,t),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),l?{x:h*c,y:u*p}:{x:u*p,y:h*c}}var Rt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:a}=e,l=await Un(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(o=a.arrow)!=null&&o.alignmentOffset?{}:{x:i+l.x,y:r+l.y,data:{...l,placement:s}}}}},Bt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:l={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...p}=me(t,e),c={x:n,y:o},d=await r.detectOverflow(e,p),u=D(q(i)),h=Ge(u),f=c[h],m=c[u];if(s){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=Xe(b,f,L)}if(a){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=Xe(b,m,L)}let g=l.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-n,y:g.y-o,enabled:{[h]:s,[u]:a}}}}}};function Ne(){return typeof window<"u"}function X(t){return Nt(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function B(t){var e;return(e=(Nt(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Nt(t){return Ne()?t instanceof Node||t instanceof A(t).Node:!1}function $(t){return Ne()?t instanceof Element||t instanceof A(t).Element:!1}function O(t){return Ne()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function Ft(t){return!Ne()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}var Wn=new Set(["inline","contents"]);function oe(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=_(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!Wn.has(i)}var qn=new Set(["table","td","th"]);function Dt(t){return qn.has(X(t))}var Kn=[":popover-open",":modal"];function ve(t){return Kn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Zn=["transform","translate","scale","rotate","perspective"],Qn=["transform","translate","scale","rotate","perspective","filter"],Jn=["paint","layout","strict","content"];function De(t){let e=ze(),n=$(t)?_(t):t;return Zn.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Qn.some(o=>(n.willChange||"").includes(o))||Jn.some(o=>(n.contain||"").includes(o))}function zt(t){let e=z(t);for(;O(e)&&!G(e);){if(De(e))return e;if(ve(e))return null;e=z(e)}return null}function ze(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Xn=new Set(["html","body","#document"]);function G(t){return Xn.has(X(t))}function _(t){return A(t).getComputedStyle(t)}function ye(t){return $(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function z(t){if(X(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Ft(t)&&t.host||B(t);return Ft(e)?e.host:e}function jt(t){let e=z(t);return G(e)?t.ownerDocument?t.ownerDocument.body:t.body:O(e)&&oe(e)?e:jt(e)}function Fe(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=jt(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=A(i);if(r){let a=je(s);return e.concat(s,s.visualViewport||[],oe(i)?i:[],a&&n?Fe(a):[])}return e.concat(i,Fe(i,[],n))}function je(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function qt(t){let e=_(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=O(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,a=fe(n)!==r||fe(o)!==s;return a&&(n=r,o=s),{width:n,height:o,$:a}}function Kt(t){return $(t)?t:t.contextElement}function ie(t){let e=Kt(t);if(!O(e))return P(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=qt(e),s=(r?fe(n.width):n.width)/o,a=(r?fe(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Gn=P(0);function Zt(t){let e=A(t);return!ze()||!e.visualViewport?Gn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Yn(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==A(t)?!1:e}function we(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=Kt(t),s=P(1);e&&(o?$(o)&&(s=ie(o)):s=ie(t));let a=Yn(r,n,o)?Zt(r):P(0),l=(i.left+a.x)/s.x,p=(i.top+a.y)/s.y,c=i.width/s.x,d=i.height/s.y;if(r){let u=A(r),h=o&&$(o)?A(o):o,f=u,m=je(f);for(;m&&o&&h!==f;){let g=ie(m),y=m.getBoundingClientRect(),w=_(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*g.x,L=y.top+(m.clientTop+parseFloat(w.paddingTop))*g.y;l*=g.x,p*=g.y,c*=g.x,d*=g.y,l+=b,p+=L,f=A(m),m=je(f)}}return J({width:c,height:d,x:l,y:p})}function Ve(t,e){let n=ye(t).scrollLeft;return e?e.left+n:we(B(t)).left+n}function Qt(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Ve(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function eo(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=B(o),a=e?ve(e.floating):!1;if(o===s||a&&r)return n;let l={scrollLeft:0,scrollTop:0},p=P(1),c=P(0),d=O(o);if((d||!d&&!r)&&((X(o)!=="body"||oe(s))&&(l=ye(o)),O(o))){let h=we(o);p=ie(o),c.x=h.x+o.clientLeft,c.y=h.y+o.clientTop}let u=s&&!d&&!r?Qt(s,l):P(0);return{width:n.width*p.x,height:n.height*p.y,x:n.x*p.x-l.scrollLeft*p.x+c.x+u.x,y:n.y*p.y-l.scrollTop*p.y+c.y+u.y}}function to(t){return Array.from(t.getClientRects())}function no(t){let e=B(t),n=ye(t),o=t.ownerDocument.body,i=W(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=W(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+Ve(t),a=-n.scrollTop;return _(o).direction==="rtl"&&(s+=W(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:a}}var Vt=25;function oo(t,e){let n=A(t),o=B(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,a=0,l=0;if(i){r=i.width,s=i.height;let c=ze();(!c||c&&e==="fixed")&&(a=i.offsetLeft,l=i.offsetTop)}let p=Ve(o);if(p<=0){let c=o.ownerDocument,d=c.body,u=getComputedStyle(d),h=c.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(o.clientWidth-d.clientWidth-h);f<=Vt&&(r-=f)}else p<=Vt&&(r+=p);return{width:r,height:s,x:a,y:l}}var io=new Set(["absolute","fixed"]);function ro(t,e){let n=we(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=O(t)?ie(t):P(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,l=i*r.x,p=o*r.y;return{width:s,height:a,x:l,y:p}}function Ut(t,e,n){let o;if(e==="viewport")o=oo(t,n);else if(e==="document")o=no(B(t));else if($(e))o=ro(e,n);else{let i=Zt(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return J(o)}function Jt(t,e){let n=z(t);return n===e||!$(n)||G(n)?!1:_(n).position==="fixed"||Jt(n,e)}function so(t,e){let n=e.get(t);if(n)return n;let o=Fe(t,[],!1).filter(a=>$(a)&&X(a)!=="body"),i=null,r=_(t).position==="fixed",s=r?z(t):t;for(;$(s)&&!G(s);){let a=_(s),l=De(s);!l&&a.position==="fixed"&&(i=null),(r?!l&&!i:!l&&a.position==="static"&&!!i&&io.has(i.position)||oe(s)&&!l&&Jt(t,s))?o=o.filter(c=>c!==s):i=a,s=z(s)}return e.set(t,o),o}function ao(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?ve(e)?[]:so(e,this._c):[].concat(n),o],a=s[0],l=s.reduce((p,c)=>{let d=Ut(e,c,i);return p.top=W(d.top,p.top),p.right=he(d.right,p.right),p.bottom=he(d.bottom,p.bottom),p.left=W(d.left,p.left),p},Ut(e,a,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function lo(t){let{width:e,height:n}=qt(t);return{width:e,height:n}}function co(t,e,n){let o=O(e),i=B(e),r=n==="fixed",s=we(t,!0,r,e),a={scrollLeft:0,scrollTop:0},l=P(0);function p(){l.x=Ve(i)}if(o||!o&&!r)if((X(e)!=="body"||oe(i))&&(a=ye(e)),o){let h=we(e,!0,r,e);l.x=h.x+e.clientLeft,l.y=h.y+e.clientTop}else i&&p();r&&!o&&i&&p();let c=i&&!o&&!r?Qt(i,a):P(0),d=s.left+a.scrollLeft-l.x-c.x,u=s.top+a.scrollTop-l.y-c.y;return{x:d,y:u,width:s.width,height:s.height}}function tt(t){return _(t).position==="static"}function Wt(t,e){if(!O(t)||_(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return B(t)===n&&(n=n.ownerDocument.body),n}function Xt(t,e){let n=A(t);if(ve(t))return n;if(!O(t)){let i=z(t);for(;i&&!G(i);){if($(i)&&!tt(i))return i;i=z(i)}return n}let o=Wt(t,e);for(;o&&Dt(o)&&tt(o);)o=Wt(o,e);return o&&G(o)&&tt(o)&&!De(o)?n:o||zt(t)||n}var po=async function(t){let e=this.getOffsetParent||Xt,n=this.getDimensions,o=await n(t.floating);return{reference:co(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function uo(t){return _(t).direction==="rtl"}var ho={convertOffsetParentRelativeRectToViewportRelativeRect:eo,getDocumentElement:B,getClippingRect:ao,getOffsetParent:Xt,getElementRects:po,getClientRects:to,getDimensions:lo,getScale:ie,isElement:$,isRTL:uo};var Gt=Rt;var Yt=Bt,en=It;var tn=(t,e,n)=>{let o=new Map,i={platform:ho,...n},r={...i.platform,_c:o};return Ot(t,e,{...i,platform:r})};var Ue=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=`
|
|
65
65
|
<span style="display: flex; align-items: center; gap: 6px;">
|
|
66
66
|
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
|
|
67
67
|
<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>
|
|
@@ -69,8 +69,8 @@ ${a}`:r;if(p){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!
|
|
|
69
69
|
</svg>
|
|
70
70
|
<span class="overtype-link-tooltip-url"></span>
|
|
71
71
|
</span>
|
|
72
|
-
`,this.tooltip.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.currentLink&&(window.open(this.currentLink.url,"_blank"),this.hide())}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,n=this.editor.textarea.value,o=this.findLinkAtPosition(n,e);o?(!this.currentLink||this.currentLink.url!==o.url||this.currentLink.index!==o.index)&&this.show(o):this.scheduleHide()}findLinkAtPosition(e,n){let o=/\[([^\]]+)\]\(([^)]+)\)/g,i,r=0;for(;(i=o.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(n>=s&&n<=a)return{text:i[1],url:i[2],index:r,start:s,end:a};r++}return null}async show(e){this.currentLink=e,this.cancelHide();let n=this.tooltip.querySelector(".overtype-link-tooltip-url");n.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let n=this.findAnchorElement(e.index);if(!n)return;let o=n.getBoundingClientRect();if(!(o.width===0||o.height===0))try{let{x:i,y:r}=await tn(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Gt(8),Yt({padding:8}),en()]});Object.assign(this.tooltip.style,{left:`${i}px`,top:`${r}px`,position:"fixed"})}catch(i){console.warn("Floating UI positioning failed:",i)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var nn='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z"></path></svg>',on='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line></svg>',rn='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z"></path></svg>',sn='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',an='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.65186,12.30664a2.6742,2.6742,0,0,1-2.915,2.68457,3.96592,3.96592,0,0,1-2.25537-.6709.56007.56007,0,0,1-.13232-.83594L11.64648,13c.209-.34082.48389-.36328.82471-.1543a2.32654,2.32654,0,0,0,1.12256.33008c.71484,0,1.12207-.35156,1.12207-.78125,0-.61523-.61621-.86816-1.46338-.86816H13.2085a.65159.65159,0,0,1-.68213-.41895l-.05518-.10937a.67114.67114,0,0,1,.14307-.78125l.71533-.86914a8.55289,8.55289,0,0,1,.68213-.7373V8.58887a3.93913,3.93913,0,0,1-.748.05469H11.9873a.54085.54085,0,0,1-.605-.60547V7.59863a.54085.54085,0,0,1,.605-.60547h3.75146a.53773.53773,0,0,1,.60547.59375v.17676a1.03723,1.03723,0,0,1-.27539.748L14.74854,10.0293A2.31132,2.31132,0,0,1,16.65186,12.30664ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',ln='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z"></path></svg>',cn='<svg viewBox="0 0 18 18"><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line></svg>',pn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line></svg>',dn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" x1="2.5" x2="4.5" y1="5.5" y2="5.5"></line><path fill="currentColor" d="M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109"></path></svg>',un='<svg viewBox="2 2 20 20"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 10.8182L9 10.8182C8.80222 10.8182 8.60888 10.7649 8.44443 10.665C8.27998 10.5651 8.15181 10.4231 8.07612 10.257C8.00043 10.0909 7.98063 9.90808 8.01922 9.73174C8.0578 9.55539 8.15304 9.39341 8.29289 9.26627C8.43275 9.13913 8.61093 9.05255 8.80491 9.01747C8.99889 8.98239 9.19996 9.00039 9.38268 9.0692C9.56541 9.13801 9.72159 9.25453 9.83147 9.40403C9.94135 9.55353 10 9.72929 10 9.90909L10 12.1818C10 12.664 9.78929 13.1265 9.41421 13.4675C9.03914 13.8084 8.53043 14 8 14"></path><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 10.8182L15 10.8182C14.8022 10.8182 14.6089 10.7649 14.4444 10.665C14.28 10.5651 14.1518 10.4231 14.0761 10.257C14.0004 10.0909 13.9806 9.90808 14.0192 9.73174C14.0578 9.55539 14.153 9.39341 14.2929 9.26627C14.4327 9.13913 14.6109 9.05255 14.8049 9.01747C14.9989 8.98239 15.2 9.00039 15.3827 9.0692C15.5654 9.13801 15.7216 9.25453 15.8315 9.40403C15.9414 9.55353 16 9.72929 16 9.90909L16 12.1818C16 12.664 15.7893 13.1265 15.4142 13.4675C15.0391 13.8084 14.5304 14 14 14"></path></svg>',hn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" points="2.65 9.5 3.5 10.5 5 8.5"></polyline></svg>',fn='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.25 12.375v1.688A1.688 1.688 0 0 0 3.938 15.75h10.124a1.688 1.688 0 0 0 1.688-1.688V12.375"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.063 6.188L9 2.25l3.938 3.938"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 2.25v10.125"></path></svg>',mn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path><circle cx="12" cy="12" r="3" fill="none"></circle></svg>';var S={bold:{name:"bold",actionId:"toggleBold",icon:nn,title:"Bold (Ctrl+B)",action:({editor:t})=>{Ee(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:on,title:"Italic (Ctrl+I)",action:({editor:t})=>{Ce(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:cn,title:"Inline Code",action:({editor:t})=>{Te(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:ln,title:"Insert Link",action:({editor:t})=>{Ae(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:rn,title:"Heading 1",action:({editor:t})=>{Pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:sn,title:"Heading 2",action:({editor:t})=>{Oe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:an,title:"Heading 3",action:({editor:t})=>{_e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:pn,title:"Bullet List",action:({editor:t})=>{Me(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:dn,title:"Numbered List",action:({editor:t})=>{$e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:hn,title:"Task List",action:({editor:t})=>{pe&&(pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:un,title:"Quote",action:({editor:t})=>{He(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:fn,title:"Upload File",action:({editor:t})=>{var n,o;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((o=t.options.fileUpload.mimeTypes)==null?void 0:o.length)>0&&(e.accept=t.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let i=new DataTransfer;for(let s of e.files)i.items.add(s);t._handleDataTransfer(i)},e.click()}},viewMode:{name:"viewMode",icon:mn,title:"View mode"}},re=[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 nt(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let o=n.actionId||n.name;n.action&&(e[o]=n.action)}),e}function gn(t){let e=t||re;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 mo(t,e){let n=gn(t),o=gn(e);if(n===null||o===null)return n!==o;if(n.length!==o.length)return!0;for(let i=0;i<n.length;i++){let r=n[i],s=o[i];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 o=v._resolveTargets(e);if(typeof e=="string"&&o.length===0)throw new Error(`No elements found for selector: ${e}`);return o.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 o=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");o||i?this._recoverFromDOM(o,i):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new ae(this),this._rebuildActionsMap(),this.linkTooltip=new Ue(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this._notifyChange()}_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,onFocus:null,onBlur:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:o,colors:i,...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 o=this.instanceTheme||v.currentTheme||F,i=typeof o=="string"?o:o.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?U(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._applyInstanceCSSVars(),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||v.currentTheme||F,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let o=typeof this.instanceTheme=="string"?U(this.instanceTheme):this.instanceTheme;if(o&&o.colors){let i=Q(o.colors);this.container.style.cssText+=i}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this._applyInstanceCSSVars(),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([o,i])=>{o==="className"||o==="class"?this.textarea.className+=" "+i:o==="style"&&typeof i=="object"?Object.assign(this.textarea.style,i):this.textarea.setAttribute(o,i)}),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||re;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(o=>(o==null?void 0:o.name)==="upload")){let o=e.findIndex(i=>(i==null?void 0:i.name)==="viewMode");o!==-1?(e=[...e],e.splice(o,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new Re(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=nt(re),this.options.toolbarButtons&&Object.assign(this.actionsById,nt(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,nt([S.upload]))}_applyInstanceCSSVars(){this.wrapper&&(this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.options.fontFamily&&this.wrapper.style.setProperty("--instance-font-family",this.options.fontFamily))}_applyOptions(){this._applyInstanceCSSVars(),this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_handleFilePaste(e){var n,o;(o=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,o;(o=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let o of e.files){if(o.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(o.type))continue;let i=++this._fileUploadCounter,s=`${o.type.startsWith("image/")?"!":""}[Uploading ${o.name} (#${i})...]()`;if(this.insertAtCursor(`${s}
|
|
73
|
-
`),this.options.fileUpload.batch){n.push({file:o,placeholder:s});continue}this.options.fileUpload.onInsertFile(o).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(o=>o.file)).then(o=>{(Array.isArray(o)?o:[o]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},o=>{console.error("OverType: File upload failed",o),n.forEach(({placeholder:i})=>{this.textarea.value=this.textarea.value.replace(i,"[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,o=this.textarea.selectionEnd,i=!1;try{i=document.execCommand("insertText",!1,e)}catch(r){}if(!i){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(o);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,o=this._getCurrentLine(e,n),i=this.container.dataset.mode==="preview",r=C.parse(e,o,this.options.showActiveLineRaw,this.options.codeHighlighter,i);this.preview.innerHTML=r,this.placeholderEl&&(this.placeholderEl.style.display=e?"none":""),this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onRender&&this.options.onRender(this.preview,i?"preview":"normal",this)}_notifyChange(){
|
|
72
|
+
`,this.tooltip.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.currentLink&&(window.open(this.currentLink.url,"_blank"),this.hide())}),this.editor.container.appendChild(this.tooltip)}checkCursorPosition(){let e=this.editor.textarea.selectionStart,n=this.editor.textarea.value,o=this.findLinkAtPosition(n,e);o?(!this.currentLink||this.currentLink.url!==o.url||this.currentLink.index!==o.index)&&this.show(o):this.scheduleHide()}findLinkAtPosition(e,n){let o=/\[([^\]]+)\]\(([^)]+)\)/g,i,r=0;for(;(i=o.exec(e))!==null;){let s=i.index,a=i.index+i[0].length;if(n>=s&&n<=a)return{text:i[1],url:i[2],index:r,start:s,end:a};r++}return null}async show(e){this.currentLink=e,this.cancelHide();let n=this.tooltip.querySelector(".overtype-link-tooltip-url");n.textContent=e.url,await this.positionTooltip(e),this.currentLink===e&&this.tooltip.classList.add("visible")}async positionTooltip(e){let n=this.findAnchorElement(e.index);if(!n)return;let o=n.getBoundingClientRect();if(!(o.width===0||o.height===0))try{let{x:i,y:r}=await tn(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Gt(8),Yt({padding:8}),en()]});Object.assign(this.tooltip.style,{left:`${i}px`,top:`${r}px`,position:"fixed"})}catch(i){console.warn("Floating UI positioning failed:",i)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var nn='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z"></path></svg>',on='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="13" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="5" x2="11" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="10" y1="14" y2="4"></line></svg>',rn='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z"></path></svg>',sn='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',an='<svg viewBox="0 0 18 18"><path fill="currentColor" d="M16.65186,12.30664a2.6742,2.6742,0,0,1-2.915,2.68457,3.96592,3.96592,0,0,1-2.25537-.6709.56007.56007,0,0,1-.13232-.83594L11.64648,13c.209-.34082.48389-.36328.82471-.1543a2.32654,2.32654,0,0,0,1.12256.33008c.71484,0,1.12207-.35156,1.12207-.78125,0-.61523-.61621-.86816-1.46338-.86816H13.2085a.65159.65159,0,0,1-.68213-.41895l-.05518-.10937a.67114.67114,0,0,1,.14307-.78125l.71533-.86914a8.55289,8.55289,0,0,1,.68213-.7373V8.58887a3.93913,3.93913,0,0,1-.748.05469H11.9873a.54085.54085,0,0,1-.605-.60547V7.59863a.54085.54085,0,0,1,.605-.60547h3.75146a.53773.53773,0,0,1,.60547.59375v.17676a1.03723,1.03723,0,0,1-.27539.748L14.74854,10.0293A2.31132,2.31132,0,0,1,16.65186,12.30664ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z"></path></svg>',ln='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="11" y1="7" y2="11"></line><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z"></path></svg>',cn='<svg viewBox="0 0 18 18"><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="5 7 3 9 5 11"></polyline><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="13 7 15 9 13 11"></polyline><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="10" x2="8" y1="5" y2="13"></line></svg>',pn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="6" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="3" x2="3" y1="14" y2="14"></line></svg>',dn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="7" x2="15" y1="14" y2="14"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" x1="2.5" x2="4.5" y1="5.5" y2="5.5"></line><path fill="currentColor" d="M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109"></path></svg>',un='<svg viewBox="2 2 20 20"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 10.8182L9 10.8182C8.80222 10.8182 8.60888 10.7649 8.44443 10.665C8.27998 10.5651 8.15181 10.4231 8.07612 10.257C8.00043 10.0909 7.98063 9.90808 8.01922 9.73174C8.0578 9.55539 8.15304 9.39341 8.29289 9.26627C8.43275 9.13913 8.61093 9.05255 8.80491 9.01747C8.99889 8.98239 9.19996 9.00039 9.38268 9.0692C9.56541 9.13801 9.72159 9.25453 9.83147 9.40403C9.94135 9.55353 10 9.72929 10 9.90909L10 12.1818C10 12.664 9.78929 13.1265 9.41421 13.4675C9.03914 13.8084 8.53043 14 8 14"></path><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 10.8182L15 10.8182C14.8022 10.8182 14.6089 10.7649 14.4444 10.665C14.28 10.5651 14.1518 10.4231 14.0761 10.257C14.0004 10.0909 13.9806 9.90808 14.0192 9.73174C14.0578 9.55539 14.153 9.39341 14.2929 9.26627C14.4327 9.13913 14.6109 9.05255 14.8049 9.01747C14.9989 8.98239 15.2 9.00039 15.3827 9.0692C15.5654 9.13801 15.7216 9.25453 15.8315 9.40403C15.9414 9.55353 16 9.72929 16 9.90909L16 12.1818C16 12.664 15.7893 13.1265 15.4142 13.4675C15.0391 13.8084 14.5304 14 14 14"></path></svg>',hn='<svg viewBox="0 0 18 18"><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="4" y2="4"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="9" y2="9"></line><line stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" x1="8" x2="16" y1="14" y2="14"></line><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect><rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect><polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" points="2.65 9.5 3.5 10.5 5 8.5"></polyline></svg>',fn='<svg viewBox="0 0 18 18"><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.25 12.375v1.688A1.688 1.688 0 0 0 3.938 15.75h10.124a1.688 1.688 0 0 0 1.688-1.688V12.375"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.063 6.188L9 2.25l3.938 3.938"></path><path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 2.25v10.125"></path></svg>',mn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path><circle cx="12" cy="12" r="3" fill="none"></circle></svg>';var S={bold:{name:"bold",actionId:"toggleBold",icon:nn,title:"Bold (Ctrl+B)",action:({editor:t})=>{Ee(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:on,title:"Italic (Ctrl+I)",action:({editor:t})=>{Ce(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:cn,title:"Inline Code",action:({editor:t})=>{Te(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:ln,title:"Insert Link",action:({editor:t})=>{Ae(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:rn,title:"Heading 1",action:({editor:t})=>{He(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:sn,title:"Heading 2",action:({editor:t})=>{Pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:an,title:"Heading 3",action:({editor:t})=>{Oe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:pn,title:"Bullet List",action:({editor:t})=>{Me(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:dn,title:"Numbered List",action:({editor:t})=>{$e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:hn,title:"Task List",action:({editor:t})=>{pe&&(pe(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:un,title:"Quote",action:({editor:t})=>{_e(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:fn,title:"Upload File",action:({editor:t})=>{var n,o;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((o=t.options.fileUpload.mimeTypes)==null?void 0:o.length)>0&&(e.accept=t.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let i=new DataTransfer;for(let s of e.files)i.items.add(s);t._handleDataTransfer(i)},e.click()}},viewMode:{name:"viewMode",icon:mn,title:"View mode"}},re=[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 nt(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let o=n.actionId||n.name;n.action&&(e[o]=n.action)}),e}function gn(t){let e=t||re;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 mo(t,e){let n=gn(t),o=gn(e);if(n===null||o===null)return n!==o;if(n.length!==o.length)return!0;for(let i=0;i<n.length;i++){let r=n[i],s=o[i];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 o=v._resolveTargets(e);if(typeof e=="string"&&o.length===0)throw new Error(`No elements found for selector: ${e}`);return o.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 o=e.querySelector(".overtype-container"),i=e.querySelector(".overtype-wrapper");o||i?this._recoverFromDOM(o,i):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new ae(this),this._rebuildActionsMap(),this.linkTooltip=new Ue(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this._notifyChange()}_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,onFocus:null,onBlur:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:o,colors:i,...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 o=this.instanceTheme||v.currentTheme||F,i=typeof o=="string"?o:o.name;if(i&&this.container.setAttribute("data-theme",i),this.instanceTheme){let r=typeof this.instanceTheme=="string"?U(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._applyInstanceCSSVars(),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||v.currentTheme||F,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let o=typeof this.instanceTheme=="string"?U(this.instanceTheme):this.instanceTheme;if(o&&o.colors){let i=Q(o.colors);this.container.style.cssText+=i}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this._applyInstanceCSSVars(),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([o,i])=>{o==="className"||o==="class"?this.textarea.className+=" "+i:o==="style"&&typeof i=="object"?Object.assign(this.textarea.style,i):this.textarea.setAttribute(o,i)}),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||re;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(o=>(o==null?void 0:o.name)==="upload")){let o=e.findIndex(i=>(i==null?void 0:i.name)==="viewMode");o!==-1?(e=[...e],e.splice(o,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new Re(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=nt(re),this.options.toolbarButtons&&Object.assign(this.actionsById,nt(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,nt([S.upload]))}_applyInstanceCSSVars(){this.wrapper&&(this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.options.fontFamily&&this.wrapper.style.setProperty("--instance-font-family",this.options.fontFamily))}_applyOptions(){this._applyInstanceCSSVars(),this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._uploadedFiles=new Map,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}}_extractMarkdownUrls(e){let n=[],o=/!?\[[^\]]*\]\(([^)\s]+)/g,i;for(;(i=o.exec(e))!==null;)n.push(i[1]);return n}_trackInsertedUrls(e,n){if(!(!this._uploadedFiles||!n||!e))for(let o of this._extractMarkdownUrls(e))this._uploadedFiles.set(o,{filename:n.name,file:n})}_checkForRemovedUploads(){var i;if(!this._uploadedFiles||this._uploadedFiles.size===0)return;let e=(i=this.options.fileUpload)==null?void 0:i.onRemoveFile,n=this.textarea.value,o=[];for(let[r,s]of this._uploadedFiles)n.includes(r)||o.push({url:r,info:s});for(let{url:r,info:s}of o)this._uploadedFiles.delete(r),e&&e({url:r,filename:s.filename,file:s.file})}_handleFilePaste(e){var n,o;(o=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,o;(o=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&o.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let o of e.files){if(o.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(o.type))continue;let i=++this._fileUploadCounter,s=`${o.type.startsWith("image/")?"!":""}[Uploading ${o.name} (#${i})...]()`;if(this.insertAtCursor(`${s}
|
|
73
|
+
`),this.options.fileUpload.batch){n.push({file:o,placeholder:s});continue}this.options.fileUpload.onInsertFile(o).then(a=>{this.textarea.value=this.textarea.value.replace(s,a),this._trackInsertedUrls(a,o),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(o=>o.file)).then(o=>{(Array.isArray(o)?o:[o]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r),this._trackInsertedUrls(r,n[s].file)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},o=>{console.error("OverType: File upload failed",o),n.forEach(({placeholder:i})=>{this.textarea.value=this.textarea.value.replace(i,"[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._uploadedFiles=null,this.fileUploadInitialized=!1}insertAtCursor(e){let n=this.textarea.selectionStart,o=this.textarea.selectionEnd,i=!1;try{i=document.execCommand("insertText",!1,e)}catch(r){}if(!i){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(o);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,o=this._getCurrentLine(e,n),i=this.container.dataset.mode==="preview",r=C.parse(e,o,this.options.showActiveLineRaw,this.options.codeHighlighter,i);this.preview.innerHTML=r,this.placeholderEl&&(this.placeholderEl.style.display=e?"none":""),this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onRender&&this.options.onRender(this.preview,i?"preview":"normal",this)}_notifyChange(){this.initialized&&(this._checkForRemovedUploads(),this.options.onChange&&this.options.onChange(this.textarea.value,this))}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let n=0;n<e.length-1;n+=2){let o=e[n],i=e[n+1],r=o.parentElement,s=i.parentElement;!r||!s||(o.style.display="block",i.style.display="block",r.classList.add("code-block-line"),s.classList.add("code-block-line"))}}_getCurrentLine(e,n){return e.substring(0,n).split(`
|
|
74
74
|
`).length-1}handleInput(e){this.updatePreview(),this._notifyChange()}handleFocus(e){this.options.onFocus&&this.options.onFocus(e,this)}handleBlur(e){this.options.onBlur&&this.options.onBlur(e,this)}handleKeydown(e){if(e.key==="Tab"){let o=this.textarea.selectionStart,i=this.textarea.selectionEnd,r=this.textarea.value;if(e.shiftKey&&o===i)return;if(e.preventDefault(),o!==i&&e.shiftKey){let s=r.substring(0,o),a=r.substring(o,i),l=r.substring(i),c=a.split(`
|
|
75
75
|
`).map(d=>d.replace(/^ /,"")).join(`
|
|
76
76
|
`);document.execCommand?(this.textarea.setSelectionRange(o,i),document.execCommand("insertText",!1,c)):(this.textarea.value=s+c+l,this.textarea.selectionStart=o,this.textarea.selectionEnd=o+c.length)}else if(o!==i){let s=r.substring(0,o),a=r.substring(o,i),l=r.substring(i),c=a.split(`
|
package/package.json
CHANGED
package/src/overtype.d.ts
CHANGED
|
@@ -135,6 +135,7 @@ export interface Options {
|
|
|
135
135
|
mimeTypes?: string[];
|
|
136
136
|
batch?: boolean;
|
|
137
137
|
onInsertFile: (file: File | File[]) => Promise<string | string[]>;
|
|
138
|
+
onRemoveFile?: (info: { url: string; filename: string; file: File }) => void;
|
|
138
139
|
};
|
|
139
140
|
|
|
140
141
|
// Callbacks
|
package/src/overtype.js
CHANGED
|
@@ -605,6 +605,7 @@ class OverType {
|
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
this._fileUploadCounter = 0;
|
|
608
|
+
this._uploadedFiles = new Map(); // url -> { filename, file }
|
|
608
609
|
this._boundHandleFilePaste = this._handleFilePaste.bind(this);
|
|
609
610
|
this._boundHandleFileDrop = this._handleFileDrop.bind(this);
|
|
610
611
|
this._boundHandleDragOver = this._handleDragOver.bind(this);
|
|
@@ -616,6 +617,50 @@ class OverType {
|
|
|
616
617
|
this.fileUploadInitialized = true;
|
|
617
618
|
}
|
|
618
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Extract URLs from markdown link syntax: [text](url) or .
|
|
622
|
+
* @private
|
|
623
|
+
*/
|
|
624
|
+
_extractMarkdownUrls(text) {
|
|
625
|
+
const urls = [];
|
|
626
|
+
const re = /!?\[[^\]]*\]\(([^)\s]+)/g;
|
|
627
|
+
let m;
|
|
628
|
+
while ((m = re.exec(text)) !== null) urls.push(m[1]);
|
|
629
|
+
return urls;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Track URLs that were just inserted, pairing each with the source File.
|
|
634
|
+
* If multiple URLs appear in one inserted block, all get associated with
|
|
635
|
+
* the same file (rare; happens if onInsertFile returns several links).
|
|
636
|
+
* @private
|
|
637
|
+
*/
|
|
638
|
+
_trackInsertedUrls(insertedText, file) {
|
|
639
|
+
if (!this._uploadedFiles || !file || !insertedText) return;
|
|
640
|
+
for (const url of this._extractMarkdownUrls(insertedText)) {
|
|
641
|
+
this._uploadedFiles.set(url, { filename: file.name, file });
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Diff the tracked-URL set against the current value and fire
|
|
647
|
+
* fileUpload.onRemoveFile for any URL no longer present.
|
|
648
|
+
* @private
|
|
649
|
+
*/
|
|
650
|
+
_checkForRemovedUploads() {
|
|
651
|
+
if (!this._uploadedFiles || this._uploadedFiles.size === 0) return;
|
|
652
|
+
const cb = this.options.fileUpload?.onRemoveFile;
|
|
653
|
+
const value = this.textarea.value;
|
|
654
|
+
const removed = [];
|
|
655
|
+
for (const [url, info] of this._uploadedFiles) {
|
|
656
|
+
if (!value.includes(url)) removed.push({ url, info });
|
|
657
|
+
}
|
|
658
|
+
for (const { url, info } of removed) {
|
|
659
|
+
this._uploadedFiles.delete(url);
|
|
660
|
+
if (cb) cb({ url, filename: info.filename, file: info.file });
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
619
664
|
_handleFilePaste(e) {
|
|
620
665
|
if (!e?.clipboardData?.files?.length) return;
|
|
621
666
|
e.preventDefault();
|
|
@@ -647,6 +692,7 @@ class OverType {
|
|
|
647
692
|
|
|
648
693
|
this.options.fileUpload.onInsertFile(file).then((text) => {
|
|
649
694
|
this.textarea.value = this.textarea.value.replace(placeholder, text);
|
|
695
|
+
this._trackInsertedUrls(text, file);
|
|
650
696
|
this.textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
|
651
697
|
}, (error) => {
|
|
652
698
|
console.error('OverType: File upload failed', error);
|
|
@@ -660,6 +706,7 @@ class OverType {
|
|
|
660
706
|
const texts = Array.isArray(result) ? result : [result];
|
|
661
707
|
texts.forEach((text, index) => {
|
|
662
708
|
this.textarea.value = this.textarea.value.replace(files[index].placeholder, text);
|
|
709
|
+
this._trackInsertedUrls(text, files[index].file);
|
|
663
710
|
});
|
|
664
711
|
this.textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
|
665
712
|
}, (error) => {
|
|
@@ -683,6 +730,7 @@ class OverType {
|
|
|
683
730
|
this._boundHandleFilePaste = null;
|
|
684
731
|
this._boundHandleFileDrop = null;
|
|
685
732
|
this._boundHandleDragOver = null;
|
|
733
|
+
this._uploadedFiles = null;
|
|
686
734
|
this.fileUploadInitialized = false;
|
|
687
735
|
}
|
|
688
736
|
|
|
@@ -746,8 +794,11 @@ class OverType {
|
|
|
746
794
|
* @private
|
|
747
795
|
*/
|
|
748
796
|
_notifyChange() {
|
|
749
|
-
if (!this.
|
|
750
|
-
this.
|
|
797
|
+
if (!this.initialized) return;
|
|
798
|
+
this._checkForRemovedUploads();
|
|
799
|
+
if (this.options.onChange) {
|
|
800
|
+
this.options.onChange(this.textarea.value, this);
|
|
801
|
+
}
|
|
751
802
|
}
|
|
752
803
|
|
|
753
804
|
/**
|