overtype 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.3.3
2
+ * OverType v2.3.4
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -675,6 +675,11 @@ var OverTypeEditor=(()=>{var ve=Object.defineProperty;var di=Object.getOwnProper
675
675
  cursor: text !important;
676
676
  }
677
677
 
678
+ .overtype-container.overtype-auto-resize[data-mode="preview"] .overtype-preview {
679
+ position: static !important;
680
+ height: auto !important;
681
+ }
682
+
678
683
  /* Hide syntax markers in preview mode */
679
684
  .overtype-container[data-mode="preview"] .syntax-marker {
680
685
  display: none !important;
@@ -892,10 +897,10 @@ ${a}`:r;if(p){let k=i.value[i.selectionStart-1];i.selectionStart!==0&&k!=null&&!
892
897
  `),t="- ",n=e.every(r=>r.startsWith(t)),o=e;return n&&(o=e.map(r=>r.slice(t.length))),{text:o.join(`
893
898
  `),processed:n}}function re(i,e){return e?"- ":`${i+1}. `}function Ci(i,e){let t,n,o;return i.orderedList?(t=et(e),n=tt(t.text),o=n.text):(t=tt(e),n=et(t.text),o=n.text),[t,n,o]}function Ai(i,e){let t=i.selectionStart===i.selectionEnd,n=i.selectionStart,o=i.selectionEnd;nt(i);let r=i.value.slice(i.selectionStart,i.selectionEnd),[s,a,c]=Ci(e,r),p=c.split(`
894
899
  `).map((m,g)=>`${re(g,e.unorderedList)}${m}`),l=p.reduce((m,g,y)=>m+re(y,e.unorderedList).length,0),d=p.reduce((m,g,y)=>m+re(y,!e.unorderedList).length,0);if(s.processed)return t?(n=Math.max(n-re(0,e.unorderedList).length,0),o=n):(n=i.selectionStart,o=i.selectionEnd-l),{text:c,selectionStart:n,selectionEnd:o};let{newlinesToAppend:u,newlinesToPrepend:h}=Re(i),f=u+p.join(`
895
- `)+h;return t?(n=Math.max(n+re(0,e.unorderedList).length+u.length,0),o=n):a.processed?(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l-d):(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l),{text:f,selectionStart:n,selectionEnd:o}}function rt(i,e){let t=xe(i,n=>Ai(n,e),{adjustSelection:(n,o,r,s)=>{let a=i.value.slice(s,i.selectionEnd),c=/^\d+\.\s+/,p=/^- /,l=c.test(a),d=p.test(a),u=e.orderedList&&l||e.unorderedList&&d;if(o===r)if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:o+h}}else if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:r+h}}}});V(i,t)}function Ti(i){if(!i)return[];let e=[],{selectionStart:t,selectionEnd:n,value:o}=i,r=o.split(`
900
+ `)+h;return t?(n=Math.max(n+re(0,e.unorderedList).length+u.length,0),o=n):a.processed?(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l-d):(n=Math.max(i.selectionStart+u.length,0),o=i.selectionEnd+u.length+l),{text:f,selectionStart:n,selectionEnd:o}}function rt(i,e){let t=xe(i,n=>Ai(n,e),{adjustSelection:(n,o,r,s)=>{let a=i.value.slice(s,i.selectionEnd),c=/^\d+\.\s+/,p=/^- /,l=c.test(a),d=p.test(a),u=e.orderedList&&l||e.unorderedList&&d;if(o===r)if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:o+h}}else if(u){let h=a.match(e.orderedList?c:p),f=h?h[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||d){let h=a.match(l?c:p),f=h?h[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let h=e.unorderedList?2:3;return{start:o+h,end:r+h}}}});V(i,t)}function _i(i){if(!i)return[];let e=[],{selectionStart:t,selectionEnd:n,value:o}=i,r=o.split(`
896
901
  `),s=0,a="";for(let d of r){if(t>=s&&t<=s+d.length){a=d;break}s+=d.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,t-10),p=Math.min(o.length,n+10),l=o.slice(c,p);if(l.includes("**")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("**"),f=u.indexOf("**");h!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("_"),f=u.indexOf("_");h!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100));d.includes("`")&&u.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let d=o.slice(Math.max(0,t-100),t),u=o.slice(n,Math.min(o.length,n+100)),h=d.lastIndexOf("["),f=u.indexOf("]");h!==-1&&f!==-1&&o.slice(n+f+1,n+f+10).startsWith("(")&&e.push("link")}return e}function st(i){if(!i||i.disabled||i.readOnly)return;x("toggleBold","Starting"),be(i,"Before");let e=F(R.bold),t=ke(i,e);it(t),V(i,t),be(i,"After")}function at(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.italic),t=ke(i,e);V(i,t)}function lt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.code),t=ke(i,e);V(i,t)}function ct(i,e={}){if(!i||i.disabled||i.readOnly)return;let t=i.value.slice(i.selectionStart,i.selectionEnd),n=F(R.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(n.suffix=`](${t})`,n.replaceNext=""):e.url&&(n.suffix=`](${e.url})`,n.replaceNext=""),e.text&&!t){let s=i.selectionStart;i.value=i.value.slice(0,s)+e.text+i.value.slice(s),i.selectionStart=s,i.selectionEnd=s+e.text.length}let r=ke(i,n);V(i,r)}function pt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.bulletList);rt(i,e)}function dt(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.numberedList);rt(i,e)}function ht(i){if(!i||i.disabled||i.readOnly)return;x("toggleQuote","Starting"),be(i,"Initial");let e=F(R.quote),t=xe(i,n=>ot(n,e),{prefix:e.prefix});it(t),V(i,t),be(i,"Final")}function Ie(i){if(!i||i.disabled||i.readOnly)return;let e=F(R.taskList),t=xe(i,n=>ot(n,e),{prefix:e.prefix});V(i,t)}function Be(i,e=1,t=!1){if(!i||i.disabled||i.readOnly)return;(e<1||e>6)&&(e=1),x("insertHeader","============ START ============"),x("insertHeader",`Level: ${e}, Toggle: ${t}`),x("insertHeader",`Initial cursor: ${i.selectionStart}-${i.selectionEnd}`);let n=`header${e===1?"1":e}`,o=F(R[n]||R.header1);x("insertHeader",`Style prefix: "${o.prefix}"`);let r=i.value,s=i.selectionStart,a=i.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
897
902
  `;)c--;let p=a;for(;p<r.length&&r[p]!==`
898
- `;)p++;let l=r.slice(c,p);x("insertHeader",`Current line (before): "${l}"`);let d=l.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=t&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${u}, level=${e})`);let m=xe(i,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let b=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${b}"`);let w;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),w=b):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),w=o.prefix+b):(x("insertHeader","ACTION: Adding new header"),w=o.prefix+b),x("insertHeader",`New line: "${w}"`),{text:w,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,y,b,w)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${b}`),x("insertHeader",` - lineStartPos: ${w}`),f){let S=Math.max(y-h,w);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:S,end:y===b?S:Math.max(b-h,w)}}else if(h>0){let S=o.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${S}`),{start:y+S,end:b+S}}else return x("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:y+o.prefix.length,end:b+o.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),V(i,m)}function ut(i){Be(i,1,!0)}function ft(i){Be(i,2,!0)}function mt(i){Be(i,3,!0)}function gt(i){return Ti(i)}var Se=class{constructor(e,t={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=t.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let t=this.createSeparator();this.container.appendChild(t)}else{let t=this.createButton(e);this.buttons[e.name]=t,this.container.appendChild(t)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.setAttribute("data-button",e.name),t.title=e.title||"",t.setAttribute("aria-label",e.title||e.name),t.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(t.classList.add("has-dropdown"),t.dataset.dropdown="true",t.addEventListener("click",n=>{n.preventDefault(),this.toggleViewModeDropdown(t)}),t):(t._clickHandler=n=>{n.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,n)},t.addEventListener("click",t._clickHandler),t)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:t=>this.editor.setValue(t),event:null}),!0}catch(t){return console.error(`Action "${e.name}" error:`,t),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:t}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let n=this.createViewModeDropdown(e),o=e.getBoundingClientRect();n.style.position="absolute",n.style.top=`${o.bottom+5}px`,n.style.left=`${o.left}px`,document.body.appendChild(n),this.handleDocumentClick=r=>{!n.contains(r.target)&&!e.contains(r.target)&&(n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let t=document.createElement("div");t.className="overtype-dropdown-menu";let n=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],o=this.editor.container.dataset.mode||"normal";return n.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===o){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),t.appendChild(s)}),t}updateButtonStates(){var e;try{let t=((e=gt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,o])=>{if(n==="viewMode")return;let r=!1;switch(n){case"bold":r=t.includes("bold");break;case"italic":r=t.includes("italic");break;case"code":r=!1;break;case"bulletList":r=t.includes("bullet-list");break;case"orderedList":r=t.includes("numbered-list");break;case"taskList":r=t.includes("task-list");break;case"quote":r=t.includes("quote");break;case"h1":r=t.includes("header");break;case"h2":r=t.includes("header-2");break;case"h3":r=t.includes("header-3");break}o.classList.toggle("active",r),o.setAttribute("aria-pressed",r.toString())})}catch(t){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var ae=Math.min,U=Math.max,le=Math.round;var O=i=>({x:i,y:i}),_i={left:"right",right:"left",bottom:"top",top:"bottom"},Hi={start:"end",end:"start"};function ze(i,e,t){return U(i,ae(e,t))}function ce(i,e){return typeof i=="function"?i(e):i}function W(i){return i.split("-")[0]}function pe(i){return i.split("-")[1]}function Fe(i){return i==="x"?"y":"x"}function Ne(i){return i==="y"?"height":"width"}var Mi=new Set(["top","bottom"]);function N(i){return Mi.has(W(i))?"y":"x"}function De(i){return Fe(N(i))}function wt(i,e,t){t===void 0&&(t=!1);let n=pe(i),o=De(i),r=Ne(o),s=o==="x"?n===(t?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=se(s)),[s,se(s)]}function xt(i){let e=se(i);return[Le(i),e,Le(e)]}function Le(i){return i.replace(/start|end/g,e=>Hi[e])}var yt=["left","right"],bt=["right","left"],Oi=["top","bottom"],Pi=["bottom","top"];function $i(i,e,t){switch(i){case"top":case"bottom":return t?e?bt:yt:e?yt:bt;case"left":case"right":return e?Oi:Pi;default:return[]}}function kt(i,e,t,n){let o=pe(i),r=$i(W(i),t==="start",n);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Le)))),r}function se(i){return i.replace(/left|right|bottom|top/g,e=>_i[e])}function Ri(i){return{top:0,right:0,bottom:0,left:0,...i}}function St(i){return typeof i!="number"?Ri(i):{top:i,right:i,bottom:i,left:i}}function G(i){let{x:e,y:t,width:n,height:o}=i;return{width:n,height:o,top:t,left:e,right:e+n,bottom:t+o,x:e,y:t}}function Lt(i,e,t){let{reference:n,floating:o}=i,r=N(e),s=De(e),a=Ne(s),c=W(e),p=r==="y",l=n.x+n.width/2-o.width/2,d=n.y+n.height/2-o.height/2,u=n[a]/2-o[a]/2,h;switch(c){case"top":h={x:l,y:n.y-o.height};break;case"bottom":h={x:l,y:n.y+n.height};break;case"right":h={x:n.x+n.width,y:d};break;case"left":h={x:n.x-o.width,y:d};break;default:h={x:n.x,y:n.y}}switch(pe(e)){case"start":h[s]-=u*(t&&p?-1:1);break;case"end":h[s]+=u*(t&&p?-1:1);break}return h}async function Et(i,e){var t;e===void 0&&(e={});let{x:n,y:o,platform:r,rects:s,elements:a,strategy:c}=i,{boundary:p="clippingAncestors",rootBoundary:l="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=ce(e,i),f=St(h),g=a[u?d==="floating"?"reference":"floating":d],y=G(await r.getClippingRect({element:(t=await(r.isElement==null?void 0:r.isElement(g)))==null||t?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:p,rootBoundary:l,strategy:c})),b=d==="floating"?{x:n,y:o,width:s.floating.width,height:s.floating.height}:s.reference,w=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),S=await(r.isElement==null?void 0:r.isElement(w))?await(r.getScale==null?void 0:r.getScale(w))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:w,strategy:c}):b);return{top:(y.top-k.top+f.top)/S.y,bottom:(k.bottom-y.bottom+f.bottom)/S.y,left:(y.left-k.left+f.left)/S.x,right:(k.right-y.right+f.right)/S.x}}var Ct=async(i,e,t)=>{let{placement:n="bottom",strategy:o="absolute",middleware:r=[],platform:s}=t,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:i,floating:e,strategy:o}),{x:l,y:d}=Lt(p,n,c),u=n,h={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:b}=a[g],{x:w,y:S,data:k,reset:E}=await b({x:l,y:d,initialPlacement:n,placement:u,strategy:o,middlewareData:h,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Et},elements:{reference:i,floating:e}});l=w!=null?w:l,d=S!=null?S:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:i,floating:e,strategy:o}):E.rects),{x:l,y:d}=Lt(p,u,c)),g=-1)}return{x:l,y:d,placement:u,strategy:o,middlewareData:h}};var At=function(i){return i===void 0&&(i={}),{name:"flip",options:i,async fn(e){var t,n;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:p}=e,{mainAxis:l=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=ce(i,e);if((t=r.arrow)!=null&&t.alignmentOffset)return{};let y=W(o),b=N(a),w=W(a)===a,S=await(c.isRTL==null?void 0:c.isRTL(p.floating)),k=u||(w||!m?[se(a)]:xt(a)),E=f!=="none";!u&&E&&k.push(...kt(a,m,f,S));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((n=r.flip)==null?void 0:n.overflows)||[];if(l&&ge.push(Y[y]),d){let K=wt(o,s,S);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ge}],!ge.every(K=>K<=0)){var Ue,We;let K=(((Ue=r.flip)==null?void 0:Ue.index)||0)+1,Pe=me[K];if(Pe&&(!(d==="alignment"?b!==N(Pe):!1)||ee.every(M=>N(M.placement)===b?M.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let ne=(We=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,M)=>Z.overflows[1]-M.overflows[1])[0])==null?void 0:We.placement;if(!ne)switch(h){case"bestFit":{var qe;let Z=(qe=ee.filter(M=>{if(E){let j=N(M.placement);return j===b||j==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(j=>j>0).reduce((j,pi)=>j+pi,0)]).sort((M,j)=>M[1]-j[1])[0])==null?void 0:qe[0];Z&&(ne=Z);break}case"initialPlacement":ne=a;break}if(o!==ne)return{reset:{placement:ne}}}return{}}}};var Ii=new Set(["left","top"]);async function Bi(i,e){let{placement:t,platform:n,elements:o}=i,r=await(n.isRTL==null?void 0:n.isRTL(o.floating)),s=W(t),a=pe(t),c=N(t)==="y",p=Ii.has(s)?-1:1,l=r&&c?-1:1,d=ce(e,i),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),c?{x:h*l,y:u*p}:{x:u*p,y:h*l}}var Tt=function(i){return i===void 0&&(i=0),{name:"offset",options:i,async fn(e){var t,n;let{x:o,y:r,placement:s,middlewareData:a}=e,c=await Bi(e,i);return s===((t=a.offset)==null?void 0:t.placement)&&(n=a.arrow)!=null&&n.alignmentOffset?{}:{x:o+c.x,y:r+c.y,data:{...c,placement:s}}}}},_t=function(i){return i===void 0&&(i={}),{name:"shift",options:i,async fn(e){let{x:t,y:n,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:b,y:w}=y;return{x:b,y:w}}},...p}=ce(i,e),l={x:t,y:n},d=await r.detectOverflow(e,p),u=N(W(o)),h=Fe(u),f=l[h],m=l[u];if(s){let y=h==="y"?"top":"left",b=h==="y"?"bottom":"right",w=f+d[y],S=f-d[b];f=ze(w,f,S)}if(a){let y=u==="y"?"top":"left",b=u==="y"?"bottom":"right",w=m+d[y],S=m-d[b];m=ze(w,m,S)}let g=c.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-t,y:g.y-n,enabled:{[h]:s,[u]:a}}}}}};function Ce(){return typeof window<"u"}function J(i){return Mt(i)?(i.nodeName||"").toLowerCase():"#document"}function T(i){var e;return(i==null||(e=i.ownerDocument)==null?void 0:e.defaultView)||window}function I(i){var e;return(e=(Mt(i)?i.ownerDocument:i.document)||window.document)==null?void 0:e.documentElement}function Mt(i){return Ce()?i instanceof Node||i instanceof T(i).Node:!1}function _(i){return Ce()?i instanceof Element||i instanceof T(i).Element:!1}function P(i){return Ce()?i instanceof HTMLElement||i instanceof T(i).HTMLElement:!1}function Ht(i){return!Ce()||typeof ShadowRoot>"u"?!1:i instanceof ShadowRoot||i instanceof T(i).ShadowRoot}var zi=new Set(["inline","contents"]);function te(i){let{overflow:e,overflowX:t,overflowY:n,display:o}=H(i);return/auto|scroll|overlay|hidden|clip/.test(e+n+t)&&!zi.has(o)}var Fi=new Set(["table","td","th"]);function Ot(i){return Fi.has(J(i))}var Ni=[":popover-open",":modal"];function de(i){return Ni.some(e=>{try{return i.matches(e)}catch(t){return!1}})}var Di=["transform","translate","scale","rotate","perspective"],ji=["transform","translate","scale","rotate","perspective","filter"],Vi=["paint","layout","strict","content"];function Ae(i){let e=Te(),t=_(i)?H(i):i;return Di.some(n=>t[n]?t[n]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||ji.some(n=>(t.willChange||"").includes(n))||Vi.some(n=>(t.contain||"").includes(n))}function Pt(i){let e=D(i);for(;P(e)&&!X(e);){if(Ae(e))return e;if(de(e))return null;e=D(e)}return null}function Te(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Ui=new Set(["html","body","#document"]);function X(i){return Ui.has(J(i))}function H(i){return T(i).getComputedStyle(i)}function he(i){return _(i)?{scrollLeft:i.scrollLeft,scrollTop:i.scrollTop}:{scrollLeft:i.scrollX,scrollTop:i.scrollY}}function D(i){if(J(i)==="html")return i;let e=i.assignedSlot||i.parentNode||Ht(i)&&i.host||I(i);return Ht(e)?e.host:e}function $t(i){let e=D(i);return X(e)?i.ownerDocument?i.ownerDocument.body:i.body:P(e)&&te(e)?e:$t(e)}function Ee(i,e,t){var n;e===void 0&&(e=[]),t===void 0&&(t=!0);let o=$t(i),r=o===((n=i.ownerDocument)==null?void 0:n.body),s=T(o);if(r){let a=_e(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&t?Ee(a):[])}return e.concat(o,Ee(o,[],t))}function _e(i){return i.parent&&Object.getPrototypeOf(i.parent)?i.frameElement:null}function zt(i){let e=H(i),t=parseFloat(e.width)||0,n=parseFloat(e.height)||0,o=P(i),r=o?i.offsetWidth:t,s=o?i.offsetHeight:n,a=le(t)!==r||le(n)!==s;return a&&(t=r,n=s),{width:t,height:n,$:a}}function Ft(i){return _(i)?i:i.contextElement}function ie(i){let e=Ft(i);if(!P(e))return O(1);let t=e.getBoundingClientRect(),{width:n,height:o,$:r}=zt(e),s=(r?le(t.width):t.width)/n,a=(r?le(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Wi=O(0);function Nt(i){let e=T(i);return!Te()||!e.visualViewport?Wi:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function qi(i,e,t){return e===void 0&&(e=!1),!t||e&&t!==T(i)?!1:e}function ue(i,e,t,n){e===void 0&&(e=!1),t===void 0&&(t=!1);let o=i.getBoundingClientRect(),r=Ft(i),s=O(1);e&&(n?_(n)&&(s=ie(n)):s=ie(i));let a=qi(r,t,n)?Nt(r):O(0),c=(o.left+a.x)/s.x,p=(o.top+a.y)/s.y,l=o.width/s.x,d=o.height/s.y;if(r){let u=T(r),h=n&&_(n)?T(n):n,f=u,m=_e(f);for(;m&&n&&h!==f;){let g=ie(m),y=m.getBoundingClientRect(),b=H(m),w=y.left+(m.clientLeft+parseFloat(b.paddingLeft))*g.x,S=y.top+(m.clientTop+parseFloat(b.paddingTop))*g.y;c*=g.x,p*=g.y,l*=g.x,d*=g.y,c+=w,p+=S,f=T(m),m=_e(f)}}return G({width:l,height:d,x:c,y:p})}function He(i,e){let t=he(i).scrollLeft;return e?e.left+t:ue(I(i)).left+t}function Dt(i,e){let t=i.getBoundingClientRect(),n=t.left+e.scrollLeft-He(i,t),o=t.top+e.scrollTop;return{x:n,y:o}}function Ki(i){let{elements:e,rect:t,offsetParent:n,strategy:o}=i,r=o==="fixed",s=I(n),a=e?de(e.floating):!1;if(n===s||a&&r)return t;let c={scrollLeft:0,scrollTop:0},p=O(1),l=O(0),d=P(n);if((d||!d&&!r)&&((J(n)!=="body"||te(s))&&(c=he(n)),P(n))){let h=ue(n);p=ie(n),l.x=h.x+n.clientLeft,l.y=h.y+n.clientTop}let u=s&&!d&&!r?Dt(s,c):O(0);return{width:t.width*p.x,height:t.height*p.y,x:t.x*p.x-c.scrollLeft*p.x+l.x+u.x,y:t.y*p.y-c.scrollTop*p.y+l.y+u.y}}function Zi(i){return Array.from(i.getClientRects())}function Qi(i){let e=I(i),t=he(i),n=i.ownerDocument.body,o=U(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),r=U(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),s=-t.scrollLeft+He(i),a=-t.scrollTop;return H(n).direction==="rtl"&&(s+=U(e.clientWidth,n.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Rt=25;function Gi(i,e){let t=T(i),n=I(i),o=t.visualViewport,r=n.clientWidth,s=n.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=Te();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let p=He(n);if(p<=0){let l=n.ownerDocument,d=l.body,u=getComputedStyle(d),h=l.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(n.clientWidth-d.clientWidth-h);f<=Rt&&(r-=f)}else p<=Rt&&(r+=p);return{width:r,height:s,x:a,y:c}}var Ji=new Set(["absolute","fixed"]);function Xi(i,e){let t=ue(i,!0,e==="fixed"),n=t.top+i.clientTop,o=t.left+i.clientLeft,r=P(i)?ie(i):O(1),s=i.clientWidth*r.x,a=i.clientHeight*r.y,c=o*r.x,p=n*r.y;return{width:s,height:a,x:c,y:p}}function It(i,e,t){let n;if(e==="viewport")n=Gi(i,t);else if(e==="document")n=Qi(I(i));else if(_(e))n=Xi(e,t);else{let o=Nt(i);n={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(n)}function jt(i,e){let t=D(i);return t===e||!_(t)||X(t)?!1:H(t).position==="fixed"||jt(t,e)}function Yi(i,e){let t=e.get(i);if(t)return t;let n=Ee(i,[],!1).filter(a=>_(a)&&J(a)!=="body"),o=null,r=H(i).position==="fixed",s=r?D(i):i;for(;_(s)&&!X(s);){let a=H(s),c=Ae(s);!c&&a.position==="fixed"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Ji.has(o.position)||te(s)&&!c&&jt(i,s))?n=n.filter(l=>l!==s):o=a,s=D(s)}return e.set(i,n),n}function en(i){let{element:e,boundary:t,rootBoundary:n,strategy:o}=i,s=[...t==="clippingAncestors"?de(e)?[]:Yi(e,this._c):[].concat(t),n],a=s[0],c=s.reduce((p,l)=>{let d=It(e,l,o);return p.top=U(d.top,p.top),p.right=ae(d.right,p.right),p.bottom=ae(d.bottom,p.bottom),p.left=U(d.left,p.left),p},It(e,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function tn(i){let{width:e,height:t}=zt(i);return{width:e,height:t}}function nn(i,e,t){let n=P(e),o=I(e),r=t==="fixed",s=ue(i,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function p(){c.x=He(o)}if(n||!n&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),n){let h=ue(e,!0,r,e);c.x=h.x+e.clientLeft,c.y=h.y+e.clientTop}else o&&p();r&&!n&&o&&p();let l=o&&!n&&!r?Dt(o,a):O(0),d=s.left+a.scrollLeft-c.x-l.x,u=s.top+a.scrollTop-c.y-l.y;return{x:d,y:u,width:s.width,height:s.height}}function je(i){return H(i).position==="static"}function Bt(i,e){if(!P(i)||H(i).position==="fixed")return null;if(e)return e(i);let t=i.offsetParent;return I(i)===t&&(t=t.ownerDocument.body),t}function Vt(i,e){let t=T(i);if(de(i))return t;if(!P(i)){let o=D(i);for(;o&&!X(o);){if(_(o)&&!je(o))return o;o=D(o)}return t}let n=Bt(i,e);for(;n&&Ot(n)&&je(n);)n=Bt(n,e);return n&&X(n)&&je(n)&&!Ae(n)?t:n||Pt(i)||t}var on=async function(i){let e=this.getOffsetParent||Vt,t=this.getDimensions,n=await t(i.floating);return{reference:nn(i.reference,await e(i.floating),i.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function rn(i){return H(i).direction==="rtl"}var sn={convertOffsetParentRelativeRectToViewportRelativeRect:Ki,getDocumentElement:I,getClippingRect:en,getOffsetParent:Vt,getElementRects:on,getClientRects:Zi,getDimensions:tn,getScale:ie,isElement:_,isRTL:rn};var Ut=Tt;var Wt=_t,qt=At;var Kt=(i,e,t)=>{let n=new Map,o={platform:sn,...t},r={...o.platform,_c:n};return Ct(i,e,{...o,platform:r})};var Me=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
903
+ `;)p++;let l=r.slice(c,p);x("insertHeader",`Current line (before): "${l}"`);let d=l.match(/^(#{1,6})\s*/),u=d?d[1].length:0,h=d?d[0].length:0;x("insertHeader","Existing header check:"),x("insertHeader",` - Match: ${d?`"${d[0]}"`:"none"}`),x("insertHeader",` - Existing level: ${u}`),x("insertHeader",` - Existing prefix length: ${h}`),x("insertHeader",` - Target level: ${e}`);let f=t&&u===e;x("insertHeader",`Should toggle OFF: ${f} (toggle=${t}, existingLevel=${u}, level=${e})`);let m=xe(i,g=>{let y=g.value.slice(g.selectionStart,g.selectionEnd);x("insertHeader",`Line in operation: "${y}"`);let b=y.replace(/^#{1,6}\s*/,"");x("insertHeader",`Cleaned line: "${b}"`);let w;return f?(x("insertHeader","ACTION: Toggling OFF - removing header"),w=b):u>0?(x("insertHeader",`ACTION: Replacing H${u} with H${e}`),w=o.prefix+b):(x("insertHeader","ACTION: Adding new header"),w=o.prefix+b),x("insertHeader",`New line: "${w}"`),{text:w,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,y,b,w)=>{if(x("insertHeader","Adjusting selection:"),x("insertHeader",` - isRemoving param: ${g}`),x("insertHeader",` - shouldToggleOff: ${f}`),x("insertHeader",` - selStart: ${y}, selEnd: ${b}`),x("insertHeader",` - lineStartPos: ${w}`),f){let S=Math.max(y-h,w);return x("insertHeader",` - Removing header, adjusting by -${h}`),{start:S,end:y===b?S:Math.max(b-h,w)}}else if(h>0){let S=o.prefix.length-h;return x("insertHeader",` - Replacing header, adjusting by ${S}`),{start:y+S,end:b+S}}else return x("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:y+o.prefix.length,end:b+o.prefix.length}}});x("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),x("insertHeader","============ END ============"),V(i,m)}function ut(i){Be(i,1,!0)}function ft(i){Be(i,2,!0)}function mt(i){Be(i,3,!0)}function gt(i){return _i(i)}var Se=class{constructor(e,t={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=t.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let t=this.createSeparator();this.container.appendChild(t)}else{let t=this.createButton(e);this.buttons[e.name]=t,this.container.appendChild(t)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.setAttribute("data-button",e.name),t.title=e.title||"",t.setAttribute("aria-label",e.title||e.name),t.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(t.classList.add("has-dropdown"),t.dataset.dropdown="true",t.addEventListener("click",n=>{n.preventDefault(),this.toggleViewModeDropdown(t)}),t):(t._clickHandler=n=>{n.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,n)},t.addEventListener("click",t._clickHandler),t)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:t=>this.editor.setValue(t),event:null}),!0}catch(t){return console.error(`Action "${e.name}" error:`,t),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:t}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/\son\w+\s*=\s*["'][^"']*["']/gi,"").replace(/\son\w+\s*=\s*[^\s>]*/gi,"")}toggleViewModeDropdown(e){let t=document.querySelector(".overtype-dropdown-menu");if(t){t.remove(),e.classList.remove("dropdown-active");return}e.classList.add("dropdown-active");let n=this.createViewModeDropdown(e),o=e.getBoundingClientRect();n.style.position="absolute",n.style.top=`${o.bottom+5}px`,n.style.left=`${o.left}px`,document.body.appendChild(n),this.handleDocumentClick=r=>{!n.contains(r.target)&&!e.contains(r.target)&&(n.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick))},setTimeout(()=>{document.addEventListener("click",this.handleDocumentClick)},0)}createViewModeDropdown(e){let t=document.createElement("div");t.className="overtype-dropdown-menu";let n=[{id:"normal",label:"Normal Edit",icon:"\u2713"},{id:"plain",label:"Plain Textarea",icon:"\u2713"},{id:"preview",label:"Preview Mode",icon:"\u2713"}],o=this.editor.container.dataset.mode||"normal";return n.forEach(r=>{let s=document.createElement("button");if(s.className="overtype-dropdown-item",s.type="button",s.textContent=r.label,r.id===o){s.classList.add("active"),s.setAttribute("aria-current","true");let a=document.createElement("span");a.className="overtype-dropdown-icon",a.textContent=r.icon,s.prepend(a)}s.addEventListener("click",a=>{switch(a.preventDefault(),r.id){case"plain":this.editor.showPlainTextarea();break;case"preview":this.editor.showPreviewMode();break;case"normal":default:this.editor.showNormalEditMode();break}t.remove(),e.classList.remove("dropdown-active"),document.removeEventListener("click",this.handleDocumentClick)}),t.appendChild(s)}),t}updateButtonStates(){var e;try{let t=((e=gt)==null?void 0:e(this.editor.textarea,this.editor.textarea.selectionStart))||[];Object.entries(this.buttons).forEach(([n,o])=>{if(n==="viewMode")return;let r=!1;switch(n){case"bold":r=t.includes("bold");break;case"italic":r=t.includes("italic");break;case"code":r=!1;break;case"bulletList":r=t.includes("bullet-list");break;case"orderedList":r=t.includes("numbered-list");break;case"taskList":r=t.includes("task-list");break;case"quote":r=t.includes("quote");break;case"h1":r=t.includes("header");break;case"h2":r=t.includes("header-2");break;case"h3":r=t.includes("header-3");break}o.classList.toggle("active",r),o.setAttribute("aria-pressed",r.toString())})}catch(t){}}show(){this.container&&this.container.classList.remove("overtype-toolbar-hidden")}hide(){this.container&&this.container.classList.add("overtype-toolbar-hidden")}destroy(){this.container&&(this.handleDocumentClick&&document.removeEventListener("click",this.handleDocumentClick),Object.values(this.buttons).forEach(e=>{e._clickHandler&&(e.removeEventListener("click",e._clickHandler),delete e._clickHandler)}),this.container.remove(),this.container=null,this.buttons={})}};var ae=Math.min,U=Math.max,le=Math.round;var O=i=>({x:i,y:i}),Ti={left:"right",right:"left",bottom:"top",top:"bottom"},Hi={start:"end",end:"start"};function ze(i,e,t){return U(i,ae(e,t))}function ce(i,e){return typeof i=="function"?i(e):i}function W(i){return i.split("-")[0]}function pe(i){return i.split("-")[1]}function Fe(i){return i==="x"?"y":"x"}function Ne(i){return i==="y"?"height":"width"}var Mi=new Set(["top","bottom"]);function N(i){return Mi.has(W(i))?"y":"x"}function De(i){return Fe(N(i))}function wt(i,e,t){t===void 0&&(t=!1);let n=pe(i),o=De(i),r=Ne(o),s=o==="x"?n===(t?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=se(s)),[s,se(s)]}function xt(i){let e=se(i);return[Le(i),e,Le(e)]}function Le(i){return i.replace(/start|end/g,e=>Hi[e])}var yt=["left","right"],bt=["right","left"],Oi=["top","bottom"],Pi=["bottom","top"];function $i(i,e,t){switch(i){case"top":case"bottom":return t?e?bt:yt:e?yt:bt;case"left":case"right":return e?Oi:Pi;default:return[]}}function kt(i,e,t,n){let o=pe(i),r=$i(W(i),t==="start",n);return o&&(r=r.map(s=>s+"-"+o),e&&(r=r.concat(r.map(Le)))),r}function se(i){return i.replace(/left|right|bottom|top/g,e=>Ti[e])}function Ri(i){return{top:0,right:0,bottom:0,left:0,...i}}function St(i){return typeof i!="number"?Ri(i):{top:i,right:i,bottom:i,left:i}}function G(i){let{x:e,y:t,width:n,height:o}=i;return{width:n,height:o,top:t,left:e,right:e+n,bottom:t+o,x:e,y:t}}function Lt(i,e,t){let{reference:n,floating:o}=i,r=N(e),s=De(e),a=Ne(s),c=W(e),p=r==="y",l=n.x+n.width/2-o.width/2,d=n.y+n.height/2-o.height/2,u=n[a]/2-o[a]/2,h;switch(c){case"top":h={x:l,y:n.y-o.height};break;case"bottom":h={x:l,y:n.y+n.height};break;case"right":h={x:n.x+n.width,y:d};break;case"left":h={x:n.x-o.width,y:d};break;default:h={x:n.x,y:n.y}}switch(pe(e)){case"start":h[s]-=u*(t&&p?-1:1);break;case"end":h[s]+=u*(t&&p?-1:1);break}return h}async function Et(i,e){var t;e===void 0&&(e={});let{x:n,y:o,platform:r,rects:s,elements:a,strategy:c}=i,{boundary:p="clippingAncestors",rootBoundary:l="viewport",elementContext:d="floating",altBoundary:u=!1,padding:h=0}=ce(e,i),f=St(h),g=a[u?d==="floating"?"reference":"floating":d],y=G(await r.getClippingRect({element:(t=await(r.isElement==null?void 0:r.isElement(g)))==null||t?g:g.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(a.floating)),boundary:p,rootBoundary:l,strategy:c})),b=d==="floating"?{x:n,y:o,width:s.floating.width,height:s.floating.height}:s.reference,w=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a.floating)),S=await(r.isElement==null?void 0:r.isElement(w))?await(r.getScale==null?void 0:r.getScale(w))||{x:1,y:1}:{x:1,y:1},k=G(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:w,strategy:c}):b);return{top:(y.top-k.top+f.top)/S.y,bottom:(k.bottom-y.bottom+f.bottom)/S.y,left:(y.left-k.left+f.left)/S.x,right:(k.right-y.right+f.right)/S.x}}var Ct=async(i,e,t)=>{let{placement:n="bottom",strategy:o="absolute",middleware:r=[],platform:s}=t,a=r.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(e)),p=await s.getElementRects({reference:i,floating:e,strategy:o}),{x:l,y:d}=Lt(p,n,c),u=n,h={},f=0;for(let g=0;g<a.length;g++){var m;let{name:y,fn:b}=a[g],{x:w,y:S,data:k,reset:E}=await b({x:l,y:d,initialPlacement:n,placement:u,strategy:o,middlewareData:h,rects:p,platform:{...s,detectOverflow:(m=s.detectOverflow)!=null?m:Et},elements:{reference:i,floating:e}});l=w!=null?w:l,d=S!=null?S:d,h={...h,[y]:{...h[y],...k}},E&&f<=50&&(f++,typeof E=="object"&&(E.placement&&(u=E.placement),E.rects&&(p=E.rects===!0?await s.getElementRects({reference:i,floating:e,strategy:o}):E.rects),{x:l,y:d}=Lt(p,u,c)),g=-1)}return{x:l,y:d,placement:u,strategy:o,middlewareData:h}};var At=function(i){return i===void 0&&(i={}),{name:"flip",options:i,async fn(e){var t,n;let{placement:o,middlewareData:r,rects:s,initialPlacement:a,platform:c,elements:p}=e,{mainAxis:l=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=ce(i,e);if((t=r.arrow)!=null&&t.alignmentOffset)return{};let y=W(o),b=N(a),w=W(a)===a,S=await(c.isRTL==null?void 0:c.isRTL(p.floating)),k=u||(w||!m?[se(a)]:xt(a)),E=f!=="none";!u&&E&&k.push(...kt(a,m,f,S));let me=[a,...k],Y=await c.detectOverflow(e,g),ge=[],ee=((n=r.flip)==null?void 0:n.overflows)||[];if(l&&ge.push(Y[y]),d){let K=wt(o,s,S);ge.push(Y[K[0]],Y[K[1]])}if(ee=[...ee,{placement:o,overflows:ge}],!ge.every(K=>K<=0)){var Ue,We;let K=(((Ue=r.flip)==null?void 0:Ue.index)||0)+1,Pe=me[K];if(Pe&&(!(d==="alignment"?b!==N(Pe):!1)||ee.every(M=>N(M.placement)===b?M.overflows[0]>0:!0)))return{data:{index:K,overflows:ee},reset:{placement:Pe}};let ne=(We=ee.filter(Z=>Z.overflows[0]<=0).sort((Z,M)=>Z.overflows[1]-M.overflows[1])[0])==null?void 0:We.placement;if(!ne)switch(h){case"bestFit":{var qe;let Z=(qe=ee.filter(M=>{if(E){let j=N(M.placement);return j===b||j==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(j=>j>0).reduce((j,pi)=>j+pi,0)]).sort((M,j)=>M[1]-j[1])[0])==null?void 0:qe[0];Z&&(ne=Z);break}case"initialPlacement":ne=a;break}if(o!==ne)return{reset:{placement:ne}}}return{}}}};var Ii=new Set(["left","top"]);async function Bi(i,e){let{placement:t,platform:n,elements:o}=i,r=await(n.isRTL==null?void 0:n.isRTL(o.floating)),s=W(t),a=pe(t),c=N(t)==="y",p=Ii.has(s)?-1:1,l=r&&c?-1:1,d=ce(e,i),{mainAxis:u,crossAxis:h,alignmentAxis:f}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof f=="number"&&(h=a==="end"?f*-1:f),c?{x:h*l,y:u*p}:{x:u*p,y:h*l}}var _t=function(i){return i===void 0&&(i=0),{name:"offset",options:i,async fn(e){var t,n;let{x:o,y:r,placement:s,middlewareData:a}=e,c=await Bi(e,i);return s===((t=a.offset)==null?void 0:t.placement)&&(n=a.arrow)!=null&&n.alignmentOffset?{}:{x:o+c.x,y:r+c.y,data:{...c,placement:s}}}}},Tt=function(i){return i===void 0&&(i={}),{name:"shift",options:i,async fn(e){let{x:t,y:n,placement:o,platform:r}=e,{mainAxis:s=!0,crossAxis:a=!1,limiter:c={fn:y=>{let{x:b,y:w}=y;return{x:b,y:w}}},...p}=ce(i,e),l={x:t,y:n},d=await r.detectOverflow(e,p),u=N(W(o)),h=Fe(u),f=l[h],m=l[u];if(s){let y=h==="y"?"top":"left",b=h==="y"?"bottom":"right",w=f+d[y],S=f-d[b];f=ze(w,f,S)}if(a){let y=u==="y"?"top":"left",b=u==="y"?"bottom":"right",w=m+d[y],S=m-d[b];m=ze(w,m,S)}let g=c.fn({...e,[h]:f,[u]:m});return{...g,data:{x:g.x-t,y:g.y-n,enabled:{[h]:s,[u]:a}}}}}};function Ce(){return typeof window<"u"}function J(i){return Mt(i)?(i.nodeName||"").toLowerCase():"#document"}function _(i){var e;return(i==null||(e=i.ownerDocument)==null?void 0:e.defaultView)||window}function I(i){var e;return(e=(Mt(i)?i.ownerDocument:i.document)||window.document)==null?void 0:e.documentElement}function Mt(i){return Ce()?i instanceof Node||i instanceof _(i).Node:!1}function T(i){return Ce()?i instanceof Element||i instanceof _(i).Element:!1}function P(i){return Ce()?i instanceof HTMLElement||i instanceof _(i).HTMLElement:!1}function Ht(i){return!Ce()||typeof ShadowRoot>"u"?!1:i instanceof ShadowRoot||i instanceof _(i).ShadowRoot}var zi=new Set(["inline","contents"]);function te(i){let{overflow:e,overflowX:t,overflowY:n,display:o}=H(i);return/auto|scroll|overlay|hidden|clip/.test(e+n+t)&&!zi.has(o)}var Fi=new Set(["table","td","th"]);function Ot(i){return Fi.has(J(i))}var Ni=[":popover-open",":modal"];function de(i){return Ni.some(e=>{try{return i.matches(e)}catch(t){return!1}})}var Di=["transform","translate","scale","rotate","perspective"],ji=["transform","translate","scale","rotate","perspective","filter"],Vi=["paint","layout","strict","content"];function Ae(i){let e=_e(),t=T(i)?H(i):i;return Di.some(n=>t[n]?t[n]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||ji.some(n=>(t.willChange||"").includes(n))||Vi.some(n=>(t.contain||"").includes(n))}function Pt(i){let e=D(i);for(;P(e)&&!X(e);){if(Ae(e))return e;if(de(e))return null;e=D(e)}return null}function _e(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var Ui=new Set(["html","body","#document"]);function X(i){return Ui.has(J(i))}function H(i){return _(i).getComputedStyle(i)}function he(i){return T(i)?{scrollLeft:i.scrollLeft,scrollTop:i.scrollTop}:{scrollLeft:i.scrollX,scrollTop:i.scrollY}}function D(i){if(J(i)==="html")return i;let e=i.assignedSlot||i.parentNode||Ht(i)&&i.host||I(i);return Ht(e)?e.host:e}function $t(i){let e=D(i);return X(e)?i.ownerDocument?i.ownerDocument.body:i.body:P(e)&&te(e)?e:$t(e)}function Ee(i,e,t){var n;e===void 0&&(e=[]),t===void 0&&(t=!0);let o=$t(i),r=o===((n=i.ownerDocument)==null?void 0:n.body),s=_(o);if(r){let a=Te(s);return e.concat(s,s.visualViewport||[],te(o)?o:[],a&&t?Ee(a):[])}return e.concat(o,Ee(o,[],t))}function Te(i){return i.parent&&Object.getPrototypeOf(i.parent)?i.frameElement:null}function zt(i){let e=H(i),t=parseFloat(e.width)||0,n=parseFloat(e.height)||0,o=P(i),r=o?i.offsetWidth:t,s=o?i.offsetHeight:n,a=le(t)!==r||le(n)!==s;return a&&(t=r,n=s),{width:t,height:n,$:a}}function Ft(i){return T(i)?i:i.contextElement}function ie(i){let e=Ft(i);if(!P(e))return O(1);let t=e.getBoundingClientRect(),{width:n,height:o,$:r}=zt(e),s=(r?le(t.width):t.width)/n,a=(r?le(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var Wi=O(0);function Nt(i){let e=_(i);return!_e()||!e.visualViewport?Wi:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function qi(i,e,t){return e===void 0&&(e=!1),!t||e&&t!==_(i)?!1:e}function ue(i,e,t,n){e===void 0&&(e=!1),t===void 0&&(t=!1);let o=i.getBoundingClientRect(),r=Ft(i),s=O(1);e&&(n?T(n)&&(s=ie(n)):s=ie(i));let a=qi(r,t,n)?Nt(r):O(0),c=(o.left+a.x)/s.x,p=(o.top+a.y)/s.y,l=o.width/s.x,d=o.height/s.y;if(r){let u=_(r),h=n&&T(n)?_(n):n,f=u,m=Te(f);for(;m&&n&&h!==f;){let g=ie(m),y=m.getBoundingClientRect(),b=H(m),w=y.left+(m.clientLeft+parseFloat(b.paddingLeft))*g.x,S=y.top+(m.clientTop+parseFloat(b.paddingTop))*g.y;c*=g.x,p*=g.y,l*=g.x,d*=g.y,c+=w,p+=S,f=_(m),m=Te(f)}}return G({width:l,height:d,x:c,y:p})}function He(i,e){let t=he(i).scrollLeft;return e?e.left+t:ue(I(i)).left+t}function Dt(i,e){let t=i.getBoundingClientRect(),n=t.left+e.scrollLeft-He(i,t),o=t.top+e.scrollTop;return{x:n,y:o}}function Ki(i){let{elements:e,rect:t,offsetParent:n,strategy:o}=i,r=o==="fixed",s=I(n),a=e?de(e.floating):!1;if(n===s||a&&r)return t;let c={scrollLeft:0,scrollTop:0},p=O(1),l=O(0),d=P(n);if((d||!d&&!r)&&((J(n)!=="body"||te(s))&&(c=he(n)),P(n))){let h=ue(n);p=ie(n),l.x=h.x+n.clientLeft,l.y=h.y+n.clientTop}let u=s&&!d&&!r?Dt(s,c):O(0);return{width:t.width*p.x,height:t.height*p.y,x:t.x*p.x-c.scrollLeft*p.x+l.x+u.x,y:t.y*p.y-c.scrollTop*p.y+l.y+u.y}}function Zi(i){return Array.from(i.getClientRects())}function Qi(i){let e=I(i),t=he(i),n=i.ownerDocument.body,o=U(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),r=U(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),s=-t.scrollLeft+He(i),a=-t.scrollTop;return H(n).direction==="rtl"&&(s+=U(e.clientWidth,n.clientWidth)-o),{width:o,height:r,x:s,y:a}}var Rt=25;function Gi(i,e){let t=_(i),n=I(i),o=t.visualViewport,r=n.clientWidth,s=n.clientHeight,a=0,c=0;if(o){r=o.width,s=o.height;let l=_e();(!l||l&&e==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}let p=He(n);if(p<=0){let l=n.ownerDocument,d=l.body,u=getComputedStyle(d),h=l.compatMode==="CSS1Compat"&&parseFloat(u.marginLeft)+parseFloat(u.marginRight)||0,f=Math.abs(n.clientWidth-d.clientWidth-h);f<=Rt&&(r-=f)}else p<=Rt&&(r+=p);return{width:r,height:s,x:a,y:c}}var Ji=new Set(["absolute","fixed"]);function Xi(i,e){let t=ue(i,!0,e==="fixed"),n=t.top+i.clientTop,o=t.left+i.clientLeft,r=P(i)?ie(i):O(1),s=i.clientWidth*r.x,a=i.clientHeight*r.y,c=o*r.x,p=n*r.y;return{width:s,height:a,x:c,y:p}}function It(i,e,t){let n;if(e==="viewport")n=Gi(i,t);else if(e==="document")n=Qi(I(i));else if(T(e))n=Xi(e,t);else{let o=Nt(i);n={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(n)}function jt(i,e){let t=D(i);return t===e||!T(t)||X(t)?!1:H(t).position==="fixed"||jt(t,e)}function Yi(i,e){let t=e.get(i);if(t)return t;let n=Ee(i,[],!1).filter(a=>T(a)&&J(a)!=="body"),o=null,r=H(i).position==="fixed",s=r?D(i):i;for(;T(s)&&!X(s);){let a=H(s),c=Ae(s);!c&&a.position==="fixed"&&(o=null),(r?!c&&!o:!c&&a.position==="static"&&!!o&&Ji.has(o.position)||te(s)&&!c&&jt(i,s))?n=n.filter(l=>l!==s):o=a,s=D(s)}return e.set(i,n),n}function en(i){let{element:e,boundary:t,rootBoundary:n,strategy:o}=i,s=[...t==="clippingAncestors"?de(e)?[]:Yi(e,this._c):[].concat(t),n],a=s[0],c=s.reduce((p,l)=>{let d=It(e,l,o);return p.top=U(d.top,p.top),p.right=ae(d.right,p.right),p.bottom=ae(d.bottom,p.bottom),p.left=U(d.left,p.left),p},It(e,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function tn(i){let{width:e,height:t}=zt(i);return{width:e,height:t}}function nn(i,e,t){let n=P(e),o=I(e),r=t==="fixed",s=ue(i,!0,r,e),a={scrollLeft:0,scrollTop:0},c=O(0);function p(){c.x=He(o)}if(n||!n&&!r)if((J(e)!=="body"||te(o))&&(a=he(e)),n){let h=ue(e,!0,r,e);c.x=h.x+e.clientLeft,c.y=h.y+e.clientTop}else o&&p();r&&!n&&o&&p();let l=o&&!n&&!r?Dt(o,a):O(0),d=s.left+a.scrollLeft-c.x-l.x,u=s.top+a.scrollTop-c.y-l.y;return{x:d,y:u,width:s.width,height:s.height}}function je(i){return H(i).position==="static"}function Bt(i,e){if(!P(i)||H(i).position==="fixed")return null;if(e)return e(i);let t=i.offsetParent;return I(i)===t&&(t=t.ownerDocument.body),t}function Vt(i,e){let t=_(i);if(de(i))return t;if(!P(i)){let o=D(i);for(;o&&!X(o);){if(T(o)&&!je(o))return o;o=D(o)}return t}let n=Bt(i,e);for(;n&&Ot(n)&&je(n);)n=Bt(n,e);return n&&X(n)&&je(n)&&!Ae(n)?t:n||Pt(i)||t}var on=async function(i){let e=this.getOffsetParent||Vt,t=this.getDimensions,n=await t(i.floating);return{reference:nn(i.reference,await e(i.floating),i.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function rn(i){return H(i).direction==="rtl"}var sn={convertOffsetParentRelativeRectToViewportRelativeRect:Ki,getDocumentElement:I,getClippingRect:en,getOffsetParent:Vt,getElementRects:on,getClientRects:Zi,getDimensions:tn,getScale:ie,isElement:T,isRTL:rn};var Ut=_t;var Wt=Tt,qt=At;var Kt=(i,e,t)=>{let n=new Map,o={platform:sn,...t},r={...o.platform,_c:n};return Ct(i,e,{...o,platform:r})};var Me=class{constructor(e){this.editor=e,this.tooltip=null,this.currentLink=null,this.hideTimeout=null,this.visibilityChangeHandler=null,this.isTooltipHovered=!1,this.init()}init(){this.createTooltip(),this.editor.textarea.addEventListener("selectionchange",()=>this.checkCursorPosition()),this.editor.textarea.addEventListener("keyup",e=>{(e.key.includes("Arrow")||e.key==="Home"||e.key==="End")&&this.checkCursorPosition()}),this.editor.textarea.addEventListener("input",()=>this.hide()),this.editor.textarea.addEventListener("scroll",()=>{this.currentLink&&this.positionTooltip(this.currentLink)}),this.editor.textarea.addEventListener("blur",()=>{this.isTooltipHovered||this.hide()}),this.visibilityChangeHandler=()=>{document.hidden&&this.hide()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.tooltip.addEventListener("mouseenter",()=>{this.isTooltipHovered=!0,this.cancelHide()}),this.tooltip.addEventListener("mouseleave",()=>{this.isTooltipHovered=!1,this.scheduleHide()})}createTooltip(){this.tooltip=document.createElement("div"),this.tooltip.className="overtype-link-tooltip",this.tooltip.innerHTML=`
899
904
  <span style="display: flex; align-items: center; gap: 6px;">
900
905
  <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
901
906
  <path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path>
@@ -974,7 +979,7 @@ ${a}`:r;if(p){let k=i.value[i.selectionStart-1];i.selectionStart!==0&&k!=null&&!
974
979
  <span>${n} chars, ${o} words, ${t.length} lines</span>
975
980
  </div>
976
981
  <div class="overtype-stat">Line ${c}, Col ${p}</div>
977
- `}_setupAutoResize(){this.container.classList.add("overtype-auto-resize"),this.previousHeight=null,this._updateAutoHeight(),this.textarea.addEventListener("input",()=>this._updateAutoHeight()),window.addEventListener("resize",()=>this._updateAutoHeight())}_updateAutoHeight(){if(!this.options.autoResize)return;let e=this.textarea,t=this.preview,n=this.wrapper,o=this.container.dataset.mode==="preview",r=o?t.scrollTop:e.scrollTop;n.style.setProperty("height","auto","important"),t.style.setProperty("height","auto","important"),e.style.setProperty("height","auto","important");let s=o?t.scrollHeight: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"),t.style.setProperty("height",c,"important"),t.style.setProperty("overflow-y",a,"important"),n.style.setProperty("height",c,"important"),e.scrollTop=r,t.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="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,t={}){return new v(e,t)}static initFromData(e,t={}){let n=document.querySelectorAll(e);return Array.from(n).map(o=>{let r={...t};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(t=>{let n=v.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=v.currentTheme||B,o=ye({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,t=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=t,v._startAutoListener(),v._applyGlobalTheme($e("auto"),t);return}v._stopAutoListener(),v._applyGlobalTheme(e,t)}static _applyGlobalTheme(e,t=null){let n=typeof e=="string"?$(e):e;t&&(n=Qe(n,t)),v.currentTheme=n,v.injectStyles(!0);let o=typeof n=="string"?n:n.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 t=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(t,v._globalAutoCustomColors),v._autoInstances.forEach(n=>n._applyResolvedTheme(t))},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){C.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static setCustomSyntax(e){C.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let n=t.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&(o.options.showStats&&o.statsBar&&o._updateStats(),clearTimeout(o._selectionTimeout),o._selectionTimeout=setTimeout(()=>{o.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};A(v,"instances",new WeakMap),A(v,"stylesInjected",!1),A(v,"globalListenersInitialized",!1),A(v,"instanceCount",0),A(v,"_autoMediaQuery",null),A(v,"_autoMediaListener",null),A(v,"_autoInstances",new Set),A(v,"_globalAutoTheme",!1),A(v,"_globalAutoCustomColors",null);var q=v;q.MarkdownParser=C;q.ShortcutsManager=oe;q.themes={solar:B,cave:$("cave")};q.getTheme=$;q.currentTheme=B;var li=q;var ci="overtype-webcomponent-container",cn="Start typing...",pn=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly","spellcheck"],Oe=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._editor=null,this._initialized=!1,this._pendingOptions={},this._styleVersion=0,this._baseStyleElement=null,this._selectionChangeHandler=null,this._isConnected=!1,this._handleChange=this._handleChange.bind(this),this._handleKeydown=this._handleKeydown.bind(this)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
982
+ `}_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,t=this.preview,n=this.wrapper;if(this.container.dataset.mode==="preview"){n.style.removeProperty("height"),t.style.removeProperty("height"),t.style.removeProperty("overflow-y"),e.style.removeProperty("height"),e.style.removeProperty("overflow-y");return}let r=e.scrollTop;n.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"),t.style.setProperty("height",c,"important"),t.style.setProperty("overflow-y",a,"important"),n.style.setProperty("height",c,"important"),e.scrollTop=r,t.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="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,t={}){return new v(e,t)}static initFromData(e,t={}){let n=document.querySelectorAll(e);return Array.from(n).map(o=>{let r={...t};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(t=>{let n=v.getInstance(t);n&&n.destroy()})}static injectStyles(e=!1){if(v.stylesInjected&&!e)return;let t=document.querySelector("style.overtype-styles");t&&t.remove();let n=v.currentTheme||B,o=ye({theme:n}),r=document.createElement("style");r.className="overtype-styles",r.textContent=o,document.head.appendChild(r),v.stylesInjected=!0}static setTheme(e,t=null){if(v._globalAutoTheme=!1,v._globalAutoCustomColors=null,e==="auto"){v._globalAutoTheme=!0,v._globalAutoCustomColors=t,v._startAutoListener(),v._applyGlobalTheme($e("auto"),t);return}v._stopAutoListener(),v._applyGlobalTheme(e,t)}static _applyGlobalTheme(e,t=null){let n=typeof e=="string"?$(e):e;t&&(n=Qe(n,t)),v.currentTheme=n,v.injectStyles(!0);let o=typeof n=="string"?n:n.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 t=e.matches?"cave":"solar";v._globalAutoTheme&&v._applyGlobalTheme(t,v._globalAutoCustomColors),v._autoInstances.forEach(n=>n._applyResolvedTheme(t))},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){C.setCodeHighlighter(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static setCustomSyntax(e){C.setCustomSyntax(e),document.querySelectorAll(".overtype-wrapper").forEach(t=>{let n=t._instance;n&&n.updatePreview&&n.updatePreview()}),document.querySelectorAll("overtype-editor").forEach(t=>{if(typeof t.getEditor=="function"){let n=t.getEditor();n&&n.updatePreview&&n.updatePreview()}})}static initGlobalListeners(){v.globalListenersInitialized||(document.addEventListener("input",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.handleInput(e)}}),document.addEventListener("keydown",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.handleKeydown(e)}}),document.addEventListener("scroll",e=>{if(e.target&&e.target.classList&&e.target.classList.contains("overtype-input")){let t=e.target.closest(".overtype-wrapper"),n=t==null?void 0:t._instance;n&&n.handleScroll(e)}},!0),document.addEventListener("selectionchange",e=>{let t=document.activeElement;if(t&&t.classList.contains("overtype-input")){let n=t.closest(".overtype-wrapper"),o=n==null?void 0:n._instance;o&&(o.options.showStats&&o.statsBar&&o._updateStats(),clearTimeout(o._selectionTimeout),o._selectionTimeout=setTimeout(()=>{o.updatePreview()},50))}}),v.globalListenersInitialized=!0)}};A(v,"instances",new WeakMap),A(v,"stylesInjected",!1),A(v,"globalListenersInitialized",!1),A(v,"instanceCount",0),A(v,"_autoMediaQuery",null),A(v,"_autoMediaListener",null),A(v,"_autoInstances",new Set),A(v,"_globalAutoTheme",!1),A(v,"_globalAutoCustomColors",null);var q=v;q.MarkdownParser=C;q.ShortcutsManager=oe;q.themes={solar:B,cave:$("cave")};q.getTheme=$;q.currentTheme=B;var li=q;var ci="overtype-webcomponent-container",cn="Start typing...",pn=["value","theme","toolbar","height","min-height","max-height","placeholder","font-size","line-height","padding","auto-resize","autofocus","show-stats","smart-lists","readonly","spellcheck"],Oe=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._editor=null,this._initialized=!1,this._pendingOptions={},this._styleVersion=0,this._baseStyleElement=null,this._selectionChangeHandler=null,this._isConnected=!1,this._handleChange=this._handleChange.bind(this),this._handleKeydown=this._handleKeydown.bind(this)}_decodeValue(e){return typeof e!="string"?"":e.replace(/\\r/g,"\r").replace(/\\n/g,`
978
983
  `).replace(/\\t/g," ")}static get observedAttributes(){return pn}connectedCallback(){this._isConnected=!0,this._initializeEditor()}disconnectedCallback(){this._isConnected=!1,this._cleanup()}attributeChangedCallback(e,t,n){if(t!==n&&!this._silentUpdate){if(!this._initialized){this._pendingOptions[e]=n;return}this._updateOption(e,n)}}_initializeEditor(){if(!(this._initialized||!this._isConnected))try{let e=document.createElement("div");e.className=ci;let t=this.getAttribute("height"),n=this.getAttribute("min-height"),o=this.getAttribute("max-height");t&&(e.style.height=t),n&&(e.style.minHeight=n),o&&(e.style.maxHeight=o),this._injectStyles(),this.shadowRoot.appendChild(e);let r=this._getOptionsFromAttributes(),s=new li(e,r);this._editor=s[0],this._initialized=!0,this._editor&&this._editor.textarea&&(this._editor.textarea.addEventListener("scroll",()=>{this._editor&&this._editor.preview&&this._editor.textarea&&(this._editor.preview.scrollTop=this._editor.textarea.scrollTop,this._editor.preview.scrollLeft=this._editor.textarea.scrollLeft)}),this._editor.textarea.addEventListener("input",a=>{this._editor&&this._editor.handleInput&&this._editor.handleInput(a)}),this._editor.textarea.addEventListener("keydown",a=>{this._editor&&this._editor.handleKeydown&&this._editor.handleKeydown(a)}),this._selectionChangeHandler=()=>{if(document.activeElement===this){let a=this.shadowRoot.activeElement;a&&a===this._editor.textarea&&(this._editor.options.showStats&&this._editor.statsBar&&this._editor._updateStats(),this._editor.linkTooltip&&this._editor.linkTooltip.checkCursorPosition&&this._editor.linkTooltip.checkCursorPosition())}},document.addEventListener("selectionchange",this._selectionChangeHandler)),this._applyPendingOptions(),this._dispatchEvent("ready",{editor:this._editor})}catch(e){let t=e&&e.message?e.message:String(e);console.warn("OverType Web Component initialization failed:",t),this._dispatchEvent("error",{error:{message:t}})}}_injectStyles(){let e=document.createElement("style"),t=this.getAttribute("theme")||"solar",n=$(t),o=this._getOptionsFromAttributes(),r=ye({...o,theme:n}),s=`
979
984
  /* Web Component Host Styles */
980
985
  :host {
package/dist/overtype.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.3.3
2
+ * OverType v2.3.4
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -1704,6 +1704,11 @@ function generateStyles(options = {}) {
1704
1704
  cursor: text !important;
1705
1705
  }
1706
1706
 
1707
+ .overtype-container.overtype-auto-resize[data-mode="preview"] .overtype-preview {
1708
+ position: static !important;
1709
+ height: auto !important;
1710
+ }
1711
+
1707
1712
  /* Hide syntax markers in preview mode */
1708
1713
  .overtype-container[data-mode="preview"] .syntax-marker {
1709
1714
  display: none !important;
@@ -5611,11 +5616,18 @@ var _OverType = class _OverType {
5611
5616
  const preview = this.preview;
5612
5617
  const wrapper = this.wrapper;
5613
5618
  const isPreviewMode = this.container.dataset.mode === "preview";
5614
- const scrollTop = isPreviewMode ? preview.scrollTop : textarea.scrollTop;
5619
+ if (isPreviewMode) {
5620
+ wrapper.style.removeProperty("height");
5621
+ preview.style.removeProperty("height");
5622
+ preview.style.removeProperty("overflow-y");
5623
+ textarea.style.removeProperty("height");
5624
+ textarea.style.removeProperty("overflow-y");
5625
+ return;
5626
+ }
5627
+ const scrollTop = textarea.scrollTop;
5615
5628
  wrapper.style.setProperty("height", "auto", "important");
5616
- preview.style.setProperty("height", "auto", "important");
5617
5629
  textarea.style.setProperty("height", "auto", "important");
5618
- let newHeight = isPreviewMode ? preview.scrollHeight : textarea.scrollHeight;
5630
+ let newHeight = textarea.scrollHeight;
5619
5631
  if (this.options.minHeight) {
5620
5632
  const minHeight = parseInt(this.options.minHeight);
5621
5633
  newHeight = Math.max(newHeight, minHeight);