autumnnote 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,74 +1,106 @@
1
- (function(J,W){typeof exports=="object"&&typeof module<"u"?module.exports=W():typeof define=="function"&&define.amd?define(W):(J=typeof globalThis<"u"?globalThis:J||self,J.AutumnNote=W())})(this,function(){"use strict";function J(n,e){let t;return function(...i){clearTimeout(t),t=setTimeout(()=>n.apply(this,i),e)}}function W(n,e){const t={};for(const i of Object.keys(n))t[i]=Array.isArray(n[i])?[...n[i]]:n[i];if(he(n)&&he(e))for(const i of Object.keys(e))he(e[i])?i in n?t[i]=W(n[i],e[i]):t[i]=W({},e[i]):Array.isArray(e[i])?t[i]=[...e[i]]:t[i]=e[i];return t}function he(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}const Xe=1,se=n=>n&&n.nodeType===Xe,Ye=n=>se(n)&&/^(p|div|li|h[1-6]|blockquote|td|th|pre)$/i.test(n.nodeName),Ke=n=>se(n)&&/^(li)$/i.test(n.nodeName);function me(n,e,t){let i=n;for(;i&&i!==t;){if(e(i))return i;i=i.parentNode}return null}function fe(n,e){return me(n,Ye,e)}function c(n,e={},t=[]){const i=document.createElement(n);for(const[s,o]of Object.entries(e))i.setAttribute(s,o);for(const s of t)typeof s=="string"?i.appendChild(document.createTextNode(s)):i.appendChild(s);return i}function d(n,e,t,i){return n.addEventListener(e,t,i),()=>n.removeEventListener(e,t,i)}function q(n,e){const t='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',i=()=>Array.from(n.querySelectorAll(t)).filter(o=>!o.closest('[style*="display: none"]')&&!o.closest('[style*="display:none"]')),s=o=>{if(o.key==="Escape"){o.stopPropagation(),e&&e();return}if(o.key!=="Tab")return;const a=i();if(!a.length)return;const l=a[0],r=a[a.length-1];o.shiftKey?document.activeElement===l&&(o.preventDefault(),r.focus()):document.activeElement===r&&(o.preventDefault(),l.focus())};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)}class Ge{constructor(e,t,i,s){this.sc=e,this.so=t,this.ec=i,this.eo=s}isCollapsed(){return this.sc===this.ec&&this.so===this.eo}toNativeRange(){const e=document.createRange();try{e.setStart(this.sc,this.so),e.setEnd(this.ec,this.eo)}catch{}return e}select(){const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(this.toNativeRange()))}commonAncestor(){const t=this.toNativeRange().commonAncestorContainer;return se(t)?t:t.parentElement}blockNode(e){return me(this.sc,t=>se(t)&&t!==e,e)}toString(){return this.toNativeRange().toString()}getClientRects(){const e=this.toNativeRange().getClientRects();return e.length>0?e[e.length-1]:null}insertNode(e){this.toNativeRange().insertNode(e)}}function ge(n){return new Ge(n.startContainer,n.startOffset,n.endContainer,n.endOffset)}function _e(n){const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0);return n&&!n.contains(t.commonAncestorContainer)?null:ge(t)}function ee(n){const e=window.getSelection();if(!e||e.rangeCount===0){n(null);return}const t=e.getRangeAt(0).cloneRange();n(ge(t)),e.removeAllRanges(),e.addRange(t)}function S(n,e=null){return document.execCommand(n,!1,e)}const ye=()=>S("bold"),ve=()=>S("italic");function be(){const n=window.getSelection();if(!n||!n.rangeCount)return;let e=n.getRangeAt(0).commonAncestorContainer;e.nodeType===3&&(e=e.parentElement);const t=e&&e.closest&&e.closest("u"),i=document.queryCommandState("underline");if(t&&!i){const s=t.parentNode;for(;t.firstChild;)s.insertBefore(t.firstChild,t);s.removeChild(t);return}S("underline")}const we=()=>S("strikeThrough"),xe=()=>S("superscript"),ke=()=>S("subscript"),Ce=n=>S("foreColor",n),Te=n=>S("hiliteColor",n),Se=n=>S("fontName",n);function Ie(n,e=document){S("fontSize","7"),e.querySelectorAll('font[size="7"]').forEach(t=>{const i=document.createElement("span");for(i.style.fontSize=n,t.parentNode.insertBefore(i,t);t.firstChild;)i.appendChild(t.firstChild);t.parentNode.removeChild(t)})}const Re=n=>S("formatBlock",`<${n}>`),Ee=()=>S("justifyLeft"),Ae=()=>S("justifyCenter"),Le=()=>S("justifyRight"),Be=()=>S("justifyFull"),Me=()=>S("indent"),Ne=()=>S("outdent"),je=()=>S("insertUnorderedList"),ze=()=>S("insertOrderedList");function Qe(n){const e=window.getSelection();if(!e||e.rangeCount===0)return;const t=e.getRangeAt(0),i=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE","PRE","TD","TH"]),s=r=>{let h=r instanceof Element?r:r.parentElement;for(;h;){if(i.has(h.tagName))return h;h=h.parentElement}return null};if(t.collapsed){const r=s(t.startContainer);r&&(r.style.lineHeight=n);return}const o=new Set,a=document.createNodeIterator(t.commonAncestorContainer,NodeFilter.SHOW_TEXT,null);let l;for(;l=a.nextNode();)if(t.intersectsNode(l)){const r=s(l);r&&o.add(r)}if(o.size===0){const r=s(t.commonAncestorContainer);r&&o.add(r)}o.forEach(r=>{r.style.lineHeight=n})}function Ze(n){const e=window.getSelection();if(!e||!e.rangeCount)return;const t=e.getRangeAt(0);let i=t.commonAncestorContainer;i.nodeType===3&&(i=i.parentElement);const s=i&&i.closest?i.closest("code"):null;if(s&&!s.closest("pre")){const o=s.parentNode;for(;s.firstChild;)o.insertBefore(s.firstChild,s);o.removeChild(s),n&&n.normalize()}else{if(t.collapsed)return;try{const o=document.createElement("code");t.surroundContents(o);const a=document.createRange();a.selectNodeContents(o),e.removeAllRanges(),e.addRange(a)}catch{const o=t.extractContents(),a=document.createElement("code");a.appendChild(o),t.insertNode(a);const l=document.createRange();l.selectNodeContents(a),e.removeAllRanges(),e.addRange(l)}}}function Je(){const n=window.getSelection();if(!n||!n.rangeCount)return!1;let e=n.getRangeAt(0).commonAncestorContainer;e.nodeType===3&&(e=e.parentElement);const t=e&&e.closest?e.closest("code"):null;return!!(t&&!t.closest("pre"))}function et(){const n=window.getSelection();if(!n||!n.rangeCount)return;let t=n.getRangeAt(0).commonAncestorContainer;t.nodeType===3&&(t=t.parentElement);const i=t&&t.closest?t.closest(".an-checklist li"):null;if(i){const s=i.closest(".an-checklist"),o=Array.from(i.childNodes).filter(h=>!(h.nodeType===1&&h.tagName==="INPUT")).map(h=>h.textContent).join("").replace(/\u00a0/g," ").trim(),a=document.createElement("p");a.textContent=o||" ",s.parentNode.insertBefore(a,s.nextSibling),s.removeChild(i),s.children.length===0&&s.remove();const l=document.createRange(),r=a.firstChild||a;l.setStart(r,0),l.collapse(!0),n.removeAllRanges(),n.addRange(l)}else{const s="data-an-new-cli";S("insertHTML",`<ul class="an-checklist"><li ${s}><input type="checkbox" contenteditable="false"></li></ul>`);const o=document.querySelector(`[${s}]`);if(o){o.removeAttribute(s);const a=o.querySelector('input[type="checkbox"]');if(a){let l=a.nextSibling;!l||l.nodeType!==Node.TEXT_NODE?(l=document.createTextNode("​"),o.appendChild(l)):l.textContent||(l.textContent="​");const r=document.createRange();r.setStart(l,0),r.collapse(!0),n.removeAllRanges(),n.addRange(r)}}}}function tt(){const n=window.getSelection();if(!n||!n.rangeCount)return!1;let e=n.getRangeAt(0).commonAncestorContainer;return e.nodeType===3&&(e=e.parentElement),!!(e&&e.closest&&e.closest(".an-checklist li"))}function R(n,e,t,i,s,o){return{name:n,icon:e,tooltip:t,action:i,isActive:s,isDisabled:o}}const it=R("bold","bold","Bold (Ctrl+B)",()=>ye(),()=>document.queryCommandState("bold")),st=R("italic","italic","Italic (Ctrl+I)",()=>ve(),()=>document.queryCommandState("italic")),ot=R("underline","underline","Underline (Ctrl+U)",()=>be(),()=>{if(document.queryCommandState("underline"))return!0;const n=window.getSelection();if(!n||!n.rangeCount)return!1;let e=n.getRangeAt(0).commonAncestorContainer;return e.nodeType===3&&(e=e.parentElement),!!(e&&e.closest&&e.closest("u"))}),nt=R("strikethrough","strikethrough","Strikethrough",()=>we(),()=>document.queryCommandState("strikeThrough")),at=R("superscript","superscript","Superscript",()=>xe(),()=>document.queryCommandState("superscript")),lt=R("subscript","subscript","Subscript",()=>ke(),()=>document.queryCommandState("subscript")),rt=R("alignLeft","align-left","Align Left",()=>Ee()),ct=R("alignCenter","align-center","Align Center",()=>Ae()),ht=R("alignRight","align-right","Align Right",()=>Le()),dt=R("alignJustify","align-justify","Justify",()=>Be()),pt=R("ul","list-ul","Unordered List",()=>je()),ut=R("ol","list-ol","Ordered List",()=>ze()),mt=R("indent","indent","Indent",()=>Me()),ft=R("outdent","outdent","Outdent",()=>Ne()),gt=R("undo","undo","Undo (Ctrl+Z)",n=>n.invoke("editor.undo"),void 0,n=>!n.invoke("editor.canUndo")),_t=R("redo","redo","Redo (Ctrl+Y)",n=>n.invoke("editor.redo"),void 0,n=>!n.invoke("editor.canRedo")),yt=R("hr","minus","Horizontal Rule",()=>S("insertHorizontalRule")),vt=R("link","link","Insert Link",n=>n.invoke("linkDialog.show")),bt=R("image","image","Insert Image",n=>n.invoke("imageDialog.show")),wt=R("video","video","Insert Video",n=>n.invoke("videoDialog.show")),xt=R("emoji","emoji","Insert Emoji",n=>n.invoke("emojiDialog.show")),kt=R("icon","icon","Insert FA Icon",n=>n.invoke("iconDialog.show")),Ct={name:"table",type:"grid",icon:"table",tooltip:"Insert Table",action:(n,e,t)=>{n.invoke("editor.insertTable",t,e),n.invoke("editor.afterCommand")}},Tt={name:"fontSize",type:"select",tooltip:"Font Size",placeholder:"Size",selectClass:"an-select-narrow",items:["8px","10px","11px","12px","13px","14px","16px","18px","20px","24px","28px","32px","36px","48px","72px"],action:(n,e)=>Ie(e,n.layoutInfo.editable),getValue:n=>{try{const e=window.getSelection();if(e&&e.rangeCount){let i=e.getRangeAt(0).startContainer;for(i.nodeType===3&&(i=i.parentElement);i&&i.nodeType===1&&!i.style.fontSize;)i=i.parentElement;const s=i&&i.style&&i.style.fontSize?i.style.fontSize:"";if(s)return s}const t=n&&n.layoutInfo&&n.layoutInfo.editable;return t&&t.style.fontSize||""}catch{return""}}},St=R("removeFormat","remove-format","Remove Format",()=>S("removeFormat")),It={name:"fontFamily",type:"select",tooltip:"Font Family",action:(n,e)=>Se(e),getValue:()=>{try{return document.queryCommandValue("fontName")||""}catch{return""}}},Rt={name:"paragraphStyle",type:"select",tooltip:"Paragraph Style",placeholder:"Style",selectClass:"an-select-style",items:[{value:"p",label:"Normal"},{value:"h1",label:"H1"},{value:"h2",label:"H2"},{value:"h3",label:"H3"},{value:"h4",label:"H4"},{value:"h5",label:"H5"},{value:"h6",label:"H6"},{value:"blockquote",label:"Quote"},{value:"pre",label:"Code"}],action:(n,e)=>Re(e),getValue:()=>{try{const n=document.queryCommandValue("formatBlock").toLowerCase().replace(/[<>]/g,"");return n==="div"?"p":n||"p"}catch{return""}}},Et={name:"lineHeight",type:"select",tooltip:"Line Height",placeholder:"↕ Line",selectClass:"an-select-narrow",items:["1.0","1.15","1.5","1.75","2.0","2.5","3.0"],action:(n,e)=>Qe(e),getValue:()=>{try{const n=window.getSelection();if(!n||!n.rangeCount)return"";const e=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE","PRE","TD","TH"]);let t=n.getRangeAt(0).startContainer;for(t.nodeType===3&&(t=t.parentElement);t&&!e.has(t.tagName);)t=t.parentElement;return t&&(t.style.lineHeight||getComputedStyle(t).lineHeight)||""}catch{return""}}},At=R("codeview","code","HTML Code View",n=>n.invoke("codeview.toggle"),n=>n.invoke("codeview.isActive")),Lt=R("fullscreen","expand","Fullscreen",n=>n.invoke("fullscreen.toggle"),n=>n.invoke("fullscreen.isActive")),Bt=R("shortcuts","keyboard","Keyboard Shortcuts (Ctrl+Shift+/)",n=>n.invoke("shortcutsDialog.show")),Mt=R("find","search","Find (Ctrl+F)",n=>n.invoke("findReplace.show","find")),Nt=R("inlineCode","inline-code","Inline Code (Ctrl+`)",n=>n.invoke("editor.inlineCode"),()=>Je()),jt=R("checklist","checklist","Checklist",n=>n.invoke("editor.toggleChecklist"),()=>tt()),zt=R("print","print","Print",n=>n.invoke("editor.print")),U={placeholder:"",height:200,minHeight:100,maxHeight:0,focus:!1,resizable:!0,toolbar:[[Rt,It,Tt,Et],[gt,_t],[it,st,ot,nt,Nt],[at,lt],[{name:"foreColor",type:"colorpicker",icon:"foreColor",tooltip:"Text Color",defaultColor:"#e11d48",action:(n,e)=>Ce(e)},{name:"backColor",type:"colorpicker",icon:"backColor",tooltip:"Highlight Color",defaultColor:"#fbbf24",action:(n,e)=>Te(e)}],[rt,ct,ht,dt],[pt,ut,jt,mt,ft],[yt,vt,bt,wt,Ct,xt,kt],[St,At,Lt,Mt,zt,Bt]],useBootstrap:!1,toolbarButtonClass:"btn btn-sm btn-light",useFontAwesome:!0,fontAwesomeClass:"fas",pasteAsPlainText:!1,pasteCleanHTML:!0,pasteStripAttributes:!1,allowImageUpload:!0,maxImageSize:5,tabSize:4,onChange:null,onFocus:null,onBlur:null,onInit:null,onImageUpload:null,onImageError:null,stickyToolbar:!1,stickyToolbarOffset:0,theme:"light",codeHighlight:!0,codeHighlightCDN:"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0",markdownPaste:!0,historyLimit:100,defaultFontFamily:"Arial",defaultFontSize:"14px",fontFamilies:["Arial","Arial Black","Comic Sans MS","Courier New","Georgia","Impact","Tahoma","Times New Roman","Trebuchet MS","Verdana"],readOnly:!1,spellcheck:!0,direction:"ltr",toolbarOverflow:"wrap",autoSave:!1,autoSaveKey:"autumnnote-autosave",maxChars:0,maxWords:0,tableHeaderRow:!1,onSelectionChange:null,colorSwatches:[],onPaste:null,onDestroy:null,onCharLimitReached:null,onWordLimitReached:null,focusColor:null},He=["script","style","iframe","object","embed","form","input","button"],Ht=["href","src","action","formaction"],$t=new Set(["www.youtube.com","youtube.com","m.youtube.com","www.youtube-nocookie.com","youtube-nocookie.com","player.vimeo.com"]);function V(n,{allowIframes:e=!1}={}){const t=new DOMParser().parseFromString(`<body>${n||""}</body>`,"text/html");return(e?He.filter(s=>s!=="iframe"):He).forEach(s=>{t.querySelectorAll(s).forEach(o=>o.remove())}),t.querySelectorAll("*").forEach(s=>{Array.from(s.attributes).forEach(o=>{if(o.name.startsWith("on")){s.removeAttribute(o.name);return}if(Ht.includes(o.name)){const a=o.value.trim();if(/^(javascript|vbscript):/i.test(a)){s.removeAttribute(o.name);return}/^data:/i.test(a)&&!(o.name==="src"&&s.tagName==="IMG")&&s.removeAttribute(o.name)}if(s.tagName==="IFRAME"){if(o.name==="srcdoc"){s.removeAttribute(o.name);return}if(o.name==="src"){Dt(o.value)||s.removeAttribute(o.name);return}}})}),t.body.innerHTML}function Dt(n){const e=(n||"").trim();if(!e||e.startsWith("//")||e.startsWith("/"))return!1;try{const t=new URL(e);return t.protocol!=="https:"?!1:$t.has(t.hostname.toLowerCase())}catch{return!1}}function $e(n,{allowData:e=!1}={}){const t=(n||"").trim();return/^(javascript|vbscript):/i.test(t)||!e&&/^data:/i.test(t)?null:n}function Pt(n,e){const t=c("div",{class:"an-container"}),i=c("div",{class:"an-editable",contenteditable:e.readOnly?"false":"true",spellcheck:String(e.spellcheck!==!1),"aria-multiline":"true","aria-label":"Rich text editor",role:"textbox"});let s="";if(e.autoSave&&e.autoSaveKey)try{s=localStorage.getItem(e.autoSaveKey)||""}catch{}s||(s=n.tagName==="TEXTAREA"?(n.value||"").trim():(n.innerHTML||"").trim()),i.innerHTML=V(s,{allowIframes:!0});const o=e.defaultFontFamily||e.fontFamilies&&e.fontFamilies[0];return o&&(i.style.fontFamily=o),e.defaultFontSize&&(i.style.fontSize=e.defaultFontSize),e.height?i.style.minHeight=`${e.height}px`:e.minHeight&&(i.style.minHeight=`${e.minHeight}px`),e.maxHeight&&(i.style.maxHeight=`${e.maxHeight}px`),t.appendChild(i),e.theme==="dark"&&t.classList.add("an-theme-dark"),e.readOnly&&t.classList.add("an-disabled"),e.direction==="rtl"&&(i.setAttribute("dir","rtl"),t.classList.add("an-dir-rtl")),e.toolbarOverflow==="scroll"&&t.classList.add("an-toolbar-overflow-scroll"),e.stickyToolbar&&(t.classList.add("an-sticky-toolbar"),e.stickyToolbarOffset&&t.style.setProperty("--an-sticky-top",`${e.stickyToolbarOffset}px`)),e.focusColor&&t.style.setProperty("--an-focus-color",e.focusColor),n.style.display="none",n.insertAdjacentElement("afterend",t),{container:t,editable:i}}class Ot{constructor(e,t=100){this.editable=e,this._limit=t,this.stack=[],this.stackOffset=-1,this._savePoint()}_serialize(){return this.editable.innerHTML}_serializeSelection(){const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0);return this.editable.contains(t.startContainer)?{start:this._charOffset(t.startContainer,t.startOffset),end:this._charOffset(t.endContainer,t.endOffset)}:null}_charOffset(e,t){let i=0;const s=document.createTreeWalker(this.editable,NodeFilter.SHOW_TEXT,null);let o;for(;o=s.nextNode();){if(o===e)return i+t;i+=o.length}return 0}_restoreSelection(e){if(!e)return;let t=null,i=0,s=null,o=0,a=0;const l=document.createTreeWalker(this.editable,NodeFilter.SHOW_TEXT,null);let r;for(;r=l.nextNode();){const h=r.length;if(!t&&a+h>=e.start&&(t=r,i=e.start-a),!s&&a+h>=e.end){s=r,o=e.end-a;break}a+=h}if(!t){const h=document.createTreeWalker(this.editable,NodeFilter.SHOW_TEXT,null);let p=null;for(;p=h.nextNode();)t=p;i=t?t.length:0,s=t,o=i}s||(s=t,o=i);try{const h=document.createRange();h.setStart(t,i),h.setEnd(s,o);const p=window.getSelection();p.removeAllRanges(),p.addRange(h)}catch{}}_savePoint(){this.stackOffset<this.stack.length-1&&(this.stack=this.stack.slice(0,this.stackOffset+1));const e=this._serialize(),{html:t,images:i}=this._tokenizeImages(e);this.stack.push({html:t,images:i,sel:this._serializeSelection()}),this.stack.length>this._limit?this.stack.shift():this.stackOffset++}_restore(e){e&&(this.editable.innerHTML=this._detokenizeImages(e),this._restoreSelection(e.sel))}_tokenizeImages(e){const t={};let i=0;return{html:e.replace(/data:[^;]+;base64,[^"' >]*/g,o=>{const a=`__asn_img_${i}__`;return t[a]=o,i++,a}),images:t}}_detokenizeImages(e){return!e.images||Object.keys(e.images).length===0?e.html:e.html.replace(/__asn_img_\d+__/g,t=>e.images[t]||t)}recordUndo(){const e=this._serialize(),{html:t}=this._tokenizeImages(e),i=this.stack[this.stackOffset];i&&i.html===t||this._savePoint()}undo(){this.stackOffset<=0||(this.stackOffset--,this._restore(this.stack[this.stackOffset]))}redo(){this.stackOffset>=this.stack.length-1||(this.stackOffset++,this._restore(this.stack[this.stackOffset]))}reset(){this.stack=[],this.stackOffset=-1,this._savePoint()}canUndo(){return this.stackOffset>0}canRedo(){return this.stackOffset<this.stack.length-1}}function Ft(n,e,t={}){const{headerRow:i=!1}=t,s=c("table",{class:"an-table"});if(i&&e>0){const l=c("thead"),r=c("tr");for(let h=0;h<n;h++){const p=c("th",{},[" "]);r.appendChild(p)}l.appendChild(r),s.appendChild(l)}const o=i?Math.max(e-1,1):e,a=c("tbody");s.appendChild(a);for(let l=0;l<o;l++){const r=c("tr");for(let h=0;h<n;h++){const p=c("td",{},[" "]);r.appendChild(p)}a.appendChild(r)}return s}function Wt(n,e,t={}){const i=Ft(n,e,t);S("insertHTML",i.outerHTML)}const O={BACKSPACE:"Backspace",TAB:"Tab",ENTER:"Enter",ESCAPE:"Escape",LEFT:"ArrowLeft",RIGHT:"ArrowRight"};function D(n,e){return n.key===e||n.key===e.toUpperCase()}function z(n,e){return(n.ctrlKey||n.metaKey)&&D(n,e)}function qt(n,e,t={}){const i=a=>!!(a&&a.nodeName==="I"&&/\bfa-/.test(a.className||"")),s=a=>!!(a&&a.nodeType===Node.TEXT_NODE&&(a.textContent==="​"||a.textContent==="")),o=a=>{const l=window.getSelection();if(!l)return!1;const r=document.createRange();return a(r),r.collapse(!0),l.removeAllRanges(),l.addRange(r),!0};if(D(n,O.BACKSPACE)){const a=window.getSelection();if(a&&a.rangeCount>0){const l=a.getRangeAt(0);if(l.collapsed&&l.startContainer.nodeType===Node.TEXT_NODE){const r=l.startContainer;if(l.startOffset===0&&i(r.previousSibling))return n.preventDefault(),r.previousSibling.remove(),!0;if(l.startOffset===1&&r.textContent==="​"&&i(r.previousSibling))return n.preventDefault(),r.previousSibling.remove(),r.remove(),!0}}return!1}if(D(n,O.LEFT)||D(n,O.RIGHT)){const a=window.getSelection();if(!a||a.rangeCount===0)return!1;const l=a.getRangeAt(0);if(!l.collapsed)return!1;const r=l.startContainer,h=D(n,O.LEFT);if(r.nodeType===Node.TEXT_NODE){const p=r;if(h&&l.startOffset===1&&p.textContent==="​"&&i(p.previousSibling))return n.preventDefault(),o(u=>u.setStartBefore(p.previousSibling));if(h&&l.startOffset===0&&i(p.previousSibling))return n.preventDefault(),o(u=>u.setStartBefore(p.previousSibling));if(h&&l.startOffset===0&&s(p.previousSibling)&&i(p.previousSibling.previousSibling))return n.preventDefault(),o(u=>u.setStartBefore(p.previousSibling.previousSibling));if(!h&&l.startOffset===p.textContent.length&&i(p.nextSibling)){const u=p.nextSibling,m=u.nextSibling;if(n.preventDefault(),m&&m.nodeType===Node.TEXT_NODE){const f=(m.textContent||"").startsWith("​")?1:0;return o(g=>g.setStart(m,Math.min(f,m.textContent.length)))}return o(f=>f.setStartAfter(u))}if(!h&&l.startOffset===p.textContent.length&&s(p.nextSibling)&&i(p.nextSibling.nextSibling)){const u=p.nextSibling.nextSibling,m=u.nextSibling;if(n.preventDefault(),m&&m.nodeType===Node.TEXT_NODE){const f=(m.textContent||"").startsWith("​")?1:0;return o(g=>g.setStart(m,Math.min(f,m.textContent.length)))}return o(f=>f.setStartAfter(u))}}if(r.nodeType===Node.ELEMENT_NODE){const p=r;if(h&&l.startOffset>0){const u=p.childNodes[l.startOffset-1];if(i(u))return n.preventDefault(),o(m=>m.setStartBefore(u));if(s(u)&&i(u.previousSibling))return n.preventDefault(),o(m=>m.setStartBefore(u.previousSibling))}if(!h&&l.startOffset<p.childNodes.length){const u=p.childNodes[l.startOffset];if(i(u)){const m=u.nextSibling;if(n.preventDefault(),m&&m.nodeType===Node.TEXT_NODE){const f=(m.textContent||"").startsWith("​")?1:0;return o(g=>g.setStart(m,Math.min(f,m.textContent.length)))}return o(f=>f.setStartAfter(u))}if(s(u)&&i(u.nextSibling)){const m=u.nextSibling,f=m.nextSibling;if(n.preventDefault(),f&&f.nodeType===Node.TEXT_NODE){const g=(f.textContent||"").startsWith("​")?1:0;return o(v=>v.setStart(f,Math.min(g,f.textContent.length)))}return o(g=>g.setStartAfter(m))}}}}if(D(n,O.TAB)){const a=_e(e);if(!a)return!1;const l=fe(a.sc,e);if(l&&Ke(l))return n.preventDefault(),n.shiftKey?S("outdent"):S("indent"),!0;if(l&&l.nodeName.toUpperCase()==="PRE")return n.shiftKey?!1:(n.preventDefault(),S("insertText"," "),!0);if(t.tabSize)return n.shiftKey?!1:(n.preventDefault(),S("insertText"," ".repeat(t.tabSize)),!0)}if(D(n,O.ENTER)&&n.shiftKey)return n.preventDefault(),S("insertLineBreak"),!0;if(D(n,O.ENTER)&&!n.shiftKey){const a=_e(e);if(!a)return!1;const l=a.sc,r=l.nodeType===3?l.parentElement:l;if(r&&r.nodeName==="I"&&/\bfa-/.test(r.className||"")){const m=document.createRange();m.setStartAfter(r),m.collapse(!0);const f=window.getSelection();return f&&(f.removeAllRanges(),f.addRange(m)),!1}const h=r&&r.closest&&r.closest(".an-video-wrapper");if(h){n.preventDefault();const m=document.createElement("p");m.innerHTML=" ",h.parentNode.insertBefore(m,h.nextSibling);const f=document.createRange();f.setStart(m,0),f.collapse(!0);const g=window.getSelection();return g.removeAllRanges(),g.addRange(f),!0}const p=r&&r.closest&&r.closest(".an-checklist li");if(p){n.preventDefault();const m=p.closest(".an-checklist"),f=window.getSelection();let g=f.getRangeAt(0);if(!(y=>Array.from(y.childNodes).filter(I=>!(I.nodeType===1&&I.tagName==="INPUT")).map(I=>I.textContent).join("").replace(/[\u00a0\u200B]/g," ").trim())(p)){const y=document.createElement("p");y.innerHTML=" ",m.parentNode.insertBefore(y,m.nextSibling),p.remove(),m.children.length===0&&m.remove();const I=document.createRange();return I.setStart(y.firstChild,0),I.collapse(!0),f.removeAllRanges(),f.addRange(I),!0}g.collapsed||(g.deleteContents(),g=f.getRangeAt(0));const k=document.createRange();k.setStart(g.startContainer,g.startOffset),k.setEnd(p,p.childNodes.length);const T=k.extractContents(),C=document.createElement("li"),b=document.createElement("input");b.type="checkbox",b.setAttribute("contenteditable","false"),C.appendChild(b),T.textContent.replace(/[\u00a0\u200B]/g,"").length>0&&C.appendChild(T);let w=C.childNodes[1];(!w||w.nodeType!==Node.TEXT_NODE)&&(w=document.createTextNode("​"),C.appendChild(w)),p.insertAdjacentElement("afterend",C);const _=document.createRange();return _.setStart(w,0),_.collapse(!0),f.removeAllRanges(),f.addRange(_),!0}const u=fe(a.sc,e);if(u&&u.nodeName.toUpperCase()==="BLOCKQUOTE"){const m=a.toNativeRange();if(m.setEnd(u,u.childNodes.length),m.toString()===""&&a.isCollapsed())return n.preventDefault(),S("formatBlock","<p>"),!0}}return!1}function Ut(n){const e=new DOMParser().parseFromString(`<body>${n||""}</body>`,"text/html");return oe(e.body).replace(/\n{3,}/g,`
1
+ (function(et,U){typeof exports=="object"&&typeof module<"u"?module.exports=U():typeof define=="function"&&define.amd?define(U):(et=typeof globalThis<"u"?globalThis:et||self,et.AutumnNote=U())})(this,function(){"use strict";function et(a,t){let e;return function(...i){clearTimeout(e),e=setTimeout(()=>a.apply(this,i),t)}}function U(a,t){const e={};for(const i of Object.keys(a))e[i]=Array.isArray(a[i])?[...a[i]]:a[i];if(pt(a)&&pt(t))for(const i of Object.keys(t))pt(t[i])?i in a?e[i]=U(a[i],t[i]):e[i]=U({},t[i]):Array.isArray(t[i])?e[i]=[...t[i]]:e[i]=t[i];return e}function pt(a){return a!==null&&typeof a=="object"&&!Array.isArray(a)}const Gt=1,nt=a=>a&&a.nodeType===Gt,Qt=a=>nt(a)&&/^(p|div|li|h[1-6]|blockquote|td|th|pre)$/i.test(a.nodeName),Zt=a=>nt(a)&&/^(li)$/i.test(a.nodeName);function _t(a,t,e){let i=a;for(;i&&i!==e;){if(t(i))return i;i=i.parentNode}return null}function yt(a,t){return _t(a,Qt,t)}function c(a,t={},e=[]){const i=document.createElement(a);for(const[s,o]of Object.entries(t))i.setAttribute(s,o);for(const s of e)typeof s=="string"?i.appendChild(document.createTextNode(s)):i.appendChild(s);return i}function p(a,t,e,i){return a.addEventListener(t,e,i),()=>a.removeEventListener(t,e,i)}function V(a,t){const e='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',i=()=>Array.from(a.querySelectorAll(e)).filter(o=>!o.closest('[style*="display: none"]')&&!o.closest('[style*="display:none"]')),s=o=>{if(o.key==="Escape"){o.stopPropagation(),t&&t();return}if(o.key!=="Tab")return;const n=i();if(!n.length)return;const r=n[0],l=n[n.length-1];o.shiftKey?document.activeElement===r&&(o.preventDefault(),l.focus()):document.activeElement===l&&(o.preventDefault(),r.focus())};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)}class Jt{constructor(t,e,i,s){this.sc=t,this.so=e,this.ec=i,this.eo=s}isCollapsed(){return this.sc===this.ec&&this.so===this.eo}toNativeRange(){const t=document.createRange();try{t.setStart(this.sc,this.so),t.setEnd(this.ec,this.eo)}catch{}return t}select(){const t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(this.toNativeRange()))}commonAncestor(){const e=this.toNativeRange().commonAncestorContainer;return nt(e)?e:e.parentElement}blockNode(t){return _t(this.sc,e=>nt(e)&&e!==t,t)}toString(){return this.toNativeRange().toString()}getClientRects(){const t=this.toNativeRange().getClientRects();return t.length>0?t[t.length-1]:null}insertNode(t){this.toNativeRange().insertNode(t)}}function bt(a){return new Jt(a.startContainer,a.startOffset,a.endContainer,a.endOffset)}function vt(a){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0);return a&&!a.contains(e.commonAncestorContainer)?null:bt(e)}function it(a){const t=window.getSelection();if(!t||t.rangeCount===0){a(null);return}const e=t.getRangeAt(0).cloneRange();a(bt(e)),t.removeAllRanges(),t.addRange(e)}function S(a,t=null){return document.execCommand(a,!1,t)}const wt=()=>S("bold"),xt=()=>S("italic");function Ct(){const a=window.getSelection();if(!a||!a.rangeCount)return;let t=a.getRangeAt(0).commonAncestorContainer;t.nodeType===3&&(t=t.parentElement);const e=t&&t.closest&&t.closest("u"),i=document.queryCommandState("underline");if(e&&!i){const s=e.parentNode;for(;e.firstChild;)s.insertBefore(e.firstChild,e);s.removeChild(e);return}S("underline")}const kt=()=>S("strikeThrough"),Tt=()=>S("superscript"),St=()=>S("subscript"),Et=a=>S("foreColor",a),It=a=>S("hiliteColor",a),Rt=a=>S("fontName",a);function At(a,t=document){S("fontSize","7"),t.querySelectorAll('font[size="7"]').forEach(e=>{const i=document.createElement("span");for(i.style.fontSize=a,e.parentNode.insertBefore(i,e);e.firstChild;)i.appendChild(e.firstChild);e.parentNode.removeChild(e)})}const Lt=a=>S("formatBlock",`<${a}>`),Bt=()=>S("justifyLeft"),Mt=()=>S("justifyCenter"),Nt=()=>S("justifyRight"),jt=()=>S("justifyFull"),zt=()=>S("indent"),Ht=()=>S("outdent"),$t=()=>S("insertUnorderedList"),Dt=()=>S("insertOrderedList");function te(a){const t=window.getSelection();if(!t||t.rangeCount===0)return;const e=t.getRangeAt(0),i=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE","PRE","TD","TH"]),s=l=>{let h=l instanceof Element?l:l.parentElement;for(;h;){if(i.has(h.tagName))return h;h=h.parentElement}return null};if(e.collapsed){const l=s(e.startContainer);l&&(l.style.lineHeight=a);return}const o=new Set,n=document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_TEXT,null);let r;for(;r=n.nextNode();)if(e.intersectsNode(r)){const l=s(r);l&&o.add(l)}if(o.size===0){const l=s(e.commonAncestorContainer);l&&o.add(l)}o.forEach(l=>{l.style.lineHeight=a})}function ee(a){const t=window.getSelection();if(!t||!t.rangeCount)return;const e=t.getRangeAt(0);let i=e.commonAncestorContainer;i.nodeType===3&&(i=i.parentElement);const s=i&&i.closest?i.closest("code"):null;if(s&&!s.closest("pre")){const o=s.parentNode;for(;s.firstChild;)o.insertBefore(s.firstChild,s);o.removeChild(s),a&&a.normalize()}else{if(e.collapsed)return;try{const o=document.createElement("code");e.surroundContents(o);const n=document.createRange();n.selectNodeContents(o),t.removeAllRanges(),t.addRange(n)}catch{const o=e.extractContents(),n=document.createElement("code");n.appendChild(o),e.insertNode(n);const r=document.createRange();r.selectNodeContents(n),t.removeAllRanges(),t.addRange(r)}}}function ie(){const a=window.getSelection();if(!a||!a.rangeCount)return!1;let t=a.getRangeAt(0).commonAncestorContainer;t.nodeType===3&&(t=t.parentElement);const e=t&&t.closest?t.closest("code"):null;return!!(e&&!e.closest("pre"))}function se(){const a=window.getSelection();if(!a||!a.rangeCount)return;let e=a.getRangeAt(0).commonAncestorContainer;e.nodeType===3&&(e=e.parentElement);const i=e.closest&&e.closest(".an-checklist");if(i){const r=Array.from(i.querySelectorAll("li")).filter(l=>a.containsNode(l,!0));if(r.length>0){let l=null;if(r.forEach(h=>{const m=Array.from(h.childNodes).filter(u=>!(u.nodeType===1&&u.tagName==="INPUT")).map(u=>u.textContent).join("").replace(/\u00a0/g," ").trim(),d=document.createElement("p");d.textContent=m||" ",i.parentNode.insertBefore(d,i),l||(l=d),i.removeChild(h)}),i.children.length===0&&i.remove(),l){const h=document.createRange();h.setStart(l.firstChild||l,0),h.collapse(!0),a.removeAllRanges(),a.addRange(h)}return}}const o=a.toString().split(/\r?\n/).filter(r=>r.trim().length>0);if(o.length===0)return;const n=o.map(r=>`<li><input type="checkbox" contenteditable="false">${r||"​"}</li>`).join("");document.execCommand("insertHTML",!1,`<ul class="an-checklist">${n}</ul>`)}function oe(){const a=window.getSelection();if(!a||!a.rangeCount)return!1;let t=a.getRangeAt(0).commonAncestorContainer;return t.nodeType===3&&(t=t.parentElement),!!(t&&t.closest&&t.closest(".an-checklist li"))}function I(a,t,e,i,s,o){return{name:a,icon:t,tooltip:e,action:i,isActive:s,isDisabled:o}}const ne=I("bold","bold","Bold (Ctrl+B)",()=>wt(),()=>document.queryCommandState("bold")),ae=I("italic","italic","Italic (Ctrl+I)",()=>xt(),()=>document.queryCommandState("italic")),le=I("underline","underline","Underline (Ctrl+U)",()=>Ct(),()=>{if(document.queryCommandState("underline"))return!0;const a=window.getSelection();if(!a||!a.rangeCount)return!1;let t=a.getRangeAt(0).commonAncestorContainer;return t.nodeType===3&&(t=t.parentElement),!!(t&&t.closest&&t.closest("u"))}),re=I("strikethrough","strikethrough","Strikethrough",()=>kt(),()=>document.queryCommandState("strikeThrough")),ce=I("superscript","superscript","Superscript",()=>Tt(),()=>document.queryCommandState("superscript")),he=I("subscript","subscript","Subscript",()=>St(),()=>document.queryCommandState("subscript")),de=I("alignLeft","align-left","Align Left",()=>Bt()),pe=I("alignCenter","align-center","Align Center",()=>Mt()),ue=I("alignRight","align-right","Align Right",()=>Nt()),me=I("alignJustify","align-justify","Justify",()=>jt()),fe=I("ul","list-ul","Unordered List",()=>$t()),ge=I("ol","list-ol","Ordered List",()=>Dt()),_e=I("indent","indent","Indent",()=>zt()),ye=I("outdent","outdent","Outdent",()=>Ht()),be=I("undo","undo","Undo (Ctrl+Z)",a=>a.invoke("editor.undo"),void 0,a=>!a.invoke("editor.canUndo")),ve=I("redo","redo","Redo (Ctrl+Y)",a=>a.invoke("editor.redo"),void 0,a=>!a.invoke("editor.canRedo")),we=I("hr","minus","Horizontal Rule",()=>S("insertHorizontalRule")),xe=I("link","link","Insert Link",a=>a.invoke("linkDialog.show")),Ce=I("image","image","Insert Image",a=>a.invoke("imageDialog.show")),ke=I("video","video","Insert Video",a=>a.invoke("videoDialog.show")),Te=I("emoji","emoji","Insert Emoji",a=>a.invoke("emojiDialog.show")),Se=I("icon","icon","Insert FA Icon",a=>a.invoke("iconDialog.show")),Ee={name:"table",type:"grid",icon:"table",tooltip:"Insert Table",action:(a,t,e)=>{a.invoke("editor.insertTable",e,t),a.invoke("editor.afterCommand")}},Ie={name:"fontSize",type:"select",tooltip:"Font Size",placeholder:"Size",selectClass:"an-select-narrow",items:["8px","10px","11px","12px","13px","14px","16px","18px","20px","24px","28px","32px","36px","48px","72px"],action:(a,t)=>At(t,a.layoutInfo.editable),getValue:a=>{try{const t=window.getSelection();if(t&&t.rangeCount){let i=t.getRangeAt(0).startContainer;for(i.nodeType===3&&(i=i.parentElement);i&&i.nodeType===1&&!i.style.fontSize;)i=i.parentElement;const s=i&&i.style&&i.style.fontSize?i.style.fontSize:"";if(s)return s}const e=a&&a.layoutInfo&&a.layoutInfo.editable;return e&&e.style.fontSize||""}catch{return""}}},Re=I("removeFormat","remove-format","Remove Format",()=>S("removeFormat")),Ae={name:"fontFamily",type:"select",tooltip:"Font Family",action:(a,t)=>Rt(t),getValue:()=>{try{return document.queryCommandValue("fontName")||""}catch{return""}}},Le={name:"paragraphStyle",type:"select",tooltip:"Paragraph Style",placeholder:"Style",selectClass:"an-select-style",items:[{value:"p",label:"Normal"},{value:"h1",label:"H1"},{value:"h2",label:"H2"},{value:"h3",label:"H3"},{value:"h4",label:"H4"},{value:"h5",label:"H5"},{value:"h6",label:"H6"},{value:"blockquote",label:"Quote"},{value:"pre",label:"Code"}],action:(a,t)=>Lt(t),getValue:()=>{try{const a=document.queryCommandValue("formatBlock").toLowerCase().replace(/[<>]/g,"");return a==="div"?"p":a||"p"}catch{return""}}},Be={name:"lineHeight",type:"select",tooltip:"Line Height",placeholder:"↕ Line",selectClass:"an-select-narrow",items:["1.0","1.15","1.5","1.75","2.0","2.5","3.0"],action:(a,t)=>te(t),getValue:()=>{try{const a=window.getSelection();if(!a||!a.rangeCount)return"";const t=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE","PRE","TD","TH"]);let e=a.getRangeAt(0).startContainer;for(e.nodeType===3&&(e=e.parentElement);e&&!t.has(e.tagName);)e=e.parentElement;return e&&(e.style.lineHeight||getComputedStyle(e).lineHeight)||""}catch{return""}}},Me=I("codeview","code","HTML Code View",a=>a.invoke("codeview.toggle"),a=>a.invoke("codeview.isActive")),Ne=I("fullscreen","expand","Fullscreen",a=>a.invoke("fullscreen.toggle"),a=>a.invoke("fullscreen.isActive")),je=I("shortcuts","keyboard","Keyboard Shortcuts (Ctrl+Shift+/)",a=>a.invoke("shortcutsDialog.show")),ze=I("find","search","Find (Ctrl+F)",a=>a.invoke("findReplace.show","find")),He=I("inlineCode","inline-code","Inline Code (Ctrl+`)",a=>a.invoke("editor.inlineCode"),()=>ie()),$e=I("checklist","checklist","Checklist",a=>a.invoke("editor.toggleChecklist"),()=>oe()),De=I("print","print","Print",a=>a.invoke("editor.print")),Y={placeholder:"",height:200,minHeight:100,maxHeight:0,focus:!1,resizable:!0,toolbar:[[Le,Ae,Ie,Be],[be,ve],[ne,ae,le,re,He],[ce,he],[{name:"foreColor",type:"colorpicker",icon:"foreColor",tooltip:"Text Color",defaultColor:"#e11d48",action:(a,t)=>Et(t)},{name:"backColor",type:"colorpicker",icon:"backColor",tooltip:"Highlight Color",defaultColor:"#fbbf24",action:(a,t)=>It(t)}],[de,pe,ue,me],[fe,ge,$e,_e,ye],[we,xe,Ce,ke,Ee,Te,Se],[Re,Me,Ne,ze,De,je]],useBootstrap:!1,toolbarButtonClass:"btn btn-sm btn-light",useFontAwesome:!0,fontAwesomeClass:"fas",pasteAsPlainText:!1,pasteCleanHTML:!0,pasteStripAttributes:!1,allowImageUpload:!0,maxImageSize:5,tabSize:4,onChange:null,onFocus:null,onBlur:null,onInit:null,onImageUpload:null,onImageError:null,stickyToolbar:!1,stickyToolbarOffset:0,theme:"light",codeHighlight:!0,codeHighlightCDN:"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0",markdownPaste:!0,historyLimit:100,defaultFontFamily:"Arial",defaultFontSize:"14px",fontFamilies:["Arial","Arial Black","Comic Sans MS","Courier New","Georgia","Impact","Tahoma","Times New Roman","Trebuchet MS","Verdana"],readOnly:!1,spellcheck:!0,direction:"ltr",toolbarOverflow:"wrap",autoSave:!1,autoSaveKey:"autumnnote-autosave",maxChars:0,maxWords:0,tableHeaderRow:!1,onSelectionChange:null,colorSwatches:[],onPaste:null,onDestroy:null,onCharLimitReached:null,onWordLimitReached:null,focusColor:null},Pt=["script","style","iframe","object","embed","form","input","button"],Pe=["href","src","action","formaction"],Oe=new Set(["www.youtube.com","youtube.com","m.youtube.com","www.youtube-nocookie.com","youtube-nocookie.com","player.vimeo.com"]);function X(a,{allowIframes:t=!1}={}){const e=new DOMParser().parseFromString(`<body>${a||""}</body>`,"text/html");return(t?Pt.filter(s=>s!=="iframe"):Pt).forEach(s=>{e.querySelectorAll(s).forEach(o=>o.remove())}),e.querySelectorAll("*").forEach(s=>{Array.from(s.attributes).forEach(o=>{if(o.name.startsWith("on")){s.removeAttribute(o.name);return}if(Pe.includes(o.name)){const n=o.value.trim();if(/^(javascript|vbscript):/i.test(n)){s.removeAttribute(o.name);return}/^data:/i.test(n)&&!(o.name==="src"&&s.tagName==="IMG")&&s.removeAttribute(o.name)}if(s.tagName==="IFRAME"){if(o.name==="srcdoc"){s.removeAttribute(o.name);return}if(o.name==="src"){Fe(o.value)||s.removeAttribute(o.name);return}}})}),e.body.innerHTML}function Fe(a){const t=(a||"").trim();if(!t||t.startsWith("//")||t.startsWith("/"))return!1;try{const e=new URL(t);return e.protocol!=="https:"?!1:Oe.has(e.hostname.toLowerCase())}catch{return!1}}function Ot(a,{allowData:t=!1}={}){const e=(a||"").trim();return/^(javascript|vbscript):/i.test(e)||!t&&/^data:/i.test(e)?null:a}function We(a,t){const e=c("div",{class:"an-container"}),i=c("div",{class:"an-editable",contenteditable:t.readOnly?"false":"true",spellcheck:String(t.spellcheck!==!1),"aria-multiline":"true","aria-label":"Rich text editor",role:"textbox"});let s="";if(t.autoSave&&t.autoSaveKey)try{s=localStorage.getItem(t.autoSaveKey)||""}catch{}s||(s=a.tagName==="TEXTAREA"?(a.value||"").trim():(a.innerHTML||"").trim()),i.innerHTML=X(s,{allowIframes:!0});const o=t.defaultFontFamily||t.fontFamilies&&t.fontFamilies[0];return o&&(i.style.fontFamily=o),t.defaultFontSize&&(i.style.fontSize=t.defaultFontSize),t.height?i.style.minHeight=`${t.height}px`:t.minHeight&&(i.style.minHeight=`${t.minHeight}px`),t.maxHeight&&(i.style.maxHeight=`${t.maxHeight}px`),e.appendChild(i),t.theme==="dark"&&e.classList.add("an-theme-dark"),t.readOnly&&e.classList.add("an-disabled"),t.direction==="rtl"&&(i.setAttribute("dir","rtl"),e.classList.add("an-dir-rtl")),t.toolbarOverflow==="scroll"&&e.classList.add("an-toolbar-overflow-scroll"),t.stickyToolbar&&(e.classList.add("an-sticky-toolbar"),t.stickyToolbarOffset&&e.style.setProperty("--an-sticky-top",`${t.stickyToolbarOffset}px`)),t.focusColor&&e.style.setProperty("--an-focus-color",t.focusColor),a.style.display="none",a.insertAdjacentElement("afterend",e),{container:e,editable:i}}class qe{constructor(t,e=100){this.editable=t,this._limit=e,this.stack=[],this.stackOffset=-1,this._savePoint()}_serialize(){return this.editable.innerHTML}_serializeSelection(){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0);return this.editable.contains(e.startContainer)?{start:this._charOffset(e.startContainer,e.startOffset),end:this._charOffset(e.endContainer,e.endOffset)}:null}_charOffset(t,e){let i=0;const s=document.createTreeWalker(this.editable,NodeFilter.SHOW_TEXT,null);let o;for(;o=s.nextNode();){if(o===t)return i+e;i+=o.length}return 0}_restoreSelection(t){if(!t)return;let e=null,i=0,s=null,o=0,n=0;const r=document.createTreeWalker(this.editable,NodeFilter.SHOW_TEXT,null);let l;for(;l=r.nextNode();){const h=l.length;if(!e&&n+h>=t.start&&(e=l,i=t.start-n),!s&&n+h>=t.end){s=l,o=t.end-n;break}n+=h}if(!e){const h=document.createTreeWalker(this.editable,NodeFilter.SHOW_TEXT,null);let m=null;for(;m=h.nextNode();)e=m;i=e?e.length:0,s=e,o=i}s||(s=e,o=i);try{const h=document.createRange();h.setStart(e,i),h.setEnd(s,o);const m=window.getSelection();m.removeAllRanges(),m.addRange(h)}catch{}}_savePoint(){this.stackOffset<this.stack.length-1&&(this.stack=this.stack.slice(0,this.stackOffset+1));const t=this._serialize(),{html:e,images:i}=this._tokenizeImages(t);this.stack.push({html:e,images:i,sel:this._serializeSelection()}),this.stack.length>this._limit?this.stack.shift():this.stackOffset++}_restore(t){t&&(this.editable.innerHTML=this._detokenizeImages(t),this._restoreSelection(t.sel))}_tokenizeImages(t){const e={};let i=0;return{html:t.replace(/data:[^;]+;base64,[^"' >]*/g,o=>{const n=`__asn_img_${i}__`;return e[n]=o,i++,n}),images:e}}_detokenizeImages(t){return!t.images||Object.keys(t.images).length===0?t.html:t.html.replace(/__asn_img_\d+__/g,e=>t.images[e]||e)}recordUndo(){const t=this._serialize(),{html:e}=this._tokenizeImages(t),i=this.stack[this.stackOffset];i&&i.html===e||this._savePoint()}undo(){this.stackOffset<=0||(this.stackOffset--,this._restore(this.stack[this.stackOffset]))}redo(){this.stackOffset>=this.stack.length-1||(this.stackOffset++,this._restore(this.stack[this.stackOffset]))}reset(){this.stack=[],this.stackOffset=-1,this._savePoint()}canUndo(){return this.stackOffset>0}canRedo(){return this.stackOffset<this.stack.length-1}}function Ue(a,t,e={}){const{headerRow:i=!1}=e,s=c("table",{class:"an-table"});if(i&&t>0){const r=c("thead"),l=c("tr");for(let h=0;h<a;h++){const m=c("th",{},[" "]);l.appendChild(m)}r.appendChild(l),s.appendChild(r)}const o=i?Math.max(t-1,1):t,n=c("tbody");s.appendChild(n);for(let r=0;r<o;r++){const l=c("tr");for(let h=0;h<a;h++){const m=c("td",{},[" "]);l.appendChild(m)}n.appendChild(l)}return s}function Ve(a,t,e={}){const i=Ue(a,t,e);S("insertHTML",i.outerHTML)}const F={BACKSPACE:"Backspace",TAB:"Tab",ENTER:"Enter",ESCAPE:"Escape",LEFT:"ArrowLeft",RIGHT:"ArrowRight"};function O(a,t){return a.key===t||a.key===t.toUpperCase()}function H(a,t){return(a.ctrlKey||a.metaKey)&&O(a,t)}function Ye(a,t,e={}){const i=n=>!!(n&&n.nodeName==="I"&&/\bfa-/.test(n.className||"")),s=n=>!!(n&&n.nodeType===Node.TEXT_NODE&&(n.textContent==="​"||n.textContent==="")),o=n=>{const r=window.getSelection();if(!r)return!1;const l=document.createRange();return n(l),l.collapse(!0),r.removeAllRanges(),r.addRange(l),!0};if(O(a,F.BACKSPACE)){const n=window.getSelection();if(n&&n.rangeCount>0){const r=n.getRangeAt(0);if(r.collapsed&&r.startContainer.nodeType===Node.TEXT_NODE){const l=r.startContainer;if(r.startOffset===0&&i(l.previousSibling))return a.preventDefault(),l.previousSibling.remove(),!0;if(r.startOffset===1&&l.textContent==="​"&&i(l.previousSibling))return a.preventDefault(),l.previousSibling.remove(),l.remove(),!0}}return!1}if(O(a,F.LEFT)||O(a,F.RIGHT)){const n=window.getSelection();if(!n||n.rangeCount===0)return!1;const r=n.getRangeAt(0);if(!r.collapsed)return!1;const l=r.startContainer,h=O(a,F.LEFT);if(l.nodeType===Node.TEXT_NODE){const m=l;if(h&&r.startOffset===1&&m.textContent==="​"&&i(m.previousSibling))return a.preventDefault(),o(d=>d.setStartBefore(m.previousSibling));if(h&&r.startOffset===0&&i(m.previousSibling))return a.preventDefault(),o(d=>d.setStartBefore(m.previousSibling));if(h&&r.startOffset===0&&s(m.previousSibling)&&i(m.previousSibling.previousSibling))return a.preventDefault(),o(d=>d.setStartBefore(m.previousSibling.previousSibling));if(!h&&r.startOffset===m.textContent.length&&i(m.nextSibling)){const d=m.nextSibling,u=d.nextSibling;if(a.preventDefault(),u&&u.nodeType===Node.TEXT_NODE){const f=(u.textContent||"").startsWith("​")?1:0;return o(g=>g.setStart(u,Math.min(f,u.textContent.length)))}return o(f=>f.setStartAfter(d))}if(!h&&r.startOffset===m.textContent.length&&s(m.nextSibling)&&i(m.nextSibling.nextSibling)){const d=m.nextSibling.nextSibling,u=d.nextSibling;if(a.preventDefault(),u&&u.nodeType===Node.TEXT_NODE){const f=(u.textContent||"").startsWith("​")?1:0;return o(g=>g.setStart(u,Math.min(f,u.textContent.length)))}return o(f=>f.setStartAfter(d))}}if(l.nodeType===Node.ELEMENT_NODE){const m=l;if(h&&r.startOffset>0){const d=m.childNodes[r.startOffset-1];if(i(d))return a.preventDefault(),o(u=>u.setStartBefore(d));if(s(d)&&i(d.previousSibling))return a.preventDefault(),o(u=>u.setStartBefore(d.previousSibling))}if(!h&&r.startOffset<m.childNodes.length){const d=m.childNodes[r.startOffset];if(i(d)){const u=d.nextSibling;if(a.preventDefault(),u&&u.nodeType===Node.TEXT_NODE){const f=(u.textContent||"").startsWith("​")?1:0;return o(g=>g.setStart(u,Math.min(f,u.textContent.length)))}return o(f=>f.setStartAfter(d))}if(s(d)&&i(d.nextSibling)){const u=d.nextSibling,f=u.nextSibling;if(a.preventDefault(),f&&f.nodeType===Node.TEXT_NODE){const g=(f.textContent||"").startsWith("​")?1:0;return o(_=>_.setStart(f,Math.min(g,f.textContent.length)))}return o(g=>g.setStartAfter(u))}}}}if(O(a,F.TAB)){const n=vt(t);if(!n)return!1;const r=yt(n.sc,t);if(r&&Zt(r))return a.preventDefault(),a.shiftKey?S("outdent"):S("indent"),!0;if(r&&r.nodeName.toUpperCase()==="PRE")return a.shiftKey?!1:(a.preventDefault(),S("insertText"," "),!0);if(e.tabSize)return a.shiftKey?!1:(a.preventDefault(),S("insertText"," ".repeat(e.tabSize)),!0)}if(O(a,F.ENTER)&&a.shiftKey)return a.preventDefault(),S("insertLineBreak"),!0;if(O(a,F.ENTER)&&!a.shiftKey){const n=vt(t);if(!n)return!1;const r=n.sc,l=r.nodeType===3?r.parentElement:r;if(l&&l.nodeName==="I"&&/\bfa-/.test(l.className||"")){const u=document.createRange();u.setStartAfter(l),u.collapse(!0);const f=window.getSelection();return f&&(f.removeAllRanges(),f.addRange(u)),!1}const h=l&&l.closest&&l.closest(".an-video-wrapper");if(h){a.preventDefault();const u=document.createElement("p");u.innerHTML=" ",h.parentNode.insertBefore(u,h.nextSibling);const f=document.createRange();f.setStart(u,0),f.collapse(!0);const g=window.getSelection();return g.removeAllRanges(),g.addRange(f),!0}const m=l&&l.closest&&l.closest(".an-checklist li");if(m){a.preventDefault();const u=m.closest(".an-checklist"),f=window.getSelection();let g=f.getRangeAt(0);if(!(v=>Array.from(v.childNodes).filter(E=>!(E.nodeType===1&&E.tagName==="INPUT")).map(E=>E.textContent).join("").replace(/[\u00a0\u200B]/g," ").trim())(m)){const v=document.createElement("p");v.innerHTML=" ",u.parentNode.insertBefore(v,u.nextSibling),m.remove(),u.children.length===0&&u.remove();const E=document.createRange();return E.setStart(v.firstChild,0),E.collapse(!0),f.removeAllRanges(),f.addRange(E),!0}g.collapsed||(g.deleteContents(),g=f.getRangeAt(0));const b=document.createRange();b.setStart(g.startContainer,g.startOffset),b.setEnd(m,m.childNodes.length);const T=b.extractContents(),k=document.createElement("li"),w=document.createElement("input");w.type="checkbox",w.setAttribute("contenteditable","false"),k.appendChild(w),T.textContent.replace(/[\u00a0\u200B]/g,"").length>0&&k.appendChild(T);let x=k.childNodes[1];(!x||x.nodeType!==Node.TEXT_NODE)&&(x=document.createTextNode("​"),k.appendChild(x)),m.insertAdjacentElement("afterend",k);const y=document.createRange();return y.setStart(x,0),y.collapse(!0),f.removeAllRanges(),f.addRange(y),!0}const d=yt(n.sc,t);if(d&&d.nodeName.toUpperCase()==="BLOCKQUOTE"){const u=n.toNativeRange();if(u.setEnd(d,d.childNodes.length),u.toString()===""&&n.isCollapsed())return a.preventDefault(),S("formatBlock","<p>"),!0}}return!1}function Xe(a){const t=new DOMParser().parseFromString(`<body>${a||""}</body>`,"text/html");return at(t.body).replace(/\n{3,}/g,`
2
2
 
3
- `).trim()}function oe(n){if(n.nodeType===3)return n.textContent.replace(/\s+/g," ");if(n.nodeType!==1)return"";const e=n.nodeName.toLowerCase(),t=()=>Array.from(n.childNodes).map(oe).join("");switch(e){case"p":case"div":return`
3
+ `).trim()}function at(a){if(a.nodeType===3)return a.textContent.replace(/\s+/g," ");if(a.nodeType!==1)return"";const t=a.nodeName.toLowerCase(),e=()=>Array.from(a.childNodes).map(at).join("");switch(t){case"p":case"div":return`
4
4
 
5
- ${t()}
5
+ ${e()}
6
6
 
7
7
  `;case"br":return`
8
8
  `;case"h1":return`
9
9
 
10
- # ${t()}
10
+ # ${e()}
11
11
 
12
12
  `;case"h2":return`
13
13
 
14
- ## ${t()}
14
+ ## ${e()}
15
15
 
16
16
  `;case"h3":return`
17
17
 
18
- ### ${t()}
18
+ ### ${e()}
19
19
 
20
20
  `;case"h4":return`
21
21
 
22
- #### ${t()}
22
+ #### ${e()}
23
23
 
24
24
  `;case"h5":return`
25
25
 
26
- ##### ${t()}
26
+ ##### ${e()}
27
27
 
28
28
  `;case"h6":return`
29
29
 
30
- ###### ${t()}
30
+ ###### ${e()}
31
31
 
32
- `;case"strong":case"b":return`**${t()}**`;case"em":case"i":return`*${t()}*`;case"del":case"s":case"strike":return`~~${t()}~~`;case"sup":return`^${t()}`;case"sub":return`~${t()}`;case"code":return n.closest("pre")?t():`\`${t()}\``;case"pre":{const i=n.querySelector("code"),s=(i&&i.className||"").match(/language-(\S+)/),o=s?s[1]:"",a=(i||n).textContent||"";return`
32
+ `;case"strong":case"b":return`**${e()}**`;case"em":case"i":return`*${e()}*`;case"del":case"s":case"strike":return`~~${e()}~~`;case"sup":return`^${e()}`;case"sub":return`~${e()}`;case"code":return a.closest("pre")?e():`\`${e()}\``;case"pre":{const i=a.querySelector("code"),s=(i&&i.className||"").match(/language-(\S+)/),o=s?s[1]:"",n=(i||a).textContent||"";return`
33
33
 
34
34
  \`\`\`${o}
35
- ${a}
35
+ ${n}
36
36
  \`\`\`
37
37
 
38
38
  `}case"blockquote":return`
39
39
 
40
- ${t().trim().split(`
40
+ ${e().trim().split(`
41
41
  `).map(s=>`> ${s}`).join(`
42
42
  `)}
43
43
 
44
- `;case"a":{const i=n.getAttribute("href")||"";return`[${t()}](${i})`}case"img":{const i=n.getAttribute("src")||"";return`![${n.getAttribute("alt")||""}](${i})`}case"ul":{const i=Array.from(n.querySelectorAll(":scope > li"));return i.length?`
44
+ `;case"a":{const i=a.getAttribute("href")||"";return`[${e()}](${i})`}case"img":{const i=a.getAttribute("src")||"";return`![${a.getAttribute("alt")||""}](${i})`}case"ul":{const i=Array.from(a.querySelectorAll(":scope > li"));return i.length?`
45
45
 
46
- ${i.map(s=>`- ${oe(s).trim()}`).join(`
46
+ ${i.map(s=>`- ${at(s).trim()}`).join(`
47
47
  `)}
48
48
 
49
- `:t()}case"ol":{const i=Array.from(n.querySelectorAll(":scope > li"));return i.length?`
49
+ `:e()}case"ol":{const i=Array.from(a.querySelectorAll(":scope > li"));return i.length?`
50
50
 
51
- ${i.map((s,o)=>`${o+1}. ${oe(s).trim()}`).join(`
51
+ ${i.map((s,o)=>`${o+1}. ${at(s).trim()}`).join(`
52
52
  `)}
53
53
 
54
- `:t()}case"li":return t();case"hr":return`
54
+ `:e()}case"li":return e();case"hr":return`
55
55
 
56
56
  ---
57
57
 
58
- `;case"table":{const i=Array.from(n.querySelectorAll("tr"));if(!i.length)return t();const s=i.map(r=>Array.from(r.querySelectorAll("th, td")).map(h=>h.textContent.trim().replace(/\|/g,"\\|"))),o=Math.max(...s.map(r=>r.length)),a=r=>{const h=[...r];for(;h.length<o;)h.push("");return h};let l=`
58
+ `;case"table":{const i=Array.from(a.querySelectorAll("tr"));if(!i.length)return e();const s=i.map(l=>Array.from(l.querySelectorAll("th, td")).map(h=>h.textContent.trim().replace(/\|/g,"\\|"))),o=Math.max(...s.map(l=>l.length)),n=l=>{const h=[...l];for(;h.length<o;)h.push("");return h};let r=`
59
59
 
60
- `;l+=`| ${a(s[0]).join(" | ")} |
61
- `,l+=`| ${Array(o).fill("---").join(" | ")} |
62
- `;for(let r=1;r<s.length;r++)l+=`| ${a(s[r]).join(" | ")} |
63
- `;return l+`
64
- `}default:return t()}}function Vt(n){return/^#{1,6} \S|^\s*[-*+] \S|^\s*\d+\. \S|^> \S|\*{2}.+?\*{2}|^```/m.test(n)}function De(n){const e=n.replace(/\r\n/g,`
60
+ `;r+=`| ${n(s[0]).join(" | ")} |
61
+ `,r+=`| ${Array(o).fill("---").join(" | ")} |
62
+ `;for(let l=1;l<s.length;l++)r+=`| ${n(s[l]).join(" | ")} |
63
+ `;return r+`
64
+ `}default:return e()}}function Ke(a){return/^#{1,6} \S|^\s*[-*+] \S|^\s*\d+\. \S|^> \S|\*{2}.+?\*{2}|^```/m.test(a)}function Ft(a){const t=a.replace(/\r\n/g,`
65
65
  `).replace(/\r/g,`
66
66
  `).split(`
67
- `),t=[];let i=0;for(;i<e.length;){const s=e[i],o=s.match(/^```(\S*)$/);if(o){const r=o[1],h=[];for(i++;i<e.length&&!e[i].startsWith("```");)h.push(H(e[i])),i++;const p=r?` class="language-${ne(r)}"`:"";t.push(`<pre><code${p}>${h.join(`
68
- `)}</code></pre>`),i++;continue}if(/^(-{3,}|\*{3,}|_{3,})\s*$/.test(s)){t.push("<hr>"),i++;continue}const a=s.match(/^(#{1,6})\s+(.+)$/);if(a){const r=a[1].length;t.push(`<h${r}>${X(a[2])}</h${r}>`),i++;continue}if(s.startsWith("> ")){const r=[];for(;i<e.length&&e[i].startsWith("> ");)r.push(e[i].slice(2)),i++;t.push(`<blockquote>${r.map(X).join("<br>")}</blockquote>`);continue}if(/^[-*+] /.test(s)){const r=[];for(;i<e.length&&/^[-*+] /.test(e[i]);)r.push(`<li>${X(e[i].slice(2))}</li>`),i++;t.push(`<ul>${r.join("")}</ul>`);continue}if(/^\d+\. /.test(s)){const r=[];for(;i<e.length&&/^\d+\. /.test(e[i]);)r.push(`<li>${X(e[i].replace(/^\d+\. /,""))}</li>`),i++;t.push(`<ol>${r.join("")}</ol>`);continue}if(s.trim()===""){i++;continue}if(/^\|.+\|/.test(s)&&i+1<e.length&&/^\|[\s|:-]+\|/.test(e[i+1])){const r=Pe(s);i+=2;const h=[];for(;i<e.length&&/^\|.+\|/.test(e[i]);)h.push(Pe(e[i])),i++;const p=`<thead><tr>${r.map(m=>`<th>${X(m)}</th>`).join("")}</tr></thead>`,u=h.length?`<tbody>${h.map(m=>`<tr>${m.map(f=>`<td>${X(f)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";t.push(`<table>${p}${u}</table>`);continue}const l=[];for(;i<e.length&&e[i].trim()!==""&&!/^(#{1,6} |> |[-*+] |\d+\. |```|---\s*$|\*{3}\s*$|_{3}\s*$)/.test(e[i])&&!/^\|.+\|/.test(e[i]);)l.push(e[i]),i++;l.length&&t.push(`<p>${X(l.join(" "))}</p>`)}return t.join("")}function Pe(n){return n.replace(/^\|/,"").replace(/\|$/,"").split("|").map(e=>e.trim())}function X(n){return n=n.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,i)=>`<img src="${ne(i)}" alt="${ne(t)}" class="an-image">`),n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,i)=>`<a href="${ne(i)}">${H(t)}</a>`),n=n.replace(/\*{3}(.+?)\*{3}/g,(e,t)=>`<strong><em>${H(t)}</em></strong>`),n=n.replace(/_{3}(.+?)_{3}/g,(e,t)=>`<strong><em>${H(t)}</em></strong>`),n=n.replace(/\*{2}(.+?)\*{2}/g,(e,t)=>`<strong>${H(t)}</strong>`),n=n.replace(/_{2}(.+?)_{2}/g,(e,t)=>`<strong>${H(t)}</strong>`),n=n.replace(/\*([^*\n]+?)\*/g,(e,t)=>`<em>${H(t)}</em>`),n=n.replace(/_([^_\n]+?)_/g,(e,t)=>`<em>${H(t)}</em>`),n=n.replace(/~~(.+?)~~/g,(e,t)=>`<del>${H(t)}</del>`),n=n.replace(/`([^`]+)`/g,(e,t)=>`<code>${H(t)}</code>`),n}function H(n){return String(n).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ne(n){return String(n).replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}class Xt{constructor(e){this.context=e,this.options=e.options,this._history=null,this._disposers=[],this._snapshotTimer=null}initialize(){const e=this.context.layoutInfo.editable;return this._history=new Ot(e,this.options.historyLimit||100),this._bindEvents(e),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._history=null,clearTimeout(this._snapshotTimer),this._snapshotTimer=null}_bindEvents(e){const t=r=>this._onKeydown(r),i=()=>this.afterCommand(),s=r=>this._enforceLimit(r),o=()=>{if(!this.context._alive)return;const r=window.getSelection();r&&r.rangeCount>0&&e.contains(r.anchorNode)&&(this.context.invoke("toolbar.refresh"),typeof this.options.onSelectionChange=="function"&&this.options.onSelectionChange(this.context))},a=r=>{r.target.type==="checkbox"&&r.target.closest(".an-checklist")&&this.afterCommand()},l=r=>{const h=window.getSelection();if(!h||!h.rangeCount)return;const p=h.getRangeAt(0);if(!p.collapsed)return;const u=p.startContainer;if(u.nodeType!==Node.ELEMENT_NODE)return;const m=u.matches&&u.matches(".an-checklist li")?u:null;if(!m)return;const f=m.querySelector('input[type="checkbox"]');if(!f)return;if(r&&r.type==="mouseup"){let k=null;if(document.caretRangeFromPoint)k=document.caretRangeFromPoint(r.clientX,r.clientY);else if(document.caretPositionFromPoint){const T=document.caretPositionFromPoint(r.clientX,r.clientY);T&&(k=document.createRange(),k.setStart(T.offsetNode,T.offset))}if(k&&e.contains(k.startContainer)&&k.startContainer!==m){k.collapse(!0),h.removeAllRanges(),h.addRange(k);return}}const g=document.createRange();let v=null;for(const k of m.childNodes)if(k!==f&&k.nodeType===Node.TEXT_NODE){v=k;break}v?g.setStart(v,0):g.setStartAfter(f),g.collapse(!0),h.removeAllRanges(),h.addRange(g)};this._disposers.push(d(e,"keydown",t),d(e,"beforeinput",s),d(e,"input",i),d(document,"selectionchange",o),d(e,"click",a),d(e,"mouseup",l),d(e,"keyup",l))}_onKeydown(e){const t=this.context.layoutInfo.editable;if(!qt(e,t,this.options)){if(z(e,"z")&&!e.shiftKey){e.preventDefault(),this.undo();return}if(z(e,"z")&&e.shiftKey||z(e,"y")){e.preventDefault(),this.redo();return}if(z(e,"b")){e.preventDefault(),this.bold();return}if(z(e,"i")){e.preventDefault(),this.italic();return}if(z(e,"u")){e.preventDefault(),this.underline();return}if(z(e,"k")){e.preventDefault(),this.context.invoke("linkDialog.show");return}if(z(e,"v")&&e.shiftKey){this.context.invoke("clipboard.setForcePlain",!0);return}if(e.key==="/"&&e.shiftKey&&e.ctrlKey&&!e.metaKey){e.preventDefault(),this.context.invoke("shortcutsDialog.show");return}if(z(e,"f")){e.preventDefault(),this.context.invoke("findReplace.show","find");return}z(e,"h")&&(e.preventDefault(),this.context.invoke("findReplace.show","replace")),z(e,"`")&&(e.preventDefault(),this.inlineCode())}}_enforceLimit(e){const t=this.options.maxChars||0,i=this.options.maxWords||0;if(!t&&!i)return;const s=e.inputType||"";if(s.startsWith("delete")||s==="historyUndo"||s==="historyRedo"||s==="insertFromPaste"||s==="insertFromDrop"||!s.startsWith("insert"))return;const o=this.context.layoutInfo.editable.innerText||"",a=o.replace(/\n/g,"").length;if(t&&a>=t){e.preventDefault(),typeof this.options.onCharLimitReached=="function"&&this.options.onCharLimitReached(this.context);return}i&&(e.data===" "||s==="insertParagraph"||s==="insertLineBreak")&&(o.trim()?o.trim().split(/\s+/).length:0)>=i&&(e.preventDefault(),typeof this.options.onWordLimitReached=="function"&&this.options.onWordLimitReached(this.context))}afterCommand(){this.context.invoke("toolbar.refresh"),this.context.invoke("statusbar.update"),this._scheduleSnapshot()}_scheduleSnapshot(){clearTimeout(this._snapshotTimer),this._snapshotTimer=setTimeout(()=>{this._snapshotTimer=null,this._history&&this._history.recordUndo(),this.context.triggerEvent("change",this.getHTML())},400)}focus(){this.context.layoutInfo.editable.focus()}getHTML(){const e=this.context.layoutInfo.editable.innerHTML.replace(/\u200B/g,"");return this.context.invoke("clipboard.resolveImages",e)??e}setHTML(e){this.context.layoutInfo.editable.innerHTML=V(e),this._history&&this._history.reset(),this.afterCommand()}getText(){return this.context.layoutInfo.editable.innerText||""}setText(e){this.context.layoutInfo.editable.textContent=e,this._history&&this._history.reset(),this.afterCommand()}clear(){this.setHTML("")}clearHistory(){this._history&&this._history.reset()}isEmpty(){const e=(this.context.layoutInfo.editable.innerText||"").trim().replace(/\u00a0/g,""),t=!!this.context.layoutInfo.editable.querySelector("img, video, iframe, table");return!e&&!t}insertHTML(e){e&&(S("insertHTML",V(e)),this.afterCommand())}insertText(e){e&&(S("insertText",e),this.afterCommand())}setMarkdown(e){this.setHTML(De(e||""))}getMarkdown(){return Ut(this.getHTML())}undo(){this._history&&(clearTimeout(this._snapshotTimer),this._snapshotTimer=null,this._history.undo(),this.context.invoke("toolbar.refresh"),this.context.invoke("statusbar.update"),this.context.triggerEvent("change",this.getHTML()))}redo(){this._history&&(clearTimeout(this._snapshotTimer),this._snapshotTimer=null,this._history.redo(),this.context.invoke("toolbar.refresh"),this.context.invoke("statusbar.update"),this.context.triggerEvent("change",this.getHTML()))}canUndo(){return this._history?this._history.canUndo():!1}canRedo(){return this._history?this._history.canRedo():!1}bold(){ye(),this.afterCommand()}italic(){ve(),this.afterCommand()}underline(){be(),this.afterCommand()}strikethrough(){we(),this.afterCommand()}superscript(){xe(),this.afterCommand()}subscript(){ke(),this.afterCommand()}justifyLeft(){Ee(),this.afterCommand()}justifyCenter(){Ae(),this.afterCommand()}justifyRight(){Le(),this.afterCommand()}justifyFull(){Be(),this.afterCommand()}indent(){Me(),this.afterCommand()}outdent(){Ne(),this.afterCommand()}insertUL(){je(),this.afterCommand()}insertOL(){ze(),this.afterCommand()}inlineCode(){Ze(this.context.layoutInfo.editable),this.afterCommand()}toggleChecklist(){et(),this.afterCommand()}print(){this.context.print()}formatBlock(e){Re(e),this.afterCommand()}foreColor(e){Ce(e),this.afterCommand()}backColor(e){Te(e),this.afterCommand()}fontName(e){Se(e),this.afterCommand()}fontSize(e){Ie(e,this.context.layoutInfo.editable),this.afterCommand()}insertHr(){S("insertHorizontalRule"),this.afterCommand()}insertLink(e,t,i=!1){const s=window.getSelection();if(!s||s.rangeCount===0)return;const o=$e(e);if(!o)return;if(s.toString().trim().length>0){if(S("createLink",o),i){const l=this._getClosestAnchor();l&&(l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"))}}else{const l=this._escapeAttr(t||o);S("insertHTML",`<a href="${this._escapeAttr(o)}"${i?' target="_blank" rel="noopener noreferrer"':""}>${l}</a>`)}this.afterCommand()}unlink(){S("unlink"),this.afterCommand()}insertImage(e,t="",i=""){const s=$e(e,{allowData:!0});if(!s)return;const a={left:"float:left;margin:0 1em 1em 0",center:"display:block;margin:0 auto",right:"float:right;margin:0 0 1em 1em"}[i]||"",l=a?` style="${a}"`:"";S("insertHTML",`<img src="${this._escapeAttr(s)}" alt="${this._escapeAttr(t)}" class="an-image"${l}>`),this.afterCommand()}insertVideo(e){e&&(S("insertHTML",e),this.afterCommand())}insertTable(e,t){Wt(e,t,{headerRow:this.context.options.tableHeaderRow}),this.afterCommand()}_getClosestAnchor(){const e=window.getSelection();if(!e||e.rangeCount===0)return null;let t=e.getRangeAt(0).startContainer;for(;t;){if(t.nodeName==="A")return t;t=t.parentNode}return null}_escapeAttr(e){return String(e??"").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}}let te=null;class Yt{constructor(e){this.context=e,this.options=e.options,this.el=null,this._disposers=[],this._colorPickerClosers=[]}initialize(){return this.el=c("div",{class:"an-toolbar"}),this._faReady=this._detectFontAwesome(),this._buildButtons(),this._btnMap=new Map((this.options.toolbar||[]).flat().map(e=>[e.name,e])),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null}_buildButtons(){(this.options.toolbar||[]).forEach(t=>{const i=c("div",{class:"an-btn-group"});t.forEach(s=>{let o;s.type==="select"?o=this._createSelect(s):s.type==="grid"?o=this._createGridPicker(s):s.type==="colorpicker"?o=this._createColorPicker(s):o=this._createButton(s),i.appendChild(o)}),this.el.appendChild(i)})}_createGridPicker(e){const s=c("div",{class:"an-table-picker-wrap"}),a=!!this.options.useBootstrap?this.options.toolbarButtonClass||"btn btn-sm btn-light":"an-btn",l=c("button",{type:"button",class:a,title:e.tooltip||"","data-btn":e.name,"aria-label":e.tooltip||e.name,"aria-haspopup":"true","aria-expanded":"false"});if(this._faReady){const _=this.options.fontAwesomeClass||"fas";l.innerHTML=`<i class="${_} fa-table" aria-hidden="true"></i>`}else{const _='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';l.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${_} style="display:block"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>`}const r=c("div",{class:"an-table-picker-popup",role:"dialog","aria-label":"Select table size"}),h=c("div",{class:"an-table-grid"}),p=c("div",{class:"an-table-label"});p.textContent="Insert Table";const u=[];for(let _=1;_<=10;_++)for(let y=1;y<=10;y++){const I=c("div",{class:"an-table-cell","data-row":String(_),"data-col":String(y)});u.push(I),h.appendChild(I)}r.appendChild(h),r.appendChild(p);let m=!1;const f=(_,y)=>{u.forEach(I=>{const E=+I.getAttribute("data-row"),B=+I.getAttribute("data-col");I.classList.toggle("active",E<=_&&B<=y)}),p.textContent=_&&y?`${_} × ${y}`:"Insert Table"},g=()=>{m=!0,r.style.display="block",l.setAttribute("aria-expanded","true")},v=()=>{m=!1,r.style.display="none",l.setAttribute("aria-expanded","false"),f(0,0)},k=d(l,"click",_=>{_.stopPropagation(),m?v():g()}),T=d(h,"mouseover",_=>{const y=_.target.closest(".an-table-cell");y&&f(+y.getAttribute("data-row"),+y.getAttribute("data-col"))}),C=d(h,"mouseleave",()=>f(0,0)),b=d(h,"click",_=>{const y=_.target.closest(".an-table-cell");if(!y)return;const I=+y.getAttribute("data-row"),E=+y.getAttribute("data-col");v(),this.context.invoke("editor.focus"),e.action(this.context,I,E)}),w=d(document,"click",()=>{m&&v()});return this._disposers.push(k,T,C,b,w),s.appendChild(l),s.appendChild(r),s}_createColorPicker(e){const t=["#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#efefef","#ffffff","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#9900ff","#ff00ff","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#d9d2e9","#ead1dc"];let i=e.defaultColor||"#000000";const s=c("div",{class:"an-color-picker-wrap"}),a=!!this.options.useBootstrap?this.options.toolbarButtonClass||"btn btn-sm btn-light":"an-btn",l=c("button",{type:"button",class:`${a} an-color-btn`,title:e.tooltip||"","data-btn":e.name,"aria-label":e.tooltip||e.name}),r='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"',h=e.name==="foreColor"?`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${r} style="display:block"><path d="M4 20L12 4L20 20"/><line x1="7.5" y1="14" x2="16.5" y2="14"/></svg>`:`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${r} style="display:block"><path d="M3 21v-4l9-9 4 4-9 9z"/><path d="M12 8l4 4"/></svg>`;l.innerHTML=h;const p=c("span",{class:"an-color-strip"});p.style.background=i,l.appendChild(p);const u=c("button",{type:"button",class:`${a} an-color-arrow`,title:`Choose ${e.name==="foreColor"?"text":"highlight"} color`,"aria-haspopup":"true","aria-expanded":"false"});u.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 24 24" fill="currentColor" stroke="none" style="display:block"><path d="M7 10l5 5 5-5H7z"/></svg>';const m=c("div",{class:"an-color-popup"});m.style.display="none";const f=c("div",{class:"an-color-swatches"}),g=Array.isArray(this.options.colorSwatches)?this.options.colorSwatches:[];[...new Set([...g,...t])].forEach(x=>{const A=c("div",{class:"an-color-swatch",title:x,"data-color":x});A.style.background=x,f.appendChild(A)});const k=c("div",{class:"an-color-custom"}),T=c("input",{type:"color",value:i,title:"Custom color"}),C=c("span",{},["Custom color"]);k.appendChild(T),k.appendChild(C),m.appendChild(f),m.appendChild(k);let b=!1,w=null;const _=()=>{const x=window.getSelection();w=x&&x.rangeCount?x.getRangeAt(0).cloneRange():null},y=()=>{if(!w)return;const x=window.getSelection();x&&(x.removeAllRanges(),x.addRange(w))},I=()=>{this._colorPickerClosers.forEach(ce=>{ce!==E&&ce()}),_(),b=!0;const x=u.getBoundingClientRect(),A=184;let N=x.left;N+A>window.innerWidth&&(N=x.right-A),m.style.top=`${x.bottom+4}px`,m.style.left=`${Math.max(4,N)}px`,m.style.display="block",u.setAttribute("aria-expanded","true")},E=()=>{b=!1,m.style.display="none",m.style.top="",m.style.left="",u.setAttribute("aria-expanded","false")},B=x=>{i=x,p.style.background=x,T.value=x,y(),e.action(this.context,x),this.context.invoke("editor.afterCommand"),E()},L=d(l,"click",x=>{x.preventDefault(),y(),e.action(this.context,i),this.context.invoke("editor.afterCommand")}),F=d(u,"mousedown",x=>{x.preventDefault()}),K=d(u,"click",x=>{x.stopPropagation(),b?E():I()}),G=d(f,"mousedown",x=>{x.preventDefault()}),j=d(f,"click",x=>{const A=x.target.closest(".an-color-swatch");A&&B(A.dataset.color)}),de=d(T,"change",x=>{B(x.target.value)}),pe=d(document,"click",x=>{b&&!s.contains(x.target)&&!m.contains(x.target)&&E()}),ue=d(m,"click",x=>x.stopPropagation()),Z=()=>{b&&E()};return document.addEventListener("scroll",Z,{passive:!0,capture:!0}),window.addEventListener("resize",Z,{passive:!0}),this._disposers.push(L,F,K,G,j,de,pe,ue,()=>document.removeEventListener("scroll",Z,{capture:!0}),()=>window.removeEventListener("resize",Z),()=>{m.parentNode&&m.parentNode.removeChild(m)}),this._colorPickerClosers.push(E),this._disposers.push(()=>{const x=this._colorPickerClosers.indexOf(E);x!==-1&&this._colorPickerClosers.splice(x,1)}),s.appendChild(l),s.appendChild(u),document.body.appendChild(m),s}_createSelect(e){const t=e.name==="fontFamily"?this.options.fontFamilies||[]:e.items||[],i=e.selectClass?`an-select ${e.selectClass}`:"an-select",s=c("select",{class:i,title:e.tooltip||"","data-btn":e.name,"aria-label":e.tooltip||e.name}),o=e.placeholder||"Font",a=c("option",{value:"",disabled:"",hidden:""},[o]);s.appendChild(a),t.forEach(r=>{const h=typeof r=="object"?r.value:r,p=typeof r=="object"?r.label:r,u=typeof r=="object"&&!!r.disabled,m={value:h};u&&(m.disabled="");const f=c("option",m,[p]);e.name==="fontFamily"&&!u&&(f.style.fontFamily=h),s.appendChild(f)});const l=d(s,"change",r=>{const h=r.target.value,p=r.target.options[r.target.selectedIndex];!h||p.disabled||(this.context.invoke("editor.focus"),e.action(this.context,h),this.context.invoke("editor.afterCommand"))});return this._disposers.push(l),s}_createButton(e){const i=!!this.options.useBootstrap?this.options.toolbarButtonClass||"btn btn-sm btn-light":"an-btn",s=e.className?` ${e.className}`:"",o=`${i}${s}`,a=c("button",{type:"button",class:o,title:e.tooltip||"","data-btn":e.name,"aria-label":e.tooltip||e.name}),l='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"',r=g=>`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${l} style="display:block">${g}</svg>`,h=new Map([["bold",r('<path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/>')],["italic",r('<line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/>')],["underline",r('<path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" y1="21" x2="20" y2="21"/>')],["strikethrough",r('<path d="M17.3 12H6.7"/><path d="M10 6.5C10 5.1 11.1 4 12.5 4c1.4 0 2.5 1.1 2.5 2.5 0 .8-.4 1.5-1 2"/><path d="M14 17.5C14 19 12.9 20 11.5 20 10.1 20 9 18.9 9 17.5c0-.8.4-1.5 1-2"/>')],["superscript",r('<path d="m4 19 8-8"/><path d="m12 19-8-8"/><path d="M20 12h-4c0-1.5.44-2 1.5-2.5S20 8.33 20 7.25C20 6 19 5 17.5 5S15 6 15 7"/>')],["subscript",r('<path d="m4 5 8 8"/><path d="m12 5-8 8"/><path d="M20 21h-4c0-1.5.44-2 1.5-2.5S20 17.33 20 16.25C20 15 19 14 17.5 14S15 15 15 16"/>')],["align-left",r('<line x1="21" y1="6" x2="3" y2="6"/><line x1="15" y1="12" x2="3" y2="12"/><line x1="17" y1="18" x2="3" y2="18"/>')],["align-center",r('<line x1="21" y1="6" x2="3" y2="6"/><line x1="18" y1="12" x2="6" y2="12"/><line x1="21" y1="18" x2="3" y2="18"/>')],["align-right",r('<line x1="21" y1="6" x2="3" y2="6"/><line x1="21" y1="12" x2="9" y2="12"/><line x1="21" y1="18" x2="7" y2="18"/>')],["align-justify",r('<line x1="21" y1="6" x2="3" y2="6"/><line x1="21" y1="12" x2="3" y2="12"/><line x1="21" y1="18" x2="3" y2="18"/>')],["list-ul",r('<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4" cy="6" r="1" fill="currentColor" stroke="none"/><circle cx="4" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="4" cy="18" r="1" fill="currentColor" stroke="none"/>')],["list-ol",r('<line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/><path d="M4 6h1V3"/><path d="M4 10h2l-2 2h2"/><path d="M4 16.5A1.5 1.5 0 0 1 5.5 15a1.5 1.5 0 0 1 0 3H4"/>')],["indent",r('<polyline points="3 8 7 12 3 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/>')],["outdent",r('<polyline points="7 8 3 12 7 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/>')],["undo",r('<path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/>')],["redo",r('<path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"/>')],["minus",r('<line x1="5" y1="12" x2="19" y2="12"/>')],["link",r('<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>')],["image",r('<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/>')],["video",r('<polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/>')],["table",r('<rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/>')],["emoji",r('<circle cx="12" cy="12" r="10"/><path d="M8.5 14.5s1.5 2.5 3.5 2.5 3.5-2.5 3.5-2.5"/><circle cx="9" cy="9" r="1.5" fill="currentColor" stroke="none"/><circle cx="15" cy="9" r="1.5" fill="currentColor" stroke="none"/>')],["icon",r('<circle cx="8" cy="8" r="3"/><circle cx="16" cy="8" r="3"/><rect x="5" y="13" width="6" height="6" rx="1"/><rect x="13" y="13" width="6" height="6" rx="1"/>')],["code",r('<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>')],["expand",r('<polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/>')],["foreColor",r('<path d="M4 20L12 4L20 20"/><line x1="7.5" y1="14" x2="16.5" y2="14"/>')],["backColor",r('<path d="M3 21v-4l9-9 4 4-9 9z"/><path d="M12 8l4 4"/>')],["keyboard",r('<rect x="2" y="6" width="20" height="12" rx="2"/><line x1="6" y1="10" x2="6" y2="10" stroke-width="2.5"/><line x1="10" y1="10" x2="10" y2="10" stroke-width="2.5"/><line x1="14" y1="10" x2="14" y2="10" stroke-width="2.5"/><line x1="18" y1="10" x2="18" y2="10" stroke-width="2.5"/><line x1="8" y1="14" x2="16" y2="14" stroke-width="2"/>')],["caption",r('<rect x="3" y="3" width="18" height="11" rx="2"/><line x1="6" y1="18" x2="18" y2="18"/><line x1="9" y1="21" x2="15" y2="21"/>')],["remove-format",r('<path d="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/>')],["direction",r('<path d="M12 20V4"/><path d="m9 7-3 3 3 3"/><path d="M4 10h8"/><path d="m15 7 3 3-3 3"/><path d="M20 10h-8"/>')],["search",r('<circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>')],["find-replace",r('<circle cx="10" cy="10" r="6"/><line x1="18" y1="18" x2="14.35" y2="14.35"/><path d="M16 19h6"/><path d="M19 16v6"/>')],["inline-code",r('<path d="M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1"/><path d="M16 3h1a2 2 0 0 1 2 2v5c0 1.1.9 2 2 2a2 2 0 0 1-2 2v5a2 2 0 0 1-2 2h-1"/>')],["checklist",r('<rect x="3" y="4" width="5" height="5" rx="1"/><path d="m4 6.5 1 1 2-2"/><rect x="3" y="13" width="5" height="5" rx="1"/><line x1="10" y1="6.5" x2="21" y2="6.5"/><line x1="10" y1="15.5" x2="21" y2="15.5"/>')],["print",r('<path d="M6 9V2h12v7"/><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/><rect x="6" y="14" width="12" height="8"/>')]]),p=this.options.fontAwesomeClass||"fas",u=new Map([["bold","fa-bold"],["italic","fa-italic"],["underline","fa-underline"],["strikethrough","fa-strikethrough"],["superscript","fa-superscript"],["subscript","fa-subscript"],["align-left","fa-align-left"],["align-center","fa-align-center"],["align-right","fa-align-right"],["align-justify","fa-align-justify"],["list-ul","fa-list-ul"],["list-ol","fa-list-ol"],["indent","fa-indent"],["outdent","fa-outdent"],["undo","fa-rotate-left"],["redo","fa-rotate-right"],["minus","fa-minus"],["link","fa-link"],["image","fa-image"],["code","fa-code"],["expand","fa-expand"],["emoji","fa-face-smile"],["icon","fa-icons"],["foreColor","fa-font"],["backColor","fa-highlighter"],["keyboard","fa-keyboard"],["remove-format","fa-remove-format"],["direction","fa-arrow-right-arrow-left"],["search","fa-magnifying-glass"],["find-replace","fa-magnifying-glass-plus"],["inline-code","fa-code"],["checklist","fa-list-check"],["print","fa-print"]]);if(this._faReady){const g=u.get(e.icon)||u.get(e.name)||null;g?a.innerHTML=`<i class="${p} ${g}" aria-hidden="true"></i>`:h.has(e.icon)?a.innerHTML=h.get(e.icon):a.textContent=e.icon||e.name}else h.has(e.icon)?a.innerHTML=h.get(e.icon):h.has(e.name)?a.innerHTML=h.get(e.name):a.textContent=e.icon||e.name;const f=d(a,"click",g=>{g.preventDefault(),this.context.invoke("editor.focus"),e.action(this.context),this.context.invoke("editor.afterCommand"),this.refresh()});return this._disposers.push(f),a}_detectFontAwesome(){if(!this.options.useFontAwesome)return!1;if(te!==null)return te;if(document.querySelector(".fa, .fas, .far, .fal, .fab, .fa-solid"))return te=!0,!0;const e=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(t=>t.id!=="an-fontawesome-css").map(t=>t.href||"").join(" ");return te=/fontawesome|font-awesome|use\.fontawesome|all\.css/.test(e),te}refresh(){if(!this.el)return;const e=this._btnMap||new Map;this.el.querySelectorAll("button[data-btn]").forEach(t=>{const i=e.get(t.getAttribute("data-btn"));i&&typeof i.isActive=="function"&&t.classList.toggle("active",!!i.isActive(this.context)),i&&typeof i.isDisabled=="function"&&(t.disabled=!!i.isDisabled(this.context))}),this.el.querySelectorAll("select[data-btn]").forEach(t=>{const i=e.get(t.getAttribute("data-btn"));if(!i||typeof i.getValue!="function")return;let s=(i.getValue(this.context)||"").replace(/["']/g,"").trim();s||(s=this.options.defaultFontFamily||this.options.fontFamilies&&this.options.fontFamilies[0]||"");const o=Array.from(t.options).find(a=>a.value&&a.value.toLowerCase()===s.toLowerCase());t.value=o?o.value:""})}show(){this.el&&(this.el.style.display="")}hide(){this.el&&(this.el.style.display="none")}}const Oe=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null;function Fe(n){const e=n.trim();if(!e)return 0;if(Oe){let t=0;for(const i of Oe.segment(e))i.isWordLike&&t++;return t}return e.split(/\s+/).length}function We(n,e,t){if(!t){n.classList.remove("an-count-warn","an-count-exceeded");return}e>t?(n.classList.add("an-count-exceeded"),n.classList.remove("an-count-warn")):e>=t*.9?(n.classList.add("an-count-warn"),n.classList.remove("an-count-exceeded")):n.classList.remove("an-count-warn","an-count-exceeded")}class Kt{constructor(e){this.context=e,this.options=e.options,this.el=null,this._disposers=[],this._wordCountEl=null,this._charCountEl=null}initialize(){if(this.el=c("div",{class:"an-statusbar"}),this.options.resizable!==!1){const t=c("div",{class:"an-resize-handle",title:"Resize editor","aria-hidden":"true"});this._bindResize(t),this.el.appendChild(t)}this._wordCountEl=c("span",{class:"an-word-count"}),this._charCountEl=c("span",{class:"an-char-count"});const e=c("div",{class:"an-status-info"});return e.appendChild(this._wordCountEl),e.appendChild(this._charCountEl),this.el.appendChild(e),this._bindContentEvents(),this.update(),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dragDisposers&&(this._dragDisposers.forEach(e=>e()),this._dragDisposers=null),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null}_bindResize(e){let t=0,i=0;const s=this.context.layoutInfo.container,o=g=>{const v=g-t,k=40,T=Array.from(s.children).filter(b=>!b.classList.contains("an-editable")).reduce((b,w)=>b+w.offsetHeight,0),C=Math.max(this.options.minHeight||100,T+k);s.style.height=`${Math.max(C,i+v)}px`},a=g=>o(g.clientY),l=()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",l),this._dragDisposers=null},r=g=>{t=g.clientY,i=s.offsetHeight,this.context.layoutInfo.editable.style.minHeight="",document.addEventListener("mousemove",a),document.addEventListener("mouseup",l),this._dragDisposers=[()=>document.removeEventListener("mousemove",a),()=>document.removeEventListener("mouseup",l)],g.preventDefault()},h=g=>{const v=g.touches[0];v&&(g.preventDefault(),o(v.clientY))},p=()=>{document.removeEventListener("touchmove",h),document.removeEventListener("touchend",p),this._dragDisposers=null},u=g=>{const v=g.touches[0];v&&(t=v.clientY,i=s.offsetHeight,this.context.layoutInfo.editable.style.minHeight="",document.addEventListener("touchmove",h,{passive:!1}),document.addEventListener("touchend",p),this._dragDisposers=[()=>document.removeEventListener("touchmove",h),()=>document.removeEventListener("touchend",p)])},m=d(e,"mousedown",r),f=d(e,"touchstart",u);this._disposers.push(m,f)}_bindContentEvents(){const e=this.context.layoutInfo.editable,t=J(()=>this.update(),200),i=d(e,"input",t);this._disposers.push(i)}update(){if(!this._wordCountEl||!this._charCountEl)return;const t=this.context.layoutInfo.editable.innerText||"",i=Fe(t),s=t.replace(/\n/g,"").length,o=this.options.maxWords||0,a=this.options.maxChars||0;this._wordCountEl.textContent=o?`Words: ${i}/${o}`:`Words: ${i}`,this._charCountEl.textContent=a?`Chars: ${s}/${a}`:`Chars: ${s}`,We(this._wordCountEl,i,o),We(this._charCountEl,s,a)}getWordCount(){const e=this.context.layoutInfo.editable;return Fe(e.innerText||"")}getCharCount(){return(this.context.layoutInfo.editable.innerText||"").replace(/\n/g,"").length}}class Gt{constructor(e){this.context=e,this.options=e.options,this._disposers=[]}initialize(){this._blobRegistry=new Map,this._forcePlain=!1;const e=this.context.layoutInfo.editable;return this._disposers.push(d(e,"paste",t=>this._onPaste(t)),d(e,"dragover",t=>this._onDragover(t)),d(e,"drop",t=>this._onDrop(t))),this._mutationObserver=new MutationObserver(t=>{for(const i of t)for(const s of i.removedNodes)this._revokeRemovedBlobs(s)}),this._mutationObserver.observe(e,{childList:!0,subtree:!0}),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._mutationObserver&&(this._mutationObserver.disconnect(),this._mutationObserver=null),this._blobRegistry&&(this._blobRegistry.forEach((e,t)=>URL.revokeObjectURL(t)),this._blobRegistry.clear())}_revokeRemovedBlobs(e){if(!this._blobRegistry||!this._blobRegistry.size)return;const t=[];e.nodeName==="IMG"?t.push(e):e.querySelectorAll&&t.push(...e.querySelectorAll("img")),t.forEach(i=>{const s=i.getAttribute("src")||"";s.startsWith("blob:")&&this._blobRegistry.has(s)&&(URL.revokeObjectURL(s),this._blobRegistry.delete(s))})}_cleanWordHtml(e){return e.replace(/<!--\[if[\s\S]*?\[endif\]-->/gi,"").replace(/<xml[\s\S]*?<\/xml>/gi,"").replace(/<\?xml[\s\S]*?\?>/gi,"").replace(/<\/?(o|w|m|v|st1):[a-z][^>]*>/gi,"").replace(/\s+class="Mso[^"]*"/gi,"").replace(/\s+style="([^"]*)"/gi,(t,i)=>{const s=i.split(";").map(o=>o.trim()).filter(o=>o&&!/^mso-/i.test(o)&&!/^(tab-stops|margin-[a-z]+-alt)/i.test(o)).join("; ");return s?` style="${s}"`:""}).replace(/<p[^>]*>\s*(&nbsp;)?\s*<\/p>/gi,"")}_cleanSocialHtml(e){const t=new DOMParser().parseFromString(`<body>${e}</body>`,"text/html"),i=new Set(["span","div"]);let s=!0;for(;s;)s=!1,t.querySelectorAll("span, div").forEach(o=>{if(!i.has(o.tagName.toLowerCase())||o.querySelector("a, strong, em, b, i, ul, ol, li, table, img, blockquote, pre, code, h1, h2, h3, h4, h5, h6"))return;const a=o.parentNode;if(a){for(;o.firstChild;)a.insertBefore(o.firstChild,o);a.removeChild(o),s=!0}});return t.querySelectorAll("*").forEach(o=>{o.removeAttribute("class"),o.removeAttribute("id"),Array.from(o.attributes).filter(a=>a.name.startsWith("data-")||a.name.startsWith("aria-")).forEach(a=>o.removeAttribute(a.name))}),t.body.innerHTML}_stripAttributes(e){const t=new DOMParser().parseFromString(`<body>${e}</body>`,"text/html"),i=new Set(["href","src","alt","target","rel","colspan","rowspan","type"]);return t.querySelectorAll("*").forEach(s=>{Array.from(s.attributes).filter(o=>!i.has(o.name)).forEach(o=>s.removeAttribute(o.name))}),t.body.innerHTML}setForcePlain(e){this._forcePlain=!!e}_onPaste(e){const t=e.clipboardData||window.clipboardData;if(!t)return;const i=this._forcePlain;if(this._forcePlain=!1,t.items){const s=Array.from(t.items).filter(o=>o.kind==="file"&&o.type.startsWith("image/"));if(s.length>0){e.preventDefault();const o=s.map(a=>a.getAsFile()).filter(Boolean);this._insertImageFiles(o);return}}if(typeof this.options.onPaste=="function"&&this.options.onPaste({text:t.getData("text/plain")||"",html:t.types.includes("text/html")?t.getData("text/html"):null}),i||this.options.pasteAsPlainText){e.preventDefault();const o=t.getData("text/plain").split(/\r?\n/).map(a=>`<p>${this._escapeHTML(a)||"<br>"}</p>`).join("");S("insertHTML",o),this.context.invoke("editor.afterCommand");return}if(this.options.markdownPaste!==!1&&!t.types.includes("text/html")){const s=t.getData("text/plain");if(s&&Vt(s)){e.preventDefault();const o=V(De(s));S("insertHTML",o),this.context.invoke("editor.afterCommand");return}}if(this.options.pasteCleanHTML!==!1&&t.types.includes("text/html")){e.preventDefault();const s=t.getData("text/html"),o=/<[a-z]+:[a-z]/i.test(s)||/class="Mso/i.test(s)||/\bmso-/i.test(s),a=/\bdata-testid\b/.test(s)||/class="[^"]*\b(?:x[a-z0-9]{6,}|r-[a-z0-9]{3,})\b/.test(s);let l=s;o?l=this._cleanWordHtml(l):a&&(l=this._cleanSocialHtml(l)),l=V(l),this.options.pasteStripAttributes&&(l=this._stripAttributes(l)),S("insertHTML",l),this.context.invoke("editor.afterCommand");return}}_onDragover(e){if(!e.dataTransfer)return;Array.from(e.dataTransfer.types||[]).includes("Files")&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")}_onDrop(e){const t=e.dataTransfer;if(!t||!t.files||t.files.length===0)return;const i=Array.from(t.files).filter(s=>s.type.startsWith("image/"));i.length!==0&&(e.preventDefault(),e.stopPropagation(),this._placeCaretAtPoint(e.clientX,e.clientY),this._insertImageFiles(i))}_insertImageFiles(e){if(!e||e.length===0)return;if(typeof this.options.onImageUpload=="function"){this.options.onImageUpload(e);return}const t=(this.options.maxImageSize||5)*1024*1024;e.forEach(i=>{if(!i||!i.type.startsWith("image/"))return;if(i.size>t){const o=`Image "${i.name}" exceeds the ${this.options.maxImageSize||5} MB size limit.`;this.context.triggerEvent("imageError",{file:i,message:o}),console.warn(`[AutumnNote] ${o}`);return}const s=i.name.replace(/\.[^.]+$/,"");this._compressImage(i).then(o=>{const a=this._dataUrlToBlob(o),l=URL.createObjectURL(a);this._blobRegistry.set(l,o),this.context.invoke("editor.insertImage",l,s)}).catch(o=>{var l;const a=`Image "${i.name}" could not be processed.`;this.context.triggerEvent("imageError",{file:i,message:a,error:o}),(typeof process>"u"||((l=process.env)==null?void 0:l.NODE_ENV)!=="production")&&console.warn("[AutumnNote]",a,o)})})}resolveImages(e){return!this._blobRegistry||!this._blobRegistry.size?e:e.replace(/blob:[^"'> \t\n\r]*/g,t=>this._blobRegistry.get(t)||t)}_dataUrlToBlob(e){const[t,i]=e.split(","),s=t.match(/:(.*?);/)[1],o=atob(i),a=new Uint8Array(o.length);for(let l=0;l<o.length;l++)a[l]=o.charCodeAt(l);return new Blob([a],{type:s})}_compressImage(e){return new Promise(s=>{const o=URL.createObjectURL(e),a=new Image;a.onload=()=>{URL.revokeObjectURL(o);let{width:l,height:r}=a;(l>1920||r>1920)&&(l>=r?(r=Math.round(r*1920/l),l=1920):(l=Math.round(l*1920/r),r=1920));const h=document.createElement("canvas");h.width=l,h.height=r;const p=h.getContext("2d");if(!p){const m=new FileReader;m.onload=f=>s(f.target.result),m.readAsDataURL(e);return}p.drawImage(a,0,0,l,r);const u=h.toDataURL("image/webp",.85);s(u.startsWith("data:image/webp")?u:h.toDataURL("image/jpeg",.85))},a.onerror=()=>{URL.revokeObjectURL(o);const l=new FileReader;l.onload=r=>s(r.target.result),l.readAsDataURL(e)},a.src=o})}_placeCaretAtPoint(e,t){let i;if(document.caretRangeFromPoint)i=document.caretRangeFromPoint(e,t);else if(document.caretPositionFromPoint){const o=document.caretPositionFromPoint(e,t);o&&(i=document.createRange(),i.setStart(o.offsetNode,o.offset),i.collapse(!0))}if(!i)return;const s=window.getSelection();s&&(s.removeAllRanges(),s.addRange(i))}_escapeHTML(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}}class Qt{constructor(e){this.context=e,this.options=e.options,this._disposers=[]}initialize(){const e=this.context.layoutInfo.editable,t=this.options.placeholder||"";t&&(e.dataset.placeholder=t);const i=()=>this._update(),s=d(e,"input",i),o=d(e,"focus",i),a=d(e,"blur",i);return this._disposers.push(s,o,a),this._update(),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[]}_update(){const e=this.context.layoutInfo.editable,t=document.activeElement===e,i=!e.textContent.trim()&&!e.querySelector("img, table, hr");e.classList.toggle("an-placeholder",i&&!t)}}class Zt{constructor(e){this.context=e,this.options=e.options,this._active=!1,this._textarea=null,this._disposers=[]}initialize(){return this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._textarea&&this._textarea.parentNode&&this._textarea.parentNode.removeChild(this._textarea),this._textarea=null}toggle(){this._active?this.deactivate():this.activate()}isActive(){return this._active}activate(){if(this._active)return;const{editable:e}=this.context.layoutInfo,t=e.innerHTML;this._textarea=c("textarea",{class:"an-codeview",spellcheck:"false",autocomplete:"off",autocorrect:"off",autocapitalize:"off"}),this._textarea.value=this._prettyPrint(t),e.style.display="none",e.parentNode.insertBefore(this._textarea,e.nextSibling),this._active=!0,this.context.invoke("toolbar.refresh")}deactivate(){if(!this._active||!this._textarea)return;const{editable:e}=this.context.layoutInfo;e.innerHTML=V(this._textarea.value,{allowIframes:!0}),this._textarea.parentNode.removeChild(this._textarea),this._textarea=null,e.style.display="",this._active=!1,this.context.invoke("toolbar.refresh"),this.context.invoke("editor.afterCommand")}_prettyPrint(e){const t=/^<(a|abbr|b|bdo|br|button|cite|code|dfn|em|i|img|input|kbd|label|output|q|samp|select|small|span|strong|sub|sup|textarea|time|tt|u|var)([\s>/])/i;let i=0;return e.replace(/>\s*</g,(s,o,a)=>{const l=a.slice(o+1);return t.test(l.trimStart())?"><":`>
67
+ `),e=[];let i=0;for(;i<t.length;){const s=t[i],o=s.match(/^```(\S*)$/);if(o){const l=o[1],h=[];for(i++;i<t.length&&!t[i].startsWith("```");)h.push($(t[i])),i++;const m=l?` class="language-${lt(l)}"`:"";e.push(`<pre><code${m}>${h.join(`
68
+ `)}</code></pre>`),i++;continue}if(/^(-{3,}|\*{3,}|_{3,})\s*$/.test(s)){e.push("<hr>"),i++;continue}const n=s.match(/^(#{1,6})\s+(.+)$/);if(n){const l=n[1].length;e.push(`<h${l}>${K(n[2])}</h${l}>`),i++;continue}if(s.startsWith("> ")){const l=[];for(;i<t.length&&t[i].startsWith("> ");)l.push(t[i].slice(2)),i++;e.push(`<blockquote>${l.map(K).join("<br>")}</blockquote>`);continue}if(/^[-*+] /.test(s)){const l=[];for(;i<t.length&&/^[-*+] /.test(t[i]);)l.push(`<li>${K(t[i].slice(2))}</li>`),i++;e.push(`<ul>${l.join("")}</ul>`);continue}if(/^\d+\. /.test(s)){const l=[];for(;i<t.length&&/^\d+\. /.test(t[i]);)l.push(`<li>${K(t[i].replace(/^\d+\. /,""))}</li>`),i++;e.push(`<ol>${l.join("")}</ol>`);continue}if(s.trim()===""){i++;continue}if(/^\|.+\|/.test(s)&&i+1<t.length&&/^\|[\s|:-]+\|/.test(t[i+1])){const l=Wt(s);i+=2;const h=[];for(;i<t.length&&/^\|.+\|/.test(t[i]);)h.push(Wt(t[i])),i++;const m=`<thead><tr>${l.map(u=>`<th>${K(u)}</th>`).join("")}</tr></thead>`,d=h.length?`<tbody>${h.map(u=>`<tr>${u.map(f=>`<td>${K(f)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";e.push(`<table>${m}${d}</table>`);continue}const r=[];for(;i<t.length&&t[i].trim()!==""&&!/^(#{1,6} |> |[-*+] |\d+\. |```|---\s*$|\*{3}\s*$|_{3}\s*$)/.test(t[i])&&!/^\|.+\|/.test(t[i]);)r.push(t[i]),i++;r.length&&e.push(`<p>${K(r.join(" "))}</p>`)}return e.join("")}function Wt(a){return a.replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function K(a){return a=a.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(t,e,i)=>`<img src="${lt(i)}" alt="${lt(e)}" class="an-image">`),a=a.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(t,e,i)=>`<a href="${lt(i)}">${$(e)}</a>`),a=a.replace(/\*{3}(.+?)\*{3}/g,(t,e)=>`<strong><em>${$(e)}</em></strong>`),a=a.replace(/_{3}(.+?)_{3}/g,(t,e)=>`<strong><em>${$(e)}</em></strong>`),a=a.replace(/\*{2}(.+?)\*{2}/g,(t,e)=>`<strong>${$(e)}</strong>`),a=a.replace(/_{2}(.+?)_{2}/g,(t,e)=>`<strong>${$(e)}</strong>`),a=a.replace(/\*([^*\n]+?)\*/g,(t,e)=>`<em>${$(e)}</em>`),a=a.replace(/_([^_\n]+?)_/g,(t,e)=>`<em>${$(e)}</em>`),a=a.replace(/~~(.+?)~~/g,(t,e)=>`<del>${$(e)}</del>`),a=a.replace(/`([^`]+)`/g,(t,e)=>`<code>${$(e)}</code>`),a}function $(a){return String(a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function lt(a){return String(a).replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}class Ge{constructor(t){this.context=t,this.options=t.options,this._history=null,this._disposers=[],this._snapshotTimer=null}initialize(){const t=this.context.layoutInfo.editable;return this._history=new qe(t,this.options.historyLimit||100),this._bindEvents(t),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._history=null,clearTimeout(this._snapshotTimer),this._snapshotTimer=null}_bindEvents(t){const e=l=>this._onKeydown(l),i=()=>this.afterCommand(),s=l=>this._enforceLimit(l),o=()=>{if(!this.context._alive)return;const l=window.getSelection();l&&l.rangeCount>0&&t.contains(l.anchorNode)&&(this.context.invoke("toolbar.refresh"),typeof this.options.onSelectionChange=="function"&&this.options.onSelectionChange(this.context))},n=l=>{l.target.type==="checkbox"&&l.target.closest(".an-checklist")&&this.afterCommand()},r=l=>{const h=window.getSelection();if(!h||!h.rangeCount)return;const m=h.getRangeAt(0);if(!m.collapsed)return;const d=m.startContainer;if(d.nodeType!==Node.ELEMENT_NODE)return;const u=d.matches&&d.matches(".an-checklist li")?d:null;if(!u)return;const f=u.querySelector('input[type="checkbox"]');if(!f)return;if(l&&l.type==="mouseup"){let b=null;if(document.caretRangeFromPoint)b=document.caretRangeFromPoint(l.clientX,l.clientY);else if(document.caretPositionFromPoint){const T=document.caretPositionFromPoint(l.clientX,l.clientY);T&&(b=document.createRange(),b.setStart(T.offsetNode,T.offset))}if(b&&t.contains(b.startContainer)&&b.startContainer!==u){b.collapse(!0),h.removeAllRanges(),h.addRange(b);return}}const g=document.createRange();let _=null;for(const b of u.childNodes)if(b!==f&&b.nodeType===Node.TEXT_NODE){_=b;break}_?g.setStart(_,0):g.setStartAfter(f),g.collapse(!0),h.removeAllRanges(),h.addRange(g)};this._disposers.push(p(t,"keydown",e),p(t,"beforeinput",s),p(t,"input",i),p(document,"selectionchange",o),p(t,"click",n),p(t,"mouseup",r),p(t,"keyup",r))}_onKeydown(t){const e=this.context.layoutInfo.editable;if(!Ye(t,e,this.options)){if(H(t,"z")&&!t.shiftKey){t.preventDefault(),this.undo();return}if(H(t,"z")&&t.shiftKey||H(t,"y")){t.preventDefault(),this.redo();return}if(H(t,"b")){t.preventDefault(),this.bold();return}if(H(t,"i")){t.preventDefault(),this.italic();return}if(H(t,"u")){t.preventDefault(),this.underline();return}if(H(t,"k")){t.preventDefault(),this.context.invoke("linkDialog.show");return}if(H(t,"v")&&t.shiftKey){this.context.invoke("clipboard.setForcePlain",!0);return}if(t.key==="/"&&t.shiftKey&&t.ctrlKey&&!t.metaKey){t.preventDefault(),this.context.invoke("shortcutsDialog.show");return}if(H(t,"f")){t.preventDefault(),this.context.invoke("findReplace.show","find");return}H(t,"h")&&(t.preventDefault(),this.context.invoke("findReplace.show","replace")),H(t,"`")&&(t.preventDefault(),this.inlineCode())}}_enforceLimit(t){const e=this.options.maxChars||0,i=this.options.maxWords||0;if(!e&&!i)return;const s=t.inputType||"";if(s.startsWith("delete")||s==="historyUndo"||s==="historyRedo"||s==="insertFromPaste"||s==="insertFromDrop"||!s.startsWith("insert"))return;const o=this.context.layoutInfo.editable.innerText||"",n=o.replace(/\n/g,"").length;if(e&&n>=e){t.preventDefault(),typeof this.options.onCharLimitReached=="function"&&this.options.onCharLimitReached(this.context);return}i&&(t.data===" "||s==="insertParagraph"||s==="insertLineBreak")&&(o.trim()?o.trim().split(/\s+/).length:0)>=i&&(t.preventDefault(),typeof this.options.onWordLimitReached=="function"&&this.options.onWordLimitReached(this.context))}afterCommand(){this.context.invoke("toolbar.refresh"),this.context.invoke("statusbar.update"),this._scheduleSnapshot()}_scheduleSnapshot(){clearTimeout(this._snapshotTimer),this._snapshotTimer=setTimeout(()=>{this._snapshotTimer=null,this._history&&this._history.recordUndo(),this.context.triggerEvent("change",this.getHTML())},400)}focus(){this.context.layoutInfo.editable.focus()}getHTML(){const t=this.context.layoutInfo.editable.innerHTML.replace(/\u200B/g,"");return this.context.invoke("clipboard.resolveImages",t)??t}setHTML(t){this.context.layoutInfo.editable.innerHTML=X(t),this._history&&this._history.reset(),this.afterCommand()}getText(){return this.context.layoutInfo.editable.innerText||""}setText(t){this.context.layoutInfo.editable.textContent=t,this._history&&this._history.reset(),this.afterCommand()}clear(){this.setHTML("")}clearHistory(){this._history&&this._history.reset()}isEmpty(){const t=(this.context.layoutInfo.editable.innerText||"").trim().replace(/\u00a0/g,""),e=!!this.context.layoutInfo.editable.querySelector("img, video, iframe, table");return!t&&!e}insertHTML(t){t&&(S("insertHTML",X(t)),this.afterCommand())}insertText(t){t&&(S("insertText",t),this.afterCommand())}setMarkdown(t){this.setHTML(Ft(t||""))}getMarkdown(){return Xe(this.getHTML())}undo(){this._history&&(clearTimeout(this._snapshotTimer),this._snapshotTimer=null,this._history.undo(),this.context.invoke("toolbar.refresh"),this.context.invoke("statusbar.update"),this.context.triggerEvent("change",this.getHTML()))}redo(){this._history&&(clearTimeout(this._snapshotTimer),this._snapshotTimer=null,this._history.redo(),this.context.invoke("toolbar.refresh"),this.context.invoke("statusbar.update"),this.context.triggerEvent("change",this.getHTML()))}canUndo(){return this._history?this._history.canUndo():!1}canRedo(){return this._history?this._history.canRedo():!1}bold(){wt(),this.afterCommand()}italic(){xt(),this.afterCommand()}underline(){Ct(),this.afterCommand()}strikethrough(){kt(),this.afterCommand()}superscript(){Tt(),this.afterCommand()}subscript(){St(),this.afterCommand()}justifyLeft(){Bt(),this.afterCommand()}justifyCenter(){Mt(),this.afterCommand()}justifyRight(){Nt(),this.afterCommand()}justifyFull(){jt(),this.afterCommand()}indent(){zt(),this.afterCommand()}outdent(){Ht(),this.afterCommand()}insertUL(){$t(),this.afterCommand()}insertOL(){Dt(),this.afterCommand()}inlineCode(){ee(this.context.layoutInfo.editable),this.afterCommand()}toggleChecklist(){se(),this.afterCommand()}print(){this.context.print()}formatBlock(t){Lt(t),this.afterCommand()}foreColor(t){Et(t),this.afterCommand()}backColor(t){It(t),this.afterCommand()}fontName(t){Rt(t),this.afterCommand()}fontSize(t){At(t,this.context.layoutInfo.editable),this.afterCommand()}insertHr(){S("insertHorizontalRule"),this.afterCommand()}insertLink(t,e,i=!1){const s=window.getSelection();if(!s||s.rangeCount===0)return;const o=Ot(t);if(!o)return;if(s.toString().trim().length>0){if(S("createLink",o),i){const r=this._getClosestAnchor();r&&(r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer"))}}else{const r=this._escapeAttr(e||o);S("insertHTML",`<a href="${this._escapeAttr(o)}"${i?' target="_blank" rel="noopener noreferrer"':""}>${r}</a>`)}this.afterCommand()}unlink(){S("unlink"),this.afterCommand()}insertImage(t,e="",i=""){const s=Ot(t,{allowData:!0});if(!s)return;const n={left:"float:left;margin:0 1em 1em 0",center:"display:block;margin:0 auto",right:"float:right;margin:0 0 1em 1em"}[i]||"",r=n?` style="${n}"`:"";S("insertHTML",`<img src="${this._escapeAttr(s)}" alt="${this._escapeAttr(e)}" class="an-image"${r}>`),this.afterCommand()}insertVideo(t){t&&(S("insertHTML",t),this.afterCommand())}insertTable(t,e){Ve(t,e,{headerRow:this.context.options.tableHeaderRow}),this.afterCommand()}_getClosestAnchor(){const t=window.getSelection();if(!t||t.rangeCount===0)return null;let e=t.getRangeAt(0).startContainer;for(;e;){if(e.nodeName==="A")return e;e=e.parentNode}return null}_escapeAttr(t){return String(t??"").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}}let st=null;class Qe{constructor(t){this.context=t,this.options=t.options,this.el=null,this._disposers=[],this._colorPickerClosers=[]}initialize(){return this.el=c("div",{class:"an-toolbar"}),this._faReady=this._detectFontAwesome(),this._buildButtons(),this._btnMap=new Map((this.options.toolbar||[]).flat().map(t=>[t.name,t])),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null}_buildButtons(){(this.options.toolbar||[]).forEach(e=>{const i=c("div",{class:"an-btn-group"});e.forEach(s=>{let o;s.type==="select"?o=this._createSelect(s):s.type==="grid"?o=this._createGridPicker(s):s.type==="colorpicker"?o=this._createColorPicker(s):o=this._createButton(s),i.appendChild(o)}),this.el.appendChild(i)})}_createGridPicker(t){const s=c("div",{class:"an-table-picker-wrap"}),n=!!this.options.useBootstrap?this.options.toolbarButtonClass||"btn btn-sm btn-light":"an-btn",r=c("button",{type:"button",class:n,title:t.tooltip||"","data-btn":t.name,"aria-label":t.tooltip||t.name,"aria-haspopup":"true","aria-expanded":"false"});if(this._faReady){const y=this.options.fontAwesomeClass||"fas";r.innerHTML=`<i class="${y} fa-table" aria-hidden="true"></i>`}else{const y='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';r.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${y} style="display:block"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>`}const l=c("div",{class:"an-table-picker-popup",role:"dialog","aria-label":"Select table size"}),h=c("div",{class:"an-table-grid"}),m=c("div",{class:"an-table-label"});m.textContent="Insert Table";const d=[];for(let y=1;y<=10;y++)for(let v=1;v<=10;v++){const E=c("div",{class:"an-table-cell","data-row":String(y),"data-col":String(v)});d.push(E),h.appendChild(E)}l.appendChild(h),l.appendChild(m);let u=!1;const f=(y,v)=>{d.forEach(E=>{const R=+E.getAttribute("data-row"),B=+E.getAttribute("data-col");E.classList.toggle("active",R<=y&&B<=v)}),m.textContent=y&&v?`${y} × ${v}`:"Insert Table"},g=()=>{u=!0,l.style.display="block",r.setAttribute("aria-expanded","true")},_=()=>{u=!1,l.style.display="none",r.setAttribute("aria-expanded","false"),f(0,0)},b=p(r,"click",y=>{y.stopPropagation(),u?_():g()}),T=p(h,"mouseover",y=>{const v=y.target.closest(".an-table-cell");v&&f(+v.getAttribute("data-row"),+v.getAttribute("data-col"))}),k=p(h,"mouseleave",()=>f(0,0)),w=p(h,"click",y=>{const v=y.target.closest(".an-table-cell");if(!v)return;const E=+v.getAttribute("data-row"),R=+v.getAttribute("data-col");_(),this.context.invoke("editor.focus"),t.action(this.context,E,R)}),x=p(document,"click",()=>{u&&_()});return this._disposers.push(b,T,k,w,x),s.appendChild(r),s.appendChild(l),s}_createColorPicker(t){const e=["#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#efefef","#ffffff","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#9900ff","#ff00ff","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#d9d2e9","#ead1dc"];let i=t.defaultColor||"#000000";const s=c("div",{class:"an-color-picker-wrap"}),n=!!this.options.useBootstrap?this.options.toolbarButtonClass||"btn btn-sm btn-light":"an-btn",r=c("button",{type:"button",class:`${n} an-color-btn`,title:t.tooltip||"","data-btn":t.name,"aria-label":t.tooltip||t.name}),l='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"',h=t.name==="foreColor"?`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${l} style="display:block"><path d="M4 20L12 4L20 20"/><line x1="7.5" y1="14" x2="16.5" y2="14"/></svg>`:`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${l} style="display:block"><path d="M3 21v-4l9-9 4 4-9 9z"/><path d="M12 8l4 4"/></svg>`;r.innerHTML=h;const m=c("span",{class:"an-color-strip"});m.style.background=i,r.appendChild(m);const d=c("button",{type:"button",class:`${n} an-color-arrow`,title:`Choose ${t.name==="foreColor"?"text":"highlight"} color`,"aria-haspopup":"true","aria-expanded":"false"});d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 24 24" fill="currentColor" stroke="none" style="display:block"><path d="M7 10l5 5 5-5H7z"/></svg>';const u=c("div",{class:"an-color-popup"});u.style.display="none";const f=c("div",{class:"an-color-swatches"}),g=Array.isArray(this.options.colorSwatches)?this.options.colorSwatches:[];[...new Set([...g,...e])].forEach(C=>{const A=c("div",{class:"an-color-swatch",title:C,"data-color":C});A.style.background=C,f.appendChild(A)});const b=c("div",{class:"an-color-custom"}),T=c("input",{type:"color",value:i,title:"Custom color"}),k=c("span",{},["Custom color"]);b.appendChild(T),b.appendChild(k),u.appendChild(f),u.appendChild(b);let w=!1,x=null;const y=()=>{const C=window.getSelection();x=C&&C.rangeCount?C.getRangeAt(0).cloneRange():null},v=()=>{if(!x)return;const C=window.getSelection();C&&(C.removeAllRanges(),C.addRange(x))},E=()=>{this._colorPickerClosers.forEach(dt=>{dt!==R&&dt()}),y(),w=!0;const C=d.getBoundingClientRect(),A=184;let N=C.left;N+A>window.innerWidth&&(N=C.right-A),u.style.top=`${C.bottom+4}px`,u.style.left=`${Math.max(4,N)}px`,u.style.display="block",d.setAttribute("aria-expanded","true")},R=()=>{w=!1,u.style.display="none",u.style.top="",u.style.left="",d.setAttribute("aria-expanded","false")},B=C=>{i=C,m.style.background=C,T.value=C,v(),t.action(this.context,C),this.context.invoke("editor.afterCommand"),R()},L=p(r,"click",C=>{C.preventDefault(),v(),t.action(this.context,i),this.context.invoke("editor.afterCommand")}),q=p(d,"mousedown",C=>{C.preventDefault()}),Q=p(d,"click",C=>{C.stopPropagation(),w?R():E()}),Z=p(f,"mousedown",C=>{C.preventDefault()}),z=p(f,"click",C=>{const A=C.target.closest(".an-color-swatch");A&&B(A.dataset.color)}),mt=p(T,"change",C=>{B(C.target.value)}),ft=p(document,"click",C=>{w&&!s.contains(C.target)&&!u.contains(C.target)&&R()}),gt=p(u,"click",C=>C.stopPropagation()),tt=()=>{w&&R()};return document.addEventListener("scroll",tt,{passive:!0,capture:!0}),window.addEventListener("resize",tt,{passive:!0}),this._disposers.push(L,q,Q,Z,z,mt,ft,gt,()=>document.removeEventListener("scroll",tt,{capture:!0}),()=>window.removeEventListener("resize",tt),()=>{u.parentNode&&u.parentNode.removeChild(u)}),this._colorPickerClosers.push(R),this._disposers.push(()=>{const C=this._colorPickerClosers.indexOf(R);C!==-1&&this._colorPickerClosers.splice(C,1)}),s.appendChild(r),s.appendChild(d),document.body.appendChild(u),s}_createSelect(t){const e=t.name==="fontFamily"?this.options.fontFamilies||[]:t.items||[],i=t.selectClass?`an-select ${t.selectClass}`:"an-select",s=c("select",{class:i,title:t.tooltip||"","data-btn":t.name,"aria-label":t.tooltip||t.name}),o=t.placeholder||"Font",n=c("option",{value:"",disabled:"",hidden:""},[o]);s.appendChild(n),e.forEach(l=>{const h=typeof l=="object"?l.value:l,m=typeof l=="object"?l.label:l,d=typeof l=="object"&&!!l.disabled,u={value:h};d&&(u.disabled="");const f=c("option",u,[m]);t.name==="fontFamily"&&!d&&(f.style.fontFamily=h),s.appendChild(f)});const r=p(s,"change",l=>{const h=l.target.value,m=l.target.options[l.target.selectedIndex];!h||m.disabled||(this.context.invoke("editor.focus"),t.action(this.context,h),this.context.invoke("editor.afterCommand"))});return this._disposers.push(r),s}_createButton(t){const i=!!this.options.useBootstrap?this.options.toolbarButtonClass||"btn btn-sm btn-light":"an-btn",s=t.className?` ${t.className}`:"",o=`${i}${s}`,n=c("button",{type:"button",class:o,title:t.tooltip||"","data-btn":t.name,"aria-label":t.tooltip||t.name}),r='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"',l=g=>`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${r} style="display:block">${g}</svg>`,h=new Map([["bold",l('<path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/>')],["italic",l('<line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/>')],["underline",l('<path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" y1="21" x2="20" y2="21"/>')],["strikethrough",l('<path d="M17.3 12H6.7"/><path d="M10 6.5C10 5.1 11.1 4 12.5 4c1.4 0 2.5 1.1 2.5 2.5 0 .8-.4 1.5-1 2"/><path d="M14 17.5C14 19 12.9 20 11.5 20 10.1 20 9 18.9 9 17.5c0-.8.4-1.5 1-2"/>')],["superscript",l('<path d="m4 19 8-8"/><path d="m12 19-8-8"/><path d="M20 12h-4c0-1.5.44-2 1.5-2.5S20 8.33 20 7.25C20 6 19 5 17.5 5S15 6 15 7"/>')],["subscript",l('<path d="m4 5 8 8"/><path d="m12 5-8 8"/><path d="M20 21h-4c0-1.5.44-2 1.5-2.5S20 17.33 20 16.25C20 15 19 14 17.5 14S15 15 15 16"/>')],["align-left",l('<line x1="21" y1="6" x2="3" y2="6"/><line x1="15" y1="12" x2="3" y2="12"/><line x1="17" y1="18" x2="3" y2="18"/>')],["align-center",l('<line x1="21" y1="6" x2="3" y2="6"/><line x1="18" y1="12" x2="6" y2="12"/><line x1="21" y1="18" x2="3" y2="18"/>')],["align-right",l('<line x1="21" y1="6" x2="3" y2="6"/><line x1="21" y1="12" x2="9" y2="12"/><line x1="21" y1="18" x2="7" y2="18"/>')],["align-justify",l('<line x1="21" y1="6" x2="3" y2="6"/><line x1="21" y1="12" x2="3" y2="12"/><line x1="21" y1="18" x2="3" y2="18"/>')],["list-ul",l('<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4" cy="6" r="1" fill="currentColor" stroke="none"/><circle cx="4" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="4" cy="18" r="1" fill="currentColor" stroke="none"/>')],["list-ol",l('<line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/><path d="M4 6h1V3"/><path d="M4 10h2l-2 2h2"/><path d="M4 16.5A1.5 1.5 0 0 1 5.5 15a1.5 1.5 0 0 1 0 3H4"/>')],["indent",l('<polyline points="3 8 7 12 3 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/>')],["outdent",l('<polyline points="7 8 3 12 7 16"/><line x1="21" y1="12" x2="11" y2="12"/><line x1="21" y1="6" x2="11" y2="6"/><line x1="21" y1="18" x2="11" y2="18"/>')],["undo",l('<path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/>')],["redo",l('<path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"/>')],["minus",l('<line x1="5" y1="12" x2="19" y2="12"/>')],["link",l('<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>')],["image",l('<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/>')],["video",l('<polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/>')],["table",l('<rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/>')],["emoji",l('<circle cx="12" cy="12" r="10"/><path d="M8.5 14.5s1.5 2.5 3.5 2.5 3.5-2.5 3.5-2.5"/><circle cx="9" cy="9" r="1.5" fill="currentColor" stroke="none"/><circle cx="15" cy="9" r="1.5" fill="currentColor" stroke="none"/>')],["icon",l('<circle cx="8" cy="8" r="3"/><circle cx="16" cy="8" r="3"/><rect x="5" y="13" width="6" height="6" rx="1"/><rect x="13" y="13" width="6" height="6" rx="1"/>')],["code",l('<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>')],["expand",l('<polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/>')],["foreColor",l('<path d="M4 20L12 4L20 20"/><line x1="7.5" y1="14" x2="16.5" y2="14"/>')],["backColor",l('<path d="M3 21v-4l9-9 4 4-9 9z"/><path d="M12 8l4 4"/>')],["keyboard",l('<rect x="2" y="6" width="20" height="12" rx="2"/><line x1="6" y1="10" x2="6" y2="10" stroke-width="2.5"/><line x1="10" y1="10" x2="10" y2="10" stroke-width="2.5"/><line x1="14" y1="10" x2="14" y2="10" stroke-width="2.5"/><line x1="18" y1="10" x2="18" y2="10" stroke-width="2.5"/><line x1="8" y1="14" x2="16" y2="14" stroke-width="2"/>')],["caption",l('<rect x="3" y="3" width="18" height="11" rx="2"/><line x1="6" y1="18" x2="18" y2="18"/><line x1="9" y1="21" x2="15" y2="21"/>')],["remove-format",l('<path d="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/>')],["direction",l('<path d="M12 20V4"/><path d="m9 7-3 3 3 3"/><path d="M4 10h8"/><path d="m15 7 3 3-3 3"/><path d="M20 10h-8"/>')],["search",l('<circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>')],["find-replace",l('<circle cx="10" cy="10" r="6"/><line x1="18" y1="18" x2="14.35" y2="14.35"/><path d="M16 19h6"/><path d="M19 16v6"/>')],["inline-code",l('<path d="M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1"/><path d="M16 3h1a2 2 0 0 1 2 2v5c0 1.1.9 2 2 2a2 2 0 0 1-2 2v5a2 2 0 0 1-2 2h-1"/>')],["checklist",l('<rect x="3" y="4" width="5" height="5" rx="1"/><path d="m4 6.5 1 1 2-2"/><rect x="3" y="13" width="5" height="5" rx="1"/><line x1="10" y1="6.5" x2="21" y2="6.5"/><line x1="10" y1="15.5" x2="21" y2="15.5"/>')],["print",l('<path d="M6 9V2h12v7"/><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/><rect x="6" y="14" width="12" height="8"/>')]]),m=this.options.fontAwesomeClass||"fas",d=new Map([["bold","fa-bold"],["italic","fa-italic"],["underline","fa-underline"],["strikethrough","fa-strikethrough"],["superscript","fa-superscript"],["subscript","fa-subscript"],["align-left","fa-align-left"],["align-center","fa-align-center"],["align-right","fa-align-right"],["align-justify","fa-align-justify"],["list-ul","fa-list-ul"],["list-ol","fa-list-ol"],["indent","fa-indent"],["outdent","fa-outdent"],["undo","fa-rotate-left"],["redo","fa-rotate-right"],["minus","fa-minus"],["link","fa-link"],["image","fa-image"],["code","fa-code"],["expand","fa-expand"],["emoji","fa-face-smile"],["icon","fa-icons"],["foreColor","fa-font"],["backColor","fa-highlighter"],["keyboard","fa-keyboard"],["remove-format","fa-remove-format"],["direction","fa-arrow-right-arrow-left"],["search","fa-magnifying-glass"],["find-replace","fa-magnifying-glass-plus"],["inline-code","fa-code"],["checklist","fa-list-check"],["print","fa-print"]]);if(this._faReady){const g=d.get(t.icon)||d.get(t.name)||null;g?n.innerHTML=`<i class="${m} ${g}" aria-hidden="true"></i>`:h.has(t.icon)?n.innerHTML=h.get(t.icon):n.textContent=t.icon||t.name}else h.has(t.icon)?n.innerHTML=h.get(t.icon):h.has(t.name)?n.innerHTML=h.get(t.name):n.textContent=t.icon||t.name;const f=p(n,"click",g=>{g.preventDefault(),this.context.invoke("editor.focus"),t.action(this.context),this.context.invoke("editor.afterCommand"),this.refresh()});return this._disposers.push(f),n}_detectFontAwesome(){if(!this.options.useFontAwesome)return!1;if(st!==null)return st;if(document.querySelector(".fa, .fas, .far, .fal, .fab, .fa-solid"))return st=!0,!0;const t=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(e=>e.id!=="an-fontawesome-css").map(e=>e.href||"").join(" ");return st=/fontawesome|font-awesome|use\.fontawesome|all\.css/.test(t),st}refresh(){if(!this.el)return;const t=this._btnMap||new Map;this.el.querySelectorAll("button[data-btn]").forEach(e=>{const i=t.get(e.getAttribute("data-btn"));i&&typeof i.isActive=="function"&&e.classList.toggle("active",!!i.isActive(this.context)),i&&typeof i.isDisabled=="function"&&(e.disabled=!!i.isDisabled(this.context))}),this.el.querySelectorAll("select[data-btn]").forEach(e=>{const i=t.get(e.getAttribute("data-btn"));if(!i||typeof i.getValue!="function")return;let s=(i.getValue(this.context)||"").replace(/["']/g,"").trim();s||(s=this.options.defaultFontFamily||this.options.fontFamilies&&this.options.fontFamilies[0]||"");const o=Array.from(e.options).find(n=>n.value&&n.value.toLowerCase()===s.toLowerCase());e.value=o?o.value:""})}show(){this.el&&(this.el.style.display="")}hide(){this.el&&(this.el.style.display="none")}}const qt=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null;function Ut(a){const t=a.trim();if(!t)return 0;if(qt){let e=0;for(const i of qt.segment(t))i.isWordLike&&e++;return e}return t.split(/\s+/).length}function Vt(a,t,e){if(!e){a.classList.remove("an-count-warn","an-count-exceeded");return}t>e?(a.classList.add("an-count-exceeded"),a.classList.remove("an-count-warn")):t>=e*.9?(a.classList.add("an-count-warn"),a.classList.remove("an-count-exceeded")):a.classList.remove("an-count-warn","an-count-exceeded")}class Ze{constructor(t){this.context=t,this.options=t.options,this.el=null,this._disposers=[],this._wordCountEl=null,this._charCountEl=null}initialize(){if(this.el=c("div",{class:"an-statusbar"}),this.options.resizable!==!1){const e=c("div",{class:"an-resize-handle",title:"Resize editor","aria-hidden":"true"});this._bindResize(e),this.el.appendChild(e)}this._wordCountEl=c("span",{class:"an-word-count"}),this._charCountEl=c("span",{class:"an-char-count"});const t=c("div",{class:"an-status-info"});return t.appendChild(this._wordCountEl),t.appendChild(this._charCountEl),this.el.appendChild(t),this._bindContentEvents(),this.update(),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dragDisposers&&(this._dragDisposers.forEach(t=>t()),this._dragDisposers=null),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null}_bindResize(t){let e=0,i=0;const s=this.context.layoutInfo.container,o=g=>{const _=g-e,b=40,T=Array.from(s.children).filter(w=>!w.classList.contains("an-editable")).reduce((w,x)=>w+x.offsetHeight,0),k=Math.max(this.options.minHeight||100,T+b);s.style.height=`${Math.max(k,i+_)}px`},n=g=>o(g.clientY),r=()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),this._dragDisposers=null},l=g=>{e=g.clientY,i=s.offsetHeight,this.context.layoutInfo.editable.style.minHeight="",document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),this._dragDisposers=[()=>document.removeEventListener("mousemove",n),()=>document.removeEventListener("mouseup",r)],g.preventDefault()},h=g=>{const _=g.touches[0];_&&(g.preventDefault(),o(_.clientY))},m=()=>{document.removeEventListener("touchmove",h),document.removeEventListener("touchend",m),this._dragDisposers=null},d=g=>{const _=g.touches[0];_&&(e=_.clientY,i=s.offsetHeight,this.context.layoutInfo.editable.style.minHeight="",document.addEventListener("touchmove",h,{passive:!1}),document.addEventListener("touchend",m),this._dragDisposers=[()=>document.removeEventListener("touchmove",h),()=>document.removeEventListener("touchend",m)])},u=p(t,"mousedown",l),f=p(t,"touchstart",d);this._disposers.push(u,f)}_bindContentEvents(){const t=this.context.layoutInfo.editable,e=et(()=>this.update(),200),i=p(t,"input",e);this._disposers.push(i)}update(){if(!this._wordCountEl||!this._charCountEl)return;const e=this.context.layoutInfo.editable.innerText||"",i=Ut(e),s=e.replace(/\n/g,"").length,o=this.options.maxWords||0,n=this.options.maxChars||0;this._wordCountEl.textContent=o?`Words: ${i}/${o}`:`Words: ${i}`,this._charCountEl.textContent=n?`Chars: ${s}/${n}`:`Chars: ${s}`,Vt(this._wordCountEl,i,o),Vt(this._charCountEl,s,n)}getWordCount(){const t=this.context.layoutInfo.editable;return Ut(t.innerText||"")}getCharCount(){return(this.context.layoutInfo.editable.innerText||"").replace(/\n/g,"").length}}class Je{constructor(t){this.context=t,this.options=t.options,this._disposers=[]}initialize(){this._blobRegistry=new Map,this._forcePlain=!1;const t=this.context.layoutInfo.editable;return this._disposers.push(p(t,"paste",e=>this._onPaste(e)),p(t,"dragover",e=>this._onDragover(e)),p(t,"drop",e=>this._onDrop(e))),this._mutationObserver=new MutationObserver(e=>{for(const i of e)for(const s of i.removedNodes)this._revokeRemovedBlobs(s)}),this._mutationObserver.observe(t,{childList:!0,subtree:!0}),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._mutationObserver&&(this._mutationObserver.disconnect(),this._mutationObserver=null),this._blobRegistry&&(this._blobRegistry.forEach((t,e)=>URL.revokeObjectURL(e)),this._blobRegistry.clear())}_revokeRemovedBlobs(t){if(!this._blobRegistry||!this._blobRegistry.size)return;const e=[];t.nodeName==="IMG"?e.push(t):t.querySelectorAll&&e.push(...t.querySelectorAll("img")),e.forEach(i=>{const s=i.getAttribute("src")||"";s.startsWith("blob:")&&this._blobRegistry.has(s)&&(URL.revokeObjectURL(s),this._blobRegistry.delete(s))})}_cleanWordHtml(t){return t.replace(/<!--\[if[\s\S]*?\[endif\]-->/gi,"").replace(/<xml[\s\S]*?<\/xml>/gi,"").replace(/<\?xml[\s\S]*?\?>/gi,"").replace(/<\/?(o|w|m|v|st1):[a-z][^>]*>/gi,"").replace(/\s+class="Mso[^"]*"/gi,"").replace(/\s+style="([^"]*)"/gi,(e,i)=>{const s=i.split(";").map(o=>o.trim()).filter(o=>o&&!/^mso-/i.test(o)&&!/^(tab-stops|margin-[a-z]+-alt)/i.test(o)).join("; ");return s?` style="${s}"`:""}).replace(/<p[^>]*>\s*(&nbsp;)?\s*<\/p>/gi,"")}_cleanSocialHtml(t){const e=new DOMParser().parseFromString(`<body>${t}</body>`,"text/html"),i=new Set(["span","div"]);let s=!0;for(;s;)s=!1,e.querySelectorAll("span, div").forEach(o=>{if(!i.has(o.tagName.toLowerCase())||o.querySelector("a, strong, em, b, i, ul, ol, li, table, img, blockquote, pre, code, h1, h2, h3, h4, h5, h6"))return;const n=o.parentNode;if(n){for(;o.firstChild;)n.insertBefore(o.firstChild,o);n.removeChild(o),s=!0}});return e.querySelectorAll("*").forEach(o=>{o.removeAttribute("class"),o.removeAttribute("id"),Array.from(o.attributes).filter(n=>n.name.startsWith("data-")||n.name.startsWith("aria-")).forEach(n=>o.removeAttribute(n.name))}),e.body.innerHTML}_stripAttributes(t){const e=new DOMParser().parseFromString(`<body>${t}</body>`,"text/html"),i=new Set(["href","src","alt","target","rel","colspan","rowspan","type"]);return e.querySelectorAll("*").forEach(s=>{Array.from(s.attributes).filter(o=>!i.has(o.name)).forEach(o=>s.removeAttribute(o.name))}),e.body.innerHTML}setForcePlain(t){this._forcePlain=!!t}_onPaste(t){const e=t.clipboardData||window.clipboardData;if(!e)return;const i=this._forcePlain;if(this._forcePlain=!1,e.items){const s=Array.from(e.items).filter(o=>o.kind==="file"&&o.type.startsWith("image/"));if(s.length>0){t.preventDefault();const o=s.map(n=>n.getAsFile()).filter(Boolean);this._insertImageFiles(o);return}}if(typeof this.options.onPaste=="function"&&this.options.onPaste({text:e.getData("text/plain")||"",html:e.types.includes("text/html")?e.getData("text/html"):null}),i||this.options.pasteAsPlainText){t.preventDefault();const o=e.getData("text/plain").split(/\r?\n/).map(n=>`<p>${this._escapeHTML(n)||"<br>"}</p>`).join("");S("insertHTML",o),this.context.invoke("editor.afterCommand");return}if(this.options.markdownPaste!==!1&&!e.types.includes("text/html")){const s=e.getData("text/plain");if(s&&Ke(s)){t.preventDefault();const o=X(Ft(s));S("insertHTML",o),this.context.invoke("editor.afterCommand");return}}if(this.options.pasteCleanHTML!==!1&&e.types.includes("text/html")){t.preventDefault();const s=e.getData("text/html"),o=/<[a-z]+:[a-z]/i.test(s)||/class="Mso/i.test(s)||/\bmso-/i.test(s),n=/\bdata-testid\b/.test(s)||/class="[^"]*\b(?:x[a-z0-9]{6,}|r-[a-z0-9]{3,})\b/.test(s);let r=s;o?r=this._cleanWordHtml(r):n&&(r=this._cleanSocialHtml(r)),r=X(r),this.options.pasteStripAttributes&&(r=this._stripAttributes(r)),S("insertHTML",r),this.context.invoke("editor.afterCommand");return}}_onDragover(t){if(!t.dataTransfer)return;Array.from(t.dataTransfer.types||[]).includes("Files")&&(t.preventDefault(),t.dataTransfer.dropEffect="copy")}_onDrop(t){const e=t.dataTransfer;if(!e||!e.files||e.files.length===0)return;const i=Array.from(e.files).filter(s=>s.type.startsWith("image/"));i.length!==0&&(t.preventDefault(),t.stopPropagation(),this._placeCaretAtPoint(t.clientX,t.clientY),this._insertImageFiles(i))}_insertImageFiles(t){if(!t||t.length===0)return;if(typeof this.options.onImageUpload=="function"){this.options.onImageUpload(t);return}const e=(this.options.maxImageSize||5)*1024*1024;t.forEach(i=>{if(!i||!i.type.startsWith("image/"))return;if(i.size>e){const o=`Image "${i.name}" exceeds the ${this.options.maxImageSize||5} MB size limit.`;this.context.triggerEvent("imageError",{file:i,message:o}),console.warn(`[AutumnNote] ${o}`);return}const s=i.name.replace(/\.[^.]+$/,"");this._compressImage(i).then(o=>{const n=this._dataUrlToBlob(o),r=URL.createObjectURL(n);this._blobRegistry.set(r,o),this.context.invoke("editor.insertImage",r,s)}).catch(o=>{var r;const n=`Image "${i.name}" could not be processed.`;this.context.triggerEvent("imageError",{file:i,message:n,error:o}),(typeof process>"u"||((r=process.env)==null?void 0:r.NODE_ENV)!=="production")&&console.warn("[AutumnNote]",n,o)})})}resolveImages(t){return!this._blobRegistry||!this._blobRegistry.size?t:t.replace(/blob:[^"'> \t\n\r]*/g,e=>this._blobRegistry.get(e)||e)}_dataUrlToBlob(t){const[e,i]=t.split(","),s=e.match(/:(.*?);/)[1],o=atob(i),n=new Uint8Array(o.length);for(let r=0;r<o.length;r++)n[r]=o.charCodeAt(r);return new Blob([n],{type:s})}_compressImage(t){return new Promise(s=>{const o=URL.createObjectURL(t),n=new Image;n.onload=()=>{URL.revokeObjectURL(o);let{width:r,height:l}=n;(r>1920||l>1920)&&(r>=l?(l=Math.round(l*1920/r),r=1920):(r=Math.round(r*1920/l),l=1920));const h=document.createElement("canvas");h.width=r,h.height=l;const m=h.getContext("2d");if(!m){const u=new FileReader;u.onload=f=>s(f.target.result),u.readAsDataURL(t);return}m.drawImage(n,0,0,r,l);const d=h.toDataURL("image/webp",.85);s(d.startsWith("data:image/webp")?d:h.toDataURL("image/jpeg",.85))},n.onerror=()=>{URL.revokeObjectURL(o);const r=new FileReader;r.onload=l=>s(l.target.result),r.readAsDataURL(t)},n.src=o})}_placeCaretAtPoint(t,e){let i;if(document.caretRangeFromPoint)i=document.caretRangeFromPoint(t,e);else if(document.caretPositionFromPoint){const o=document.caretPositionFromPoint(t,e);o&&(i=document.createRange(),i.setStart(o.offsetNode,o.offset),i.collapse(!0))}if(!i)return;const s=window.getSelection();s&&(s.removeAllRanges(),s.addRange(i))}_escapeHTML(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}}class ti{constructor(t){this.context=t,this.options=t.options,this._disposers=[]}initialize(){const t=this.context.layoutInfo.editable,e=this.options.placeholder||"";e&&(t.dataset.placeholder=e);const i=()=>this._update(),s=p(t,"input",i),o=p(t,"focus",i),n=p(t,"blur",i);return this._disposers.push(s,o,n),this._update(),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[]}_update(){const t=this.context.layoutInfo.editable,e=document.activeElement===t,i=!t.textContent.trim()&&!t.querySelector("img, table, hr");t.classList.toggle("an-placeholder",i&&!e)}}class ei{constructor(t){this.context=t,this.options=t.options,this._active=!1,this._textarea=null,this._disposers=[]}initialize(){return this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._textarea&&this._textarea.parentNode&&this._textarea.parentNode.removeChild(this._textarea),this._textarea=null}toggle(){this._active?this.deactivate():this.activate()}isActive(){return this._active}activate(){if(this._active)return;const{editable:t}=this.context.layoutInfo,e=t.innerHTML;this._textarea=c("textarea",{class:"an-codeview",spellcheck:"false",autocomplete:"off",autocorrect:"off",autocapitalize:"off"}),this._textarea.value=this._prettyPrint(e),t.style.display="none",t.parentNode.insertBefore(this._textarea,t.nextSibling),this._active=!0,this.context.invoke("toolbar.refresh")}deactivate(){if(!this._active||!this._textarea)return;const{editable:t}=this.context.layoutInfo;t.innerHTML=X(this._textarea.value,{allowIframes:!0}),this._textarea.parentNode.removeChild(this._textarea),this._textarea=null,t.style.display="",this._active=!1,this.context.invoke("toolbar.refresh"),this.context.invoke("editor.afterCommand")}_prettyPrint(t){const e=/^<(a|abbr|b|bdo|br|button|cite|code|dfn|em|i|img|input|kbd|label|output|q|samp|select|small|span|strong|sub|sup|textarea|time|tt|u|var)([\s>/])/i;let i=0;return t.replace(/>\s*</g,(s,o,n)=>{const r=n.slice(o+1);return e.test(r.trimStart())?"><":`>
69
69
  <`}).split(`
70
- `).map(s=>{const o=s.trim();if(!o)return"";/^<\//.test(o)&&(i=Math.max(0,i-1));const a=" ".repeat(i)+o;return/^<[^/!][^>]*[^/]>/.test(o)&&!t.test(o)&&!/^<(br|hr|img|input|link|meta)/.test(o)&&i++,a}).filter(Boolean).join(`
71
- `)}}class Jt{constructor(e){this.context=e,this._active=!1,this._disposers=[],this._prevHeight=""}initialize(){const e=d(document,"keydown",t=>{this._active&&D(t,O.ESCAPE)&&this.deactivate()});return this._disposers.push(e),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._active&&this.deactivate()}toggle(){this._active?this.deactivate():this.activate()}isActive(){return this._active}activate(){if(this._active)return;const e=this.context.layoutInfo.container;this._prevHeight=e.style.height,e.classList.add("an-fullscreen"),e.style.height="",document.body.style.overflow="hidden",this._active=!0,this.context.invoke("toolbar.refresh")}deactivate(){if(!this._active)return;const e=this.context.layoutInfo.container;e.classList.remove("an-fullscreen"),e.style.height=this._prevHeight,document.body.style.overflow="",this._active=!1,this.context.invoke("toolbar.refresh")}}class ei{constructor(e){this.context=e,this.options=e.options,this._dialog=null,this._disposers=[],this._savedRange=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){ee(e=>{this._savedRange=e}),this._prefill(),this._open()}_buildDialog(){const e=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert link"}),t=c("div",{class:"an-dialog-box"}),i=c("h3",{class:"an-dialog-title"});i.textContent="Insert Link";const s=c("label",{class:"an-label"});s.textContent="URL";const o=c("input",{type:"url",class:"an-input",placeholder:"https://",id:"an-link-url",name:"url",autocomplete:"off"});this._urlInput=o;const a=c("label",{class:"an-label"});a.textContent="Display Text";const l=c("input",{type:"text",class:"an-input",placeholder:"Link text",id:"an-link-text",name:"linkText",autocomplete:"off"});this._textInput=l;const r=c("label",{class:"an-label an-label-inline"}),h=c("input",{type:"checkbox",id:"an-link-newtab",name:"openInNewTab"});this._tabCheckbox=h,r.appendChild(h),r.appendChild(document.createTextNode(" Open in new tab"));const p=c("div",{class:"an-dialog-actions"}),u=c("button",{type:"button",class:"an-btn an-btn-primary"});u.textContent="Insert";const m=c("button",{type:"button",class:"an-btn"});m.textContent="Cancel",p.appendChild(u),p.appendChild(m),t.append(i,s,o,a,l,r,p),e.appendChild(t);const f=d(u,"click",()=>this._onInsert()),g=d(m,"click",()=>this._close()),v=d(e,"click",C=>{C.target===e&&this._close()}),k=d(o,"keydown",C=>{C.key==="Enter"&&(C.preventDefault(),this._onInsert())}),T=d(l,"keydown",C=>{C.key==="Enter"&&(C.preventDefault(),this._onInsert())});return this._disposers.push(f,g,v,k,T),e}_prefill(){const e=window.getSelection();let t=null;if(e&&e.rangeCount>0){let i=e.getRangeAt(0).startContainer;for(;i;){if(i.nodeName==="A"){t=i;break}i=i.parentNode}}t?(this._urlInput.value=t.getAttribute("href")||"",this._textInput.value=t.textContent||"",this._tabCheckbox.checked=t.getAttribute("target")==="_blank"):(this._urlInput.value="",this._textInput.value=e?e.toString():"",this._tabCheckbox.checked=!1)}_onInsert(){let e=this._urlInput.value.trim();const t=this._textInput.value.trim(),i=this._tabCheckbox.checked;if(!e){this._urlInput.focus();return}/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(e)||(e="https://"+e);try{const s=new URL(e);if(/^javascript:/i.test(s.protocol)||/^vbscript:/i.test(s.protocol)||/^data:/i.test(s.protocol)){this._urlInput.focus();return}}catch{this._urlInput.focus();return}this._savedRange&&this._savedRange.select(),this.context.invoke("editor.insertLink",e,t,i),this._close()}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=q(this._dialog,()=>this._close()),setTimeout(()=>this._urlInput&&this._urlInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}}class ti{constructor(e){this.context=e,this.options=e.options,this._dialog=null,this._disposers=[],this._savedRange=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){ee(e=>{this._savedRange=e}),this._urlInput.value="",this._altInput.value="",this._fileInput&&(this._fileInput.value=""),this._open()}_buildDialog(){const e=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert image"}),t=c("div",{class:"an-dialog-box"}),i=c("h3",{class:"an-dialog-title"});i.textContent="Insert Image";const s=c("label",{class:"an-label"});s.textContent="Image URL";const o=c("input",{type:"url",class:"an-input",placeholder:"https://example.com/image.png",autocomplete:"off"});this._urlInput=o;const a=c("label",{class:"an-label"});a.textContent="Alt Text";const l=c("input",{type:"text",class:"an-input",placeholder:"Describe the image",autocomplete:"off"});this._altInput=l,t.append(i,s,o,a,l);const r=c("label",{class:"an-label"});r.textContent="Alignment";const h=c("div",{class:"an-align-row"});if([{value:"",label:"None"},{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}].forEach(({value:b,label:w})=>{const _=`an-align-${b||"none"}`,y=c("input",{type:"radio",name:"an-img-align",id:_,value:b});b===""&&(y.checked=!0);const I=c("label",{for:_,class:"an-align-label"});I.textContent=w,h.append(y,I)}),this._alignRow=h,t.append(r,h),this.options.allowImageUpload!==!1){const b=c("label",{class:"an-label"});b.textContent="Or upload a file";const w=c("input",{type:"file",class:"an-input",accept:"image/*"});this._fileInput=w;const _=d(w,"change",()=>this._onFileChange());this._disposers.push(_),t.append(b,w)}const u=c("div",{class:"an-dialog-actions"}),m=c("button",{type:"button",class:"an-btn an-btn-primary"});m.textContent="Insert";const f=c("button",{type:"button",class:"an-btn"});f.textContent="Cancel",u.appendChild(m),u.appendChild(f),t.append(u),e.appendChild(t);const g=d(m,"click",()=>this._onInsert()),v=d(f,"click",()=>this._close()),k=d(e,"click",b=>{b.target===e&&this._close()}),T=d(o,"keydown",b=>{b.key==="Enter"&&(b.preventDefault(),this._onInsert())}),C=d(l,"keydown",b=>{b.key==="Enter"&&(b.preventDefault(),this._onInsert())});return this._disposers.push(g,v,k,T,C),e}_onFileChange(){const e=this._fileInput&&this._fileInput.files&&this._fileInput.files[0];if(!e||!e.type.startsWith("image/"))return;const t=(this.options.maxImageSize||5)*1024*1024;if(e.size>t){const s=`Image file is too large. Maximum allowed size is ${this.options.maxImageSize||5} MB.`;console.warn("[AutumnNote] ImageDialog:",s),this.context.triggerEvent("imageError",{file:e,message:s}),this._fileInput.value="";return}const i=new FileReader;i.onload=s=>{this._urlInput.value=s.target.result},i.readAsDataURL(e)}_onInsert(){const e=this._urlInput.value.trim(),t=this._altInput.value.trim(),i=this._alignRow&&this._alignRow.querySelector('input[name="an-img-align"]:checked'),s=i?i.value:"";if(!e){this._urlInput.focus();return}this._savedRange&&this._savedRange.select(),this.context.invoke("editor.insertImage",e,t,s),this._close()}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=q(this._dialog,()=>this._close()),setTimeout(()=>this._urlInput&&this._urlInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}}class ii{constructor(e){this.context=e,this.options=e.options,this._dialog=null,this._disposers=[],this._savedRange=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){ee(e=>{this._savedRange=e}),this._urlInput.value="",this._widthInput.value="560",this._hintEl.textContent="",this._open()}_buildDialog(){const e=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert video"}),t=c("div",{class:"an-dialog-box"}),i=c("h3",{class:"an-dialog-title"});i.textContent="Insert Video";const s=c("label",{class:"an-label"});s.textContent="Video URL";const o=c("input",{type:"url",class:"an-input",placeholder:"YouTube, Vimeo, or direct .mp4 URL",autocomplete:"off"});this._urlInput=o;const a=c("p",{class:"an-dialog-hint"});this._hintEl=a;const l=c("label",{class:"an-label"});l.textContent="Width (px)";const r=c("input",{type:"number",class:"an-input",placeholder:"560",min:"80",max:"1920",value:"560"});this._widthInput=r;const h=c("div",{class:"an-dialog-actions"}),p=c("button",{type:"button",class:"an-btn an-btn-primary"});p.textContent="Insert";const u=c("button",{type:"button",class:"an-btn"});u.textContent="Cancel",h.appendChild(p),h.appendChild(u),t.append(i,s,o,a,l,r,h),e.appendChild(t);const m=d(o,"input",()=>{const T=this._parseVideoUrl(o.value.trim());a.textContent=T?`Detected: ${T.type}`:o.value?"Unknown format — will try direct video embed":""}),f=d(p,"click",()=>this._onInsert()),g=d(u,"click",()=>this._close()),v=d(e,"click",T=>{T.target===e&&this._close()}),k=d(o,"keydown",T=>{T.key==="Enter"&&(T.preventDefault(),this._onInsert())});return this._disposers.push(m,f,g,v,k),e}_onInsert(){const e=this._urlInput.value.trim(),t=Math.max(80,parseInt(this._widthInput.value,10)||560);if(!e){this._urlInput.focus();return}const i=this._buildEmbedHtml(e,t);if(!i){this._hintEl.textContent="Invalid URL — please enter a valid video link.",this._urlInput.focus();return}this._savedRange&&this._savedRange.select(),this.context.invoke("editor.insertVideo",i),this._close()}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=q(this._dialog,()=>this._close()),setTimeout(()=>this._urlInput&&this._urlInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}_parseVideoUrl(e){if(!e)return null;try{const a=new URL(e);if(/^javascript:/i.test(a.protocol)||/^vbscript:/i.test(a.protocol))return null}catch{return null}const t=e.match(/(?:youtube\.com\/watch\?(?:.*&)?v=|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/);if(t)return{type:"YouTube",embedUrl:`https://www.youtube.com/embed/${t[1]}`};const i=e.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);if(i)return{type:"YouTube",embedUrl:`https://www.youtube.com/embed/${i[1]}`};const s=e.match(/youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/);if(s)return{type:"YouTube Shorts",embedUrl:`https://www.youtube.com/embed/${s[1]}`};const o=e.match(/vimeo\.com\/(\d+)/);return o?{type:"Vimeo",embedUrl:`https://player.vimeo.com/video/${o[1]}`}:/\.(mp4|webm|ogg|ogv|mov)(#.*|\?.*)?$/i.test(e)?{type:"Direct video",embedUrl:e}:null}_buildEmbedHtml(e,t){const i=this._parseVideoUrl(e),s=Math.round(t*9/16);if(i&&(i.type==="YouTube"||i.type==="YouTube Shorts"||i.type==="Vimeo")){const l=`${i.type} video player`;return`<div class="an-video-wrapper" style="position:relative;display:block;width:${t}px;max-width:100%"><iframe src="${i.embedUrl}" width="${t}" height="${s}" title="${l}" frameborder="0" allowfullscreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" style="display:block;max-width:100%"></iframe><div class="an-video-shield"></div></div>`}if(i&&i.type==="Direct video"){const l=i.embedUrl.replace(/"/g,"%22");return`<div class="an-video-wrapper" style="position:relative;display:block;width:${t}px;max-width:100%"><video src="${l}" width="${t}" height="${s}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`}const o=(()=>{try{const l=new URL(e);return/^javascript:/i.test(l.protocol)||/^vbscript:/i.test(l.protocol)?null:e}catch{return null}})();if(!o)return null;const a=o.replace(/"/g,"%22");return`<div class="an-video-wrapper" style="position:relative;display:block;width:${t}px;max-width:100%"><video src="${a}" width="${t}" height="${s}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`}}const si=[{pos:"nw",cursor:"nw-resize"},{pos:"n",cursor:"n-resize"},{pos:"ne",cursor:"ne-resize"},{pos:"e",cursor:"e-resize"},{pos:"se",cursor:"se-resize"},{pos:"s",cursor:"s-resize"},{pos:"sw",cursor:"sw-resize"},{pos:"w",cursor:"w-resize"}];class oi{constructor(e){this.context=e,this._activeImg=null,this._overlay=null,this._disposers=[],this._positionRaf=null}initialize(){this._overlay=this._buildOverlay();const e=this.context.layoutInfo.editable.closest(".an-container")||document.body;e.appendChild(this._overlay),this._container=e;const t=this.context.layoutInfo.editable;let i=null;const s=()=>{clearTimeout(i),i=setTimeout(()=>this._updateOverlayPosition(),100)};return this._disposers.push(d(t,"click",o=>this._onEditorClick(o)),d(t,"contextmenu",o=>{const a=o.target.closest("img");a&&this._select(a)}),d(document,"click",o=>this._onDocClick(o)),d(window,"scroll",()=>this._updateOverlayPosition(),{passive:!0}),d(window,"resize",s),d(t,"scroll",()=>this._updateOverlayPosition(),{passive:!0})),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dragDisposers&&(this._dragDisposers.forEach(e=>e()),this._dragDisposers=null),this._positionRaf&&(cancelAnimationFrame(this._positionRaf),this._positionRaf=null),this._deselect(),this._overlay&&this._overlay.parentNode&&this._overlay.parentNode.removeChild(this._overlay),this._overlay=null}getActiveImage(){return this._activeImg}updateOverlay(){this._updateOverlayPosition()}deselect(){this._deselect()}_buildOverlay(){const e=document.createElement("div");return e.className="an-image-resizer",e.style.display="none",si.forEach(({pos:t})=>{const i=document.createElement("div");i.className=`an-resize-handle an-resize-${t}`,i.dataset.handle=t,this._disposers.push(d(i,"mousedown",s=>{s.preventDefault(),s.stopPropagation(),this._startResize(s,t)})),e.appendChild(i)}),e}_onEditorClick(e){const t=e.target.closest("img");t&&(e.preventDefault(),this._select(t))}_onDocClick(e){this._activeImg&&e.target!==this._activeImg&&(this._overlay&&this._overlay.contains(e.target)||e.target.closest(".an-contextmenu")||this._deselect())}_select(e){this._activeImg&&this._activeImg!==e&&this._activeImg.classList.remove("an-image-selected"),this._activeImg=e,e.classList.add("an-image-selected"),this._updateOverlayPosition(),this._overlay.style.display="block"}_deselect(){this._activeImg&&(this._activeImg.classList.remove("an-image-selected"),this._activeImg=null),this._overlay&&(this._overlay.style.display="none")}_updateOverlayPosition(){this._positionRaf&&cancelAnimationFrame(this._positionRaf),this._positionRaf=requestAnimationFrame(()=>{this._positionRaf=null,this._updateOverlayPositionNow()})}_updateOverlayPositionNow(){if(!this._activeImg||!this._overlay)return;const e=this._overlay.offsetParent||this._container,t=e.getBoundingClientRect(),i=this._activeImg.getBoundingClientRect(),s=i.left-t.left+e.scrollLeft,o=i.top-t.top+e.scrollTop;this._overlay.style.left=`${s}px`,this._overlay.style.top=`${o}px`,this._overlay.style.width=`${i.width}px`,this._overlay.style.height=`${i.height}px`}_startResize(e,t){const i=this._activeImg;if(!i)return;const s=e.clientX,o=e.clientY,a=i.offsetWidth||i.naturalWidth||100,l=i.offsetHeight||i.naturalHeight||100,r=a/l,h=t.length===2,p=this.context.layoutInfo.editable;let u=null;const m=g=>{if(u!==null)return;const v=g.clientX,k=g.clientY;u=requestAnimationFrame(()=>{u=null;const T=v-s,C=k-o,b=p.clientWidth||1/0;let w=a,_=l;t.includes("e")&&(w=Math.max(20,a+T)),t.includes("w")&&(w=Math.max(20,a-T)),t.includes("s")&&(_=Math.max(20,l+C)),t.includes("n")&&(_=Math.max(20,l-C)),w=Math.min(w,b),h&&(Math.abs(T)>=Math.abs(C)||(w=Math.min(Math.max(20,Math.round(_*r)),b)),_=Math.max(20,Math.round(w/r))),i.style.width=`${w}px`,i.style.height=`${_}px`,this._updateOverlayPosition()})},f=()=>{u!==null&&(cancelAnimationFrame(u),u=null),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",f),this._dragDisposers=null,this.context.invoke("editor.afterCommand")};document.addEventListener("mousemove",m),document.addEventListener("mouseup",f),this._dragDisposers=[()=>document.removeEventListener("mousemove",m),()=>document.removeEventListener("mouseup",f)]}}const ni=[{pos:"nw",cursor:"nw-resize"},{pos:"n",cursor:"n-resize"},{pos:"ne",cursor:"ne-resize"},{pos:"e",cursor:"e-resize"},{pos:"se",cursor:"se-resize"},{pos:"s",cursor:"s-resize"},{pos:"sw",cursor:"sw-resize"},{pos:"w",cursor:"w-resize"}];class ai{constructor(e){this.context=e,this._activeWrapper=null,this._overlay=null,this._disposers=[],this._positionRaf=null}initialize(){this._overlay=this._buildOverlay();const e=this.context.layoutInfo.editable.closest(".an-container")||document.body;e.appendChild(this._overlay),this._container=e;const t=this.context.layoutInfo.editable;let i=null;const s=()=>{clearTimeout(i),i=setTimeout(()=>this._updateOverlayPosition(),100)};return this._disposers.push(d(t,"click",o=>this._onEditorClick(o)),d(t,"contextmenu",o=>{const a=this._findWrapper(o.target);a&&this._select(a)}),d(document,"click",o=>this._onDocClick(o)),d(window,"scroll",()=>this._updateOverlayPosition(),{passive:!0}),d(window,"resize",s),d(t,"scroll",()=>this._updateOverlayPosition(),{passive:!0})),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dragDisposers&&(this._dragDisposers.forEach(e=>e()),this._dragDisposers=null),this._positionRaf&&(cancelAnimationFrame(this._positionRaf),this._positionRaf=null),this._deselect(),this._overlay&&this._overlay.parentNode&&this._overlay.parentNode.removeChild(this._overlay),this._overlay=null}getActiveWrapper(){return this._activeWrapper}updateOverlay(){this._updateOverlayPosition()}deselect(){this._deselect()}_findWrapper(e){if(!e||!(e instanceof Element))return null;if(e.classList&&e.classList.contains("an-video-wrapper"))return e;const t=e.closest(".an-video-wrapper");return t||null}_buildOverlay(){const e=document.createElement("div");return e.className="an-video-resizer",e.style.display="none",ni.forEach(({pos:t})=>{const i=document.createElement("div");i.className=`an-resize-handle an-resize-${t}`,i.dataset.handle=t,this._disposers.push(d(i,"mousedown",s=>{s.preventDefault(),s.stopPropagation(),this._startResize(s,t)})),e.appendChild(i)}),e}_onEditorClick(e){const t=this._findWrapper(e.target);t&&(e.preventDefault(),this._select(t))}_onDocClick(e){this._activeWrapper&&(this._activeWrapper.contains(e.target)||this._overlay&&this._overlay.contains(e.target)||e.target.closest(".an-contextmenu")||this._deselect())}_select(e){this._activeWrapper&&this._activeWrapper!==e&&this._activeWrapper.classList.remove("an-video-selected"),this._activeWrapper=e,e.classList.add("an-video-selected"),this._updateOverlayPosition(),this._overlay.style.display="block"}_deselect(){this._activeWrapper&&(this._activeWrapper.classList.remove("an-video-selected"),this._activeWrapper=null),this._overlay&&(this._overlay.style.display="none")}_updateOverlayPosition(){this._positionRaf&&cancelAnimationFrame(this._positionRaf),this._positionRaf=requestAnimationFrame(()=>{this._positionRaf=null,this._updateOverlayPositionNow()})}_updateOverlayPositionNow(){if(!this._activeWrapper||!this._overlay)return;const e=this._overlay.offsetParent||this._container,t=e.getBoundingClientRect(),i=this._activeWrapper.getBoundingClientRect(),s=i.left-t.left+e.scrollLeft,o=i.top-t.top+e.scrollTop;this._overlay.style.left=`${s}px`,this._overlay.style.top=`${o}px`,this._overlay.style.width=`${i.width}px`,this._overlay.style.height=`${i.height}px`}_startResize(e,t){const i=this._activeWrapper;if(!i)return;const s=i.querySelector("iframe, video"),o=e.clientX,a=e.clientY,l=i.offsetWidth||560,r=i.offsetHeight||315,h=l/r,p=t.length===2,u=this.context.layoutInfo.editable;let m=null;const f=v=>{if(m!==null)return;const k=v.clientX,T=v.clientY;m=requestAnimationFrame(()=>{m=null;const C=k-o,b=T-a,w=u.clientWidth||1/0;let _=l,y=r;t.includes("e")&&(_=Math.max(80,l+C)),t.includes("w")&&(_=Math.max(80,l-C)),t.includes("s")&&(y=Math.max(45,r+b)),t.includes("n")&&(y=Math.max(45,r-b)),_=Math.min(_,w),p&&(Math.abs(C)>=Math.abs(b)||(_=Math.min(Math.max(80,Math.round(y*h)),w)),y=Math.max(45,Math.round(_/h))),i.style.width=`${_}px`,i.style.height=`${y}px`,s&&(s.style.width=`${_}px`,s.style.height=`${y}px`),this._updateOverlayPosition()})},g=()=>{m!==null&&(cancelAnimationFrame(m),m=null),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g),this._dragDisposers=null,this.context.invoke("editor.afterCommand")};document.addEventListener("mousemove",f),document.addEventListener("mouseup",g),this._dragDisposers=[()=>document.removeEventListener("mousemove",f),()=>document.removeEventListener("mouseup",g)]}}const ae={open:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',edit:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',unlink:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18.84 12.25l1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71"/><path d="M5.17 11.75l-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71"/><line x1="8" y1="2" x2="8" y2="5"/><line x1="2" y1="8" x2="5" y2="8"/><line x1="16" y1="19" x2="16" y2="22"/><line x1="19" y1="16" x2="22" y2="16"/></svg>',copy:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>'},li=120,ri=200;class ci{constructor(e){this.context=e,this._el=null,this._activeAnchor=null,this._showTimer=null,this._hideTimer=null,this._disposers=[]}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el);const e=this.context.layoutInfo.editable;return this._disposers.push(d(e,"mouseover",t=>{const i=t.target.closest("a[href]");i&&e.contains(i)&&this._scheduleShow(i)}),d(e,"mouseout",t=>{const i=t.relatedTarget;(!i||!e.contains(i)&&!this._el.contains(i))&&this._scheduleHide()})),this}destroy(){this._clearTimers(),this._disposers.forEach(e=>e()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const e=c("div",{class:"an-link-tooltip",role:"toolbar","aria-label":"Link actions"});return e.style.display="none",this._urlLabel=c("span",{class:"an-link-tooltip-url"}),e.appendChild(this._urlLabel),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._openBtn=this._makeBtn(ae.open,"Open link",()=>this._openLink()),this._copyBtn=this._makeBtn(ae.copy,"Copy URL",()=>this._copyLink()),this._editBtn=this._makeBtn(ae.edit,"Edit link",()=>this._editLink()),this._unlinkBtn=this._makeBtn(ae.unlink,"Remove link",()=>this._unlink()),e.appendChild(this._openBtn),e.appendChild(this._copyBtn),e.appendChild(this._editBtn),e.appendChild(this._unlinkBtn),this._disposers.push(d(e,"mouseenter",()=>this._clearTimers()),d(e,"mouseleave",()=>this._scheduleHide())),e}_makeBtn(e,t,i){const s=c("button",{type:"button",class:"an-link-tooltip-btn",title:t});return s.innerHTML=e,this._disposers.push(d(s,"click",o=>{o.preventDefault(),o.stopPropagation(),i()})),s}_scheduleShow(e){this._activeAnchor===e&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeAnchor=e,this._show(e)},li))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>{this._hide()},ri))}_show(e){const t=e.getAttribute("href")||"";this._urlLabel.textContent=this._truncateUrl(t),this._urlLabel.title=t,this._el.style.display="flex",this._positionNear(e)}_hide(){this._el.style.display="none",this._activeAnchor=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(e){const t=e.getBoundingClientRect(),i=this._el.offsetWidth||260,s=this._el.offsetHeight||34,o=6;let a=t.bottom+o,l=t.left;a+s>window.innerHeight-o&&(a=t.top-s-o),l+i>window.innerWidth-o&&(l=window.innerWidth-i-o),l<o&&(l=o),this._el.style.top=`${a}px`,this._el.style.left=`${l}px`}_truncateUrl(e){try{const t=new URL(e),i=t.host+(t.pathname!=="/"?t.pathname:"");return i.length>48?i.slice(0,48)+"…":i}catch{return e.length>48?e.slice(0,48)+"…":e}}_openLink(){const e=this._activeAnchor&&this._activeAnchor.getAttribute("href");e&&window.open(e,"_blank","noopener,noreferrer"),this._hide()}_copyLink(){const e=this._activeAnchor&&this._activeAnchor.getAttribute("href");e&&navigator.clipboard.writeText(e).catch(()=>{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}),this._copyBtn&&(this._copyBtn.classList.add("an-link-tooltip-btn--copied"),setTimeout(()=>this._copyBtn&&this._copyBtn.classList.remove("an-link-tooltip-btn--copied"),1e3))}_editLink(){const e=this._activeAnchor;if(!e)return;this._hide();const t=window.getSelection(),i=document.createRange();i.selectNodeContents(e),t.removeAllRanges(),t.addRange(i),this.context.invoke("linkDialog.show")}_unlink(){const e=this._activeAnchor;if(!e)return;this._hide();const t=window.getSelection(),i=document.createRange();i.selectNode(e),t.removeAllRanges(),t.addRange(i),document.execCommand("unlink"),this.context.invoke("editor.afterCommand")}}const P={floatLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="8" height="8" rx="1"/><line x1="12" y1="6" x2="22" y2="6"/><line x1="12" y1="9" x2="22" y2="9"/><line x1="12" y1="12" x2="22" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="14" y="4" width="8" height="8" rx="1"/><line x1="2" y1="6" x2="12" y2="6"/><line x1="2" y1="9" x2="12" y2="9"/><line x1="2" y1="12" x2="12" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatNone:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="8" height="8" rx="1"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="3" y1="19" x2="17" y2="19"/></svg>',alignCenter:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="4" width="10" height="8" rx="1"/><line x1="3" y1="16" x2="21" y2="16"/><line x1="6" y1="20" x2="18" y2="20"/></svg>',originalSize:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',deleteImg:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>',caption:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="11" rx="2"/><line x1="6" y1="18" x2="18" y2="18"/><line x1="9" y1="21" x2="15" y2="21"/></svg>',rotateLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><polyline points="3 3 3 8 8 8"/></svg>',rotateRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><polyline points="21 3 21 8 16 8"/></svg>'},hi=100,di=180;class pi{constructor(e){this.context=e,this._el=null,this._activeImg=null,this._showTimer=null,this._hideTimer=null,this._disposers=[]}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el);const e=this.context.layoutInfo.editable;return this._disposers.push(d(e,"mouseover",t=>{const i=t.target.closest("img");i&&e.contains(i)&&!i.closest("a[href]")&&this._scheduleShow(i)},{passive:!0}),d(e,"mouseout",t=>{const i=t.relatedTarget;(!i||!e.contains(i)&&!this._el.contains(i))&&this._scheduleHide()},{passive:!0}),d(document,"click",t=>{this._activeImg&&!this._activeImg.contains(t.target)&&!this._el.contains(t.target)&&this._hide()})),this}destroy(){this._clearTimers(),this._disposers.forEach(e=>e()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const e=c("div",{class:"an-link-tooltip an-image-tooltip",role:"toolbar","aria-label":"Image actions"});return e.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Image",e.appendChild(this._label),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._floatLeftBtn=this._makeBtn(P.floatLeft,"Float Left",()=>this._setFloat("left")),this._floatNoneBtn=this._makeBtn(P.floatNone,"No Float",()=>this._setFloat("")),this._alignCenterBtn=this._makeBtn(P.alignCenter,"Align Center",()=>this._setCenter()),this._floatRightBtn=this._makeBtn(P.floatRight,"Float Right",()=>this._setFloat("right")),e.appendChild(this._floatLeftBtn),e.appendChild(this._floatNoneBtn),e.appendChild(this._alignCenterBtn),e.appendChild(this._floatRightBtn),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._originalBtn=this._makeBtn(P.originalSize,"Original Size",()=>this._resetSize()),e.appendChild(this._originalBtn),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),e.appendChild(this._makeBtn(P.rotateLeft,"Rotate Left",()=>this._rotate(-90))),e.appendChild(this._makeBtn(P.rotateRight,"Rotate Right",()=>this._rotate(90))),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._captionBtn=this._makeBtn(P.caption,"Add / Edit Caption",()=>this._toggleCaption()),e.appendChild(this._captionBtn),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._deleteBtn=this._makeBtn(P.deleteImg,"Delete Image",()=>this._delete(),!0),e.appendChild(this._deleteBtn),this._disposers.push(d(e,"mouseenter",()=>this._clearTimers()),d(e,"mouseleave",()=>this._scheduleHide())),e}_makeBtn(e,t,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:t});return o.innerHTML=e,this._disposers.push(d(o,"click",a=>{a.preventDefault(),a.stopPropagation(),i()})),o}_scheduleShow(e){this._activeImg===e&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeImg=e,this._show(e)},hi))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),di))}_show(e){this._el.style.display="flex",requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_hide(){this._el.style.display="none",this._activeImg=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(e){const t=e.getBoundingClientRect(),i=this._el.offsetWidth||220,s=this._el.offsetHeight||32,o=6;let a=t.bottom+o,l=t.left+(t.width-i)/2;a+s>window.innerHeight-o&&(a=t.top-s-o),l+i>window.innerWidth-o&&(l=window.innerWidth-i-o),l<o&&(l=o),this._el.style.top=`${a}px`,this._el.style.left=`${l}px`}_setFloat(e){const t=this._activeImg;if(!t)return;const i=t.closest("figure.an-figure")||t;i.style.float=e,i.style.display="",i.style.marginLeft=e==="right"?"12px":"",i.style.marginRight=e==="left"?"12px":"",this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_setCenter(){const e=this._activeImg;if(!e)return;const t=e.closest("figure.an-figure")||e;t.style.float="",t.style.display="block",t.style.marginLeft="auto",t.style.marginRight="auto",this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_resetSize(){const e=this._activeImg;e&&(e.style.width="",e.style.height="",this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)}))}_rotate(e){const t=this._activeImg;if(!t)return;const i=t.style.transform||"",s=i.match(/rotate\((-?[\d.]+)deg\)/),a=((s?parseFloat(s[1]):0)+e+360)%360,l=i.replace(/rotate\(-?[\d.]+deg\)/,"").trim();t.style.transform=l?`${l} rotate(${a}deg)`:a===0?"":`rotate(${a}deg)`,this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_delete(){const e=this._activeImg;if(!e)return;this._hide(),this.context.invoke("imageResizer.deselect");const t=e.closest("figure.an-figure");t&&t.parentNode?t.parentNode.removeChild(t):e.parentNode&&e.parentNode.removeChild(e),this.context.invoke("editor.afterCommand")}_toggleCaption(){const e=this._activeImg;if(!e)return;const t=e.closest("figure.an-figure");if(t){const l=t.querySelector("figcaption.an-figcaption");if(l){this._hide();const r=document.createRange();r.selectNodeContents(l);const h=window.getSelection();h&&(h.removeAllRanges(),h.addRange(r))}return}const i=document.createElement("figure");i.className="an-figure",e.style.float?(i.style.float=e.style.float,i.style.marginLeft=e.style.marginLeft,i.style.marginRight=e.style.marginRight,e.style.float="",e.style.marginLeft="",e.style.marginRight=""):e.style.display==="block"&&e.style.marginLeft==="auto"&&(i.style.display="block",i.style.marginLeft="auto",i.style.marginRight="auto",e.style.display="",e.style.marginLeft="",e.style.marginRight="");const s=document.createElement("figcaption");s.className="an-figcaption",s.textContent="Caption",e.parentNode.insertBefore(i,e),i.appendChild(e),i.appendChild(s);const o=document.createRange();o.selectNodeContents(s);const a=window.getSelection();a&&(a.removeAllRanges(),a.addRange(o)),this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),this._hide()}}const Y={floatLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="8" height="8" rx="1"/><line x1="12" y1="6" x2="22" y2="6"/><line x1="12" y1="9" x2="22" y2="9"/><line x1="12" y1="12" x2="22" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="14" y="4" width="8" height="8" rx="1"/><line x1="2" y1="6" x2="12" y2="6"/><line x1="2" y1="9" x2="12" y2="9"/><line x1="2" y1="12" x2="12" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatNone:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="8" height="8" rx="1"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="3" y1="19" x2="17" y2="19"/></svg>',alignCenter:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="4" width="10" height="8" rx="1"/><line x1="3" y1="16" x2="21" y2="16"/><line x1="6" y1="20" x2="18" y2="20"/></svg>',originalSize:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',deleteVideo:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>',preview:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"/></svg>'},ui=100,mi=180;class fi{constructor(e){this.context=e,this._el=null,this._activeWrapper=null,this._showTimer=null,this._hideTimer=null,this._disposers=[],this._previewMode=!1,this._previewClickOff=null}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el);const e=this.context.layoutInfo.editable;return this._disposers.push(d(e,"mouseover",t=>{const i=t.target.closest(".an-video-wrapper");i&&e.contains(i)&&this._scheduleShow(i)},{passive:!0}),d(e,"mouseout",t=>{const i=t.relatedTarget;(!i||!e.contains(i)&&!this._el.contains(i))&&this._scheduleHide()},{passive:!0}),d(document,"click",t=>{this._activeWrapper&&!this._activeWrapper.contains(t.target)&&!this._el.contains(t.target)&&this._hide()})),this}destroy(){this._previewMode&&this._exitPreview(),this._clearTimers(),this._disposers.forEach(e=>e()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const e=c("div",{class:"an-link-tooltip an-video-tooltip",role:"toolbar","aria-label":"Video actions"});return e.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Video",e.appendChild(this._label),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._floatLeftBtn=this._makeBtn(Y.floatLeft,"Float Left",()=>this._setFloat("left")),this._floatNoneBtn=this._makeBtn(Y.floatNone,"No Float",()=>this._setFloat("")),this._alignCenterBtn=this._makeBtn(Y.alignCenter,"Align Center",()=>this._setCenter()),this._floatRightBtn=this._makeBtn(Y.floatRight,"Float Right",()=>this._setFloat("right")),e.appendChild(this._floatLeftBtn),e.appendChild(this._floatNoneBtn),e.appendChild(this._alignCenterBtn),e.appendChild(this._floatRightBtn),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._originalBtn=this._makeBtn(Y.originalSize,"Original Size",()=>this._resetSize()),e.appendChild(this._originalBtn),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._previewBtn=this._makeBtn(Y.preview,"Preview Video",()=>this._togglePreview()),e.appendChild(this._previewBtn),e.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._deleteBtn=this._makeBtn(Y.deleteVideo,"Delete Video",()=>this._delete(),!0),e.appendChild(this._deleteBtn),this._disposers.push(d(e,"mouseenter",()=>this._clearTimers()),d(e,"mouseleave",()=>this._scheduleHide())),e}_makeBtn(e,t,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:t});return o.innerHTML=e,this._disposers.push(d(o,"click",a=>{a.preventDefault(),a.stopPropagation(),i()})),o}_scheduleShow(e){this._activeWrapper===e&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeWrapper=e,this._show(e)},ui))}_scheduleHide(){this._previewMode||(clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),mi)))}_show(e){this._el.style.display="flex",requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)})}_hide(){this._previewMode&&this._exitPreview(),this._el.style.display="none",this._activeWrapper=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(e){const t=e.getBoundingClientRect(),i=this._el.offsetWidth||220,s=this._el.offsetHeight||32,o=6;let a=t.bottom+o,l=t.left+(t.width-i)/2;a+s>window.innerHeight-o&&(a=t.top-s-o),l+i>window.innerWidth-o&&(l=window.innerWidth-i-o),l<o&&(l=o),this._el.style.top=`${a}px`,this._el.style.left=`${l}px`}_setFloat(e){const t=this._activeWrapper;t&&(t.style.float=e,t.style.display=e?"inline-block":"",t.style.marginLeft=e==="right"?"12px":"",t.style.marginRight=e==="left"?"12px":"",this.context.invoke("editor.afterCommand"),this.context.invoke("videoResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)}))}_setCenter(){const e=this._activeWrapper;e&&(e.style.float="",e.style.display="block",e.style.marginLeft="auto",e.style.marginRight="auto",this.context.invoke("editor.afterCommand"),this.context.invoke("videoResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)}))}_resetSize(){const e=this._activeWrapper;if(!e)return;const t=e.querySelector("iframe, video");e.style.width="",e.style.height="",t&&(t.removeAttribute("width"),t.removeAttribute("height"),t.style.width="",t.style.height=""),this.context.invoke("editor.afterCommand"),this.context.invoke("videoResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)})}_delete(){const e=this._activeWrapper;e&&(this._hide(),this.context.invoke("videoResizer.deselect"),e.parentNode&&e.parentNode.removeChild(e),this.context.invoke("editor.afterCommand"))}_togglePreview(){this._previewMode?this._exitPreview():this._enterPreview()}_enterPreview(){const e=this._activeWrapper;if(!e)return;this._previewMode=!0;const t=e.querySelector(".an-video-shield");t&&(t.style.display="none"),this.context.invoke("videoResizer.deselect"),this._previewBtn.classList.add("an-link-tooltip-btn--copied"),this._previewBtn.title="Exit Preview",this._previewClickOff=i=>{!e.contains(i.target)&&!this._el.contains(i.target)&&this._exitPreview()},document.addEventListener("mousedown",this._previewClickOff,!0)}_exitPreview(){this._previewMode=!1;const e=this._activeWrapper;if(e){const t=e.querySelector(".an-video-shield");t&&(t.style.display="")}this._previewBtn.classList.remove("an-link-tooltip-btn--copied"),this._previewBtn.title="Preview Video",this._previewClickOff&&(document.removeEventListener("mousedown",this._previewClickOff,!0),this._previewClickOff=null)}}const gi=120,_i=200;function ie(n){const e=n.closest("tr");if(!e)return-1;let t=0;for(const i of e.cells){if(i===n)return t;t+=i.colSpan||1}return-1}function le(n,e){let t=0;for(const i of n.cells){if(t===e)return i;if(t>e)break;t+=i.colSpan||1}return null}function yi(n,e){let t=0;for(const i of n.cells)if(t+=i.colSpan||1,t>e){const s=i.nextElementSibling;return s&&s.tagName==="TD"||s&&s.tagName==="TH"?s:null}return null}const $={rowAbove:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="12" x2="21" y2="12"/><path d="M12 3v7"/><path d="M9 7l3-4 3 4"/></svg>',rowBelow:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="12" x2="21" y2="12"/><path d="M12 12v7"/><path d="M9 17l3 4 3-4"/></svg>',deleteRow:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="15" y1="15" x2="21" y2="21"/><line x1="21" y1="15" x2="15" y2="21"/></svg>',colLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="12" y1="3" x2="12" y2="21"/><path d="M3 12h7"/><path d="M7 8l-4 4 4 4"/></svg>',colRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="12" y1="3" x2="12" y2="21"/><path d="M12 12h9"/><path d="M17 8l4 4-4 4"/></svg>',deleteCol:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="12" y1="3" x2="12" y2="21"/><line x1="15" y1="6" x2="21" y2="12"/><line x1="21" y1="6" x2="15" y2="12"/></svg>',mergeCells:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="8" height="10" rx="1"/><rect x="14" y="7" width="8" height="10" rx="1"/><path d="M10 12h4"/><path d="M12 10l2 2-2 2"/></svg>',colWidth:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="4" x2="7" y2="20"/><line x1="17" y1="4" x2="17" y2="20"/><line x1="7" y1="12" x2="17" y2="12"/><path d="M10 9l-3 3 3 3"/><path d="M14 9l3 3-3 3"/></svg>',rowHeight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="7" x2="20" y2="7"/><line x1="4" y1="17" x2="20" y2="17"/><line x1="12" y1="7" x2="12" y2="17"/><path d="M9 10l3-3 3 3"/><path d="M9 14l3 3 3-3"/></svg>',deleteTable:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/><line x1="16" y1="16" x2="22" y2="22" stroke="#ef4444"/><line x1="22" y1="16" x2="16" y2="22" stroke="#ef4444"/></svg>'};class vi{constructor(e){this.context=e,this._el=null,this._activeTable=null,this._activeCell=null,this._showTimer=null,this._hideTimer=null,this._disposers=[],this._sizePopover=null,this._sizeApply=null,this._sizeTitleEl=null,this._sizeInputEl=null}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el),this._sizePopover=this._buildSizePopover(),document.body.appendChild(this._sizePopover);const e=this.context.layoutInfo.editable;return this._disposers.push(d(e,"mouseover",t=>{const i=t.target.closest("table");if(i&&e.contains(i)){const s=t.target.closest("td, th");s&&(this._activeCell=s),this._scheduleShow(i)}},{passive:!0}),d(e,"mouseout",t=>{const i=t.relatedTarget;(!i||!e.contains(i)&&!this._el.contains(i)&&!(this._sizePopover&&this._sizePopover.contains(i)))&&this._scheduleHide()},{passive:!0}),d(document,"click",t=>{this._activeTable&&!this._activeTable.contains(t.target)&&!this._el.contains(t.target)&&!(this._sizePopover&&this._sizePopover.contains(t.target))&&this._hide()})),this._initResize(),this}_initResize(){const e=this.context.layoutInfo.editable,t=6;let i=null,s=null,o=!1,a=null,l=0,r=0,h=0,p=0,u=-1,m=null,f=null,g=null,v=null,k=null;const T=()=>{i&&(i.style.cursor="",i=null),s=null},C=y=>{if(o||k!==null)return;const I=y.target,E=y.clientX,B=y.clientY;k=requestAnimationFrame(()=>{k=null;const L=I.closest("td, th");if(!L||!e.contains(L)){T();return}i&&i!==L&&(i.style.cursor="");const F=L.getBoundingClientRect(),K=Math.abs(E-F.right)<t,G=Math.abs(B-F.bottom)<t;K?(L.style.cursor="col-resize",i=L,s="col"):G?(L.style.cursor="row-resize",i=L,s="row"):T()})},b=y=>{!i||!s||(o=!0,a=s,l=y.clientX,r=y.clientY,g=i.closest("table"),a==="col"?(h=i.offsetWidth,u=ie(i),m=u>=0?Array.from(g.querySelectorAll("tr")).map(I=>le(I,u)).filter(Boolean):[],document.body.style.cursor="col-resize"):(f=i.closest("tr"),p=f?f.offsetHeight:40,document.body.style.cursor="row-resize"),document.body.style.userSelect="none",y.preventDefault(),y.stopPropagation())},w=y=>{if(!o||v!==null)return;const I=y.clientX,E=y.clientY;v=requestAnimationFrame(()=>{if(v=null,a==="col"){const B=Math.max(30,h+(I-l));for(const L of m)L.style.width=`${B}px`,L.style.minWidth=`${B}px`}else{const B=Math.max(20,p+(E-r));if(f)for(const L of f.cells)L.style.height=`${B}px`,L.style.minHeight=`${B}px`}})},_=()=>{o&&(v!==null&&(cancelAnimationFrame(v),v=null),o=!1,document.body.style.userSelect="",document.body.style.cursor="",a=null,g=null,f=null,u=-1,m=null,this.context.invoke("editor.afterCommand"))};this._disposers.push(d(e,"mousemove",C),d(e,"mousedown",b),d(document,"mousemove",w),d(document,"mouseup",_))}destroy(){this._clearTimers(),this._disposers.forEach(e=>e()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null,this._sizePopover&&this._sizePopover.parentNode&&this._sizePopover.parentNode.removeChild(this._sizePopover),this._sizePopover=null}_buildTooltip(){const e=c("div",{class:"an-link-tooltip an-table-tooltip",role:"toolbar","aria-label":"Table actions"});return e.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Table",e.appendChild(this._label),e.appendChild(this._sep()),e.appendChild(this._makeBtn($.rowAbove,"Add Row Above",()=>this._addRow("above"))),e.appendChild(this._makeBtn($.rowBelow,"Add Row Below",()=>this._addRow("below"))),e.appendChild(this._makeBtn($.deleteRow,"Delete Row",()=>this._deleteRow())),e.appendChild(this._sep()),e.appendChild(this._makeBtn($.colLeft,"Add Column Left",()=>this._addColumn("left"))),e.appendChild(this._makeBtn($.colRight,"Add Column Right",()=>this._addColumn("right"))),e.appendChild(this._makeBtn($.deleteCol,"Delete Column",()=>this._deleteColumn())),e.appendChild(this._sep()),e.appendChild(this._makeBtn($.mergeCells,"Merge Cells",()=>this._mergeCells())),e.appendChild(this._sep()),e.appendChild(this._makeBtn($.colWidth,"Column Width",()=>this._openSizePopover("col"))),e.appendChild(this._makeBtn($.rowHeight,"Row Height",()=>this._openSizePopover("row"))),e.appendChild(this._sep()),e.appendChild(this._makeBtn($.deleteTable,"Delete Table",()=>this._deleteTable(),!0)),this._disposers.push(d(e,"mouseenter",()=>this._clearTimers()),d(e,"mouseleave",()=>{this._sizePopover&&this._sizePopover.style.display!=="none"||this._scheduleHide()})),e}_sep(){return c("div",{class:"an-link-tooltip-sep"})}_makeBtn(e,t,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:t});return o.innerHTML=e,this._disposers.push(d(o,"click",a=>{a.preventDefault(),a.stopPropagation(),i()})),o}_scheduleShow(e){this._activeTable===e&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeTable=e,this._show()},gi))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),_i))}_show(){this._activeTable&&(this._el.style.display="flex",requestAnimationFrame(()=>{this._activeTable&&this._positionNear(this._activeTable)}))}_hide(){this._el.style.display="none",this._activeTable=null,this._activeCell=null,this._clearTimers(),this._hideSizePopover()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(e){if(!e)return;const t=e.getBoundingClientRect(),i=this._el.offsetWidth||400,s=this._el.offsetHeight||30,o=6;let a=t.left+(t.width-i)/2,l=t.top-s-o;l<o&&(l=t.bottom+o),a+i>window.innerWidth-o&&(a=window.innerWidth-i-o),a<o&&(a=o),this._el.style.left=`${a}px`,this._el.style.top=`${l}px`}_getCell(){const e=window.getSelection();if(e&&e.rangeCount){let t=e.getRangeAt(0).commonAncestorContainer;t.nodeType===3&&(t=t.parentElement);const i=t&&t.closest&&t.closest("td, th");if(i&&this._activeTable&&this._activeTable.contains(i))return i}return this._activeCell||this._activeTable&&this._activeTable.querySelector("td, th")}_addRow(e){var l;const t=this._getCell();if(!t)return;const i=t.closest("tr");if(!i)return;const s=Array.from(i.cells).reduce((r,h)=>r+(h.colSpan||1),0),o=document.createElement("tr"),a=Array.from(i.cells);for(let r=0;r<s;r++){const h=c("td",{},[" "]),p=a[r];p&&p.style.width&&(h.style.width=p.style.width),p&&p.style.minWidth&&(h.style.minWidth=p.style.minWidth),o.appendChild(h)}e==="above"?(l=i.parentElement)==null||l.insertBefore(o,i):i.insertAdjacentElement("afterend",o),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand")}_addColumn(e){const t=this._getCell();if(!t)return;const i=t.closest("table");if(!i)return;const s=ie(t),o=Array.from(i.querySelectorAll("tr")),a=o.map(r=>e==="left"?le(r,s):yi(r,s)),l=o.map(r=>r.closest("thead")!==null);o.forEach((r,h)=>{r.insertBefore(c(l[h]?"th":"td",{},[" "]),a[h])}),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand")}_deleteRow(){var a;const e=this._getCell();if(!e)return;const t=e.closest("tr"),i=e.closest("table");if(!t||!i)return;const s=i.querySelector("tbody");(s?s.querySelectorAll("tr").length:i.querySelectorAll("tr").length)<=1&&t.closest("tbody")||(this._activeCell=null,(a=t.parentElement)==null||a.removeChild(t),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand"))}_deleteColumn(){const e=this._getCell();if(!e)return;const t=e.closest("table");if(!t)return;const i=e.closest("tr");if(i&&i.cells.length<=1)return;const s=ie(e);this._activeCell=null;const o=Array.from(t.querySelectorAll("tr"));o.map(l=>le(l,s)).forEach((l,r)=>{l&&o[r].removeChild(l)}),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand")}_mergeCells(){const e=this._getCell();if(!e)return;const t=window.getSelection();if(!t||t.rangeCount===0)return;const i=t.getRangeAt(0),s=e.closest("table");if(!s)return;const a=Array.from(s.querySelectorAll("td, th")).filter(r=>{try{return i.intersectsNode(r)}catch{return!1}});if(a.length<2)return;const l=[...new Set(a.map(r=>r.closest("tr")))];if(l.length===1){const r=l[0],h=Array.from(r.cells).filter(u=>a.includes(u));if(h.length<2)return;const p=h[0];p.colSpan=h.reduce((u,m)=>u+(m.colSpan||1),0),p.innerHTML=h.map(u=>u.innerHTML).join(""),h.slice(1).forEach(u=>r.removeChild(u))}else{if([...new Set(a.map(p=>ie(p)))].length!==1)return;const h=a[0];h.rowSpan=a.reduce((p,u)=>p+(u.rowSpan||1),0),h.innerHTML=a.map(p=>p.innerHTML).join(""),a.slice(1).forEach(p=>{p.closest("tr")&&p.closest("tr").removeChild(p)})}this.context.invoke("editor.afterCommand")}_deleteTable(){const e=this._activeTable;e&&(this._hide(),e.parentNode&&e.parentNode.removeChild(e),this.context.invoke("editor.afterCommand"))}_buildSizePopover(){const e=c("div",{class:"an-size-popover"});e.style.display="none";const t=c("div",{class:"an-size-popover-title"}),i=c("div",{class:"an-size-popover-body"}),s=c("input",{type:"number",class:"an-size-input",min:"1",max:"2000",step:"1"}),o=c("span",{class:"an-size-unit"},["px"]);i.appendChild(s),i.appendChild(o);const a=c("div",{class:"an-size-popover-actions"}),l=c("button",{type:"button",class:"an-btn"});l.textContent="Cancel";const r=c("button",{type:"button",class:"an-btn an-btn-primary"});r.textContent="Apply",a.appendChild(l),a.appendChild(r),e.appendChild(t),e.appendChild(i),e.appendChild(a),this._sizeTitleEl=t,this._sizeInputEl=s,this._sizeApply=null;const h=d(r,"click",()=>{const v=parseInt(this._sizeInputEl.value,10);v>0&&typeof this._sizeApply=="function"&&this._sizeApply(v),this._hideSizePopover()}),p=d(l,"click",()=>this._hideSizePopover()),u=d(s,"keydown",v=>{v.key==="Enter"&&(v.preventDefault(),r.click()),v.key==="Escape"&&this._hideSizePopover()}),m=d(document,"click",v=>{this._sizePopover&&this._sizePopover.style.display!=="none"&&!this._sizePopover.contains(v.target)&&!this._el.contains(v.target)&&this._hideSizePopover()}),f=d(e,"mouseenter",()=>this._clearTimers()),g=d(e,"mouseleave",()=>this._scheduleHide());return this._disposers.push(h,p,u,m,f,g),e}_openSizePopover(e){const t=this._getCell();if(!t||!this._sizePopover)return;const i=e==="col";this._sizeTitleEl.textContent=i?"Column Width (px)":"Row Height (px)",this._sizeInputEl.value=i?t.offsetWidth||120:t.closest("tr")&&t.closest("tr").offsetHeight||40,this._sizeApply=s=>{if(i){const o=t.closest("table"),a=ie(t);Array.from(o.querySelectorAll("tr")).map(h=>le(h,a)).forEach(h=>{h&&(h.style.width=`${s}px`,h.style.minWidth=`${s}px`)})}else{const o=t.closest("tr");if(o)for(const a of o.cells)a.style.height=`${s}px`,a.style.minHeight=`${s}px`}this.context.invoke("editor.afterCommand")},this._sizePopover.style.display="block",requestAnimationFrame(()=>{if(!this._sizePopover||!this._el)return;const s=this._el.getBoundingClientRect(),o=this._sizePopover.offsetWidth||220,a=this._sizePopover.offsetHeight||110;let l=s.left,r=s.bottom+6;l+o>window.innerWidth-8&&(l=window.innerWidth-o-8),r+a>window.innerHeight-8&&(r=s.top-a-6),this._sizePopover.style.left=`${l}px`,this._sizePopover.style.top=`${r}px`,this._sizeInputEl&&(this._sizeInputEl.focus(),this._sizeInputEl.select())})}_hideSizePopover(){this._sizePopover&&(this._sizePopover.style.display="none"),this._sizeApply=null}}const bi=100,wi=180,re={copy:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',wrapOn:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="6" x2="21" y2="6"/><path d="M3 12h15a3 3 0 0 1 0 6H3"/><polyline points="6 15 3 18 6 21"/></svg>',toParagraph:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13 4v16"/><path d="M17 4v16"/><path d="M9 4h8a4 4 0 0 1 0 8H9V4z"/></svg>',deleteCode:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>'};class xi{constructor(e){this.context=e,this._el=null,this._activePre=null,this._showTimer=null,this._hideTimer=null,this._disposers=[],this._copyBtn=null,this._langSelect=null,this._prismScript=null}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el),this._ensurePrism();const e=this.context.layoutInfo.editable;return this._disposers.push(d(e,"mouseover",t=>{const i=t.target.closest("pre");i&&e.contains(i)&&this._scheduleShow(i)}),d(e,"mouseout",t=>{const i=t.relatedTarget;(!i||!e.contains(i)&&!this._el.contains(i))&&this._scheduleHide()}),d(document,"click",t=>{this._activePre&&!this._activePre.contains(t.target)&&!this._el.contains(t.target)&&this._hide()})),this}destroy(){this._clearTimers(),this._disposers.forEach(e=>e()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const e=c("div",{class:"an-link-tooltip an-code-tooltip",role:"toolbar","aria-label":"Code block actions"});return e.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Code",e.appendChild(this._label),e.appendChild(this._sep()),this._langSelect=c("select",{class:"an-code-lang-select",title:"Syntax Language","aria-label":"Syntax language"}),[["","Plain text"],["javascript","JavaScript"],["typescript","TypeScript"],["python","Python"],["html","HTML"],["css","CSS"],["json","JSON"],["xml","XML"],["bash","Bash / Shell"],["sql","SQL"],["java","Java"],["csharp","C#"],["php","PHP"],["ruby","Ruby"],["go","Go"],["rust","Rust"],["cpp","C++"],["c","C"],["kotlin","Kotlin"],["swift","Swift"]].forEach(([i,s])=>{const o=c("option",{value:i});o.textContent=s,this._langSelect.appendChild(o)}),this._disposers.push(d(this._langSelect,"change",()=>this._onLangChange())),e.appendChild(this._langSelect),e.appendChild(this._sep()),this._copyBtn=this._makeBtn(re.copy,"Copy Code",()=>this._copyCode()),e.appendChild(this._copyBtn),e.appendChild(this._sep()),this._wrapBtn=this._makeBtn(re.wrapOn,"Toggle Word Wrap",()=>this._toggleWrap()),e.appendChild(this._wrapBtn),e.appendChild(this._sep()),e.appendChild(this._makeBtn(re.toParagraph,"Convert to Paragraph",()=>this._toParagraph())),e.appendChild(this._sep()),e.appendChild(this._makeBtn(re.deleteCode,"Delete Code Block",()=>this._delete(),!0)),this._disposers.push(d(e,"mouseenter",()=>this._clearTimers()),d(e,"mouseleave",()=>this._scheduleHide())),e}_sep(){return c("div",{class:"an-link-tooltip-sep"})}_makeBtn(e,t,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:t});return o.innerHTML=e,this._disposers.push(d(o,"click",a=>{a.preventDefault(),a.stopPropagation(),i()})),o}_scheduleShow(e){this._activePre===e&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activePre=e,this._syncWrapBtn(),this._syncLangSelect(),this._show(e)},bi))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),wi))}_show(e){this._el.style.display="flex",this._positionNear(e)}_hide(){this._el.style.display="none",this._activePre=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(e){const t=e.getBoundingClientRect(),i=this._el.offsetWidth||260,s=this._el.offsetHeight||32,o=6;let a=t.top-s-o,l=t.left+(t.width-i)/2;a<o&&(a=t.bottom+o),l+i>window.innerWidth-o&&(l=window.innerWidth-i-o),l<o&&(l=o),this._el.style.top=`${a}px`,this._el.style.left=`${l}px`}_syncWrapBtn(){if(!this._activePre||!this._wrapBtn)return;const e=(this._activePre.style.whiteSpace||"").includes("pre-wrap")||window.getComputedStyle(this._activePre).whiteSpace==="pre-wrap";this._wrapBtn.classList.toggle("active",e),this._wrapBtn.title=e?"Disable Word Wrap":"Enable Word Wrap"}_syncLangSelect(){if(!this._activePre||!this._langSelect)return;const e=this._activePre.querySelector("code"),t=this._activePre.getAttribute("data-language")||"",i=e&&(e.className.match(/language-(\S+)/)||[])[1]||"";this._langSelect.value=t||i||""}_copyCode(){const e=this._activePre;if(!e)return;const t=e.textContent||"";if(navigator.clipboard)navigator.clipboard.writeText(t).then(()=>this._flashCopied()).catch(()=>{});else{const i=document.createElement("textarea");i.value=t,i.style.cssText="position:fixed;opacity:0;top:0;left:0",document.body.appendChild(i),i.select();try{document.execCommand("copy"),this._flashCopied()}catch{}document.body.removeChild(i)}}_flashCopied(){if(!this._copyBtn)return;const e=this._copyBtn.innerHTML;this._copyBtn.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',this._copyBtn.classList.add("an-link-tooltip-btn--copied"),setTimeout(()=>{this._copyBtn&&(this._copyBtn.innerHTML=e,this._copyBtn.classList.remove("an-link-tooltip-btn--copied"))},1400)}_toggleWrap(){const e=this._activePre;if(!e)return;const t=e.style.whiteSpace==="pre-wrap";e.style.whiteSpace=t?"pre":"pre-wrap",this._syncWrapBtn(),this.context.invoke("editor.afterCommand"),this._positionNear(e)}_onLangChange(){const e=this._activePre;if(!e)return;const t=this._langSelect.value;let i=e.querySelector("code");i||(i=document.createElement("code"),i.innerHTML=e.innerHTML,e.innerHTML="",e.appendChild(i)),i.className=t?`language-${t}`:"",e.className=t?`language-${t}`:"",t?e.setAttribute("data-language",t):e.removeAttribute("data-language");const s=()=>{i.querySelectorAll("br").forEach(o=>o.replaceWith(`
72
- `)),window.Prism.highlightElement(i),this.context.invoke("editor.afterCommand")};if(t){if(typeof window.Prism<"u"){if(window.Prism.languages[t]){s();return}this._loadPrismComponent(t,s);return}else if(this._prismScript){this._prismScript.addEventListener("load",()=>{window.Prism.languages[t]?s():this._loadPrismComponent(t,s)},{once:!0});return}}this.context.invoke("editor.afterCommand")}_ensurePrism(){if(!this.context.options.codeHighlight||window.Prism)return;const e=this.context.options.codeHighlightCDN||"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0",t=`${e}/themes/prism-tomorrow.min.css`,i=`${e}/prism.min.js`;if(!document.querySelector(`link[href="${t}"]`)){const a=document.createElement("link");a.rel="stylesheet",a.href=t,document.head.appendChild(a)}const s=document.querySelector(`script[src="${i}"]`);if(s){this._prismScript=window.Prism?null:s;return}const o=document.createElement("script");o.dataset.manual="",o.src=i,this._prismScript=o,o.addEventListener("load",()=>{this._prismScript=null},{once:!0}),document.head.appendChild(o)}_loadPrismComponent(e,t){const s=`${this.context.options.codeHighlightCDN||"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0"}/components/prism-${e}.min.js`;if(document.querySelector(`script[src="${s}"]`)){const a=setInterval(()=>{window.Prism&&window.Prism.languages[e]&&(clearInterval(a),t())},50);setTimeout(()=>clearInterval(a),3e3);return}const o=document.createElement("script");o.src=s,o.addEventListener("load",t,{once:!0}),document.head.appendChild(o)}_toParagraph(){const e=this._activePre;if(!e||!this.context.layoutInfo.editable)return;const i=(e.textContent||"").split(`
73
- `),s=document.createElement("p");i.forEach((o,a)=>{a>0&&s.appendChild(document.createElement("br")),s.appendChild(document.createTextNode(o))}),e.parentNode.replaceChild(s,e),this._hide(),this.context.invoke("editor.afterCommand")}_delete(){const e=this._activePre;e&&(this._hide(),e.parentNode&&e.parentNode.removeChild(e),this.context.invoke("editor.afterCommand"))}}const ki=[{id:"smileys",label:"Smileys"},{id:"people",label:"People"},{id:"animals",label:"Animals"},{id:"food",label:"Food"},{id:"travel",label:"Travel"},{id:"objects",label:"Objects"},{id:"symbols",label:"Symbols"}],Ci=[["😀","grin smile happy face","smileys"],["😃","happy smile big eyes","smileys"],["😄","grinning smile laugh","smileys"],["😁","beaming smile grin","smileys"],["😆","laughing lol","smileys"],["😅","sweat grin awkward","smileys"],["🤣","rolling laugh rofl","smileys"],["😂","tears laugh cry joy","smileys"],["🙂","slight smile","smileys"],["🙃","upside down smile","smileys"],["😉","wink","smileys"],["😊","blush smile happy","smileys"],["😇","innocent halo angel","smileys"],["🥰","hearts love adore","smileys"],["😍","heart eyes love","smileys"],["🤩","star eyes excited wow","smileys"],["😘","kiss blow love","smileys"],["😋","yum delicious tongue","smileys"],["😛","tongue stuck out","smileys"],["😜","wink tongue crazy","smileys"],["🤪","zany crazy wild","smileys"],["😝","squint tongue","smileys"],["🤑","money mouth","smileys"],["🤗","hugging hug","smileys"],["🤔","thinking hmm","smileys"],["🤨","raised eyebrow","smileys"],["😐","neutral face","smileys"],["😶","no mouth","smileys"],["😏","smirk","smileys"],["😒","unamused","smileys"],["🙄","roll eyes","smileys"],["😬","grimace","smileys"],["😔","pensive sad","smileys"],["😪","sleepy tired","smileys"],["😴","sleeping zzz","smileys"],["🤤","drool","smileys"],["😷","mask sick","smileys"],["🤒","sick thermometer","smileys"],["🤕","hurt bandage","smileys"],["🤢","nausea sick","smileys"],["🤮","vomit sick","smileys"],["🤧","sneeze cold","smileys"],["🥵","hot sweat","smileys"],["🥶","cold freeze","smileys"],["😵","dizzy dead","smileys"],["🤯","mind blown","smileys"],["🤠","cowboy hat","smileys"],["🥳","party celebrate","smileys"],["😎","cool sunglasses","smileys"],["🤓","nerd glasses","smileys"],["🧐","monocle curious","smileys"],["😕","confused","smileys"],["😟","worried","smileys"],["🙁","frown sad","smileys"],["☹️","sad frown","smileys"],["😮","surprised open mouth","smileys"],["😲","astonished","smileys"],["🥺","pleading begging puppy eyes","smileys"],["😢","cry sad tear","smileys"],["😭","sob cry loudly","smileys"],["😱","scream horror fear","smileys"],["😡","angry red pouting","smileys"],["😠","angry mad","smileys"],["🤬","cursing swear","smileys"],["😈","devil evil smile","smileys"],["👿","devil angry evil","smileys"],["💀","skull death","smileys"],["☠️","skull crossbones","smileys"],["💩","poop","smileys"],["🤡","clown","smileys"],["👻","ghost boo","smileys"],["👽","alien ufo","smileys"],["🤖","robot","smileys"],["👋","wave hello hi hand","people"],["🤚","raised back hand","people"],["✋","raised hand stop","people"],["🖖","vulcan salute spock","people"],["👌","ok perfect fine","people"],["✌️","peace victory fingers","people"],["🤞","fingers crossed luck","people"],["🤟","love you gesture","people"],["🤘","sign of horns rock","people"],["🤙","call me hand","people"],["👈","point left","people"],["👉","point right","people"],["👆","point up","people"],["👇","point down","people"],["☝️","index pointing up","people"],["👍","thumbs up like good","people"],["👎","thumbs down dislike bad","people"],["✊","raised fist punch","people"],["👊","oncoming fist punch","people"],["👏","clap applause","people"],["🙌","celebrate raise hands","people"],["🤝","handshake deal","people"],["🙏","pray hope please thanks","people"],["💅","nail polish","people"],["💪","flexed bicep strong muscle","people"],["👀","eyes look see","people"],["👁️","eye","people"],["👅","tongue","people"],["👶","baby","people"],["🧒","child","people"],["👦","boy","people"],["👧","girl","people"],["🧑","person adult","people"],["👨","man","people"],["👩","woman","people"],["🧔","beard man","people"],["🧓","older person","people"],["👴","old man","people"],["👵","old woman","people"],["❤️","heart love red","people"],["🧡","orange heart love","people"],["💛","yellow heart love","people"],["💚","green heart love","people"],["💙","blue heart love","people"],["💜","purple heart love","people"],["🖤","black heart","people"],["🤍","white heart","people"],["🤎","brown heart","people"],["💔","broken heart","people"],["❣️","exclamation heart","people"],["💕","two hearts love","people"],["💞","revolving hearts","people"],["💓","beating heart","people"],["💗","growing heart","people"],["💖","sparkling heart","people"],["💘","heart arrow","people"],["💝","heart ribbon","people"],["💬","speech bubble comment chat","people"],["💭","thought bubble","people"],["💯","100 hundred percent perfect","people"],["💢","anger symbol mad","people"],["💤","zzz sleep","people"],["🐶","dog puppy","animals"],["🐱","cat kitten","animals"],["🐭","mouse","animals"],["🐹","hamster","animals"],["🐰","rabbit bunny","animals"],["🦊","fox","animals"],["🐻","bear","animals"],["🐼","panda","animals"],["🐨","koala","animals"],["🐯","tiger","animals"],["🦁","lion","animals"],["🐮","cow","animals"],["🐷","pig","animals"],["🐸","frog","animals"],["🐵","monkey","animals"],["🙈","see no evil monkey","animals"],["🙉","hear no evil monkey","animals"],["🙊","speak no evil monkey","animals"],["🐔","chicken hen","animals"],["🐧","penguin","animals"],["🐦","bird","animals"],["🦆","duck","animals"],["🦅","eagle","animals"],["🦉","owl","animals"],["🦇","bat","animals"],["🐺","wolf","animals"],["🐴","horse","animals"],["🦄","unicorn","animals"],["🐝","bee","animals"],["🦋","butterfly","animals"],["🐌","snail","animals"],["🐞","ladybug","animals"],["🐢","turtle","animals"],["🐍","snake","animals"],["🦎","lizard","animals"],["🐊","crocodile","animals"],["🐟","fish","animals"],["🐠","tropical fish","animals"],["🦈","shark","animals"],["🐬","dolphin","animals"],["🐳","whale","animals"],["🐙","octopus","animals"],["🦑","squid","animals"],["🦀","crab","animals"],["🌸","cherry blossom flower","animals"],["🌺","hibiscus flower","animals"],["🌻","sunflower","animals"],["🌹","rose flower","animals"],["🌷","tulip flower","animals"],["🍀","four leaf clover luck","animals"],["🌿","herb leaf green","animals"],["🌱","seedling sprout","animals"],["🌲","evergreen tree pine","animals"],["🌳","deciduous tree","animals"],["🌴","palm tree","animals"],["🍄","mushroom","animals"],["🌾","sheaf wheat","animals"],["🐾","paw prints animal","animals"],["🍎","apple red","food"],["🍊","orange tangerine","food"],["🍋","lemon yellow","food"],["🍇","grapes","food"],["🍓","strawberry","food"],["🫐","blueberry","food"],["🍒","cherry","food"],["🍑","peach","food"],["🥭","mango","food"],["🍍","pineapple","food"],["🥥","coconut","food"],["🥝","kiwi","food"],["🍅","tomato","food"],["🥑","avocado","food"],["🍆","eggplant aubergine","food"],["🥕","carrot","food"],["🌽","corn","food"],["🥦","broccoli","food"],["🥬","leafy green","food"],["🧄","garlic","food"],["🥜","peanut nut","food"],["🍞","bread loaf","food"],["🥐","croissant","food"],["🧀","cheese","food"],["🍳","egg fry cooking","food"],["🥚","egg","food"],["🥞","pancake","food"],["🧇","waffle","food"],["🥓","bacon","food"],["🥩","meat steak","food"],["🍗","chicken leg","food"],["🌭","hotdog","food"],["🍔","burger hamburger","food"],["🍟","fries french","food"],["🍕","pizza","food"],["🌮","taco","food"],["🌯","burrito wrap","food"],["🍜","noodles ramen","food"],["🍝","spaghetti pasta","food"],["🍣","sushi","food"],["🍱","bento box","food"],["🍦","ice cream soft serve","food"],["🍩","donut","food"],["🍪","cookie","food"],["🎂","birthday cake","food"],["🍰","cake slice","food"],["🧁","cupcake","food"],["🍫","chocolate","food"],["🍬","candy","food"],["🍭","lollipop","food"],["☕","coffee hot","food"],["🍵","tea hot","food"],["🧋","bubble tea boba","food"],["🥤","cup straw drink","food"],["🍷","wine red","food"],["🍸","cocktail martini","food"],["🍺","beer mug","food"],["🍻","clinking beer mugs","food"],["🥂","champagne toast celebrate","food"],["🧃","juice box","food"],["🧊","ice cube","food"],["🚀","rocket space","travel"],["🛸","ufo flying saucer","travel"],["✈️","airplane plane fly","travel"],["🚁","helicopter","travel"],["🚂","train locomotive","travel"],["🚄","bullet train fast","travel"],["🚇","subway metro","travel"],["🚌","bus","travel"],["🚑","ambulance","travel"],["🚒","fire truck","travel"],["🚓","police car","travel"],["🚕","taxi cab","travel"],["🚗","car automobile red","travel"],["🚙","suv car","travel"],["🚚","truck delivery","travel"],["🚜","tractor farm","travel"],["🏎️","racing car fast","travel"],["🏍️","motorcycle","travel"],["🚲","bicycle bike","travel"],["🛴","scooter kick","travel"],["⛵","sailboat boat","travel"],["🚢","ship cruise","travel"],["🏠","house home","travel"],["🏢","office building","travel"],["🏥","hospital","travel"],["🏦","bank","travel"],["🏪","store shop convenience","travel"],["🏫","school","travel"],["🏰","castle european","travel"],["🏯","japanese castle","travel"],["🗼","tokyo tower","travel"],["🗽","statue liberty new york","travel"],["⛪","church","travel"],["🕌","mosque","travel"],["⛩️","shinto shrine","travel"],["⛲","fountain","travel"],["⛺","tent camping","travel"],["🌁","fog foggy bridge","travel"],["🌃","night city stars","travel"],["🏙️","cityscape city buildings","travel"],["🌅","sunrise morning","travel"],["🌈","rainbow colorful","travel"],["⛰️","mountain","travel"],["🏔️","snow mountain","travel"],["🗻","mount fuji","travel"],["🏕️","camping tent","travel"],["🗺️","world map","travel"],["🧭","compass navigation","travel"],["🌍","earth europe africa globe","travel"],["🌎","earth americas globe","travel"],["🌏","earth asia globe","travel"],["🌐","globe internet web","travel"],["💎","diamond gem jewel","objects"],["💍","ring engagement","objects"],["👑","crown royal king queen","objects"],["🎩","top hat magic","objects"],["💼","briefcase work business","objects"],["👜","handbag purse","objects"],["🎒","backpack bag school","objects"],["👓","glasses eyewear","objects"],["🕶️","sunglasses cool","objects"],["💡","light bulb idea","objects"],["🔦","flashlight torch","objects"],["🕯️","candle light","objects"],["🔋","battery charge","objects"],["💻","laptop computer","objects"],["🖥️","desktop monitor computer","objects"],["📱","phone mobile cell","objects"],["⌨️","keyboard type","objects"],["🖱️","mouse computer click","objects"],["📺","television tv","objects"],["📷","camera photo","objects"],["📹","video camera","objects"],["🎥","movie camera film","objects"],["☎️","telephone phone","objects"],["⏰","alarm clock wake","objects"],["⌚","watch time","objects"],["🔑","key","objects"],["🗝️","old key","objects"],["🔒","lock closed","objects"],["🔓","unlock open","objects"],["🔨","hammer tool","objects"],["🔧","wrench tool","objects"],["🔩","bolt nut","objects"],["⚙️","gear setting","objects"],["🧲","magnet attract","objects"],["📚","books stack library","objects"],["📖","book open read","objects"],["📝","memo write note","objects"],["✏️","pencil write edit","objects"],["📌","pushpin tack","objects"],["📎","paperclip attach","objects"],["📊","bar chart graph","objects"],["📈","chart up growth trend","objects"],["📉","chart down loss decline","objects"],["📅","calendar date","objects"],["📦","package box","objects"],["📫","mailbox closed","objects"],["📧","email envelope","objects"],["🎁","gift present","objects"],["🎀","ribbon bow","objects"],["🎉","party celebrate confetti","objects"],["🎊","confetti celebrate","objects"],["🔮","crystal ball magic fortune","objects"],["🪄","magic wand","objects"],["🎯","target bullseye dart","objects"],["🎲","dice game board","objects"],["🎮","video game controller","objects"],["🎭","theater masks drama","objects"],["🎨","art palette paint","objects"],["🎬","clapper film movie","objects"],["🎤","microphone sing karaoke","objects"],["🎧","headphones music listen","objects"],["🎵","music note","objects"],["🎶","music notes","objects"],["🎸","guitar electric","objects"],["🎹","piano keyboard music","objects"],["🥁","drum percussion","objects"],["🎷","saxophone jazz","objects"],["🎺","trumpet","objects"],["🎻","violin","objects"],["⚽","soccer ball football","objects"],["🏀","basketball","objects"],["🏈","american football","objects"],["⚾","baseball","objects"],["🎾","tennis","objects"],["🏐","volleyball","objects"],["🏆","trophy winner award","objects"],["🥇","gold medal first","objects"],["🏅","sports medal","objects"],["✅","check green done success","symbols"],["❌","cross x no cancel","symbols"],["⭕","circle red","symbols"],["⛔","no entry stop","symbols"],["🚫","prohibited no banned","symbols"],["⚠️","warning caution danger","symbols"],["❗","exclamation red important","symbols"],["❓","question mark","symbols"],["‼️","double exclamation","symbols"],["💯","100 hundred percent perfect","symbols"],["🔴","red circle dot","symbols"],["🟠","orange circle","symbols"],["🟡","yellow circle","symbols"],["🟢","green circle","symbols"],["🔵","blue circle","symbols"],["🟣","purple circle","symbols"],["⚫","black circle","symbols"],["⚪","white circle","symbols"],["🟤","brown circle","symbols"],["🔺","red triangle up","symbols"],["🔻","red triangle down","symbols"],["🔷","blue diamond large","symbols"],["🔶","orange diamond large","symbols"],["🔹","blue diamond small","symbols"],["🔸","orange diamond small","symbols"],["⭐","star yellow","symbols"],["🌟","glowing star shine","symbols"],["✨","sparkles shine","symbols"],["💫","dizzy star spin","symbols"],["⚡","lightning bolt energy power","symbols"],["🔥","fire hot flame","symbols"],["💥","explosion boom","symbols"],["❄️","snowflake cold ice winter","symbols"],["🌊","wave water ocean sea","symbols"],["💨","wind blow dash","symbols"],["🌀","cyclone tornado spiral","symbols"],["♻️","recycle loop green","symbols"],["✔️","check tick done","symbols"],["➕","plus add","symbols"],["➖","minus subtract","symbols"],["➗","divide division","symbols"],["✖️","multiply times cross","symbols"],["▶️","play button right","symbols"],["⏸️","pause","symbols"],["⏹️","stop square","symbols"],["⏩","fast forward","symbols"],["⏪","rewind fast backward","symbols"],["🔔","bell notification","symbols"],["🔕","bell slash mute","symbols"],["🔊","speaker volume high","symbols"],["🔇","mute silent no sound","symbols"],["📢","loudspeaker announcement","symbols"],["📣","megaphone cheer","symbols"],["🏳️","white flag","symbols"],["🏴","black flag","symbols"],["🚩","red flag","symbols"],["🏁","checkered flag finish race","symbols"],["🆕","new badge","symbols"],["🆓","free badge","symbols"],["🆒","cool badge","symbols"],["🔝","top arrow","symbols"],["🔙","back arrow","symbols"],["ℹ️","information info","symbols"],["📍","pin location map","symbols"],["🔗","link chain","symbols"],["©️","copyright","symbols"],["®️","registered trademark","symbols"],["™️","trademark","symbols"],["#️⃣","hash number","symbols"],["0️⃣","zero number","symbols"],["1️⃣","one number","symbols"],["2️⃣","two number","symbols"],["3️⃣","three number","symbols"],["4️⃣","four number","symbols"],["5️⃣","five number","symbols"]];class Ti{constructor(e){this.context=e,this._dialog=null,this._disposers=[],this._savedRange=null,this._activeCat="all"}initialize(){return this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){this._dialog||(this._dialog=this._buildDialog(),document.body.appendChild(this._dialog)),ee(e=>{this._savedRange=e}),this._activeCat="all",this._searchInput.value="",this._updateCatTabs(),this._filterEmojis("","all"),this._open()}_buildDialog(){const e=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert emoji"}),t=c("div",{class:"an-dialog-box an-emoji-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Insert Emoji";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.innerHTML="&times;",i.append(s,o);const a=c("input",{type:"search",class:"an-input an-icon-search",placeholder:"Search emojis…",autocomplete:"off"});this._searchInput=a;const l=c("div",{class:"an-icon-cats"}),r=c("button",{type:"button",class:"an-icon-cat active","data-cat":"all"});r.textContent="All",l.appendChild(r),ki.forEach(({id:C,label:b})=>{const w=c("button",{type:"button",class:"an-icon-cat","data-cat":C});w.textContent=b,l.appendChild(w)}),this._catBar=l;const h=c("div",{class:"an-emoji-grid"});Ci.forEach(([C,b,w])=>{const _=c("button",{type:"button",class:"an-emoji-cell","data-char":C,"data-keywords":b,"data-cat":w,title:b.split(" ").slice(0,2).join(" ")});_.textContent=C,h.appendChild(_)}),this._grid=h;const p=c("div",{class:"an-dialog-actions"}),u=c("button",{type:"button",class:"an-btn"});u.textContent="Cancel",p.appendChild(u),t.append(i,a,l,h,p),e.appendChild(t);const m=d(o,"click",()=>this._close()),f=d(u,"click",()=>this._close()),g=d(e,"click",C=>{C.target===e&&this._close()}),v=d(a,"input",()=>this._filterEmojis(a.value,this._activeCat)),k=d(l,"click",C=>{const b=C.target.closest("[data-cat]");b&&(this._activeCat=b.dataset.cat,this._updateCatTabs(),this._filterEmojis(this._searchInput.value,this._activeCat))}),T=d(h,"click",C=>{const b=C.target.closest(".an-emoji-cell");b&&this._onEmojiClick(b.dataset.char)});return this._disposers.push(m,f,g,v,k,T),e}_updateCatTabs(){this._catBar.querySelectorAll(".an-icon-cat").forEach(e=>{e.classList.toggle("active",e.dataset.cat===this._activeCat)})}_filterEmojis(e,t){const i=(e||"").trim().toLowerCase();let s=0;this._grid.querySelectorAll(".an-emoji-cell").forEach(a=>{const l=!t||t==="all"||a.dataset.cat===t,r=!i||a.dataset.keywords.includes(i)||a.dataset.char===i,h=l&&r;a.style.display=h?"":"none",h&&s++});let o=this._grid.querySelector(".an-icon-empty");o||(o=c("div",{class:"an-icon-empty"}),o.textContent="No emojis found",this._grid.appendChild(o)),o.style.display=s>0?"none":""}_onEmojiClick(e){const t=this._savedRange,i=this.context.layoutInfo.editable;t&&t.select();const s=window.getSelection();let o=s&&s.rangeCount>0?s.getRangeAt(0):null;o||(o=document.createRange(),o.selectNodeContents(i),o.collapse(!1)),o.deleteContents();const a=document.createTextNode(e);o.insertNode(a),o.setStartAfter(a),o.collapse(!0),s&&(s.removeAllRanges(),s.addRange(o)),this._close(),i.focus(),this.context.invoke("editor.afterCommand")}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=q(this._dialog,()=>this._close()),setTimeout(()=>this._searchInput&&this._searchInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}}const Si=[{id:"popular",label:"Popular"},{id:"interface",label:"Interface"},{id:"navigation",label:"Navigation"},{id:"media",label:"Media"},{id:"communication",label:"Communication"},{id:"files",label:"Files"},{id:"people",label:"People"},{id:"objects",label:"Objects"}],Ii=[["house","popular"],["star","popular"],["heart","popular"],["check","popular"],["xmark","popular"],["plus","popular"],["minus","popular"],["magnifying-glass","popular"],["gear","popular"],["bell","popular"],["user","popular"],["envelope","popular"],["phone","popular"],["calendar","popular"],["clock","popular"],["lock","popular"],["eye","popular"],["eye-slash","popular"],["trash","popular"],["pen","popular"],["bookmark","popular"],["flag","popular"],["thumbs-up","popular"],["thumbs-down","popular"],["circle-info","popular"],["triangle-exclamation","popular"],["circle-check","popular"],["circle-xmark","popular"],["share","popular"],["download","popular"],["upload","popular"],["tag","popular"],["bars","interface"],["ellipsis","interface"],["ellipsis-vertical","interface"],["list","interface"],["table-cells","interface"],["table-list","interface"],["grip","interface"],["filter","interface"],["sort","interface"],["arrows-rotate","interface"],["rotate","interface"],["rotate-left","interface"],["rotate-right","interface"],["copy","interface"],["floppy-disk","interface"],["print","interface"],["link","interface"],["code","interface"],["expand","interface"],["compress","interface"],["cloud","interface"],["lock-open","interface"],["key","interface"],["shield","interface"],["shield-halved","interface"],["sliders","interface"],["toggle-on","interface"],["square-check","interface"],["circle-plus","interface"],["circle-minus","interface"],["arrow-right","navigation"],["arrow-left","navigation"],["arrow-up","navigation"],["arrow-down","navigation"],["chevron-right","navigation"],["chevron-left","navigation"],["chevron-up","navigation"],["chevron-down","navigation"],["angle-right","navigation"],["angle-left","navigation"],["angle-up","navigation"],["angle-down","navigation"],["angles-right","navigation"],["angles-left","navigation"],["location-dot","navigation"],["compass","navigation"],["map","navigation"],["map-pin","navigation"],["route","navigation"],["circle-arrow-right","navigation"],["circle-arrow-left","navigation"],["arrow-trend-up","navigation"],["arrow-trend-down","navigation"],["right-from-bracket","navigation"],["right-to-bracket","navigation"],["play","media"],["pause","media"],["stop","media"],["forward","media"],["backward","media"],["forward-step","media"],["backward-step","media"],["volume-high","media"],["volume-low","media"],["volume-xmark","media"],["volume-off","media"],["music","media"],["headphones","media"],["microphone","media"],["microphone-slash","media"],["film","media"],["camera","media"],["camera-rotate","media"],["video","media"],["image","media"],["images","media"],["photo-film","media"],["podcast","media"],["radio","media"],["comment","communication"],["comments","communication"],["comment-dots","communication"],["message","communication"],["paper-plane","communication"],["reply","communication"],["reply-all","communication"],["at","communication"],["hashtag","communication"],["wifi","communication"],["signal","communication"],["rss","communication"],["share-nodes","communication"],["inbox","communication"],["phone-volume","communication"],["mobile","communication"],["mobile-screen","communication"],["laptop","communication"],["desktop","communication"],["tower-broadcast","communication"],["file","files"],["file-lines","files"],["folder","files"],["folder-open","files"],["folder-plus","files"],["folder-minus","files"],["file-image","files"],["file-pdf","files"],["file-code","files"],["file-zipper","files"],["file-audio","files"],["file-video","files"],["file-arrow-up","files"],["file-arrow-down","files"],["database","files"],["box","files"],["box-open","files"],["hard-drive","files"],["server","files"],["user","people"],["users","people"],["user-group","people"],["user-plus","people"],["user-minus","people"],["user-check","people"],["user-xmark","people"],["user-tie","people"],["user-shield","people"],["user-secret","people"],["person","people"],["person-running","people"],["person-walking","people"],["child","people"],["handshake","people"],["hand","people"],["hands-holding","people"],["people-group","people"],["pencil","objects"],["paintbrush","objects"],["eraser","objects"],["scissors","objects"],["wrench","objects"],["screwdriver","objects"],["hammer","objects"],["toolbox","objects"],["graduation-cap","objects"],["book","objects"],["book-open","objects"],["glasses","objects"],["microscope","objects"],["flask","objects"],["stethoscope","objects"],["hospital","objects"],["building","objects"],["city","objects"],["car","objects"],["truck","objects"],["plane","objects"],["train","objects"],["bicycle","objects"],["bus","objects"],["rocket","objects"],["briefcase","objects"],["cart-shopping","objects"],["bag-shopping","objects"],["credit-card","objects"],["money-bill","objects"],["chart-bar","objects"],["chart-line","objects"],["chart-pie","objects"],["bolt","objects"],["sun","objects"],["moon","objects"],["snowflake","objects"],["fire","objects"],["droplet","objects"],["leaf","objects"],["tree","objects"],["earth-americas","objects"],["globe","objects"],["award","objects"],["trophy","objects"],["gift","objects"],["puzzle-piece","objects"]];class Ri{constructor(e){this.context=e,this._dialog=null,this._disposers=[],this._savedRange=null,this._selectedIcon=null,this._activeCat="all"}initialize(){return this._ensureFontAwesome(),this}_ensureFontAwesome(){if(document.getElementById("an-fontawesome-css"))return;const e=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).map(i=>i.href||"").join(" ");if(/fontawesome|font-awesome/.test(e)||document.querySelector(".fa-solid, .fas, .far, .fab"))return;const t=document.createElement("link");t.id="an-fontawesome-css",t.rel="stylesheet",t.href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css",t.crossOrigin="anonymous",t.referrerPolicy="no-referrer",document.head.appendChild(t)}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){this._dialog||(this._dialog=this._buildDialog(),document.body.appendChild(this._dialog)),ee(e=>{this._savedRange=e}),this._selectedIcon=null,this._activeCat="all",this._searchInput.value="",this._grid.querySelectorAll(".an-icon-cell.active").forEach(e=>e.classList.remove("active")),this._insertBtn.setAttribute("disabled",""),this._updateCatTabs(),this._filterIcons("","all"),this._updatePreview(null),this._open()}_buildDialog(){const e=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert FA icon"}),t=c("div",{class:"an-dialog-box an-icon-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Insert FA Icon";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.innerHTML="&times;",i.append(s,o);const a=c("input",{type:"search",class:"an-input an-icon-search",placeholder:"Search icons…",autocomplete:"off"});this._searchInput=a;const l=c("div",{class:"an-icon-cats"}),r=c("button",{type:"button",class:"an-icon-cat active","data-cat":"all"});r.textContent="All",l.appendChild(r),Si.forEach(({id:x,label:A})=>{const N=c("button",{type:"button",class:"an-icon-cat","data-cat":x});N.textContent=A,l.appendChild(N)}),this._catBar=l;const h=c("div",{class:"an-icon-grid"});Ii.forEach(([x,A])=>{const N=c("button",{type:"button",class:"an-icon-cell","data-name":x,"data-cat":A,title:x}),ce=c("i",{class:"fa-solid fa-"+x,"aria-hidden":"true"}),Ve=c("span");Ve.textContent=x,N.append(ce,Ve),h.appendChild(N)}),this._grid=h;const p=c("div",{class:"an-icon-options"}),u=c("label",{class:"an-label"});u.textContent="Style";const m=c("select",{class:"an-input an-icon-option-select"});[["fa-solid","Solid"],["fa-regular","Regular"],["fa-light","Light (Pro)"]].forEach(([x,A])=>{const N=c("option",{value:x});N.textContent=A,m.appendChild(N)}),m.value="fa-solid",this._styleSelect=m;const f=c("label",{class:"an-label"});f.textContent="Size";const g=c("select",{class:"an-input an-icon-option-select"});[["","Inherit"],["0.75em","0.75em"],["1em","1em"],["1.25em","1.25em"],["1.5em","1.5em"],["2em","2em"],["3em","3em"]].forEach(([x,A])=>{const N=c("option",{value:x});x==="1em"&&(N.selected=!0),N.textContent=A,g.appendChild(N)}),this._sizeSelect=g;const v=c("label",{class:"an-label"});v.textContent="Color";const k=c("input",{type:"color",class:"an-icon-color",value:"#000000"});this._colorInput=k;const T=c("label",{class:"an-label an-label-inline an-icon-use-color"}),C=c("input",{type:"checkbox",checked:""});this._useColorCb=C,T.append(C,document.createTextNode(" Use color")),p.append(u,m,f,g,v,k,T);const b=c("div",{class:"an-icon-preview"}),w=c("span",{class:"an-icon-preview-hint"});w.textContent="Select an icon",b.appendChild(w),this._preview=b;const _=c("div",{class:"an-dialog-actions"}),y=c("button",{type:"button",class:"an-btn an-btn-primary",disabled:""});y.textContent="Insert FA Icon";const I=c("button",{type:"button",class:"an-btn"});I.textContent="Cancel",_.append(y,I),this._insertBtn=y,t.append(i,a,l,h,p,b,_),e.appendChild(t);const E=d(o,"click",()=>this._close()),B=d(I,"click",()=>this._close()),L=d(y,"click",()=>this._onInsert()),F=d(e,"click",x=>{x.target===e&&this._close()}),K=d(a,"input",()=>this._filterIcons(a.value,this._activeCat)),G=d(l,"click",x=>{const A=x.target.closest("[data-cat]");A&&(this._activeCat=A.dataset.cat,this._updateCatTabs(),this._filterIcons(this._searchInput.value,this._activeCat))}),j=d(h,"click",x=>{const A=x.target.closest(".an-icon-cell");A&&this._selectIcon(A.dataset.name)}),de=d(m,"change",()=>this._updatePreview(this._selectedIcon)),pe=d(g,"change",()=>this._updatePreview(this._selectedIcon)),ue=d(k,"input",()=>this._updatePreview(this._selectedIcon)),Z=d(C,"change",()=>this._updatePreview(this._selectedIcon));return this._disposers.push(E,B,L,F,K,G,j,de,pe,ue,Z),e}_updateCatTabs(){this._catBar.querySelectorAll(".an-icon-cat").forEach(e=>{e.classList.toggle("active",e.dataset.cat===this._activeCat)})}_filterIcons(e,t){const i=(e||"").trim().toLowerCase();let s=0;this._grid.querySelectorAll(".an-icon-cell").forEach(a=>{const l=a.dataset.name,r=a.dataset.cat,h=!t||t==="all"||r===t,p=!i||l.includes(i),u=h&&p;a.style.display=u?"":"none",u&&s++});let o=this._grid.querySelector(".an-icon-empty");o||(o=c("div",{class:"an-icon-empty"}),o.textContent="No icons found",this._grid.appendChild(o)),o.style.display=s>0?"none":""}_selectIcon(e){this._selectedIcon=e,this._grid.querySelectorAll(".an-icon-cell").forEach(t=>{t.classList.toggle("active",t.dataset.name===e)}),this._insertBtn.removeAttribute("disabled"),this._updatePreview(e)}_updatePreview(e){if(!this._preview)return;if(!e){this._preview.innerHTML='<span class="an-icon-preview-hint">Select an icon</span>';return}const t=this._styleSelect&&this._styleSelect.value||"fa-solid",i=this._sizeSelect&&this._sizeSelect.value||"1em",o=(this._useColorCb?this._useColorCb.checked:!1)&&this._colorInput?this._colorInput.value:"",a=[`font-size:${i}`,o?`color:${o}`:""].filter(Boolean).join(";");this._preview.innerHTML=`<i class="${t} fa-${e}" aria-hidden="true"${a?` style="${a}"`:""}></i><div class="an-icon-preview-name">${t} fa-${e}</div>`}_onInsert(){if(!this._selectedIcon)return;const e=this._styleSelect&&this._styleSelect.value||"fa-solid",t=this._sizeSelect&&this._sizeSelect.value||"",s=(this._useColorCb?this._useColorCb.checked:!1)&&this._colorInput?this._colorInput.value:"",o=[t?`font-size:${t}`:"",s?`color:${s}`:""].filter(Boolean),a=document.createElement("i");a.className=`${e} fa-${this._selectedIcon}`,a.setAttribute("aria-hidden","true"),a.setAttribute("contenteditable","false"),o.length&&a.setAttribute("style",o.join(";"));const l=this._savedRange,r=this.context.layoutInfo.editable;l&&l.select();const h=window.getSelection();let p=h&&h.rangeCount>0?h.getRangeAt(0):null;p||(p=document.createRange(),p.selectNodeContents(r),p.collapse(!1)),p.deleteContents(),p.insertNode(a);let u=a.nextSibling;!u||u.nodeType!==Node.TEXT_NODE?(u=document.createTextNode("​"),a.parentNode.insertBefore(u,a.nextSibling)):u.textContent||(u.textContent="​");const m=(u.textContent||"").startsWith("​")?1:0,f=document.createRange();f.setStart(u,Math.min(m,u.textContent.length)),f.collapse(!0),h&&(h.removeAllRanges(),h.addRange(f)),this._close(),r.focus(),h&&(h.removeAllRanges(),h.addRange(f)),this.context.invoke("editor.afterCommand")}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=q(this._dialog,()=>this._close()),setTimeout(()=>this._searchInput&&this._searchInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null,this._selectedIcon=null}}const M={undo:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>',redo:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"/></svg>',cut:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="6" cy="20" r="3"/><circle cx="6" cy="4" r="3"/><line x1="19" y1="5" x2="6" y2="19"/><line x1="19" y1="19" x2="13.5" y2="13.5"/></svg>',copy:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',paste:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><rect x="8" y="2" width="8" height="4" rx="1"/></svg>',bold:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>',italic:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>',underline:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" y1="21" x2="20" y2="21"/></svg>',link:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',image:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',video:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg>',copyFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',pasteFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><rect x="8" y="2" width="8" height="4" rx="1"/><path d="m9 14 2 2 4-4"/></svg>',removeFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/></svg>',table:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>'},Ei=[{name:"undo",label:"Undo",icon:M.undo,action:n=>n.invoke("editor.undo")},{name:"redo",label:"Redo",icon:M.redo,action:n=>n.invoke("editor.redo")},{separator:!0},{name:"cut",label:"Cut",icon:M.cut,action:()=>document.execCommand("cut")},{name:"copy",label:"Copy",icon:M.copy,action:()=>document.execCommand("copy")},{name:"paste",label:"Paste",icon:M.paste,action:n=>{if(!navigator.clipboard)return;const e=n.layoutInfo&&n.layoutInfo.editable;if(!e)return;const t=(i,s)=>{if(e.focus(),i){const o=V(i);document.execCommand("insertHTML",!1,o)}else s&&document.execCommand("insertText",!1,s);n.invoke("editor.afterCommand")};typeof navigator.clipboard.read=="function"?navigator.clipboard.read().then(i=>{for(const s of i)if(s.types.includes("text/html")){s.getType("text/html").then(o=>o.text()).then(o=>t(o,null));return}navigator.clipboard.readText().then(s=>t(null,s)).catch(()=>{})}).catch(()=>{navigator.clipboard.readText().then(i=>t(null,i)).catch(()=>{})}):typeof navigator.clipboard.readText=="function"&&navigator.clipboard.readText().then(i=>t(null,i)).catch(()=>{})}},{separator:!0},{name:"bold",label:"Bold",icon:M.bold,action:n=>n.invoke("editor.bold")},{name:"italic",label:"Italic",icon:M.italic,action:n=>n.invoke("editor.italic")},{name:"underline",label:"Underline",icon:M.underline,action:n=>n.invoke("editor.underline")},{separator:!0},{name:"copyFormat",label:"Copy Format",icon:M.copyFormat,action:n=>n.invoke("contextMenu.copyFormat")},{name:"pasteFormat",label:"Paste Format",icon:M.pasteFormat,action:n=>n.invoke("contextMenu.pasteFormat"),disabled:n=>!n.invoke("contextMenu.hasCopiedFormat")},{name:"removeFormat",label:"Remove Format",icon:M.removeFormat,action:n=>n.invoke("contextMenu.removeFormat")},{separator:!0},{name:"link",label:"Insert Link",icon:M.link,action:n=>n.invoke("linkDialog.show")},{name:"image",label:"Insert Image",icon:M.image,action:n=>n.invoke("imageDialog.show")},{name:"video",label:"Insert Video",icon:M.video,action:n=>n.invoke("videoDialog.show")},{name:"table",label:"Insert Table",icon:M.table,tableGrid:!0}];class Ai{constructor(e){this.context=e,this.options=e.options||{},this._items=this.options.contextMenu&&this.options.contextMenu.items||Ei,this.el=null,this._disposers=[],this._menuDisposers=[],this._lastX=0,this._lastY=0,this._copiedFormat=null,this._savedRange=null}initialize(){this.el=c("div",{class:"an-contextmenu",role:"menu","aria-hidden":"true"}),this.el.style.display="none",document.body.appendChild(this.el),this._renderItems(this._items);const e=this.context.layoutInfo&&this.context.layoutInfo.editable;return e&&this._disposers.push(d(e,"contextmenu",t=>this._onContextMenu(t))),this._disposers.push(d(document,"click",t=>this._maybeHide(t))),this._disposers.push(d(document,"keydown",t=>{t.key==="Escape"&&this.hide()})),this._disposers.push(d(window,"scroll",()=>this.hide(),{passive:!0})),this}destroy(){this._menuDisposers.forEach(e=>{try{e()}catch{}}),this._menuDisposers=[],this._disposers.forEach(e=>{try{e()}catch{}}),this._disposers=[],this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null}_renderItems(e){this._menuDisposers.forEach(t=>t()),this._menuDisposers=[],this.el&&(this.el.innerHTML="",e.forEach(t=>{if(t.separator||t.sep){this.el.appendChild(c("div",{class:"an-context-sep"}));return}if(t.back){const o=c("button",{type:"button",class:"an-context-back"}),a=c("span",{class:"an-context-icon","aria-hidden":"true"});a.innerHTML=M.back,o.appendChild(a),o.appendChild(c("span",{class:"an-context-label"},[t.label||"Back"]));const l=d(o,"click",r=>{r.stopPropagation(),this._renderItems(t.navigate()),this._reposition()});this._menuDisposers.push(l),this.el.appendChild(o);return}if(t.navigate){const o=c("button",{type:"button",class:"an-context-item an-context-submenu","data-name":t.name||""});if(t.icon){const r=c("span",{class:"an-context-icon","aria-hidden":"true"});r.innerHTML=t.icon,o.appendChild(r)}o.appendChild(c("span",{class:"an-context-label"},[t.label||t.name]));const a=c("span",{class:"an-context-chevron","aria-hidden":"true"});a.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>',o.appendChild(a);const l=d(o,"click",r=>{r.stopPropagation(),this._renderItems(t.navigate()),this._reposition()});this._menuDisposers.push(l),this.el.appendChild(o);return}if(t.tableGrid){const l=c("div",{class:"an-context-table-wrap"}),r=c("button",{type:"button",class:"an-context-item an-context-submenu","data-name":t.name||"table"});if(t.icon){const w=c("span",{class:"an-context-icon","aria-hidden":"true"});w.innerHTML=t.icon,r.appendChild(w)}r.appendChild(c("span",{class:"an-context-label"},[t.label||"Insert Table"]));const h=c("span",{class:"an-context-chevron","aria-hidden":"true"});h.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>',r.appendChild(h);const p=c("div",{class:"an-context-table-grid-panel"});p.style.display="none";const u=c("div",{class:"an-table-grid"});u.style.gridTemplateColumns="repeat(8, 16px)";const m=c("div",{class:"an-table-label"});m.textContent="Insert Table";const f=[];for(let w=1;w<=8;w++)for(let _=1;_<=8;_++){const y=c("div",{class:"an-table-cell","data-row":String(w),"data-col":String(_)});y.style.width="16px",y.style.height="16px",f.push(y),u.appendChild(y)}const g=(w,_)=>{f.forEach(y=>{y.classList.toggle("active",+y.dataset.row<=w&&+y.dataset.col<=_)}),m.textContent=w&&_?`${_} × ${w}`:"Insert Table"};p.appendChild(u),p.appendChild(m);let v=!1;const k=d(r,"click",w=>{w.stopPropagation(),v=!v,p.style.display=v?"":"none",h.style.transform=v?"rotate(90deg)":"",this._reposition()});this._menuDisposers.push(k);const T=d(u,"mousemove",w=>{const _=w.target.closest("[data-row]");_&&g(+_.dataset.row,+_.dataset.col)}),C=d(u,"mouseleave",()=>g(0,0)),b=d(u,"click",w=>{const _=w.target.closest("[data-row]");if(!_)return;const y=+_.dataset.row,I=+_.dataset.col,E=this.context.layoutInfo&&this.context.layoutInfo.editable;if(E&&this._savedRange){E.focus();const B=window.getSelection();B.removeAllRanges(),B.addRange(this._savedRange.cloneRange())}this.hide(),this.context.invoke("editor.insertTable",I,y)});this._menuDisposers.push(T,C,b),l.appendChild(r),l.appendChild(p),this.el.appendChild(l);return}const i=c("button",{type:"button",class:"an-context-item","data-name":t.name||""});if((typeof t.disabled=="function"?t.disabled(this.context):t.disabled)&&(i.disabled=!0),t.icon){const o=c("span",{class:"an-context-icon","aria-hidden":"true"});o.innerHTML=t.icon,i.appendChild(o)}i.appendChild(c("span",{class:"an-context-label"},[t.label||t.name]));const s=d(i,"click",o=>{o.stopPropagation(),this.hide();try{t.action(this.context)}catch(a){console.error(a)}});this._menuDisposers.push(s),this.el.appendChild(i)}))}_onContextMenu(e){const t=this.context.layoutInfo&&this.context.layoutInfo.editable;if(!t||!t.contains(e.target))return;e.preventDefault(),this._lastX=e.clientX,this._lastY=e.clientY;const i=window.getSelection();this._savedRange=i&&i.rangeCount>0?i.getRangeAt(0).cloneRange():null,this._renderItems(this._items),this.showAt(e.clientX,e.clientY)}_maybeHide(e){this.el&&(this.el.contains(e.target)||this.hide())}showAt(e,t){this.el&&(this.el.style.display="block",this._reposition(e,t),this.el.setAttribute("aria-hidden","false"))}_reposition(e,t){if(!this.el)return;const i=e!==void 0?e:this._lastX,s=t!==void 0?t:this._lastY,o=this.el.getBoundingClientRect();let a=i,l=s;a+o.width>window.innerWidth&&(a=window.innerWidth-o.width-8),l+o.height>window.innerHeight&&(l=window.innerHeight-o.height-8),this.el.style.left=`${a}px`,this.el.style.top=`${l}px`}hide(){this.el&&(this.el.style.display="none",this.el.setAttribute("aria-hidden","true"))}hasCopiedFormat(){return!!this._copiedFormat}copyFormat(){const e=this._savedRange;if(!e)return;const t=this.context.layoutInfo&&this.context.layoutInfo.editable;let i=e.startContainer;if(i.nodeType===Node.TEXT_NODE&&(i=i.parentElement),!i||!t||!t.contains(i))return;const s=window.getComputedStyle(i),o=this._findExplicitStyle(i,t,"fontFamily"),a=this._findExplicitStyle(i,t,"fontSize");this._copiedFormat={bold:parseInt(s.fontWeight,10)>=700,italic:s.fontStyle==="italic"||s.fontStyle==="oblique",underline:(s.textDecorationLine||"").includes("underline"),strikethrough:(s.textDecorationLine||"").includes("line-through"),fontFamily:o,fontSize:a,color:this._isDefaultColor(s.color)?null:s.color,backgroundColor:s.backgroundColor}}_findExplicitStyle(e,t,i){let s=e;for(;s&&s!==t&&s!==document.body;){if(s.style&&s.style[i])return s.style[i];if(s.nodeName==="FONT"){if(i==="fontFamily"&&s.getAttribute("face"))return s.getAttribute("face");if(i==="fontSize"&&s.getAttribute("size"))return null}s=s.parentElement}return null}_isDefaultColor(e){return!e||e==="rgb(0, 0, 0)"||e==="rgba(0, 0, 0, 0)"||e==="transparent"}pasteFormat(){if(!this._copiedFormat||!this._savedRange)return;const e=this._copiedFormat,t=this.context.layoutInfo&&this.context.layoutInfo.editable;if(!t)return;t.focus();const i=window.getSelection();if(i.removeAllRanges(),i.addRange(this._savedRange.cloneRange()),document.execCommand("removeFormat"),e.bold&&document.execCommand("bold"),e.italic&&document.execCommand("italic"),e.underline&&document.execCommand("underline"),e.strikethrough&&document.execCommand("strikeThrough"),e.color&&document.execCommand("foreColor",!1,e.color),(o=>!o||o==="rgba(0, 0, 0, 0)"||o==="transparent")(e.backgroundColor)||document.execCommand("hiliteColor",!1,e.backgroundColor),e.fontFamily&&document.execCommand("fontName",!1,e.fontFamily),e.fontSize){const o=`fs-${Date.now()}`,a=new Set(t.querySelectorAll('font[size="7"]'));document.execCommand("fontSize",!1,"7"),t.querySelectorAll('font[size="7"]').forEach(l=>{a.has(l)||l.setAttribute("data-an-tmp",o)}),t.querySelectorAll(`[data-an-tmp="${o}"]`).forEach(l=>{const r=document.createElement("span");for(r.style.fontSize=e.fontSize,l.parentNode.insertBefore(r,l);l.firstChild;)r.appendChild(l.firstChild);l.parentNode.removeChild(l)})}this.context.invoke("editor.afterCommand")}removeFormat(){if(!this._savedRange)return;const e=this.context.layoutInfo&&this.context.layoutInfo.editable;if(!e)return;e.focus();const t=window.getSelection();t.removeAllRanges(),t.addRange(this._savedRange.cloneRange()),document.execCommand("removeFormat");const i=t.getRangeAt(0),s=i.commonAncestorContainer,o=s.nodeType===Node.TEXT_NODE?s.parentElement:s,a=document.createNodeIterator(o,NodeFilter.SHOW_ELEMENT);let l;for(;l=a.nextNode();)if(!(!e.contains(l)||l===e))try{i.intersectsNode(l)&&l.removeAttribute("style")}catch{}this.context.invoke("editor.afterCommand")}}const Li=[{category:"Text Formatting",items:[{keys:"Ctrl + B",action:"Bold"},{keys:"Ctrl + I",action:"Italic"},{keys:"Ctrl + U",action:"Underline"},{keys:"Ctrl + K",action:"Insert / edit link"}]},{category:"History",items:[{keys:"Ctrl + Z",action:"Undo"},{keys:"Ctrl + Y / Ctrl + Shift + Z",action:"Redo"}]},{category:"Selection & Navigation",items:[{keys:"Ctrl + A",action:"Select all content"},{keys:"Tab",action:"Indent list item / insert spaces"},{keys:"Shift + Tab",action:"Outdent list item"}]},{category:"Clipboard",items:[{keys:"Ctrl + Shift + V",action:"Paste as plain text"}]},{category:"Find & Replace",items:[{keys:"Ctrl + F",action:"Find in document"},{keys:"Ctrl + H",action:"Find & Replace"}]},{category:"Editor",items:[{keys:"Shift + ?",action:"Show this keyboard shortcuts dialog"}]}];class Bi{constructor(e){this.context=e,this._dialog=null,this._closeBtn=null,this._disposers=[]}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=q(this._dialog,()=>this._close()),setTimeout(()=>this._closeBtn&&this._closeBtn.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null)}_buildDialog(){const e=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Keyboard Shortcuts"}),t=c("div",{class:"an-dialog-box an-shortcuts-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Keyboard Shortcuts";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.textContent="×",this._closeBtn=o,i.append(s,o),t.appendChild(i),Li.forEach(({category:r,items:h})=>{const p=c("div",{class:"an-shortcuts-cat"});p.textContent=r,t.appendChild(p);const u=c("div",{class:"an-shortcuts-table"});h.forEach(({keys:m,action:f})=>{const g=c("div",{class:"an-shortcuts-row"}),v=c("span",{class:"an-shortcuts-key"});v.textContent=m;const k=c("span",{class:"an-shortcuts-action"});k.textContent=f,g.append(v,k),u.appendChild(g)}),t.appendChild(u)}),e.appendChild(t);const a=d(o,"click",()=>this._close()),l=d(e,"click",r=>{r.target===e&&this._close()});return this._disposers.push(a,l),e}}class Mi{constructor(e){this.context=e,this._dialog=null,this._findInput=null,this._replaceInput=null,this._caseCheckbox=null,this._counterEl=null,this._closeBtn=null,this._matches=[],this._currentIndex=-1,this._caseSensitive=!1,this._mode="find",this._disposers=[],this._removeTrap=null,this._focusTimer=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){clearTimeout(this._focusTimer),this._focusTimer=null,this._clearHighlights(),this._disposers.forEach(e=>e()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(e="find"){this._mode=e,this._updateMode(),this._open(),clearTimeout(this._focusTimer),this._focusTimer=setTimeout(()=>{this._findInput&&(this._findInput.select(),this._findInput.focus())},50)}_open(){if(this._dialog){if(this._dialog.style.display==="flex"){this._findInput&&this._findInput.focus();return}this._dialog.style.display="flex",this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._removeTrap=q(this._dialog,()=>this._close())}}_close(){this._clearHighlights(),this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this.context.invoke("editor.focus")}_updateMode(){if(!this._dialog)return;const e=this._dialog.querySelector(".an-fr-replace-row"),t=this._dialog.querySelector(".an-fr-replace-actions"),i=this._dialog.querySelector(".an-dialog-title"),s=this._mode==="replace";e&&(e.style.display=s?"":"none"),t&&(t.style.display=s?"":"none"),i&&(i.textContent=s?"Find & Replace":"Find")}_buildDialog(){const e=c("div",{class:"an-dialog-overlay an-fr-dialog",role:"dialog","aria-modal":"true","aria-label":"Find and Replace"}),t=c("div",{class:"an-dialog-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Find";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.textContent="×",this._closeBtn=o,i.append(s,o),t.appendChild(i);const a=c("div",{class:"an-fr-find-row"}),l=c("input",{type:"text",class:"an-input",placeholder:"Find…","aria-label":"Search text"});this._findInput=l,a.appendChild(l),t.appendChild(a);const r=c("div",{class:"an-fr-options-row"}),h=c("label",{class:"an-label an-label-inline"}),p=c("input",{type:"checkbox","aria-label":"Case sensitive"});this._caseCheckbox=p,h.append(p,document.createTextNode(" Case sensitive"));const u=c("span",{class:"an-fr-counter"});this._counterEl=u,r.append(h,u),t.appendChild(r);const m=c("div",{class:"an-dialog-actions an-fr-find-actions"}),f=c("button",{type:"button",class:"an-btn"});f.textContent="← Prev";const g=c("button",{type:"button",class:"an-btn an-btn-primary"});g.textContent="Next →",m.append(f,g),t.appendChild(m);const v=c("div",{class:"an-fr-replace-row"});v.style.display="none";const k=c("input",{type:"text",class:"an-input",placeholder:"Replace with…","aria-label":"Replace with"});this._replaceInput=k,v.appendChild(k),t.appendChild(v);const T=c("div",{class:"an-dialog-actions an-fr-replace-actions"});T.style.display="none";const C=c("button",{type:"button",class:"an-btn"});C.textContent="Replace";const b=c("button",{type:"button",class:"an-btn an-btn-primary"});b.textContent="Replace All",T.append(C,b),t.appendChild(T),e.appendChild(t);const w=d(o,"click",()=>this._close()),_=d(e,"click",j=>{j.target===e&&this._close()}),y=d(l,"input",()=>this._onSearch()),I=d(p,"change",()=>{this._caseSensitive=p.checked,this._onSearch()}),E=d(g,"click",()=>this._next()),B=d(f,"click",()=>this._prev()),L=d(C,"click",()=>this._replace()),F=d(b,"click",()=>this._replaceAll()),K=d(l,"keydown",j=>{j.key==="Enter"&&(j.preventDefault(),j.shiftKey?this._prev():this._next())}),G=d(k,"keydown",j=>{j.key==="Enter"&&(j.preventDefault(),this._replace())});return this._disposers.push(w,_,y,I,E,B,L,F,K,G),e}_onSearch(){this._clearHighlights();const e=this._findInput?this._findInput.value:"";if(!e){this._updateCounter();return}this._findAndHighlight(e),this._updateCounter()}_findAndHighlight(e){const t=this.context.layoutInfo.editable;if(!t)return;const i=this._findRawMatches(e,t);if(i.length!==0){this._currentIndex=0;for(let s=i.length-1;s>=0;s--){const{node:o,start:a,end:l}=i[s];try{const r=document.createRange();r.setStart(o,a),r.setEnd(o,l);const h=document.createElement("mark");h.className="an-highlight",r.surroundContents(h),this._matches.unshift({mark:h})}catch{this._matches.unshift({mark:null})}}this._matches=this._matches.filter(s=>s.mark),this._matches.length!==0&&this._matches[0]&&this._matches[0].mark&&(this._matches[0].mark.className="an-highlight an-highlight-current",this._matches[0].mark.scrollIntoView({block:"center",behavior:"smooth"}))}}_findRawMatches(e,t){const i=[],s=this._caseSensitive?"g":"gi",o=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(o,s),l=document.createTreeWalker(t,4);let r;for(;r=l.nextNode();){a.lastIndex=0;let h;for(;(h=a.exec(r.textContent))!==null;)i.push({node:r,start:h.index,end:h.index+h[0].length})}return i}_next(){this._matches.length!==0&&(this._currentIndex=(this._currentIndex+1)%this._matches.length,this._scrollToMatch(this._currentIndex),this._updateCounter())}_prev(){this._matches.length!==0&&(this._currentIndex=(this._currentIndex-1+this._matches.length)%this._matches.length,this._scrollToMatch(this._currentIndex),this._updateCounter())}_scrollToMatch(e){const t=this._matches[e];!t||!t.mark||(this._matches.forEach((i,s)=>{i.mark&&(i.mark.className=s===e?"an-highlight an-highlight-current":"an-highlight")}),t.mark.scrollIntoView({block:"center",behavior:"smooth"}))}_replace(){if(this._matches.length===0||this._currentIndex<0)return;const e=this._matches[this._currentIndex];if(!e||!e.mark||!e.mark.parentNode)return;const t=this._replaceInput?this._replaceInput.value:"",i=e.mark.parentNode,s=document.createTextNode(t);i.insertBefore(s,e.mark),i.removeChild(e.mark),i.normalize(),this.context.invoke("editor.afterCommand");const o=this._currentIndex;this._onSearch(),this._matches.length>0&&(this._currentIndex=Math.min(o,this._matches.length-1),this._scrollToMatch(this._currentIndex),this._updateCounter())}_replaceAll(){if(this._matches.length===0)return;const e=this._replaceInput?this._replaceInput.value:"";this._matches.forEach(({mark:t})=>{if(!t||!t.parentNode)return;const i=document.createTextNode(e);t.parentNode.insertBefore(i,t),t.parentNode.removeChild(t)}),this.context.layoutInfo.editable&&this.context.layoutInfo.editable.normalize(),this._matches=[],this._currentIndex=-1,this.context.invoke("editor.afterCommand"),this._onSearch()}_clearHighlights(){const e=this.context.layoutInfo.editable;e&&(e.querySelectorAll("mark.an-highlight").forEach(t=>{const i=t.parentNode;if(i){for(;t.firstChild;)i.insertBefore(t.firstChild,t);i.removeChild(t)}}),e.normalize(),this._matches=[],this._currentIndex=-1)}_updateCounter(){if(!this._counterEl)return;const e=this._matches.length;if(e===0){const t=this._findInput?this._findInput.value:"";this._counterEl.textContent=t?"No results":""}else this._counterEl.textContent=`${this._currentIndex+1} / ${e}`}}const qe=new Map;class Ni{constructor(e,t={}){this.targetEl=e,this.options=W(U,t),this.layoutInfo={},this._listeners=new Map,this._modules=new Map,this._disposers=[],this._alive=!1}initialize(){const{container:e,editable:t}=Pt(this.targetEl,this.options);this.layoutInfo.container=e,this.layoutInfo.editable=t,this._registerModules();const i=this._modules.get("toolbar");i&&i.el&&(e.insertBefore(i.el,t),this.layoutInfo.toolbar=i.el);const s=this._modules.get("statusbar");return s&&s.el&&(e.appendChild(s.el),this.layoutInfo.statusbar=s.el),this._bindEditorEvents(t),this.options.focus&&t.focus(),this._alive=!0,this.invoke("toolbar.refresh"),typeof this.options.onInit=="function"&&this.options.onInit(this),this}_registerModules(){const e=(t,i)=>{const s=new i(this);s.initialize(),this._modules.set(t,s)};e("editor",Xt),e("toolbar",Yt),e("statusbar",Kt),e("clipboard",Gt),e("contextMenu",Ai),e("placeholder",Qt),e("codeview",Zt),e("fullscreen",Jt),e("linkDialog",ei),e("imageDialog",ti),e("videoDialog",ii),e("imageResizer",oi),e("videoResizer",ai),e("linkTooltip",ci),e("imageTooltip",pi),e("videoTooltip",fi),e("tableTooltip",vi),e("codeTooltip",xi),e("emojiDialog",Ti),e("iconDialog",Ri),e("shortcutsDialog",Bi),e("findReplace",Mi);for(const[t,i]of qe)e(t,i)}registerModule(e,t){if(this._modules.has(e))return this;const i=new t(this);return i.initialize(),this._modules.set(e,i),this}_bindEditorEvents(e){const t=d(e,"focus",()=>{this.layoutInfo.container.classList.add("an-focused"),typeof this.options.onFocus=="function"&&this.options.onFocus(this)}),i=d(e,"blur",()=>{this.layoutInfo.container.classList.remove("an-focused"),this._syncToTarget(),typeof this.options.onBlur=="function"&&this.options.onBlur(this)}),s=this.on("change",()=>this._syncToTarget());if(this._disposers.push(t,i,s),this.options.autoSave&&this.options.autoSaveKey){const o=this.on("change",()=>{try{localStorage.setItem(this.options.autoSaveKey,this.getHTML())}catch{}});this._disposers.push(o)}}invoke(e,...t){var a,l;const[i,s]=e.split("."),o=this._modules.get(i);if(!o){(typeof process>"u"||((a=process.env)==null?void 0:a.NODE_ENV)!=="production")&&console.warn(`[AutumnNote] invoke: module "${i}" not found (path: "${e}")`);return}if(typeof o[s]!="function"){(typeof process>"u"||((l=process.env)==null?void 0:l.NODE_ENV)!=="production")&&console.warn(`[AutumnNote] invoke: method "${s}" not found on module "${i}" (path: "${e}")`);return}return o[s](...t)}on(e,t){return this._listeners.has(e)||this._listeners.set(e,[]),this._listeners.get(e).push(t),()=>this.off(e,t)}off(e,t){const i=this._listeners.get(e);if(!i)return;const s=i.indexOf(t);s!==-1&&i.splice(s,1)}triggerEvent(e,...t){(this._listeners.get(e)||[]).forEach(o=>o(...t));const s="on"+e.charAt(0).toUpperCase()+e.slice(1);typeof this.options[s]=="function"&&this.options[s](...t)}getHTML(){return this.invoke("editor.getHTML")}setHTML(e){this.invoke("editor.setHTML",e)}getText(){return this.invoke("editor.getText")}setText(e){this.invoke("editor.setText",e)}clear(){this.invoke("editor.clear")}clearHistory(){this.invoke("editor.clearHistory")}isEmpty(){return this.invoke("editor.isEmpty")}insertHTML(e){this.invoke("editor.insertHTML",e)}insertText(e){this.invoke("editor.insertText",e)}setMarkdown(e){this.invoke("editor.setMarkdown",e)}getMarkdown(){return this.invoke("editor.getMarkdown")}getWordCount(){return this.invoke("statusbar.getWordCount")??0}getCharCount(){return this.invoke("statusbar.getCharCount")??0}downloadHTML(e="document.html"){this._download(this.getHTML(),e,"text/html")}downloadText(e="document.txt"){this._download(this.getText(),e,"text/plain")}downloadMarkdown(e="document.md"){this._download(this.getMarkdown(),e,"text/markdown")}_download(e,t,i){const s=new Blob([e],{type:i}),o=URL.createObjectURL(s),a=document.createElement("a");a.href=o,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}print(e=""){const t=this.getHTML(),i=(e||"").replace(/</g,"&lt;").replace(/>/g,"&gt;"),s=window.open("","_blank");s&&(s.document.write(`<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>${i}</title><style>body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;font-size:14px;line-height:1.6;padding:20mm;color:#111827;}ul.an-checklist{list-style:none;padding-left:0;}ul.an-checklist li{padding-left:24px;position:relative;margin:2px 0;}ul.an-checklist li input[type="checkbox"]{position:absolute;left:0;top:3px;}code{background:#f3f4f6;border-radius:3px;padding:.1em .35em;font-family:monospace;}pre{background:#f3f4f6;padding:.75em 1em;border-radius:4px;overflow-x:auto;}table{border-collapse:collapse;}td,th{border:1px solid #d1d5db;padding:4px 8px;}</style></head><body>${t}</body></html>`),s.document.close(),s.onload=()=>{s.print()})}setDisabled(e){const t=this.layoutInfo.editable;e?(t.setAttribute("contenteditable","false"),this.layoutInfo.container.classList.add("an-disabled")):(t.setAttribute("contenteditable","true"),this.layoutInfo.container.classList.remove("an-disabled"))}destroy(){if(!this._alive)return;this._modules.forEach(t=>{typeof t.destroy=="function"&&t.destroy()}),this._modules.clear(),this._disposers.forEach(t=>t()),this._disposers=[];const e=this.layoutInfo.container;e&&e.parentNode&&(this.targetEl.style.display="",e.parentNode.removeChild(e)),typeof this.options.onDestroy=="function"&&this.options.onDestroy(this),this._alive=!1,this._listeners.clear()}_syncToTarget(){(this.targetEl.tagName==="TEXTAREA"||this.targetEl.tagName==="INPUT")&&(this.targetEl.value=this.getHTML())}}const ji={...U},Q=new WeakMap,zi={create(n,e={}){const i=Ue(n).map(s=>{if(Q.has(s))return Q.get(s);const o=new Ni(s,e);return o.initialize(),Q.set(s,o),o});return i.length===1?i[0]:i},destroy(n){Ue(n).forEach(e=>{const t=Q.get(e);t&&(t.destroy(),Q.delete(e))})},getInstance(n){const e=typeof n=="string"?document.querySelector(n):n;return e&&Q.get(e)||null},get defaults(){return{...U}},setDefaults(n){Object.assign(U,n)},resetDefaults(){Object.keys(U).forEach(n=>delete U[n]),Object.assign(U,ji)},registerModule(n,e){qe.set(n,e)},version:"1.0.1"};function Ue(n){return typeof n=="string"?Array.from(document.querySelectorAll(n)):n instanceof Element?[n]:n instanceof NodeList||Array.isArray(n)?Array.from(n):[]}return zi});
70
+ `).map(s=>{const o=s.trim();if(!o)return"";/^<\//.test(o)&&(i=Math.max(0,i-1));const n=" ".repeat(i)+o;return/^<[^/!][^>]*[^/]>/.test(o)&&!e.test(o)&&!/^<(br|hr|img|input|link|meta)/.test(o)&&i++,n}).filter(Boolean).join(`
71
+ `)}}class ii{constructor(t){this.context=t,this._active=!1,this._disposers=[],this._prevHeight=""}initialize(){const t=p(document,"keydown",e=>{this._active&&O(e,F.ESCAPE)&&this.deactivate()});return this._disposers.push(t),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._active&&this.deactivate()}toggle(){this._active?this.deactivate():this.activate()}isActive(){return this._active}activate(){if(this._active)return;const t=this.context.layoutInfo.container;this._prevHeight=t.style.height,t.classList.add("an-fullscreen"),t.style.height="",document.body.style.overflow="hidden",this._active=!0,this.context.invoke("toolbar.refresh")}deactivate(){if(!this._active)return;const t=this.context.layoutInfo.container;t.classList.remove("an-fullscreen"),t.style.height=this._prevHeight,document.body.style.overflow="",this._active=!1,this.context.invoke("toolbar.refresh")}}class si{constructor(t){this.context=t,this.options=t.options,this._dialog=null,this._disposers=[],this._savedRange=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){it(t=>{this._savedRange=t}),this._prefill(),this._open()}_buildDialog(){const t=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert link"}),e=c("div",{class:"an-dialog-box"}),i=c("h3",{class:"an-dialog-title"});i.textContent="Insert Link";const s=c("label",{class:"an-label"});s.textContent="URL";const o=c("input",{type:"url",class:"an-input",placeholder:"https://",id:"an-link-url",name:"url",autocomplete:"off"});this._urlInput=o;const n=c("label",{class:"an-label"});n.textContent="Display Text";const r=c("input",{type:"text",class:"an-input",placeholder:"Link text",id:"an-link-text",name:"linkText",autocomplete:"off"});this._textInput=r;const l=c("label",{class:"an-label an-label-inline"}),h=c("input",{type:"checkbox",id:"an-link-newtab",name:"openInNewTab"});this._tabCheckbox=h,l.appendChild(h),l.appendChild(document.createTextNode(" Open in new tab"));const m=c("div",{class:"an-dialog-actions"}),d=c("button",{type:"button",class:"an-btn an-btn-primary"});d.textContent="Insert";const u=c("button",{type:"button",class:"an-btn"});u.textContent="Cancel",m.appendChild(d),m.appendChild(u),e.append(i,s,o,n,r,l,m),t.appendChild(e);const f=p(d,"click",()=>this._onInsert()),g=p(u,"click",()=>this._close()),_=p(t,"click",k=>{k.target===t&&this._close()}),b=p(o,"keydown",k=>{k.key==="Enter"&&(k.preventDefault(),this._onInsert())}),T=p(r,"keydown",k=>{k.key==="Enter"&&(k.preventDefault(),this._onInsert())});return this._disposers.push(f,g,_,b,T),t}_prefill(){const t=window.getSelection();let e=null;if(t&&t.rangeCount>0){let i=t.getRangeAt(0).startContainer;for(;i;){if(i.nodeName==="A"){e=i;break}i=i.parentNode}}e?(this._urlInput.value=e.getAttribute("href")||"",this._textInput.value=e.textContent||"",this._tabCheckbox.checked=e.getAttribute("target")==="_blank"):(this._urlInput.value="",this._textInput.value=t?t.toString():"",this._tabCheckbox.checked=!1)}_onInsert(){let t=this._urlInput.value.trim();const e=this._textInput.value.trim(),i=this._tabCheckbox.checked;if(!t){this._urlInput.focus();return}/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(t)||(t="https://"+t);try{const s=new URL(t);if(/^javascript:/i.test(s.protocol)||/^vbscript:/i.test(s.protocol)||/^data:/i.test(s.protocol)){this._urlInput.focus();return}}catch{this._urlInput.focus();return}this._savedRange&&this._savedRange.select(),this.context.invoke("editor.insertLink",t,e,i),this._close()}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=V(this._dialog,()=>this._close()),setTimeout(()=>this._urlInput&&this._urlInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}}class oi{constructor(t){this.context=t,this.options=t.options,this._dialog=null,this._disposers=[],this._savedRange=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){it(t=>{this._savedRange=t}),this._urlInput.value="",this._altInput.value="",this._fileInput&&(this._fileInput.value=""),this._open()}_buildDialog(){const t=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert image"}),e=c("div",{class:"an-dialog-box"}),i=c("h3",{class:"an-dialog-title"});i.textContent="Insert Image";const s=c("label",{class:"an-label"});s.textContent="Image URL";const o=c("input",{type:"url",class:"an-input",placeholder:"https://example.com/image.png",autocomplete:"off"});this._urlInput=o;const n=c("label",{class:"an-label"});n.textContent="Alt Text";const r=c("input",{type:"text",class:"an-input",placeholder:"Describe the image",autocomplete:"off"});this._altInput=r,e.append(i,s,o,n,r);const l=c("label",{class:"an-label"});l.textContent="Alignment";const h=c("div",{class:"an-align-row"});if([{value:"",label:"None"},{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}].forEach(({value:w,label:x})=>{const y=`an-align-${w||"none"}`,v=c("input",{type:"radio",name:"an-img-align",id:y,value:w});w===""&&(v.checked=!0);const E=c("label",{for:y,class:"an-align-label"});E.textContent=x,h.append(v,E)}),this._alignRow=h,e.append(l,h),this.options.allowImageUpload!==!1){const w=c("label",{class:"an-label"});w.textContent="Or upload a file";const x=c("input",{type:"file",class:"an-input",accept:"image/*"});this._fileInput=x;const y=p(x,"change",()=>this._onFileChange());this._disposers.push(y),e.append(w,x)}const d=c("div",{class:"an-dialog-actions"}),u=c("button",{type:"button",class:"an-btn an-btn-primary"});u.textContent="Insert";const f=c("button",{type:"button",class:"an-btn"});f.textContent="Cancel",d.appendChild(u),d.appendChild(f),e.append(d),t.appendChild(e);const g=p(u,"click",()=>this._onInsert()),_=p(f,"click",()=>this._close()),b=p(t,"click",w=>{w.target===t&&this._close()}),T=p(o,"keydown",w=>{w.key==="Enter"&&(w.preventDefault(),this._onInsert())}),k=p(r,"keydown",w=>{w.key==="Enter"&&(w.preventDefault(),this._onInsert())});return this._disposers.push(g,_,b,T,k),t}_onFileChange(){const t=this._fileInput&&this._fileInput.files&&this._fileInput.files[0];if(!t||!t.type.startsWith("image/"))return;const e=(this.options.maxImageSize||5)*1024*1024;if(t.size>e){const s=`Image file is too large. Maximum allowed size is ${this.options.maxImageSize||5} MB.`;console.warn("[AutumnNote] ImageDialog:",s),this.context.triggerEvent("imageError",{file:t,message:s}),this._fileInput.value="";return}const i=new FileReader;i.onload=s=>{this._urlInput.value=s.target.result},i.readAsDataURL(t)}_onInsert(){const t=this._urlInput.value.trim(),e=this._altInput.value.trim(),i=this._alignRow&&this._alignRow.querySelector('input[name="an-img-align"]:checked'),s=i?i.value:"";if(!t){this._urlInput.focus();return}this._savedRange&&this._savedRange.select(),this.context.invoke("editor.insertImage",t,e,s),this._close()}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=V(this._dialog,()=>this._close()),setTimeout(()=>this._urlInput&&this._urlInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}}class ni{constructor(t){this.context=t,this.options=t.options,this._dialog=null,this._disposers=[],this._savedRange=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){it(t=>{this._savedRange=t}),this._urlInput.value="",this._widthInput.value="560",this._hintEl.textContent="",this._open()}_buildDialog(){const t=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert video"}),e=c("div",{class:"an-dialog-box"}),i=c("h3",{class:"an-dialog-title"});i.textContent="Insert Video";const s=c("label",{class:"an-label"});s.textContent="Video URL";const o=c("input",{type:"url",class:"an-input",placeholder:"YouTube, Vimeo, or direct .mp4 URL",autocomplete:"off"});this._urlInput=o;const n=c("p",{class:"an-dialog-hint"});this._hintEl=n;const r=c("label",{class:"an-label"});r.textContent="Width (px)";const l=c("input",{type:"number",class:"an-input",placeholder:"560",min:"80",max:"1920",value:"560"});this._widthInput=l;const h=c("div",{class:"an-dialog-actions"}),m=c("button",{type:"button",class:"an-btn an-btn-primary"});m.textContent="Insert";const d=c("button",{type:"button",class:"an-btn"});d.textContent="Cancel",h.appendChild(m),h.appendChild(d),e.append(i,s,o,n,r,l,h),t.appendChild(e);const u=p(o,"input",()=>{const T=this._parseVideoUrl(o.value.trim());n.textContent=T?`Detected: ${T.type}`:o.value?"Unknown format — will try direct video embed":""}),f=p(m,"click",()=>this._onInsert()),g=p(d,"click",()=>this._close()),_=p(t,"click",T=>{T.target===t&&this._close()}),b=p(o,"keydown",T=>{T.key==="Enter"&&(T.preventDefault(),this._onInsert())});return this._disposers.push(u,f,g,_,b),t}_onInsert(){const t=this._urlInput.value.trim(),e=Math.max(80,parseInt(this._widthInput.value,10)||560);if(!t){this._urlInput.focus();return}const i=this._buildEmbedHtml(t,e);if(!i){this._hintEl.textContent="Invalid URL — please enter a valid video link.",this._urlInput.focus();return}this._savedRange&&this._savedRange.select(),this.context.invoke("editor.insertVideo",i),this._close()}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=V(this._dialog,()=>this._close()),setTimeout(()=>this._urlInput&&this._urlInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}_parseVideoUrl(t){if(!t)return null;try{const n=new URL(t);if(/^javascript:/i.test(n.protocol)||/^vbscript:/i.test(n.protocol))return null}catch{return null}const e=t.match(/(?:youtube\.com\/watch\?(?:.*&)?v=|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/);if(e)return{type:"YouTube",embedUrl:`https://www.youtube.com/embed/${e[1]}`};const i=t.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);if(i)return{type:"YouTube",embedUrl:`https://www.youtube.com/embed/${i[1]}`};const s=t.match(/youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/);if(s)return{type:"YouTube Shorts",embedUrl:`https://www.youtube.com/embed/${s[1]}`};const o=t.match(/vimeo\.com\/(\d+)/);return o?{type:"Vimeo",embedUrl:`https://player.vimeo.com/video/${o[1]}`}:/\.(mp4|webm|ogg|ogv|mov)(#.*|\?.*)?$/i.test(t)?{type:"Direct video",embedUrl:t}:null}_buildEmbedHtml(t,e){const i=this._parseVideoUrl(t),s=Math.round(e*9/16);if(i&&(i.type==="YouTube"||i.type==="YouTube Shorts"||i.type==="Vimeo")){const r=`${i.type} video player`;return`<div class="an-video-wrapper" style="position:relative;display:block;width:${e}px;max-width:100%"><iframe src="${i.embedUrl}" width="${e}" height="${s}" title="${r}" frameborder="0" allowfullscreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" style="display:block;max-width:100%"></iframe><div class="an-video-shield"></div></div>`}if(i&&i.type==="Direct video"){const r=i.embedUrl.replace(/"/g,"%22");return`<div class="an-video-wrapper" style="position:relative;display:block;width:${e}px;max-width:100%"><video src="${r}" width="${e}" height="${s}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`}const o=(()=>{try{const r=new URL(t);return/^javascript:/i.test(r.protocol)||/^vbscript:/i.test(r.protocol)?null:t}catch{return null}})();if(!o)return null;const n=o.replace(/"/g,"%22");return`<div class="an-video-wrapper" style="position:relative;display:block;width:${e}px;max-width:100%"><video src="${n}" width="${e}" height="${s}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`}}const ai=[{pos:"nw",cursor:"nw-resize"},{pos:"n",cursor:"n-resize"},{pos:"ne",cursor:"ne-resize"},{pos:"e",cursor:"e-resize"},{pos:"se",cursor:"se-resize"},{pos:"s",cursor:"s-resize"},{pos:"sw",cursor:"sw-resize"},{pos:"w",cursor:"w-resize"}];class li{constructor(t){this.context=t,this._activeImg=null,this._overlay=null,this._disposers=[],this._positionRaf=null}initialize(){this._overlay=this._buildOverlay();const t=this.context.layoutInfo.editable.closest(".an-container")||document.body;t.appendChild(this._overlay),this._container=t;const e=this.context.layoutInfo.editable;let i=null;const s=()=>{clearTimeout(i),i=setTimeout(()=>this._updateOverlayPosition(),100)};return this._disposers.push(p(e,"click",o=>this._onEditorClick(o)),p(e,"contextmenu",o=>{const n=o.target.closest("img");n&&this._select(n)}),p(document,"click",o=>this._onDocClick(o)),p(window,"scroll",()=>this._updateOverlayPosition(),{passive:!0}),p(window,"resize",s),p(e,"scroll",()=>this._updateOverlayPosition(),{passive:!0})),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dragDisposers&&(this._dragDisposers.forEach(t=>t()),this._dragDisposers=null),this._positionRaf&&(cancelAnimationFrame(this._positionRaf),this._positionRaf=null),this._deselect(),this._overlay&&this._overlay.parentNode&&this._overlay.parentNode.removeChild(this._overlay),this._overlay=null}getActiveImage(){return this._activeImg}updateOverlay(){this._updateOverlayPosition()}deselect(){this._deselect()}_buildOverlay(){const t=document.createElement("div");return t.className="an-image-resizer",t.style.display="none",ai.forEach(({pos:e})=>{const i=document.createElement("div");i.className=`an-resize-handle an-resize-${e}`,i.dataset.handle=e,this._disposers.push(p(i,"mousedown",s=>{s.preventDefault(),s.stopPropagation(),this._startResize(s,e)})),t.appendChild(i)}),t}_onEditorClick(t){const e=t.target.closest("img");e&&(t.preventDefault(),this._select(e))}_onDocClick(t){this._activeImg&&t.target!==this._activeImg&&(this._overlay&&this._overlay.contains(t.target)||t.target.closest(".an-contextmenu")||this._deselect())}_select(t){this._activeImg&&this._activeImg!==t&&this._activeImg.classList.remove("an-image-selected"),this._activeImg=t,t.classList.add("an-image-selected"),this._updateOverlayPosition(),this._overlay.style.display="block"}_deselect(){this._activeImg&&(this._activeImg.classList.remove("an-image-selected"),this._activeImg=null),this._overlay&&(this._overlay.style.display="none")}_updateOverlayPosition(){this._positionRaf&&cancelAnimationFrame(this._positionRaf),this._positionRaf=requestAnimationFrame(()=>{this._positionRaf=null,this._updateOverlayPositionNow()})}_updateOverlayPositionNow(){if(!this._activeImg||!this._overlay)return;const t=this._overlay.offsetParent||this._container,e=t.getBoundingClientRect(),i=this._activeImg.getBoundingClientRect(),s=i.left-e.left+t.scrollLeft,o=i.top-e.top+t.scrollTop;this._overlay.style.left=`${s}px`,this._overlay.style.top=`${o}px`,this._overlay.style.width=`${i.width}px`,this._overlay.style.height=`${i.height}px`}_startResize(t,e){const i=this._activeImg;if(!i)return;const s=t.clientX,o=t.clientY,n=i.offsetWidth||i.naturalWidth||100,r=i.offsetHeight||i.naturalHeight||100,l=n/r,h=e.length===2,m=this.context.layoutInfo.editable;let d=null;const u=g=>{if(d!==null)return;const _=g.clientX,b=g.clientY;d=requestAnimationFrame(()=>{d=null;const T=_-s,k=b-o,w=m.clientWidth||1/0;let x=n,y=r;e.includes("e")&&(x=Math.max(20,n+T)),e.includes("w")&&(x=Math.max(20,n-T)),e.includes("s")&&(y=Math.max(20,r+k)),e.includes("n")&&(y=Math.max(20,r-k)),x=Math.min(x,w),h&&(Math.abs(T)>=Math.abs(k)||(x=Math.min(Math.max(20,Math.round(y*l)),w)),y=Math.max(20,Math.round(x/l))),i.style.width=`${x}px`,i.style.height=`${y}px`,this._updateOverlayPosition()})},f=()=>{d!==null&&(cancelAnimationFrame(d),d=null),document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",f),this._dragDisposers=null,this.context.invoke("editor.afterCommand")};document.addEventListener("mousemove",u),document.addEventListener("mouseup",f),this._dragDisposers=[()=>document.removeEventListener("mousemove",u),()=>document.removeEventListener("mouseup",f)]}}const ri=[{pos:"nw",cursor:"nw-resize"},{pos:"n",cursor:"n-resize"},{pos:"ne",cursor:"ne-resize"},{pos:"e",cursor:"e-resize"},{pos:"se",cursor:"se-resize"},{pos:"s",cursor:"s-resize"},{pos:"sw",cursor:"sw-resize"},{pos:"w",cursor:"w-resize"}];class ci{constructor(t){this.context=t,this._activeWrapper=null,this._overlay=null,this._disposers=[],this._positionRaf=null}initialize(){this._overlay=this._buildOverlay();const t=this.context.layoutInfo.editable.closest(".an-container")||document.body;t.appendChild(this._overlay),this._container=t;const e=this.context.layoutInfo.editable;let i=null;const s=()=>{clearTimeout(i),i=setTimeout(()=>this._updateOverlayPosition(),100)};return this._disposers.push(p(e,"click",o=>this._onEditorClick(o)),p(e,"contextmenu",o=>{const n=this._findWrapper(o.target);n&&this._select(n)}),p(document,"click",o=>this._onDocClick(o)),p(window,"scroll",()=>this._updateOverlayPosition(),{passive:!0}),p(window,"resize",s),p(e,"scroll",()=>this._updateOverlayPosition(),{passive:!0})),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dragDisposers&&(this._dragDisposers.forEach(t=>t()),this._dragDisposers=null),this._positionRaf&&(cancelAnimationFrame(this._positionRaf),this._positionRaf=null),this._deselect(),this._overlay&&this._overlay.parentNode&&this._overlay.parentNode.removeChild(this._overlay),this._overlay=null}getActiveWrapper(){return this._activeWrapper}updateOverlay(){this._updateOverlayPosition()}deselect(){this._deselect()}_findWrapper(t){if(!t||!(t instanceof Element))return null;if(t.classList&&t.classList.contains("an-video-wrapper"))return t;const e=t.closest(".an-video-wrapper");return e||null}_buildOverlay(){const t=document.createElement("div");return t.className="an-video-resizer",t.style.display="none",ri.forEach(({pos:e})=>{const i=document.createElement("div");i.className=`an-resize-handle an-resize-${e}`,i.dataset.handle=e,this._disposers.push(p(i,"mousedown",s=>{s.preventDefault(),s.stopPropagation(),this._startResize(s,e)})),t.appendChild(i)}),t}_onEditorClick(t){const e=this._findWrapper(t.target);e&&(t.preventDefault(),this._select(e))}_onDocClick(t){this._activeWrapper&&(this._activeWrapper.contains(t.target)||this._overlay&&this._overlay.contains(t.target)||t.target.closest(".an-contextmenu")||this._deselect())}_select(t){this._activeWrapper&&this._activeWrapper!==t&&this._activeWrapper.classList.remove("an-video-selected"),this._activeWrapper=t,t.classList.add("an-video-selected"),this._updateOverlayPosition(),this._overlay.style.display="block"}_deselect(){this._activeWrapper&&(this._activeWrapper.classList.remove("an-video-selected"),this._activeWrapper=null),this._overlay&&(this._overlay.style.display="none")}_updateOverlayPosition(){this._positionRaf&&cancelAnimationFrame(this._positionRaf),this._positionRaf=requestAnimationFrame(()=>{this._positionRaf=null,this._updateOverlayPositionNow()})}_updateOverlayPositionNow(){if(!this._activeWrapper||!this._overlay)return;const t=this._overlay.offsetParent||this._container,e=t.getBoundingClientRect(),i=this._activeWrapper.getBoundingClientRect(),s=i.left-e.left+t.scrollLeft,o=i.top-e.top+t.scrollTop;this._overlay.style.left=`${s}px`,this._overlay.style.top=`${o}px`,this._overlay.style.width=`${i.width}px`,this._overlay.style.height=`${i.height}px`}_startResize(t,e){const i=this._activeWrapper;if(!i)return;const s=i.querySelector("iframe, video"),o=t.clientX,n=t.clientY,r=i.offsetWidth||560,l=i.offsetHeight||315,h=r/l,m=e.length===2,d=this.context.layoutInfo.editable;let u=null;const f=_=>{if(u!==null)return;const b=_.clientX,T=_.clientY;u=requestAnimationFrame(()=>{u=null;const k=b-o,w=T-n,x=d.clientWidth||1/0;let y=r,v=l;e.includes("e")&&(y=Math.max(80,r+k)),e.includes("w")&&(y=Math.max(80,r-k)),e.includes("s")&&(v=Math.max(45,l+w)),e.includes("n")&&(v=Math.max(45,l-w)),y=Math.min(y,x),m&&(Math.abs(k)>=Math.abs(w)||(y=Math.min(Math.max(80,Math.round(v*h)),x)),v=Math.max(45,Math.round(y/h))),i.style.width=`${y}px`,i.style.height=`${v}px`,s&&(s.style.width=`${y}px`,s.style.height=`${v}px`),this._updateOverlayPosition()})},g=()=>{u!==null&&(cancelAnimationFrame(u),u=null),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g),this._dragDisposers=null,this.context.invoke("editor.afterCommand")};document.addEventListener("mousemove",f),document.addEventListener("mouseup",g),this._dragDisposers=[()=>document.removeEventListener("mousemove",f),()=>document.removeEventListener("mouseup",g)]}}const rt={open:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',edit:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',unlink:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18.84 12.25l1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71"/><path d="M5.17 11.75l-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71"/><line x1="8" y1="2" x2="8" y2="5"/><line x1="2" y1="8" x2="5" y2="8"/><line x1="16" y1="19" x2="16" y2="22"/><line x1="19" y1="16" x2="22" y2="16"/></svg>',copy:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>'},hi=120,di=200;class pi{constructor(t){this.context=t,this._el=null,this._activeAnchor=null,this._showTimer=null,this._hideTimer=null,this._disposers=[]}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el);const t=this.context.layoutInfo.editable;return this._disposers.push(p(t,"mouseover",e=>{const i=e.target.closest("a[href]");i&&t.contains(i)&&this._scheduleShow(i)}),p(t,"mouseout",e=>{const i=e.relatedTarget;(!i||!t.contains(i)&&!this._el.contains(i))&&this._scheduleHide()})),this}destroy(){this._clearTimers(),this._disposers.forEach(t=>t()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const t=c("div",{class:"an-link-tooltip",role:"toolbar","aria-label":"Link actions"});return t.style.display="none",this._urlLabel=c("span",{class:"an-link-tooltip-url"}),t.appendChild(this._urlLabel),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._openBtn=this._makeBtn(rt.open,"Open link",()=>this._openLink()),this._copyBtn=this._makeBtn(rt.copy,"Copy URL",()=>this._copyLink()),this._editBtn=this._makeBtn(rt.edit,"Edit link",()=>this._editLink()),this._unlinkBtn=this._makeBtn(rt.unlink,"Remove link",()=>this._unlink()),t.appendChild(this._openBtn),t.appendChild(this._copyBtn),t.appendChild(this._editBtn),t.appendChild(this._unlinkBtn),this._disposers.push(p(t,"mouseenter",()=>this._clearTimers()),p(t,"mouseleave",()=>this._scheduleHide())),t}_makeBtn(t,e,i){const s=c("button",{type:"button",class:"an-link-tooltip-btn",title:e});return s.innerHTML=t,this._disposers.push(p(s,"click",o=>{o.preventDefault(),o.stopPropagation(),i()})),s}_scheduleShow(t){this._activeAnchor===t&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeAnchor=t,this._show(t)},hi))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>{this._hide()},di))}_show(t){const e=t.getAttribute("href")||"";this._urlLabel.textContent=this._truncateUrl(e),this._urlLabel.title=e,this._el.style.display="flex",this._positionNear(t)}_hide(){this._el.style.display="none",this._activeAnchor=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(t){const e=t.getBoundingClientRect(),i=this._el.offsetWidth||260,s=this._el.offsetHeight||34,o=6;let n=e.bottom+o,r=e.left;n+s>window.innerHeight-o&&(n=e.top-s-o),r+i>window.innerWidth-o&&(r=window.innerWidth-i-o),r<o&&(r=o),this._el.style.top=`${n}px`,this._el.style.left=`${r}px`}_truncateUrl(t){try{const e=new URL(t),i=e.host+(e.pathname!=="/"?e.pathname:"");return i.length>48?i.slice(0,48)+"…":i}catch{return t.length>48?t.slice(0,48)+"…":t}}_openLink(){const t=this._activeAnchor&&this._activeAnchor.getAttribute("href");t&&window.open(t,"_blank","noopener,noreferrer"),this._hide()}_copyLink(){const t=this._activeAnchor&&this._activeAnchor.getAttribute("href");t&&navigator.clipboard.writeText(t).catch(()=>{const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}),this._copyBtn&&(this._copyBtn.classList.add("an-link-tooltip-btn--copied"),setTimeout(()=>this._copyBtn&&this._copyBtn.classList.remove("an-link-tooltip-btn--copied"),1e3))}_editLink(){const t=this._activeAnchor;if(!t)return;this._hide();const e=window.getSelection(),i=document.createRange();i.selectNodeContents(t),e.removeAllRanges(),e.addRange(i),this.context.invoke("linkDialog.show")}_unlink(){const t=this._activeAnchor;if(!t)return;this._hide();const e=window.getSelection(),i=document.createRange();i.selectNode(t),e.removeAllRanges(),e.addRange(i),document.execCommand("unlink"),this.context.invoke("editor.afterCommand")}}const D={floatLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="8" height="8" rx="1"/><line x1="12" y1="6" x2="22" y2="6"/><line x1="12" y1="9" x2="22" y2="9"/><line x1="12" y1="12" x2="22" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="14" y="4" width="8" height="8" rx="1"/><line x1="2" y1="6" x2="12" y2="6"/><line x1="2" y1="9" x2="12" y2="9"/><line x1="2" y1="12" x2="12" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatNone:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="8" height="8" rx="1"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="3" y1="19" x2="17" y2="19"/></svg>',alignCenter:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="4" width="10" height="8" rx="1"/><line x1="3" y1="16" x2="21" y2="16"/><line x1="6" y1="20" x2="18" y2="20"/></svg>',originalSize:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',deleteImg:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>',caption:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="11" rx="2"/><line x1="6" y1="18" x2="18" y2="18"/><line x1="9" y1="21" x2="15" y2="21"/></svg>',rotateLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><polyline points="3 3 3 8 8 8"/></svg>',rotateRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><polyline points="21 3 21 8 16 8"/></svg>',crop:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 2 6 18 22 18"/><polyline points="2 6 18 6 18 22"/></svg>'},ui=100,mi=180;class fi{constructor(t){this.context=t,this._el=null,this._activeImg=null,this._showTimer=null,this._hideTimer=null,this._disposers=[]}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el);const t=this.context.layoutInfo.editable;return this._disposers.push(p(t,"mouseover",e=>{const i=e.target.closest("img");i&&t.contains(i)&&!i.closest("a[href]")&&this._scheduleShow(i)},{passive:!0}),p(t,"mouseout",e=>{const i=e.relatedTarget;(!i||!t.contains(i)&&!this._el.contains(i))&&this._scheduleHide()},{passive:!0}),p(document,"click",e=>{this._activeImg&&!this._activeImg.contains(e.target)&&!this._el.contains(e.target)&&this._hide()})),this}destroy(){this._clearTimers(),this._disposers.forEach(t=>t()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const t=c("div",{class:"an-link-tooltip an-image-tooltip",role:"toolbar","aria-label":"Image actions"});return t.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Image",t.appendChild(this._label),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._floatLeftBtn=this._makeBtn(D.floatLeft,"Float Left",()=>this._setFloat("left")),this._floatNoneBtn=this._makeBtn(D.floatNone,"No Float",()=>this._setFloat("")),this._alignCenterBtn=this._makeBtn(D.alignCenter,"Align Center",()=>this._setCenter()),this._floatRightBtn=this._makeBtn(D.floatRight,"Float Right",()=>this._setFloat("right")),t.appendChild(this._floatLeftBtn),t.appendChild(this._floatNoneBtn),t.appendChild(this._alignCenterBtn),t.appendChild(this._floatRightBtn),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._originalBtn=this._makeBtn(D.originalSize,"Original Size",()=>this._resetSize()),t.appendChild(this._originalBtn),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),t.appendChild(this._makeBtn(D.rotateLeft,"Rotate Left",()=>this._rotate(-90))),t.appendChild(this._makeBtn(D.rotateRight,"Rotate Right",()=>this._rotate(90))),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._cropBtn=this._makeBtn(D.crop,"Crop Image",()=>this._crop()),t.appendChild(this._cropBtn),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._captionBtn=this._makeBtn(D.caption,"Add / Edit Caption",()=>this._toggleCaption()),t.appendChild(this._captionBtn),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._deleteBtn=this._makeBtn(D.deleteImg,"Delete Image",()=>this._delete(),!0),t.appendChild(this._deleteBtn),this._disposers.push(p(t,"mouseenter",()=>this._clearTimers()),p(t,"mouseleave",()=>this._scheduleHide())),t}_makeBtn(t,e,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:e});return o.innerHTML=t,this._disposers.push(p(o,"click",n=>{n.preventDefault(),n.stopPropagation(),i()})),o}_scheduleShow(t){this._activeImg===t&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeImg=t,this._show(t)},ui))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),mi))}_show(t){this._el.style.display="flex",requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_hide(){this._el.style.display="none",this._activeImg=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(t){const e=t.getBoundingClientRect(),i=this._el.offsetWidth||220,s=this._el.offsetHeight||32,o=6;let n=e.bottom+o,r=e.left+(e.width-i)/2;n+s>window.innerHeight-o&&(n=e.top-s-o),r+i>window.innerWidth-o&&(r=window.innerWidth-i-o),r<o&&(r=o),this._el.style.top=`${n}px`,this._el.style.left=`${r}px`}_setFloat(t){const e=this._activeImg;if(!e)return;const i=e.closest("figure.an-figure")||e;i.style.float=t,i.style.display="",i.style.marginLeft=t==="right"?"12px":"",i.style.marginRight=t==="left"?"12px":"",this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_setCenter(){const t=this._activeImg;if(!t)return;const e=t.closest("figure.an-figure")||t;e.style.float="",e.style.display="block",e.style.marginLeft="auto",e.style.marginRight="auto",this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_resetSize(){const t=this._activeImg;t&&(t.style.width="",t.style.height="",this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)}))}_rotate(t){const e=this._activeImg;if(!e)return;const i=e.style.transform||"",s=i.match(/rotate\((-?[\d.]+)deg\)/),n=((s?parseFloat(s[1]):0)+t+360)%360,r=i.replace(/rotate\(-?[\d.]+deg\)/,"").trim();e.style.transform=r?`${r} rotate(${n}deg)`:n===0?"":`rotate(${n}deg)`,this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeImg&&this._positionNear(this._activeImg)})}_delete(){const t=this._activeImg;if(!t)return;this._hide(),this.context.invoke("imageResizer.deselect");const e=t.closest("figure.an-figure");e&&e.parentNode?e.parentNode.removeChild(e):t.parentNode&&t.parentNode.removeChild(t),this.context.invoke("editor.afterCommand")}_crop(){const t=this._activeImg;t&&(this._hide(),this.context.invoke("imageCropOverlay.open",t))}_toggleCaption(){const t=this._activeImg;if(!t)return;const e=t.closest("figure.an-figure");if(e){const r=e.querySelector("figcaption.an-figcaption");if(r){this._hide();const l=document.createRange();l.selectNodeContents(r);const h=window.getSelection();h&&(h.removeAllRanges(),h.addRange(l))}return}const i=document.createElement("figure");i.className="an-figure",t.style.float?(i.style.float=t.style.float,i.style.marginLeft=t.style.marginLeft,i.style.marginRight=t.style.marginRight,t.style.float="",t.style.marginLeft="",t.style.marginRight=""):t.style.display==="block"&&t.style.marginLeft==="auto"&&(i.style.display="block",i.style.marginLeft="auto",i.style.marginRight="auto",t.style.display="",t.style.marginLeft="",t.style.marginRight="");const s=document.createElement("figcaption");s.className="an-figcaption",s.textContent="Caption",t.parentNode.insertBefore(i,t),i.appendChild(t),i.appendChild(s);const o=document.createRange();o.selectNodeContents(s);const n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(o)),this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay"),this._hide()}}const G={floatLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="8" height="8" rx="1"/><line x1="12" y1="6" x2="22" y2="6"/><line x1="12" y1="9" x2="22" y2="9"/><line x1="12" y1="12" x2="22" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="14" y="4" width="8" height="8" rx="1"/><line x1="2" y1="6" x2="12" y2="6"/><line x1="2" y1="9" x2="12" y2="9"/><line x1="2" y1="12" x2="12" y2="12"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="2" y1="20" x2="18" y2="20"/></svg>',floatNone:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="8" height="8" rx="1"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="3" y1="19" x2="17" y2="19"/></svg>',alignCenter:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="4" width="10" height="8" rx="1"/><line x1="3" y1="16" x2="21" y2="16"/><line x1="6" y1="20" x2="18" y2="20"/></svg>',originalSize:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',deleteVideo:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>',preview:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"/></svg>'},gi=100,_i=180;class yi{constructor(t){this.context=t,this._el=null,this._activeWrapper=null,this._showTimer=null,this._hideTimer=null,this._disposers=[],this._previewMode=!1,this._previewClickOff=null}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el);const t=this.context.layoutInfo.editable;return this._disposers.push(p(t,"mouseover",e=>{const i=e.target.closest(".an-video-wrapper");i&&t.contains(i)&&this._scheduleShow(i)},{passive:!0}),p(t,"mouseout",e=>{const i=e.relatedTarget;(!i||!t.contains(i)&&!this._el.contains(i))&&this._scheduleHide()},{passive:!0}),p(document,"click",e=>{this._activeWrapper&&!this._activeWrapper.contains(e.target)&&!this._el.contains(e.target)&&this._hide()})),this}destroy(){this._previewMode&&this._exitPreview(),this._clearTimers(),this._disposers.forEach(t=>t()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const t=c("div",{class:"an-link-tooltip an-video-tooltip",role:"toolbar","aria-label":"Video actions"});return t.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Video",t.appendChild(this._label),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._floatLeftBtn=this._makeBtn(G.floatLeft,"Float Left",()=>this._setFloat("left")),this._floatNoneBtn=this._makeBtn(G.floatNone,"No Float",()=>this._setFloat("")),this._alignCenterBtn=this._makeBtn(G.alignCenter,"Align Center",()=>this._setCenter()),this._floatRightBtn=this._makeBtn(G.floatRight,"Float Right",()=>this._setFloat("right")),t.appendChild(this._floatLeftBtn),t.appendChild(this._floatNoneBtn),t.appendChild(this._alignCenterBtn),t.appendChild(this._floatRightBtn),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._originalBtn=this._makeBtn(G.originalSize,"Original Size",()=>this._resetSize()),t.appendChild(this._originalBtn),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._previewBtn=this._makeBtn(G.preview,"Preview Video",()=>this._togglePreview()),t.appendChild(this._previewBtn),t.appendChild(c("div",{class:"an-link-tooltip-sep"})),this._deleteBtn=this._makeBtn(G.deleteVideo,"Delete Video",()=>this._delete(),!0),t.appendChild(this._deleteBtn),this._disposers.push(p(t,"mouseenter",()=>this._clearTimers()),p(t,"mouseleave",()=>this._scheduleHide())),t}_makeBtn(t,e,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:e});return o.innerHTML=t,this._disposers.push(p(o,"click",n=>{n.preventDefault(),n.stopPropagation(),i()})),o}_scheduleShow(t){this._activeWrapper===t&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeWrapper=t,this._show(t)},gi))}_scheduleHide(){this._previewMode||(clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),_i)))}_show(t){this._el.style.display="flex",requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)})}_hide(){this._previewMode&&this._exitPreview(),this._el.style.display="none",this._activeWrapper=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(t){const e=t.getBoundingClientRect(),i=this._el.offsetWidth||220,s=this._el.offsetHeight||32,o=6;let n=e.bottom+o,r=e.left+(e.width-i)/2;n+s>window.innerHeight-o&&(n=e.top-s-o),r+i>window.innerWidth-o&&(r=window.innerWidth-i-o),r<o&&(r=o),this._el.style.top=`${n}px`,this._el.style.left=`${r}px`}_setFloat(t){const e=this._activeWrapper;e&&(e.style.float=t,e.style.display=t?"inline-block":"",e.style.marginLeft=t==="right"?"12px":"",e.style.marginRight=t==="left"?"12px":"",this.context.invoke("editor.afterCommand"),this.context.invoke("videoResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)}))}_setCenter(){const t=this._activeWrapper;t&&(t.style.float="",t.style.display="block",t.style.marginLeft="auto",t.style.marginRight="auto",this.context.invoke("editor.afterCommand"),this.context.invoke("videoResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)}))}_resetSize(){const t=this._activeWrapper;if(!t)return;const e=t.querySelector("iframe, video");t.style.width="",t.style.height="",e&&(e.removeAttribute("width"),e.removeAttribute("height"),e.style.width="",e.style.height=""),this.context.invoke("editor.afterCommand"),this.context.invoke("videoResizer.updateOverlay"),requestAnimationFrame(()=>{this._activeWrapper&&this._positionNear(this._activeWrapper)})}_delete(){const t=this._activeWrapper;t&&(this._hide(),this.context.invoke("videoResizer.deselect"),t.parentNode&&t.parentNode.removeChild(t),this.context.invoke("editor.afterCommand"))}_togglePreview(){this._previewMode?this._exitPreview():this._enterPreview()}_enterPreview(){const t=this._activeWrapper;if(!t)return;this._previewMode=!0;const e=t.querySelector(".an-video-shield");e&&(e.style.display="none"),this.context.invoke("videoResizer.deselect"),this._previewBtn.classList.add("an-link-tooltip-btn--copied"),this._previewBtn.title="Exit Preview",this._previewClickOff=i=>{!t.contains(i.target)&&!this._el.contains(i.target)&&this._exitPreview()},document.addEventListener("mousedown",this._previewClickOff,!0)}_exitPreview(){this._previewMode=!1;const t=this._activeWrapper;if(t){const e=t.querySelector(".an-video-shield");e&&(e.style.display="")}this._previewBtn.classList.remove("an-link-tooltip-btn--copied"),this._previewBtn.title="Preview Video",this._previewClickOff&&(document.removeEventListener("mousedown",this._previewClickOff,!0),this._previewClickOff=null)}}const bi=120,vi=200;function ot(a){const t=a.closest("tr");if(!t)return-1;let e=0;for(const i of t.cells){if(i===a)return e;e+=i.colSpan||1}return-1}function ct(a,t){let e=0;for(const i of a.cells){if(e===t)return i;if(e>t)break;e+=i.colSpan||1}return null}function wi(a,t){let e=0;for(const i of a.cells)if(e+=i.colSpan||1,e>t){const s=i.nextElementSibling;return s&&s.tagName==="TD"||s&&s.tagName==="TH"?s:null}return null}const P={rowAbove:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="12" x2="21" y2="12"/><path d="M12 3v7"/><path d="M9 7l3-4 3 4"/></svg>',rowBelow:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="12" x2="21" y2="12"/><path d="M12 12v7"/><path d="M9 17l3 4 3-4"/></svg>',deleteRow:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="15" y1="15" x2="21" y2="21"/><line x1="21" y1="15" x2="15" y2="21"/></svg>',colLeft:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="12" y1="3" x2="12" y2="21"/><path d="M3 12h7"/><path d="M7 8l-4 4 4 4"/></svg>',colRight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="12" y1="3" x2="12" y2="21"/><path d="M12 12h9"/><path d="M17 8l4 4-4 4"/></svg>',deleteCol:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="12" y1="3" x2="12" y2="21"/><line x1="15" y1="6" x2="21" y2="12"/><line x1="21" y1="6" x2="15" y2="12"/></svg>',mergeCells:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="8" height="10" rx="1"/><rect x="14" y="7" width="8" height="10" rx="1"/><path d="M10 12h4"/><path d="M12 10l2 2-2 2"/></svg>',colWidth:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="4" x2="7" y2="20"/><line x1="17" y1="4" x2="17" y2="20"/><line x1="7" y1="12" x2="17" y2="12"/><path d="M10 9l-3 3 3 3"/><path d="M14 9l3 3-3 3"/></svg>',rowHeight:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="7" x2="20" y2="7"/><line x1="4" y1="17" x2="20" y2="17"/><line x1="12" y1="7" x2="12" y2="17"/><path d="M9 10l3-3 3 3"/><path d="M9 14l3 3 3-3"/></svg>',deleteTable:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/><line x1="16" y1="16" x2="22" y2="22" stroke="#ef4444"/><line x1="22" y1="16" x2="16" y2="22" stroke="#ef4444"/></svg>'};class xi{constructor(t){this.context=t,this._el=null,this._activeTable=null,this._activeCell=null,this._showTimer=null,this._hideTimer=null,this._disposers=[],this._sizePopover=null,this._sizeApply=null,this._sizeTitleEl=null,this._sizeInputEl=null}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el),this._sizePopover=this._buildSizePopover(),document.body.appendChild(this._sizePopover);const t=this.context.layoutInfo.editable;return this._disposers.push(p(t,"mouseover",e=>{const i=e.target.closest("table");if(i&&t.contains(i)){const s=e.target.closest("td, th");s&&(this._activeCell=s),this._scheduleShow(i)}},{passive:!0}),p(t,"mouseout",e=>{const i=e.relatedTarget;(!i||!t.contains(i)&&!this._el.contains(i)&&!(this._sizePopover&&this._sizePopover.contains(i)))&&this._scheduleHide()},{passive:!0}),p(document,"click",e=>{this._activeTable&&!this._activeTable.contains(e.target)&&!this._el.contains(e.target)&&!(this._sizePopover&&this._sizePopover.contains(e.target))&&this._hide()})),this._initResize(),this}_initResize(){const t=this.context.layoutInfo.editable,e=6;let i=null,s=null,o=!1,n=null,r=0,l=0,h=0,m=0,d=-1,u=null,f=null,g=null,_=null,b=null;const T=()=>{i&&(i.style.cursor="",i=null),s=null},k=v=>{if(o||b!==null)return;const E=v.target,R=v.clientX,B=v.clientY;b=requestAnimationFrame(()=>{b=null;const L=E.closest("td, th");if(!L||!t.contains(L)){T();return}i&&i!==L&&(i.style.cursor="");const q=L.getBoundingClientRect(),Q=Math.abs(R-q.right)<e,Z=Math.abs(B-q.bottom)<e;Q?(L.style.cursor="col-resize",i=L,s="col"):Z?(L.style.cursor="row-resize",i=L,s="row"):T()})},w=v=>{!i||!s||(o=!0,n=s,r=v.clientX,l=v.clientY,g=i.closest("table"),n==="col"?(h=i.offsetWidth,d=ot(i),u=d>=0?Array.from(g.querySelectorAll("tr")).map(E=>ct(E,d)).filter(Boolean):[],document.body.style.cursor="col-resize"):(f=i.closest("tr"),m=f?f.offsetHeight:40,document.body.style.cursor="row-resize"),document.body.style.userSelect="none",v.preventDefault(),v.stopPropagation())},x=v=>{if(!o||_!==null)return;const E=v.clientX,R=v.clientY;_=requestAnimationFrame(()=>{if(_=null,n==="col"){const B=Math.max(30,h+(E-r));for(const L of u)L.style.width=`${B}px`,L.style.minWidth=`${B}px`}else{const B=Math.max(20,m+(R-l));if(f)for(const L of f.cells)L.style.height=`${B}px`,L.style.minHeight=`${B}px`}})},y=()=>{o&&(_!==null&&(cancelAnimationFrame(_),_=null),o=!1,document.body.style.userSelect="",document.body.style.cursor="",n=null,g=null,f=null,d=-1,u=null,this.context.invoke("editor.afterCommand"))};this._disposers.push(p(t,"mousemove",k),p(t,"mousedown",w),p(document,"mousemove",x),p(document,"mouseup",y))}destroy(){this._clearTimers(),this._disposers.forEach(t=>t()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null,this._sizePopover&&this._sizePopover.parentNode&&this._sizePopover.parentNode.removeChild(this._sizePopover),this._sizePopover=null}_buildTooltip(){const t=c("div",{class:"an-link-tooltip an-table-tooltip",role:"toolbar","aria-label":"Table actions"});return t.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Table",t.appendChild(this._label),t.appendChild(this._sep()),t.appendChild(this._makeBtn(P.rowAbove,"Add Row Above",()=>this._addRow("above"))),t.appendChild(this._makeBtn(P.rowBelow,"Add Row Below",()=>this._addRow("below"))),t.appendChild(this._makeBtn(P.deleteRow,"Delete Row",()=>this._deleteRow())),t.appendChild(this._sep()),t.appendChild(this._makeBtn(P.colLeft,"Add Column Left",()=>this._addColumn("left"))),t.appendChild(this._makeBtn(P.colRight,"Add Column Right",()=>this._addColumn("right"))),t.appendChild(this._makeBtn(P.deleteCol,"Delete Column",()=>this._deleteColumn())),t.appendChild(this._sep()),t.appendChild(this._makeBtn(P.mergeCells,"Merge Cells",()=>this._mergeCells())),t.appendChild(this._sep()),t.appendChild(this._makeBtn(P.colWidth,"Column Width",()=>this._openSizePopover("col"))),t.appendChild(this._makeBtn(P.rowHeight,"Row Height",()=>this._openSizePopover("row"))),t.appendChild(this._sep()),t.appendChild(this._makeBtn(P.deleteTable,"Delete Table",()=>this._deleteTable(),!0)),this._disposers.push(p(t,"mouseenter",()=>this._clearTimers()),p(t,"mouseleave",()=>{this._sizePopover&&this._sizePopover.style.display!=="none"||this._scheduleHide()})),t}_sep(){return c("div",{class:"an-link-tooltip-sep"})}_makeBtn(t,e,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:e});return o.innerHTML=t,this._disposers.push(p(o,"click",n=>{n.preventDefault(),n.stopPropagation(),i()})),o}_scheduleShow(t){this._activeTable===t&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activeTable=t,this._show()},bi))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),vi))}_show(){this._activeTable&&(this._el.style.display="flex",requestAnimationFrame(()=>{this._activeTable&&this._positionNear(this._activeTable)}))}_hide(){this._el.style.display="none",this._activeTable=null,this._activeCell=null,this._clearTimers(),this._hideSizePopover()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(t){if(!t)return;const e=t.getBoundingClientRect(),i=this._el.offsetWidth||400,s=this._el.offsetHeight||30,o=6;let n=e.left+(e.width-i)/2,r=e.top-s-o;r<o&&(r=e.bottom+o),n+i>window.innerWidth-o&&(n=window.innerWidth-i-o),n<o&&(n=o),this._el.style.left=`${n}px`,this._el.style.top=`${r}px`}_getCell(){const t=window.getSelection();if(t&&t.rangeCount){let e=t.getRangeAt(0).commonAncestorContainer;e.nodeType===3&&(e=e.parentElement);const i=e&&e.closest&&e.closest("td, th");if(i&&this._activeTable&&this._activeTable.contains(i))return i}return this._activeCell||this._activeTable&&this._activeTable.querySelector("td, th")}_addRow(t){var r;const e=this._getCell();if(!e)return;const i=e.closest("tr");if(!i)return;const s=Array.from(i.cells).reduce((l,h)=>l+(h.colSpan||1),0),o=document.createElement("tr"),n=Array.from(i.cells);for(let l=0;l<s;l++){const h=c("td",{},[" "]),m=n[l];m&&m.style.width&&(h.style.width=m.style.width),m&&m.style.minWidth&&(h.style.minWidth=m.style.minWidth),o.appendChild(h)}t==="above"?(r=i.parentElement)==null||r.insertBefore(o,i):i.insertAdjacentElement("afterend",o),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand")}_addColumn(t){const e=this._getCell();if(!e)return;const i=e.closest("table");if(!i)return;const s=ot(e),o=Array.from(i.querySelectorAll("tr")),n=o.map(l=>t==="left"?ct(l,s):wi(l,s)),r=o.map(l=>l.closest("thead")!==null);o.forEach((l,h)=>{l.insertBefore(c(r[h]?"th":"td",{},[" "]),n[h])}),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand")}_deleteRow(){var n;const t=this._getCell();if(!t)return;const e=t.closest("tr"),i=t.closest("table");if(!e||!i)return;const s=i.querySelector("tbody");(s?s.querySelectorAll("tr").length:i.querySelectorAll("tr").length)<=1&&e.closest("tbody")||(this._activeCell=null,(n=e.parentElement)==null||n.removeChild(e),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand"))}_deleteColumn(){const t=this._getCell();if(!t)return;const e=t.closest("table");if(!e)return;const i=t.closest("tr");if(i&&i.cells.length<=1)return;const s=ot(t);this._activeCell=null;const o=Array.from(e.querySelectorAll("tr"));o.map(r=>ct(r,s)).forEach((r,l)=>{r&&o[l].removeChild(r)}),requestAnimationFrame(()=>this._positionNear(this._activeTable)),this.context.invoke("editor.afterCommand")}_mergeCells(){const t=this._getCell();if(!t)return;const e=window.getSelection();if(!e||e.rangeCount===0)return;const i=e.getRangeAt(0),s=t.closest("table");if(!s)return;const n=Array.from(s.querySelectorAll("td, th")).filter(l=>{try{return i.intersectsNode(l)}catch{return!1}});if(n.length<2)return;const r=[...new Set(n.map(l=>l.closest("tr")))];if(r.length===1){const l=r[0],h=Array.from(l.cells).filter(d=>n.includes(d));if(h.length<2)return;const m=h[0];m.colSpan=h.reduce((d,u)=>d+(u.colSpan||1),0),m.innerHTML=h.map(d=>d.innerHTML).join(""),h.slice(1).forEach(d=>l.removeChild(d))}else{if([...new Set(n.map(m=>ot(m)))].length!==1)return;const h=n[0];h.rowSpan=n.reduce((m,d)=>m+(d.rowSpan||1),0),h.innerHTML=n.map(m=>m.innerHTML).join(""),n.slice(1).forEach(m=>{m.closest("tr")&&m.closest("tr").removeChild(m)})}this.context.invoke("editor.afterCommand")}_deleteTable(){const t=this._activeTable;t&&(this._hide(),t.parentNode&&t.parentNode.removeChild(t),this.context.invoke("editor.afterCommand"))}_buildSizePopover(){const t=c("div",{class:"an-size-popover"});t.style.display="none";const e=c("div",{class:"an-size-popover-title"}),i=c("div",{class:"an-size-popover-body"}),s=c("input",{type:"number",class:"an-size-input",min:"1",max:"2000",step:"1"}),o=c("span",{class:"an-size-unit"},["px"]);i.appendChild(s),i.appendChild(o);const n=c("div",{class:"an-size-popover-actions"}),r=c("button",{type:"button",class:"an-btn"});r.textContent="Cancel";const l=c("button",{type:"button",class:"an-btn an-btn-primary"});l.textContent="Apply",n.appendChild(r),n.appendChild(l),t.appendChild(e),t.appendChild(i),t.appendChild(n),this._sizeTitleEl=e,this._sizeInputEl=s,this._sizeApply=null;const h=p(l,"click",()=>{const _=parseInt(this._sizeInputEl.value,10);_>0&&typeof this._sizeApply=="function"&&this._sizeApply(_),this._hideSizePopover()}),m=p(r,"click",()=>this._hideSizePopover()),d=p(s,"keydown",_=>{_.key==="Enter"&&(_.preventDefault(),l.click()),_.key==="Escape"&&this._hideSizePopover()}),u=p(document,"click",_=>{this._sizePopover&&this._sizePopover.style.display!=="none"&&!this._sizePopover.contains(_.target)&&!this._el.contains(_.target)&&this._hideSizePopover()}),f=p(t,"mouseenter",()=>this._clearTimers()),g=p(t,"mouseleave",()=>this._scheduleHide());return this._disposers.push(h,m,d,u,f,g),t}_openSizePopover(t){const e=this._getCell();if(!e||!this._sizePopover)return;const i=t==="col";this._sizeTitleEl.textContent=i?"Column Width (px)":"Row Height (px)",this._sizeInputEl.value=i?e.offsetWidth||120:e.closest("tr")&&e.closest("tr").offsetHeight||40,this._sizeApply=s=>{if(i){const o=e.closest("table"),n=ot(e);Array.from(o.querySelectorAll("tr")).map(h=>ct(h,n)).forEach(h=>{h&&(h.style.width=`${s}px`,h.style.minWidth=`${s}px`)})}else{const o=e.closest("tr");if(o)for(const n of o.cells)n.style.height=`${s}px`,n.style.minHeight=`${s}px`}this.context.invoke("editor.afterCommand")},this._sizePopover.style.display="block",requestAnimationFrame(()=>{if(!this._sizePopover||!this._el)return;const s=this._el.getBoundingClientRect(),o=this._sizePopover.offsetWidth||220,n=this._sizePopover.offsetHeight||110;let r=s.left,l=s.bottom+6;r+o>window.innerWidth-8&&(r=window.innerWidth-o-8),l+n>window.innerHeight-8&&(l=s.top-n-6),this._sizePopover.style.left=`${r}px`,this._sizePopover.style.top=`${l}px`,this._sizeInputEl&&(this._sizeInputEl.focus(),this._sizeInputEl.select())})}_hideSizePopover(){this._sizePopover&&(this._sizePopover.style.display="none"),this._sizeApply=null}}const Ci=100,ki=180,ht={copy:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',wrapOn:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="6" x2="21" y2="6"/><path d="M3 12h15a3 3 0 0 1 0 6H3"/><polyline points="6 15 3 18 6 21"/></svg>',toParagraph:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13 4v16"/><path d="M17 4v16"/><path d="M9 4h8a4 4 0 0 1 0 8H9V4z"/></svg>',deleteCode:'<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>'};class Ti{constructor(t){this.context=t,this._el=null,this._activePre=null,this._showTimer=null,this._hideTimer=null,this._disposers=[],this._copyBtn=null,this._langSelect=null,this._prismScript=null}initialize(){this._el=this._buildTooltip(),document.body.appendChild(this._el),this._ensurePrism();const t=this.context.layoutInfo.editable;return this._disposers.push(p(t,"mouseover",e=>{const i=e.target.closest("pre");i&&t.contains(i)&&this._scheduleShow(i)}),p(t,"mouseout",e=>{const i=e.relatedTarget;(!i||!t.contains(i)&&!this._el.contains(i))&&this._scheduleHide()}),p(document,"click",e=>{this._activePre&&!this._activePre.contains(e.target)&&!this._el.contains(e.target)&&this._hide()})),this}destroy(){this._clearTimers(),this._disposers.forEach(t=>t()),this._disposers=[],this._el&&this._el.parentNode&&this._el.parentNode.removeChild(this._el),this._el=null}_buildTooltip(){const t=c("div",{class:"an-link-tooltip an-code-tooltip",role:"toolbar","aria-label":"Code block actions"});return t.style.display="none",this._label=c("span",{class:"an-link-tooltip-url"}),this._label.textContent="Code",t.appendChild(this._label),t.appendChild(this._sep()),this._langSelect=c("select",{class:"an-code-lang-select",title:"Syntax Language","aria-label":"Syntax language"}),[["","Plain text"],["javascript","JavaScript"],["typescript","TypeScript"],["python","Python"],["html","HTML"],["css","CSS"],["json","JSON"],["xml","XML"],["bash","Bash / Shell"],["sql","SQL"],["java","Java"],["csharp","C#"],["php","PHP"],["ruby","Ruby"],["go","Go"],["rust","Rust"],["cpp","C++"],["c","C"],["kotlin","Kotlin"],["swift","Swift"]].forEach(([i,s])=>{const o=c("option",{value:i});o.textContent=s,this._langSelect.appendChild(o)}),this._disposers.push(p(this._langSelect,"change",()=>this._onLangChange())),t.appendChild(this._langSelect),t.appendChild(this._sep()),this._copyBtn=this._makeBtn(ht.copy,"Copy Code",()=>this._copyCode()),t.appendChild(this._copyBtn),t.appendChild(this._sep()),this._wrapBtn=this._makeBtn(ht.wrapOn,"Toggle Word Wrap",()=>this._toggleWrap()),t.appendChild(this._wrapBtn),t.appendChild(this._sep()),t.appendChild(this._makeBtn(ht.toParagraph,"Convert to Paragraph",()=>this._toParagraph())),t.appendChild(this._sep()),t.appendChild(this._makeBtn(ht.deleteCode,"Delete Code Block",()=>this._delete(),!0)),this._disposers.push(p(t,"mouseenter",()=>this._clearTimers()),p(t,"mouseleave",()=>this._scheduleHide())),t}_sep(){return c("div",{class:"an-link-tooltip-sep"})}_makeBtn(t,e,i,s=!1){const o=c("button",{type:"button",class:s?"an-link-tooltip-btn an-link-tooltip-btn--danger":"an-link-tooltip-btn",title:e});return o.innerHTML=t,this._disposers.push(p(o,"click",n=>{n.preventDefault(),n.stopPropagation(),i()})),o}_scheduleShow(t){this._activePre===t&&this._el.style.display!=="none"||(clearTimeout(this._hideTimer),this._hideTimer=null,clearTimeout(this._showTimer),this._showTimer=setTimeout(()=>{this._activePre=t,this._syncWrapBtn(),this._syncLangSelect(),this._show(t)},Ci))}_scheduleHide(){clearTimeout(this._showTimer),this._showTimer=null,!this._hideTimer&&(this._hideTimer=setTimeout(()=>this._hide(),ki))}_show(t){this._el.style.display="flex",this._positionNear(t)}_hide(){this._el.style.display="none",this._activePre=null,this._clearTimers()}_clearTimers(){clearTimeout(this._showTimer),clearTimeout(this._hideTimer),this._showTimer=null,this._hideTimer=null}_positionNear(t){const e=t.getBoundingClientRect(),i=this._el.offsetWidth||260,s=this._el.offsetHeight||32,o=6;let n=e.top-s-o,r=e.left+(e.width-i)/2;n<o&&(n=e.bottom+o),r+i>window.innerWidth-o&&(r=window.innerWidth-i-o),r<o&&(r=o),this._el.style.top=`${n}px`,this._el.style.left=`${r}px`}_syncWrapBtn(){if(!this._activePre||!this._wrapBtn)return;const t=(this._activePre.style.whiteSpace||"").includes("pre-wrap")||window.getComputedStyle(this._activePre).whiteSpace==="pre-wrap";this._wrapBtn.classList.toggle("active",t),this._wrapBtn.title=t?"Disable Word Wrap":"Enable Word Wrap"}_syncLangSelect(){if(!this._activePre||!this._langSelect)return;const t=this._activePre.querySelector("code"),e=this._activePre.getAttribute("data-language")||"",i=t&&(t.className.match(/language-(\S+)/)||[])[1]||"";this._langSelect.value=e||i||""}_copyCode(){const t=this._activePre;if(!t)return;const e=t.textContent||"";if(navigator.clipboard)navigator.clipboard.writeText(e).then(()=>this._flashCopied()).catch(()=>{});else{const i=document.createElement("textarea");i.value=e,i.style.cssText="position:fixed;opacity:0;top:0;left:0",document.body.appendChild(i),i.select();try{document.execCommand("copy"),this._flashCopied()}catch{}document.body.removeChild(i)}}_flashCopied(){if(!this._copyBtn)return;const t=this._copyBtn.innerHTML;this._copyBtn.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',this._copyBtn.classList.add("an-link-tooltip-btn--copied"),setTimeout(()=>{this._copyBtn&&(this._copyBtn.innerHTML=t,this._copyBtn.classList.remove("an-link-tooltip-btn--copied"))},1400)}_toggleWrap(){const t=this._activePre;if(!t)return;const e=t.style.whiteSpace==="pre-wrap";t.style.whiteSpace=e?"pre":"pre-wrap",this._syncWrapBtn(),this.context.invoke("editor.afterCommand"),this._positionNear(t)}_onLangChange(){const t=this._activePre;if(!t)return;const e=this._langSelect.value;let i=t.querySelector("code");i||(i=document.createElement("code"),i.innerHTML=t.innerHTML,t.innerHTML="",t.appendChild(i)),i.className=e?`language-${e}`:"",t.className=e?`language-${e}`:"",e?t.setAttribute("data-language",e):t.removeAttribute("data-language");const s=()=>{i.querySelectorAll("br").forEach(o=>o.replaceWith(`
72
+ `)),window.Prism.highlightElement(i),this.context.invoke("editor.afterCommand")};if(e){if(typeof window.Prism<"u"){if(window.Prism.languages[e]){s();return}this._loadPrismComponent(e,s);return}else if(this._prismScript){this._prismScript.addEventListener("load",()=>{window.Prism.languages[e]?s():this._loadPrismComponent(e,s)},{once:!0});return}}this.context.invoke("editor.afterCommand")}_ensurePrism(){if(!this.context.options.codeHighlight||window.Prism)return;const t=this.context.options.codeHighlightCDN||"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0",e=`${t}/themes/prism-tomorrow.min.css`,i=`${t}/prism.min.js`;if(!document.querySelector(`link[href="${e}"]`)){const n=document.createElement("link");n.rel="stylesheet",n.href=e,document.head.appendChild(n)}const s=document.querySelector(`script[src="${i}"]`);if(s){this._prismScript=window.Prism?null:s;return}const o=document.createElement("script");o.dataset.manual="",o.src=i,this._prismScript=o,o.addEventListener("load",()=>{this._prismScript=null},{once:!0}),document.head.appendChild(o)}_loadPrismComponent(t,e){const s=`${this.context.options.codeHighlightCDN||"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0"}/components/prism-${t}.min.js`;if(document.querySelector(`script[src="${s}"]`)){const n=setInterval(()=>{window.Prism&&window.Prism.languages[t]&&(clearInterval(n),e())},50);setTimeout(()=>clearInterval(n),3e3);return}const o=document.createElement("script");o.src=s,o.addEventListener("load",e,{once:!0}),document.head.appendChild(o)}_toParagraph(){const t=this._activePre;if(!t||!this.context.layoutInfo.editable)return;const i=(t.textContent||"").split(`
73
+ `),s=document.createElement("p");i.forEach((o,n)=>{n>0&&s.appendChild(document.createElement("br")),s.appendChild(document.createTextNode(o))}),t.parentNode.replaceChild(s,t),this._hide(),this.context.invoke("editor.afterCommand")}_delete(){const t=this._activePre;t&&(this._hide(),t.parentNode&&t.parentNode.removeChild(t),this.context.invoke("editor.afterCommand"))}}const Si=[{id:"smileys",label:"Smileys"},{id:"people",label:"People"},{id:"animals",label:"Animals"},{id:"food",label:"Food"},{id:"travel",label:"Travel"},{id:"objects",label:"Objects"},{id:"symbols",label:"Symbols"}],Ei=[["😀","grin smile happy face","smileys"],["😃","happy smile big eyes","smileys"],["😄","grinning smile laugh","smileys"],["😁","beaming smile grin","smileys"],["😆","laughing lol","smileys"],["😅","sweat grin awkward","smileys"],["🤣","rolling laugh rofl","smileys"],["😂","tears laugh cry joy","smileys"],["🙂","slight smile","smileys"],["🙃","upside down smile","smileys"],["😉","wink","smileys"],["😊","blush smile happy","smileys"],["😇","innocent halo angel","smileys"],["🥰","hearts love adore","smileys"],["😍","heart eyes love","smileys"],["🤩","star eyes excited wow","smileys"],["😘","kiss blow love","smileys"],["😋","yum delicious tongue","smileys"],["😛","tongue stuck out","smileys"],["😜","wink tongue crazy","smileys"],["🤪","zany crazy wild","smileys"],["😝","squint tongue","smileys"],["🤑","money mouth","smileys"],["🤗","hugging hug","smileys"],["🤔","thinking hmm","smileys"],["🤨","raised eyebrow","smileys"],["😐","neutral face","smileys"],["😶","no mouth","smileys"],["😏","smirk","smileys"],["😒","unamused","smileys"],["🙄","roll eyes","smileys"],["😬","grimace","smileys"],["😔","pensive sad","smileys"],["😪","sleepy tired","smileys"],["😴","sleeping zzz","smileys"],["🤤","drool","smileys"],["😷","mask sick","smileys"],["🤒","sick thermometer","smileys"],["🤕","hurt bandage","smileys"],["🤢","nausea sick","smileys"],["🤮","vomit sick","smileys"],["🤧","sneeze cold","smileys"],["🥵","hot sweat","smileys"],["🥶","cold freeze","smileys"],["😵","dizzy dead","smileys"],["🤯","mind blown","smileys"],["🤠","cowboy hat","smileys"],["🥳","party celebrate","smileys"],["😎","cool sunglasses","smileys"],["🤓","nerd glasses","smileys"],["🧐","monocle curious","smileys"],["😕","confused","smileys"],["😟","worried","smileys"],["🙁","frown sad","smileys"],["☹️","sad frown","smileys"],["😮","surprised open mouth","smileys"],["😲","astonished","smileys"],["🥺","pleading begging puppy eyes","smileys"],["😢","cry sad tear","smileys"],["😭","sob cry loudly","smileys"],["😱","scream horror fear","smileys"],["😡","angry red pouting","smileys"],["😠","angry mad","smileys"],["🤬","cursing swear","smileys"],["😈","devil evil smile","smileys"],["👿","devil angry evil","smileys"],["💀","skull death","smileys"],["☠️","skull crossbones","smileys"],["💩","poop","smileys"],["🤡","clown","smileys"],["👻","ghost boo","smileys"],["👽","alien ufo","smileys"],["🤖","robot","smileys"],["👋","wave hello hi hand","people"],["🤚","raised back hand","people"],["✋","raised hand stop","people"],["🖖","vulcan salute spock","people"],["👌","ok perfect fine","people"],["✌️","peace victory fingers","people"],["🤞","fingers crossed luck","people"],["🤟","love you gesture","people"],["🤘","sign of horns rock","people"],["🤙","call me hand","people"],["👈","point left","people"],["👉","point right","people"],["👆","point up","people"],["👇","point down","people"],["☝️","index pointing up","people"],["👍","thumbs up like good","people"],["👎","thumbs down dislike bad","people"],["✊","raised fist punch","people"],["👊","oncoming fist punch","people"],["👏","clap applause","people"],["🙌","celebrate raise hands","people"],["🤝","handshake deal","people"],["🙏","pray hope please thanks","people"],["💅","nail polish","people"],["💪","flexed bicep strong muscle","people"],["👀","eyes look see","people"],["👁️","eye","people"],["👅","tongue","people"],["👶","baby","people"],["🧒","child","people"],["👦","boy","people"],["👧","girl","people"],["🧑","person adult","people"],["👨","man","people"],["👩","woman","people"],["🧔","beard man","people"],["🧓","older person","people"],["👴","old man","people"],["👵","old woman","people"],["❤️","heart love red","people"],["🧡","orange heart love","people"],["💛","yellow heart love","people"],["💚","green heart love","people"],["💙","blue heart love","people"],["💜","purple heart love","people"],["🖤","black heart","people"],["🤍","white heart","people"],["🤎","brown heart","people"],["💔","broken heart","people"],["❣️","exclamation heart","people"],["💕","two hearts love","people"],["💞","revolving hearts","people"],["💓","beating heart","people"],["💗","growing heart","people"],["💖","sparkling heart","people"],["💘","heart arrow","people"],["💝","heart ribbon","people"],["💬","speech bubble comment chat","people"],["💭","thought bubble","people"],["💯","100 hundred percent perfect","people"],["💢","anger symbol mad","people"],["💤","zzz sleep","people"],["🐶","dog puppy","animals"],["🐱","cat kitten","animals"],["🐭","mouse","animals"],["🐹","hamster","animals"],["🐰","rabbit bunny","animals"],["🦊","fox","animals"],["🐻","bear","animals"],["🐼","panda","animals"],["🐨","koala","animals"],["🐯","tiger","animals"],["🦁","lion","animals"],["🐮","cow","animals"],["🐷","pig","animals"],["🐸","frog","animals"],["🐵","monkey","animals"],["🙈","see no evil monkey","animals"],["🙉","hear no evil monkey","animals"],["🙊","speak no evil monkey","animals"],["🐔","chicken hen","animals"],["🐧","penguin","animals"],["🐦","bird","animals"],["🦆","duck","animals"],["🦅","eagle","animals"],["🦉","owl","animals"],["🦇","bat","animals"],["🐺","wolf","animals"],["🐴","horse","animals"],["🦄","unicorn","animals"],["🐝","bee","animals"],["🦋","butterfly","animals"],["🐌","snail","animals"],["🐞","ladybug","animals"],["🐢","turtle","animals"],["🐍","snake","animals"],["🦎","lizard","animals"],["🐊","crocodile","animals"],["🐟","fish","animals"],["🐠","tropical fish","animals"],["🦈","shark","animals"],["🐬","dolphin","animals"],["🐳","whale","animals"],["🐙","octopus","animals"],["🦑","squid","animals"],["🦀","crab","animals"],["🌸","cherry blossom flower","animals"],["🌺","hibiscus flower","animals"],["🌻","sunflower","animals"],["🌹","rose flower","animals"],["🌷","tulip flower","animals"],["🍀","four leaf clover luck","animals"],["🌿","herb leaf green","animals"],["🌱","seedling sprout","animals"],["🌲","evergreen tree pine","animals"],["🌳","deciduous tree","animals"],["🌴","palm tree","animals"],["🍄","mushroom","animals"],["🌾","sheaf wheat","animals"],["🐾","paw prints animal","animals"],["🍎","apple red","food"],["🍊","orange tangerine","food"],["🍋","lemon yellow","food"],["🍇","grapes","food"],["🍓","strawberry","food"],["🫐","blueberry","food"],["🍒","cherry","food"],["🍑","peach","food"],["🥭","mango","food"],["🍍","pineapple","food"],["🥥","coconut","food"],["🥝","kiwi","food"],["🍅","tomato","food"],["🥑","avocado","food"],["🍆","eggplant aubergine","food"],["🥕","carrot","food"],["🌽","corn","food"],["🥦","broccoli","food"],["🥬","leafy green","food"],["🧄","garlic","food"],["🥜","peanut nut","food"],["🍞","bread loaf","food"],["🥐","croissant","food"],["🧀","cheese","food"],["🍳","egg fry cooking","food"],["🥚","egg","food"],["🥞","pancake","food"],["🧇","waffle","food"],["🥓","bacon","food"],["🥩","meat steak","food"],["🍗","chicken leg","food"],["🌭","hotdog","food"],["🍔","burger hamburger","food"],["🍟","fries french","food"],["🍕","pizza","food"],["🌮","taco","food"],["🌯","burrito wrap","food"],["🍜","noodles ramen","food"],["🍝","spaghetti pasta","food"],["🍣","sushi","food"],["🍱","bento box","food"],["🍦","ice cream soft serve","food"],["🍩","donut","food"],["🍪","cookie","food"],["🎂","birthday cake","food"],["🍰","cake slice","food"],["🧁","cupcake","food"],["🍫","chocolate","food"],["🍬","candy","food"],["🍭","lollipop","food"],["☕","coffee hot","food"],["🍵","tea hot","food"],["🧋","bubble tea boba","food"],["🥤","cup straw drink","food"],["🍷","wine red","food"],["🍸","cocktail martini","food"],["🍺","beer mug","food"],["🍻","clinking beer mugs","food"],["🥂","champagne toast celebrate","food"],["🧃","juice box","food"],["🧊","ice cube","food"],["🚀","rocket space","travel"],["🛸","ufo flying saucer","travel"],["✈️","airplane plane fly","travel"],["🚁","helicopter","travel"],["🚂","train locomotive","travel"],["🚄","bullet train fast","travel"],["🚇","subway metro","travel"],["🚌","bus","travel"],["🚑","ambulance","travel"],["🚒","fire truck","travel"],["🚓","police car","travel"],["🚕","taxi cab","travel"],["🚗","car automobile red","travel"],["🚙","suv car","travel"],["🚚","truck delivery","travel"],["🚜","tractor farm","travel"],["🏎️","racing car fast","travel"],["🏍️","motorcycle","travel"],["🚲","bicycle bike","travel"],["🛴","scooter kick","travel"],["⛵","sailboat boat","travel"],["🚢","ship cruise","travel"],["🏠","house home","travel"],["🏢","office building","travel"],["🏥","hospital","travel"],["🏦","bank","travel"],["🏪","store shop convenience","travel"],["🏫","school","travel"],["🏰","castle european","travel"],["🏯","japanese castle","travel"],["🗼","tokyo tower","travel"],["🗽","statue liberty new york","travel"],["⛪","church","travel"],["🕌","mosque","travel"],["⛩️","shinto shrine","travel"],["⛲","fountain","travel"],["⛺","tent camping","travel"],["🌁","fog foggy bridge","travel"],["🌃","night city stars","travel"],["🏙️","cityscape city buildings","travel"],["🌅","sunrise morning","travel"],["🌈","rainbow colorful","travel"],["⛰️","mountain","travel"],["🏔️","snow mountain","travel"],["🗻","mount fuji","travel"],["🏕️","camping tent","travel"],["🗺️","world map","travel"],["🧭","compass navigation","travel"],["🌍","earth europe africa globe","travel"],["🌎","earth americas globe","travel"],["🌏","earth asia globe","travel"],["🌐","globe internet web","travel"],["💎","diamond gem jewel","objects"],["💍","ring engagement","objects"],["👑","crown royal king queen","objects"],["🎩","top hat magic","objects"],["💼","briefcase work business","objects"],["👜","handbag purse","objects"],["🎒","backpack bag school","objects"],["👓","glasses eyewear","objects"],["🕶️","sunglasses cool","objects"],["💡","light bulb idea","objects"],["🔦","flashlight torch","objects"],["🕯️","candle light","objects"],["🔋","battery charge","objects"],["💻","laptop computer","objects"],["🖥️","desktop monitor computer","objects"],["📱","phone mobile cell","objects"],["⌨️","keyboard type","objects"],["🖱️","mouse computer click","objects"],["📺","television tv","objects"],["📷","camera photo","objects"],["📹","video camera","objects"],["🎥","movie camera film","objects"],["☎️","telephone phone","objects"],["⏰","alarm clock wake","objects"],["⌚","watch time","objects"],["🔑","key","objects"],["🗝️","old key","objects"],["🔒","lock closed","objects"],["🔓","unlock open","objects"],["🔨","hammer tool","objects"],["🔧","wrench tool","objects"],["🔩","bolt nut","objects"],["⚙️","gear setting","objects"],["🧲","magnet attract","objects"],["📚","books stack library","objects"],["📖","book open read","objects"],["📝","memo write note","objects"],["✏️","pencil write edit","objects"],["📌","pushpin tack","objects"],["📎","paperclip attach","objects"],["📊","bar chart graph","objects"],["📈","chart up growth trend","objects"],["📉","chart down loss decline","objects"],["📅","calendar date","objects"],["📦","package box","objects"],["📫","mailbox closed","objects"],["📧","email envelope","objects"],["🎁","gift present","objects"],["🎀","ribbon bow","objects"],["🎉","party celebrate confetti","objects"],["🎊","confetti celebrate","objects"],["🔮","crystal ball magic fortune","objects"],["🪄","magic wand","objects"],["🎯","target bullseye dart","objects"],["🎲","dice game board","objects"],["🎮","video game controller","objects"],["🎭","theater masks drama","objects"],["🎨","art palette paint","objects"],["🎬","clapper film movie","objects"],["🎤","microphone sing karaoke","objects"],["🎧","headphones music listen","objects"],["🎵","music note","objects"],["🎶","music notes","objects"],["🎸","guitar electric","objects"],["🎹","piano keyboard music","objects"],["🥁","drum percussion","objects"],["🎷","saxophone jazz","objects"],["🎺","trumpet","objects"],["🎻","violin","objects"],["⚽","soccer ball football","objects"],["🏀","basketball","objects"],["🏈","american football","objects"],["⚾","baseball","objects"],["🎾","tennis","objects"],["🏐","volleyball","objects"],["🏆","trophy winner award","objects"],["🥇","gold medal first","objects"],["🏅","sports medal","objects"],["✅","check green done success","symbols"],["❌","cross x no cancel","symbols"],["⭕","circle red","symbols"],["⛔","no entry stop","symbols"],["🚫","prohibited no banned","symbols"],["⚠️","warning caution danger","symbols"],["❗","exclamation red important","symbols"],["❓","question mark","symbols"],["‼️","double exclamation","symbols"],["💯","100 hundred percent perfect","symbols"],["🔴","red circle dot","symbols"],["🟠","orange circle","symbols"],["🟡","yellow circle","symbols"],["🟢","green circle","symbols"],["🔵","blue circle","symbols"],["🟣","purple circle","symbols"],["⚫","black circle","symbols"],["⚪","white circle","symbols"],["🟤","brown circle","symbols"],["🔺","red triangle up","symbols"],["🔻","red triangle down","symbols"],["🔷","blue diamond large","symbols"],["🔶","orange diamond large","symbols"],["🔹","blue diamond small","symbols"],["🔸","orange diamond small","symbols"],["⭐","star yellow","symbols"],["🌟","glowing star shine","symbols"],["✨","sparkles shine","symbols"],["💫","dizzy star spin","symbols"],["⚡","lightning bolt energy power","symbols"],["🔥","fire hot flame","symbols"],["💥","explosion boom","symbols"],["❄️","snowflake cold ice winter","symbols"],["🌊","wave water ocean sea","symbols"],["💨","wind blow dash","symbols"],["🌀","cyclone tornado spiral","symbols"],["♻️","recycle loop green","symbols"],["✔️","check tick done","symbols"],["➕","plus add","symbols"],["➖","minus subtract","symbols"],["➗","divide division","symbols"],["✖️","multiply times cross","symbols"],["▶️","play button right","symbols"],["⏸️","pause","symbols"],["⏹️","stop square","symbols"],["⏩","fast forward","symbols"],["⏪","rewind fast backward","symbols"],["🔔","bell notification","symbols"],["🔕","bell slash mute","symbols"],["🔊","speaker volume high","symbols"],["🔇","mute silent no sound","symbols"],["📢","loudspeaker announcement","symbols"],["📣","megaphone cheer","symbols"],["🏳️","white flag","symbols"],["🏴","black flag","symbols"],["🚩","red flag","symbols"],["🏁","checkered flag finish race","symbols"],["🆕","new badge","symbols"],["🆓","free badge","symbols"],["🆒","cool badge","symbols"],["🔝","top arrow","symbols"],["🔙","back arrow","symbols"],["ℹ️","information info","symbols"],["📍","pin location map","symbols"],["🔗","link chain","symbols"],["©️","copyright","symbols"],["®️","registered trademark","symbols"],["™️","trademark","symbols"],["#️⃣","hash number","symbols"],["0️⃣","zero number","symbols"],["1️⃣","one number","symbols"],["2️⃣","two number","symbols"],["3️⃣","three number","symbols"],["4️⃣","four number","symbols"],["5️⃣","five number","symbols"]];class Ii{constructor(t){this.context=t,this._dialog=null,this._disposers=[],this._savedRange=null,this._activeCat="all"}initialize(){return this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){this._dialog||(this._dialog=this._buildDialog(),document.body.appendChild(this._dialog)),it(t=>{this._savedRange=t}),this._activeCat="all",this._searchInput.value="",this._updateCatTabs(),this._filterEmojis("","all"),this._open()}_buildDialog(){const t=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert emoji"}),e=c("div",{class:"an-dialog-box an-emoji-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Insert Emoji";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.innerHTML="&times;",i.append(s,o);const n=c("input",{type:"search",class:"an-input an-icon-search",placeholder:"Search emojis…",autocomplete:"off"});this._searchInput=n;const r=c("div",{class:"an-icon-cats"}),l=c("button",{type:"button",class:"an-icon-cat active","data-cat":"all"});l.textContent="All",r.appendChild(l),Si.forEach(({id:k,label:w})=>{const x=c("button",{type:"button",class:"an-icon-cat","data-cat":k});x.textContent=w,r.appendChild(x)}),this._catBar=r;const h=c("div",{class:"an-emoji-grid"});Ei.forEach(([k,w,x])=>{const y=c("button",{type:"button",class:"an-emoji-cell","data-char":k,"data-keywords":w,"data-cat":x,title:w.split(" ").slice(0,2).join(" ")});y.textContent=k,h.appendChild(y)}),this._grid=h;const m=c("div",{class:"an-dialog-actions"}),d=c("button",{type:"button",class:"an-btn"});d.textContent="Cancel",m.appendChild(d),e.append(i,n,r,h,m),t.appendChild(e);const u=p(o,"click",()=>this._close()),f=p(d,"click",()=>this._close()),g=p(t,"click",k=>{k.target===t&&this._close()}),_=p(n,"input",()=>this._filterEmojis(n.value,this._activeCat)),b=p(r,"click",k=>{const w=k.target.closest("[data-cat]");w&&(this._activeCat=w.dataset.cat,this._updateCatTabs(),this._filterEmojis(this._searchInput.value,this._activeCat))}),T=p(h,"click",k=>{const w=k.target.closest(".an-emoji-cell");w&&this._onEmojiClick(w.dataset.char)});return this._disposers.push(u,f,g,_,b,T),t}_updateCatTabs(){this._catBar.querySelectorAll(".an-icon-cat").forEach(t=>{t.classList.toggle("active",t.dataset.cat===this._activeCat)})}_filterEmojis(t,e){const i=(t||"").trim().toLowerCase();let s=0;this._grid.querySelectorAll(".an-emoji-cell").forEach(n=>{const r=!e||e==="all"||n.dataset.cat===e,l=!i||n.dataset.keywords.includes(i)||n.dataset.char===i,h=r&&l;n.style.display=h?"":"none",h&&s++});let o=this._grid.querySelector(".an-icon-empty");o||(o=c("div",{class:"an-icon-empty"}),o.textContent="No emojis found",this._grid.appendChild(o)),o.style.display=s>0?"none":""}_onEmojiClick(t){const e=this._savedRange,i=this.context.layoutInfo.editable;e&&e.select();const s=window.getSelection();let o=s&&s.rangeCount>0?s.getRangeAt(0):null;o||(o=document.createRange(),o.selectNodeContents(i),o.collapse(!1)),o.deleteContents();const n=document.createTextNode(t);o.insertNode(n),o.setStartAfter(n),o.collapse(!0),s&&(s.removeAllRanges(),s.addRange(o)),this._close(),i.focus(),this.context.invoke("editor.afterCommand")}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=V(this._dialog,()=>this._close()),setTimeout(()=>this._searchInput&&this._searchInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null}}const Ri=[{id:"popular",label:"Popular"},{id:"interface",label:"Interface"},{id:"navigation",label:"Navigation"},{id:"media",label:"Media"},{id:"communication",label:"Communication"},{id:"files",label:"Files"},{id:"people",label:"People"},{id:"objects",label:"Objects"}],Ai=[["house","popular"],["star","popular"],["heart","popular"],["check","popular"],["xmark","popular"],["plus","popular"],["minus","popular"],["magnifying-glass","popular"],["gear","popular"],["bell","popular"],["user","popular"],["envelope","popular"],["phone","popular"],["calendar","popular"],["clock","popular"],["lock","popular"],["eye","popular"],["eye-slash","popular"],["trash","popular"],["pen","popular"],["bookmark","popular"],["flag","popular"],["thumbs-up","popular"],["thumbs-down","popular"],["circle-info","popular"],["triangle-exclamation","popular"],["circle-check","popular"],["circle-xmark","popular"],["share","popular"],["download","popular"],["upload","popular"],["tag","popular"],["bars","interface"],["ellipsis","interface"],["ellipsis-vertical","interface"],["list","interface"],["table-cells","interface"],["table-list","interface"],["grip","interface"],["filter","interface"],["sort","interface"],["arrows-rotate","interface"],["rotate","interface"],["rotate-left","interface"],["rotate-right","interface"],["copy","interface"],["floppy-disk","interface"],["print","interface"],["link","interface"],["code","interface"],["expand","interface"],["compress","interface"],["cloud","interface"],["lock-open","interface"],["key","interface"],["shield","interface"],["shield-halved","interface"],["sliders","interface"],["toggle-on","interface"],["square-check","interface"],["circle-plus","interface"],["circle-minus","interface"],["arrow-right","navigation"],["arrow-left","navigation"],["arrow-up","navigation"],["arrow-down","navigation"],["chevron-right","navigation"],["chevron-left","navigation"],["chevron-up","navigation"],["chevron-down","navigation"],["angle-right","navigation"],["angle-left","navigation"],["angle-up","navigation"],["angle-down","navigation"],["angles-right","navigation"],["angles-left","navigation"],["location-dot","navigation"],["compass","navigation"],["map","navigation"],["map-pin","navigation"],["route","navigation"],["circle-arrow-right","navigation"],["circle-arrow-left","navigation"],["arrow-trend-up","navigation"],["arrow-trend-down","navigation"],["right-from-bracket","navigation"],["right-to-bracket","navigation"],["play","media"],["pause","media"],["stop","media"],["forward","media"],["backward","media"],["forward-step","media"],["backward-step","media"],["volume-high","media"],["volume-low","media"],["volume-xmark","media"],["volume-off","media"],["music","media"],["headphones","media"],["microphone","media"],["microphone-slash","media"],["film","media"],["camera","media"],["camera-rotate","media"],["video","media"],["image","media"],["images","media"],["photo-film","media"],["podcast","media"],["radio","media"],["comment","communication"],["comments","communication"],["comment-dots","communication"],["message","communication"],["paper-plane","communication"],["reply","communication"],["reply-all","communication"],["at","communication"],["hashtag","communication"],["wifi","communication"],["signal","communication"],["rss","communication"],["share-nodes","communication"],["inbox","communication"],["phone-volume","communication"],["mobile","communication"],["mobile-screen","communication"],["laptop","communication"],["desktop","communication"],["tower-broadcast","communication"],["file","files"],["file-lines","files"],["folder","files"],["folder-open","files"],["folder-plus","files"],["folder-minus","files"],["file-image","files"],["file-pdf","files"],["file-code","files"],["file-zipper","files"],["file-audio","files"],["file-video","files"],["file-arrow-up","files"],["file-arrow-down","files"],["database","files"],["box","files"],["box-open","files"],["hard-drive","files"],["server","files"],["user","people"],["users","people"],["user-group","people"],["user-plus","people"],["user-minus","people"],["user-check","people"],["user-xmark","people"],["user-tie","people"],["user-shield","people"],["user-secret","people"],["person","people"],["person-running","people"],["person-walking","people"],["child","people"],["handshake","people"],["hand","people"],["hands-holding","people"],["people-group","people"],["pencil","objects"],["paintbrush","objects"],["eraser","objects"],["scissors","objects"],["wrench","objects"],["screwdriver","objects"],["hammer","objects"],["toolbox","objects"],["graduation-cap","objects"],["book","objects"],["book-open","objects"],["glasses","objects"],["microscope","objects"],["flask","objects"],["stethoscope","objects"],["hospital","objects"],["building","objects"],["city","objects"],["car","objects"],["truck","objects"],["plane","objects"],["train","objects"],["bicycle","objects"],["bus","objects"],["rocket","objects"],["briefcase","objects"],["cart-shopping","objects"],["bag-shopping","objects"],["credit-card","objects"],["money-bill","objects"],["chart-bar","objects"],["chart-line","objects"],["chart-pie","objects"],["bolt","objects"],["sun","objects"],["moon","objects"],["snowflake","objects"],["fire","objects"],["droplet","objects"],["leaf","objects"],["tree","objects"],["earth-americas","objects"],["globe","objects"],["award","objects"],["trophy","objects"],["gift","objects"],["puzzle-piece","objects"]];class Li{constructor(t){this.context=t,this._dialog=null,this._disposers=[],this._savedRange=null,this._selectedIcon=null,this._activeCat="all"}initialize(){return this._ensureFontAwesome(),this}_ensureFontAwesome(){if(document.getElementById("an-fontawesome-css"))return;const t=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).map(i=>i.href||"").join(" ");if(/fontawesome|font-awesome/.test(t)||document.querySelector(".fa-solid, .fas, .far, .fab"))return;const e=document.createElement("link");e.id="an-fontawesome-css",e.rel="stylesheet",e.href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css",e.crossOrigin="anonymous",e.referrerPolicy="no-referrer",document.head.appendChild(e)}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){this._dialog||(this._dialog=this._buildDialog(),document.body.appendChild(this._dialog)),it(t=>{this._savedRange=t}),this._selectedIcon=null,this._activeCat="all",this._searchInput.value="",this._grid.querySelectorAll(".an-icon-cell.active").forEach(t=>t.classList.remove("active")),this._insertBtn.setAttribute("disabled",""),this._updateCatTabs(),this._filterIcons("","all"),this._updatePreview(null),this._open()}_buildDialog(){const t=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Insert FA icon"}),e=c("div",{class:"an-dialog-box an-icon-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Insert FA Icon";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.innerHTML="&times;",i.append(s,o);const n=c("input",{type:"search",class:"an-input an-icon-search",placeholder:"Search icons…",autocomplete:"off"});this._searchInput=n;const r=c("div",{class:"an-icon-cats"}),l=c("button",{type:"button",class:"an-icon-cat active","data-cat":"all"});l.textContent="All",r.appendChild(l),Ri.forEach(({id:C,label:A})=>{const N=c("button",{type:"button",class:"an-icon-cat","data-cat":C});N.textContent=A,r.appendChild(N)}),this._catBar=r;const h=c("div",{class:"an-icon-grid"});Ai.forEach(([C,A])=>{const N=c("button",{type:"button",class:"an-icon-cell","data-name":C,"data-cat":A,title:C}),dt=c("i",{class:"fa-solid fa-"+C,"aria-hidden":"true"}),Kt=c("span");Kt.textContent=C,N.append(dt,Kt),h.appendChild(N)}),this._grid=h;const m=c("div",{class:"an-icon-options"}),d=c("label",{class:"an-label"});d.textContent="Style";const u=c("select",{class:"an-input an-icon-option-select"});[["fa-solid","Solid"],["fa-regular","Regular"],["fa-light","Light (Pro)"]].forEach(([C,A])=>{const N=c("option",{value:C});N.textContent=A,u.appendChild(N)}),u.value="fa-solid",this._styleSelect=u;const f=c("label",{class:"an-label"});f.textContent="Size";const g=c("select",{class:"an-input an-icon-option-select"});[["","Inherit"],["0.75em","0.75em"],["1em","1em"],["1.25em","1.25em"],["1.5em","1.5em"],["2em","2em"],["3em","3em"]].forEach(([C,A])=>{const N=c("option",{value:C});C==="1em"&&(N.selected=!0),N.textContent=A,g.appendChild(N)}),this._sizeSelect=g;const _=c("label",{class:"an-label"});_.textContent="Color";const b=c("input",{type:"color",class:"an-icon-color",value:"#000000"});this._colorInput=b;const T=c("label",{class:"an-label an-label-inline an-icon-use-color"}),k=c("input",{type:"checkbox",checked:""});this._useColorCb=k,T.append(k,document.createTextNode(" Use color")),m.append(d,u,f,g,_,b,T);const w=c("div",{class:"an-icon-preview"}),x=c("span",{class:"an-icon-preview-hint"});x.textContent="Select an icon",w.appendChild(x),this._preview=w;const y=c("div",{class:"an-dialog-actions"}),v=c("button",{type:"button",class:"an-btn an-btn-primary",disabled:""});v.textContent="Insert FA Icon";const E=c("button",{type:"button",class:"an-btn"});E.textContent="Cancel",y.append(v,E),this._insertBtn=v,e.append(i,n,r,h,m,w,y),t.appendChild(e);const R=p(o,"click",()=>this._close()),B=p(E,"click",()=>this._close()),L=p(v,"click",()=>this._onInsert()),q=p(t,"click",C=>{C.target===t&&this._close()}),Q=p(n,"input",()=>this._filterIcons(n.value,this._activeCat)),Z=p(r,"click",C=>{const A=C.target.closest("[data-cat]");A&&(this._activeCat=A.dataset.cat,this._updateCatTabs(),this._filterIcons(this._searchInput.value,this._activeCat))}),z=p(h,"click",C=>{const A=C.target.closest(".an-icon-cell");A&&this._selectIcon(A.dataset.name)}),mt=p(u,"change",()=>this._updatePreview(this._selectedIcon)),ft=p(g,"change",()=>this._updatePreview(this._selectedIcon)),gt=p(b,"input",()=>this._updatePreview(this._selectedIcon)),tt=p(k,"change",()=>this._updatePreview(this._selectedIcon));return this._disposers.push(R,B,L,q,Q,Z,z,mt,ft,gt,tt),t}_updateCatTabs(){this._catBar.querySelectorAll(".an-icon-cat").forEach(t=>{t.classList.toggle("active",t.dataset.cat===this._activeCat)})}_filterIcons(t,e){const i=(t||"").trim().toLowerCase();let s=0;this._grid.querySelectorAll(".an-icon-cell").forEach(n=>{const r=n.dataset.name,l=n.dataset.cat,h=!e||e==="all"||l===e,m=!i||r.includes(i),d=h&&m;n.style.display=d?"":"none",d&&s++});let o=this._grid.querySelector(".an-icon-empty");o||(o=c("div",{class:"an-icon-empty"}),o.textContent="No icons found",this._grid.appendChild(o)),o.style.display=s>0?"none":""}_selectIcon(t){this._selectedIcon=t,this._grid.querySelectorAll(".an-icon-cell").forEach(e=>{e.classList.toggle("active",e.dataset.name===t)}),this._insertBtn.removeAttribute("disabled"),this._updatePreview(t)}_updatePreview(t){if(!this._preview)return;if(!t){this._preview.innerHTML='<span class="an-icon-preview-hint">Select an icon</span>';return}const e=this._styleSelect&&this._styleSelect.value||"fa-solid",i=this._sizeSelect&&this._sizeSelect.value||"1em",o=(this._useColorCb?this._useColorCb.checked:!1)&&this._colorInput?this._colorInput.value:"",n=[`font-size:${i}`,o?`color:${o}`:""].filter(Boolean).join(";");this._preview.innerHTML=`<i class="${e} fa-${t}" aria-hidden="true"${n?` style="${n}"`:""}></i><div class="an-icon-preview-name">${e} fa-${t}</div>`}_onInsert(){if(!this._selectedIcon)return;const t=this._styleSelect&&this._styleSelect.value||"fa-solid",e=this._sizeSelect&&this._sizeSelect.value||"",s=(this._useColorCb?this._useColorCb.checked:!1)&&this._colorInput?this._colorInput.value:"",o=[e?`font-size:${e}`:"",s?`color:${s}`:""].filter(Boolean),n=document.createElement("i");n.className=`${t} fa-${this._selectedIcon}`,n.setAttribute("aria-hidden","true"),n.setAttribute("contenteditable","false"),o.length&&n.setAttribute("style",o.join(";"));const r=this._savedRange,l=this.context.layoutInfo.editable;r&&r.select();const h=window.getSelection();let m=h&&h.rangeCount>0?h.getRangeAt(0):null;m||(m=document.createRange(),m.selectNodeContents(l),m.collapse(!1)),m.deleteContents(),m.insertNode(n);let d=n.nextSibling;!d||d.nodeType!==Node.TEXT_NODE?(d=document.createTextNode("​"),n.parentNode.insertBefore(d,n.nextSibling)):d.textContent||(d.textContent="​");const u=(d.textContent||"").startsWith("​")?1:0,f=document.createRange();f.setStart(d,Math.min(u,d.textContent.length)),f.collapse(!0),h&&(h.removeAllRanges(),h.addRange(f)),this._close(),l.focus(),h&&(h.removeAllRanges(),h.addRange(f)),this.context.invoke("editor.afterCommand")}_open(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=V(this._dialog,()=>this._close()),setTimeout(()=>this._searchInput&&this._searchInput.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._savedRange=null,this._selectedIcon=null}}const M={undo:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>',redo:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"/></svg>',cut:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="6" cy="20" r="3"/><circle cx="6" cy="4" r="3"/><line x1="19" y1="5" x2="6" y2="19"/><line x1="19" y1="19" x2="13.5" y2="13.5"/></svg>',copy:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',paste:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><rect x="8" y="2" width="8" height="4" rx="1"/></svg>',bold:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>',italic:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>',underline:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" y1="21" x2="20" y2="21"/></svg>',link:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',image:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',video:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg>',copyFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',pasteFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><rect x="8" y="2" width="8" height="4" rx="1"/><path d="m9 14 2 2 4-4"/></svg>',removeFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/></svg>',table:'<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>'},Bi=[{name:"undo",label:"Undo",icon:M.undo,action:a=>a.invoke("editor.undo")},{name:"redo",label:"Redo",icon:M.redo,action:a=>a.invoke("editor.redo")},{separator:!0},{name:"cut",label:"Cut",icon:M.cut,action:()=>document.execCommand("cut")},{name:"copy",label:"Copy",icon:M.copy,action:()=>document.execCommand("copy")},{name:"paste",label:"Paste",icon:M.paste,action:a=>{if(!navigator.clipboard)return;const t=a.layoutInfo&&a.layoutInfo.editable;if(!t)return;const e=(i,s)=>{if(t.focus(),i){const o=X(i);document.execCommand("insertHTML",!1,o)}else s&&document.execCommand("insertText",!1,s);a.invoke("editor.afterCommand")};typeof navigator.clipboard.read=="function"?navigator.clipboard.read().then(i=>{for(const s of i)if(s.types.includes("text/html")){s.getType("text/html").then(o=>o.text()).then(o=>e(o,null));return}navigator.clipboard.readText().then(s=>e(null,s)).catch(()=>{})}).catch(()=>{navigator.clipboard.readText().then(i=>e(null,i)).catch(()=>{})}):typeof navigator.clipboard.readText=="function"&&navigator.clipboard.readText().then(i=>e(null,i)).catch(()=>{})}},{separator:!0},{name:"bold",label:"Bold",icon:M.bold,action:a=>a.invoke("editor.bold")},{name:"italic",label:"Italic",icon:M.italic,action:a=>a.invoke("editor.italic")},{name:"underline",label:"Underline",icon:M.underline,action:a=>a.invoke("editor.underline")},{separator:!0},{name:"copyFormat",label:"Copy Format",icon:M.copyFormat,action:a=>a.invoke("contextMenu.copyFormat")},{name:"pasteFormat",label:"Paste Format",icon:M.pasteFormat,action:a=>a.invoke("contextMenu.pasteFormat"),disabled:a=>!a.invoke("contextMenu.hasCopiedFormat")},{name:"removeFormat",label:"Remove Format",icon:M.removeFormat,action:a=>a.invoke("contextMenu.removeFormat")},{separator:!0},{name:"link",label:"Insert Link",icon:M.link,action:a=>a.invoke("linkDialog.show")},{name:"image",label:"Insert Image",icon:M.image,action:a=>a.invoke("imageDialog.show")},{name:"video",label:"Insert Video",icon:M.video,action:a=>a.invoke("videoDialog.show")},{name:"table",label:"Insert Table",icon:M.table,tableGrid:!0}];class Mi{constructor(t){this.context=t,this.options=t.options||{},this._items=this.options.contextMenu&&this.options.contextMenu.items||Bi,this.el=null,this._disposers=[],this._menuDisposers=[],this._lastX=0,this._lastY=0,this._copiedFormat=null,this._savedRange=null}initialize(){this.el=c("div",{class:"an-contextmenu",role:"menu","aria-hidden":"true"}),this.el.style.display="none",document.body.appendChild(this.el),this._renderItems(this._items);const t=this.context.layoutInfo&&this.context.layoutInfo.editable;return t&&this._disposers.push(p(t,"contextmenu",e=>this._onContextMenu(e))),this._disposers.push(p(document,"click",e=>this._maybeHide(e))),this._disposers.push(p(document,"keydown",e=>{e.key==="Escape"&&this.hide()})),this._disposers.push(p(window,"scroll",()=>this.hide(),{passive:!0})),this}destroy(){this._menuDisposers.forEach(t=>{try{t()}catch{}}),this._menuDisposers=[],this._disposers.forEach(t=>{try{t()}catch{}}),this._disposers=[],this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null}_renderItems(t){this._menuDisposers.forEach(e=>e()),this._menuDisposers=[],this.el&&(this.el.innerHTML="",t.forEach(e=>{if(e.separator||e.sep){this.el.appendChild(c("div",{class:"an-context-sep"}));return}if(e.back){const o=c("button",{type:"button",class:"an-context-back"}),n=c("span",{class:"an-context-icon","aria-hidden":"true"});n.innerHTML=M.back,o.appendChild(n),o.appendChild(c("span",{class:"an-context-label"},[e.label||"Back"]));const r=p(o,"click",l=>{l.stopPropagation(),this._renderItems(e.navigate()),this._reposition()});this._menuDisposers.push(r),this.el.appendChild(o);return}if(e.navigate){const o=c("button",{type:"button",class:"an-context-item an-context-submenu","data-name":e.name||""});if(e.icon){const l=c("span",{class:"an-context-icon","aria-hidden":"true"});l.innerHTML=e.icon,o.appendChild(l)}o.appendChild(c("span",{class:"an-context-label"},[e.label||e.name]));const n=c("span",{class:"an-context-chevron","aria-hidden":"true"});n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>',o.appendChild(n);const r=p(o,"click",l=>{l.stopPropagation(),this._renderItems(e.navigate()),this._reposition()});this._menuDisposers.push(r),this.el.appendChild(o);return}if(e.tableGrid){const r=c("div",{class:"an-context-table-wrap"}),l=c("button",{type:"button",class:"an-context-item an-context-submenu","data-name":e.name||"table"});if(e.icon){const x=c("span",{class:"an-context-icon","aria-hidden":"true"});x.innerHTML=e.icon,l.appendChild(x)}l.appendChild(c("span",{class:"an-context-label"},[e.label||"Insert Table"]));const h=c("span",{class:"an-context-chevron","aria-hidden":"true"});h.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>',l.appendChild(h);const m=c("div",{class:"an-context-table-grid-panel"});m.style.display="none";const d=c("div",{class:"an-table-grid"});d.style.gridTemplateColumns="repeat(8, 16px)";const u=c("div",{class:"an-table-label"});u.textContent="Insert Table";const f=[];for(let x=1;x<=8;x++)for(let y=1;y<=8;y++){const v=c("div",{class:"an-table-cell","data-row":String(x),"data-col":String(y)});v.style.width="16px",v.style.height="16px",f.push(v),d.appendChild(v)}const g=(x,y)=>{f.forEach(v=>{v.classList.toggle("active",+v.dataset.row<=x&&+v.dataset.col<=y)}),u.textContent=x&&y?`${y} × ${x}`:"Insert Table"};m.appendChild(d),m.appendChild(u);let _=!1;const b=p(l,"click",x=>{x.stopPropagation(),_=!_,m.style.display=_?"":"none",h.style.transform=_?"rotate(90deg)":"",this._reposition()});this._menuDisposers.push(b);const T=p(d,"mousemove",x=>{const y=x.target.closest("[data-row]");y&&g(+y.dataset.row,+y.dataset.col)}),k=p(d,"mouseleave",()=>g(0,0)),w=p(d,"click",x=>{const y=x.target.closest("[data-row]");if(!y)return;const v=+y.dataset.row,E=+y.dataset.col,R=this.context.layoutInfo&&this.context.layoutInfo.editable;if(R&&this._savedRange){R.focus();const B=window.getSelection();B.removeAllRanges(),B.addRange(this._savedRange.cloneRange())}this.hide(),this.context.invoke("editor.insertTable",E,v)});this._menuDisposers.push(T,k,w),r.appendChild(l),r.appendChild(m),this.el.appendChild(r);return}const i=c("button",{type:"button",class:"an-context-item","data-name":e.name||""});if((typeof e.disabled=="function"?e.disabled(this.context):e.disabled)&&(i.disabled=!0),e.icon){const o=c("span",{class:"an-context-icon","aria-hidden":"true"});o.innerHTML=e.icon,i.appendChild(o)}i.appendChild(c("span",{class:"an-context-label"},[e.label||e.name]));const s=p(i,"click",o=>{o.stopPropagation(),this.hide();try{e.action(this.context)}catch(n){console.error(n)}});this._menuDisposers.push(s),this.el.appendChild(i)}))}_onContextMenu(t){const e=this.context.layoutInfo&&this.context.layoutInfo.editable;if(!e||!e.contains(t.target))return;t.preventDefault(),this._lastX=t.clientX,this._lastY=t.clientY;const i=window.getSelection();this._savedRange=i&&i.rangeCount>0?i.getRangeAt(0).cloneRange():null,this._renderItems(this._items),this.showAt(t.clientX,t.clientY)}_maybeHide(t){this.el&&(this.el.contains(t.target)||this.hide())}showAt(t,e){this.el&&(this.el.style.display="block",this._reposition(t,e),this.el.setAttribute("aria-hidden","false"))}_reposition(t,e){if(!this.el)return;const i=t!==void 0?t:this._lastX,s=e!==void 0?e:this._lastY,o=this.el.getBoundingClientRect();let n=i,r=s;n+o.width>window.innerWidth&&(n=window.innerWidth-o.width-8),r+o.height>window.innerHeight&&(r=window.innerHeight-o.height-8),this.el.style.left=`${n}px`,this.el.style.top=`${r}px`}hide(){this.el&&(this.el.style.display="none",this.el.setAttribute("aria-hidden","true"))}hasCopiedFormat(){return!!this._copiedFormat}copyFormat(){const t=this._savedRange;if(!t)return;const e=this.context.layoutInfo&&this.context.layoutInfo.editable;let i=t.startContainer;if(i.nodeType===Node.TEXT_NODE&&(i=i.parentElement),!i||!e||!e.contains(i))return;const s=window.getComputedStyle(i),o=this._findExplicitStyle(i,e,"fontFamily"),n=this._findExplicitStyle(i,e,"fontSize");this._copiedFormat={bold:parseInt(s.fontWeight,10)>=700,italic:s.fontStyle==="italic"||s.fontStyle==="oblique",underline:(s.textDecorationLine||"").includes("underline"),strikethrough:(s.textDecorationLine||"").includes("line-through"),fontFamily:o,fontSize:n,color:this._isDefaultColor(s.color)?null:s.color,backgroundColor:s.backgroundColor}}_findExplicitStyle(t,e,i){let s=t;for(;s&&s!==e&&s!==document.body;){if(s.style&&s.style[i])return s.style[i];if(s.nodeName==="FONT"){if(i==="fontFamily"&&s.getAttribute("face"))return s.getAttribute("face");if(i==="fontSize"&&s.getAttribute("size"))return null}s=s.parentElement}return null}_isDefaultColor(t){return!t||t==="rgb(0, 0, 0)"||t==="rgba(0, 0, 0, 0)"||t==="transparent"}pasteFormat(){if(!this._copiedFormat||!this._savedRange)return;const t=this._copiedFormat,e=this.context.layoutInfo&&this.context.layoutInfo.editable;if(!e)return;e.focus();const i=window.getSelection();if(i.removeAllRanges(),i.addRange(this._savedRange.cloneRange()),document.execCommand("removeFormat"),t.bold&&document.execCommand("bold"),t.italic&&document.execCommand("italic"),t.underline&&document.execCommand("underline"),t.strikethrough&&document.execCommand("strikeThrough"),t.color&&document.execCommand("foreColor",!1,t.color),(o=>!o||o==="rgba(0, 0, 0, 0)"||o==="transparent")(t.backgroundColor)||document.execCommand("hiliteColor",!1,t.backgroundColor),t.fontFamily&&document.execCommand("fontName",!1,t.fontFamily),t.fontSize){const o=`fs-${Date.now()}`,n=new Set(e.querySelectorAll('font[size="7"]'));document.execCommand("fontSize",!1,"7"),e.querySelectorAll('font[size="7"]').forEach(r=>{n.has(r)||r.setAttribute("data-an-tmp",o)}),e.querySelectorAll(`[data-an-tmp="${o}"]`).forEach(r=>{const l=document.createElement("span");for(l.style.fontSize=t.fontSize,r.parentNode.insertBefore(l,r);r.firstChild;)l.appendChild(r.firstChild);r.parentNode.removeChild(r)})}this.context.invoke("editor.afterCommand")}removeFormat(){if(!this._savedRange)return;const t=this.context.layoutInfo&&this.context.layoutInfo.editable;if(!t)return;t.focus();const e=window.getSelection();e.removeAllRanges(),e.addRange(this._savedRange.cloneRange()),document.execCommand("removeFormat");const i=e.getRangeAt(0),s=i.commonAncestorContainer,o=s.nodeType===Node.TEXT_NODE?s.parentElement:s,n=document.createNodeIterator(o,NodeFilter.SHOW_ELEMENT);let r;for(;r=n.nextNode();)if(!(!t.contains(r)||r===t))try{i.intersectsNode(r)&&r.removeAttribute("style")}catch{}this.context.invoke("editor.afterCommand")}}const Ni=[{category:"Text Formatting",items:[{keys:"Ctrl + B",action:"Bold"},{keys:"Ctrl + I",action:"Italic"},{keys:"Ctrl + U",action:"Underline"},{keys:"Ctrl + K",action:"Insert / edit link"}]},{category:"History",items:[{keys:"Ctrl + Z",action:"Undo"},{keys:"Ctrl + Y / Ctrl + Shift + Z",action:"Redo"}]},{category:"Selection & Navigation",items:[{keys:"Ctrl + A",action:"Select all content"},{keys:"Tab",action:"Indent list item / insert spaces"},{keys:"Shift + Tab",action:"Outdent list item"}]},{category:"Clipboard",items:[{keys:"Ctrl + Shift + V",action:"Paste as plain text"}]},{category:"Find & Replace",items:[{keys:"Ctrl + F",action:"Find in document"},{keys:"Ctrl + H",action:"Find & Replace"}]},{category:"Editor",items:[{keys:"Ctrl + Shift + /",action:"Show this keyboard shortcuts dialog"}]}];class ji{constructor(t){this.context=t,this._dialog=null,this._closeBtn=null,this._disposers=[]}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(){this._dialog&&(this._dialog.style.display="flex",this._removeTrap=V(this._dialog,()=>this._close()),setTimeout(()=>this._closeBtn&&this._closeBtn.focus(),50))}_close(){this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null)}_buildDialog(){const t=c("div",{class:"an-dialog-overlay",role:"dialog","aria-modal":"true","aria-label":"Keyboard Shortcuts"}),e=c("div",{class:"an-dialog-box an-shortcuts-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Keyboard Shortcuts";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.textContent="×",this._closeBtn=o,i.append(s,o),e.appendChild(i),Ni.forEach(({category:l,items:h})=>{const m=c("div",{class:"an-shortcuts-cat"});m.textContent=l,e.appendChild(m);const d=c("div",{class:"an-shortcuts-table"});h.forEach(({keys:u,action:f})=>{const g=c("div",{class:"an-shortcuts-row"}),_=c("span",{class:"an-shortcuts-key"});_.textContent=u;const b=c("span",{class:"an-shortcuts-action"});b.textContent=f,g.append(_,b),d.appendChild(g)}),e.appendChild(d)}),t.appendChild(e);const n=p(o,"click",()=>this._close()),r=p(t,"click",l=>{l.target===t&&this._close()});return this._disposers.push(n,r),t}}class zi{constructor(t){this.context=t,this._dialog=null,this._findInput=null,this._replaceInput=null,this._caseCheckbox=null,this._counterEl=null,this._closeBtn=null,this._matches=[],this._currentIndex=-1,this._caseSensitive=!1,this._mode="find",this._disposers=[],this._removeTrap=null,this._focusTimer=null}initialize(){return this._dialog=this._buildDialog(),document.body.appendChild(this._dialog),this}destroy(){clearTimeout(this._focusTimer),this._focusTimer=null,this._clearHighlights(),this._disposers.forEach(t=>t()),this._disposers=[],this._dialog&&this._dialog.parentNode&&this._dialog.parentNode.removeChild(this._dialog),this._dialog=null}show(t="find"){this._mode=t,this._updateMode(),this._open(),clearTimeout(this._focusTimer),this._focusTimer=setTimeout(()=>{this._findInput&&(this._findInput.select(),this._findInput.focus())},50)}_open(){if(this._dialog){if(this._dialog.style.display==="flex"){this._findInput&&this._findInput.focus();return}this._dialog.style.display="flex",this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this._removeTrap=V(this._dialog,()=>this._close())}}_close(){this._clearHighlights(),this._dialog&&(this._dialog.style.display="none"),this._removeTrap&&(this._removeTrap(),this._removeTrap=null),this.context.invoke("editor.focus")}_updateMode(){if(!this._dialog)return;const t=this._dialog.querySelector(".an-fr-replace-row"),e=this._dialog.querySelector(".an-fr-replace-actions"),i=this._dialog.querySelector(".an-dialog-title"),s=this._mode==="replace";t&&(t.style.display=s?"":"none"),e&&(e.style.display=s?"":"none"),i&&(i.textContent=s?"Find & Replace":"Find")}_buildDialog(){const t=c("div",{class:"an-dialog-overlay an-fr-dialog",role:"dialog","aria-modal":"true","aria-label":"Find and Replace"}),e=c("div",{class:"an-dialog-box"}),i=c("div",{class:"an-icon-title-row"}),s=c("h3",{class:"an-dialog-title"});s.textContent="Find";const o=c("button",{type:"button",class:"an-icon-close","aria-label":"Close"});o.textContent="×",this._closeBtn=o,i.append(s,o),e.appendChild(i);const n=c("div",{class:"an-fr-find-row"}),r=c("input",{type:"text",class:"an-input",placeholder:"Find…","aria-label":"Search text"});this._findInput=r,n.appendChild(r),e.appendChild(n);const l=c("div",{class:"an-fr-options-row"}),h=c("label",{class:"an-label an-label-inline"}),m=c("input",{type:"checkbox","aria-label":"Case sensitive"});this._caseCheckbox=m,h.append(m,document.createTextNode(" Case sensitive"));const d=c("span",{class:"an-fr-counter"});this._counterEl=d,l.append(h,d),e.appendChild(l);const u=c("div",{class:"an-dialog-actions an-fr-find-actions"}),f=c("button",{type:"button",class:"an-btn"});f.textContent="← Prev";const g=c("button",{type:"button",class:"an-btn an-btn-primary"});g.textContent="Next →",u.append(f,g),e.appendChild(u);const _=c("div",{class:"an-fr-replace-row"});_.style.display="none";const b=c("input",{type:"text",class:"an-input",placeholder:"Replace with…","aria-label":"Replace with"});this._replaceInput=b,_.appendChild(b),e.appendChild(_);const T=c("div",{class:"an-dialog-actions an-fr-replace-actions"});T.style.display="none";const k=c("button",{type:"button",class:"an-btn"});k.textContent="Replace";const w=c("button",{type:"button",class:"an-btn an-btn-primary"});w.textContent="Replace All",T.append(k,w),e.appendChild(T),t.appendChild(e);const x=p(o,"click",()=>this._close()),y=p(t,"click",z=>{z.target===t&&this._close()}),v=p(r,"input",()=>this._onSearch()),E=p(m,"change",()=>{this._caseSensitive=m.checked,this._onSearch()}),R=p(g,"click",()=>this._next()),B=p(f,"click",()=>this._prev()),L=p(k,"click",()=>this._replace()),q=p(w,"click",()=>this._replaceAll()),Q=p(r,"keydown",z=>{z.key==="Enter"&&(z.preventDefault(),z.shiftKey?this._prev():this._next())}),Z=p(b,"keydown",z=>{z.key==="Enter"&&(z.preventDefault(),this._replace())});return this._disposers.push(x,y,v,E,R,B,L,q,Q,Z),t}_onSearch(){this._clearHighlights();const t=this._findInput?this._findInput.value:"";if(!t){this._updateCounter();return}this._findAndHighlight(t),this._updateCounter()}_findAndHighlight(t){const e=this.context.layoutInfo.editable;if(!e)return;const i=this._findRawMatches(t,e);if(i.length!==0){this._currentIndex=0;for(let s=i.length-1;s>=0;s--){const{node:o,start:n,end:r}=i[s];try{const l=document.createRange();l.setStart(o,n),l.setEnd(o,r);const h=document.createElement("mark");h.className="an-highlight",l.surroundContents(h),this._matches.unshift({mark:h})}catch{this._matches.unshift({mark:null})}}this._matches=this._matches.filter(s=>s.mark),this._matches.length!==0&&this._matches[0]&&this._matches[0].mark&&(this._matches[0].mark.className="an-highlight an-highlight-current",this._matches[0].mark.scrollIntoView({block:"center",behavior:"smooth"}))}}_findRawMatches(t,e){const i=[],s=this._caseSensitive?"g":"gi",o=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n=new RegExp(o,s),r=document.createTreeWalker(e,4);let l;for(;l=r.nextNode();){n.lastIndex=0;let h;for(;(h=n.exec(l.textContent))!==null;)i.push({node:l,start:h.index,end:h.index+h[0].length})}return i}_next(){this._matches.length!==0&&(this._currentIndex=(this._currentIndex+1)%this._matches.length,this._scrollToMatch(this._currentIndex),this._updateCounter())}_prev(){this._matches.length!==0&&(this._currentIndex=(this._currentIndex-1+this._matches.length)%this._matches.length,this._scrollToMatch(this._currentIndex),this._updateCounter())}_scrollToMatch(t){const e=this._matches[t];!e||!e.mark||(this._matches.forEach((i,s)=>{i.mark&&(i.mark.className=s===t?"an-highlight an-highlight-current":"an-highlight")}),e.mark.scrollIntoView({block:"center",behavior:"smooth"}))}_replace(){if(this._matches.length===0||this._currentIndex<0)return;const t=this._matches[this._currentIndex];if(!t||!t.mark||!t.mark.parentNode)return;const e=this._replaceInput?this._replaceInput.value:"",i=t.mark.parentNode,s=document.createTextNode(e);i.insertBefore(s,t.mark),i.removeChild(t.mark),i.normalize(),this.context.invoke("editor.afterCommand");const o=this._currentIndex;this._onSearch(),this._matches.length>0&&(this._currentIndex=Math.min(o,this._matches.length-1),this._scrollToMatch(this._currentIndex),this._updateCounter())}_replaceAll(){if(this._matches.length===0)return;const t=this._replaceInput?this._replaceInput.value:"";this._matches.forEach(({mark:e})=>{if(!e||!e.parentNode)return;const i=document.createTextNode(t);e.parentNode.insertBefore(i,e),e.parentNode.removeChild(e)}),this.context.layoutInfo.editable&&this.context.layoutInfo.editable.normalize(),this._matches=[],this._currentIndex=-1,this.context.invoke("editor.afterCommand"),this._onSearch()}_clearHighlights(){const t=this.context.layoutInfo.editable;t&&(t.querySelectorAll("mark.an-highlight").forEach(e=>{const i=e.parentNode;if(i){for(;e.firstChild;)i.insertBefore(e.firstChild,e);i.removeChild(e)}}),t.normalize(),this._matches=[],this._currentIndex=-1)}_updateCounter(){if(!this._counterEl)return;const t=this._matches.length;if(t===0){const e=this._findInput?this._findInput.value:"";this._counterEl.textContent=e?"No results":""}else this._counterEl.textContent=`${this._currentIndex+1} / ${t}`}}const W=20,ut="#3b82f6",j=(a,t,e)=>Math.min(Math.max(a,t),e);function Hi(a,t,e,i){return new Promise(s=>{const o=r=>{const l=document.createElement("canvas");l.width=Math.round(e),l.height=Math.round(i);const h=l.getContext("2d");try{h.drawImage(r,t.x,t.y,t.width,t.height,0,0,l.width,l.height),h.getImageData(0,0,1,1),s(l)}catch{s(null)}};if(a.src.startsWith("data:")||a.src.startsWith("blob:")||a.src.startsWith(location.origin)){o(a);return}const n=new Image;n.crossOrigin="anonymous",n.onload=()=>o(n),n.onerror=()=>s(null),n.src=a.src+(a.src.includes("?")?"&":"?")+"_an="+Date.now()})}class $i{constructor(t){this.context=t,this._img=null,this._box=null,this._imgRect=null,this._scrim=null,this._cropBox=null,this._handles={},this._toolbar=null,this._infoEl=null,this._dragDisposers=null,this._disposers=[]}initialize(){return this}destroy(){this._disposers.forEach(t=>t()),this._disposers=[],this._close(!1)}open(t){this._scrim&&this._close(!1),this._img=t;const e=t.getBoundingClientRect();this._imgRect=e;const i=Math.min(12,e.width*.1,e.height*.1);this._box={x:e.left+i,y:e.top+i,w:e.width-i*2,h:e.height-i*2},this._buildDOM(),this._updateDOM(),this._bindEsc()}_buildDOM(){const t=document.createElement("div");t.className="an-crop-scrim",t.style.cssText=`
74
+ position:fixed; inset:0; z-index:10100;
75
+ cursor:crosshair;
76
+ background: rgba(0,0,0,0.55);
77
+ `,this._disposers.push(p(t,"mousedown",d=>{d.target===t&&this._close(!1)}));const e=document.createElement("div");e.className="an-crop-box",e.style.cssText=`
78
+ position:fixed; z-index:10101;
79
+ box-sizing:border-box;
80
+ border:2px solid ${ut};
81
+ cursor:move;
82
+ outline: none;
83
+ `;const i=document.createElement("div");i.className="an-crop-grid",i.style.cssText=`
84
+ position:absolute; inset:0; pointer-events:none;
85
+ opacity:0.35;
86
+ `,["33.33%","66.66%"].forEach(d=>{const u=document.createElement("div");u.style.cssText=`position:absolute;top:0;bottom:0;left:${d};width:1px;background:#fff;`;const f=document.createElement("div");f.style.cssText=`position:absolute;left:0;right:0;top:${d};height:1px;background:#fff;`,i.appendChild(u),i.appendChild(f)}),e.appendChild(i),[{id:"nw",cur:"nw-resize",top:"-5px",left:"-5px"},{id:"n",cur:"n-resize",top:"-5px",left:"calc(50% - 5px)"},{id:"ne",cur:"ne-resize",top:"-5px",right:"-5px"},{id:"e",cur:"e-resize",top:"calc(50% - 5px)",right:"-5px"},{id:"se",cur:"se-resize",bottom:"-5px",right:"-5px"},{id:"s",cur:"s-resize",bottom:"-5px",left:"calc(50% - 5px)"},{id:"sw",cur:"sw-resize",bottom:"-5px",left:"-5px"},{id:"w",cur:"w-resize",top:"calc(50% - 5px)",left:"-5px"}].forEach(({id:d,cur:u,...f})=>{const g=document.createElement("div");g.className=`an-crop-handle an-crop-handle-${d}`,g.style.cssText=["position:absolute","width:10px","height:10px",`background:${ut}`,"border:2px solid #fff","border-radius:2px","box-sizing:border-box",`cursor:${u}`,...Object.entries(f).map(([_,b])=>`${_}:${b}`)].join(";"),this._disposers.push(p(g,"mousedown",_=>{_.preventDefault(),_.stopPropagation(),this._startHandleDrag(_,d)})),this._handles[d]=g,e.appendChild(g)}),this._disposers.push(p(e,"mousedown",d=>{d.target!==e&&d.target!==i&&!(d.target.tagName==="DIV"&&!d.target.className.includes("handle"))||d.target.className&&d.target.className.includes("an-crop-handle")||(d.preventDefault(),d.stopPropagation(),this._startBoxMove(d))}));const o=document.createElement("div");o.className="an-crop-info",o.style.cssText=`
87
+ position:absolute; bottom:-28px; left:0;
88
+ font:bold 11px/20px system-ui,sans-serif;
89
+ color:#fff; white-space:nowrap;
90
+ pointer-events:none;
91
+ text-shadow: 0 1px 3px rgba(0,0,0,.6);
92
+ `,e.appendChild(o),this._infoEl=o;const n=document.createElement("div");n.className="an-crop-toolbar",n.style.cssText=`
93
+ position:fixed; z-index:10102;
94
+ background:#1e1e2e; border-radius:6px;
95
+ padding:5px 8px; display:flex; gap:6px;
96
+ align-items:center;
97
+ box-shadow:0 4px 16px rgba(0,0,0,.4);
98
+ font:13px system-ui,sans-serif;
99
+ `;const r=this._makeToolbarBtn("✓ Crop","#22c55e",()=>this._confirm()),l=this._makeToolbarBtn("✕ Cancel","#94a3b8",()=>this._close(!1)),h=document.createElement("label");h.style.cssText="color:#94a3b8;font-size:11px;cursor:pointer;display:flex;align-items:center;gap:4px;";const m=document.createElement("input");m.type="checkbox",m.style.accentColor=ut,h.appendChild(m),h.appendChild(document.createTextNode("Lock ratio")),this._arCheck=m,n.appendChild(r),n.appendChild(l),n.appendChild(h),this._toolbar=n,this._disposers.push(p(n,"mousedown",d=>d.stopPropagation())),document.body.appendChild(t),document.body.appendChild(e),document.body.appendChild(n),this._scrim=t,this._cropBox=e}_makeToolbarBtn(t,e,i){const s=document.createElement("button");return s.type="button",s.textContent=t,s.style.cssText=`
100
+ background:none; border:1px solid ${e}; border-radius:4px;
101
+ color:${e}; padding:3px 10px; cursor:pointer; font-size:12px;
102
+ font-family:inherit;
103
+ transition:background 0.12s;
104
+ `,s.addEventListener("mouseover",()=>{s.style.background=e+"22"}),s.addEventListener("mouseout",()=>{s.style.background="none"}),this._disposers.push(p(s,"click",o=>{o.stopPropagation(),i()})),s}_updateDOM(){const{x:t,y:e,w:i,h:s}=this._box;this._cropBox.style.left=`${t}px`,this._cropBox.style.top=`${e}px`,this._cropBox.style.width=`${i}px`,this._cropBox.style.height=`${s}px`;const o=window.innerWidth,n=window.innerHeight;if(this._scrim.style.clipPath=["polygon(",`0 0, ${o}px 0, ${o}px ${n}px, 0 ${n}px, 0 0,`,`${t}px ${e}px, ${t}px ${e+s}px, ${t+i}px ${e+s}px, ${t+i}px ${e}px, ${t}px ${e}px`,")"].join(""),this._img){const h=this._img.naturalWidth||0,m=this._img.naturalHeight||0,d=this._imgRect.width||1,u=this._imgRect.height||1,f={x:h/d,y:m/u},g=j(t-this._imgRect.left,0,d),_=j(e-this._imgRect.top,0,u),b=j(i,0,d-g),T=j(s,0,u-_);this._infoEl.textContent=`${Math.round(b*f.x)} × ${Math.round(T*f.y)} px`}const r=8;let l=e+s+r;l+40>window.innerHeight-r&&(l=e-40-r),this._toolbar.style.left=`${t}px`,this._toolbar.style.top=`${l}px`}_startBoxMove(t){const e=t.clientX-this._box.x,i=t.clientY-this._box.y,s=this._imgRect,o=n=>{this._box.x=j(n.clientX-e,s.left,s.right-this._box.w),this._box.y=j(n.clientY-i,s.top,s.bottom-this._box.h),this._updateDOM()};this._attachDocDrag(o)}_startHandleDrag(t,e){const i=t.clientX,s=t.clientY,o={...this._box},n=this._imgRect,r=this._arCheck&&this._arCheck.checked,l=o.w/(o.h||1),h=m=>{const d=m.clientX-i,u=m.clientY-s;let{x:f,y:g,w:_,h:b}=o;e.includes("e")&&(_=Math.max(W,o.w+d)),e.includes("s")&&(b=Math.max(W,o.h+u)),e.includes("w")&&(f=Math.min(o.x+o.w-W,o.x+d),_=o.x+o.w-f),e.includes("n")&&(g=Math.min(o.y+o.h-W,o.y+u),b=o.y+o.h-g),r&&e.length===2&&(Math.abs(d)>=Math.abs(u)?(b=_/l,e.includes("n")&&(g=o.y+o.h-b)):(_=b*l,e.includes("w")&&(f=o.x+o.w-_))),f=j(f,n.left,n.right-W),g=j(g,n.top,n.bottom-W),_=j(_,W,n.right-f),b=j(b,W,n.bottom-g),this._box={x:f,y:g,w:_,h:b},this._updateDOM()};this._attachDocDrag(h)}_attachDocDrag(t){const e=()=>{document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",e),document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.addEventListener("mousemove",t),document.addEventListener("mouseup",e,{once:!0})}_bindEsc(){const t=e=>{e.key==="Escape"&&(e.preventDefault(),this._close(!1)),e.key==="Enter"&&(e.preventDefault(),this._confirm())};document.addEventListener("keydown",t),this._disposers.push(()=>document.removeEventListener("keydown",t))}async _confirm(){const t=this._img;if(!t){this._close(!1);return}const e=this._imgRect,{x:i,y:s,w:o,h:n}=this._box,r=(t.naturalWidth||t.width||1)/(e.width||1),l=(t.naturalHeight||t.height||1)/(e.height||1),h=Math.round(j(i-e.left,0,e.width)*r),m=Math.round(j(s-e.top,0,e.height)*l),d=Math.round(j(o,0,e.width-(i-e.left))*r),u=Math.round(j(n,0,e.height-(s-e.top))*l);if(d<=0||u<=0){this._close(!1);return}const b=await Hi(t,{x:h,y:m,width:d,height:u},o,n);if(!b){alert(`Cannot crop this image: the image server does not allow cross-origin access.
105
+ Upload the image directly to use the crop tool.`),this._close(!1);return}const T=t.src.match(/^data:image\/(jpe?g)/i)?"image/jpeg":"image/png",k=T==="image/jpeg"?.92:void 0,w=b.toDataURL(T,k);this._close(!1),t.src=w,t.style.width="",t.style.height="",t.removeAttribute("width"),t.removeAttribute("height"),this.context.invoke("editor.afterCommand"),this.context.invoke("imageResizer.updateOverlay")}_close(t){this._disposers.forEach(e=>e()),this._disposers=[],[this._scrim,this._cropBox,this._toolbar].forEach(e=>{e&&e.parentNode&&e.parentNode.removeChild(e)}),this._scrim=null,this._cropBox=null,this._toolbar=null,this._infoEl=null,this._handles={},this._img=null,this._box=null,this._imgRect=null,this._arCheck=null}}const Yt=new Map;class Di{constructor(t,e={}){this.targetEl=t,this.options=U(Y,e),this.layoutInfo={},this._listeners=new Map,this._modules=new Map,this._disposers=[],this._alive=!1}initialize(){const{container:t,editable:e}=We(this.targetEl,this.options);this.layoutInfo.container=t,this.layoutInfo.editable=e,this._registerModules();const i=this._modules.get("toolbar");i&&i.el&&(t.insertBefore(i.el,e),this.layoutInfo.toolbar=i.el);const s=this._modules.get("statusbar");return s&&s.el&&(t.appendChild(s.el),this.layoutInfo.statusbar=s.el),this._bindEditorEvents(e),this.options.focus&&e.focus(),this._alive=!0,this.invoke("toolbar.refresh"),typeof this.options.onInit=="function"&&this.options.onInit(this),this}_registerModules(){const t=(e,i)=>{const s=new i(this);this._modules.set(e,s),s.initialize()};t("editor",Ge),t("toolbar",Qe),t("statusbar",Ze),t("clipboard",Je),t("contextMenu",Mi),t("placeholder",ti),t("codeview",ei),t("fullscreen",ii),t("linkDialog",si),t("imageDialog",oi),t("videoDialog",ni),t("imageResizer",li),t("videoResizer",ci),t("linkTooltip",pi),t("imageTooltip",fi),t("videoTooltip",yi),t("tableTooltip",xi),t("codeTooltip",Ti),t("emojiDialog",Ii),t("iconDialog",Li),t("shortcutsDialog",ji),t("findReplace",zi),t("imageCropOverlay",$i);for(const[e,i]of Yt)t(e,i)}registerModule(t,e){if(this._modules.has(t))return this;const i=new e(this);return i.initialize(),this._modules.set(t,i),this}_bindEditorEvents(t){const e=p(t,"input",()=>this._syncToTarget()),i=p(t,"focus",()=>{this.layoutInfo.container.classList.add("an-focused"),typeof this.options.onFocus=="function"&&this.options.onFocus(this)}),s=p(t,"blur",()=>{this.layoutInfo.container.classList.remove("an-focused"),this._syncToTarget(),typeof this.options.onBlur=="function"&&this.options.onBlur(this)}),o=this.on("change",()=>this._syncToTarget());if(this._disposers.push(e,i,s,o),this.options.autoSave&&this.options.autoSaveKey){const n=this.on("change",()=>{try{localStorage.setItem(this.options.autoSaveKey,this.getHTML())}catch{}});this._disposers.push(n)}}invoke(t,...e){var n,r;const[i,s]=t.split("."),o=this._modules.get(i);if(!o){(typeof process>"u"||((n=process.env)==null?void 0:n.NODE_ENV)!=="production")&&console.warn(`[AutumnNote] invoke: module "${i}" not found (path: "${t}")`);return}if(typeof o[s]!="function"){(typeof process>"u"||((r=process.env)==null?void 0:r.NODE_ENV)!=="production")&&console.warn(`[AutumnNote] invoke: method "${s}" not found on module "${i}" (path: "${t}")`);return}return o[s](...e)}on(t,e){return this._listeners.has(t)||this._listeners.set(t,[]),this._listeners.get(t).push(e),()=>this.off(t,e)}off(t,e){const i=this._listeners.get(t);if(!i)return;const s=i.indexOf(e);s!==-1&&i.splice(s,1)}triggerEvent(t,...e){(this._listeners.get(t)||[]).forEach(o=>o(...e));const s="on"+t.charAt(0).toUpperCase()+t.slice(1);typeof this.options[s]=="function"&&this.options[s](...e)}getHTML(){return this.invoke("editor.getHTML")}setHTML(t){this.invoke("editor.setHTML",t)}getText(){return this.invoke("editor.getText")}setText(t){this.invoke("editor.setText",t)}clear(){this.invoke("editor.clear")}clearHistory(){this.invoke("editor.clearHistory")}isEmpty(){return this.invoke("editor.isEmpty")}insertHTML(t){this.invoke("editor.insertHTML",t)}insertText(t){this.invoke("editor.insertText",t)}setMarkdown(t){this.invoke("editor.setMarkdown",t)}getMarkdown(){return this.invoke("editor.getMarkdown")}getWordCount(){return this.invoke("statusbar.getWordCount")??0}getCharCount(){return this.invoke("statusbar.getCharCount")??0}downloadHTML(t="document.html"){this._download(this.getHTML(),t,"text/html")}downloadText(t="document.txt"){this._download(this.getText(),t,"text/plain")}downloadMarkdown(t="document.md"){this._download(this.getMarkdown(),t,"text/markdown")}_download(t,e,i){const s=new Blob([t],{type:i}),o=URL.createObjectURL(s),n=document.createElement("a");n.href=o,n.download=e,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(o)}print(t=""){const e=this.getHTML(),i=(t||"").replace(/</g,"&lt;").replace(/>/g,"&gt;"),s=window.open("","_blank");s&&(s.document.write(`<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>${i}</title><style>body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;font-size:14px;line-height:1.6;padding:20mm;color:#111827;}ul.an-checklist{list-style:none;padding-left:0;}ul.an-checklist li{padding-left:24px;position:relative;margin:2px 0;}ul.an-checklist li input[type="checkbox"]{position:absolute;left:0;top:3px;}code{background:#f3f4f6;border-radius:3px;padding:.1em .35em;font-family:monospace;}pre{background:#f3f4f6;padding:.75em 1em;border-radius:4px;overflow-x:auto;}table{border-collapse:collapse;}td,th{border:1px solid #d1d5db;padding:4px 8px;}</style></head><body>${e}</body></html>`),s.document.close(),s.onload=()=>{s.print()})}setDisabled(t){const e=this.layoutInfo.editable;t?(e.setAttribute("contenteditable","false"),this.layoutInfo.container.classList.add("an-disabled")):(e.setAttribute("contenteditable","true"),this.layoutInfo.container.classList.remove("an-disabled"))}destroy(){if(!this._alive)return;this._modules.forEach(e=>{typeof e.destroy=="function"&&e.destroy()}),this._modules.clear(),this._disposers.forEach(e=>e()),this._disposers=[];const t=this.layoutInfo.container;t&&t.parentNode&&(this.targetEl.style.display="",t.parentNode.removeChild(t)),typeof this.options.onDestroy=="function"&&this.options.onDestroy(this),this._alive=!1,this._listeners.clear()}_syncToTarget(){(this.targetEl.tagName==="TEXTAREA"||this.targetEl.tagName==="INPUT")&&(this.targetEl.value=this.getHTML())}}const Pi={...Y},J=new WeakMap,Oi={create(a,t={}){const i=Xt(a).map(s=>{if(J.has(s))return J.get(s);const o=new Di(s,t);return o.initialize(),J.set(s,o),o});return i.length===1?i[0]:i},destroy(a){Xt(a).forEach(t=>{const e=J.get(t);e&&(e.destroy(),J.delete(t))})},getInstance(a){const t=typeof a=="string"?document.querySelector(a):a;return t&&J.get(t)||null},get defaults(){return{...Y}},setDefaults(a){Object.assign(Y,a)},resetDefaults(){Object.keys(Y).forEach(a=>delete Y[a]),Object.assign(Y,Pi)},registerModule(a,t){Yt.set(a,t)},version:"1.0.4"};function Xt(a){return typeof a=="string"?Array.from(document.querySelectorAll(a)):a instanceof Element?[a]:a instanceof NodeList||Array.isArray(a)?Array.from(a):[]}return Oi});
74
106
  //# sourceMappingURL=autumnnote.umd.js.map