autumnnote 3.0.0 → 3.0.1

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.
@@ -72,4 +72,4 @@
72
72
  color:${t}; padding:3px 10px; cursor:pointer; font-size:12px;
73
73
  font-family:inherit;
74
74
  transition:background 0.12s;
75
- `,r.addEventListener(`mouseover`,()=>{r.style.background=t+`22`}),r.addEventListener(`mouseout`,()=>{r.style.background=`none`}),this._disposers.push(v(r,`click`,e=>{e.stopPropagation(),n()})),r}_updateDOM(){let{x:e,y:t,w:n,h:r}=this._box;this._cropBox.style.left=`${e}px`,this._cropBox.style.top=`${t}px`,this._cropBox.style.width=`${n}px`,this._cropBox.style.height=`${r}px`;let i=globalThis.innerWidth,a=globalThis.innerHeight;if(this._scrim.style.clipPath=[`polygon(`,`0 0, ${i}px 0, ${i}px ${a}px, 0 ${a}px, 0 0,`,`${e}px ${t}px, ${e}px ${t+r}px, ${e+n}px ${t+r}px, ${e+n}px ${t}px, ${e}px ${t}px`,`)`].join(``),this._img){let i=this._img.naturalWidth||0,a=this._img.naturalHeight||0,o=this._imgRect.width||1,s=this._imgRect.height||1,c={x:i/o,y:a/s},l=Z(e-this._imgRect.left,0,o),u=Z(t-this._imgRect.top,0,s),d=Z(n,0,o-l),f=Z(r,0,s-u);this._infoEl.textContent=`${Math.round(d*c.x)} × ${Math.round(f*c.y)} px`}let o=t+r+8;o+40>globalThis.innerHeight-8&&(o=t-40-8),this._toolbar.style.left=`${e}px`,this._toolbar.style.top=`${o}px`}_startBoxMove(e){let t=e.clientX-this._box.x,n=e.clientY-this._box.y,r=this._imgRect;this._attachDocDrag(e=>{this._box.x=Z(e.clientX-t,r.left,r.right-this._box.w),this._box.y=Z(e.clientY-n,r.top,r.bottom-this._box.h),this._updateDOM()})}_startHandleDrag(e,t){let n=e.clientX,r=e.clientY,i={...this._box},a=this._imgRect,o=this._arCheck?.checked,s=i.w/(i.h||1);this._attachDocDrag(e=>{let c=e.clientX-n,l=e.clientY-r,{x:u,y:d,w:f,h:p}=i;t.includes(`e`)&&(f=Math.max(X,i.w+c)),t.includes(`s`)&&(p=Math.max(X,i.h+l)),t.includes(`w`)&&(u=Math.min(i.x+i.w-X,i.x+c),f=i.x+i.w-u),t.includes(`n`)&&(d=Math.min(i.y+i.h-X,i.y+l),p=i.y+i.h-d),o&&t.length===2&&(Math.abs(c)>=Math.abs(l)?(p=f/s,t.includes(`n`)&&(d=i.y+i.h-p)):(f=p*s,t.includes(`w`)&&(u=i.x+i.w-f))),u=Z(u,a.left,a.right-X),d=Z(d,a.top,a.bottom-X),f=Z(f,X,a.right-u),p=Z(p,X,a.bottom-d),this._box={x:u,y:d,w:f,h:p},this._updateDOM()})}_attachDocDrag(e){this._dragDisposers?.();let t=t=>{t.preventDefault();let n=t;e({clientX:n.touches[0].clientX,clientY:n.touches[0].clientY})},n=()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.body.style.userSelect=``,document.body.style.cursor=``,this._dragDisposers=null};this._dragDisposers=n,document.body.style.userSelect=`none`,document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n,{once:!0}),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n,{once:!0})}_bindEsc(){let e=e=>{e.key===`Escape`&&(e.preventDefault(),this._close(!1)),e.key===`Enter`&&(e.preventDefault(),this._confirm())};document.addEventListener(`keydown`,e),this._disposers.push(()=>document.removeEventListener(`keydown`,e))}async _confirm(){let e=this._img;if(!e){this._close(!1);return}let t=this._imgRect,{x:n,y:r,w:i,h:a}=this._box,o=(e.naturalWidth||e.width||1)/(t.width||1),s=(e.naturalHeight||e.height||1)/(t.height||1),c=Math.round(Z(n-t.left,0,t.width)*o),l=Math.round(Z(r-t.top,0,t.height)*s),u=Math.round(Z(i,0,t.width-(n-t.left))*o),d=Math.round(Z(a,0,t.height-(r-t.top))*s);if(u<=0||d<=0){this._close(!1);return}let f=await ua(e,{x:c,y:l,width:u,height:d},i,a);if(!f){this._showCropError(`Cannot crop this image: the image server does not allow cross-origin access. Upload the image directly to use the crop tool.`),this._close(!1);return}let p=/^data:image\/(jpe?g)/i.exec(e.src)?`image/jpeg`:`image/png`,m=p===`image/jpeg`?.92:void 0,h=f.toDataURL(p,m);this._close(!1),e.src=h,e.style.width=``,e.style.height=``,e.removeAttribute(`width`),e.removeAttribute(`height`),this.context.invoke(`editor.afterCommand`),this.context.invoke(`imageResizer.updateOverlay`)}_showCropError(e){let t=document.createElement(`div`);t.setAttribute(`role`,`alert`),t.style.cssText=[`position:fixed`,`bottom:24px`,`left:50%`,`transform:translateX(-50%)`,`z-index:calc(10200 + var(--an-z-offset, 0))`,`max-width:420px`,`width:max-content`,`background:#7f1d1d`,`color:#fecaca`,`border:1px solid #b91c1c`,`border-radius:8px`,`padding:12px 18px`,`font:13px/1.5 system-ui,sans-serif`,`box-shadow:0 4px 16px rgba(0,0,0,.4)`,`pointer-events:auto`].join(`;`),t.textContent=e,x(this.context).appendChild(t),setTimeout(()=>{t.remove()},4e3)}_close(e){this._dragDisposers?.(),this._dragDisposers=null,this._disposers.forEach(e=>e()),this._disposers=[],[this._scrim,this._cropBox,this._toolbar].forEach(e=>{e?.remove()}),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}},fa=class{constructor(e){this.context=e,this.options=e.options,this._banner=null}initialize(){if(!this.options.autoSave||!this.options.autoSaveRestore)return this;let e=this.options.autoSaveKey,t=e+`:asrmeta`,n,r;try{n=localStorage.getItem(e),r=JSON.parse(localStorage.getItem(t)||`{}`)}catch{return this}if(!n)return this;let i=this.options.autoSaveRestoreTimeout;if(i>0&&Date.now()-(r.savedAt||0)>i*864e5){try{localStorage.removeItem(e),localStorage.removeItem(t)}catch{}return this}return this._showBanner(n,r),this}destroy(){this._removeBanner()}_showBanner(e,t){let n=this.context.locale.autoSaveRestore||{},r=n.found||`Draft found. Restore?`,i=n.restore||`Restore`,a=n.discard||`Discard`,o=document.createElement(`div`);o.className=`an-asr-banner`,o.setAttribute(`role`,`alert`);let s=document.createElement(`span`);if(s.className=`an-asr-msg`,t.savedAt){let e=new Date(t.savedAt).toLocaleString();s.textContent=(n.foundAt||`Draft from {date}. Restore?`).replace(`{date}`,e)}else s.textContent=r;let c=document.createElement(`button`);c.type=`button`,c.className=`an-btn an-asr-btn-restore`,c.textContent=i,c.addEventListener(`click`,()=>this._restore(e));let l=document.createElement(`button`);l.type=`button`,l.className=`an-btn an-asr-btn-discard`,l.textContent=a,l.addEventListener(`click`,()=>this._discard()),o.appendChild(s),o.appendChild(c),o.appendChild(l),this._banner=o;let u=this.context.layoutInfo.container;u.insertBefore(o,u.firstChild)}_restore(e){this.context.setHTML(e),this.context.clearHistory(),this._removeBanner(),this.context.triggerEvent(`autoSaveRestore`,e,this.context)}_discard(){let e=this.options.autoSaveKey;try{localStorage.removeItem(e),localStorage.removeItem(e+`:asrmeta`)}catch{}this._removeBanner()}_removeBanner(){this._banner?.remove(),this._banner=null}},pa=class{constructor(e){this.context=e,this.options=e.options,this._disposers=[]}initialize(){if(!this.options.markdownShortcuts)return this;let e=this.context.layoutInfo.editable,t=v(e,`keydown`,e=>this._onKeydown(e)),n=v(e,`input`,()=>this._onInput());return this._disposers.push(t,n),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[]}_onKeydown(e){this._inCodeContext()||(e.key===` `?this._applyBlockRule()&&e.preventDefault():e.key===`Enter`&&this._applyEnterRule()&&e.preventDefault())}_inCodeContext(){let e=globalThis.getSelection();if(!e?.rangeCount)return!1;let t=e.getRangeAt(0).startContainer;return!!(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement)?.closest(`pre, code`)}_getLineContext(){let e=globalThis.getSelection();if(!e?.rangeCount)return null;let t=e.getRangeAt(0);if(!t.collapsed)return null;let n=this.context.layoutInfo.editable;if(!n.contains(t.startContainer))return null;let r=t.startContainer;for(;r&&r!==n&&!this._isBlock(r);)r=r.parentNode;(!r||r===n)&&(r=t.startContainer);let i=document.createRange();return i.setStart(r,0),i.setEnd(t.startContainer,t.startOffset),{text:i.toString(),range:t,lineNode:r}}_isBlock(e){if(e.nodeType!==Node.ELEMENT_NODE)return!1;let t=globalThis.getComputedStyle(e).display;return t===`block`||t===`list-item`||t===`table-cell`}_applyBlockRule(){let e=this._getLineContext();if(!e)return!1;let{text:t}=e,n=[{re:/^(#{1,6})$/,handler:e=>this._convertToHeading(e[1].length)},{re:/^>$/,handler:()=>this._convertToBlockquote()},{re:/^[-*+]$/,handler:()=>this._convertToList(`ul`)},{re:/^1[.)]$/,handler:()=>this._convertToList(`ol`)},{re:/^\[([ xX])\]$/,handler:e=>this._convertToChecklist(e[1].toLowerCase()===`x`)}];for(let{re:e,handler:r}of n){let n=e.exec(t);if(n)return r(n),!0}return!1}_applyEnterRule(){let e=this._getLineContext();if(!e)return!1;let{text:t}=e;return/^(?:-{3,}|\*{3,}|_{3,})$/.test(t)?(this._convertToHr(),!0):/^(?:`{3}|~{3})/.test(t)?(this._convertToCodeBlock(),!0):!1}_selectLineAndDelete(){let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0),n=document.createRange();n.setStart(t.startContainer.parentNode||t.startContainer,0),n.setEnd(t.startContainer,t.startOffset),n.deleteContents()}_convertToHeading(e){this._selectLineAndDelete(),document.execCommand(`formatBlock`,!1,`h${e}`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToBlockquote(){this._selectLineAndDelete(),document.execCommand(`formatBlock`,!1,`blockquote`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToList(e){this._selectLineAndDelete(),document.execCommand(e===`ul`?`insertUnorderedList`:`insertOrderedList`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToChecklist(e=!1){if(this._selectLineAndDelete(),this.context.invoke(`editor.toggleChecklist`),e){let e=globalThis.getSelection(),t=e?.rangeCount?e.getRangeAt(0).startContainer:null,n=(t?.nodeType===Node.ELEMENT_NODE?t:t?.parentElement??null)?.closest(`li`)?.querySelector(`input[type="checkbox"]`)??null;n&&(n.checked=!0)}this.context.triggerEvent(`change`,this.context.getHTML())}_convertToHr(){this._selectLineAndDelete(),this.context.invoke(`editor.insertHr`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToCodeBlock(){this._selectLineAndDelete(),document.execCommand(`formatBlock`,!1,`pre`),this.context.triggerEvent(`change`,this.context.getHTML())}_onInput(){if(this._inCodeContext())return;let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0);if(!t.collapsed||!this.context.layoutInfo.editable.contains(t.startContainer))return;let n=t.startContainer;if(n.nodeType!==Node.TEXT_NODE)return;let r=n.textContent,i=t.startOffset,a=[{re:/\*\*(.+?)\*\*$/,tag:`strong`},{re:/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)$/,tag:`em`},{re:/~~(.+?)~~$/,tag:`s`},{re:/`([^`]+)`$/,tag:`code`}],o=r.slice(0,i);for(let{re:t,tag:s}of a){let a=t.exec(o);if(!a)continue;let c=o.length-a[0].length,l=i,u=a[1],d=r.slice(0,c),f=r.slice(l),p=document.createElement(s);p.textContent=u;let m=document.createTextNode(d),h=document.createTextNode(`​`+f);n.before(m,p,h),n.remove();let g=document.createRange();g.setStart(h,1),g.collapse(!0),e.removeAllRanges(),e.addRange(g),this.context.triggerEvent(`change`,this.context.getHTML());break}}},ma=`stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"`,Q=e=>`<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" ${ma} style="display:block">${e}</svg>`,ha={bold:Q(`<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:Q(`<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:Q(`<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:Q(`<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"/>`),link:Q(`<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"/>`),foreColor:Q(`<path d="M4 20L12 4L20 20"/><line x1="7.5" y1="14" x2="16.5" y2="14"/>`),hiliteColor:Q(`<path d="M3 21v-4l9-9 4 4-9 9z"/><path d="M12 8l4 4"/><line x1="3" y1="21" x2="21" y2="21"/>`),removeFormat:Q(`<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"/>`),inlineCode:Q(`<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"/>`)},ga={bold:e=>e.invoke(`editor.bold`),italic:e=>e.invoke(`editor.italic`),underline:e=>e.invoke(`editor.underline`),strikethrough:e=>e.invoke(`editor.strikethrough`),link:e=>e.invoke(`linkDialog.show`),removeFormat:e=>{let t=e.layoutInfo?.editable;if(!t)return;t.focus(),document.execCommand(`removeFormat`);let n=globalThis.getSelection();if(n?.rangeCount>0&&!n.getRangeAt(0).collapsed){let e=n.getRangeAt(0),t=e.commonAncestorContainer,r=t.nodeType===1?t:t.parentElement;if(r){let t=[r,...r.querySelectorAll(`[style]`)];for(let n of t)n.hasAttribute(`style`)&&e.intersectsNode(n)&&n.removeAttribute(`style`)}}e.invoke(`editor.afterCommand`)},inlineCode:e=>e.invoke(`editor.inlineCode`)},_a={bold:()=>document.queryCommandState(`bold`),italic:()=>document.queryCommandState(`italic`),underline:()=>document.queryCommandState(`underline`),strikethrough:()=>document.queryCommandState(`strikeThrough`)},va={foreColor:!0,hiliteColor:!0},ya=[{name:`editor`,Class:Wr},{name:`toolbar`,Class:Zr},{name:`statusbar`,Class:$r},{name:`clipboard`,Class:ei},{name:`placeholder`,Class:oi},{name:`contextMenu`,Class:ri},{name:`codeview`,Class:si},{name:`fullscreen`,Class:ci},{name:`linkDialog`,Class:ui},{name:`imageDialog`,Class:fi},{name:`videoDialog`,Class:mi},{name:`imageResizer`,Class:_i},{name:`videoResizer`,Class:vi},{name:`linkTooltip`,Class:Si},{name:`imageTooltip`,Class:wi},{name:`videoTooltip`,Class:Ti},{name:`tableTooltip`,Class:Mi},{name:`codeTooltip`,Class:Bi},{name:`emojiDialog`,Class:Ji},{name:`iconDialog`,Class:ra},{name:`shortcutsDialog`,Class:sa},{name:`findReplace`,Class:ca},{name:`imageCropOverlay`,Class:da},{name:`autoSaveRestore`,Class:fa,enabled:e=>!!e.autoSaveRestore},{name:`markdownShortcuts`,Class:pa,enabled:e=>e.markdownShortcuts!==!1},{name:`bubbleToolbar`,Class:class{constructor(e){this.context=e,this.options=e.options,this._el=null,this._picker=null,this._pickerType=null,this._savedRange=null,this._visible=!1,this._rafId=null,this._contextMenuOpen=!1,this._disposers=[],this._onSelectionChange=this._onSelectionChange.bind(this),this._onMousedown=this._onMousedown.bind(this),this._onKeydown=this._onKeydown.bind(this),this._onContextMenu=this._onContextMenu.bind(this)}initialize(){if(!this.options.bubbleToolbar)return this;this._build(),this._buildColorPicker();let e=v(document,`selectionchange`,this._onSelectionChange),t=v(document,`mousedown`,this._onMousedown),n=v(document,`keydown`,this._onKeydown),r=v(document,`contextmenu`,this._onContextMenu),i=this.context.on(`contextMenu:show`,()=>{this._contextMenuOpen=!0,this._hide()}),a=this.context.on(`contextMenu:hide`,()=>{this._contextMenuOpen=!1}),o=v(globalThis,`scroll`,()=>this._hide(),{passive:!0}),s=v(globalThis,`resize`,()=>this._hide(),{passive:!0});return this._disposers.push(e,t,n,r,i,a,o,s),this}destroy(){this._el?.remove(),this._el=null,this._picker?.remove(),this._picker=null,this._disposers.forEach(e=>e()),this._disposers=[],cancelAnimationFrame(this._rafId)}_build(){let e=document.createElement(`div`);e.className=`an-bubble-toolbar`,e.setAttribute(`role`,`toolbar`),e.setAttribute(`aria-label`,`Formatting`);let t=this.options.bubbleToolbarItems||[`bold`,`italic`,`underline`,`link`,`foreColor`,`hiliteColor`,`removeFormat`];for(let n of t){if(!ha[n])continue;let t=qe(this.options,[n])??ha[n],r=document.createElement(`button`);r.type=`button`,r.dataset.name=n;let i=this.context.locale?.toolbar?.[n];if(r.setAttribute(`aria-label`,typeof i==`string`?i:n),va[n]){r.className=`an-bubble-btn an-bubble-btn--color`;let e=document.createElement(`span`);e.className=`an-bubble-btn-svg`,e.innerHTML=t;let i=document.createElement(`span`);i.className=`an-bubble-color-strip`,i.style.background=n===`foreColor`?`#000000`:`transparent`,r.appendChild(e),r.appendChild(i)}else r.className=`an-bubble-btn`,r.innerHTML=t;r.addEventListener(`mousedown`,e=>{e.preventDefault()}),r.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),va[n]){this._openColorPicker(n,r);return}this.context.triggerEvent?.(`beforeCommand`,{name:n,source:`bubbleToolbar`})!==!1&&(this.context.invoke(`editor.focus`),ga[n]&&ga[n](this.context),this._syncActive())}),e.appendChild(r)}x(this.context).appendChild(e),this._el=e,this._btnCache=Array.from(e.querySelectorAll(`.an-bubble-btn`))}_buildColorPicker(){let e=document.createElement(`div`);e.className=`an-bubble-color-picker`,e.style.display=`none`,e.addEventListener(`mousedown`,e=>e.preventDefault());let t=document.createElement(`div`);t.className=`an-context-color-palette`,Kr(this.options).forEach(e=>{let n=document.createElement(`div`);n.className=`an-context-color-swatch`,n.title=e,n.style.background=e,n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,e),n.addEventListener(`click`,t=>{t.stopPropagation(),this._applyColor(this._pickerType,e)}),t.appendChild(n)});let n=document.createElement(`div`);n.className=`an-context-color-swatch an-context-color-none`,n.title=`No highlight`,n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,`No highlight`),n.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="4" y1="4" x2="20" y2="20"/><line x1="20" y1="4" x2="4" y2="20"/></svg>`,n.addEventListener(`click`,e=>{e.stopPropagation(),this._applyColor(`hiliteColor`,`transparent`)});let r=document.createElement(`div`);r.className=`an-context-color-custom`;let i=document.createElement(`input`);i.type=`color`,i.value=`#000000`,i.title=`Custom color`,i.addEventListener(`mousedown`,e=>e.stopPropagation()),i.addEventListener(`change`,()=>{this._applyColor(this._pickerType,i.value)});let a=document.createElement(`span`);a.textContent=`Custom…`,r.appendChild(i),r.appendChild(a),e.appendChild(t),e.appendChild(r),x(this.context).appendChild(e),this._picker=e;let o=e;o._paletteEl=t,o._noColorBtn=n,o._colorInput=i}_openColorPicker(e,t){let n=globalThis.getSelection();n?.rangeCount>0&&(this._savedRange=n.getRangeAt(0).cloneRange()),this._pickerType=e;let r=this._picker,i=r._paletteEl,a=r._noColorBtn;e===`hiliteColor`?i.contains(a)||i.appendChild(a):i.contains(a)&&a.remove(),this._picker._colorInput.value=e===`foreColor`?`#000000`:`#ffff00`,this._picker.style.display=`block`;let o=this._picker.offsetWidth,s=this._picker.offsetHeight,c=this._el.getBoundingClientRect(),l=c.top-s-6;l<8&&(l=c.bottom+6);let u=t.getBoundingClientRect().left;u=Math.max(8,Math.min(u,globalThis.innerWidth-o-8)),this._picker.style.left=`${u}px`,this._picker.style.top=`${l}px`}_closeColorPicker(){this._picker&&(this._picker.style.display=`none`),this._pickerType=null}_applyColor(e,t){let n=this.context.layoutInfo?.editable;if(!n||!this._savedRange)return;n.focus();let r=globalThis.getSelection();r.removeAllRanges();try{r.addRange(this._savedRange.cloneRange())}catch{return}let i=e===`hiliteColor`?`hiliteColor`:e;!document.execCommand(i,!1,t)&&i===`hiliteColor`&&document.execCommand(`backColor`,!1,t),this.context.invoke(`editor.afterCommand`);let a=e===`hiliteColor`?`hiliteColor`:`foreColor`,o=(this._el?.querySelector(`[data-name="${a}"]`))?.querySelector(`.an-bubble-color-strip`);o&&(o.style.background=t===`transparent`?`transparent`:t),this._closeColorPicker(),this._syncActive()}_show(e){if(!this._el)return;let t=this._el;t.style.visibility=`hidden`,t.style.display=`flex`;let n=t.offsetWidth,r=t.offsetHeight,i=e.left+e.width/2-n/2,a=e.top-r-8;i=Math.max(8,Math.min(i,globalThis.innerWidth-n-8)),a<8&&(a=e.bottom+8);let o=document.querySelector(`.an-table-tooltip`);if(o&&o.style.display!==`none`){let t=o.getBoundingClientRect();a<t.bottom+8&&a+r>t.top-8&&(a=e.bottom+8,a+r>globalThis.innerHeight-8&&(a=t.bottom+8))}t.style.top=`${a}px`,t.style.left=`${i}px`,t.style.visibility=``,this._syncActive(),this._syncColorStrips(),this._visible=!0}_hide(){this._el&&(this._el.style.display=`none`,this._visible=!1,this._closeColorPicker())}_syncActive(){this._btnCache&&this._btnCache.forEach(e=>{let t=_a[e.dataset.name];e.classList.toggle(`an-active`,!!t?.())})}_syncColorStrips(){if(!this._el)return;let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0).startContainer;if(t.nodeType===Node.TEXT_NODE&&(t=t.parentElement),!t)return;let n=globalThis.getComputedStyle(t),r=this._el.querySelector(`[data-name="foreColor"]`)?.querySelector(`.an-bubble-color-strip`);r&&(r.style.background=n.color||`#000000`);let i=this._el.querySelector(`[data-name="hiliteColor"]`)?.querySelector(`.an-bubble-color-strip`);if(i){let e=n.backgroundColor;i.style.background=!e||e===`rgba(0, 0, 0, 0)`||e===`transparent`?`transparent`:e}}_onSelectionChange(){cancelAnimationFrame(this._rafId),this._rafId=requestAnimationFrame(()=>{if(this._contextMenuOpen||this._picker&&this._picker.style.display!==`none`)return;let e=globalThis.getSelection();if(!e||e.isCollapsed||!e.rangeCount){this._hide();return}if(!this.context.layoutInfo.editable.contains(e.anchorNode)){this._hide();return}if(this.context.options.readOnly){this._hide();return}let t=e.getRangeAt(0).getBoundingClientRect();if(!t||t.width===0){this._hide();return}this._show(t)})}_onMousedown(e){this._visible&&(this._el?.contains(e.target)||this._picker?.contains(e.target)||this.context.layoutInfo.editable.contains(e.target)||this._hide())}_onKeydown(e){e.key===`Escape`&&(this._picker&&this._picker.style.display!==`none`?this._closeColorPicker():this._visible&&this._hide())}_onContextMenu(){this._hide()}},enabled:e=>!!e.bubbleToolbar},{name:`mention`,Class:class{constructor(e){this.context=e,this._dropdown=null,this._query=``,this._debounceTimer=null,this._activeIndex=-1,this._items=[],this._open=!1,this._triggerNode=null,this._triggerOffset=0,this._caretRect=null,this._disposers=[]}initialize(){let e=this.context.options.mention;if(!e||typeof e.onSearch!=`function`)return this;this._cfg={trigger:e.trigger||`@`,minChars:e.minChars??0,maxResults:e.maxResults??8,debounce:e.debounce??200,onSearch:e.onSearch,onInsert:e.onInsert||null,onError:e.onError||null,mentionClass:e.mentionClass||`an-mention`,allowSpaces:e.allowSpaces||!1},this._buildDropdown();let t=this.context.layoutInfo.editable,n=v(t,`keydown`,e=>this._onKeydown(e)),r=v(t,`input`,()=>this._onInput()),i=v(document,`click`,e=>this._onDocClick(e));return this._disposers.push(n,r,i),this}destroy(){clearTimeout(this._debounceTimer),this._dropdown?.remove(),this._dropdown=null,this._disposers.forEach(e=>e()),this._disposers=[]}_buildDropdown(){let e=document.createElement(`div`);e.className=`an-mention-dropdown`,e.setAttribute(`role`,`listbox`),e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{let t=e.target?.closest(`.an-mention-item`);t&&this._select(+t.dataset.index)}),e.addEventListener(`mousemove`,e=>{let t=e.target?.closest(`.an-mention-item`);t&&this._highlightItem(+t.dataset.index)}),x(this.context).appendChild(e),this._dropdown=e}_renderItems(e){let t=this._dropdown;this._items=e.slice(0,this._cfg.maxResults),this._activeIndex=this._items.length>0?0:-1;let n=document.createDocumentFragment();this._items.forEach((e,t)=>{let r=document.createElement(`div`);if(r.className=`an-mention-item`,r.setAttribute(`role`,`option`),r.dataset.index=String(t),e.avatar){let t=document.createElement(`img`);t.src=e.avatar,t.className=`an-mention-avatar`,t.alt=``,r.appendChild(t)}let i=document.createElement(`span`);i.textContent=e.label,r.appendChild(i),n.appendChild(r)}),t.innerHTML=``,t.appendChild(n),this._highlightItem(this._activeIndex)}_highlightItem(e){this._dropdown&&(this._dropdown.querySelectorAll(`.an-mention-item`).forEach((t,n)=>{t.classList.toggle(`an-mention-active`,n===e)}),this._activeIndex=e)}_positionDropdown(){let e=this._dropdown,t=this._caretRect;if(!t||t.height===0)return;e.style.visibility=`hidden`,e.style.display=`block`;let n=e.offsetHeight,r=e.offsetWidth,i=t.bottom+4,a=t.left;t.bottom+n+8>globalThis.innerHeight&&(i=t.top-n-4),a=Math.max(8,Math.min(a,globalThis.innerWidth-r-8)),e.style.top=`${i}px`,e.style.left=`${a}px`,e.style.visibility=``}_showDropdown(){this._open=!0,this._positionDropdown()}_hideDropdown(){this._dropdown&&(this._dropdown.style.display=`none`),this._open=!1,this._items=[],this._activeIndex=-1,this._triggerNode=null,this._caretRect=null,this._query=``}_captureCaretRect(){if(this._triggerNode?.isConnected)try{let e=document.createRange(),t=Math.min(this._triggerOffset+1,this._triggerNode.textContent.length);e.setStart(this._triggerNode,this._triggerOffset),e.setEnd(this._triggerNode,t);let n=e.getBoundingClientRect();if(n.height>0){this._caretRect=n;return}}catch{}let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0).getClientRects();t.length>0&&(this._caretRect=t[t.length-1])}_getQueryAtCursor(){let e=globalThis.getSelection();if(!e?.rangeCount)return null;let t=e.getRangeAt(0);if(!t.collapsed)return null;let n=t.startContainer;if(n.nodeType!==Node.TEXT_NODE)return null;let r=n.textContent.slice(0,t.startOffset),i=this._cfg.trigger,a=r.lastIndexOf(i);if(a===-1)return null;let o=r.slice(a+i.length);return!this._cfg.allowSpaces&&/\s/.test(o)||o.length<this._cfg.minChars?null:(this._triggerNode=n,this._triggerOffset=a,o)}_onInput(){if(!this._cfg)return;let e=this._getQueryAtCursor();if(e===null){this._hideDropdown();return}this._captureCaretRect(),this._query=e,clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{let e=e=>{if(!Array.isArray(e)||e.length===0){this._hideDropdown();return}this._renderItems(e),this._showDropdown()},t;try{t=this._cfg.onSearch(this._query,e)}catch(e){this._hideDropdown(),typeof this._cfg.onError==`function`&&this._cfg.onError(e);return}t&&typeof t.then==`function`&&t.then(e).catch(e=>{this._hideDropdown(),typeof this._cfg.onError==`function`&&this._cfg.onError(e)})},this._cfg.debounce)}_onKeydown(e){if(!(!this._cfg||!this._open)){if(e.key===`ArrowDown`){e.preventDefault();let t=(this._activeIndex+1)%this._items.length;this._highlightItem(t)}else if(e.key===`ArrowUp`){e.preventDefault();let t=(this._activeIndex-1+this._items.length)%this._items.length;this._highlightItem(t)}else e.key===`Enter`||e.key===`Tab`?this._activeIndex>=0&&(e.preventDefault(),this._select(this._activeIndex)):e.key===`Escape`&&this._hideDropdown()}}_onDocClick(e){this._open&&(this._dropdown?.contains(e.target)||this._hideDropdown())}_select(e){let t=this._items[e];if(!t)return;if(this._triggerNode){let e=this._triggerNode;e.textContent=e.textContent.slice(0,this._triggerOffset)+e.textContent.slice(this._triggerOffset+this._cfg.trigger.length+this._query.length);let t=globalThis.getSelection(),n=document.createRange();n.setStart(e,this._triggerOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}let n;typeof this._cfg.onInsert==`function`&&(n=this._cfg.onInsert(t)),n||=`<span class="${this._cfg.mentionClass}" data-mention-id="${t.id}" contenteditable="false">@${t.label}</span>`,this.context.invoke(`editor.insertHTML`,n+`&#8203;`),this._hideDropdown(),this.context.triggerEvent(`change`,this.context.getHTML())}},enabled:e=>!!e.mention},{name:`slashMenu`,Class:class{constructor(e){this.context=e,this.options=e.options,this._disposers=[],this._menu=null,this._filtered=[],this._activeIndex=-1,this._open=!1,this._query=``,this._textNode=null,this._triggerOffset=0,this._caretRect=null}initialize(){if(this.options.slashMenu===!1)return this;let e=this.context.layoutInfo.editable,t=v(e,`input`,()=>this._onInput()),n=v(e,`keydown`,e=>this._onKeydown(e)),r=v(document,`click`,e=>this._onDocClick(e));return this._disposers.push(t,n,r),this}destroy(){this._menu?.remove(),this._menu=null,this._disposers.forEach(e=>e()),this._disposers=[]}_commands(){let e=this.context.locale.slashMenu,t=this.context,n=[{id:`h1`,label:e.heading1,keywords:`h1 heading title`,run:()=>t.invoke(`editor.formatBlock`,`h1`)},{id:`h2`,label:e.heading2,keywords:`h2 heading subtitle`,run:()=>t.invoke(`editor.formatBlock`,`h2`)},{id:`h3`,label:e.heading3,keywords:`h3 heading`,run:()=>t.invoke(`editor.formatBlock`,`h3`)},{id:`ul`,label:e.bulletList,keywords:`ul bullet list unordered`,run:()=>t.invoke(`editor.insertUL`)},{id:`ol`,label:e.numberedList,keywords:`ol numbered list ordered`,run:()=>t.invoke(`editor.insertOL`)},{id:`checklist`,label:e.checklist,keywords:`checklist todo checkbox task`,run:()=>t.invoke(`editor.toggleChecklist`)},{id:`quote`,label:e.blockquote,keywords:`quote blockquote`,run:()=>t.invoke(`editor.formatBlock`,`blockquote`)},{id:`code`,label:e.codeBlock,keywords:`code pre block`,run:()=>t.invoke(`editor.formatBlock`,`pre`)},{id:`hr`,label:e.horizontalRule,keywords:`hr divider rule line`,run:()=>t.invoke(`editor.insertHr`)},{id:`table`,label:e.table,keywords:`table grid`,run:()=>t.invoke(`editor.insertTable`,3,3)},{id:`image`,label:e.image,keywords:`image picture photo upload`,run:()=>t.invoke(`imageDialog.show`)}],r=(this.options.slashCommands||[]).map(e=>({id:e.id,label:e.label||e.id,keywords:e.keywords||``,run:()=>e.run(t)}));return[...n,...r]}refresh(){this._open&&this._filterAndRender()}_buildMenu(){let e=document.createElement(`div`);return e.className=`an-slash-menu`,e.setAttribute(`role`,`listbox`),e.style.display=`none`,e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{let t=e.target?.closest(`.an-slash-menu-item`);t&&this._select(+t.dataset.index)}),e.addEventListener(`mousemove`,e=>{let t=e.target?.closest(`.an-slash-menu-item`);t&&this._highlight(+t.dataset.index)}),x(this.context).appendChild(e),this._menu=e,e}_renderItems(){this._menu||this._buildMenu();let e=this._menu,t=this.context.locale.slashMenu;if(this._filtered.length===0){e.innerHTML=``;let n=document.createElement(`div`);n.className=`an-slash-menu-empty`,n.textContent=t.noResults,e.appendChild(n),this._activeIndex=-1;return}let n=document.createDocumentFragment();this._filtered.forEach((e,t)=>{let r=document.createElement(`div`);r.className=`an-slash-menu-item`,r.setAttribute(`role`,`option`),r.id=`an-slash-option-${e.id}`,r.dataset.index=String(t),r.textContent=e.label,n.appendChild(r)}),e.innerHTML=``,e.appendChild(n),this._highlight(0)}_highlight(e){this._menu&&(this._menu.querySelectorAll(`.an-slash-menu-item`).forEach((t,n)=>{let r=n===e;t.classList.toggle(`an-slash-menu-active`,r),t.setAttribute(`aria-selected`,String(r)),r&&this._menu.setAttribute(`aria-activedescendant`,t.id)}),this._activeIndex=e)}_position(){let e=this._menu,t=this._caretRect;if(!e||!t||t.height===0)return;e.style.visibility=`hidden`,e.style.display=`block`;let n=e.offsetHeight,r=e.offsetWidth,i=t.bottom+4,a=t.left;t.bottom+n+8>globalThis.innerHeight&&(i=t.top-n-4),a=Math.max(8,Math.min(a,globalThis.innerWidth-r-8)),e.style.top=`${i}px`,e.style.left=`${a}px`,e.style.visibility=``}_open_(){this._open=!0,this._filterAndRender(),this._position()}_close(){this._menu&&(this._menu.style.display=`none`),this._open=!1,this._filtered=[],this._activeIndex=-1,this._menu?.removeAttribute(`aria-activedescendant`),this._textNode=null,this._caretRect=null,this._query=``}_isBlock(e){if(e.nodeType!==Node.ELEMENT_NODE)return!1;let t=globalThis.getComputedStyle(e).display;return t===`block`||t===`list-item`||t===`table-cell`}_getTriggerContext(){let e=globalThis.getSelection();if(!e?.rangeCount)return null;let t=e.getRangeAt(0);if(!t.collapsed)return null;let n=this.context.layoutInfo.editable;if(!n.contains(t.startContainer)||t.startContainer.nodeType!==Node.TEXT_NODE)return null;let r=t.startContainer.parentNode;for(;r&&r!==n&&!this._isBlock(r);)r=r.parentNode;if(!r||r===n)return null;let i=r.textContent||``,a=document.createRange();a.setStart(r,0),a.setEnd(t.startContainer,t.startOffset);let o=a.toString(),s=/^\/(\S*)$/.exec(o);return!s||i.length>o.length?null:{query:s[1],textNode:t.startContainer,triggerOffset:t.startOffset-s[0].length}}_captureCaretRect(e,t){try{let n=document.createRange(),r=Math.min(t+1,e.textContent.length);n.setStart(e,t),n.setEnd(e,r);let i=n.getBoundingClientRect();if(i.height>0)return i}catch{}let n=globalThis.getSelection();if(!n?.rangeCount)return null;let r=n.getRangeAt(0).getClientRects();return r.length>0?r[r.length-1]:null}_filterAndRender(){let e=this._query.toLowerCase();this._filtered=e?this._commands().filter(t=>t.keywords.includes(e)||t.label.toLowerCase().includes(e)):this._commands(),this._renderItems()}_onInput(){let e=this._getTriggerContext();if(!e){this._open&&this._close();return}this._textNode=e.textNode,this._triggerOffset=e.triggerOffset,this._query=e.query,this._caretRect=this._captureCaretRect(e.textNode,e.triggerOffset),this._open?(this._filterAndRender(),this._position()):this._open_()}_onKeydown(e){if(this._open){if(e.key===`ArrowDown`){if(e.preventDefault(),this._filtered.length===0)return;this._highlight((this._activeIndex+1)%this._filtered.length)}else if(e.key===`ArrowUp`){if(e.preventDefault(),this._filtered.length===0)return;this._highlight((this._activeIndex-1+this._filtered.length)%this._filtered.length)}else e.key===`Enter`||e.key===`Tab`?this._activeIndex>=0&&(e.preventDefault(),this._select(this._activeIndex)):e.key===`Escape`&&(e.preventDefault(),this._close())}}_onDocClick(e){this._open&&(this._menu?.contains(e.target)||this._close())}_deleteTriggerText(){let e=this._textNode;if(!e?.isConnected)return;e.textContent=e.textContent.slice(0,this._triggerOffset)+e.textContent.slice(this._triggerOffset+1+this._query.length);let t=globalThis.getSelection();if(!t)return;let n=document.createRange();n.setStart(e,this._triggerOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}_makeTriggerRemover(){let e=this._textNode,t=this._triggerOffset,n=this._query;return()=>{if(!e?.isConnected)return;let r=e.textContent.slice(0,t),i=e.textContent.slice(t+1+n.length);e.textContent=r+i;let a=globalThis.getSelection();if(!a)return;let o=document.createRange();o.setStart(e,t),o.collapse(!0),a.removeAllRanges(),a.addRange(o)}}_select(e){let t=this._filtered[e];if(t){if(t.id===`image`){let e=this._makeTriggerRemover();this._close(),this.context.invoke(`imageDialog.show`,{beforeInsert:e});return}this._deleteTriggerText(),this._close(),t.run()}}},enabled:e=>e.slashMenu!==!1}],ba=`3.0.0`,xa={...j},$=new WeakMap,Sa={create(e,t={}){let n=Ca(e).map(e=>{if($.has(e))return $.get(e);let n=new _n(e,t);return n._releaseInstance=()=>{$.get(e)===n&&$.delete(e)},n.initialize(),$.set(e,n),n});return n.length===1?n[0]:n},destroy(e){Ca(e).forEach(e=>{let t=$.get(e);t&&(t.destroy(),$.delete(e))})},getInstance(e){let t=typeof e==`string`?document.querySelector(e):e;return t&&$.get(t)||null},get defaults(){return{...j}},setDefaults(e){Object.assign(j,e)},resetDefaults(){Object.keys(j).forEach(e=>delete j[e]),Object.assign(j,xa)},registerModule(e,t){un.set(e,t)},use(e,t={}){if(!e||typeof e.name!=`string`)throw TypeError("[AutumnNote] AutumnNote.use: plugin must have a string `name` property.");return gn.has(e.name)?(console.warn(`[AutumnNote] Plugin "${e.name}" already registered globally. Skipping.`),this):(Array.isArray(e.buttons)&&e.buttons.forEach(e=>ze(e)),gn.set(e.name,{plugin:e,options:t}),this)},hasPlugin(e){return gn.has(e)},registerButton(e){return ze(e),this},registerIcon(e,t){return Ge(e,t),this},registerLocale(e,t){return c(e,t),this},registerSlashCommand(e){if(!e?.id||typeof e.run!=`function`)throw TypeError(`[AutumnNote] Slash command requires an id and run(context) function.`);let t=j.slashCommands,n=t.findIndex(t=>t.id===e.id);return n>=0?t[n]=e:t.push(e),this},buttons:Lt,version:ba};function Ca(e){return typeof e==`string`?Array.from(document.querySelectorAll(e)):e instanceof Element?[e]:e instanceof NodeList||Array.isArray(e)?Array.from(e):[]}return fn(ya),Sa});
75
+ `,r.addEventListener(`mouseover`,()=>{r.style.background=t+`22`}),r.addEventListener(`mouseout`,()=>{r.style.background=`none`}),this._disposers.push(v(r,`click`,e=>{e.stopPropagation(),n()})),r}_updateDOM(){let{x:e,y:t,w:n,h:r}=this._box;this._cropBox.style.left=`${e}px`,this._cropBox.style.top=`${t}px`,this._cropBox.style.width=`${n}px`,this._cropBox.style.height=`${r}px`;let i=globalThis.innerWidth,a=globalThis.innerHeight;if(this._scrim.style.clipPath=[`polygon(`,`0 0, ${i}px 0, ${i}px ${a}px, 0 ${a}px, 0 0,`,`${e}px ${t}px, ${e}px ${t+r}px, ${e+n}px ${t+r}px, ${e+n}px ${t}px, ${e}px ${t}px`,`)`].join(``),this._img){let i=this._img.naturalWidth||0,a=this._img.naturalHeight||0,o=this._imgRect.width||1,s=this._imgRect.height||1,c={x:i/o,y:a/s},l=Z(e-this._imgRect.left,0,o),u=Z(t-this._imgRect.top,0,s),d=Z(n,0,o-l),f=Z(r,0,s-u);this._infoEl.textContent=`${Math.round(d*c.x)} × ${Math.round(f*c.y)} px`}let o=t+r+8;o+40>globalThis.innerHeight-8&&(o=t-40-8),this._toolbar.style.left=`${e}px`,this._toolbar.style.top=`${o}px`}_startBoxMove(e){let t=e.clientX-this._box.x,n=e.clientY-this._box.y,r=this._imgRect;this._attachDocDrag(e=>{this._box.x=Z(e.clientX-t,r.left,r.right-this._box.w),this._box.y=Z(e.clientY-n,r.top,r.bottom-this._box.h),this._updateDOM()})}_startHandleDrag(e,t){let n=e.clientX,r=e.clientY,i={...this._box},a=this._imgRect,o=this._arCheck?.checked,s=i.w/(i.h||1);this._attachDocDrag(e=>{let c=e.clientX-n,l=e.clientY-r,{x:u,y:d,w:f,h:p}=i;t.includes(`e`)&&(f=Math.max(X,i.w+c)),t.includes(`s`)&&(p=Math.max(X,i.h+l)),t.includes(`w`)&&(u=Math.min(i.x+i.w-X,i.x+c),f=i.x+i.w-u),t.includes(`n`)&&(d=Math.min(i.y+i.h-X,i.y+l),p=i.y+i.h-d),o&&t.length===2&&(Math.abs(c)>=Math.abs(l)?(p=f/s,t.includes(`n`)&&(d=i.y+i.h-p)):(f=p*s,t.includes(`w`)&&(u=i.x+i.w-f))),u=Z(u,a.left,a.right-X),d=Z(d,a.top,a.bottom-X),f=Z(f,X,a.right-u),p=Z(p,X,a.bottom-d),this._box={x:u,y:d,w:f,h:p},this._updateDOM()})}_attachDocDrag(e){this._dragDisposers?.();let t=t=>{t.preventDefault();let n=t;e({clientX:n.touches[0].clientX,clientY:n.touches[0].clientY})},n=()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.body.style.userSelect=``,document.body.style.cursor=``,this._dragDisposers=null};this._dragDisposers=n,document.body.style.userSelect=`none`,document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n,{once:!0}),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n,{once:!0})}_bindEsc(){let e=e=>{e.key===`Escape`&&(e.preventDefault(),this._close(!1)),e.key===`Enter`&&(e.preventDefault(),this._confirm())};document.addEventListener(`keydown`,e),this._disposers.push(()=>document.removeEventListener(`keydown`,e))}async _confirm(){let e=this._img;if(!e){this._close(!1);return}let t=this._imgRect,{x:n,y:r,w:i,h:a}=this._box,o=(e.naturalWidth||e.width||1)/(t.width||1),s=(e.naturalHeight||e.height||1)/(t.height||1),c=Math.round(Z(n-t.left,0,t.width)*o),l=Math.round(Z(r-t.top,0,t.height)*s),u=Math.round(Z(i,0,t.width-(n-t.left))*o),d=Math.round(Z(a,0,t.height-(r-t.top))*s);if(u<=0||d<=0){this._close(!1);return}let f=await ua(e,{x:c,y:l,width:u,height:d},i,a);if(!f){this._showCropError(`Cannot crop this image: the image server does not allow cross-origin access. Upload the image directly to use the crop tool.`),this._close(!1);return}let p=/^data:image\/(jpe?g)/i.exec(e.src)?`image/jpeg`:`image/png`,m=p===`image/jpeg`?.92:void 0,h=f.toDataURL(p,m);this._close(!1),e.src=h,e.style.width=``,e.style.height=``,e.removeAttribute(`width`),e.removeAttribute(`height`),this.context.invoke(`editor.afterCommand`),this.context.invoke(`imageResizer.updateOverlay`)}_showCropError(e){let t=document.createElement(`div`);t.setAttribute(`role`,`alert`),t.style.cssText=[`position:fixed`,`bottom:24px`,`left:50%`,`transform:translateX(-50%)`,`z-index:calc(10200 + var(--an-z-offset, 0))`,`max-width:420px`,`width:max-content`,`background:#7f1d1d`,`color:#fecaca`,`border:1px solid #b91c1c`,`border-radius:8px`,`padding:12px 18px`,`font:13px/1.5 system-ui,sans-serif`,`box-shadow:0 4px 16px rgba(0,0,0,.4)`,`pointer-events:auto`].join(`;`),t.textContent=e,x(this.context).appendChild(t),setTimeout(()=>{t.remove()},4e3)}_close(e){this._dragDisposers?.(),this._dragDisposers=null,this._disposers.forEach(e=>e()),this._disposers=[],[this._scrim,this._cropBox,this._toolbar].forEach(e=>{e?.remove()}),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}},fa=class{constructor(e){this.context=e,this.options=e.options,this._banner=null}initialize(){if(!this.options.autoSave||!this.options.autoSaveRestore)return this;let e=this.options.autoSaveKey,t=e+`:asrmeta`,n,r;try{n=localStorage.getItem(e),r=JSON.parse(localStorage.getItem(t)||`{}`)}catch{return this}if(!n)return this;let i=this.options.autoSaveRestoreTimeout;if(i>0&&Date.now()-(r.savedAt||0)>i*864e5){try{localStorage.removeItem(e),localStorage.removeItem(t)}catch{}return this}return this._showBanner(n,r),this}destroy(){this._removeBanner()}_showBanner(e,t){let n=this.context.locale.autoSaveRestore||{},r=n.found||`Draft found. Restore?`,i=n.restore||`Restore`,a=n.discard||`Discard`,o=document.createElement(`div`);o.className=`an-asr-banner`,o.setAttribute(`role`,`alert`);let s=document.createElement(`span`);if(s.className=`an-asr-msg`,t.savedAt){let e=new Date(t.savedAt).toLocaleString();s.textContent=(n.foundAt||`Draft from {date}. Restore?`).replace(`{date}`,e)}else s.textContent=r;let c=document.createElement(`button`);c.type=`button`,c.className=`an-btn an-asr-btn-restore`,c.textContent=i,c.addEventListener(`click`,()=>this._restore(e));let l=document.createElement(`button`);l.type=`button`,l.className=`an-btn an-asr-btn-discard`,l.textContent=a,l.addEventListener(`click`,()=>this._discard()),o.appendChild(s),o.appendChild(c),o.appendChild(l),this._banner=o;let u=this.context.layoutInfo.container;u.insertBefore(o,u.firstChild)}_restore(e){this.context.setHTML(e),this.context.clearHistory(),this._removeBanner(),this.context.triggerEvent(`autoSaveRestore`,e,this.context)}_discard(){let e=this.options.autoSaveKey;try{localStorage.removeItem(e),localStorage.removeItem(e+`:asrmeta`)}catch{}this._removeBanner()}_removeBanner(){this._banner?.remove(),this._banner=null}},pa=class{constructor(e){this.context=e,this.options=e.options,this._disposers=[]}initialize(){if(!this.options.markdownShortcuts)return this;let e=this.context.layoutInfo.editable,t=v(e,`keydown`,e=>this._onKeydown(e)),n=v(e,`input`,()=>this._onInput());return this._disposers.push(t,n),this}destroy(){this._disposers.forEach(e=>e()),this._disposers=[]}_onKeydown(e){this._inCodeContext()||(e.key===` `?this._applyBlockRule()&&e.preventDefault():e.key===`Enter`&&this._applyEnterRule()&&e.preventDefault())}_inCodeContext(){let e=globalThis.getSelection();if(!e?.rangeCount)return!1;let t=e.getRangeAt(0).startContainer;return!!(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement)?.closest(`pre, code`)}_getLineContext(){let e=globalThis.getSelection();if(!e?.rangeCount)return null;let t=e.getRangeAt(0);if(!t.collapsed)return null;let n=this.context.layoutInfo.editable;if(!n.contains(t.startContainer))return null;let r=t.startContainer;for(;r&&r!==n&&!this._isBlock(r);)r=r.parentNode;(!r||r===n)&&(r=t.startContainer);let i=document.createRange();return i.setStart(r,0),i.setEnd(t.startContainer,t.startOffset),{text:i.toString(),range:t,lineNode:r}}_isBlock(e){if(e.nodeType!==Node.ELEMENT_NODE)return!1;let t=globalThis.getComputedStyle(e).display;return t===`block`||t===`list-item`||t===`table-cell`}_applyBlockRule(){let e=this._getLineContext();if(!e)return!1;let{text:t}=e,n=[{re:/^(#{1,6})$/,handler:e=>this._convertToHeading(e[1].length)},{re:/^>$/,handler:()=>this._convertToBlockquote()},{re:/^[-*+]$/,handler:()=>this._convertToList(`ul`)},{re:/^1[.)]$/,handler:()=>this._convertToList(`ol`)},{re:/^\[([ xX])\]$/,handler:e=>this._convertToChecklist(e[1].toLowerCase()===`x`)}];for(let{re:e,handler:r}of n){let n=e.exec(t);if(n)return r(n),!0}return!1}_applyEnterRule(){let e=this._getLineContext();if(!e)return!1;let{text:t}=e;return/^(?:-{3,}|\*{3,}|_{3,})$/.test(t)?(this._convertToHr(),!0):/^(?:`{3}|~{3})/.test(t)?(this._convertToCodeBlock(),!0):!1}_selectLineAndDelete(){let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0),n=document.createRange();n.setStart(t.startContainer.parentNode||t.startContainer,0),n.setEnd(t.startContainer,t.startOffset),n.deleteContents()}_convertToHeading(e){this._selectLineAndDelete(),document.execCommand(`formatBlock`,!1,`h${e}`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToBlockquote(){this._selectLineAndDelete(),document.execCommand(`formatBlock`,!1,`blockquote`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToList(e){this._selectLineAndDelete(),document.execCommand(e===`ul`?`insertUnorderedList`:`insertOrderedList`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToChecklist(e=!1){if(this._selectLineAndDelete(),this.context.invoke(`editor.toggleChecklist`),e){let e=globalThis.getSelection(),t=e?.rangeCount?e.getRangeAt(0).startContainer:null,n=(t?.nodeType===Node.ELEMENT_NODE?t:t?.parentElement??null)?.closest(`li`)?.querySelector(`input[type="checkbox"]`)??null;n&&(n.checked=!0)}this.context.triggerEvent(`change`,this.context.getHTML())}_convertToHr(){this._selectLineAndDelete(),this.context.invoke(`editor.insertHr`),this.context.triggerEvent(`change`,this.context.getHTML())}_convertToCodeBlock(){this._selectLineAndDelete(),document.execCommand(`formatBlock`,!1,`pre`),this.context.triggerEvent(`change`,this.context.getHTML())}_onInput(){if(this._inCodeContext())return;let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0);if(!t.collapsed||!this.context.layoutInfo.editable.contains(t.startContainer))return;let n=t.startContainer;if(n.nodeType!==Node.TEXT_NODE)return;let r=n.textContent,i=t.startOffset,a=[{re:/\*\*(.+?)\*\*$/,tag:`strong`},{re:/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)$/,tag:`em`},{re:/~~(.+?)~~$/,tag:`s`},{re:/`([^`]+)`$/,tag:`code`}],o=r.slice(0,i);for(let{re:t,tag:s}of a){let a=t.exec(o);if(!a)continue;let c=o.length-a[0].length,l=i,u=a[1],d=r.slice(0,c),f=r.slice(l),p=document.createElement(s);p.textContent=u;let m=document.createTextNode(d),h=document.createTextNode(`​`+f);n.before(m,p,h),n.remove();let g=document.createRange();g.setStart(h,1),g.collapse(!0),e.removeAllRanges(),e.addRange(g),this.context.triggerEvent(`change`,this.context.getHTML());break}}},ma=`stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"`,Q=e=>`<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" ${ma} style="display:block">${e}</svg>`,ha={bold:Q(`<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:Q(`<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:Q(`<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:Q(`<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"/>`),link:Q(`<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"/>`),foreColor:Q(`<path d="M4 20L12 4L20 20"/><line x1="7.5" y1="14" x2="16.5" y2="14"/>`),hiliteColor:Q(`<path d="M3 21v-4l9-9 4 4-9 9z"/><path d="M12 8l4 4"/><line x1="3" y1="21" x2="21" y2="21"/>`),removeFormat:Q(`<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"/>`),inlineCode:Q(`<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"/>`)},ga={bold:e=>e.invoke(`editor.bold`),italic:e=>e.invoke(`editor.italic`),underline:e=>e.invoke(`editor.underline`),strikethrough:e=>e.invoke(`editor.strikethrough`),link:e=>e.invoke(`linkDialog.show`),removeFormat:e=>{let t=e.layoutInfo?.editable;if(!t)return;t.focus(),document.execCommand(`removeFormat`);let n=globalThis.getSelection();if(n?.rangeCount>0&&!n.getRangeAt(0).collapsed){let e=n.getRangeAt(0),t=e.commonAncestorContainer,r=t.nodeType===1?t:t.parentElement;if(r){let t=[r,...r.querySelectorAll(`[style]`)];for(let n of t)n.hasAttribute(`style`)&&e.intersectsNode(n)&&n.removeAttribute(`style`)}}e.invoke(`editor.afterCommand`)},inlineCode:e=>e.invoke(`editor.inlineCode`)},_a={bold:()=>document.queryCommandState(`bold`),italic:()=>document.queryCommandState(`italic`),underline:()=>document.queryCommandState(`underline`),strikethrough:()=>document.queryCommandState(`strikeThrough`)},va={foreColor:!0,hiliteColor:!0},ya=[{name:`editor`,Class:Wr},{name:`toolbar`,Class:Zr},{name:`statusbar`,Class:$r},{name:`clipboard`,Class:ei},{name:`placeholder`,Class:oi},{name:`contextMenu`,Class:ri},{name:`codeview`,Class:si},{name:`fullscreen`,Class:ci},{name:`linkDialog`,Class:ui},{name:`imageDialog`,Class:fi},{name:`videoDialog`,Class:mi},{name:`imageResizer`,Class:_i},{name:`videoResizer`,Class:vi},{name:`linkTooltip`,Class:Si},{name:`imageTooltip`,Class:wi},{name:`videoTooltip`,Class:Ti},{name:`tableTooltip`,Class:Mi},{name:`codeTooltip`,Class:Bi},{name:`emojiDialog`,Class:Ji},{name:`iconDialog`,Class:ra},{name:`shortcutsDialog`,Class:sa},{name:`findReplace`,Class:ca},{name:`imageCropOverlay`,Class:da},{name:`autoSaveRestore`,Class:fa,enabled:e=>!!e.autoSaveRestore},{name:`markdownShortcuts`,Class:pa,enabled:e=>e.markdownShortcuts!==!1},{name:`bubbleToolbar`,Class:class{constructor(e){this.context=e,this.options=e.options,this._el=null,this._picker=null,this._pickerType=null,this._savedRange=null,this._visible=!1,this._rafId=null,this._contextMenuOpen=!1,this._disposers=[],this._onSelectionChange=this._onSelectionChange.bind(this),this._onMousedown=this._onMousedown.bind(this),this._onKeydown=this._onKeydown.bind(this),this._onContextMenu=this._onContextMenu.bind(this)}initialize(){if(!this.options.bubbleToolbar)return this;this._build(),this._buildColorPicker();let e=v(document,`selectionchange`,this._onSelectionChange),t=v(document,`mousedown`,this._onMousedown),n=v(document,`keydown`,this._onKeydown),r=v(document,`contextmenu`,this._onContextMenu),i=this.context.on(`contextMenu:show`,()=>{this._contextMenuOpen=!0,this._hide()}),a=this.context.on(`contextMenu:hide`,()=>{this._contextMenuOpen=!1}),o=v(globalThis,`scroll`,()=>this._hide(),{passive:!0}),s=v(globalThis,`resize`,()=>this._hide(),{passive:!0});return this._disposers.push(e,t,n,r,i,a,o,s),this}destroy(){this._el?.remove(),this._el=null,this._picker?.remove(),this._picker=null,this._disposers.forEach(e=>e()),this._disposers=[],cancelAnimationFrame(this._rafId)}_build(){let e=document.createElement(`div`);e.className=`an-bubble-toolbar`,e.setAttribute(`role`,`toolbar`),e.setAttribute(`aria-label`,`Formatting`);let t=this.options.bubbleToolbarItems||[`bold`,`italic`,`underline`,`link`,`foreColor`,`hiliteColor`,`removeFormat`];for(let n of t){if(!ha[n])continue;let t=qe(this.options,[n])??ha[n],r=document.createElement(`button`);r.type=`button`,r.dataset.name=n;let i=this.context.locale?.toolbar?.[n];if(r.setAttribute(`aria-label`,typeof i==`string`?i:n),va[n]){r.className=`an-bubble-btn an-bubble-btn--color`;let e=document.createElement(`span`);e.className=`an-bubble-btn-svg`,e.innerHTML=t;let i=document.createElement(`span`);i.className=`an-bubble-color-strip`,i.style.background=n===`foreColor`?`#000000`:`transparent`,r.appendChild(e),r.appendChild(i)}else r.className=`an-bubble-btn`,r.innerHTML=t;r.addEventListener(`mousedown`,e=>{e.preventDefault()}),r.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),va[n]){this._openColorPicker(n,r);return}this.context.triggerEvent?.(`beforeCommand`,{name:n,source:`bubbleToolbar`})!==!1&&(this.context.invoke(`editor.focus`),ga[n]&&ga[n](this.context),this._syncActive())}),e.appendChild(r)}x(this.context).appendChild(e),this._el=e,this._btnCache=Array.from(e.querySelectorAll(`.an-bubble-btn`))}_buildColorPicker(){let e=document.createElement(`div`);e.className=`an-bubble-color-picker`,e.style.display=`none`,e.addEventListener(`mousedown`,e=>e.preventDefault());let t=document.createElement(`div`);t.className=`an-context-color-palette`,Kr(this.options).forEach(e=>{let n=document.createElement(`div`);n.className=`an-context-color-swatch`,n.title=e,n.style.background=e,n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,e),n.addEventListener(`click`,t=>{t.stopPropagation(),this._applyColor(this._pickerType,e)}),t.appendChild(n)});let n=document.createElement(`div`);n.className=`an-context-color-swatch an-context-color-none`,n.title=`No highlight`,n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,`No highlight`),n.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="4" y1="4" x2="20" y2="20"/><line x1="20" y1="4" x2="4" y2="20"/></svg>`,n.addEventListener(`click`,e=>{e.stopPropagation(),this._applyColor(`hiliteColor`,`transparent`)});let r=document.createElement(`div`);r.className=`an-context-color-custom`;let i=document.createElement(`input`);i.type=`color`,i.value=`#000000`,i.title=`Custom color`,i.addEventListener(`mousedown`,e=>e.stopPropagation()),i.addEventListener(`change`,()=>{this._applyColor(this._pickerType,i.value)});let a=document.createElement(`span`);a.textContent=`Custom…`,r.appendChild(i),r.appendChild(a),e.appendChild(t),e.appendChild(r),x(this.context).appendChild(e),this._picker=e;let o=e;o._paletteEl=t,o._noColorBtn=n,o._colorInput=i}_openColorPicker(e,t){let n=globalThis.getSelection();n?.rangeCount>0&&(this._savedRange=n.getRangeAt(0).cloneRange()),this._pickerType=e;let r=this._picker,i=r._paletteEl,a=r._noColorBtn;e===`hiliteColor`?i.contains(a)||i.appendChild(a):i.contains(a)&&a.remove(),this._picker._colorInput.value=e===`foreColor`?`#000000`:`#ffff00`,this._picker.style.display=`block`;let o=this._picker.offsetWidth,s=this._picker.offsetHeight,c=this._el.getBoundingClientRect(),l=c.top-s-6;l<8&&(l=c.bottom+6);let u=t.getBoundingClientRect().left;u=Math.max(8,Math.min(u,globalThis.innerWidth-o-8)),this._picker.style.left=`${u}px`,this._picker.style.top=`${l}px`}_closeColorPicker(){this._picker&&(this._picker.style.display=`none`),this._pickerType=null}_applyColor(e,t){let n=this.context.layoutInfo?.editable;if(!n||!this._savedRange)return;n.focus();let r=globalThis.getSelection();r.removeAllRanges();try{r.addRange(this._savedRange.cloneRange())}catch{return}let i=e===`hiliteColor`?`hiliteColor`:e;!document.execCommand(i,!1,t)&&i===`hiliteColor`&&document.execCommand(`backColor`,!1,t),this.context.invoke(`editor.afterCommand`);let a=e===`hiliteColor`?`hiliteColor`:`foreColor`,o=(this._el?.querySelector(`[data-name="${a}"]`))?.querySelector(`.an-bubble-color-strip`);o&&(o.style.background=t===`transparent`?`transparent`:t),this._closeColorPicker(),this._syncActive()}_show(e){if(!this._el)return;let t=this._el;t.style.visibility=`hidden`,t.style.display=`flex`;let n=t.offsetWidth,r=t.offsetHeight,i=e.left+e.width/2-n/2,a=e.top-r-8;i=Math.max(8,Math.min(i,globalThis.innerWidth-n-8)),a<8&&(a=e.bottom+8);let o=document.querySelector(`.an-table-tooltip`);if(o&&o.style.display!==`none`){let t=o.getBoundingClientRect();a<t.bottom+8&&a+r>t.top-8&&(a=e.bottom+8,a+r>globalThis.innerHeight-8&&(a=t.bottom+8))}t.style.top=`${a}px`,t.style.left=`${i}px`,t.style.visibility=``,this._syncActive(),this._syncColorStrips(),this._visible=!0}_hide(){this._el&&(this._el.style.display=`none`,this._visible=!1,this._closeColorPicker())}_syncActive(){this._btnCache&&this._btnCache.forEach(e=>{let t=_a[e.dataset.name];e.classList.toggle(`an-active`,!!t?.())})}_syncColorStrips(){if(!this._el)return;let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0).startContainer;if(t.nodeType===Node.TEXT_NODE&&(t=t.parentElement),!t)return;let n=globalThis.getComputedStyle(t),r=this._el.querySelector(`[data-name="foreColor"]`)?.querySelector(`.an-bubble-color-strip`);r&&(r.style.background=n.color||`#000000`);let i=this._el.querySelector(`[data-name="hiliteColor"]`)?.querySelector(`.an-bubble-color-strip`);if(i){let e=n.backgroundColor;i.style.background=!e||e===`rgba(0, 0, 0, 0)`||e===`transparent`?`transparent`:e}}_onSelectionChange(){cancelAnimationFrame(this._rafId),this._rafId=requestAnimationFrame(()=>{if(this._contextMenuOpen||this._picker&&this._picker.style.display!==`none`)return;let e=globalThis.getSelection();if(!e||e.isCollapsed||!e.rangeCount){this._hide();return}if(!this.context.layoutInfo.editable.contains(e.anchorNode)){this._hide();return}if(this.context.options.readOnly){this._hide();return}let t=e.getRangeAt(0).getBoundingClientRect();if(!t||t.width===0){this._hide();return}this._show(t)})}_onMousedown(e){this._visible&&(this._el?.contains(e.target)||this._picker?.contains(e.target)||this.context.layoutInfo.editable.contains(e.target)||this._hide())}_onKeydown(e){e.key===`Escape`&&(this._picker&&this._picker.style.display!==`none`?this._closeColorPicker():this._visible&&this._hide())}_onContextMenu(){this._hide()}},enabled:e=>!!e.bubbleToolbar},{name:`mention`,Class:class{constructor(e){this.context=e,this._dropdown=null,this._query=``,this._debounceTimer=null,this._activeIndex=-1,this._items=[],this._open=!1,this._triggerNode=null,this._triggerOffset=0,this._caretRect=null,this._disposers=[]}initialize(){let e=this.context.options.mention;if(!e||typeof e.onSearch!=`function`)return this;this._cfg={trigger:e.trigger||`@`,minChars:e.minChars??0,maxResults:e.maxResults??8,debounce:e.debounce??200,onSearch:e.onSearch,onInsert:e.onInsert||null,onError:e.onError||null,mentionClass:e.mentionClass||`an-mention`,allowSpaces:e.allowSpaces||!1},this._buildDropdown();let t=this.context.layoutInfo.editable,n=v(t,`keydown`,e=>this._onKeydown(e)),r=v(t,`input`,()=>this._onInput()),i=v(document,`click`,e=>this._onDocClick(e));return this._disposers.push(n,r,i),this}destroy(){clearTimeout(this._debounceTimer),this._dropdown?.remove(),this._dropdown=null,this._disposers.forEach(e=>e()),this._disposers=[]}_buildDropdown(){let e=document.createElement(`div`);e.className=`an-mention-dropdown`,e.setAttribute(`role`,`listbox`),e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{let t=e.target?.closest(`.an-mention-item`);t&&this._select(+t.dataset.index)}),e.addEventListener(`mousemove`,e=>{let t=e.target?.closest(`.an-mention-item`);t&&this._highlightItem(+t.dataset.index)}),x(this.context).appendChild(e),this._dropdown=e}_renderItems(e){let t=this._dropdown;this._items=e.slice(0,this._cfg.maxResults),this._activeIndex=this._items.length>0?0:-1;let n=document.createDocumentFragment();this._items.forEach((e,t)=>{let r=document.createElement(`div`);if(r.className=`an-mention-item`,r.setAttribute(`role`,`option`),r.dataset.index=String(t),e.avatar){let t=document.createElement(`img`);t.src=e.avatar,t.className=`an-mention-avatar`,t.alt=``,r.appendChild(t)}let i=document.createElement(`span`);i.textContent=e.label,r.appendChild(i),n.appendChild(r)}),t.innerHTML=``,t.appendChild(n),this._highlightItem(this._activeIndex)}_highlightItem(e){this._dropdown&&(this._dropdown.querySelectorAll(`.an-mention-item`).forEach((t,n)=>{t.classList.toggle(`an-mention-active`,n===e)}),this._activeIndex=e)}_positionDropdown(){let e=this._dropdown,t=this._caretRect;if(!t||t.height===0)return;e.style.visibility=`hidden`,e.style.display=`block`;let n=e.offsetHeight,r=e.offsetWidth,i=t.bottom+4,a=t.left;t.bottom+n+8>globalThis.innerHeight&&(i=t.top-n-4),a=Math.max(8,Math.min(a,globalThis.innerWidth-r-8)),e.style.top=`${i}px`,e.style.left=`${a}px`,e.style.visibility=``}_showDropdown(){this._open=!0,this._positionDropdown()}_hideDropdown(){this._dropdown&&(this._dropdown.style.display=`none`),this._open=!1,this._items=[],this._activeIndex=-1,this._triggerNode=null,this._caretRect=null,this._query=``}_captureCaretRect(){if(this._triggerNode?.isConnected)try{let e=document.createRange(),t=Math.min(this._triggerOffset+1,this._triggerNode.textContent.length);e.setStart(this._triggerNode,this._triggerOffset),e.setEnd(this._triggerNode,t);let n=e.getBoundingClientRect();if(n.height>0){this._caretRect=n;return}}catch{}let e=globalThis.getSelection();if(!e?.rangeCount)return;let t=e.getRangeAt(0).getClientRects();t.length>0&&(this._caretRect=t[t.length-1])}_getQueryAtCursor(){let e=globalThis.getSelection();if(!e?.rangeCount)return null;let t=e.getRangeAt(0);if(!t.collapsed)return null;let n=t.startContainer;if(n.nodeType!==Node.TEXT_NODE)return null;let r=n.textContent.slice(0,t.startOffset),i=this._cfg.trigger,a=r.lastIndexOf(i);if(a===-1)return null;let o=r.slice(a+i.length);return!this._cfg.allowSpaces&&/\s/.test(o)||o.length<this._cfg.minChars?null:(this._triggerNode=n,this._triggerOffset=a,o)}_onInput(){if(!this._cfg)return;let e=this._getQueryAtCursor();if(e===null){this._hideDropdown();return}this._captureCaretRect(),this._query=e,clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{let e=e=>{if(!Array.isArray(e)||e.length===0){this._hideDropdown();return}this._renderItems(e),this._showDropdown()},t;try{t=this._cfg.onSearch(this._query,e)}catch(e){this._hideDropdown(),typeof this._cfg.onError==`function`&&this._cfg.onError(e);return}t&&typeof t.then==`function`&&t.then(e).catch(e=>{this._hideDropdown(),typeof this._cfg.onError==`function`&&this._cfg.onError(e)})},this._cfg.debounce)}_onKeydown(e){if(!(!this._cfg||!this._open)){if(e.key===`ArrowDown`){e.preventDefault();let t=(this._activeIndex+1)%this._items.length;this._highlightItem(t)}else if(e.key===`ArrowUp`){e.preventDefault();let t=(this._activeIndex-1+this._items.length)%this._items.length;this._highlightItem(t)}else e.key===`Enter`||e.key===`Tab`?this._activeIndex>=0&&(e.preventDefault(),this._select(this._activeIndex)):e.key===`Escape`&&this._hideDropdown()}}_onDocClick(e){this._open&&(this._dropdown?.contains(e.target)||this._hideDropdown())}_select(e){let t=this._items[e];if(!t)return;if(this._triggerNode){let e=this._triggerNode;e.textContent=e.textContent.slice(0,this._triggerOffset)+e.textContent.slice(this._triggerOffset+this._cfg.trigger.length+this._query.length);let t=globalThis.getSelection(),n=document.createRange();n.setStart(e,this._triggerOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}let n;typeof this._cfg.onInsert==`function`&&(n=this._cfg.onInsert(t)),n||=`<span class="${this._cfg.mentionClass}" data-mention-id="${t.id}" contenteditable="false">@${t.label}</span>`,this.context.invoke(`editor.insertHTML`,n+`&#8203;`),this._hideDropdown(),this.context.triggerEvent(`change`,this.context.getHTML())}},enabled:e=>!!e.mention},{name:`slashMenu`,Class:class{constructor(e){this.context=e,this.options=e.options,this._disposers=[],this._menu=null,this._filtered=[],this._activeIndex=-1,this._open=!1,this._query=``,this._textNode=null,this._triggerOffset=0,this._caretRect=null}initialize(){if(this.options.slashMenu===!1)return this;let e=this.context.layoutInfo.editable,t=v(e,`input`,()=>this._onInput()),n=v(e,`keydown`,e=>this._onKeydown(e)),r=v(document,`click`,e=>this._onDocClick(e));return this._disposers.push(t,n,r),this}destroy(){this._menu?.remove(),this._menu=null,this._disposers.forEach(e=>e()),this._disposers=[]}_commands(){let e=this.context.locale.slashMenu,t=this.context,n=[{id:`h1`,label:e.heading1,keywords:`h1 heading title`,run:()=>t.invoke(`editor.formatBlock`,`h1`)},{id:`h2`,label:e.heading2,keywords:`h2 heading subtitle`,run:()=>t.invoke(`editor.formatBlock`,`h2`)},{id:`h3`,label:e.heading3,keywords:`h3 heading`,run:()=>t.invoke(`editor.formatBlock`,`h3`)},{id:`ul`,label:e.bulletList,keywords:`ul bullet list unordered`,run:()=>t.invoke(`editor.insertUL`)},{id:`ol`,label:e.numberedList,keywords:`ol numbered list ordered`,run:()=>t.invoke(`editor.insertOL`)},{id:`checklist`,label:e.checklist,keywords:`checklist todo checkbox task`,run:()=>t.invoke(`editor.toggleChecklist`)},{id:`quote`,label:e.blockquote,keywords:`quote blockquote`,run:()=>t.invoke(`editor.formatBlock`,`blockquote`)},{id:`code`,label:e.codeBlock,keywords:`code pre block`,run:()=>t.invoke(`editor.formatBlock`,`pre`)},{id:`hr`,label:e.horizontalRule,keywords:`hr divider rule line`,run:()=>t.invoke(`editor.insertHr`)},{id:`table`,label:e.table,keywords:`table grid`,run:()=>t.invoke(`editor.insertTable`,3,3)},{id:`image`,label:e.image,keywords:`image picture photo upload`,run:()=>t.invoke(`imageDialog.show`)}],r=(this.options.slashCommands||[]).map(e=>({id:e.id,label:e.label||e.id,keywords:e.keywords||``,run:()=>e.run(t)}));return[...n,...r]}refresh(){this._open&&this._filterAndRender()}_buildMenu(){let e=document.createElement(`div`);return e.className=`an-slash-menu`,e.setAttribute(`role`,`listbox`),e.style.display=`none`,e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{let t=e.target?.closest(`.an-slash-menu-item`);t&&this._select(+t.dataset.index)}),e.addEventListener(`mousemove`,e=>{let t=e.target?.closest(`.an-slash-menu-item`);t&&this._highlight(+t.dataset.index)}),x(this.context).appendChild(e),this._menu=e,e}_renderItems(){this._menu||this._buildMenu();let e=this._menu,t=this.context.locale.slashMenu;if(this._filtered.length===0){e.innerHTML=``;let n=document.createElement(`div`);n.className=`an-slash-menu-empty`,n.textContent=t.noResults,e.appendChild(n),this._activeIndex=-1;return}let n=document.createDocumentFragment();this._filtered.forEach((e,t)=>{let r=document.createElement(`div`);r.className=`an-slash-menu-item`,r.setAttribute(`role`,`option`),r.id=`an-slash-option-${e.id}`,r.dataset.index=String(t),r.textContent=e.label,n.appendChild(r)}),e.innerHTML=``,e.appendChild(n),this._highlight(0)}_highlight(e){this._menu&&(this._menu.querySelectorAll(`.an-slash-menu-item`).forEach((t,n)=>{let r=n===e;t.classList.toggle(`an-slash-menu-active`,r),t.setAttribute(`aria-selected`,String(r)),r&&this._menu.setAttribute(`aria-activedescendant`,t.id)}),this._activeIndex=e)}_position(){let e=this._menu,t=this._caretRect;if(!e||!t||t.height===0)return;e.style.visibility=`hidden`,e.style.display=`block`;let n=e.offsetHeight,r=e.offsetWidth,i=t.bottom+4,a=t.left;t.bottom+n+8>globalThis.innerHeight&&(i=t.top-n-4),a=Math.max(8,Math.min(a,globalThis.innerWidth-r-8)),e.style.top=`${i}px`,e.style.left=`${a}px`,e.style.visibility=``}_open_(){this._open=!0,this._filterAndRender(),this._position()}_close(){this._menu&&(this._menu.style.display=`none`),this._open=!1,this._filtered=[],this._activeIndex=-1,this._menu?.removeAttribute(`aria-activedescendant`),this._textNode=null,this._caretRect=null,this._query=``}_isBlock(e){if(e.nodeType!==Node.ELEMENT_NODE)return!1;let t=globalThis.getComputedStyle(e).display;return t===`block`||t===`list-item`||t===`table-cell`}_getTriggerContext(){let e=globalThis.getSelection();if(!e?.rangeCount)return null;let t=e.getRangeAt(0);if(!t.collapsed)return null;let n=this.context.layoutInfo.editable;if(!n.contains(t.startContainer)||t.startContainer.nodeType!==Node.TEXT_NODE)return null;let r=t.startContainer.parentNode;for(;r&&r!==n&&!this._isBlock(r);)r=r.parentNode;if(!r||r===n)return null;let i=r.textContent||``,a=document.createRange();a.setStart(r,0),a.setEnd(t.startContainer,t.startOffset);let o=a.toString(),s=/^\/(\S*)$/.exec(o);return!s||i.length>o.length?null:{query:s[1],textNode:t.startContainer,triggerOffset:t.startOffset-s[0].length}}_captureCaretRect(e,t){try{let n=document.createRange(),r=Math.min(t+1,e.textContent.length);n.setStart(e,t),n.setEnd(e,r);let i=n.getBoundingClientRect();if(i.height>0)return i}catch{}let n=globalThis.getSelection();if(!n?.rangeCount)return null;let r=n.getRangeAt(0).getClientRects();return r.length>0?r[r.length-1]:null}_filterAndRender(){let e=this._query.toLowerCase();this._filtered=e?this._commands().filter(t=>t.keywords.includes(e)||t.label.toLowerCase().includes(e)):this._commands(),this._renderItems()}_onInput(){let e=this._getTriggerContext();if(!e){this._open&&this._close();return}this._textNode=e.textNode,this._triggerOffset=e.triggerOffset,this._query=e.query,this._caretRect=this._captureCaretRect(e.textNode,e.triggerOffset),this._open?(this._filterAndRender(),this._position()):this._open_()}_onKeydown(e){if(this._open){if(e.key===`ArrowDown`){if(e.preventDefault(),this._filtered.length===0)return;this._highlight((this._activeIndex+1)%this._filtered.length)}else if(e.key===`ArrowUp`){if(e.preventDefault(),this._filtered.length===0)return;this._highlight((this._activeIndex-1+this._filtered.length)%this._filtered.length)}else e.key===`Enter`||e.key===`Tab`?this._activeIndex>=0&&(e.preventDefault(),this._select(this._activeIndex)):e.key===`Escape`&&(e.preventDefault(),this._close())}}_onDocClick(e){this._open&&(this._menu?.contains(e.target)||this._close())}_deleteTriggerText(){let e=this._textNode;if(!e?.isConnected)return;e.textContent=e.textContent.slice(0,this._triggerOffset)+e.textContent.slice(this._triggerOffset+1+this._query.length);let t=globalThis.getSelection();if(!t)return;let n=document.createRange();n.setStart(e,this._triggerOffset),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}_makeTriggerRemover(){let e=this._textNode,t=this._triggerOffset,n=this._query;return()=>{if(!e?.isConnected)return;let r=e.textContent.slice(0,t),i=e.textContent.slice(t+1+n.length);e.textContent=r+i;let a=globalThis.getSelection();if(!a)return;let o=document.createRange();o.setStart(e,t),o.collapse(!0),a.removeAllRanges(),a.addRange(o)}}_select(e){let t=this._filtered[e];if(t){if(t.id===`image`){let e=this._makeTriggerRemover();this._close(),this.context.invoke(`imageDialog.show`,{beforeInsert:e});return}this._deleteTriggerText(),this._close(),t.run()}}},enabled:e=>e.slashMenu!==!1}],ba=`3.0.1`,xa={...j},$=new WeakMap,Sa={create(e,t={}){let n=Ca(e).map(e=>{if($.has(e))return $.get(e);let n=new _n(e,t);return n._releaseInstance=()=>{$.get(e)===n&&$.delete(e)},n.initialize(),$.set(e,n),n});return n.length===1?n[0]:n},destroy(e){Ca(e).forEach(e=>{let t=$.get(e);t&&(t.destroy(),$.delete(e))})},getInstance(e){let t=typeof e==`string`?document.querySelector(e):e;return t&&$.get(t)||null},get defaults(){return{...j}},setDefaults(e){Object.assign(j,e)},resetDefaults(){Object.keys(j).forEach(e=>delete j[e]),Object.assign(j,xa)},registerModule(e,t){un.set(e,t)},use(e,t={}){if(!e||typeof e.name!=`string`)throw TypeError("[AutumnNote] AutumnNote.use: plugin must have a string `name` property.");return gn.has(e.name)?(console.warn(`[AutumnNote] Plugin "${e.name}" already registered globally. Skipping.`),this):(Array.isArray(e.buttons)&&e.buttons.forEach(e=>ze(e)),gn.set(e.name,{plugin:e,options:t}),this)},hasPlugin(e){return gn.has(e)},registerButton(e){return ze(e),this},registerIcon(e,t){return Ge(e,t),this},registerLocale(e,t){return c(e,t),this},registerSlashCommand(e){if(!e?.id||typeof e.run!=`function`)throw TypeError(`[AutumnNote] Slash command requires an id and run(context) function.`);let t=j.slashCommands,n=t.findIndex(t=>t.id===e.id);return n>=0?t[n]=e:t.push(e),this},buttons:Lt,version:ba};function Ca(e){return typeof e==`string`?Array.from(document.querySelectorAll(e)):e instanceof Element?[e]:e instanceof NodeList||Array.isArray(e)?Array.from(e):[]}return fn(ya),Sa});
@@ -5126,7 +5126,7 @@ var Oi = [
5126
5126
  }
5127
5127
  }
5128
5128
  }
5129
- ], ki = "3.0.0";
5129
+ ], ki = "3.0.1";
5130
5130
  //#endregion
5131
5131
  //#region src/js/core/lists.js
5132
5132
  function Ai(e) {