/** * OverType v2.3.5 * A lightweight markdown editor library with perfect WYSIWYG alignment * @license MIT * @author David Miranda * https://github.com/panphora/overtype */ var OverType=(()=>{var ve=Object.defineProperty;var cn=Object.getOwnPropertyDescriptor;var pn=Object.getOwnPropertyNames;var dn=Object.prototype.hasOwnProperty;var un=(t,e,n)=>e in t?ve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var hn=(t,e)=>{for(var n in e)ve(t,n,{get:e[n],enumerable:!0})},fn=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of pn(e))!dn.call(t,o)&&o!==n&&ve(t,o,{get:()=>e[o],enumerable:!(i=cn(e,o))||i.enumerable});return t};var mn=t=>fn(ve({},"__esModule",{value:!0}),t);var C=(t,e,n)=>(un(t,typeof e!="symbol"?e+"":e,n),n);var ai={};hn(ai,{OverType:()=>z,default:()=>si,defaultToolbarButtons:()=>ie,toolbarButtons:()=>S});var T=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static setCustomSyntax(e){this.customSyntax=e}static applyCustomSyntax(e){return this.customSyntax?this.customSyntax(e):e}static escapeHtml(e){let n={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,i=>n[i])}static preserveIndentation(e,n){let o=n.match(/^(\s*)/)[1].replace(/ /g," ");return e.replace(/^\s*/,o)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(n,i,o)=>{let r=i.length;return o=this.parseInlineElements(o),`${i} ${o}`})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`
${e}
`:null}static parseBlockquote(e){return e.replace(/^> (.+)$/,(n,i)=>`> ${i}`)}static parseBulletList(e){return e.replace(/^((?: )*)([-*+])\s(.+)$/,(n,i,o,r)=>(r=this.parseInlineElements(r),`${i}
  • ${o} ${r}
  • `))}static parseTaskList(e,n=!1){return e.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/,(i,o,r,s)=>{if(s=this.parseInlineElements(s),n){let a=r.toLowerCase()==="x";return`${o}
  • ${s}
  • `}else return`${o}
  • - [${r}] ${s}
  • `})}static parseNumberedList(e){return e.replace(/^((?: )*)(\d+\.)\s(.+)$/,(n,i,o,r)=>(r=this.parseInlineElements(r),`${i}
  • ${o} ${r}
  • `))}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`
    ${e}
    `:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'**$1**'),e=e.replace(/__(.+?)__/g,'__$1__'),e}static parseItalic(e){return e=e.replace(new RegExp("(?])\\*(?!\\*)(.+?)(?*$1*'),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?_$1_'),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?~~$1~~'),e=e.replace(new RegExp("(?~$1~'),e}static parseInlineCode(e){return e.replace(new RegExp("(?$1$2$3')}static sanitizeUrl(e){let n=e.trim(),i=n.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>i.startsWith(a)),s=n.startsWith("/")||n.startsWith("#")||n.startsWith("?")||n.startsWith(".")||!n.includes(":")&&!n.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(n,i,o)=>{let r=`--link-${this.linkIndex++}`;return`[${i}](${o})`})}static identifyAndProtectSanctuaries(e){let n=new Map,i=0,o=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let h=a.index+a[0].indexOf("](")+2,u=h+a[2].length;r.push({start:h,end:u})}let c=new RegExp("(?d>=f.start&&h<=f.end)||l.push({match:p[0],index:p.index,openTicks:p[1],content:p[2],closeTicks:p[3]})}return l.sort((d,h)=>h.index-d.index),l.forEach(d=>{let h=`\uE000${i++}\uE001`;n.set(h,{type:"code",original:d.match,openTicks:d.openTicks,content:d.content,closeTicks:d.closeTicks}),o=o.substring(0,d.index)+h+o.substring(d.index+d.match.length)}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(d,h,u)=>{let f=`\uE000${i++}\uE001`;return n.set(f,{type:"link",original:d,linkText:h,url:u}),f}),{protectedText:o,sanctuaries:n}}static restoreAndTransformSanctuaries(e,n){return Array.from(n.keys()).sort((o,r)=>{let s=e.indexOf(o),a=e.indexOf(r);return s-a}).forEach(o=>{let r=n.get(o),s;if(r.type==="code")s=`${r.openTicks}${r.content}${r.closeTicks}`;else if(r.type==="link"){let a=r.linkText;n.forEach((l,d)=>{if(a.includes(d)&&l.type==="code"){let h=`${l.openTicks}${l.content}${l.closeTicks}`;a=a.replace(d,h)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let c=`--link-${this.linkIndex++}`;s=`[${a}](${r.url})`}e=e.replace(o,s)}),e}static parseInlineElements(e){let{protectedText:n,sanctuaries:i}=this.identifyAndProtectSanctuaries(e),o=n;return o=this.parseStrikethrough(o),o=this.parseBold(o),o=this.parseItalic(o),o=this.restoreAndTransformSanctuaries(o,i),o}static parseLine(e,n=!1){let i=this.escapeHtml(e);i=this.preserveIndentation(i,e);let o=this.parseHorizontalRule(i);if(o)return o;let r=this.parseCodeBlock(i);return r||(i=this.parseHeader(i),i=this.parseBlockquote(i),i=this.parseTaskList(i,n),i=this.parseBulletList(i),i=this.parseNumberedList(i),!i.includes(" ":`
    ${i}
    `)}static parse(e,n=-1,i=!1,o,r=!1){this.resetLinkIndex();let s=e.split(` `),a=!1,p=s.map((l,d)=>{if(i&&d===n)return`
    ${this.escapeHtml(l)||" "}
    `;if(/^```[^`]*$/.test(l))return a=!a,this.applyCustomSyntax(this.parseLine(l,r));if(a){let u=this.escapeHtml(l);return`
    ${this.preserveIndentation(u,l)||" "}
    `}return this.applyCustomSyntax(this.parseLine(l,r))}).join("");return this.postProcessHTML(p,o)}static postProcessHTML(e,n){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,n);let i=document.createElement("div");i.innerHTML=e;let o=null,r=null,s=null,a=!1,c=Array.from(i.children);for(let p=0;p0&&(s._codeContent+=` `);let f=l.textContent.replace(/\u00A0/g," ");s._codeContent+=f,u.textContent.length>0&&(u.textContent+=` `),u.textContent+=f,l.remove();continue}let h=null;if(l.tagName==="DIV"&&(h=l.querySelector("li")),h){let u=h.classList.contains("bullet-list"),f=h.classList.contains("ordered-list");if(!u&&!f){o=null,r=null;continue}let m=u?"ul":"ol";(!o||r!==m)&&(o=document.createElement(m),i.insertBefore(o,l),r=m);let g=[];for(let y of l.childNodes)if(y.nodeType===3&&y.textContent.match(/^\u00A0+$/))g.push(y.cloneNode(!0));else if(y===h)break;g.forEach(y=>{h.insertBefore(y,h.firstChild)}),o.appendChild(h),l.remove()}else o=null,r=null}return i.innerHTML}static postProcessHTMLManual(e,n){let i=e;i=i.replace(/((?:
    (?: )*
  • .*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/
    (?: )*
  • .*?<\/li><\/div>/gs)||[];return s.length>0?"
      "+s.map(c=>{let p=c.match(/
      ((?: )*)
    • .*?<\/li>/);if(p&&l){let d=p[1];return l[0].replace(/
    • /,`
    • ${d}`)}return l?l[0]:""}).filter(Boolean).join("")+"
    ":r}),i=i.replace(/((?:
    (?: )*
  • .*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/
    (?: )*
  • .*?<\/li><\/div>/gs)||[];return s.length>0?"
      "+s.map(c=>{let p=c.match(/
      ((?: )*)
    1. .*?<\/li>/);if(p&&l){let d=p[1];return l[0].replace(/
    2. /,`
    3. ${d}`)}return l?l[0]:""}).filter(Boolean).join("")+"
    ":r});let o=/
    (```[^<]*)<\/span><\/div>(.*?)
    (```)<\/span><\/div>/gs;return i=i.replace(o,(r,s,a,c)=>{let l=(a.match(/
    (.*?)<\/div>/gs)||[]).map(g=>g.replace(/
    (.*?)<\/div>/s,"$1").replace(/ /g," ")).join(` `),d=s.slice(3).trim(),h=d?` class="language-${d}"`:"",u=l,f=n||this.codeHighlighter;if(f)try{let g=l.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),y=f(g,d);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(u=y)}catch(g){console.warn("Code highlighting failed:",g)}let m=`
    ${s}
    `;return m+=`
    ${u}
    `,m+=`
    ${c}
    `,m}),i}static getListContext(e,n){let i=e.split(` `),o=0,r=0,s=0;for(let h=0;h=n){r=h,s=o;break}o+=u+1}let a=i[r],c=s+a.length,p=a.match(this.LIST_PATTERNS.checkbox);if(p)return{inList:!0,listType:"checkbox",indent:p[1],marker:"-",checked:p[2]==="x",content:p[3],lineStart:s,lineEnd:c,markerEndPos:s+p[1].length+p[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[2].length+1};let d=a.match(this.LIST_PATTERNS.numbered);return d?{inList:!0,listType:"numbered",indent:d[1],marker:parseInt(d[2]),content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let n=e.split(` `),i=new Map,o=!1;return n.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let c=a[1],p=c.length,l=a[3];o||i.clear();let d=(i.get(p)||0)+1;i.set(p,d);for(let[h]of i)h>p&&i.delete(h);return o=!0,`${c}${d}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,i.clear()),s}).join(` `)}};C(T,"linkIndex",0),C(T,"codeHighlighter",null),C(T,"customSyntax",null),C(T,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var re=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let o=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(o="toggleBold");break;case"i":e.shiftKey||(o="toggleItalic");break;case"k":e.shiftKey||(o="insertLink");break;case"7":e.shiftKey&&(o="toggleNumberedList");break;case"8":e.shiftKey&&(o="toggleBulletList");break}return o?(e.preventDefault(),this.editor.performAction(o,e),!0):!1}destroy(){}};var _={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca",placeholder:"#999999"},previewColors:{text:"#0d3b66",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",bg:"transparent"}},qe={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52",placeholder:"#6a7a88"},previewColors:{text:"#c5dde8",h1:"inherit",h2:"inherit",h3:"inherit",strong:"inherit",em:"inherit",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",bg:"transparent"}},We={solar:_,cave:qe,auto:_,light:_,dark:qe};function V(t){return typeof t=="string"?{...We[t]||We.solar,name:t}:t}function Oe(t){if(t!=="auto")return t;let e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)");return e!=null&&e.matches?"cave":"solar"}function Q(t,e){let n=[];for(let[i,o]of Object.entries(t)){let r=i.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--${r}: ${o};`)}if(e)for(let[i,o]of Object.entries(e)){let r=i.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(`--preview-${r}-default: ${o};`)}return n.join(` `)}function Ke(t,e={},n={}){return{...t,colors:{...t.colors,...e},previewColors:{...t.previewColors,...n}}}function Ze(t={}){let{fontSize:e="14px",lineHeight:n=1.6,fontFamily:i='"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:o="20px",theme:r=null,mobile:s={}}=t,a=Object.keys(s).length>0?` @media (max-width: 640px) { .overtype-wrapper .overtype-input, .overtype-wrapper .overtype-preview { ${Object.entries(s).map(([p,l])=>`${p.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${l} !important;`).join(` `)} } } `:"",c=r&&r.colors?Q(r.colors,r.previewColors):"";return` /* OverType Editor Styles */ /* Middle-ground CSS Reset - Prevent parent styles from leaking in */ .overtype-container * { /* Box model - these commonly leak */ margin: 0 !important; padding: 0 !important; border: 0 !important; /* Layout - these can break our layout */ /* Don't reset position - it breaks dropdowns */ float: none !important; clear: none !important; /* Typography - only reset decorative aspects */ text-decoration: none !important; text-transform: none !important; letter-spacing: normal !important; /* Visual effects that can interfere */ box-shadow: none !important; text-shadow: none !important; /* Ensure box-sizing is consistent */ box-sizing: border-box !important; /* Keep inheritance for these */ /* font-family, color, line-height, font-size - inherit */ } /* Container base styles after reset */ .overtype-container { display: flex !important; flex-direction: column !important; width: 100% !important; height: 100% !important; position: relative !important; /* Override reset - needed for absolute children */ overflow: visible !important; /* Allow dropdown to overflow container */ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important; text-align: left !important; ${c?` /* Theme Variables */ ${c}`:""} } /* Force left alignment for all elements in the editor */ .overtype-container .overtype-wrapper * { text-align: left !important; } /* Auto-resize mode styles */ .overtype-container.overtype-auto-resize { height: auto !important; } .overtype-container.overtype-auto-resize .overtype-wrapper { flex: 0 0 auto !important; /* Don't grow/shrink, use explicit height */ height: auto !important; min-height: 60px !important; overflow: visible !important; } .overtype-wrapper { position: relative !important; /* Override reset - needed for absolute children */ width: 100% !important; flex: 1 1 0 !important; /* Grow to fill remaining space, with flex-basis: 0 */ min-height: 60px !important; /* Minimum usable height */ overflow: hidden !important; background: var(--bg-secondary, #ffffff) !important; z-index: 1; /* Below toolbar and dropdown */ } /* Critical alignment styles - must be identical for both layers */ .overtype-wrapper .overtype-input, .overtype-wrapper .overtype-preview { /* Positioning - must be identical */ position: absolute !important; /* Override reset - required for overlay */ top: 0 !important; left: 0 !important; width: 100% !important; height: 100% !important; /* Font properties - any difference breaks alignment */ font-family: ${i} !important; font-variant-ligatures: none !important; /* keep metrics stable for code */ font-size: var(--instance-font-size, ${e}) !important; line-height: var(--instance-line-height, ${n}) !important; font-weight: normal !important; font-style: normal !important; font-variant: normal !important; font-stretch: normal !important; font-kerning: none !important; font-feature-settings: normal !important; /* Box model - must match exactly */ padding: var(--instance-padding, ${o}) !important; margin: 0 !important; border: none !important; outline: none !important; box-sizing: border-box !important; /* Text layout - critical for character positioning */ white-space: pre-wrap !important; word-wrap: break-word !important; word-break: normal !important; overflow-wrap: break-word !important; tab-size: 2 !important; -moz-tab-size: 2 !important; text-align: left !important; text-indent: 0 !important; letter-spacing: normal !important; word-spacing: normal !important; /* Text rendering */ text-transform: none !important; text-rendering: auto !important; -webkit-font-smoothing: auto !important; -webkit-text-size-adjust: 100% !important; /* Direction and writing */ direction: ltr !important; writing-mode: horizontal-tb !important; unicode-bidi: normal !important; text-orientation: mixed !important; /* Visual effects that could shift perception */ text-shadow: none !important; filter: none !important; transform: none !important; zoom: 1 !important; /* Vertical alignment */ vertical-align: baseline !important; /* Size constraints */ min-width: 0 !important; min-height: 0 !important; max-width: none !important; max-height: none !important; /* Overflow */ overflow-y: auto !important; overflow-x: auto !important; /* overscroll-behavior removed to allow scroll-through to parent */ scrollbar-width: auto !important; scrollbar-gutter: auto !important; /* Animation/transition - disabled to prevent movement */ animation: none !important; transition: none !important; } /* Input layer styles */ .overtype-wrapper .overtype-input { /* Layer positioning */ z-index: 1 !important; /* Text visibility */ color: transparent !important; caret-color: var(--cursor, #f95738) !important; background-color: transparent !important; /* Textarea-specific */ resize: none !important; appearance: none !important; -webkit-appearance: none !important; -moz-appearance: none !important; /* Prevent mobile zoom on focus */ touch-action: manipulation !important; /* Disable autofill */ autocomplete: off !important; autocorrect: off !important; autocapitalize: off !important; } .overtype-wrapper .overtype-input::selection { background-color: var(--selection, rgba(244, 211, 94, 0.4)); } /* Placeholder shim - visible when textarea is empty */ .overtype-wrapper .overtype-placeholder { position: absolute !important; top: 0 !important; left: 0 !important; width: 100% !important; z-index: 0 !important; pointer-events: none !important; user-select: none !important; font-family: ${i} !important; font-size: var(--instance-font-size, ${e}) !important; line-height: var(--instance-line-height, ${n}) !important; padding: var(--instance-padding, ${o}) !important; box-sizing: border-box !important; color: var(--placeholder, #999) !important; overflow: hidden !important; white-space: nowrap !important; text-overflow: ellipsis !important; } /* Preview layer styles */ .overtype-wrapper .overtype-preview { /* Layer positioning */ z-index: 0 !important; pointer-events: none !important; color: var(--text, #0d3b66) !important; background-color: transparent !important; /* Prevent text selection */ user-select: none !important; -webkit-user-select: none !important; -moz-user-select: none !important; -ms-user-select: none !important; } /* Prevent external resets (Tailwind, Bootstrap, etc.) from breaking alignment. Any element whose font metrics differ from the textarea causes the CSS "strut" to inflate line boxes, drifting the overlay. Force inheritance so every element inside the preview matches the textarea exactly. */ .overtype-wrapper .overtype-preview * { font-family: inherit !important; font-size: inherit !important; line-height: inherit !important; } /* Defensive styles for preview child divs */ .overtype-wrapper .overtype-preview div { /* Reset any inherited styles */ 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; } /* Markdown element styling - NO SIZE CHANGES */ .overtype-wrapper .overtype-preview .header { font-weight: bold !important; } /* Header colors */ .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; } /* Semantic headers - flatten in edit mode */ .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; } /* Header colors for semantic headers */ .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; } /* Lists - remove styling in edit mode */ .overtype-wrapper .overtype-preview ul, .overtype-wrapper .overtype-preview ol { list-style: none !important; margin: 0 !important; padding: 0 !important; display: block !important; /* Lists need to be block for line breaks */ } .overtype-wrapper .overtype-preview li { display: block !important; /* Each item on its own line */ margin: 0 !important; padding: 0 !important; /* Don't set list-style here - let ul/ol control it */ } /* Bold text */ .overtype-wrapper .overtype-preview strong { color: var(--strong, #ee964b) !important; font-weight: bold !important; } /* Italic text */ .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; } /* Strikethrough text */ .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; } /* Inline code */ .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; } /* Code blocks - consolidated pre blocks */ .overtype-wrapper .overtype-preview pre { padding: 0 !important; margin: 0 !important; border-radius: 4px !important; overflow-x: auto !important; } /* Code block styling in normal mode - yellow background */ .overtype-wrapper .overtype-preview pre.code-block { background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important; white-space: break-spaces !important; /* Prevent horizontal scrollbar that breaks alignment */ } /* Code inside pre blocks - remove background */ .overtype-wrapper .overtype-preview pre code { background: transparent !important; color: var(--code, #0d3b66) !important; font-family: ${i} !important; /* Match textarea font exactly for alignment */ } /* Blockquotes */ .overtype-wrapper .overtype-preview .blockquote { color: var(--blockquote, #5a7a9b) !important; padding: 0 !important; margin: 0 !important; border: none !important; } /* Links */ .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; } /* Lists - no list styling */ .overtype-wrapper .overtype-preview ul, .overtype-wrapper .overtype-preview ol { list-style: none !important; margin: 0 !important; padding: 0 !important; } /* Horizontal rules */ .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; } /* Code fence markers - with background when not in code block */ .overtype-wrapper .overtype-preview .code-fence { color: var(--code, #0d3b66) !important; background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important; } /* Code block lines - background for entire code block */ .overtype-wrapper .overtype-preview .code-block-line { background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important; } /* Remove background from code fence when inside code block line */ .overtype-wrapper .overtype-preview .code-block-line .code-fence { background: transparent !important; } /* Raw markdown line */ .overtype-wrapper .overtype-preview .raw-line { color: var(--raw-line, #5a7a9b) !important; font-style: normal !important; font-weight: normal !important; } /* Syntax markers */ .overtype-wrapper .overtype-preview .syntax-marker { color: var(--syntax-marker, rgba(13, 59, 102, 0.52)) !important; opacity: 0.7 !important; } /* List markers */ .overtype-wrapper .overtype-preview .list-marker { color: var(--list-marker, #ee964b) !important; } /* Stats bar */ /* Stats bar - positioned by flexbox */ .overtype-stats { height: 40px !important; padding: 0 20px !important; background: #f8f9fa !important; border-top: 1px solid #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: #666 !important; flex-shrink: 0 !important; /* Don't shrink */ z-index: 10001 !important; /* Above link tooltip */ position: relative !important; /* Enable z-index */ } /* Dark theme stats bar */ .overtype-container[data-theme="cave"] .overtype-stats { background: var(--bg-secondary, #1D2D3E) !important; border-top: 1px solid rgba(197, 221, 232, 0.1) !important; color: var(--text, #c5dde8) !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); } } /* Toolbar Styles */ .overtype-toolbar.overtype-toolbar-hidden { display: none !important; } .overtype-toolbar { display: flex !important; align-items: center !important; gap: 4px !important; padding: 8px !important; /* Override reset */ background: var(--toolbar-bg, var(--bg-primary, #f8f9fa)) !important; /* Override reset */ border-bottom: 1px solid var(--toolbar-border, transparent) !important; /* Override reset */ overflow-x: auto !important; /* Allow horizontal scrolling */ overflow-y: hidden !important; /* Hide vertical overflow */ -webkit-overflow-scrolling: touch !important; flex-shrink: 0 !important; height: auto !important; position: relative !important; /* Override reset */ z-index: 100 !important; /* Ensure toolbar is above wrapper */ scrollbar-width: thin; /* Thin scrollbar on Firefox */ } /* Thin scrollbar styling */ .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; } /* Adjust wrapper when toolbar is present */ /* Mobile toolbar adjustments */ @media (max-width: 640px) { .overtype-toolbar { padding: 6px; gap: 2px; } .overtype-toolbar-button { width: 36px; height: 36px; } .overtype-toolbar-separator { margin: 0 2px; } } /* Plain mode - hide preview and show textarea text */ .overtype-container[data-mode="plain"] .overtype-preview { display: none !important; } .overtype-container[data-mode="plain"] .overtype-input { color: var(--text, #0d3b66) !important; /* Use system font stack for better plain text readability */ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important; } /* Ensure textarea remains transparent in overlay mode */ .overtype-container:not([data-mode="plain"]) .overtype-input { color: transparent !important; } /* Dropdown menu styles */ .overtype-toolbar-button { position: relative !important; /* Override reset - needed for dropdown */ } .overtype-toolbar-button.dropdown-active { background: var(--toolbar-active, var(--hover-bg, #f0f0f0)); } .overtype-dropdown-menu { position: fixed !important; /* Fixed positioning relative to viewport */ background: var(--bg-secondary, white) !important; /* Override reset */ border: 1px solid var(--border, #e0e0e0) !important; /* Override reset */ border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important; /* Override reset */ z-index: 10000; /* Very high z-index to ensure visibility */ min-width: 150px; padding: 4px 0 !important; /* Override reset */ /* Position will be set via JavaScript based on button position */ } .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; } /* Preview mode styles */ .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; } /* Hide syntax markers in preview mode */ .overtype-container[data-mode="preview"] .syntax-marker { display: none !important; } /* Hide URL part of links in preview mode - extra specificity */ .overtype-container[data-mode="preview"] .syntax-marker.url-part, .overtype-container[data-mode="preview"] .url-part { display: none !important; } /* Hide all syntax markers inside links too */ .overtype-container[data-mode="preview"] a .syntax-marker { display: none !important; } /* Headers - restore proper sizing in preview mode */ .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; } /* Lists - restore list styling in preview mode */ .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; } /* Task list checkboxes - only in preview mode */ .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; } /* Task list in normal mode - keep syntax visible */ .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; } /* Links - make clickable in preview mode */ .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; } /* Code blocks - proper pre/code styling in preview mode */ .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: ${i} !important; font-size: 0.9em !important; line-height: 1.4 !important; } /* Hide old code block lines and fences in preview mode */ .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; } /* Blockquotes - enhanced styling in preview mode */ .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; } /* Typography improvements in preview mode */ .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; } /* Inline code in preview mode - keep monospace */ .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview code { font-family: ${i} !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; } /* Strong and em elements in preview mode */ .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; } /* HR in preview mode */ .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; } /* Link Tooltip */ .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} `}var gn=Object.defineProperty,Qe=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,Ge=(t,e,n)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Je=(t,e)=>{for(var n in e||(e={}))vn.call(e,n)&&Ge(t,n,e[n]);if(Qe)for(var n of Qe(e))yn.call(e,n)&&Ge(t,n,e[n]);return t},I={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function wn(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function F(t){return Je(Je({},wn()),t)}var we=!1;function bn(){return we}function x(t,e,n){we&&(console.group(`\u{1F50D} ${t}`),console.log(e),n&&console.log("Data:",n),console.groupEnd())}function ye(t,e){if(!we)return;let n=t.value.slice(t.selectionStart,t.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Selected text:",JSON.stringify(n)),console.log("Length:",n.length);let i=t.value.slice(Math.max(0,t.selectionStart-10),t.selectionStart),o=t.value.slice(t.selectionEnd,Math.min(t.value.length,t.selectionEnd+10));console.log("Context:",JSON.stringify(i)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function tt(t){we&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(t.text)),console.log("New selection:",`${t.selectionStart}-${t.selectionEnd}`),console.groupEnd())}var B=null;function U(t,{text:e,selectionStart:n,selectionEnd:i}){let o=bn();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${t.selectionStart}-${t.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",n,"-",i)),t.focus();let r=t.selectionStart,s=t.selectionEnd,a=t.value.slice(0,r),c=t.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(t.value.slice(r,s))));let p=t.value,l=r!==s;if(B===null||B===!0){t.contentEditable="true";try{B=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",B,"for text with",e.split(` `).length,"lines")}catch(d){B=!1,o&&console.log("execCommand threw error:",d)}t.contentEditable="false"}if(o&&(console.log("canInsertText before:",B),console.log("execCommand result:",B)),B){let d=a+e+c,h=t.value;o&&(console.log("Expected length:",d.length),console.log("Actual length:",h.length)),h!==d&&o&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(d.slice(0,100))),console.log("Actual:",JSON.stringify(h.slice(0,100))))}if(!B)if(o&&console.log("Using manual insertion"),t.value===p){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(d){}t.value=a+e+c;try{document.execCommand("ms-endUndoUnit")}catch(d){}t.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else o&&console.log("Value was changed by execCommand, skipping manual insertion");o&&console.log("Setting selection range:",n,i),n!=null&&i!=null?t.setSelectionRange(n,i):t.setSelectionRange(r,t.selectionEnd),o&&(console.log("Final value length:",t.value.length),console.groupEnd())}function Xe(t){return t.trim().split(` `).length>1}function xn(t,e){let n=e;for(;t[n]&&t[n-1]!=null&&!t[n-1].match(/\s/);)n--;return n}function kn(t,e,n){let i=e,o=n?/\n/:/\s/;for(;t[i]&&!t[i].match(o);)i++;return i}function nt(t){let e=t.value.split(` `),n=0;for(let i=0;i=n&&t.selectionStart=n&&t.selectionEnd0&&s[a-1]!==` `;)a--;if(r){let p=i;for(;p0?`${s} `:o,y=Xe(m)&&a&&a.length>0?` ${a}`:r;if(p){let k=t.value[t.selectionStart-1];t.selectionStart!==0&&k!=null&&!k.match(/\s/)&&(g=` ${g}`)}m=Ln(t,g,y,e.multiline);let w=t.selectionStart,b=t.selectionEnd,L=c&&c.length>0&&y.indexOf(c)>-1&&m.length>0;if(d){let k=$e(t);n=k.newlinesToAppend,i=k.newlinesToPrepend,g=n+o,y+=i}if(m.startsWith(g)&&m.endsWith(y)){let k=m.slice(g.length,m.length-y.length);if(u===f){let E=u-g.length;E=Math.max(E,w),E=Math.min(E,w+k.length),w=b=E}else b=w+k.length;return{text:k,selectionStart:w,selectionEnd:b}}else if(L)if(l&&l.length>0&&m.match(l)){y=y.replace(c,m);let k=g+y;return w=b=w+g.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=g+m+y;return w=w+g.length+m.length+y.indexOf(c),b=w+c.length,{text:k,selectionStart:w,selectionEnd:b}}else{let k=g+m+y;w=u+g.length,b=f+g.length;let E=m.match(/^\s*|\s*$/g);if(h&&E){let me=E[0]||"",Y=E[1]||"";k=me+g+m.trim()+y+Y,w+=me.length,b-=Y.length}return{text:k,selectionStart:w,selectionEnd:b}}}function it(t,e){let{prefix:n,suffix:i,surroundWithNewlines:o}=e,r=t.value.slice(t.selectionStart,t.selectionEnd),s=t.selectionStart,a=t.selectionEnd,c=r.split(` `);if(c.every(l=>l.startsWith(n)&&(!i||l.endsWith(i))))r=c.map(l=>{let d=l.slice(n.length);return i&&(d=d.slice(0,d.length-i.length)),d}).join(` `),a=s+r.length;else if(r=c.map(l=>n+l+(i||"")).join(` `),o){let{newlinesToAppend:l,newlinesToPrepend:d}=$e(t);s+=l.length,a=s+r.length,r=l+r+d}return{text:r,selectionStart:s,selectionEnd:a}}function Ye(t){let e=t.split(` `),n=/^\d+\.\s+/,i=e.every(r=>n.test(r)),o=e;return i&&(o=e.map(r=>r.replace(n,""))),{text:o.join(` `),processed:i}}function et(t){let e=t.split(` `),n="- ",i=e.every(r=>r.startsWith(n)),o=e;return i&&(o=e.map(r=>r.slice(n.length))),{text:o.join(` `),processed:i}}function se(t,e){return e?"- ":`${t+1}. `}function Sn(t,e){let n,i,o;return t.orderedList?(n=Ye(e),i=et(n.text),o=i.text):(n=et(e),i=Ye(n.text),o=i.text),[n,i,o]}function En(t,e){let n=t.selectionStart===t.selectionEnd,i=t.selectionStart,o=t.selectionEnd;nt(t);let r=t.value.slice(t.selectionStart,t.selectionEnd),[s,a,c]=Sn(e,r),p=c.split(` `).map((m,g)=>`${se(g,e.unorderedList)}${m}`),l=p.reduce((m,g,y)=>m+se(y,e.unorderedList).length,0),d=p.reduce((m,g,y)=>m+se(y,!e.unorderedList).length,0);if(s.processed)return n?(i=Math.max(i-se(0,e.unorderedList).length,0),o=i):(i=t.selectionStart,o=t.selectionEnd-l),{text:c,selectionStart:i,selectionEnd:o};let{newlinesToAppend:h,newlinesToPrepend:u}=$e(t),f=h+p.join(` `)+u;return n?(i=Math.max(i+se(0,e.unorderedList).length+h.length,0),o=i):a.processed?(i=Math.max(t.selectionStart+h.length,0),o=t.selectionEnd+h.length+l-d):(i=Math.max(t.selectionStart+h.length,0),o=t.selectionEnd+h.length+l),{text:f,selectionStart:i,selectionEnd:o}}function ot(t,e){let n=be(t,i=>En(i,e),{adjustSelection:(i,o,r,s)=>{let a=t.value.slice(s,t.selectionEnd),c=/^\d+\.\s+/,p=/^- /,l=c.test(a),d=p.test(a),h=e.orderedList&&l||e.unorderedList&&d;if(o===r)if(h){let u=a.match(e.orderedList?c:p),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||d){let u=a.match(l?c:p),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:o+u}}else if(h){let u=a.match(e.orderedList?c:p),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||d){let u=a.match(l?c:p),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:r+u}}}});U(t,n)}function Tn(t){if(!t)return[];let e=[],{selectionStart:n,selectionEnd:i,value:o}=t,r=o.split(` `),s=0,a="";for(let d of r){if(n>=s&&n<=s+d.length){a=d;break}s+=d.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,n-10),p=Math.min(o.length,i+10),l=o.slice(c,p);if(l.includes("**")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100));d.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let d=o.slice(Math.max(0,n-100),n),h=o.slice(i,Math.min(o.length,i+100)),u=d.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&o.slice(i+f+1,i+f+10).startsWith("(")&&e.push("link")}return e}function rt(t){if(!t||t.disabled||t.readOnly)return;x("toggleBold","Starting"),ye(t,"Before");let e=F(I.bold),n=xe(t,e);tt(n),U(t,n),ye(t,"After")}function st(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.italic),n=xe(t,e);U(t,n)}function at(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.code),n=xe(t,e);U(t,n)}function lt(t,e={}){if(!t||t.disabled||t.readOnly)return;let n=t.value.slice(t.selectionStart,t.selectionEnd),i=F(I.link);if(n&&n.match(/^https?:\/\//)&&!e.url?(i.suffix=`](${n})`,i.replaceNext=""):e.url&&(i.suffix=`](${e.url})`,i.replaceNext=""),e.text&&!n){let s=t.selectionStart;t.value=t.value.slice(0,s)+e.text+t.value.slice(s),t.selectionStart=s,t.selectionEnd=s+e.text.length}let r=xe(t,i);U(t,r)}function ct(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.bulletList);ot(t,e)}function pt(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.numberedList);ot(t,e)}function dt(t){if(!t||t.disabled||t.readOnly)return;x("toggleQuote","Starting"),ye(t,"Initial");let e=F(I.quote),n=be(t,i=>it(i,e),{prefix:e.prefix});tt(n),U(t,n),ye(t,"Final")}function Ie(t){if(!t||t.disabled||t.readOnly)return;let e=F(I.taskList),n=be(t,i=>it(i,e),{prefix:e.prefix});U(t,n)}function Re(t,e=1,n=!1){if(!t||t.disabled||t.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${n}`),x("insertHeader",`Initial cursor: ${t.selectionStart}-${t.selectionEnd}`);let i=`header${e===1?"1":e}`,o=F(I[i]||I.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=t.value,s=t.selectionStart,a=t.selectionEnd,c=s;for(;c>0&&r[c-1]!==` `;)c--;let p=a;for(;p{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let w=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${w}"`);let b;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),b=w):h>0?(x("insertHeader",`ACTION: Replacing H${h} with H${e}`),b=o.prefix+w):(x("insertHeader","ACTION: Adding new header"),b=o.prefix+w),x("insertHeader",`New line: "${b}"`),{text:b,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,y,w,b)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${w}`),x("insertHeader",` - lineStartPos: ${b}`),f){let L=Math.max(y-u,b);return x("insertHeader",` - Removing header, adjusting by -${u}`),{start:L,end:y===w?L:Math.max(w-u,b)}}else if(u>0){let L=o.prefix.length-u;return x("insertHeader",` - Replacing header, adjusting by ${L}`),{start:y+L,end:w+L}}else return x("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:y+o.prefix.length,end:w+o.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),U(t,m)}function ut(t){Re(t,1,!0)}function ht(t){Re(t,2,!0)}function ft(t){Re(t,3,!0)}function mt(t){return Tn(t)}var ke=class{constructor(e,n={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=n.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let n=this.createSeparator();this.container.appendChild(n)}else{let n=this.createButton(e);this.buttons[e.name]=n,this.container.appendChild(n)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let n=document.createElement("button");return n.className="overtype-toolbar-button",n.type="button",n.setAttribute("data-button",e.name),n.title=e.title||"",n.setAttribute("aria-label",e.title||e.name),n.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(n.classList.add("has-dropdown"),n.dataset.dropdown="true",n.addEventListener("click",i=>{i.preventDefault(),this.toggleViewModeDropdown(n)}),n):(n._clickHandler=i=>{i.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,i)},n.addEventListener("click",n._clickHandler),n)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:n=>this.editor.setValue(n),event:null}),!0}catch(n){return console.error(`Action "${e.name}" error:`,n),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:n}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let n=document.querySelector(".overtype-dropdown-menu");if(n){n.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let i=this.createViewModeDropdown(e),o=e.getBoundingClientRect();i.style.position="absolute",i.style.top=`${o.bottom+5}px`,i.style.left=`${o.left}px`,document.body.appendChild(i),this.handleDocumentClick=r=>{!i.contains(r.target)&&!e.contains(r.target)&&(i.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let n=document.createElement("div");n.className="overtype-dropdown-menu";let i=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],o=this.editor.container.dataset.mode||"normal";return i.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===o){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),n.appendChild(s)}),n}updateButtonStates(){var e;try{let n=((e=mt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([i,o])=>{if(i==="viewMode")return;let r=!1;switch(i){case"bold":r=n.includes("bold");break;case"italic":r=n.includes("italic");break;case"code":r=!1;break;case"bulletList":r=n.includes("bullet-list");break;case"orderedList":r=n.includes("numbered-list");break;case"taskList":r=n.includes("task-list");break;case"quote":r=n.includes("quote");break;case"h1":r=n.includes("header");break;case"h2":r=n.includes("header-2");break;case"h3":r=n.includes("header-3");break}o.classList.toggle("active",r),o.setAttribute("aria-pressed",r.toString())})}catch(n){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var le=Math.min,q=Math.max,ce=Math.round;var O=t=>({x:t,y:t}),Cn={left:"right",right:"left",bottom:"top",top:"bottom"},An={start:"end",end:"start"};function _e(t,e,n){return q(t,le(e,n))}function pe(t,e){return typeof t=="function"?t(e):t}function W(t){return t.split("-")[0]}function de(t){return t.split("-")[1]}function Be(t){return t==="x"?"y":"x"}function Fe(t){return t==="y"?"height":"width"}var Mn=new Set(["top","bottom"]);function N(t){return Mn.has(W(t))?"y":"x"}function Ne(t){return Be(N(t))}function wt(t,e,n){n===void 0&&(n=!1);let i=de(t),o=Ne(t),r=Fe(o),s=o==="x"?i===(n?"end":"start")?"right":"left":i==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=ae(s)),[s,ae(s)]}function bt(t){let e=ae(t);return[Le(t),e,Le(e)]}function Le(t){return t.replace(/start|end/g,e=>An[e])}var vt=["left","right"],yt=["right","left"],Hn=["top","bottom"],Pn=["bottom","top"];function On(t,e,n){switch(t){case"top":case"bottom":return n?e?yt:vt:e?vt:yt;case"left":case"right":return e?Hn:Pn;default:return[]}}function xt(t,e,n,i){let o=de(t),r=On(W(t),n==="start",i);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Le)))),r}function ae(t){return t.replace(/left|right|bottom|top/g,e=>Cn[e])}function $n(t){return{top:0,right:0,bottom:0,left:0,...t}}function kt(t){return typeof t!="number"?$n(t):{top:t,right:t,bottom:t,left:t}}function G(t){let{x:e,y:n,width:i,height:o}=t;return{width:i,height:o,top:n,left:e,right:e+i,bottom:n+o,x:e,y:n}}function Lt(t,e,n){let{reference:i,floating:o}=t,r=N(e),s=Ne(e),a=Fe(s),c=W(e),p=r==="y",l=i.x+i.width/2-o.width/2,d=i.y+i.height/2-o.height/2,h=i[a]/2-o[a]/2,u;switch(c){case"top":u={x:l,y:i.y-o.height};break;case"bottom":u={x:l,y:i.y+i.height};break;case"right":u={x:i.x+i.width,y:d};break;case"left":u={x:i.x-o.width,y:d};break;default:u={x:i.x,y:i.y}}switch(de(e)){case"start":u[s]-=h*(n&&p?-1:1);break;case"end":u[s]+=h*(n&&p?-1:1);break}return u}async function St(t,e){var n;e===void 0&&(e={});let{x:i,y:o,platform:r,rects:s,elements:a,strategy:c}=t,{boundary:p="clippingAncestors",rootBoundary:l="viewport",elementContext:d="floating",altBoundary:h=!1,padding:u=0}=pe(e,t),f=kt(u),g=a[h?d==="floating"?"reference":"floating":d],y=G(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(g)))==null||n?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:p,rootBoundary:l,strategy:c})),w=d==="floating"?{x:i,y:o,width:s.floating.width,height:s.floating.height}:s.reference,b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),L=await(r.isElement==null?void 0:r.isElement(b))?await(r.getScale==null?void 0:r.getScale(b))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:b,strategy:c}):w);return{top:(y.top-k.top+f.top)/L.y,bottom:(k.bottom-y.bottom+f.bottom)/L.y,left:(y.left-k.left+f.left)/L.x,right:(k.right-y.right+f.right)/L.x}}var Et=async(t,e,n)=>{let{placement:i="bottom",strategy:o="absolute",middleware:r=[],platform:s}=n,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:t,floating:e,strategy:o}),{x:l,y:d}=Lt(p,i,c),h=i,u={},f=0;for(let g=0;gK<=0)){var je,Ve;let K=(((je=r.flip)==null?void 0:je.index)||0)+1,Pe=me[K];if(Pe&&(!(d==="alignment"?w!==N(Pe):!1)||ee.every(P=>N(P.placement)===w?P.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let oe=(Ve=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,P)=>Z.overflows[1]-P.overflows[1])[0])==null?void 0:Ve.placement;if(!oe)switch(u){case"bestFit":{var Ue;let Z=(Ue=ee.filter(P=>{if(E){let j=N(P.placement);return j===w||j==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(j=>j>0).reduce((j,ln)=>j+ln,0)]).sort((P,j)=>P[1]-j[1])[0])==null?void 0:Ue[0];Z&&(oe=Z);break}case"initialPlacement":oe=a;break}if(o!==oe)return{reset:{placement:oe}}}return{}}}};var In=new Set(["left","top"]);async function Rn(t,e){let{placement:n,platform:i,elements:o}=t,r=await(i.isRTL==null?void 0:i.isRTL(o.floating)),s=W(n),a=de(n),c=N(n)==="y",p=In.has(s)?-1:1,l=r&&c?-1:1,d=pe(e,t),{mainAxis:h,crossAxis:u,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(u=a==="end"?f*-1:f),c?{x:u*l,y:h*p}:{x:h*p,y:u*l}}var Ct=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,i;let{x:o,y:r,placement:s,middlewareData:a}=e,c=await Rn(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(i=a.arrow)!=null&&i.alignmentOffset?{}:{x:o+c.x,y:r+c.y,data:{...c,placement:s}}}}},At=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:i,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:w,y:b}=y;return{x:w,y:b}}},...p}=pe(t,e),l={x:n,y:i},d=await r.detectOverflow(e,p),h=N(W(o)),u=Be(h),f=l[u],m=l[h];if(s){let y=u==="y"?"top":"left",w=u==="y"?"bottom":"right",b=f+d[y],L=f-d[w];f=_e(b,f,L)}if(a){let y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+d[y],L=m-d[w];m=_e(b,m,L)}let g=c.fn({...e,[u]:f,[h]:m});return{...g,data:{x:g.x-n,y:g.y-i,enabled:{[u]:s,[h]:a}}}}}};function Ee(){return typeof window<"u"}function J(t){return Ht(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function R(t){var e;return(e=(Ht(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ht(t){return Ee()?t instanceof Node||t instanceof A(t).Node:!1}function M(t){return Ee()?t instanceof Element||t instanceof A(t).Element:!1}function $(t){return Ee()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function Mt(t){return!Ee()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}var _n=new Set(["inline","contents"]);function te(t){let{overflow:e,overflowX:n,overflowY:i,display:o}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!_n.has(o)}var Bn=new Set(["table","td","th"]);function Pt(t){return Bn.has(J(t))}var Fn=[":popover-open",":modal"];function ue(t){return Fn.some(e=>{try{return t.matches(e)}catch(n){return!1}})}var Nn=["transform","translate","scale","rotate","perspective"],Dn=["transform","translate","scale","rotate","perspective","filter"],zn=["paint","layout","strict","content"];function Te(t){let e=Ce(),n=M(t)?H(t):t;return Nn.some(i=>n[i]?n[i]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||Dn.some(i=>(n.willChange||"").includes(i))||zn.some(i=>(n.contain||"").includes(i))}function Ot(t){let e=D(t);for(;$(e)&&!X(e);){if(Te(e))return e;if(ue(e))return null;e=D(e)}return null}function Ce(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var jn=new Set(["html","body","#document"]);function X(t){return jn.has(J(t))}function H(t){return A(t).getComputedStyle(t)}function he(t){return M(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function D(t){if(J(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Mt(t)&&t.host||R(t);return Mt(e)?e.host:e}function $t(t){let e=D(t);return X(e)?t.ownerDocument?t.ownerDocument.body:t.body:$(e)&&te(e)?e:$t(e)}function Se(t,e,n){var i;e===void 0&&(e=[]),n===void 0&&(n=!0);let o=$t(t),r=o===((i=t.ownerDocument)==null?void 0:i.body),s=A(o);if(r){let a=Ae(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&n?Se(a):[])}return e.concat(o,Se(o,[],n))}function Ae(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Bt(t){let e=H(t),n=parseFloat(e.width)||0,i=parseFloat(e.height)||0,o=$(t),r=o?t.offsetWidth:n,s=o?t.offsetHeight:i,a=ce(n)!==r||ce(i)!==s;return a&&(n=r,i=s),{width:n,height:i,$:a}}function Ft(t){return M(t)?t:t.contextElement}function ne(t){let e=Ft(t);if(!$(e))return O(1);let n=e.getBoundingClientRect(),{width:i,height:o,$:r}=Bt(e),s=(r?ce(n.width):n.width)/i,a=(r?ce(n.height):n.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Vn=O(0);function Nt(t){let e=A(t);return!Ce()||!e.visualViewport?Vn:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Un(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==A(t)?!1:e}function fe(t,e,n,i){e===void 0&&(e=!1),n===void 0&&(n=!1);let o=t.getBoundingClientRect(),r=Ft(t),s=O(1);e&&(i?M(i)&&(s=ne(i)):s=ne(t));let a=Un(r,n,i)?Nt(r):O(0),c=(o.left+a.x)/s.x,p=(o.top+a.y)/s.y,l=o.width/s.x,d=o.height/s.y;if(r){let h=A(r),u=i&&M(i)?A(i):i,f=h,m=Ae(f);for(;m&&i&&u!==f;){let g=ne(m),y=m.getBoundingClientRect(),w=H(m),b=y.left+(m.clientLeft+parseFloat(w.paddingLeft))*g.x,L=y.top+(m.clientTop+parseFloat(w.paddingTop))*g.y;c*=g.x,p*=g.y,l*=g.x,d*=g.y,c+=b,p+=L,f=A(m),m=Ae(f)}}return G({width:l,height:d,x:c,y:p})}function Me(t,e){let n=he(t).scrollLeft;return e?e.left+n:fe(R(t)).left+n}function Dt(t,e){let n=t.getBoundingClientRect(),i=n.left+e.scrollLeft-Me(t,n),o=n.top+e.scrollTop;return{x:i,y:o}}function qn(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t,r=o==="fixed",s=R(i),a=e?ue(e.floating):!1;if(i===s||a&&r)return n;let c={scrollLeft:0,scrollTop:0},p=O(1),l=O(0),d=$(i);if((d||!d&&!r)&&((J(i)!=="body"||te(s))&&(c=he(i)),$(i))){let u=fe(i);p=ne(i),l.x=u.x+i.clientLeft,l.y=u.y+i.clientTop}let h=s&&!d&&!r?Dt(s,c):O(0);return{width:n.width*p.x,height:n.height*p.y,x:n.x*p.x-c.scrollLeft*p.x+l.x+h.x,y:n.y*p.y-c.scrollTop*p.y+l.y+h.y}}function Wn(t){return Array.from(t.getClientRects())}function Kn(t){let e=R(t),n=he(t),i=t.ownerDocument.body,o=q(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),r=q(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight),s=-n.scrollLeft+Me(t),a=-n.scrollTop;return H(i).direction==="rtl"&&(s+=q(e.clientWidth,i.clientWidth)-o),{width:o,height:r,x:s,y:a}}var It=25;function Zn(t,e){let n=A(t),i=R(t),o=n.visualViewport,r=i.clientWidth,s=i.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=Ce();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let p=Me(i);if(p<=0){let l=i.ownerDocument,d=l.body,h=getComputedStyle(d),u=l.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,f=Math.abs(i.clientWidth-d.clientWidth-u);f<=It&&(r-=f)}else p<=It&&(r+=p);return{width:r,height:s,x:a,y:c}}var Qn=new Set(["absolute","fixed"]);function Gn(t,e){let n=fe(t,!0,e==="fixed"),i=n.top+t.clientTop,o=n.left+t.clientLeft,r=$(t)?ne(t):O(1),s=t.clientWidth*r.x,a=t.clientHeight*r.y,c=o*r.x,p=i*r.y;return{width:s,height:a,x:c,y:p}}function Rt(t,e,n){let i;if(e==="viewport")i=Zn(t,n);else if(e==="document")i=Kn(R(t));else if(M(e))i=Gn(e,n);else{let o=Nt(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(i)}function zt(t,e){let n=D(t);return n===e||!M(n)||X(n)?!1:H(n).position==="fixed"||zt(n,e)}function Jn(t,e){let n=e.get(t);if(n)return n;let i=Se(t,[],!1).filter(a=>M(a)&&J(a)!=="body"),o=null,r=H(t).position==="fixed",s=r?D(t):t;for(;M(s)&&!X(s);){let a=H(s),c=Te(s);!c&&a.position==="fixed"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Qn.has(o.position)||te(s)&&!c&&zt(t,s))?i=i.filter(l=>l!==s):o=a,s=D(s)}return e.set(t,i),i}function Xn(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t,s=[...n==="clippingAncestors"?ue(e)?[]:Jn(e,this._c):[].concat(n),i],a=s[0],c=s.reduce((p,l)=>{let d=Rt(e,l,o);return p.top=q(d.top,p.top),p.right=le(d.right,p.right),p.bottom=le(d.bottom,p.bottom),p.left=q(d.left,p.left),p},Rt(e,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Yn(t){let{width:e,height:n}=Bt(t);return{width:e,height:n}}function ei(t,e,n){let i=$(e),o=R(e),r=n==="fixed",s=fe(t,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function p(){c.x=Me(o)}if(i||!i&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),i){let u=fe(e,!0,r,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else o&&p();r&&!i&&o&&p();let l=o&&!i&&!r?Dt(o,a):O(0),d=s.left+a.scrollLeft-c.x-l.x,h=s.top+a.scrollTop-c.y-l.y;return{x:d,y:h,width:s.width,height:s.height}}function De(t){return H(t).position==="static"}function _t(t,e){if(!$(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return R(t)===n&&(n=n.ownerDocument.body),n}function jt(t,e){let n=A(t);if(ue(t))return n;if(!$(t)){let o=D(t);for(;o&&!X(o);){if(M(o)&&!De(o))return o;o=D(o)}return n}let i=_t(t,e);for(;i&&Pt(i)&&De(i);)i=_t(i,e);return i&&X(i)&&De(i)&&!Te(i)?n:i||Ot(t)||n}var ti=async function(t){let e=this.getOffsetParent||jt,n=this.getDimensions,i=await n(t.floating);return{reference:ei(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function ni(t){return H(t).direction==="rtl"}var ii={convertOffsetParentRelativeRectToViewportRelativeRect:qn,getDocumentElement:R,getClippingRect:Xn,getOffsetParent:jt,getElementRects:ti,getClientRects:Wn,getDimensions:Yn,getScale:ne,isElement:M,isRTL:ni};var Vt=Ct;var Ut=At,qt=Tt;var Wt=(t,e,n)=>{let i=new Map,o={platform:ii,...n},r={...o.platform,_c:i};return Et(t,e,{...o,platform:r})};var He=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=` `,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,i=this.findLinkAtPosition(n,e);i?(!this.currentLink||this.currentLink.url!==i.url||this.currentLink.index!==i.index)&&this.show(i):this.scheduleHide()}findLinkAtPosition(e,n){let i=/\[([^\]]+)\]\(([^)]+)\)/g,o,r=0;for(;(o=i.exec(e))!==null;){let s=o.index,a=o.index+o[0].length;if(n>=s&&n<=a)return{text:o[1],url:o[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 i=n.getBoundingClientRect();if(!(i.width===0||i.height===0))try{let{x:o,y:r}=await Wt(n,this.tooltip,{strategy:"fixed",placement:"bottom",middleware:[Vt(8),Ut({padding:8}),qt()]});Object.assign(this.tooltip.style,{left:`${o}px`,top:`${r}px`,position:"fixed"})}catch(o){console.warn("Floating UI positioning failed:",o)}}findAnchorElement(e){return this.editor.preview.querySelector(`a[style*="--link-${e}"]`)}hide(){this.tooltip.classList.remove("visible"),this.currentLink=null,this.isTooltipHovered=!1}scheduleHide(){this.cancelHide(),this.hideTimeout=setTimeout(()=>this.hide(),300)}cancelHide(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}destroy(){this.cancelHide(),this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.tooltip&&this.tooltip.parentNode&&this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null,this.currentLink=null,this.isTooltipHovered=!1}};var Kt=` `,Zt=` `,Qt=` `,Gt=` `,Jt=` `,Xt=` `,Yt=` `,en=` `,tn=` `,nn=` `,on=` `,rn=` `,sn=` `;var S={bold:{name:"bold",actionId:"toggleBold",icon:Kt,title:"Bold (Ctrl+B)",action:({editor:t})=>{rt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},italic:{name:"italic",actionId:"toggleItalic",icon:Zt,title:"Italic (Ctrl+I)",action:({editor:t})=>{st(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},code:{name:"code",actionId:"toggleCode",icon:Yt,title:"Inline Code",action:({editor:t})=>{at(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},separator:{name:"separator"},link:{name:"link",actionId:"insertLink",icon:Xt,title:"Insert Link",action:({editor:t})=>{lt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h1:{name:"h1",actionId:"toggleH1",icon:Qt,title:"Heading 1",action:({editor:t})=>{ut(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h2:{name:"h2",actionId:"toggleH2",icon:Gt,title:"Heading 2",action:({editor:t})=>{ht(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},h3:{name:"h3",actionId:"toggleH3",icon:Jt,title:"Heading 3",action:({editor:t})=>{ft(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},bulletList:{name:"bulletList",actionId:"toggleBulletList",icon:en,title:"Bullet List",action:({editor:t})=>{ct(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},orderedList:{name:"orderedList",actionId:"toggleNumberedList",icon:tn,title:"Numbered List",action:({editor:t})=>{pt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},taskList:{name:"taskList",actionId:"toggleTaskList",icon:on,title:"Task List",action:({editor:t})=>{Ie&&(Ie(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0})))}},quote:{name:"quote",actionId:"toggleQuote",icon:nn,title:"Quote",action:({editor:t})=>{dt(t.textarea),t.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}},upload:{name:"upload",actionId:"uploadFile",icon:rn,title:"Upload File",action:({editor:t})=>{var n,i;if(!((n=t.options.fileUpload)!=null&&n.enabled))return;let e=document.createElement("input");e.type="file",e.multiple=!0,((i=t.options.fileUpload.mimeTypes)==null?void 0:i.length)>0&&(e.accept=t.options.fileUpload.mimeTypes.join(",")),e.onchange=()=>{var r;if(!((r=e.files)!=null&&r.length))return;let o=new DataTransfer;for(let s of e.files)o.items.add(s);t._handleDataTransfer(o)},e.click()}},viewMode:{name:"viewMode",icon:sn,title:"View mode"}},ie=[S.bold,S.italic,S.code,S.separator,S.link,S.separator,S.h1,S.h2,S.h3,S.separator,S.bulletList,S.orderedList,S.taskList,S.separator,S.quote,S.separator,S.viewMode];function ze(t){let e={};return(t||[]).forEach(n=>{if(!n||n.name==="separator")return;let i=n.actionId||n.name;n.action&&(e[i]=n.action)}),e}function an(t){let e=t||ie;return Array.isArray(e)?e.map(n=>({name:(n==null?void 0:n.name)||null,actionId:(n==null?void 0:n.actionId)||(n==null?void 0:n.name)||null,icon:(n==null?void 0:n.icon)||null,title:(n==null?void 0:n.title)||null})):null}function ri(t,e){let n=an(t),i=an(e);if(n===null||i===null)return n!==i;if(n.length!==i.length)return!0;for(let o=0;o{if(r.overTypeInstance)return r.overTypeInstance.reinit(n),r.overTypeInstance;let s=Object.create(v.prototype);return s._init(r,n),r.overTypeInstance=s,v.instances.set(r,s),s})}_init(e,n={}){this.element=e,this.instanceTheme=n.theme||null,this.options=this._mergeOptions(n),this.instanceId=++v.instanceCount,this.initialized=!1,v.injectStyles(),v.initGlobalListeners();let i=e.querySelector(".overtype-container"),o=e.querySelector(".overtype-wrapper");i||o?this._recoverFromDOM(i,o):this._buildFromScratch(),this.instanceTheme==="auto"&&this.setTheme("auto"),this.shortcuts=new re(this),this._rebuildActionsMap(),this.linkTooltip=new He(this),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft})}),this.initialized=!0,this.options.onChange&&this.options.onChange(this.getValue(),this)}_mergeOptions(e){let n={fontSize:"14px",lineHeight:1.6,fontFamily:'"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:"16px",mobile:{fontSize:"16px",padding:"12px",lineHeight:1.5},textareaProps:{},autofocus:!1,autoResize:!1,minHeight:"100px",maxHeight:null,placeholder:"Start typing...",value:"",onChange:null,onKeydown:null,onRender:null,showActiveLineRaw:!1,showStats:!1,toolbar:!1,toolbarButtons:null,statsFormatter:null,smartLists:!0,codeHighlighter:null,spellcheck:!1},{theme:i,colors:o,...r}=e;return{...n,...r}}_recoverFromDOM(e,n){if(e&&e.classList.contains("overtype-container"))this.container=e,this.wrapper=e.querySelector(".overtype-wrapper");else if(n){this.wrapper=n,this.container=document.createElement("div"),this.container.className="overtype-container";let i=this.instanceTheme||v.currentTheme||_,o=typeof i=="string"?i:i.name;if(o&&this.container.setAttribute("data-theme",o),this.instanceTheme){let r=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(r&&r.colors){let s=Q(r.colors);this.container.style.cssText+=s}}n.parentNode.insertBefore(this.container,n),this.container.appendChild(n)}if(!this.wrapper){e&&e.remove(),n&&n.remove(),this._buildFromScratch();return}if(this.textarea=this.wrapper.querySelector(".overtype-input"),this.preview=this.wrapper.querySelector(".overtype-preview"),!this.textarea||!this.preview){this.container.remove(),this._buildFromScratch();return}this.wrapper._instance=this,this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this._configureTextarea(),this._applyOptions()}_buildFromScratch(){let e=this._extractContent();this.element.innerHTML="",this._createDOM(),(e||this.options.value)&&this.setValue(e||this.options.value),this._applyOptions()}_extractContent(){let e=this.element.querySelector(".overtype-input");return e?e.value:this.element.textContent||""}_createDOM(){this.container=document.createElement("div"),this.container.className="overtype-container";let e=this.instanceTheme||v.currentTheme||_,n=typeof e=="string"?e:e.name;if(n&&this.container.setAttribute("data-theme",n),this.instanceTheme){let i=typeof this.instanceTheme=="string"?V(this.instanceTheme):this.instanceTheme;if(i&&i.colors){let o=Q(i.colors);this.container.style.cssText+=o}}this.wrapper=document.createElement("div"),this.wrapper.className="overtype-wrapper",this.options.fontSize&&this.wrapper.style.setProperty("--instance-font-size",this.options.fontSize),this.options.lineHeight&&this.wrapper.style.setProperty("--instance-line-height",String(this.options.lineHeight)),this.options.padding&&this.wrapper.style.setProperty("--instance-padding",this.options.padding),this.wrapper._instance=this,this.textarea=document.createElement("textarea"),this.textarea.className="overtype-input",this.textarea.placeholder=this.options.placeholder,this._configureTextarea(),this.options.textareaProps&&Object.entries(this.options.textareaProps).forEach(([i,o])=>{i==="className"||i==="class"?this.textarea.className+=" "+o:i==="style"&&typeof o=="object"?Object.assign(this.textarea.style,o):this.textarea.setAttribute(i,o)}),this.preview=document.createElement("div"),this.preview.className="overtype-preview",this.preview.setAttribute("aria-hidden","true"),this.placeholderEl=document.createElement("div"),this.placeholderEl.className="overtype-placeholder",this.placeholderEl.setAttribute("aria-hidden","true"),this.placeholderEl.textContent=this.options.placeholder,this.wrapper.appendChild(this.textarea),this.wrapper.appendChild(this.preview),this.wrapper.appendChild(this.placeholderEl),this.container.appendChild(this.wrapper),this.options.showStats&&(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()),this.element.appendChild(this.container),this.options.autoResize?this._setupAutoResize():this.container.classList.remove("overtype-auto-resize")}_configureTextarea(){this.textarea.setAttribute("autocomplete","off"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck",String(this.options.spellcheck)),this.textarea.setAttribute("data-gramm","false"),this.textarea.setAttribute("data-gramm_editor","false"),this.textarea.setAttribute("data-enable-grammarly","false")}_createToolbar(){var n;let e=this.options.toolbarButtons||ie;if((n=this.options.fileUpload)!=null&&n.enabled&&!e.some(i=>(i==null?void 0:i.name)==="upload")){let i=e.findIndex(o=>(o==null?void 0:o.name)==="viewMode");i!==-1?(e=[...e],e.splice(i,0,S.separator,S.upload)):e=[...e,S.separator,S.upload]}this.toolbar=new ke(this,{toolbarButtons:e}),this.toolbar.create(),this._toolbarSelectionListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this._toolbarInputListener=()=>{this.toolbar&&this.toolbar.updateButtonStates()},this.textarea.addEventListener("selectionchange",this._toolbarSelectionListener),this.textarea.addEventListener("input",this._toolbarInputListener)}_cleanupToolbarListeners(){this._toolbarSelectionListener&&(this.textarea.removeEventListener("selectionchange",this._toolbarSelectionListener),this._toolbarSelectionListener=null),this._toolbarInputListener&&(this.textarea.removeEventListener("input",this._toolbarInputListener),this._toolbarInputListener=null)}_rebuildActionsMap(){var e;this.actionsById=ze(ie),this.options.toolbarButtons&&Object.assign(this.actionsById,ze(this.options.toolbarButtons)),(e=this.options.fileUpload)!=null&&e.enabled&&Object.assign(this.actionsById,ze([S.upload]))}_applyOptions(){this.options.autofocus&&this.textarea.focus(),this.options.autoResize?this.container.classList.contains("overtype-auto-resize")?this._updateAutoHeight():this._setupAutoResize():this.container.classList.remove("overtype-auto-resize"),this.options.toolbar&&!this.toolbar?this._createToolbar():!this.options.toolbar&&this.toolbar&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null),this.placeholderEl&&(this.placeholderEl.textContent=this.options.placeholder),this.options.fileUpload&&!this.fileUploadInitialized?this._initFileUpload():!this.options.fileUpload&&this.fileUploadInitialized&&this._destroyFileUpload(),this.updatePreview()}_initFileUpload(){let e=this.options.fileUpload;if(!(!e||!e.enabled)){if(e.maxSize=e.maxSize||10*1024*1024,e.mimeTypes=e.mimeTypes||[],e.batch=e.batch||!1,!e.onInsertFile||typeof e.onInsertFile!="function"){console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");return}this._fileUploadCounter=0,this._boundHandleFilePaste=this._handleFilePaste.bind(this),this._boundHandleFileDrop=this._handleFileDrop.bind(this),this._boundHandleDragOver=this._handleDragOver.bind(this),this.textarea.addEventListener("paste",this._boundHandleFilePaste),this.textarea.addEventListener("drop",this._boundHandleFileDrop),this.textarea.addEventListener("dragover",this._boundHandleDragOver),this.fileUploadInitialized=!0}}_handleFilePaste(e){var n,i;(i=(n=e==null?void 0:e.clipboardData)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.clipboardData))}_handleFileDrop(e){var n,i;(i=(n=e==null?void 0:e.dataTransfer)==null?void 0:n.files)!=null&&i.length&&(e.preventDefault(),this._handleDataTransfer(e.dataTransfer))}_handleDataTransfer(e){let n=[];for(let i of e.files){if(i.size>this.options.fileUpload.maxSize||this.options.fileUpload.mimeTypes.length>0&&!this.options.fileUpload.mimeTypes.includes(i.type))continue;let o=++this._fileUploadCounter,s=`${i.type.startsWith("image/")?"!":""}[Uploading ${i.name} (#${o})...]()`;if(this.insertAtCursor(`${s} `),this.options.fileUpload.batch){n.push({file:i,placeholder:s});continue}this.options.fileUpload.onInsertFile(i).then(a=>{this.textarea.value=this.textarea.value.replace(s,a),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},a=>{console.error("OverType: File upload failed",a),this.textarea.value=this.textarea.value.replace(s,"[Upload failed]()"),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}this.options.fileUpload.batch&&n.length>0&&this.options.fileUpload.onInsertFile(n.map(i=>i.file)).then(i=>{(Array.isArray(i)?i:[i]).forEach((r,s)=>{this.textarea.value=this.textarea.value.replace(n[s].placeholder,r)}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))},i=>{console.error("OverType: File upload failed",i),n.forEach(({placeholder:o})=>{this.textarea.value=this.textarea.value.replace(o,"[Upload failed]()")}),this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))})}_handleDragOver(e){e.preventDefault()}_destroyFileUpload(){this.textarea.removeEventListener("paste",this._boundHandleFilePaste),this.textarea.removeEventListener("drop",this._boundHandleFileDrop),this.textarea.removeEventListener("dragover",this._boundHandleDragOver),this._boundHandleFilePaste=null,this._boundHandleFileDrop=null,this._boundHandleDragOver=null,this.fileUploadInitialized=!1}insertAtCursor(e){let n=this.textarea.selectionStart,i=this.textarea.selectionEnd,o=!1;try{o=document.execCommand("insertText",!1,e)}catch(r){}if(!o){let r=this.textarea.value.slice(0,n),s=this.textarea.value.slice(i);this.textarea.value=r+e+s,this.textarea.setSelectionRange(n+e.length,n+e.length)}this.textarea.dispatchEvent(new Event("input",{bubbles:!0}))}updatePreview(){let e=this.textarea.value,n=this.textarea.selectionStart,i=this._getCurrentLine(e,n),o=this.container.dataset.mode==="preview",r=T.parse(e,i,this.options.showActiveLineRaw,this.options.codeHighlighter,o);this.preview.innerHTML=r,this.placeholderEl&&(this.placeholderEl.style.display=e?"none":""),this._applyCodeBlockBackgrounds(),this.options.showStats&&this.statsBar&&this._updateStats(),this.options.onChange&&this.initialized&&this.options.onChange(e,this),this.options.onRender&&this.options.onRender(this.preview,o?"preview":"normal",this)}_applyCodeBlockBackgrounds(){let e=this.preview.querySelectorAll(".code-fence");for(let n=0;nd.replace(/^ /,"")).join(` `);document.execCommand?(this.textarea.setSelectionRange(i,o),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=i,this.textarea.selectionEnd=i+l.length)}else if(i!==o){let s=r.substring(0,i),a=r.substring(i,o),c=r.substring(o),l=a.split(` `).map(d=>" "+d).join(` `);document.execCommand?(this.textarea.setSelectionRange(i,o),document.execCommand("insertText",!1,l)):(this.textarea.value=s+l+c,this.textarea.selectionStart=i,this.textarea.selectionEnd=i+l.length)}else document.execCommand?document.execCommand("insertText",!1," "):(this.textarea.value=r.substring(0,i)+" "+r.substring(o),this.textarea.selectionStart=this.textarea.selectionEnd=i+2);this.textarea.dispatchEvent(new Event("input",{bubbles:!0}));return}if(e.key==="Enter"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&this.options.smartLists&&this.handleSmartListContinuation()){e.preventDefault();return}!this.shortcuts.handleKeydown(e)&&this.options.onKeydown&&this.options.onKeydown(e,this)}handleSmartListContinuation(){let e=this.textarea,n=e.selectionStart,i=T.getListContext(e.value,n);return!i||!i.inList?!1:i.content.trim()===""&&n>=i.markerEndPos?(this.deleteListMarker(i),!0):(n>i.markerEndPos&&n{this.updateNumberedLists()},10)}updateNumberedLists(){let e=this.textarea.value,n=this.textarea.selectionStart,i=T.renumberLists(e);if(i!==e){let o=0,r=e.split(` `),s=i.split(` `),a=0;for(let p=0;pthis.getValue(),setValue:s=>this.setValue(s),event:n}),!0}catch(s){return console.error(`OverType: Action "${e}" error:`,s),this.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{actionId:e,error:s}})),!1}}getRenderedHTML(e={}){let n=this.getValue(),i=T.parse(n,-1,!1,this.options.codeHighlighter);return e.cleanHTML&&(i=i.replace(/.*?<\/span>/g,""),i=i.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g,""),i=i.replace(/\sclass=""/g,"")),i}getPreviewHTML(){return this.preview.innerHTML}getCleanHTML(){return this.getRenderedHTML({cleanHTML:!0})}focus(){this.textarea.focus()}blur(){this.textarea.blur()}isInitialized(){return this.initialized}reinit(e={}){var o;let n=(o=this.options)==null?void 0:o.toolbarButtons;this.options=this._mergeOptions({...this.options,...e});let i=this.toolbar&&this.options.toolbar&&ri(n,this.options.toolbarButtons);this._rebuildActionsMap(),i&&(this._cleanupToolbarListeners(),this.toolbar.destroy(),this.toolbar=null,this._createToolbar()),this.fileUploadInitialized&&this._destroyFileUpload(),this.options.fileUpload&&this._initFileUpload(),this._applyOptions(),this.updatePreview()}showToolbar(){this.toolbar?this.toolbar.show():this._createToolbar()}hideToolbar(){this.toolbar&&this.toolbar.hide()}setTheme(e){if(v._autoInstances.delete(this),this.instanceTheme=e,e==="auto")v._autoInstances.add(this),v._startAutoListener(),this._applyResolvedTheme(Oe("auto"));else{let n=typeof e=="string"?V(e):e,i=typeof n=="string"?n:n.name;if(i&&this.container.setAttribute("data-theme",i),n&&n.colors){let o=Q(n.colors,n.previewColors);this.container.style.cssText+=o}this.updatePreview()}return v._stopAutoListener(),this}_applyResolvedTheme(e){let n=V(e);this.container.setAttribute("data-theme",e),n&&n.colors&&(this.container.style.cssText=Q(n.colors,n.previewColors)),this.updatePreview()}setCodeHighlighter(e){this.options.codeHighlighter=e,this.updatePreview()}_updateStats(){if(!this.statsBar)return;let e=this.textarea.value,n=e.split(` `),i=e.length,o=e.split(/\s+/).filter(l=>l.length>0).length,r=this.textarea.selectionStart,a=e.substring(0,r).split(` `),c=a.length,p=a[a.length-1].length+1;this.options.statsFormatter?this.statsBar.innerHTML=this.options.statsFormatter({chars:i,words:o,lines:n.length,line:c,column:p}):this.statsBar.innerHTML=`
    ${i} chars, ${o} words, ${n.length} lines
    Line ${c}, Col ${p}
    `}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,n=this.preview,i=this.wrapper;if(this.container.dataset.mode==="preview"){i.style.removeProperty("height"),n.style.removeProperty("height"),n.style.removeProperty("overflow-y"),e.style.removeProperty("height"),e.style.removeProperty("overflow-y");return}let r=e.scrollTop;i.style.setProperty("height","auto","important"),e.style.setProperty("height","auto","important");let s=e.scrollHeight;if(this.options.minHeight){let p=parseInt(this.options.minHeight);s=Math.max(s,p)}let a="hidden";if(this.options.maxHeight){let p=parseInt(this.options.maxHeight);s>p&&(s=p,a="auto")}let c=s+"px";e.style.setProperty("height",c,"important"),e.style.setProperty("overflow-y",a,"important"),n.style.setProperty("height",c,"important"),n.style.setProperty("overflow-y",a,"important"),i.style.setProperty("height",c,"important"),e.scrollTop=r,n.scrollTop=r,this.previousHeight!==s&&(this.previousHeight=s)}showStats(e){this.options.showStats=e,e&&!this.statsBar?(this.statsBar=document.createElement("div"),this.statsBar.className="overtype-stats",this.container.appendChild(this.statsBar),this._updateStats()):e&&this.statsBar?this._updateStats():!e&&this.statsBar&&(this.statsBar.remove(),this.statsBar=null)}showNormalEditMode(){return this.container.dataset.mode="normal",this.updatePreview(),this._updateAutoHeight(),requestAnimationFrame(()=>{this.textarea.scrollTop=this.preview.scrollTop,this.textarea.scrollLeft=this.preview.scrollLeft}),this}showPlainTextarea(){if(this.container.dataset.mode="plain",this._updateAutoHeight(),this.toolbar){let e=this.container.querySelector('[data-action="proxy.php?url=toggle-plain"]');e&&(e.classList.remove("active"),e.title="Show markdown preview")}return this}showPreviewMode(){return this.container.dataset.mode="preview",this.updatePreview(),this._updateAutoHeight(),this}destroy(){if(v._autoInstances.delete(this),v._stopAutoListener(),this.fileUploadInitialized&&this._destroyFileUpload(),this.element.overTypeInstance=null,v.instances.delete(this.element),this.shortcuts&&this.shortcuts.destroy(),this.wrapper){let e=this.getValue();this.wrapper.remove(),this.element.textContent=e}this.initialized=!1}static init(e,n={}){return new v(e,n)}static initFromData(e,n={}){let i=document.querySelectorAll(e);return Array.from(i).map(o=>{let r={...n};for(let s of o.attributes)if(s.name.startsWith("data-ot-")){let c=s.name.slice(8).replace(/-([a-z])/g,(p,l)=>l.toUpperCase());r[c]=v._parseDataValue(s.value)}return new v(o,r)[0]})}static _parseDataValue(e){return e==="true"?!0:e==="false"?!1:e==="null"?null:e!==""&&!isNaN(Number(e))?Number(e):e}static getInstance(e){return e.overTypeInstance||v.instances.get(e)||null}static destroyAll(){document.querySelectorAll("[data-overtype-instance]").forEach(n=>{let i=v.getInstance(n);i&&i.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let n=document.querySelector("style.overtype-styles");n&&n.remove();let i=v.currentTheme||_,o=Ze({theme:i}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,n=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=n,v._startAutoListener(),v._applyGlobalTheme(Oe("auto"),n);return}v._stopAutoListener(),v._applyGlobalTheme(e,n)}static _applyGlobalTheme(e,n=null){let i=typeof e=="string"?V(e):e;n&&(i=Ke(i,n)),v.currentTheme=i,v.injectStyles(!0);let o=typeof i=="string"?i:i.name;document.querySelectorAll(".overtype-container").forEach(r=>{o&&r.setAttribute("data-theme",o)}),document.querySelectorAll(".overtype-wrapper").forEach(r=>{r.closest(".overtype-container")||o&&r.setAttribute("data-theme",o);let s=r._instance;s&&s.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(r=>{o&&typeof r.setAttribute=="function"&&r.setAttribute("theme",o),typeof r.refreshTheme=="function"&&r.refreshTheme()})}static _startAutoListener(){v._autoMediaQuery||window.matchMedia&&(v._autoMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),v._autoMediaListener=e=>{let n=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(n,v._globalAutoCustomColors),v._autoInstances.forEach(i=>i._applyResolvedTheme(n))},v._autoMediaQuery.addEventListener("change",v._autoMediaListener))}static _stopAutoListener(){v._autoInstances.size>0||v._globalAutoTheme||v._autoMediaQuery&&(v._autoMediaQuery.removeEventListener("change",v._autoMediaListener),v._autoMediaQuery=null,v._autoMediaListener=null)}static setCodeHighlighter(e){T.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let i=n._instance;i&&i.updatePreview&&i.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let i=n.getEditor();i&&i.updatePreview&&i.updatePreview()}})}static setCustomSyntax(e){T.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(n=>{let i=n._instance;i&&i.updatePreview&&i.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(n=>{if(typeof n.getEditor=="function"){let i=n.getEditor();i&&i.updatePreview&&i.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),i=n==null?void 0:n._instance;i&&i.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),i=n==null?void 0:n._instance;i&&i.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let n=e.target.closest(".overtype-wrapper"),i=n==null?void 0:n._instance;i&&i.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let n=document.activeElement;if(n&&n.classList.contains("overtype-input")){let i=n.closest(".overtype-wrapper"),o=i==null?void 0:i._instance;o&&(o.options.showStats&&o.statsBar&&o._updateStats(),clearTimeout(o._selectionTimeout),o._selectionTimeout=setTimeout(()=>{o.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};C(v,"instances",new WeakMap),C(v,"stylesInjected",!1),C(v,"globalListenersInitialized",!1),C(v,"instanceCount",0),C(v,"_autoMediaQuery",null),C(v,"_autoMediaListener",null),C(v,"_autoInstances",new Set),C(v,"_globalAutoTheme",!1),C(v,"_globalAutoCustomColors",null);var z=v;z.MarkdownParser=T;z.ShortcutsManager=re;z.themes={solar:_,cave:V("cave")};z.getTheme=V;z.currentTheme=_;var si=z;return mn(ai);})(); /** * OverType - A lightweight markdown editor library with perfect WYSIWYG alignment * @version 1.0.0 * @license MIT */ if (typeof window !== "undefined" && typeof window.document !== "undefined") { // Extract exports BEFORE reassigning OverType (var OverType is window.OverType) window.toolbarButtons = OverType.toolbarButtons; window.defaultToolbarButtons = OverType.defaultToolbarButtons; window.OverType = OverType.default ? OverType.default : OverType; }