@jackuait/blok 0.12.0 → 0.12.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.
Files changed (46) hide show
  1. package/dist/blok.cjs +1 -1
  2. package/dist/blok.iife.js +5 -5
  3. package/dist/blok.mjs +2 -2
  4. package/dist/chunks/{blok-Cxcy7G7v.mjs → blok-B4ebnd6l.mjs} +58 -6
  5. package/dist/chunks/{blok-qY4LDF7A.cjs → blok-k8Yo4v2F.cjs} +4 -4
  6. package/dist/chunks/{constants-Bhk7u_hm.mjs → constants-BsyOzSoJ.mjs} +1 -1
  7. package/dist/chunks/{constants-BYCpx4v_.cjs → constants-DGaNl2M0.cjs} +1 -1
  8. package/dist/chunks/tools-CPzDYrWa.cjs +115 -0
  9. package/dist/chunks/{tools-Bc4e0xmz.mjs → tools-JNr7LO1_.mjs} +888 -883
  10. package/dist/full.cjs +1 -1
  11. package/dist/full.mjs +3 -3
  12. package/dist/react.cjs +1 -1
  13. package/dist/react.mjs +2 -2
  14. package/dist/tools.cjs +1 -1
  15. package/dist/tools.mjs +2 -2
  16. package/package.json +2 -2
  17. package/src/components/block-tunes/block-tune-copy-link.ts +2 -2
  18. package/src/components/modules/paste/index.ts +154 -2
  19. package/src/styles/colors.css +57 -0
  20. package/src/styles/database.css +3 -3
  21. package/src/styles/image.css +50 -140
  22. package/src/styles/main.css +148 -6
  23. package/src/tools/callout/index.ts +0 -1
  24. package/src/tools/code/index.ts +19 -2
  25. package/src/tools/database/database-board-view.ts +1 -1
  26. package/src/tools/database/database-card-drawer.ts +3 -2
  27. package/src/tools/database/database-list-view.ts +1 -1
  28. package/src/tools/database/database-model.ts +15 -3
  29. package/src/tools/database/database-property-type-popover.ts +14 -10
  30. package/src/tools/database/database-tab-bar.ts +9 -3
  31. package/src/tools/database/database-view-popover.ts +15 -7
  32. package/src/tools/database/index.ts +0 -2
  33. package/src/tools/header/index.ts +6 -6
  34. package/src/tools/image/alt-popover.css +6 -6
  35. package/src/tools/image/crop-editor.css +34 -34
  36. package/src/tools/image/crop-modal.css +1 -1
  37. package/src/tools/image/empty-state.ts +3 -3
  38. package/src/tools/image/error-state.ts +9 -9
  39. package/src/tools/image/index.ts +2 -3
  40. package/src/tools/image/ui.ts +18 -13
  41. package/src/tools/list/style-config.ts +0 -3
  42. package/src/tools/paragraph/index.ts +0 -1
  43. package/src/tools/quote/index.ts +0 -1
  44. package/src/tools/table/index.ts +0 -1
  45. package/src/tools/toggle/index.ts +0 -1
  46. package/dist/chunks/tools-DaOdAh89.cjs +0 -115
@@ -0,0 +1,115 @@
1
+ const e=require(`./chunk-Kud-AIAt.cjs`),t=require(`./constants-DGaNl2M0.cjs`),n=require(`./objectSpread2-iNkE6aJh.cjs`),r=require(`./tw-CjHZc17C.cjs`),i=require(`./lightweight-i18n-T_Nc45AF.cjs`);var a=e=>{if(!e||!e.includes(`data-blok-fake-background`))return e;let t=document.createElement(`div`);return t.innerHTML=e,t.querySelectorAll(`[data-blok-fake-background="true"]`).forEach(e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}}),t.innerHTML},o=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-placeholder)]`,`data-[blok-empty=true]:before:pointer-events-none`,`data-[blok-empty=true]:before:text-gray-text`,`data-[blok-empty=true]:before:cursor-text`,`data-[blok-empty=true]:before:content-[attr(data-placeholder)]`],s=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-blok-placeholder-active)]`,`data-[empty=true]:before:pointer-events-none`,`data-[empty=true]:before:text-gray-text`,`data-[empty=true]:before:cursor-text`,`data-[empty=true]:before:content-[attr(data-blok-placeholder-active)]`],c=[`empty:focus:before:pointer-events-none`,`empty:focus:before:text-gray-text`,`empty:focus:before:cursor-text`,`empty:focus:before:content-[attr(data-blok-placeholder-active)]`,`[&[data-empty=true]:focus]:before:pointer-events-none`,`[&[data-empty=true]:focus]:before:text-gray-text`,`[&[data-empty=true]:focus]:before:cursor-text`,`[&[data-empty=true]:focus]:before:content-[attr(data-blok-placeholder-active)]`],l=[`empty:in-data-[blok-empty=true]:before:pointer-events-none`,`empty:in-data-[blok-empty=true]:before:text-gray-text`,`empty:in-data-[blok-empty=true]:before:cursor-text`,`empty:in-data-[blok-empty=true]:before:content-[attr(data-blok-placeholder-active)]`,`[[data-blok-empty=true]_&[data-empty=true]]:before:pointer-events-none`,`[[data-blok-empty=true]_&[data-empty=true]]:before:text-gray-text`,`[[data-blok-empty=true]_&[data-empty=true]]:before:cursor-text`,`[[data-blok-empty=true]_&[data-empty=true]]:before:content-[attr(data-blok-placeholder-active)]`],u=e=>{let t=e.innerHTML.trim();return t===``||t===`<br>`},d=e=>{e.innerHTML===`<br>`&&(e.innerHTML=``);let t=window.getSelection();if(!t)return;let n=document.createRange();n.selectNodeContents(e),n.collapse(!0),t.removeAllRanges(),t.addRange(n)},f=e=>{u(e)&&d(e)},p=(e,t,n=`data-placeholder`)=>{e.setAttribute(n,t==null?``:t);let r=()=>f(e);return e.addEventListener(`focus`,r),()=>{e.removeEventListener(`focus`,r),e.removeAttribute(n)}},m,h=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},g=class e{static get DEFAULT_PLACEHOLDER(){return`tools.paragraph.placeholder`}constructor({data:t,config:n,api:r,readOnly:i}){var a,o,s;this.placeholderCleanup=null,this.api=r,this.readOnly=i,this.onKeyUp=this.onKeyUp.bind(this),this._placeholder=(a=n==null?void 0:n.placeholder)==null?e.DEFAULT_PLACEHOLDER:a,this._data=t==null?{text:``}:t,this._element=null,this._preserveBlank=(o=n==null?void 0:n.preserveBlank)==null?!1:o,this._styles=(s=n==null?void 0:n.styles)==null?{}:s}onKeyUp(e){if(e.code!==`Backspace`&&e.code!==`Delete`||!this._element)return;let{textContent:t}=this._element;t===``&&(this._element.innerHTML=``)}buildInlineStyles(){let e={};return this._styles.size&&(e.fontSize=this._styles.size),this._styles.lineHeight&&(e.lineHeight=this._styles.lineHeight),this._styles.marginTop&&(e.marginTop=this._styles.marginTop),this._styles.marginBottom&&(e.marginBottom=this._styles.marginBottom),e}drawView(){let n=document.createElement(`DIV`);n.className=r.n(this.api.styles.block,e.WRAPPER_CLASSES,c,l),n.setAttribute(t.Pr.tool,`paragraph`),n.contentEditable=`false`;let i=this.buildInlineStyles();return Object.keys(i).length>0&&Object.assign(n.style,i),this._data.text?n.innerHTML=this._data.text:this.readOnly&&(n.innerHTML=`<br>`),this.readOnly||(n.contentEditable=`true`,n.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(n,this.api.i18n.t(this._placeholder),`data-blok-placeholder-active`)),n}render(){return this._element||(this._element=this.drawView()),this._element}setReadOnly(e){this._element&&(this.readOnly=e,e?(this._element.contentEditable=`false`,this._element.removeEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null),u(this._element)&&(this._element.innerHTML=`<br>`)):(this._element.contentEditable=`true`,this._element.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(this._element,this.api.i18n.t(this._placeholder),`data-blok-placeholder-active`),this._element.innerHTML===`<br>`&&(this._element.innerHTML=``)))}merge(e){if(!this._element)return;this._data.text+=e.text;let t=h(e.text);this._element.appendChild(t),this._element.normalize()}validate(e){return!(e.text.trim()===``&&!this._preserveBlank)}save(e){return{text:a(e.innerHTML)}}onPaste(e){let t=e.detail;`data`in t&&(this._data={text:t.data.innerHTML},this._element&&(this._element.innerHTML=this._data.text||``))}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,img:{src:!0,style:!0},p:!0,ul:!0,li:!0}}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`P`]}}static get toolbox(){return{icon:t.Qt,titleKey:`text`,searchTerms:[`p`,`paragraph`,`plain`],searchTermKeys:[`paragraph`,`plain`]}}};m=g,m.WRAPPER_CLASSES=[`leading-[1.5]`,`outline-hidden`,`mt-px`,`mb-px`,`[&>p:first-of-type]:mt-0`,`[&>p:last-of-type]:mb-0`];var _=e=>{let{data:n,readOnly:r,isOpen:i,keydownHandler:a,onArrowClick:o,onBodyPlaceholderClick:s}=e,c=document.createElement(`div`);c.className=t.a,c.setAttribute(t.Pr.tool,t.p),c.setAttribute(t.u.toggleOpen,String(i)),c.setAttribute(t.u.toggleEmpty,`true`);let l=document.createElement(`div`);l.className=t.f;let u=v(i,o,{},e.ariaLabels),d=b(n,r,a);l.appendChild(u),l.appendChild(d);let f=y(s,e.bodyPlaceholderText),p=document.createElement(`div`);return p.className=t.d,p.setAttribute(t.u.toggleChildren,``),p.setAttribute(t.Pr.nestedBlocks,``),p.setAttribute(`data-blok-mutation-free`,`true`),p.id=`toggle-children-${Date.now()}-${Math.random().toString(36).slice(2)}`,u.setAttribute(`aria-controls`,p.id),c.appendChild(l),c.appendChild(f),c.appendChild(p),{wrapper:c,arrowElement:u,contentElement:d,bodyPlaceholderElement:f,childContainerElement:p}},v=(e,n,r={},i={collapse:`Collapse`,expand:`Expand`})=>{let a=document.createElement(`span`);a.className=t.i,a.setAttribute(t.u.toggleArrow,``),a.setAttribute(t.Pr.mutationFree,`true`),a.setAttribute(`role`,`button`),a.setAttribute(`tabindex`,`0`),a.setAttribute(`aria-label`,e?i.collapse:i.expand),a.setAttribute(`aria-expanded`,String(e)),r.contentEditableFalse===!0&&(a.contentEditable=`false`),a.innerHTML=t.r;let o=a.querySelector(`svg`);return o&&(o.style.transition=`transform 200ms ease-in-out`,e&&(o.style.transform=`rotate(90deg)`)),n&&(a.addEventListener(`click`,e=>{e.stopPropagation(),n()}),a.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),n())})),a},y=(e,n)=>{let r=document.createElement(`div`);return r.className=t.s,r.setAttribute(t.u.toggleBodyPlaceholder,``),r.setAttribute(`data-blok-mutation-free`,`true`),r.textContent=n,e&&r.addEventListener(`click`,e),r},b=(e,n,i)=>{let a=document.createElement(`div`);return a.className=r.n(t.c,s,l),a.setAttribute(t.u.toggleContent,``),a.contentEditable=n?`false`:`true`,a.innerHTML=e.text,i&&a.addEventListener(`keydown`,i),a},x=(e,n)=>{for(let r of n)r.holder.parentElement!==e&&(r.holder.closest(`[${t.Pr.nestedBlocks}]`)||e.appendChild(r.holder))},S=(e,n)=>{var r;if(e===null)return;let i=((r=n==null?void 0:n.textContent)==null?``:r).trim()===``;e.setAttribute(t.u.toggleEmpty,String(i))},C=e=>{let t=_(e);return t.contentElement&&p(t.contentElement,e.placeholder,`data-blok-placeholder-active`),t},w=(e,n,r,i={collapse:`Collapse`,expand:`Expand`})=>{let a=e.querySelector(`svg`);a&&(a.style.transform=r?`rotate(90deg)`:``),e.setAttribute(`aria-label`,r?i.collapse:i.expand),e.setAttribute(`aria-expanded`,String(r)),n.setAttribute(t.u.toggleOpen,String(r))},T=(e,t,n,r,i)=>{let a=e.blocks.getChildren(t);!n&&r&&i&&r.contains(document.activeElement)&&i.focus(),r&&x(r,a);for(let e of a)n?e.holder.classList.remove(`hidden`):e.holder.classList.add(`hidden`);r&&(n?r.removeAttribute(`aria-hidden`):r.setAttribute(`aria-hidden`,`true`))},E=(e,t,n,r,i)=>{if(e===null)return;if(i){e.classList.add(`hidden`);return}let a=t.blocks.getChildren(n);r&&a.length===0?e.classList.remove(`hidden`):e.classList.add(`hidden`)},D=async e=>{var n;let{api:r,blockId:i,data:a,getContentElement:o,syncContentFromDOM:s,isOpen:c}=e;if(s(),i===void 0)return;let l=o(),u=window.getSelection();if(!l||!u||u.rangeCount===0)return;let{beforeContent:d,afterContent:f}=A(l,u.getRangeAt(0)),p=(n=r.blocks.getBlockIndex(i))==null?r.blocks.getCurrentBlockIndex():n;if(c&&f===``){let e=k(r,i,p),t=r.blocks.insertInsideParent(i,e);r.caret.setToBlock(t.id,`start`);return}r.blocks.splitBlock(i,{text:d},t.p,{text:f},p+1),a.text=d},O=async(e,n)=>{let{api:r,blockId:i,data:a,getContentElement:o,syncContentFromDOM:s}=e;if(s(),i===void 0)return;let c=o();if(!c||!t.Tn(c))return;let l=a.text;l===``&&(n.preventDefault(),await r.blocks.convert(i,`paragraph`,{text:l}))},k=(e,t,n)=>{var r;let i=e.blocks.getChildren(t);if(i.length===0)return n+1;let a=i[i.length-1],o=(r=e.blocks.getBlockIndex(a.id))==null?n:r;return k(e,a.id,o)},A=(e,t)=>{if(!e.lastChild)return{beforeContent:``,afterContent:``};let n=document.createRange();n.setStart(e,0),n.setEnd(t.startContainer,t.startOffset);let r=document.createRange();r.setStart(t.endContainer,t.endOffset),r.setEndAfter(e.lastChild);let i=document.createElement(`div`);i.appendChild(n.cloneContents());let a=document.createElement(`div`);return a.appendChild(r.cloneContents()),{beforeContent:i.innerHTML,afterContent:a.innerHTML}},j=async e=>{var t;let{api:n,blockId:r,getContentElement:i,syncContentFromDOM:a,isOpen:o,currentLevel:s}=e;if(a(),r===void 0)return;let c=i(),l=window.getSelection();if(!c||!l||l.rangeCount===0)return;let{beforeContent:u,afterContent:d}=A(c,l.getRangeAt(0)),f=(t=n.blocks.getBlockIndex(r))==null?n.blocks.getCurrentBlockIndex():t;if(o&&d===``){let e=k(n,r,f),t=n.blocks.insertInsideParent(r,e);n.caret.setToBlock(t.id,`start`);return}n.blocks.splitBlock(r,{text:u,level:s,isToggleable:!0},`header`,{text:d,level:s,isToggleable:!0},f+1)},M=async(e,n)=>{let{api:r,blockId:i,getText:a,getContentElement:o,syncContentFromDOM:s,currentLevel:c}=e;if(s(),i===void 0)return;let l=o();if(!l||!t.Tn(l))return;let u=a();u===``&&(n.preventDefault(),await r.blocks.convert(i,`header`,{text:u,level:c}))},N,ee=class e{constructor({data:e,config:t,api:n,readOnly:r,block:i}){var a;this.placeholderCleanup=null,this._arrowElement=null,this._wrapper=null,this._headerRow=null,this._childContainerElement=null,this._bodyPlaceholderElement=null,this.handleChildContainerInput=()=>{S(this._wrapper,this._childContainerElement)},this.handleKeyDown=e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}e.key===`Backspace`&&M(this.createKeyboardContext(),e)},this.handleBlockChanged=e=>{this.isBlockChangedPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)&&this.updateBodyPlaceholderVisibility()},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this._isOpen=(a=this._data.isOpen)==null?!0:a,this._element=this.getTag(),i&&(this.blockId=i.id),!r&&this._data.isToggleable&&this.api.events.on(`block changed`,this.handleBlockChanged)}get _CSS(){return{block:this.api.styles.block,wrapper:``}}isHeaderData(e){return typeof e==`object`&&!!e&&`text`in e}normalizeData(e){if(!this.isHeaderData(e))return{text:``,level:this.defaultLevel.number};let n=parseInt(String(e.level)),r=e.level!==void 0&&!isNaN(n),i={text:e.text||``,level:r?n:this.defaultLevel.number};if(e.isToggleable===!0&&(i.isToggleable=!0),typeof e.isOpen==`boolean`&&(i.isOpen=e.isOpen),i.text){let e=document.createElement(`div`);e.innerHTML=i.text;let n=e.querySelector(`[${t.u.toggleArrow}]`);n&&(n.remove(),i.text=e.innerHTML)}return i}render(){return this._data.isToggleable?(this._wrapper=this.buildWrapper(),this._wrapper):this._element}rendered(){this._data.isToggleable&&(this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}removed(){this.api.events.off(`block changed`,this.handleBlockChanged),this._element.removeEventListener(`keydown`,this.handleKeyDown)}setReadOnly(e){if(this._element)if(this.readOnly=e,e)this._element.contentEditable=`false`,this._data.isToggleable&&this._element.removeEventListener(`keydown`,this.handleKeyDown),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null);else{this._element.contentEditable=`true`,this._data.isToggleable&&this._element.addEventListener(`keydown`,this.handleKeyDown);let e=this.api.i18n.t(this.currentLevel.nameKey),t=this.resolvePlaceholderText(e);this.placeholderCleanup=p(this._element,t)}}expand(){!this._data.isToggleable||this._isOpen||(this._isOpen=!0,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}collapse(){!this._data.isToggleable||!this._isOpen||(this._isOpen=!1,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}renderSettings(){return this.levels.map(e=>{let t=this.api.i18n.t(e.nameKey),n=t===e.nameKey?e.name:t;return{icon:e.icon,title:n,onActivate:()=>this.setLevel(e.number),closeOnActivate:!0,isActive:this.currentLevel.number===e.number,dataset:{"blok-header-level":String(e.number)}}})}setLevel(e){this.data={level:e,text:this.data.text,isToggleable:this._data.isToggleable}}merge(e){let n=document.createElement(`div`);n.innerHTML=e.text;let r=n.querySelector(`[${t.u.toggleArrow}]`);r&&r.remove(),this._element.insertAdjacentHTML(`beforeend`,n.innerHTML)}validate(e){return typeof e.text==`string`}setData(e){return this._data=this.normalizeData(e),typeof e.text==`string`&&(this._element.innerHTML=e.text),this._data.isToggleable&&typeof this._data.isOpen==`boolean`&&(this._isOpen=this._data.isOpen,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()),!0}save(e){let t={text:this._element.innerHTML,level:this.currentLevel.number};return this._data.isToggleable===!0&&(t.isToggleable=!0,t.isOpen=this._isOpen),t}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{level:!1,text:{},isToggleable:!1,isOpen:!1}}static get isReadOnlySupported(){return!0}get data(){return this._data.text=this._element.innerHTML,this._data.level=this.currentLevel.number,this._data}set data(n){if(this._data=this.normalizeData(n),n.level!==void 0&&this._element.parentNode){this._element.removeEventListener(`keydown`,this.handleKeyDown);let e=this.getTag();e.innerHTML=this._element.innerHTML,this._element.parentNode.replaceChild(e,this._element),this._element=e}if(n.text!==void 0&&(this._element.innerHTML=this._data.text||``),this._data.isToggleable){if(this._element.setAttribute(t.u.toggleOpen,String(this._isOpen)),this._element.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o,`pl-8`),!this._wrapper)this.createToggleWrapper();else if(!this._wrapper.querySelector(`[${t.u.toggleArrow}]`)){var i;let e=this.buildArrow();this._arrowElement=e,((i=this._headerRow)==null?this._wrapper:i).prepend(e)}}else if(this._element.removeAttribute(t.u.toggleOpen),this._element.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o),this._arrowElement=null,this._wrapper){let e=this._wrapper.parentNode;e&&e.replaceChild(this._element,this._wrapper),this._wrapper=null,this._headerRow=null}}resolvePlaceholderText(e){return this._settings.placeholder?this.api.i18n.t(this._settings.placeholder):e===this.currentLevel.nameKey?this.currentLevel.name:e}getTag(){let n=document.createElement(this.currentLevel.tag);n.innerHTML=this._data.text||``,n.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o,this._data.isToggleable?`pl-8`:``);let{inlineStyles:i}=this.currentLevel;i&&Object.assign(n.style,i),n.setAttribute(t.Pr.tool,`header`),n.contentEditable=this.readOnly?`false`:`true`,this._data.isToggleable&&n.setAttribute(t.u.toggleOpen,String(this._isOpen));let a=this.api.i18n.t(this.currentLevel.nameKey),s=this.resolvePlaceholderText(a);return this.readOnly?n.setAttribute(`data-placeholder`,s):this.placeholderCleanup=p(n,s),!this.readOnly&&this._data.isToggleable&&n.addEventListener(`keydown`,this.handleKeyDown),n}buildArrow(){let e=v(this._isOpen,()=>this.toggleOpen(),{},{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)});return e.classList.add(`absolute`,`left-0`,`top-1/2`,`-translate-y-1/2`),e}buildWrapper(){let e=document.createElement(`div`);e.setAttribute(t.u.toggleEmpty,`true`);let n=document.createElement(`div`);n.className=`relative`,this._headerRow=n;let i=this.buildArrow();this._arrowElement=i,n.appendChild(i),n.appendChild(this._element),e.appendChild(n);let a=document.createElement(`div`);a.className=r.n(t.s,`pl-8`),a.setAttribute(t.u.toggleBodyPlaceholder,``),a.setAttribute(`data-blok-mutation-free`,`true`),a.textContent=this.api.i18n.t(`tools.toggle.bodyPlaceholder`),this.readOnly||a.addEventListener(`click`,()=>this.handleBodyPlaceholderClick()),this._bodyPlaceholderElement=a,e.appendChild(a);let o=document.createElement(`div`);return o.className=`pl-8`,o.setAttribute(t.u.toggleChildren,``),o.setAttribute(t.Pr.nestedBlocks,``),o.setAttribute(`data-blok-mutation-free`,`true`),o.addEventListener(`input`,this.handleChildContainerInput),this._childContainerElement=o,e.appendChild(o),e}createToggleWrapper(){let e=this._element.parentNode;this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(t.u.toggleEmpty,`true`);let n=document.createElement(`div`);n.className=`relative`,this._headerRow=n;let r=this.buildArrow();this._arrowElement=r,n.appendChild(r),e&&e.replaceChild(this._wrapper,this._element),n.appendChild(this._element),this._wrapper.appendChild(n)}createKeyboardContext(){return{api:this.api,blockId:this.blockId,getText:()=>this._element.innerHTML,getContentElement:()=>this._element,syncContentFromDOM:()=>{this._data.text=this._element.innerHTML},isOpen:this._isOpen,currentLevel:this.currentLevel.number}}async handleEnter(){var e=this;await j(e.createKeyboardContext()),e.updateChildrenVisibility(),e.updateBodyPlaceholderVisibility()}toggleOpen(){this._isOpen=!this._isOpen,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}updateChildrenVisibility(){this.blockId!==void 0&&T(this.api,this.blockId,this._isOpen,this._childContainerElement,this._arrowElement)}updateBodyPlaceholderVisibility(){this.blockId!==void 0&&(E(this._bodyPlaceholderElement,this.api,this.blockId,this._isOpen,this.readOnly),S(this._wrapper,this._childContainerElement))}handleBodyPlaceholderClick(){var e;if(this.blockId===void 0)return;let t=this.api.blocks.getBlockIndex(this.blockId);if(t===void 0)return;let n=this.api.blocks.insertInsideParent(this.blockId,t+1);this.api.caret.setToBlock(n.id,`start`),(e=this._bodyPlaceholderElement)==null||e.classList.add(`hidden`)}isBlockChangedPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}get currentLevel(){let e=this.levels.find(e=>e.number===this._data.level);return e==null?this.defaultLevel:e}get defaultLevel(){return this._settings.defaultLevel?this.levels.find(e=>e.number===this._settings.defaultLevel)||(console.warn(`(ง'̀-'́)ง Heading Tool: the default level specified was not found in available levels`),this.levels[1]):this.levels[1]}get levels(){let t=this._settings.levelOverrides||{},n=e.DEFAULT_LEVELS.map(e=>{var n;let r=t[e.number]||{},i={};return r.size&&(i.fontSize=r.size),r.marginTop&&(i.marginTop=r.marginTop),r.marginBottom&&(i.marginBottom=r.marginBottom),{number:e.number,tag:((n=r.tag)==null?void 0:n.toUpperCase())||e.tag,nameKey:e.nameKey,name:r.name||e.name,icon:e.icon,styles:e.styles,inlineStyles:i}}),r=this._settings.levels;return r?n.filter(e=>r.includes(e.number)):n}onPaste(e){var t;let n=e.detail;if(!(`data`in n))return;let r=n.data,i=(t={H1:1,H2:2,H3:3,H4:4,H5:5,H6:6}[r.tagName])==null?this.defaultLevel.number:t;this.data={level:this._settings.levels?this._settings.levels.reduce((e,t)=>Math.abs(t-i)<Math.abs(e-i)?t:e):i,text:r.innerHTML}}static get pasteConfig(){return{tags:[`H1`,`H2`,`H3`,`H4`,`H5`,`H6`]}}static get toolbox(){let n=e.DEFAULT_LEVELS.map(e=>({icon:e.icon,title:e.name,titleKey:e.nameKey,name:`header-${e.number}`,data:{level:e.number},searchTerms:[`h${e.number}`,`title`,`header`,`heading`],searchTermKeys:[`title`,`header`,`heading`],shortcut:`#`.repeat(e.number)})),r={1:t.$t,2:t.en,3:t.tn},i=e.DEFAULT_LEVELS.filter(e=>e.number<=3).map(e=>({icon:r[e.number],title:`Toggle heading ${e.number}`,titleKey:`tools.header.toggleHeading${e.number}`,name:`toggle-header-${e.number}`,data:{level:e.number,isToggleable:!0},searchTerms:[`toggle`,`heading`,`h${e.number}`,`collapsible`],searchTermKeys:[`toggle`,`heading`,`collapsible`],shortcut:`>`+`#`.repeat(e.number)}));return[...n,...i]}};N=ee,N.BASE_STYLES=`py-[7px] px-[2px] m-0 leading-[1.3]! outline-hidden [&_p]:p-0! [&_p]:m-0! [&_div]:p-0! [&_div]:m-0!`,N.DEFAULT_LEVELS=[{number:1,tag:`H1`,nameKey:`tools.header.heading1`,name:`Heading 1`,icon:t.ct,styles:`text-3xl font-semibold mt-8 mb-px`},{number:2,tag:`H2`,nameKey:`tools.header.heading2`,name:`Heading 2`,icon:t.lt,styles:`text-2xl font-semibold mt-[26px] mb-px`},{number:3,tag:`H3`,nameKey:`tools.header.heading3`,name:`Heading 3`,icon:t.ut,styles:`text-xl font-semibold mt-5 mb-px`},{number:4,tag:`H4`,nameKey:`tools.header.heading4`,name:`Heading 4`,icon:t.dt,styles:`text-lg font-semibold mt-3 mb-px`},{number:5,tag:`H5`,nameKey:`tools.header.heading5`,name:`Heading 5`,icon:t.ft,styles:`text-base font-semibold mt-3 mb-px`},{number:6,tag:`H6`,nameKey:`tools.header.heading6`,name:`Heading 6`,icon:t.pt,styles:`text-sm font-semibold mt-3 mb-px`}];var te=`outline-hidden py-[7px] mt-[2px] mb-px`,ne=`outline-hidden pl-0.5 leading-[1.5] items-start`,re=`flex items-start pl-0.5`,ie=`mt-0.5 w-5 mr-2 h-5 cursor-pointer accent-current`,ae=`tools.list.placeholder`,oe=`list`,se={contentContainer:`list-content-container`,checklistContent:`list-checklist-content`},ce=(e,t)=>{let n=e;n._placeholder=t,Object.defineProperty(n,`getPlaceholder`,{value:()=>n._placeholder,writable:!1,enumerable:!0,configurable:!1})},le=e=>{let{data:t,keydownHandler:n,readOnly:r}=e,i=ue(e),a=t.style===`checklist`?fe(e):de(e);i.appendChild(a),!r&&n&&i.addEventListener(`keydown`,n);let o=a.querySelector(`[data-list-marker]`),s=a.querySelector(`input[type="checkbox"]`),c=t.style===`checklist`?a.querySelector(`[data-blok-testid="${se.checklistContent}"]`):a.querySelector(`[data-blok-testid="${se.contentContainer}"]`);return{wrapper:i,contentElement:c==null?a:c,markerElement:o,checkboxElement:s}},ue=e=>{var n;let{data:r}=e,i=document.createElement(`div`);return i.className=te,i.setAttribute(t.Pr.tool,oe),i.setAttribute(`data-list-style`,r.style),i.setAttribute(`data-list-depth`,String((n=r.depth)==null?0:n)),r.start!==void 0&&r.start!==1&&i.setAttribute(`data-list-start`,String(r.start)),i},de=e=>{var t;let{data:n,itemColor:i,itemSize:a,placeholder:s,markerDepth:c}=e,l=document.createElement(`div`);l.setAttribute(`role`,`listitem`),l.className=r.n(ne,`flex`,...o),i&&(l.style.color=i),a&&(l.style.fontSize=a);let u=(t=n.depth)==null?0:t;if(u>0){let e=n.style===`ordered`?26:27;l.style.marginLeft=`${u*e}px`}let d=pe(n.style,c==null?u:c);d.setAttribute(`data-list-marker`,`true`),d.setAttribute(`data-blok-mutation-free`,`true`),l.appendChild(d);let f=document.createElement(`div`);return f.className=r.n(`flex-1 min-w-0 outline-hidden`,...o),f.setAttribute(`data-blok-testid`,se.contentContainer),f.contentEditable=e.readOnly?`false`:`true`,f.innerHTML=n.text,ce(f,s),l.appendChild(f),l},fe=e=>{var t;let{data:n,itemColor:i,itemSize:a,placeholder:s,readOnly:c}=e,l=document.createElement(`div`);l.setAttribute(`role`,`listitem`),l.className=re,i&&(l.style.color=i),a&&(l.style.fontSize=a);let u=(t=n.depth)==null?0:t;u>0&&(l.style.marginLeft=`${u*27}px`);let d=document.createElement(`input`);d.type=`checkbox`,d.className=ie,d.checked=!!n.checked,d.disabled=c;let f=document.createElement(`div`);return f.className=r.n(`flex-1 outline-hidden leading-[1.5]`,n.checked?`line-through opacity-60`:``,...o),f.setAttribute(`data-blok-testid`,se.checklistContent),f.setAttribute(`data-checked`,String(n.checked)),f.contentEditable=c?`false`:`true`,f.innerHTML=n.text,ce(f,s),l.appendChild(d),l.appendChild(f),l},pe=(e,t)=>{let n=document.createElement(`span`);return n.className=`shrink-0 select-none`,n.setAttribute(`aria-hidden`,`true`),n.contentEditable=`false`,e===`ordered`?(n.textContent=`1.`,n.className=r.n(n.className,`text-right`),n.style.paddingRight=`11px`,n.style.minWidth=`fit-content`):(n.textContent=me(t),n.className=r.n(n.className,`w-6 text-center flex justify-center`),n.style.paddingLeft=`1px`,n.style.paddingRight=`13px`,n.style.fontSize=`24px`,n.style.fontFamily=`Arial`,n.style.lineHeight=`1.5rem`),n},me=e=>{let t=[`•`,`◦`,`▪`];return t[e%t.length]},he=e=>{let{data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,element:s,setupItemPlaceholder:c,onCheckboxChange:l,keydownHandler:u}=e;if(!s)return null;let d=s.parentNode;if(!d)return null;let f=le({data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,keydownHandler:u});if(f.contentElement&&c(f.contentElement),f.checkboxElement&&!n){let e=f.checkboxElement;e.addEventListener(`change`,()=>{l(e.checked,f.contentElement)})}return d.replaceChild(f.wrapper,s),f.wrapper},ge=(e,t,r)=>{if(!t)return e;let i=r(),o=n.t({text:i?a(i.innerHTML):e.text,style:e.style},e.style===`checklist`?{checked:!!e.checked}:{});return e.start!==void 0&&e.start!==1&&(o.start=e.start),e.depth!==void 0&&e.depth>0&&(o.depth=e.depth),o},_e=(e,t,r,i,a)=>{var o,s;if(!r)return{newData:e,inPlace:!1};let c=(o=e.depth)==null?0:o,l=(s=t.depth)==null?0:s,u=e.style,d=t.style;if(u!==d)return{newData:e,inPlace:!1};let f=`depth`in t?t.depth:0,p=n.t(n.t(n.t({},e),t),{},{depth:f}),m=i();if(m&&typeof t.text==`string`&&(m.innerHTML=t.text),c!==l)return a.adjustDepthTo(l),a.updateMarkerForDepth(l,d),{newData:p,inPlace:!0};if(d===`checklist`){var h;a.updateCheckboxState((h=t.checked)==null?!1:h)}return{newData:p,inPlace:!0}},ve=(e,t)=>{let{element:n,getContentElement:r,parseHTML:i,data:a}=e;if(!n)return;a.text+=t.text;let o=r();if(o&&t.text){let e=i(t.text);o.appendChild(e),o.normalize()}},ye=(e,t,n,r)=>e.map(e=>({icon:e.icon,title:n(`toolNames.${e.titleKey}`),onActivate:()=>r(e.style),closeOnActivate:!0,isActive:t===e.style})),be=e=>{if(!e)return;let t=(e.getAttribute(`style`)||``).match(/margin-left:\s*(\d+)px/);if(!t)return;let n=parseInt(t[1],10);return n>0?{left:n}:void 0},xe=e=>{let t=e.closest(`[data-list-depth]`);if(!t)return;let n=t.getAttribute(`data-list-depth`);if(n===null)return;let r=parseInt(n,10);return r>0?{left:r*27}:void 0},Se=e=>{let t=be(e.closest(`[role="listitem"]`)||e.querySelector(`[role="listitem"]`));return t===void 0?xe(e):t},Ce=(e,t)=>{let n=document.createRange();if(n.setStart(e,0),n.setEnd(t.startContainer,t.startOffset),!e.lastChild)return{beforeContent:``,afterContent:``};let r=document.createRange();return r.setStart(t.endContainer,t.endOffset),r.setEndAfter(e.lastChild),{beforeContent:we(n.cloneContents()),afterContent:we(r.cloneContents())}},we=e=>{let t=document.createElement(`div`);return t.appendChild(e),t.innerHTML},Te=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},Ee=(e,t)=>{let n=document.createRange();return n.selectNodeContents(e),n.setEnd(t.startContainer,t.startOffset),n.toString().length===0},De=(e,t)=>{let n=document.createRange();n.selectNodeContents(e),n.setEnd(t.startContainer,t.startOffset);let r=n.toString().length===0,i=document.createRange();i.selectNodeContents(e),i.setStart(t.endContainer,t.endOffset);let a=i.toString().length===0;return r&&a},Oe=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.entries(e).find(([e])=>e===`items`);return t===void 0?!1:Array.isArray(t[1])},ke=e=>typeof e==`object`&&!!e,Ae=e=>typeof e==`string`?e:``,je=(e,t)=>e===`unordered`||e===`ordered`||e===`checklist`?e:t,Me=e=>!!e,Ne=(e,t)=>typeof e==`number`?e:t,Pe=(e,t)=>{let r=t.defaultStyle||`unordered`;if(!e||typeof e!=`object`)return{text:``,style:r,checked:!1,depth:0};if(Oe(e)){let{text:t,checked:i}=(e=>{if(typeof e==`string`)return{text:e,checked:!1};if(typeof e==`object`&&e){var t,n,r;return{text:(t=(n=e.content)==null?e.text:n)==null?``:t,checked:(r=e.checked)==null?!1:r}}return{text:``,checked:!1}})(e.items[0]);return n.t({text:t,style:e.style||r,checked:!!i,depth:0},e.start!==void 0&&e.start!==1?{start:e.start}:{})}if(ke(e)){let t=Ae(e.text),i=je(e.style,r),a=Me(e.checked),o=Ne(e.depth,0),s=e.start,c=typeof s==`number`&&s!==void 0&&s!==1?s:void 0;return n.t({text:t,style:i,checked:a,depth:o},c===void 0?{}:{start:c})}return{text:``,style:r,checked:!1,depth:0}},Fe=class{constructor(e){this.blocks=e}getMaxAllowedDepth(e){if(e===0)return 1;let t=this.blocks.getBlockByIndex(e-1);return!t||t.name!==`list`?1:this.getBlockDepth(t)+1}getTargetDepthForMove(e){let{blockIndex:t,currentDepth:n,skipDepthPromotion:r}=e,i=this.getMaxAllowedDepth(t);if(n>i)return i;if(r)return n;let a=this.blocks.getBlockByIndex(t+1),o=a&&a.name===`list`,s=o?this.getBlockDepth(a):0;if(o&&s>n&&s<=i)return s;let c=t>0?this.blocks.getBlockByIndex(t-1):void 0,l=c&&c.name===`list`,u=l?this.getBlockDepth(c):0;return l&&!o&&u>n&&u<=i?u:n}isValidDepth(e,t){let n=this.getMaxAllowedDepth(e);return t>=0&&t<=n}getBlockDepth(e){var t;if(!e)return 0;let n=(t=e.holder)==null||(t=t.querySelector(`[role="listitem"]`))==null?void 0:t.getAttribute(`style`),r=n==null?void 0:n.match(/margin-left:\s*(\d+)px/);return r?Math.round(parseInt(r[1],10)/27):0}},Ie=(e,t)=>{if(!e)return null;if(t===`checklist`){let t=e.querySelector(`[data-blok-testid="list-checklist-content"]`);return t instanceof HTMLElement?t:null}let n=e.querySelector(`[data-blok-testid="list-content-container"]`);return n instanceof HTMLElement?n:null},Le=(e,t,n)=>{e&&e.setAttribute(`data-list-depth`,String(n));let r=e==null?void 0:e.querySelector(`[role="listitem"]`);r instanceof HTMLElement&&(r.style.marginLeft=n>0?`${n*27}px`:``),t.depth=n},Re=(e,t)=>t.getBlockDepth(e),ze=(e,t)=>t.getBlockStyle(e),Be=(e,t)=>t.getBulletCharacter(e),Ve=(e,t,n,r,i)=>{var a;let o=e?(a=r.getBlockIndex(e))==null?r.getCurrentBlockIndex():a:r.getCurrentBlockIndex();return o<=0?0:i.getSiblingIndex(o,t,n)},He=(e,t,n,r,i,a)=>{var o;if(e===0){var s;return(s=r.start)==null?1:s}let c=n?(o=i.getBlockIndex(n))==null?i.getCurrentBlockIndex():o:i.getCurrentBlockIndex(),l=a.findFirstItemIndex(c-1,t,e,r.style);return l===null?1:a.getBlockStartValue(l)},Ue=(e,t,n,r,i,a)=>{var o;let s=He(e,t,r,n,i,a)+e,c=r?(o=i.getBlockIndex(r))==null?i.getCurrentBlockIndex():o:i.getCurrentBlockIndex(),l=a.getVisualDepth(c,t);return a.formatNumber(s,l)},We=(e,t,n,r)=>r.findGroupStart(e,t,n),Ge=(e,t,n,r)=>{if(!e)return;let i=e.holder,a=i==null?void 0:i.querySelector(`[data-list-style="ordered"]`);if(!a)return;let o=a.querySelector(`[data-list-marker]`);if(!o)return;let s=t.getBlockIndex(e.id);if(s==null)return;let c=Re(e,n),l=ze(e,r)||`ordered`,u=r.getSiblingIndex(s,c,l),d=r.getGroupStartValue(s,c,u,l)+u,f=r.getVisualDepth(s,c);o.textContent=r.formatNumber(d,f)},Ke=(e,t,n,r,i,a,o,s)=>{let c=e=>{if(e>=t)return;if(e===n){c(e+1);return}let l=a.getBlockByIndex(e);if(!l||l.name!==`list`)return;let u=Re(l,o);if(!(u<r)){if(u>r){c(e+1);return}ze(l,s)===i&&(Ge(l,a,o,s),c(e+1))}};c(e)},qe=(e,t,n)=>{let r=e.getBlocksCount();Array.from({length:r},(e,t)=>t).forEach(r=>{let i=e.getBlockByIndex(r);if(!i||i.name!==`list`)return;let a=i.holder;a!=null&&a.querySelector(`[data-list-style="ordered"]`)&&Ge(i,e,t,n)})},Je=(e,t,n=`end`)=>{let r=()=>{let r=t.holder;if(!r)return;let i=r.querySelector(`[contenteditable="true"]`);if(!(i instanceof HTMLElement)){e.caret.setToBlock(t,n),e.caret.updateLastCaretAfterPosition();return}i.focus();let a=window.getSelection();if(!a)return;let o=document.createRange();n===`start`?(o.setStart(i,0),o.collapse(!0)):(o.selectNodeContents(i),o.collapse(!1)),a.removeAllRanges(),a.addRange(o),e.caret.updateLastCaretAfterPosition()},i=t.holder;(i==null?void 0:i.querySelector(`[contenteditable="true"]`))instanceof HTMLElement?r():requestAnimationFrame(()=>r())},Ye=async(e,t)=>{var r;let{api:i,blockId:a,data:o,element:s,getContentElement:c}=e,l=window.getSelection();if(!l||!s)return;let u=c();if(!u)return;let d=u.innerHTML.trim();if(d===``||d===`<br>`){await Xe(e,t);return}let{beforeContent:f,afterContent:p}=Ce(u,l.getRangeAt(0)),m=a?(r=i.blocks.getBlockIndex(a))==null?i.blocks.getCurrentBlockIndex():r:i.blocks.getCurrentBlockIndex();if(!a){u.innerHTML=f,o.text=f,Je(i,i.blocks.insert(oe,n.t(n.t({text:p,style:o.style},o.style===`checklist`?{checked:!!o.checked}:{}),{},{depth:o.depth}),void 0,m+1,!0),`start`);return}let h=i.blocks.splitBlock(a,{text:f},oe,n.t(n.t({text:p,style:o.style},o.style===`checklist`?{checked:!!o.checked}:{}),{},{depth:o.depth}),m+1);o.text=f,Je(i,h,`start`)},Xe=async(e,t)=>{let{api:n,blockId:r,getDepth:i}=e;if(i()>0){await et(e,t);return}r!==void 0&&Je(n,await n.blocks.convert(r,`paragraph`,{text:``}),`start`)},Ze=async(e,t)=>{let{api:n,blockId:r,data:i,element:a,getContentElement:o,getDepth:s,syncContentFromDOM:c}=e,l=window.getSelection();if(!l||!a)return;let u=l.getRangeAt(0),d=o();if(!d)return;c();let f=i.text,p=s();if(De(d,u)&&!l.isCollapsed){t.preventDefault(),d.innerHTML=``,i.text=``;let e=document.createRange();e.setStart(d,0),e.collapse(!0),l.removeAllRanges(),l.addRange(e);return}if(!Ee(d,u)||(t.preventDefault(),r===void 0))return;let m=await n.blocks.convert(r,`paragraph`,{text:f});p>0&&requestAnimationFrame(()=>{let e=m.holder;e&&(e.style.marginLeft=`${p*27}px`,e.setAttribute(`data-blok-depth`,String(p)))}),Je(n,m,`start`)},Qe=async(e,t)=>{let{api:r,blockId:i,data:a,syncContentFromDOM:o,getDepth:s}=e,c=r.blocks.getCurrentBlockIndex(),l=s();if(l>=t.getMaxAllowedDepth(c))return;o();let u=l+1;a.depth=u,Je(r,await r.blocks.update(i||``,n.t(n.t({},a),{},{depth:u})))},$e=async(e,t,n,r)=>{var i;let a=t?(i=e.blocks.getBlockIndex(t))==null?e.blocks.getCurrentBlockIndex():i:e.blocks.getCurrentBlockIndex(),o=e.blocks.getBlocksCount(),s=async t=>{if(t>=o)return;let i=e.blocks.getBlockByIndex(t);if(!i||i.name!==`list`)return;let a=r.getBlockDepth(i);a<=n||(await e.blocks.update(i.id,{depth:a-1}),await s(t+1))};await s(a+1)},et=async(e,t)=>{let{api:r,blockId:i,data:a,syncContentFromDOM:o,getDepth:s}=e,c=s();if(c===0)return;o();let l=c-1;a.depth=l;let u=await r.blocks.update(i||``,n.t(n.t({},a),{},{depth:l}));t&&await $e(r,i,c,t),Je(r,u)},tt=e=>{let{data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,setupItemPlaceholder:s,onCheckboxChange:c,keydownHandler:l}=e,u=le({data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,keydownHandler:l});if(u.contentElement&&s(u.contentElement),u.checkboxElement&&!n){let e=u.checkboxElement;e.addEventListener(`change`,()=>{c(e.checked,u.contentElement)})}return u.wrapper},nt=e=>{let t=e=>{if(e<=0)return``;let n=e-1;return t(Math.floor(n/26))+String.fromCharCode(97+n%26)};return t(e)},rt=e=>{let t=[[1e3,`m`],[900,`cm`],[500,`d`],[400,`cd`],[100,`c`],[90,`xc`],[50,`l`],[40,`xl`],[10,`x`],[9,`ix`],[5,`v`],[4,`iv`],[1,`i`]],n=(e,r)=>{if(e<=0||r>=t.length)return``;let[i,a]=t[r];return e>=i?a+n(e-i,r):n(e,r+1)};return n(e,0)},it=class{constructor(e){this.blocks=e}getMarkerText(e){let{blockIndex:t,depth:n,style:r,start:i}=e;if(r!==`ordered`)return this.getBulletCharacter(n);let a=this.getSiblingIndex(t,n,r),o=(i==null?this.getGroupStartValue(t,n,a,r):i)+a;return this.formatNumber(o,n)}getBulletCharacter(e){let t=[`•`,`◦`,`▪`];return t[e%t.length]}getSiblingIndex(e,t,n){return e<=0?0:this.countPrecedingAtDepth(e-1,t,n)}findGroupStart(e,t,n){return this.findGroupStartRecursive(e-1,e,t,n)}formatNumber(e,t){let n=t%3;return n===1?`${nt(e)}.`:n===2?`${rt(e)}.`:`${e}.`}getGroupStartValue(e,t,n,r){if(n===0)return this.getBlockStartValue(e);let i=this.findFirstItemIndex(e-1,t,n,r);return i===null?1:this.getBlockStartValue(i)}getBlockStartValue(e){var t;let n=this.blocks.getBlockByIndex(e);if(!n)return 1;let r=(t=n.holder)==null?void 0:t.querySelector(`[data-list-style]`);if(!r)return 1;let i=r.getAttribute(`data-list-start`);return i?parseInt(i,10):1}findFirstItemIndex(e,t,n,r){if(e<0||n<=0)return e+1;let i=this.blocks.getBlockByIndex(e);if(!i||i.name!==`list`)return e+1;let a=this.getBlockDepth(i);if(a<t)return e+1;if(a>t)return this.findFirstItemIndex(e-1,t,n,r);let o=this.getBlockStyle(i);return r!==void 0&&o!==r?e+1:this.findFirstItemIndex(e-1,t,n-1,r)}getGroupBaseDepth(e){let t=e=>{if(e<=0)return 0;let n=this.blocks.getBlockByIndex(e-1);return!n||n.name!==`list`?e:t(e-1)},n=t(e),r=this.blocks.getBlockByIndex(n);return this.getBlockDepth(r)}getVisualDepth(e,t){return Math.max(0,t-this.getGroupBaseDepth(e))}getBlockDepth(e){var t;if(!e)return 0;let n=(t=e.holder)==null||(t=t.querySelector(`[role="listitem"]`))==null?void 0:t.getAttribute(`style`),r=n==null?void 0:n.match(/margin-left:\s*(\d+)px/);return r?Math.round(parseInt(r[1],10)/27):0}getBlockStyle(e){var t;if(!e)return null;let n=(t=e.holder)==null||(t=t.querySelector(`[data-list-style]`))==null?void 0:t.getAttribute(`data-list-style`);return this.isValidListItemStyle(n)?n:null}isValidListItemStyle(e){return e===`unordered`||e===`ordered`||e===`checklist`}countPrecedingAtDepth(e,t,n){if(e<0)return 0;let r=this.blocks.getBlockByIndex(e);if(!r||r.name!==`list`)return 0;let i=this.getBlockDepth(r);return i<t?0:i>t?this.countPrecedingAtDepth(e-1,t,n):this.getBlockStyle(r)===n?1+this.countPrecedingAtDepth(e-1,t,n):0}findGroupStartRecursive(e,t,n,r){if(e<0)return t;let i=this.blocks.getBlockByIndex(e);if(!i||i.name!==`list`)return t;let a=this.getBlockDepth(i);return a<n?t:a>n?this.findGroupStartRecursive(e-1,t,n,r):this.getBlockStyle(i)===r?this.findGroupStartRecursive(e-1,e,n,r):t}},at={value:!1},ot=class{constructor(e){this.blocks=e,this.depthValidator=new Fe(e),this.markerCalculator=new it(e)}updateMarker(e,t,n){let r=e.querySelector(`[data-list-marker]`);if(!r)return;let i=this.markerCalculator.getSiblingIndex(t,n,`ordered`),a=this.markerCalculator.getGroupStartValue(t,n,i,`ordered`),o=(i===0&&a===1?(()=>{let t=e.getAttribute(`data-list-start`);if(!t)return a;let n=parseInt(t,10);return isNaN(n)?a:n})():a)+i,s=this.markerCalculator.getVisualDepth(t,n);r.textContent=this.markerCalculator.formatNumber(o,s)}updateSiblingMarkers(e,t){let n=this.blocks.getBlocksCount(),r=this.findListGroupStartIndex(e,t,`ordered`);this.updateMarkersInRange(r,n,e,t,`ordered`)}updateAllMarkers(){let e=this.blocks.getBlocksCount();for(let t of Array.from({length:e},(e,t)=>t)){let e=this.blocks.getBlockByIndex(t);if(!e||e.name!==`list`)continue;let n=e.holder;n!=null&&n.querySelector(`[data-list-style="ordered"]`)&&this.updateBlockMarker(e)}}scheduleUpdateAll(){at.value||(at.value=!0,requestAnimationFrame(()=>{at.value=!1,this.updateAllMarkers()}))}findListGroupStartIndex(e,t,n){return this.markerCalculator.findGroupStart(e,t,n)}updateMarkersInRange(e,t,n,r,i){let a=Array.from({length:t-e},(t,n)=>e+n);for(let e of a){if(e===n)continue;let t=this.blocks.getBlockByIndex(e);if(!t||t.name!==`list`)return;let a=this.depthValidator.getBlockDepth(t);if(a<r)return;if(!(a>r)){if(this.getBlockStyle(t)!==i)return;this.updateBlockMarker(t)}}}getBlockStyle(e){return this.markerCalculator.getBlockStyle(e)}updateBlockMarker(e){if(!e)return;let t=e.holder,n=t==null?void 0:t.querySelector(`[data-list-style="ordered"]`);if(!n)return;let r=n.querySelector(`[data-list-marker]`);if(!r)return;let i=this.blocks.getBlockIndex(e.id);if(i==null)return;let a=this.depthValidator.getBlockDepth(e),o=this.getBlockStyle(e)||`ordered`,s=this.markerCalculator.getSiblingIndex(i,a,o),c=this.markerCalculator.getGroupStartValue(i,a,s,o),l=(s===0&&c===1?(()=>{let e=n.closest(`[data-list-start]`),t=e==null?void 0:e.getAttribute(`data-list-start`);if(!t)return c;let r=parseInt(t,10);return isNaN(r)?c:r})():c)+s,u=this.markerCalculator.getVisualDepth(i,a);r.textContent=this.markerCalculator.formatNumber(l,u)}},st=e=>e instanceof HTMLElement,ct=new Set(`decimal.decimal-leading-zero.lower-roman.upper-roman.lower-greek.lower-latin.upper-latin.lower-alpha.upper-alpha.arabic-indic.armenian.bengali.cambodian.cjk-decimal.devanagari.georgian.gujarati.gurmukhi.hebrew.kannada.khmer.lao.malayalam.mongolian.myanmar.oriya.persian.telugu.thai.tibetan`.split(`.`)),lt=new Set([`disc`,`circle`,`square`,`none`]),ut=e=>{let t=e.getAttribute(`data-list-style`);if(t===`ordered`)return`ordered`;if(t===`unordered`)return`unordered`;let n=e.getAttribute(`style`);if(!n)return null;let r=n.match(/list-style-type\s*:\s*([^;]+)/);if(!r)return null;let i=r[1].trim().toLowerCase();return ct.has(i)?`ordered`:lt.has(i)?`unordered`:null},dt=(e,t)=>{let n=e.parentElement;return(n==null?void 0:n.tagName)===`OL`?`ordered`:(n==null?void 0:n.tagName)===`UL`?e.querySelector(`input[type="checkbox"]`)?`checklist`:`unordered`:ut(e)||t},ft=e=>{let t=e.innerHTML||e.textContent||``,n=e.querySelector(`input[type="checkbox"]`);return{text:t,checked:n instanceof HTMLInputElement?n.checked:!1}},pt=e=>{let t=e.getAttribute(`aria-level`);if(t){let e=parseInt(t,10);return Math.max(0,e-1)}return 0},mt=()=>({text:{br:!0,a:{href:!0,target:`_blank`,rel:`nofollow`},b:!0,i:!0}}),ht=()=>({tags:[{li:{style:!0,"aria-level":!0}}]}),gt=()=>({export:e=>e.text,import:e=>({text:e,style:`unordered`,checked:!1})}),_t=[{name:`bulletedList`,titleKey:`bulletedList`,style:`unordered`,icon:t.jt},{name:`numberedList`,titleKey:`numberedList`,style:`ordered`,icon:t.Nt},{name:`todoList`,titleKey:`todoList`,style:`checklist`,icon:t.Mt}],vt=()=>[{icon:t.jt,titleKey:`bulletedList`,data:{style:`unordered`},name:`bulleted-list`,searchTerms:[`ul`,`bullet`,`unordered`,`list`],searchTermKeys:[`bullet`,`unordered`,`list`],shortcut:`-`},{icon:t.Nt,titleKey:`numberedList`,data:{style:`ordered`},name:`numbered-list`,searchTerms:[`ol`,`ordered`,`number`,`list`],searchTermKeys:[`ordered`,`number`,`list`],shortcut:`1.`},{icon:t.Mt,titleKey:`todoList`,data:{style:`checklist`},name:`check-list`,searchTerms:[`checkbox`,`task`,`todo`,`check`,`list`],searchTermKeys:[`checkbox`,`task`,`todo`,`check`,`list`],shortcut:`[]`}],yt=class{constructor({data:e,config:t,api:n,readOnly:r,block:i}){this._element=null,this.placeholderCleanup=null,this.boundHandleKeyDown=null,this.handleBlockChanged=e=>{if(this.isBlockChangedEventPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)){var t;(t=this.markerManager)==null||t.scheduleUpdateAll()}},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this.depthValidator=new Fe(n.blocks),this.markerCalculator=new it(n.blocks),this.markerManager=this._data.style===`ordered`?new ot(n.blocks):null,i&&(this.blockId=i.id),this._data.style===`ordered`&&this.api.events.on(`block changed`,this.handleBlockChanged)}isBlockChangedEventPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}normalizeData(e){return Pe(e,this._settings)}get availableStyles(){let e=this._settings.styles;return!e||e.length===0?_t:_t.filter(t=>e.includes(t.style))}get itemColor(){return this._settings.itemColor}get itemSize(){return this._settings.itemSize}get placeholder(){return this.api.i18n.t(ae)}setupItemPlaceholder(e){this.readOnly||(this.placeholderCleanup=p(e,this.placeholder))}render(){var e,t;if(this._element)return this._element;let n=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),r=(t=this._data.depth)==null?0:t,i=this.markerCalculator.getVisualDepth(n,r);return this.boundHandleKeyDown||(this.boundHandleKeyDown=this.handleKeyDown.bind(this)),this._element=tt({data:this._data,readOnly:this.readOnly,placeholder:this.placeholder,itemColor:this.itemColor,itemSize:this.itemSize,markerDepth:i,setupItemPlaceholder:this.setupItemPlaceholder.bind(this),onCheckboxChange:(e,t)=>{this._data.checked=e,t instanceof HTMLElement&&(t.classList.toggle(`line-through`,e),t.classList.toggle(`opacity-60`,e))},keydownHandler:this.readOnly?void 0:this.boundHandleKeyDown}),this._element}setReadOnly(e){if(!this._element)return;this.readOnly=e;let t=this.getContentElement();t&&(t.contentEditable=e?`false`:`true`);let n=this._element.querySelector(`input[type="checkbox"]`);n&&(n.disabled=e),e?(this.boundHandleKeyDown&&this._element.removeEventListener(`keydown`,this.boundHandleKeyDown),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null)):(this.boundHandleKeyDown&&this._element.addEventListener(`keydown`,this.boundHandleKeyDown),t&&(this.placeholderCleanup=p(t,this.placeholder)))}rendered(){this.updateMarkersAfterPositionChange()}moved(e){this.validateAndAdjustDepthAfterMove(e.toIndex,e.isGroupMove),this.updateMarkersAfterPositionChange()}updateMarkersAfterPositionChange(){this._data.style!==`ordered`||!this._element||(this.updateMarker(),this.updateSiblingListMarkers())}validateAndAdjustDepthAfterMove(e,t){let n=this.getDepth(),r=this.depthValidator.getTargetDepthForMove({blockIndex:e,currentDepth:n,skipDepthPromotion:t});n!==r&&this.adjustDepthTo(r)}adjustDepthTo(e){Le(this._element,this._data,e)}removed(){var e;this._data.style===`ordered`&&(this.api.events.off(`block changed`,this.handleBlockChanged),(e=this.markerManager)==null||e.scheduleUpdateAll())}updateAllOrderedListMarkers(){qe(this.api.blocks,this.depthValidator,this.markerCalculator)}updateMarker(){var e;let t=(e=this._element)==null?void 0:e.querySelector(`[data-list-marker]`);if(!t)return;let n=this.getDepth();t.textContent=Ue(Ve(this.blockId,n,this._data.style,this.api.blocks,this.markerCalculator),n,this._data,this.blockId,this.api.blocks,this.markerCalculator)}updateSiblingListMarkers(){var e;let t=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),n=this.getDepth(),r=this._data.style,i=this.api.blocks.getBlocksCount();Ke(We(t,n,r,this.markerCalculator),i,t,n,r,this.api.blocks,this.depthValidator,this.markerCalculator)}updateMarkerForDepth(e,t){var n,r;let i=(n=this._element)==null?void 0:n.querySelector(`[aria-hidden="true"]`);if(!(i instanceof HTMLElement))return;let a=this.blockId?(r=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():r:this.api.blocks.getCurrentBlockIndex(),o=this.markerCalculator.getVisualDepth(a,e);t===`ordered`?i.textContent=Ue(Ve(this.blockId,e,this._data.style,this.api.blocks,this.markerCalculator),e,this._data,this.blockId,this.api.blocks,this.markerCalculator):i.textContent=Be(o,this.markerCalculator)}updateCheckboxState(e){var t;let n=(t=this._element)==null?void 0:t.querySelector(`input[type="checkbox"]`);n instanceof HTMLInputElement&&(n.checked=e)}getDepth(){var e;return(e=this._data.depth)==null?0:e}handleKeyDown(e){if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}if(e.key===`Backspace`){this.handleBackspace(e);return}if(e.key===`Tab`&&!(document.querySelectorAll(`[data-blok-selected="true"]`).length>1)){if(e.preventDefault(),e.shiftKey){this.handleOutdent();return}this.handleIndent()}}async handleEnter(){var e=this;await Ye({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}async handleBackspace(e){var t=this;await Ze({api:t.api,blockId:t.blockId,data:t._data,element:t._element,getContentElement:t.getContentElement.bind(t),syncContentFromDOM:t.syncContentFromDOM.bind(t),getDepth:t.getDepth.bind(t)},e)}async handleIndent(){var e=this;await Qe({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}async handleOutdent(){var e=this;await et({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}syncContentFromDOM(){var e;let t=this.getContentElement();if(t&&(this._data.text=t.innerHTML),this._data.style!==`checklist`)return;let n=(e=this._element)==null?void 0:e.querySelector(`input[type="checkbox"]`);n instanceof HTMLInputElement&&(this._data.checked=n.checked)}getContentElement(){return Ie(this._element,this._data.style)}renderSettings(){return ye(this.availableStyles,this._data.style,this.api.i18n.t,e=>this.setStyle(e))}setStyle(e){let t=this._data.style;if(this._data.style=e,this.rerender(),t!==e){var n;(n=this.markerManager)==null||n.scheduleUpdateAll()}}rerender(){var e,t,n;let r=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),i=(t=this._data.depth)==null?0:t,a=he({data:this._data,readOnly:this.readOnly,placeholder:this.placeholder,itemColor:this.itemColor,itemSize:this.itemSize,markerDepth:this.markerCalculator.getVisualDepth(r,i),element:this._element,setupItemPlaceholder:this.setupItemPlaceholder.bind(this),onCheckboxChange:(e,t)=>{this._data.checked=e,t instanceof HTMLElement&&(t.classList.toggle(`line-through`,e),t.classList.toggle(`opacity-60`,e))},keydownHandler:this.readOnly||(n=this.boundHandleKeyDown)==null?void 0:n});a&&(this._element=a,this.updateMarkersAfterPositionChange())}validate(e){return typeof e.text==`string`}save(){return ge(this._data,this._element,this.getContentElement.bind(this))}setData(e){let t=_e(this._data,e,this._element,this.getContentElement.bind(this),{adjustDepthTo:this.adjustDepthTo.bind(this),updateMarkerForDepth:this.updateMarkerForDepth.bind(this),updateCheckboxState:this.updateCheckboxState.bind(this)});return this._data=t.newData,t.inPlace}merge(e){ve({data:this._data,element:this._element,getContentElement:this.getContentElement.bind(this),parseHTML:Te},e)}static get conversionConfig(){return gt()}static get sanitize(){return mt()}static get pasteConfig(){return ht()}onPaste(e){let t=e.detail;if(!(`data`in t))return;let n=t.data;if(!st(n))return;let{text:r,checked:i}=ft(n),a=pt(n);this._data={text:r,style:dt(n,this._data.style),checked:i,depth:a},this.rerender()}static get isReadOnlySupported(){return!0}getContentOffset(e){return Se(e)}static get toolbox(){return vt()}},bt=`data-blok-table-add-row`,xt=`data-blok-table-add-col`,St=150,Ct=5,wt=40,Tt=[`flex`,`items-center`,`justify-center`,`transition-opacity`,`duration-150`],Et=[`flex`,`items-center`,`justify-center`,`border`,`border-gray-300`,`rounded-sm`,`group-hover/add:bg-gray-50`],Dt=`12`,Ot=class{constructor(e){this.rowHideTimeout=null,this.colHideTimeout=null,this.rowVisible=!1,this.colVisible=!1,this.interactive=!0,this.dragState=null,this.scrollContainer=null,this.boundScrollHandler=null,this.scrollContainerResizeObserver=null,this.wrapper=e.wrapper,this.grid=e.grid,this.i18n=e.i18n,this.boundAddRowClick=e.onAddRow,this.boundAddColClick=e.onAddColumn,this.onDragStart=e.onDragStart,this.onDragAddRow=e.onDragAddRow,this.onDragRemoveRow=e.onDragRemoveRow,this.onDragAddCol=e.onDragAddCol,this.onDragRemoveCol=e.onDragRemoveCol,this.onDragEnd=e.onDragEnd,this.getTableSize=e.getTableSize,this.getNewColumnWidth=e.getNewColumnWidth,this.boundMouseMove=this.handleMouseMove.bind(this),this.boundDocumentMouseMove=this.handleDocumentMouseMove.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundRowPointerDown=e=>this.handlePointerDown(`row`,e),this.boundColPointerDown=e=>this.handlePointerDown(`col`,e),this.addRowBtn=this.createAddRowButton(),this.addColBtn=this.createAddColumnButton(),this.wrapper.appendChild(this.addRowBtn),this.wrapper.appendChild(this.addColBtn),this.syncRowButtonWidth(),this.wrapper.addEventListener(`mousemove`,this.boundMouseMove),this.wrapper.addEventListener(`mouseleave`,this.boundMouseLeave),document.addEventListener(`mousemove`,this.boundDocumentMouseMove),this.addRowBtn.addEventListener(`pointerdown`,this.boundRowPointerDown),this.addColBtn.addEventListener(`pointerdown`,this.boundColPointerDown)}computeVisibleWidth(e,t,n){if(!t||n===null)return e;let r=this.wrapper.getBoundingClientRect();if(r.width>0){let e=this.grid.getBoundingClientRect(),t=n.getBoundingClientRect();return Math.min(e.right,t.right)-r.left}return n.clientWidth>0?Math.min(e,n.clientWidth):e}syncRowButtonWidth(){let e=this.grid.style.width;if(e&&e.endsWith(`px`)){let t=parseFloat(e),n=this.grid.parentElement,r=n!==null&&n!==this.wrapper,i=this.computeVisibleWidth(t,r,n);this.addRowBtn.style.width=`${i}px`,this.addRowBtn.style.right=``,this.addRowBtn.style.left=`0px`,this.addRowBtn.style.transform=``,this.addColBtn.style.left=`${i+4}px`,this.addColBtn.style.right=``}else{this.addRowBtn.style.width=``,this.addRowBtn.style.left=`0px`,this.addRowBtn.style.transform=``;let e=parseFloat(getComputedStyle(this.wrapper).paddingRight)||0;this.addRowBtn.style.right=`${e}px`,this.addColBtn.style.left=``,this.addColBtn.style.right=`${e-36}px`}let t=this.grid.getBoundingClientRect(),n=this.wrapper.getBoundingClientRect(),r=t.height;if(r>0){this.addColBtn.style.height=`${r}px`,this.addColBtn.style.bottom=``;let e=t.bottom-n.top;this.addRowBtn.style.top=`${e+4}px`,this.addRowBtn.style.bottom=``}else this.addColBtn.style.height=``,this.addColBtn.style.bottom=`0px`,this.addRowBtn.style.top=``,this.addRowBtn.style.bottom=`-36px`}setDisplay(e){let t=e?``:`none`;this.addRowBtn.style.display=t,this.addColBtn.style.display=t}setInteractive(e){if(this.interactive=e,!e){this.addRowBtn.style.pointerEvents=`none`,this.addColBtn.style.pointerEvents=`none`;return}this.addRowBtn.style.pointerEvents=this.rowVisible?``:`none`,this.addColBtn.style.pointerEvents=this.colVisible?``:`none`}attachScrollContainer(e){var t;this.scrollContainer&&this.boundScrollHandler&&this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),(t=this.scrollContainerResizeObserver)==null||t.disconnect(),this.scrollContainer=e,this.boundScrollHandler=()=>{this.syncRowButtonWidth()},e.addEventListener(`scroll`,this.boundScrollHandler,{passive:!0}),this.scrollContainerResizeObserver=new ResizeObserver(()=>{this.syncRowButtonWidth()}),this.scrollContainerResizeObserver.observe(e)}destroy(){var e;if(this.scrollContainer&&this.boundScrollHandler&&(this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),this.scrollContainer=null,this.boundScrollHandler=null),(e=this.scrollContainerResizeObserver)==null||e.disconnect(),this.scrollContainerResizeObserver=null,this.wrapper.removeEventListener(`mousemove`,this.boundMouseMove),this.wrapper.removeEventListener(`mouseleave`,this.boundMouseLeave),document.removeEventListener(`mousemove`,this.boundDocumentMouseMove),this.addRowBtn.removeEventListener(`pointerdown`,this.boundRowPointerDown),this.addColBtn.removeEventListener(`pointerdown`,this.boundColPointerDown),this.dragState){let e=this.dragState.axis===`row`?this.addRowBtn:this.addColBtn;e.removeEventListener(`pointermove`,this.boundPointerMove),e.removeEventListener(`pointerup`,this.boundPointerUp),e.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,this.dragState=null}this.clearRowTimeout(),this.clearColTimeout(),this.addRowBtn.remove(),this.addColBtn.remove()}showDimensionTooltip(){if(!this.dragState)return;let e=this.getTableSize(),n=this.dragState.axis===`row`?this.addRowBtn:this.addColBtn,r=this.dragState.axis===`row`?{placement:`bottom`,marginTop:-16}:{placement:`bottom`};t.jn(n,`${e.cols}\u00D7${e.rows}`,r)}handlePointerDown(e,t){t.preventDefault();let n=e===`row`?this.addRowBtn:this.addColBtn;n.setPointerCapture(t.pointerId);let r=this.measureUnitSize(e);this.dragState={axis:e,startPos:e===`row`?t.clientY:t.clientX,unitSize:r,addedCount:0,pointerId:t.pointerId,didDrag:!1},n.addEventListener(`pointermove`,this.boundPointerMove),n.addEventListener(`pointerup`,this.boundPointerUp),n.addEventListener(`pointercancel`,this.boundPointerCancel)}handlePointerMove(e){if(!this.dragState)return;let{axis:t,startPos:n,unitSize:r}=this.dragState,i=(t===`row`?e.clientY:e.clientX)-n,a=Math.floor(i/r);for(;this.dragState.addedCount<a;)t===`row`?this.onDragAddRow():this.onDragAddCol(),this.dragState.addedCount++;for(;this.dragState.addedCount>a;)t===`row`?this.onDragRemoveRow():this.onDragRemoveCol(),this.dragState.addedCount--;if(Math.abs(i)>Ct&&!this.dragState.didDrag){this.dragState.didDrag=!0,document.body.style.cursor=t===`row`?`row-resize`:`col-resize`,this.showDimensionTooltip(),this.onDragStart();return}this.dragState.didDrag&&this.showDimensionTooltip(),this.dragState.didDrag&&this.showDimensionTooltip()}handlePointerUp(e){if(!this.dragState)return;let{axis:n,pointerId:r,didDrag:i}=this.dragState,a=n===`row`?this.addRowBtn:this.addColBtn;if(a.releasePointerCapture(r),a.removeEventListener(`pointermove`,this.boundPointerMove),a.removeEventListener(`pointerup`,this.boundPointerUp),a.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,t.kn(),this.dragState=null,!i){(n===`row`?this.boundAddRowClick:this.boundAddColClick)();return}this.onDragEnd()}handlePointerCancel(e){if(!this.dragState)return;let{axis:n,didDrag:r}=this.dragState,i=n===`row`?this.addRowBtn:this.addColBtn;i.removeEventListener(`pointermove`,this.boundPointerMove),i.removeEventListener(`pointerup`,this.boundPointerUp),i.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,t.kn(),this.dragState=null,r&&this.onDragEnd()}measureUnitSize(e){if(e===`row`){let e=this.grid.querySelectorAll(`[data-blok-table-row]`),t=e[e.length-1];return(t==null?void 0:t.offsetHeight)||30}if(this.getNewColumnWidth)return this.getNewColumnWidth()||100;let t=this.grid.querySelector(`[data-blok-table-row]`);if(!t)return 100;let n=t.querySelectorAll(`[data-blok-table-cell]`),r=n[n.length-1];return(r==null?void 0:r.offsetWidth)||100}handleMouseMove(e){let t=this.grid.getBoundingClientRect(),n=this.grid.parentElement,r=n!==null&&n!==this.wrapper?Math.min(t.right,n.getBoundingClientRect().right):t.right,i=Math.abs(e.clientY-t.bottom),a=Math.abs(e.clientX-r);i<=wt?this.showRow():this.scheduleHideRow(),a<=wt?this.showCol():this.scheduleHideCol()}handleMouseLeave(){this.scheduleHideRow(),this.scheduleHideCol()}handleDocumentMouseMove(e){if(this.wrapper.contains(e.target))return;let t=this.grid.getBoundingClientRect(),n=wt;e.clientX>=t.left-n&&e.clientX<=t.right+n&&e.clientY>=t.top-n&&e.clientY<=t.bottom+n?this.handleMouseMove(e):(this.scheduleHideRow(),this.scheduleHideCol())}showRow(){this.clearRowTimeout(),this.rowVisible||(this.addRowBtn.style.opacity=`1`,this.addRowBtn.style.pointerEvents=this.interactive?``:`none`,this.rowVisible=!0)}showCol(){this.clearColTimeout(),this.colVisible||(this.addColBtn.style.opacity=`1`,this.addColBtn.style.pointerEvents=this.interactive?``:`none`,this.colVisible=!0)}scheduleHideRow(){var e;!this.rowVisible||this.rowHideTimeout!==null||((e=this.dragState)==null?void 0:e.axis)===`row`||(this.rowHideTimeout=setTimeout(()=>{this.addRowBtn.style.opacity=`0`,this.addRowBtn.style.pointerEvents=`none`,this.rowVisible=!1,this.rowHideTimeout=null},St))}scheduleHideCol(){var e;!this.colVisible||this.colHideTimeout!==null||((e=this.dragState)==null?void 0:e.axis)===`col`||(this.colHideTimeout=setTimeout(()=>{this.addColBtn.style.opacity=`0`,this.addColBtn.style.pointerEvents=`none`,this.colVisible=!1,this.colHideTimeout=null},St))}clearRowTimeout(){this.rowHideTimeout!==null&&(clearTimeout(this.rowHideTimeout),this.rowHideTimeout=null)}clearColTimeout(){this.colHideTimeout!==null&&(clearTimeout(this.colHideTimeout),this.colHideTimeout=null)}createAddRowButton(){let e=document.createElement(`div`);e.className=r.n(Tt,`group/add`,`items-start`,`cursor-row-resize`),e.setAttribute(bt,``),e.setAttribute(`contenteditable`,`false`),e.style.opacity=`0`,e.style.pointerEvents=`none`,e.style.position=`absolute`,e.style.left=`0`,e.style.bottom=`-36px`,e.style.zIndex=`1`,e.style.height=`32px`;let n=document.createElement(`div`);return n.className=r.n(Et),n.style.width=`100%`,n.style.height=`16px`,this.appendIcon(n),e.appendChild(n),t.An(e,t.h([this.i18n.t(`tools.table.clickToAddRow`),this.i18n.t(`tools.table.dragToAddRemoveRows`)]),{placement:`bottom`,marginTop:-16}),e}createAddColumnButton(){let e=document.createElement(`div`);e.className=r.n(Tt,`group/add`,`justify-start`,`cursor-col-resize`),e.setAttribute(xt,``),e.setAttribute(`contenteditable`,`false`),e.style.opacity=`0`,e.style.pointerEvents=`none`,e.style.position=`absolute`,e.style.right=`-36px`,e.style.top=`0px`,e.style.bottom=`0px`,e.style.width=`32px`;let n=document.createElement(`div`);return n.className=r.n(Et),n.style.width=`16px`,n.style.height=`100%`,this.appendIcon(n),e.appendChild(n),t.An(e,t.h([this.i18n.t(`tools.table.clickToAddColumn`),this.i18n.t(`tools.table.dragToAddRemoveColumns`)]),{placement:`bottom`}),e}appendIcon(e){e.insertAdjacentHTML(`beforeend`,t.Ht);let n=e.querySelector(`svg`);n&&(n.setAttribute(`width`,Dt),n.setAttribute(`height`,Dt),n.setAttribute(`viewBox`,`0 0 24 24`),n.classList.add(`text-gray-500`,`pointer-events-none`))}},P=`data-blok-table-row`,F=`data-blok-table-cell`,I=`data-blok-table-cell-row`,L=`data-blok-table-cell-col`,kt=`1px solid var(--blok-table-border)`,At=[`py-1`,`px-2`,`min-h-[2em]`,`outline-hidden`,`leading-none`,`text-sm`,`cursor-text`],jt=e=>{let t=Math.round(100/e*100)/100;return Array.from({length:e},()=>t)},Mt=class{constructor(e){this.readOnly=e.readOnly}createGrid(e,t,n){let r=document.createElement(`table`);r.style.tableLayout=`fixed`,r.style.width=`100%`,r.style.borderCollapse=`separate`,r.style.borderSpacing=`0px`,r.style.borderTop=kt,r.style.borderLeft=kt;let i=n==null?jt(t):n,a=document.createElement(`colgroup`);i.forEach(e=>{a.appendChild(this.createCol(e))}),r.appendChild(a);let o=document.createElement(`tbody`);return Array.from({length:e}).forEach((e,n)=>{o.appendChild(this.createRow(t,n))}),r.appendChild(o),r}fillGrid(e,t){}createGridFromModel(e){var t;let n=document.createElement(`table`);n.style.tableLayout=`fixed`,n.style.width=`100%`,n.style.borderCollapse=`separate`,n.style.borderSpacing=`0px`,n.style.borderTop=kt,n.style.borderLeft=kt;let r=document.createElement(`colgroup`);((t=e.colWidths)==null?jt(e.cols):t).forEach(e=>r.appendChild(this.createCol(e))),n.appendChild(r);let i=document.createElement(`tbody`);return Array.from({length:e.rows}).forEach((t,n)=>{let r=document.createElement(`tr`);r.setAttribute(P,``),Array.from({length:e.cols}).forEach((t,i)=>{if(e.isSpannedCell(n,i))return;let a=this.createCell(n,i),o=e.getCellSpan(n,i);o.colspan>1&&(a.colSpan=o.colspan),o.rowspan>1&&(a.rowSpan=o.rowspan),r.appendChild(a)}),i.appendChild(r)}),n.appendChild(i),n}addRow(e,t){var n;let r=this.getColumnCount(e),i=this.createRow(r),a=(n=e.querySelector(`tbody`))==null?e:n,o=a.querySelectorAll(`[${P}]`);return t!==void 0&&t<o.length?a.insertBefore(i,o[t]):a.appendChild(i),this.reindexCoordinates(e),i}deleteRow(e,t){let n=e.querySelectorAll(`[${P}]`);t<n.length&&n[t].remove(),this.reindexCoordinates(e)}addColumn(e,t,n,r){let i=e.querySelector(`colgroup`),a=(i?Array.from(i.querySelectorAll(`col`)):[]).length,o=n!==void 0&&n.length===a,s=o||this.detectWidthUnit(e)===`px`;return o&&i&&this.applyWidthsToCols(i,n),s?this.addColumnPx(e,a,t,r):this.addColumnPercent(e,a,t),this.reindexCoordinates(e),!0}applyWidthsToCols(e,t){let n=Array.from(e.querySelectorAll(`col`));t.forEach((e,t)=>{t<n.length&&(n[t].style.width=`${e}px`)})}addColumnPx(e,t,n,r){let i=`${r==null?this.computeHalfAvgWidth(e,t):r}px`;this.insertColumn(e,n,i)}computeHalfAvgWidth(e,t){let n=e.querySelector(`colgroup`),r=(n?Array.from(n.querySelectorAll(`col`)):[]).reduce((e,t)=>e+(parseFloat(t.style.width)||0),0);return t>0?Math.round(r/t/2*100)/100:0}addColumnPercent(e,t,n){let r=1-.5/t,i=e.querySelector(`colgroup`);(i?Array.from(i.querySelectorAll(`col`)):[]).forEach(e=>{let n=e,i=parseFloat(n.style.width)||100/t,a=Math.round(i*r*100)/100;n.style.width=`${a}%`});let a=Math.round(100/t/2*100)/100;this.insertColumn(e,n,`${a}%`)}insertColumn(e,t,n){let r=e.querySelector(`colgroup`);if(r){let e=document.createElement(`col`);e.style.width=n;let i=r.querySelectorAll(`col`);t===void 0||t>=i.length?r.appendChild(e):r.insertBefore(e,i[t])}e.querySelectorAll(`[${P}]`).forEach(e=>{let n=e.querySelectorAll(`[${F}]`),r=t===void 0||t>=n.length,i=this.createCell();r?e.appendChild(i):e.insertBefore(i,n[t])})}deleteColumn(e,t){let n=e.querySelector(`colgroup`);if(n){let e=n.querySelectorAll(`col`);t<e.length&&e[t].remove()}e.querySelectorAll(`[${P}]`).forEach(e=>{let n=e.querySelectorAll(`[${F}]`);t>=n.length||n[t].remove()}),this.reindexCoordinates(e)}moveRow(e,t,n){var r;if(t===n)return;let i=(r=e.querySelector(`tbody`))==null?e:r,a=Array.from(i.querySelectorAll(`[${P}]`));if(t>=a.length||n>=a.length)return;let o=a[t];o.remove();let s=Array.from(i.querySelectorAll(`[${P}]`));n>=s.length?i.appendChild(o):i.insertBefore(o,s[n]),this.reindexCoordinates(e)}moveColumn(e,t,n){t!==n&&(this.reorderColElement(e,t,n),e.querySelectorAll(`[${P}]`).forEach(e=>{let r=Array.from(e.querySelectorAll(`[${F}]`));if(t>=r.length||n>=r.length)return;let i=r[t];i.remove();let a=Array.from(e.querySelectorAll(`[${F}]`));n>=a.length?e.appendChild(i):e.insertBefore(i,a[n])}),this.reindexCoordinates(e))}reindexCoordinates(e){let t=Array.from(e.querySelectorAll(`[${P}]`)),n=new Map;t.forEach((e,t)=>{var r;let i=Array.from(e.querySelectorAll(`[${F}]`)),a=(r=n.get(t))==null?new Set:r;i.reduce((e,r)=>{let i=r,o=e=>a.has(e)?o(e+1):e,s=o(e);r.setAttribute(I,String(t)),r.setAttribute(L,String(s));let c=i.colSpan||1,l=i.rowSpan||1;return l>1&&this.blockRowspanCols(n,t,s,l,c),s+c},0),n.delete(t)})}blockRowspanCols(e,t,n,r,i){Array.from({length:r-1},(e,t)=>t+1).forEach(r=>{let a=t+r;e.has(a)||e.set(a,new Set);let o=e.get(a);Array.from({length:i},(e,t)=>t).forEach(e=>{o.add(n+e)})})}getRowCount(e){return e.querySelectorAll(`[${P}]`).length}getColumnCount(e){let t=e.querySelector(`colgroup`);if(t)return t.querySelectorAll(`col`).length;let n=e.querySelector(`[${P}]`);return n?n.querySelectorAll(`[${F}]`).length:0}getCell(e,t,n){let r=e.querySelector(`[${I}="${t}"][${L}="${n}"]`);if(r)return r;let i=e.querySelectorAll(`[${P}]`);if(t>=i.length)return null;let a=i[t].querySelectorAll(`[${F}]`);return n>=a.length?null:a[n]}getColWidths(e){let t=e.querySelector(`colgroup`);if(!t)return[];let n=t.querySelectorAll(`col`),r=[];return n.forEach(e=>{let t=parseFloat(e.style.width);r.push(isNaN(t)?0:t)}),r}getColgroup(e){return e.querySelector(`colgroup`)}applyColWidths(e,t){let n=e.querySelector(`colgroup`);if(!n)return;let r=Array.from(n.querySelectorAll(`col`));t.forEach((e,t)=>{t<r.length&&(r[t].style.width=`${e}px`)})}reorderColElement(e,t,n){let r=e.querySelector(`colgroup`);if(!r)return;let i=Array.from(r.querySelectorAll(`col`));if(t>=i.length||n>=i.length)return;let a=i[t];a.remove();let o=Array.from(r.querySelectorAll(`col`));n>=o.length?r.appendChild(a):r.insertBefore(a,o[n])}detectWidthUnit(e){let t=e.querySelector(`colgroup`);if(!t)return`%`;let n=t.querySelector(`col`);return n&&n.style.width.endsWith(`px`)?`px`:`%`}createCol(e){let t=document.createElement(`col`);return t.style.width=typeof e==`string`?e:`${e}%`,t}createRow(e,t){let n=document.createElement(`tr`);return n.setAttribute(P,``),Array.from({length:e}).forEach((e,r)=>{n.appendChild(this.createCell(t,t===void 0?void 0:r))}),n}createCell(e,n){let i=document.createElement(`td`);i.className=r.n(At),i.style.borderRight=kt,i.style.borderBottom=kt,i.style.overflow=`hidden`,i.style.overflowWrap=`break-word`,i.style.height=`0`,i.setAttribute(F,``),e!==void 0&&n!==void 0&&(i.setAttribute(I,String(e)),i.setAttribute(L,String(n)));let a=document.createElement(`div`);return a.setAttribute(z,``),a.setAttribute(t.Pr.nestedBlocks,``),a.style.display=`flex`,a.style.flexDirection=`column`,a.style.minHeight=`100%`,i.appendChild(a),i}},R=e=>typeof e==`object`&&!!e&&`blocks`in e,z=`data-blok-table-cell-blocks`,Nt=class{constructor(e){var t;this._activeCellWithBlocks=null,this.cellsPendingCheck=new Set,this.pendingCheckScheduled=!1,this.removedBlockCells=new Map,this.deferredEvents=[],this.isExitingTable=!1,this.handleBlockMutation=e=>{if(this.isStructuralOpActive()&&!this.api.blocks.isSyncingFromYjs){this.deferredEvents.push(e);return}if(this.isExitingTable||!this.isBlockMutationEvent(e))return;let{type:t,detail:n}=e.event;if(t===`block-removed`){this.handleBlockRemoved(n);return}if(t===`block-moved`){this.handleBlockMoved(n);return}if(t!==`block-added`||n.target.id===this.tableBlockId)return;let r=this.model.findCellForBlock(n.target.id);if(r){let e=this.gridElement.querySelector(`[${I}="${r.row}"][${L}="${r.col}"]`);if(e){this.claimBlockForCell(e,n.target.id),this.cellsPendingCheck.delete(e);return}}let i=n.index;if(i===void 0)return;let a=this.findRemovedEntryForIndex(i);if(a&&this.isAdjacentToThisTable(i)){this.claimBlockForCell(a.cell,n.target.id),this.syncBlockToModel(a.cell,n.target.id),this.cellsPendingCheck.delete(a.cell);return}let o=n.target.holder,s=o.closest(`[${z}]`);s&&this.stripPlaceholders(s);let c=s&&!this.model.findCellForBlock(n.target.id)?s.closest(`[${F}]`):null;if(c&&this.syncBlockToModel(c,n.target.id),s)return;if(!this.gridElement.contains(o)){let e=this.api.blocks.getBlockIndex(this.tableBlockId),t=e===void 0?null:this.api.blocks.getBlockByIndex(e);if(t&&!t.holder.contains(o))return;let r=this.api.blocks.getCurrentBlockIndex(),a=r>=0?this.api.blocks.getBlockByIndex(r):null;if(!(a!=null&&this.getOwnedCellForBlock(a.id)!==null))return;let s=this.findCellForNewBlock(i);s&&(this.claimBlockForCell(s,n.target.id),this.syncBlockToModel(s,n.target.id),this.cellsPendingCheck.delete(s));return}let l=this.findCellForNewBlock(i);l&&(this.claimBlockForCell(l,n.target.id),this.syncBlockToModel(l,n.target.id),this.cellsPendingCheck.delete(l))},this.handleCellBlankSpaceClick=e=>{let t=e.target;if(!t)return;let n=t.hasAttribute(F),r=t.hasAttribute(z);if(!n&&!r)return;let i=n?t:t.closest(`[${F}]`);if(!i)return;let a=n?i.querySelector(`[${z}]`):t;if(!a)return;let o=a.querySelectorAll(`[data-blok-id]`),s=o[o.length-1];if(!s)return;let c=s.getAttribute(`data-blok-id`);c&&this.api.caret.setToBlock(c,`end`)},this.api=e.api,this.gridElement=e.gridElement,this.tableBlockId=e.tableBlockId,this.model=e.model,this.onNavigateToCell=e.onNavigateToCell,this.isStructuralOpActive=(t=e.isStructuralOpActive)==null?(()=>!1):t,this.api.events.on(`block changed`,this.handleBlockMutation),this.gridElement.addEventListener(`click`,this.handleCellBlankSpaceClick)}get activeCellWithBlocks(){return this._activeCellWithBlocks}setActiveCellWithBlocks(e){this._activeCellWithBlocks=e}clearActiveCellWithBlocks(){this._activeCellWithBlocks=null}handleKeyDown(e,t){if(e.key===`Tab`&&!e.shiftKey){e.preventDefault(),this.handleTabNavigation(t);return}if(e.key===`Tab`&&e.shiftKey){e.preventDefault(),this.handleShiftTabNavigation(t);return}e.key===`ArrowDown`&&!e.defaultPrevented&&t.row===this.getRowCount()-1&&(e.preventDefault(),this.exitTableForward())}handleTabNavigation(e){let t=e.col+1;if(t<this.getColumnCount()){this.navigateToCell({row:e.row,col:t});return}let n=e.row+1;if(n<this.getRowCount()){this.navigateToCell({row:n,col:0});return}this.exitTableForward()}handleShiftTabNavigation(e){let t=e.col-1;if(t>=0){this.navigateToCell({row:e.row,col:t},!0);return}let n=e.row-1;if(n>=0){this.navigateToCell({row:n,col:this.getColumnCount()-1},!0);return}this.exitTableBackward()}exitTableForward(){let e=this.api.blocks.getBlockIndex(this.tableBlockId);if(e===void 0)return;let t=this.findFirstBlockAfterTable(e);if(t!==null){this.api.caret.setToBlock(t.id,`start`);return}this.isExitingTable=!0;try{let t=this.api.blocks.getBlocksCount(),n=this.api.blocks.insert(void 0,{},{},t,!0),r=this.gridElement.contains(n.holder)?this.api.blocks.getBlockByIndex(e):null;r&&r.holder.after(n.holder),this.api.caret.setToBlock(n.id,`start`)}finally{this.isExitingTable=!1}}exitTableBackward(){let e=this.api.blocks.getBlockIndex(this.tableBlockId);if(e===void 0||e===0)return;let t=this.api.blocks.getBlockByIndex(e-1);t&&this.api.caret.setToBlock(t.id,`end`)}findFirstBlockAfterTable(e){var t;let n=this.api.blocks.getBlocksCount();return(t=Array.from({length:n-e-1},(t,n)=>this.api.blocks.getBlockByIndex(e+1+n)).find(e=>e!=null&&!this.gridElement.contains(e.holder)))==null?null:t}navigateToCell(e,t=!1){var n;this.clearActiveCellWithBlocks();let r=this.getCell(e.row,e.col);if(!r)return;let i=r.querySelector(`[${z}]`);if(!i)return;let a=i.querySelectorAll(`[contenteditable="true"]`);a.length!==0&&((t?a[a.length-1]:a[0]).focus(),(n=this.onNavigateToCell)==null||n.call(this,e))}getRowCount(){return this.gridElement.querySelectorAll(`[data-blok-table-row]`).length}getColumnCount(){var e;let t=this.gridElement.querySelector(`colgroup`);if(t)return t.querySelectorAll(`col`).length;let n=this.gridElement.querySelector(`[data-blok-table-row]`);return(e=n==null?void 0:n.querySelectorAll(`[data-blok-table-cell]`).length)==null?0:e}getCell(e,t){var n;let r=this.gridElement.querySelectorAll(`[data-blok-table-row]`)[e];return r?(n=r.querySelector(`[data-blok-table-cell-col="${t}"]`))==null?null:n:null}initializeCells(e){let t=this.gridElement.querySelectorAll(`[${P}]`),r=[];return e.forEach((e,i)=>{let a=t[i];if(!a)return;let o=[];e.forEach((e,t)=>{let r=a.querySelector(`[${L}="${t}"]`);if(!r)return;let i=r.querySelector(`[${z}]`);if(!i)return;let s=R(e)&&e.blocks.length>0?[...e.blocks]:null,{mountedIds:c,replacements:l}=s?this.mountBlocksInCell(i,s):{mountedIds:[],replacements:new Map},u={};if(R(e)&&(e.color!==void 0&&(u.color=e.color),e.textColor!==void 0&&(u.textColor=e.textColor)),c.length>0){let e=s==null?c:s,t=l.size>0?e.map(e=>{var t;return(t=l.get(e))==null?e:t}):e;o.push(n.t({blocks:t},u))}else{var d;let t=typeof e==`string`?e:(d=e.text)==null?``:d,r=t.split(/<br\s*\/?>/i).map(e=>e.trim()).filter(Boolean),a=r.length>0?r:[t],c=[];for(let e of a){let t=this.api.blocks.insert(`paragraph`,{text:e},{},this.api.blocks.getBlocksCount(),!1);i.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),c.push(t.id)}o.push(n.t({blocks:s===null?c:[...s,...c]},u))}this.stripPlaceholders(i)}),r.push(o)}),r}reclaimReferencedBlocks(){this.model.snapshot().content.forEach((e,t)=>{e.forEach((e,n)=>{if(!R(e)||e.blocks.length===0)return;let r=this.gridElement.querySelector(`[${I}="${t}"][${L}="${n}"]`);if(!r)return;let i=r.querySelector(`[${z}]`);if(i)for(let t of e.blocks){let e=this.api.blocks.getBlockIndex,n=this.api.blocks.getBlockByIndex;if(typeof e!=`function`||typeof n!=`function`)return;let a=e(t);if(a===void 0)continue;let o=n(a);o&&(i.contains(o.holder)||this.claimBlockForCell(r,t))}})})}stripPlaceholders(e){e.querySelectorAll(`[data-blok-placeholder-active]`).forEach(e=>{e.removeAttribute(`data-blok-placeholder-active`)}),e.querySelectorAll(`[data-placeholder]`).forEach(e=>{e.removeAttribute(`data-placeholder`)})}mountBlocksInCell(e,n){let r=[],i=new Map;for(let a of n){let n=this.api.blocks.getBlockIndex(a);if(n===void 0)continue;let o=this.api.blocks.getBlockByIndex(n);if(!o)continue;let s=o.parentId!=null&&o.parentId!==``&&o.parentId!==this.tableBlockId;if(o.holder.closest(`[${t.Pr.nestedBlocks}]`)||s){let t=this.api.blocks.insert(o.name,o.preservedData,{},this.api.blocks.getBlocksCount(),!1);e.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),r.push(t.id),i.set(a,t.id);continue}e.appendChild(o.holder),this.api.blocks.setBlockParent(a,this.tableBlockId),r.push(a)}return{mountedIds:r,replacements:i}}claimBlockForCell(e,n){var r,i;let a=e.querySelector(`[${z}]`);if(!a)return;let o=this.api.blocks.getBlockIndex(n);if(o===void 0)return;let s=this.api.blocks.getBlockByIndex(o);if(!s||s.holder.contains(a))return;let c=s.parentId!=null&&s.parentId!==``&&s.parentId!==this.tableBlockId;if(s.holder.closest(`[${t.Pr.nestedBlocks}]`)||c)return;let l=this.api.blocks.getBlocksCount(),u=(r=(i=Array.from({length:l-o-1},(e,t)=>this.api.blocks.getBlockByIndex(o+1+t)).find(e=>(e==null?void 0:e.holder.parentElement)===a))==null?void 0:i.holder)==null?null:r;a.insertBefore(s.holder,u),this.api.blocks.setBlockParent(n,this.tableBlockId),this.stripPlaceholders(a)}findCellForNewBlock(e){return this.findCellForAdjacentBlock(e-1)||this.findCellForAdjacentBlock(e+1)}findCellForAdjacentBlock(e){if(e<0||e>=this.api.blocks.getBlocksCount())return null;let t=this.api.blocks.getBlockByIndex(e),n=t==null?void 0:t.holder.closest(`[${F}]`);return n&&this.gridElement.contains(n)?n:null}ensureCellHasBlock(e){var t,n;let r=e.querySelector(`[${z}]`);r&&r.querySelector(`[data-blok-id]`)===null&&((t=(n=this.api.blocks).transactWithoutCapture)==null||t.call(n,()=>{let t=this.api.blocks.insert(`paragraph`,{text:``},{},this.api.blocks.getBlocksCount(),!0);r.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),this.syncBlockToModel(e,t.id),this.stripPlaceholders(r)}))}handleBlockRemoved(e){this.recordRemovedBlockCell(e);let t=e.target.id,n=this.model.findCellForBlock(t);if(!n){this.schedulePendingCellCheck();return}this.model.removeBlockFromCell(n.row,n.col,t);let r=this.getCell(n.row,n.col);r&&this.cellsPendingCheck.add(r),this.schedulePendingCellCheck()}handleBlockMoved(e){let t=e.target.id,n=this.model.findCellForBlock(t);n&&(this.gridElement.contains(e.target.holder)||this.model.removeBlockFromCell(n.row,n.col,t))}syncBlockToModel(e,t){let n=this.getCellPosition(e);n&&this.model.addBlockToCell(n.row,n.col,t)}getCellPosition(e){let t=e.closest(`[${P}]`);if(!t)return null;let n=Array.from(this.gridElement.querySelectorAll(`[${P}]`)).indexOf(t);if(n<0)return null;let r=Array.from(t.querySelectorAll(`[${F}]`)).indexOf(e);return r<0?null:{row:n,col:r}}recordRemovedBlockCell(e){if(e.index===void 0)return;let t=e.target.holder.closest(`[${F}]`);t&&this.gridElement.contains(t)&&this.removedBlockCells.set(e.target.id,{cell:t,index:e.index})}findRemovedEntryForIndex(e){for(let[t,n]of this.removedBlockCells)if(n.index===e)return this.removedBlockCells.delete(t),n;return null}getOwnedCellForBlock(e){let t=this.model.findCellForBlock(e);if(!t)return null;let n=this.getCell(t.row,t.col);return n&&this.gridElement.contains(n)?n:null}isAdjacentToThisTable(e){let t=this.api.blocks.getBlocksCount();for(let n of[-1,1]){let r=e+n;if(r<0||r>=t)continue;let i=this.api.blocks.getBlockByIndex(r);if(i&&this.getOwnedCellForBlock(i.id))return!0}if(!this.isTableBlockAtPrevIndex(e))return!1;let n=e+1;if(n>=t)return!0;let r=this.api.blocks.getBlockByIndex(n);return r?this.getOwnedCellForBlock(r.id)!==null:!0}isTableBlockAtPrevIndex(e){let t=e-1;if(t<0)return!1;let n=this.api.blocks.getBlockByIndex(t);return(n==null?void 0:n.id)===this.tableBlockId}schedulePendingCellCheck(){this.pendingCheckScheduled||(this.pendingCheckScheduled=!0,queueMicrotask(()=>{if(this.pendingCheckScheduled=!1,!this.api.blocks.isSyncingFromYjs)for(let e of this.cellsPendingCheck)this.ensureCellHasBlock(e);this.cellsPendingCheck.clear(),this.removedBlockCells.clear()}))}isBlockMutationEvent(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null}getBlockIdsFromCells(e){let t=[];return Array.from(e).forEach(e=>{let n=e.querySelector(`[${z}]`);n&&n.querySelectorAll(`[data-blok-id]`).forEach(e=>{let n=e.getAttribute(`data-blok-id`);n&&t.push(n)})}),t}deleteBlocks(e){let t=e.map(e=>this.api.blocks.getBlockIndex(e)).filter(e=>e!==void 0).sort((e,t)=>t-e),n=window.scrollY,r=t.map(e=>this.api.blocks.delete(e));Promise.all(r).then(()=>{window.scrollY!==n&&window.scrollTo(0,n)})}deleteAllBlocks(){let e=this.gridElement.querySelectorAll(`[${F}]`),t=this.getBlockIdsFromCells(e);this.deleteBlocks(t)}destroy(){this.gridElement.removeEventListener(`click`,this.handleCellBlankSpaceClick),this.api.events.off(`block changed`,this.handleBlockMutation),this._activeCellWithBlocks=null,this.cellsPendingCheck.clear(),this.removedBlockCells.clear(),this.deferredEvents.length=0}flushDeferredEvents(){let e=[...this.deferredEvents];this.deferredEvents.length=0;for(let t of e)this.handleBlockMutation(t)}discardDeferredEvents(){this.deferredEvents.length=0}};function Pt(){var e,n;let r=document.documentElement.getAttribute(`data-blok-theme`);return r===`dark`?t.xn:r===`light`?t.bn:typeof window<`u`&&(e=(n=window).matchMedia)!=null&&e.call(n,`(prefers-color-scheme: dark)`).matches?t.xn:t.bn}function Ft(e,n){if(e===n)return!0;let r=t.yn(e),i=t.yn(n);return r===null||i===null?!1:r[0]===i[0]&&r[1]===i[1]&&r[2]===i[2]}var It=`var(--blok-swatch-neutral-bg)`;function Lt(e){let{i18n:n,modes:i,testIdPrefix:a,onColorSelect:o}=e,s={activeColors:Object.fromEntries(i.map(e=>[e.key,null]))},c=document.createElement(`div`);c.setAttribute(`data-blok-testid`,`${a}-picker`),c.className=`flex flex-col gap-3 p-2`;let l=[];i.forEach(e=>{let t=document.createElement(`div`);t.setAttribute(`data-blok-testid`,`${a}-section-${e.key}`),t.className=`flex flex-col gap-1`;let r=document.createElement(`div`);r.className=`text-xs font-medium text-text-primary/60 px-0.5`,r.textContent=n.t(e.labelKey);let i=document.createElement(`div`);i.className=`grid gap-1`,i.style.gridTemplateColumns=`repeat(5, 2.25rem)`,l.push(i),t.appendChild(r),t.appendChild(i),c.appendChild(t)});let u=e=>{let c=l[e],u=i[e],d=Pt();c.innerHTML=``;let f=s.activeColors[u.key],p=document.createElement(`button`),m=f===null;p.setAttribute(`data-blok-testid`,`${a}-swatch-${u.key}-default`),p.className=r.n(`w-9 h-9 rounded-md cursor-pointer border-none outline-hidden`,`flex items-center justify-center text-sm font-semibold`,`transition-[box-shadow,transform] ring-inset hover:ring-2 hover:ring-swatch-ring-hover active:scale-90`,m&&`ring-2 ring-swatch-ring-hover`),p.textContent=u.presetField===`text`?`A`:``,u.presetField===`text`&&(p.style.color=`var(--blok-text-primary)`),p.style.backgroundColor=It,p.addEventListener(`click`,()=>{o(null,u.key)});let h=n.t(`tools.colorPicker.defaultSwatchLabel`).replace(`{default}`,n.t(`tools.marker.default`)).replace(`{mode}`,n.t(u.labelKey).toLowerCase());t.An(p,h.charAt(0).toUpperCase()+h.slice(1),{placement:`top`}),c.appendChild(p);for(let e of d){let i=document.createElement(`button`),s=u.presetField===`text`?e.text:e.bg,l=f!==null&&Ft(s,f);i.setAttribute(`data-blok-testid`,`${a}-swatch-${u.key}-${e.name}`),i.className=r.n(`w-9 h-9 rounded-md cursor-pointer border-none outline-hidden`,`flex items-center justify-center text-sm font-semibold`,`transition-[box-shadow,transform] ring-inset hover:ring-2 hover:ring-swatch-ring-hover active:scale-90`,l&&`ring-2 ring-swatch-ring-hover`),i.textContent=u.presetField===`text`?`A`:``,u.presetField===`text`?(i.style.color=e.text,i.style.backgroundColor=It):(i.style.color=d===t.xn?e.text:`#37352f`,i.style.backgroundColor=e.bg),i.addEventListener(`click`,()=>{o(s,u.key)});let p=n.t(`tools.colorPicker.colorSwatchLabel`).replace(`{color}`,n.t(`tools.colorPicker.color.`+e.name)).replace(`{mode}`,n.t(u.labelKey).toLowerCase());t.An(i,p.charAt(0).toUpperCase()+p.slice(1),{placement:`top`}),c.appendChild(i)}},d=()=>{i.forEach((e,t)=>u(t))};return d(),{element:c,setActiveColor:(e,t)=>{let n=i.findIndex(e=>e.key===t);n!==-1&&(s.activeColors[t]=e,u(n))},reset:()=>{for(let e of i)s.activeColors[e.key]=null;d()}}}var Rt=e=>{let t=Lt({i18n:e.i18n,testIdPrefix:`cell-color`,modes:[{key:`textColor`,labelKey:`tools.marker.textColor`,presetField:`text`},{key:`backgroundColor`,labelKey:`tools.marker.background`,presetField:`bg`}],onColorSelect:(n,r)=>{t.setActiveColor(n,r),e.onColorSelect(n,r)}});return{element:t.element}},zt=[`top-left`,`top-center`,`top-right`,`middle-left`,`middle-center`,`middle-right`,`bottom-left`,`bottom-center`,`bottom-right`],Bt={"top-left":`tools.table.placementTopLeft`,"top-center":`tools.table.placementTopCenter`,"top-right":`tools.table.placementTopRight`,"middle-left":`tools.table.placementMiddleLeft`,"middle-center":`tools.table.placementMiddleCenter`,"middle-right":`tools.table.placementMiddleRight`,"bottom-left":`tools.table.placementBottomLeft`,"bottom-center":`tools.table.placementBottomCenter`,"bottom-right":`tools.table.placementBottomRight`},Vt={top:`flex-start`,middle:`center`,bottom:`flex-end`},Ht={left:`flex-start`,center:`center`,right:`flex-end`},Ut=e=>{var t;let n=(t=e.currentPlacement)==null?`top-left`:t,r=document.createElement(`div`);r.style.padding=`8px`;let i=document.createElement(`div`);i.style.display=`grid`,i.style.gridTemplateColumns=`repeat(3, 1fr)`,i.style.gap=`3px`;let a=document.createElement(`div`);a.style.textAlign=`center`,a.style.fontSize=`11px`,a.style.marginTop=`6px`,a.style.color=`var(--blok-text-secondary, #707684)`,a.textContent=e.i18n.t(Bt[n]);for(let t of zt){let[r,o]=t.split(`-`),s=document.createElement(`div`);s.setAttribute(`data-placement`,t),s.style.width=`32px`,s.style.height=`26px`,s.style.borderRadius=`3px`,s.style.display=`flex`,s.style.flexDirection=`column`,s.style.alignItems=Ht[o],s.style.justifyContent=Vt[r],s.style.padding=`3px`,s.style.cursor=`pointer`,s.style.gap=`1px`,t===n?(s.setAttribute(`data-active`,`true`),s.style.outline=`2px solid var(--blok-color-primary, #388AE5)`,s.style.outlineOffset=`-2px`,s.style.backgroundColor=`var(--blok-item-focus-bg, rgba(35, 131, 226, 0.14))`):s.style.backgroundColor=`var(--blok-bg-light, #eff2f5)`;let c=document.createElement(`div`);c.style.width=`14px`,c.style.height=`2px`,c.style.borderRadius=`1px`,c.style.backgroundColor=`currentColor`,c.style.opacity=`0.6`;let l=document.createElement(`div`);l.style.width=`9px`,l.style.height=`2px`,l.style.borderRadius=`1px`,l.style.backgroundColor=`currentColor`,l.style.opacity=`0.3`,s.appendChild(c),s.appendChild(l),s.addEventListener(`click`,()=>{i.querySelectorAll(`[data-placement]`).forEach(e=>{let t=e;t.removeAttribute(`data-active`),t.style.outline=``,t.style.outlineOffset=``,t.style.backgroundColor=`var(--blok-bg-tertiary, #f0f0f0)`}),s.setAttribute(`data-active`,`true`),s.style.outline=`2px solid var(--blok-color-primary, #388AE5)`,s.style.outlineOffset=`-2px`,s.style.backgroundColor=`var(--blok-item-focus-bg, rgba(35, 131, 226, 0.14))`,a.textContent=e.i18n.t(Bt[t]),e.onPlacementSelect(t)}),i.appendChild(s)}return r.appendChild(i),r.appendChild(a),{element:r}},Wt=(e,t,n)=>{t===`col`?Object.assign(e.style,{height:`${n}px`}):Object.assign(e.style,{width:`${n}px`})},Gt=[[2,2],[8,2],[2,7],[8,7],[2,12],[8,12]],Kt=[[2,2],[7,2],[12,2],[2,8],[7,8],[12,8]],qt=e=>{let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),n=e===`horizontal`;t.setAttribute(`width`,n?`14`:`10`),t.setAttribute(`height`,n?`10`:`14`),t.setAttribute(`viewBox`,n?`0 0 14 10`:`0 0 10 14`),t.setAttribute(`fill`,`currentColor`),t.classList.add(`opacity-0`,`transition-opacity`,`duration-150`,`text-gray-400`,`pointer-events-none`);let r=n?Kt:Gt;for(let[e,n]of r){let r=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`);r.setAttribute(`cx`,String(e)),r.setAttribute(`cy`,String(n)),r.setAttribute(`r`,`1.5`),t.appendChild(r)}return t},Jt=(e,t)=>{t===`col`?Object.assign(e.style,{height:`16px`}):Object.assign(e.style,{width:`16px`}),e.classList.add(`bg-gray-200`),e.classList.remove(`bg-gray-300`);let n=e.querySelector(`svg`);n&&(n.classList.remove(`opacity-0`),n.classList.add(`opacity-100`))},Yt=(e,t,n)=>{Wt(e,t,n),e.classList.remove(`bg-gray-200`),e.classList.add(`bg-gray-300`);let r=e.querySelector(`svg`);r&&(r.classList.add(`opacity-0`),r.classList.remove(`opacity-100`))},Xt=`data-blok-table-cell-selected`,Zt=`2px solid #3b82f6`,Qt=`data-blok-table-selection-pill`,$t=16,en=20,tn=4,nn=[`absolute`,`z-3`,`rounded-sm`,`select-none`,`transition-[opacity,background-color,width]`,`duration-150`,`flex`,`items-center`,`justify-center`,`overflow-hidden`,`cursor-pointer`,`bg-blue-500`],rn=e=>e.style.userSelect===`none`,an=class{constructor(e){this.anchorCell=null,this.extentCell=null,this.isSelecting=!1,this.hasSelection=!1,this.selectedCells=[],this.overlay=null,this.pill=null,this.pillPopover=null,this.resizeObserver=null,this.lastPaintedRange=null,this.preExpansionWasSingleCell=!1,this.grid=e.grid,this.rectangleSelection=e.rectangleSelection,this.onSelectionActiveChange=e.onSelectionActiveChange,this.onClearContent=e.onClearContent,this.onCopy=e.onCopy,this.onCut=e.onCut,this.onCopyViaButton=e.onCopyViaButton,this.onColorChange=e.onColorChange,this.onPlacementChange=e.onPlacementChange,this.getCellPlacement=e.getCellPlacement,this.onSelectionRangeChange=e.onSelectionRangeChange,this.onPointerDragActiveChange=e.onPointerDragActiveChange,this.isPopoverOpen=e.isPopoverOpen,this.canMergeCells=e.canMergeCells,this.onMergeCells=e.onMergeCells,this.isMergedCell=e.isMergedCell,this.onSplitCell=e.onSplitCell,this.getCellSpan=e.getCellSpan,this.i18n=e.i18n,this.grid.style.position=`relative`,this.boundPointerDown=this.handlePointerDown.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundClearSelection=this.handleClearSelection.bind(this),this.boundCancelRectangle=this.handleCancelRectangle.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this),this.boundCopyHandler=this.handleCopy.bind(this),this.boundCutHandler=this.handleCut.bind(this),this.boundPreventDragStart=this.handleDragStart.bind(this),this.grid.addEventListener(`pointerdown`,this.boundPointerDown),this.grid.addEventListener(`dragstart`,this.boundPreventDragStart),document.addEventListener(`keydown`,this.boundKeyDown),document.addEventListener(`copy`,this.boundCopyHandler),document.addEventListener(`cut`,this.boundCutHandler)}destroy(){if(this.destroyPillPopover(),this.disconnectResizeObserver(),this.clearSelection(),this.anchorCell){var e;(e=this.onPointerDragActiveChange)==null||e.call(this,!1),this.grid.style.userSelect=``}this.grid.removeEventListener(`pointerdown`,this.boundPointerDown),this.grid.removeEventListener(`dragstart`,this.boundPreventDragStart),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerUp),document.removeEventListener(`pointerdown`,this.boundClearSelection),document.removeEventListener(`mousemove`,this.boundCancelRectangle,!0),document.removeEventListener(`keydown`,this.boundKeyDown),document.removeEventListener(`copy`,this.boundCopyHandler),document.removeEventListener(`cut`,this.boundCutHandler)}selectRow(e){let t=this.getLogicalColumnCount();t!==0&&this.showProgrammaticSelection(e,0,e,t-1)}selectColumn(e){let t=this.grid.querySelectorAll(`[${P}]`).length;t!==0&&this.showProgrammaticSelection(0,e,t-1,e)}clearActiveSelection(){this.clearSelection()}getSelectedRange(){return this.hasSelection?this.lastPaintedRange:null}selectRange(e){this.showProgrammaticSelection(e.minRow,e.minCol,e.maxRow,e.maxCol)}handleDragStart(e){this.anchorCell&&e.preventDefault()}handlePointerDown(e){var t;if(rn(this.grid)||e.button!==0)return;let n=e.target;if(n.closest(`[data-blok-table-grip]`)||n.closest(`[data-blok-table-resize]`)||n.closest(`[${Qt}]`))return;let r=this.resolveCellCoord(n);r&&(this.hasSelection&&this.lastPaintedRange!==null&&this.lastPaintedRange.minRow===r.row&&this.lastPaintedRange.maxRow===r.row&&this.lastPaintedRange.minCol===r.col&&this.lastPaintedRange.maxCol===r.col?document.removeEventListener(`pointerdown`,this.boundClearSelection):this.hasSelection&&this.clearSelection(),this.anchorCell=r,this.isSelecting=!1,(t=this.onPointerDragActiveChange)==null||t.call(this,!0),document.addEventListener(`mousemove`,this.boundCancelRectangle,!0),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerUp))}handlePointerMove(e){if(!this.anchorCell)return;let t=document.elementFromPoint(e.clientX,e.clientY);if(!t)return;let n=this.resolveCellCoord(t);if(!n){this.clampExtentToEdge(e);return}if(!(!this.isSelecting&&n.row===this.anchorCell.row&&n.col===this.anchorCell.col)){if(!this.isSelecting){var r,i;this.isSelecting=!0,(r=this.onSelectionActiveChange)==null||r.call(this,!0),this.grid.style.userSelect=`none`,(i=window.getSelection())==null||i.removeAllRanges()}(!this.extentCell||this.extentCell.row!==n.row||this.extentCell.col!==n.col)&&(this.extentCell=n,this.paintSelection())}}handleCancelRectangle(e){if(!this.rectangleSelection)return;this.rectangleSelection.cancelActiveSelection();let t=document.querySelector(`[data-blok-overlay-rectangle]`);if(!t)return;let n=t;n.style.display=`none`}handlePointerUp(){var e;if(document.removeEventListener(`mousemove`,this.boundCancelRectangle,!0),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerUp),(e=this.onPointerDragActiveChange)==null||e.call(this,!1),this.isSelecting){if(this.grid.style.userSelect=``,this.hasSelection=!0,this.lastPaintedRange){var t;(t=this.onSelectionRangeChange)==null||t.call(this,this.lastPaintedRange)}document.addEventListener(`pointerdown`,this.boundClearSelection)}else this.anchorCell&&(this.hasSelection?document.addEventListener(`pointerdown`,this.boundClearSelection):this.showProgrammaticSelection(this.anchorCell.row,this.anchorCell.col,this.anchorCell.row,this.anchorCell.col));this.isSelecting=!1,this.anchorCell=null,this.extentCell=null}handleClearSelection(e){let t=e.target;t instanceof HTMLElement&&t.closest(`[${Qt}]`)||t instanceof HTMLElement&&t.closest(`[data-blok-popover-opened]`)!==null||(this.pillPopover!==null&&this.destroyPillPopover(),document.removeEventListener(`pointerdown`,this.boundClearSelection),this.clearSelection())}handleKeyDown(e){var t;this.hasSelection&&(e.key!==`Delete`&&e.key!==`Backspace`||this.selectedCells.length<=1||(e.preventDefault(),(t=this.onClearContent)==null||t.call(this,[...this.selectedCells]),this.clearSelection()))}handleCopy(e){var t;!this.hasSelection||!e.clipboardData||this.selectedCells.length<=1&&this.hasNativeTextSelection()||(e.preventDefault(),(t=this.onCopy)==null||t.call(this,[...this.selectedCells],e.clipboardData))}handleCut(e){var t,n;!this.hasSelection||!e.clipboardData||this.selectedCells.length<=1&&this.hasNativeTextSelection()||(e.preventDefault(),(t=this.onCut)==null||t.call(this,[...this.selectedCells],e.clipboardData),(n=this.onClearContent)==null||n.call(this,[...this.selectedCells]),this.clearSelection())}hasNativeTextSelection(){let e=window.getSelection();return e!==null&&!e.isCollapsed}clearSelection(){let e=this.hasSelection;if(this.restoreModifiedCells(),this.hasSelection=!1,this.lastPaintedRange=null,this.preExpansionWasSingleCell=!1,e){var t;(t=this.onSelectionActiveChange)==null||t.call(this,!1)}}restoreModifiedCells(){this.destroyPillPopover(),this.disconnectResizeObserver(),this.selectedCells.forEach(e=>{e.removeAttribute(Xt)}),this.pill&&(this.pill.remove(),this.pill=null),this.overlay&&(this.overlay.remove(),this.overlay=null),this.selectedCells=[]}showProgrammaticSelection(e,t,n,r){var i;if(this.clearSelection(),this.anchorCell={row:e,col:t},this.extentCell={row:n,col:r},this.paintSelection(),this.hasSelection=!0,(i=this.onSelectionActiveChange)==null||i.call(this,!0),this.lastPaintedRange){var a;(a=this.onSelectionRangeChange)==null||a.call(this,this.lastPaintedRange)}this.anchorCell=null,this.extentCell=null,document.addEventListener(`pointerdown`,this.boundClearSelection)}expandRectToMergedSpans(e){return this.getCellSpan?this.expandRectStep(e):e}expandRectStep(e){let t=this.getCellSpan;if(!t)return e;let n=Array.from({length:e.maxRow-e.minRow+1},(t,n)=>e.minRow+n),r=Array.from({length:e.maxCol-e.minCol+1},(t,n)=>e.minCol+n),i=n.reduce((e,n)=>r.reduce((e,r)=>{let{colspan:i,rowspan:a}=t(n,r);return{minRow:e.minRow,maxRow:Math.max(e.maxRow,n+a-1),minCol:e.minCol,maxCol:Math.max(e.maxCol,r+i-1)}},e),e);return i.maxRow!==e.maxRow||i.maxCol!==e.maxCol?this.expandRectStep(i):i}paintSelection(){if(!this.anchorCell||!this.extentCell)return;this.selectedCells.forEach(e=>{e.removeAttribute(Xt)}),this.selectedCells=[];let e=Math.min(this.anchorCell.row,this.extentCell.row),t=Math.max(this.anchorCell.row,this.extentCell.row),n=Math.min(this.anchorCell.col,this.extentCell.col),r=Math.max(this.anchorCell.col,this.extentCell.col);this.preExpansionWasSingleCell=e===t&&n===r,this.lastPaintedRange=this.expandRectToMergedSpans({minRow:e,maxRow:t,minCol:n,maxCol:r});let{minRow:i,maxRow:a,minCol:o,maxCol:s}=this.lastPaintedRange,c=this.grid.querySelectorAll(`[${P}]`);this.selectedCells=this.collectCellsInRange(c,i,a,o,s),this.selectedCells.forEach(e=>{e.setAttribute(Xt,``)});let l=this.findCellByCoordOrIndex(c,i,o),u=this.findCellByCoordOrIndex(c,a,s);if(!l||!u)return;let d=this.grid.getBoundingClientRect(),f=l.getBoundingClientRect(),p=u.getBoundingClientRect(),m=getComputedStyle(this.grid),h=parseFloat(m.borderTopWidth)||0,g=parseFloat(m.borderLeftWidth)||0,_=p.right-f.left+1,v=p.bottom-f.top+1,y=f.top-d.top-h-1,b=f.left-d.left-g-1;this.overlay||(this.overlay=document.createElement(`div`),this.overlay.setAttribute(`data-blok-table-selection-overlay`,``),this.overlay.style.position=`absolute`,this.overlay.style.border=Zt,this.overlay.style.pointerEvents=`none`,this.overlay.style.boxSizing=`border-box`,this.overlay.style.borderRadius=`2px`,this.grid.appendChild(this.overlay)),this.overlay.style.top=`${y}px`,this.overlay.style.left=`${b}px`,this.overlay.style.width=`${_}px`,this.overlay.style.height=`${v}px`,this.pill||(this.pill=this.createPill(),this.grid.appendChild(this.pill)),this.pill.style.left=`${b+_-1}px`,this.pill.style.top=`${y+v/2}px`,this.observeCellResizes()}repositionOverlay(){let e=this.lastPaintedRange;if(!e||!this.overlay)return;let t=this.grid.querySelectorAll(`[${P}]`),n=this.findCellByCoordOrIndex(t,e.minRow,e.minCol),r=this.findCellByCoordOrIndex(t,e.maxRow,e.maxCol);if(!n||!r)return;let i=this.grid.getBoundingClientRect(),a=n.getBoundingClientRect(),o=r.getBoundingClientRect(),s=getComputedStyle(this.grid),c=parseFloat(s.borderTopWidth)||0,l=parseFloat(s.borderLeftWidth)||0,u=o.right-a.left+1,d=o.bottom-a.top+1,f=a.top-i.top-c-1,p=a.left-i.left-l-1;this.overlay.style.top=`${f}px`,this.overlay.style.left=`${p}px`,this.overlay.style.width=`${u}px`,this.overlay.style.height=`${d}px`,this.pill&&(this.pill.style.left=`${p+u-1}px`,this.pill.style.top=`${f+d/2}px`)}observeCellResizes(){if(this.disconnectResizeObserver(),this.selectedCells.length!==0){this.resizeObserver=new ResizeObserver(()=>{this.repositionOverlay()});for(let e of this.selectedCells)this.resizeObserver.observe(e)}}disconnectResizeObserver(){this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}createPill(){let e=document.createElement(`div`);e.setAttribute(Qt,``),e.setAttribute(`contenteditable`,`false`),e.className=r.n(nn),e.style.width=`${tn}px`,e.style.height=`${en}px`,e.style.pointerEvents=`auto`,e.style.transform=`translate(-50%, -50%)`,e.style.outline=`2px solid var(--blok-table-grip-outline, transparent)`;let t=qt(`vertical`);return t.classList.remove(`text-gray-400`),t.classList.add(`text-white`),e.appendChild(t),e.addEventListener(`mouseenter`,()=>{this.pillPopover===null&&this.expandPill()}),e.addEventListener(`mouseleave`,()=>{this.pillPopover===null&&this.collapsePill()}),e.addEventListener(`pointerdown`,e=>{e.stopPropagation(),e.preventDefault(),this.openPillPopover()}),e}openPillPopover(){if(this.destroyPillPopover(),!this.pill)return;this.expandPill();let e=t.Hn===`Meta`?`⌘C`:`Ctrl+C`,n=[];if(this.onColorChange!==void 0){let{element:e}=Rt({i18n:this.i18n,onColorSelect:(e,t)=>{var n;(n=this.onColorChange)==null||n.call(this,[...this.selectedCells],e,t)}});n.push({icon:t.Ft,title:this.i18n.t(`tools.table.cellColor`),name:`cellColor`,children:{items:[{type:t.Ln.Html,element:e}],isFlippable:!1}})}let r=[];if(this.onPlacementChange!==void 0){let e=this.lastPaintedRange&&this.getCellPlacement?this.getCellPlacement(this.lastPaintedRange.minRow,this.lastPaintedRange.minCol):void 0,{element:n}=Ut({i18n:this.i18n,currentPlacement:e,onPlacementSelect:e=>{var t;(t=this.onPlacementChange)==null||t.call(this,[...this.selectedCells],e)}});r.push({icon:t.Vt,title:this.i18n.t(`tools.table.placement`),name:`cellPlacement`,children:{items:[{type:t.Ln.Html,element:n}],isFlippable:!1}})}let i=[];if(this.lastPaintedRange&&this.onMergeCells){var a;let e=this.lastPaintedRange;(e.minRow!==e.maxRow||e.minCol!==e.maxCol)&&!this.preExpansionWasSingleCell&&(a=this.canMergeCells)!=null&&a.call(this,e)&&i.push({icon:t.Lt,title:this.i18n.t(`tools.table.mergeCells`),closeOnActivate:!0,onActivate:()=>{var t;(t=this.onMergeCells)==null||t.call(this,e),this.clearSelection()}})}if(this.lastPaintedRange&&this.onSplitCell){var o,s;let e=this.lastPaintedRange,n=e.minRow===e.maxRow&&e.minCol===e.maxCol,r=this.preExpansionWasSingleCell&&((o=this.isMergedCell)==null?void 0:o.call(this,e.minRow,e.minCol));(n||r)&&(s=this.isMergedCell)!=null&&s.call(this,e.minRow,e.minCol)&&i.push({icon:t.Jt,title:this.i18n.t(`tools.table.splitCell`),closeOnActivate:!0,onActivate:()=>{var t;(t=this.onSplitCell)==null||t.call(this,e.minRow,e.minCol),this.clearSelection()}})}this.pillPopover=new t.g({items:[...n,...r,...i,{icon:t.H,title:this.i18n.t(`tools.table.copySelection`),secondaryLabel:e,closeOnActivate:!0,onActivate:()=>{var e;(e=this.onCopyViaButton)==null||e.call(this,[...this.selectedCells])}},{icon:t.W,title:this.i18n.t(`tools.table.clearSelection`),secondaryLabel:`Del`,closeOnActivate:!0,onActivate:()=>{var e;(e=this.onClearContent)==null||e.call(this,[...this.selectedCells]),this.clearSelection()}}],trigger:this.pill,flippable:!0}),this.pillPopover.on(t.v.Closed,()=>{this.pillPopover!==null&&(this.destroyPillPopover(),this.collapsePill())}),this.pillPopover.show()}expandPill(){if(!this.pill)return;this.pill.style.width=`${$t}px`;let e=this.pill.querySelector(`svg`);e&&(e.classList.remove(`opacity-0`),e.classList.add(`opacity-100`))}collapsePill(){if(!this.pill)return;this.pill.style.width=`${tn}px`;let e=this.pill.querySelector(`svg`);e&&(e.classList.add(`opacity-0`),e.classList.remove(`opacity-100`))}destroyPillPopover(){if(this.pillPopover!==null){let e=this.pillPopover;this.pillPopover=null,e.destroy()}}resolveCellCoord(e){let t=e.closest(`[${F}]`);if(!t)return null;let n=t.closest(`[${P}]`);if(!n||!this.grid.contains(n))return null;let r=t.getAttribute(I),i=t.getAttribute(L);if(r!==null&&i!==null){let e=parseInt(r,10),t=parseInt(i,10);if(!isNaN(e)&&!isNaN(t))return{row:e,col:t}}let a=Array.from(this.grid.querySelectorAll(`[${P}]`)).indexOf(n);if(a<0)return null;let o=Array.from(n.querySelectorAll(`[${F}]`)).indexOf(t);return o<0?null:{row:a,col:o}}clampExtentToEdge(e){var t,n,r,i;if(!this.anchorCell||!this.isSelecting)return;let a=this.grid.getBoundingClientRect(),o=this.grid.querySelectorAll(`[${P}]`).length,s=this.getLogicalColumnCount();if(o===0||s===0)return;let c={row:this.clampAxis(e.clientY,a.top,a.bottom,o,(t=(n=this.extentCell)==null?void 0:n.row)==null?this.anchorCell.row:t),col:this.clampAxis(e.clientX,a.left,a.right,s,(r=(i=this.extentCell)==null?void 0:i.col)==null?this.anchorCell.col:r)};(!this.extentCell||this.extentCell.row!==c.row||this.extentCell.col!==c.col)&&(this.extentCell=c,this.paintSelection())}collectCellsInRange(e,t,n,r,i){if(this.grid.querySelector(`[data-blok-table-cell-row]`)===null)return Array.from(e).slice(t,n+1).flatMap(e=>{let t=e.querySelectorAll(`[${F}]`);return Array.from(t).slice(r,i+1).filter(e=>e instanceof HTMLElement)});let a=this.grid.querySelectorAll(`[${F}]`);return Array.from(a).filter(e=>{let a=e.getAttribute(I),o=e.getAttribute(L);if(a===null||o===null)return!1;let s=Number(a),c=Number(o),l=e,u=s+(l.rowSpan||1)-1,d=c+(l.colSpan||1)-1;return s<=n&&u>=t&&c<=i&&d>=r})}findCellByCoordOrIndex(e,t,n){var r,i,a;return this.grid.querySelector(`[${I}="${t}"][${L}="${n}"]`)||((r=e[t])==null?void 0:r.querySelectorAll(`[${F}]`)[n])||Array.from((i=(a=e[t])==null?void 0:a.querySelectorAll(`[data-blok-table-cell]`))==null?[]:i).find(e=>{let t=Number(e.getAttribute(L)),r=e.colSpan||1;return t<=n&&t+r-1>=n})}getLogicalColumnCount(){var e,t;let n=(e=this.grid.querySelector(`colgroup`))==null?void 0:e.querySelectorAll(`col`).length;if(n!==void 0&&n>0)return n;let r=this.grid.querySelector(`[${P}]`);return(t=r==null?void 0:r.querySelectorAll(`[data-blok-table-cell]`).length)==null?0:t}clampAxis(e,t,n,r,i){return e<t?0:e>n?r-1:i}},B=e=>{let t=e.querySelector(`colgroup`);if(!t)return[];let n=t.querySelectorAll(`col`),r=n[0];if(r&&r.style.width.endsWith(`%`)){let t=e.querySelector(`[${P}]`);if(t)return Array.from(t.querySelectorAll(`[${F}]`)).map(e=>Math.round(e.getBoundingClientRect().width))}return Array.from(n).map(e=>parseFloat(e.style.width)||0)},V=(e,t)=>{let n=t.reduce((e,t)=>e+t,0),r=e;r.style.width=`${n+1}px`;let i=e.querySelector(`colgroup`);if(!i)return;let a=Array.from(i.querySelectorAll(`col`));t.forEach((e,t)=>{t<a.length&&(a[t].style.width=`${e}px`)})},on=(e,t)=>{let n=Array.from(e.querySelectorAll(`[${P}]`)),r=n.findIndex(e=>Array.from(e.querySelectorAll(`[${F}]`)).includes(t));return r===-1?null:{row:r,col:Array.from(n[r].querySelectorAll(`[${F}]`)).indexOf(t)}},sn=e=>{var t;let n=e.querySelector(`[${z}]`);return n?((t=n.textContent)==null?``:t).trim().length===0:!0},cn=(e,t)=>{let n=e.querySelectorAll(`[${P}]`)[t];if(!n)return!0;let r=n.querySelectorAll(`[${F}]`);return Array.from(r).every(e=>sn(e))},ln=(e,t)=>{let n=e.querySelectorAll(`[${P}]`);return Array.from(n).every(e=>{let n=e.querySelector(`[${L}="${t}"]`);return!n||sn(n)})},un=e=>{let t=e.querySelector(`colgroup`);if(!t)return;let n=t.querySelectorAll(`col`),r=Array.from(n).reduce((e,t)=>e+(parseFloat(t.style.width)||0),0);if(r<=0)return;let i=100/r;n.forEach(e=>{let t=e,n=parseFloat(t.style.width)||0;t.style.width=`${Math.round(n*i*100)/100}%`})},dn=(e,t,n)=>{if(!e)return e;let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r},fn=(e,t)=>{if(!e)return e;let n=[...e];return n.splice(t,1),n.length>0?n:void 0},pn=(e,t,n,r,i)=>{let a=n==null?B(e):n,o=r===void 0?mn(a):Math.round(r/2*100)/100;i.addColumn(e,t,a,o);let s=[...a];return s.splice(t,0,o),s},mn=e=>Math.round(e.reduce((e,t)=>e+t,0)/e.length/2*100)/100,hn=e=>e.length===0?0:Math.round(e.reduce((e,t)=>e+t,0)/e.length*100)/100,gn=(e,t,n)=>{var r;if(!e)return[];let i=e.querySelectorAll(`[${P}]`)[n];return i?(r=t==null?void 0:t.getBlockIdsFromCells(i.querySelectorAll(`[data-blok-table-cell]`)))==null?[]:r:[]},_n=(e,t,n)=>{var r;if(!e)return[];let i=e.querySelectorAll(`[${P}]`),a=[];return i.forEach(e=>{let t=e.querySelector(`[${L}="${n}"]`);t&&a.push(t)}),(r=t==null?void 0:t.getBlockIdsFromCells(a))==null?[]:r},H=(e,t)=>{e.querySelectorAll(`[${F}]`).forEach(e=>{t==null||t.ensureCellHasBlock(e)})},vn=(e,n,r,i)=>{let a=e.querySelectorAll(`[${P}]`);n.forEach((e,n)=>{let o=a[n];o&&e.forEach((e,n)=>{var a;let s=o.querySelector(`[${L}="${n}"]`);if(!s)return;let c=s.querySelector(`[${z}]`);if(!c)return;let l=c.querySelectorAll(`[data-blok-id]`).length>0;if(!(!R(e)&&l)){if(!R(e)){let t=document.createElement(`div`);t.className=`leading-[1.5]`,t.innerHTML=e,c.replaceChildren(t);return}(l||((a=c.textContent)==null?``:a).length>0)&&c.replaceChildren();for(let n of e.blocks){let e=r.blocks.getBlockIndex(n);if(e===void 0)continue;let a=r.blocks.getBlockByIndex(e);if(a&&!(a.parentId!==null&&a.parentId!==void 0&&a.parentId!==i)){if(a.holder.closest(`[${t.Pr.nestedBlocks}]`)){c.appendChild(a.holder.cloneNode(!0));continue}c.appendChild(a.holder)}}c.querySelectorAll(`[data-blok-placeholder-active]`).forEach(e=>{e.removeAttribute(`data-blok-placeholder-active`)}),c.querySelectorAll(`[data-placeholder]`).forEach(e=>{e.removeAttribute(`data-placeholder`)})}})})},yn=(e,t)=>{var n,r,i,a,o,s,c;if(!(typeof e==`object`&&e&&`content`in e)){var l,u;return{withHeadings:(l=t.withHeadings)==null?!1:l,withHeadingColumn:!1,stretched:(u=t.stretched)==null?!1:u,content:[]}}let d=e,f=(n=d.content)==null||(n=n[0])==null?void 0:n.length,p=d.colWidths,m=p&&f&&p.length===f?p:void 0;return{withHeadings:(r=(i=d.withHeadings)==null?t.withHeadings:i)==null?!1:r,withHeadingColumn:(a=d.withHeadingColumn)==null?!1:a,stretched:(o=(s=d.stretched)==null?t.stretched:s)==null?!1:o,content:(c=d.content)==null?[]:c,colWidths:m,initialColWidth:d.initialColWidth}},bn=(e,t)=>{let n=n=>{let r=n.target.closest(`[${F}]`);if(!r)return;let i=on(e,r);i&&(t==null||t.handleKeyDown(n,i))};return e.addEventListener(`keydown`,n),()=>{e.removeEventListener(`keydown`,n)}},xn=[`overflow-x-auto`,`overflow-y-hidden`],Sn=e=>{e==null||e.classList.add(...xn)},Cn=(e,t)=>{if(!e)return;let n=e.querySelectorAll(`[${P}]`);n.forEach(e=>{e.removeAttribute(`data-blok-table-heading`)}),t&&n.length>0&&n[0].setAttribute(`data-blok-table-heading`,``)},wn=(e,t)=>{let n=e.querySelectorAll(`[${P}]`);t.forEach((e,t)=>{t>=n.length||e.forEach((e,r)=>{let i=n[t].querySelector(`[${L}="${r}"]`);i&&(R(e)&&e.color?i.style.backgroundColor=e.color:i.style.backgroundColor=``,R(e)&&e.textColor?i.style.color=e.textColor:i.style.color=``)})})},Tn=(e,t)=>{let n=e.querySelectorAll(`[${P}]`);t.forEach((e,t)=>{t>=n.length||e.forEach((e,r)=>{let i=n[t].querySelector(`[${L}="${r}"]`);if(!i)return;let a=i.querySelector(`[${z}]`);a&&(R(e)&&e.placement&&e.placement!==`top-left`?a.setAttribute(`data-blok-cell-placement`,e.placement):a.removeAttribute(`data-blok-cell-placement`))})})},U=(e,t)=>{e&&(e.querySelectorAll(`[${F}]`).forEach(e=>{e.removeAttribute(`data-blok-table-heading-col`)}),t&&e.querySelectorAll(`[${P}]`).forEach(e=>{let t=e.querySelector(`[${F}]`);t&&t.setAttribute(`data-blok-table-heading-col`,``)}))},En=e=>!!(/^#[0-9a-f]{3,4}$/i.test(e)||/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e)||/^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*(,\s*[\d.]+\s*)?\)$/i.test(e)||/^hsla?\(\s*[\d.]+\s*,\s*[\d.]+%\s*,\s*[\d.]+%\s*(,\s*[\d.]+\s*)?\)$/i.test(e)||e===`transparent`),Dn=class{constructor(e){var t,n,r;this.withHeadingsValue=(t=e==null?void 0:e.withHeadings)==null?!1:t,this.withHeadingColumnValue=(n=e==null?void 0:e.withHeadingColumn)==null?!1:n,this.stretchedValue=(r=e==null?void 0:e.stretched)==null?!1:r,this.colWidthsValue=e!=null&&e.colWidths?[...e.colWidths]:void 0,this.initialColWidthValue=e==null?void 0:e.initialColWidth,this.contentGrid=this.normalizeContent(e==null?void 0:e.content),this.blockCellMap=new Map,this.rebuildBlockCellMap()}get rows(){return this.contentGrid.length}get cols(){return this.contentGrid.length>0?this.contentGrid[0].length:0}get withHeadings(){return this.withHeadingsValue}get withHeadingColumn(){return this.withHeadingColumnValue}get stretched(){return this.stretchedValue}get colWidths(){return this.colWidthsValue?[...this.colWidthsValue]:void 0}get initialColWidth(){return this.initialColWidthValue}snapshot(){let e={withHeadings:this.withHeadingsValue,withHeadingColumn:this.withHeadingColumnValue,stretched:this.stretchedValue,content:this.contentGrid.map(e=>e.map(e=>{let t={blocks:[...e.blocks]};return e.color!==void 0&&(t.color=e.color),e.textColor!==void 0&&(t.textColor=e.textColor),e.placement!==void 0&&(t.placement=e.placement),e.colspan!==void 0&&e.colspan>1&&(t.colspan=e.colspan),e.rowspan!==void 0&&e.rowspan>1&&(t.rowspan=e.rowspan),e.mergedInto!==void 0&&(t.mergedInto=[...e.mergedInto]),t}))};return this.colWidthsValue!==void 0&&(e.colWidths=[...this.colWidthsValue]),this.initialColWidthValue!==void 0&&(e.initialColWidth=this.initialColWidthValue),e}findCellForBlock(e){var t;return(t=this.blockCellMap.get(e))==null?null:t}addBlockToCell(e,t,n){if(!this.isInBounds(e,t)||this.isSpannedCell(e,t))return;let r=this.blockCellMap.get(n);if(r){let e=this.contentGrid[r.row][r.col];e.blocks=e.blocks.filter(e=>e!==n)}this.contentGrid[e][t].blocks.push(n),this.blockCellMap.set(n,{row:e,col:t})}removeBlockFromCell(e,t,n){if(!this.isInBounds(e,t))return;let r=this.contentGrid[e][t],i=r.blocks.indexOf(n);i!==-1&&(r.blocks.splice(i,1),this.blockCellMap.delete(n))}setCellBlocks(e,t,n){if(this.isInBounds(e,t)&&!this.isSpannedCell(e,t)){for(let n of this.contentGrid[e][t].blocks)this.blockCellMap.delete(n);for(let r of n){let n=this.blockCellMap.get(r);if(n!==void 0&&(n.row!==e||n.col!==t)){let e=this.contentGrid[n.row][n.col];e.blocks=e.blocks.filter(e=>e!==r)}}this.contentGrid[e][t].blocks=[...n];for(let r of n)this.blockCellMap.set(r,{row:e,col:t})}}getCellBlocks(e,t){return this.isInBounds(e,t)?[...this.contentGrid[e][t].blocks]:[]}setCellColor(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].color:En(n)&&(this.contentGrid[e][t].color=n))}getCellColor(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].color}setCellTextColor(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].textColor:En(n)&&(this.contentGrid[e][t].textColor=n))}getCellTextColor(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].textColor}setCellPlacement(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].placement:this.contentGrid[e][t].placement=n)}getCellPlacement(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].placement}addRow(e){let t=e===void 0?this.contentGrid.length:Math.min(Math.max(0,e),this.contentGrid.length),n=this.cols,r=Array.from({length:n},()=>({blocks:[]}));return this.contentGrid.splice(t,0,r),this.shiftMergedIntoRows(t,1),this.expandSpansForInsertedRow(t),this.rebuildBlockCellMap(),{type:`add-row`,index:t,cellsToPopulate:n}}deleteRow(e){if(!this.isRowInBounds(e))return{type:`delete-row`,index:e,blocksToDelete:[]};this.contractSpansForDeletedRow(e);let t=this.collectBlocksInRow(e);this.contentGrid.splice(e,1);for(let e of t)this.blockCellMap.delete(e);return this.shiftMergedIntoRows(e,-1),this.rebuildBlockCellMap(),{type:`delete-row`,index:e,blocksToDelete:t}}moveRow(e,t){if(!this.isRowInBounds(e)||!this.isRowInBounds(t)||e===t||this.isRowInvolvedInMerge(e))return{type:`move-row`,index:e,toIndex:t};let[n]=this.contentGrid.splice(e,1);return this.contentGrid.splice(t,0,n),this.rebuildMergedIntoRowCoordinates(e,t),this.rebuildBlockCellMap(),{type:`move-row`,index:e,toIndex:t}}addColumn(e,t){let n=e===void 0?this.cols:Math.min(Math.max(0,e),this.cols),r=[];if(this.contentGrid.forEach((e,t)=>{e.splice(n,0,{blocks:[]}),r.push({row:t,col:n})}),this.colWidthsValue!==void 0){let e=t==null?0:t;this.colWidthsValue.splice(n,0,e)}return this.shiftMergedIntoCols(n,1),this.expandSpansForInsertedCol(n),this.rebuildBlockCellMap(),{type:`add-column`,index:n,cellsToPopulate:r}}deleteColumn(e){var t;if(!this.isColInBounds(e))return{type:`delete-column`,index:e,blocksToDelete:[]};this.contractSpansForDeletedCol(e);let n=this.collectBlocksInColumn(e);for(let t of this.contentGrid)t.splice(e,1);for(let e of n)this.blockCellMap.delete(e);return this.colWidthsValue!==void 0&&this.colWidthsValue.splice(e,1),((t=this.colWidthsValue)==null?void 0:t.length)===0&&(this.colWidthsValue=void 0),this.shiftMergedIntoCols(e,-1),this.rebuildBlockCellMap(),{type:`delete-column`,index:e,blocksToDelete:n}}moveColumn(e,t){if(!this.isColInBounds(e)||!this.isColInBounds(t)||e===t||this.isColInvolvedInMerge(e))return{type:`move-column`,index:e,toIndex:t};for(let n of this.contentGrid){let[r]=n.splice(e,1);n.splice(t,0,r)}if(this.colWidthsValue!==void 0){let[n]=this.colWidthsValue.splice(e,1);this.colWidthsValue.splice(t,0,n)}return this.rebuildMergedIntoColCoordinates(e,t),this.rebuildBlockCellMap(),{type:`move-column`,index:e,toIndex:t}}replaceAll(e){var t;this.withHeadingsValue=e.withHeadings,this.withHeadingColumnValue=e.withHeadingColumn,this.stretchedValue=(t=e.stretched)==null?!1:t,this.colWidthsValue=e.colWidths?[...e.colWidths]:void 0,this.initialColWidthValue=e.initialColWidth,this.contentGrid=this.normalizeContent(e.content),this.blockCellMap.clear(),this.rebuildBlockCellMap()}canMergeCells(e){let{minRow:t,maxRow:n,minCol:r,maxCol:i}=e;return t===n&&r===i||t<0||n>=this.rows||r<0||i>=this.cols?!1:this.contentGrid.slice(t,n+1).every((e,a)=>{let o=t+a;return e.slice(r,i+1).every((e,a)=>{var s,c;let l=r+a,u=(s=e.colspan)==null?1:s,d=(c=e.rowspan)==null?1:c;if((u>1||d>1)&&(o+d-1>n||l+u-1>i))return!1;if(e.mergedInto!==void 0){let[n,i]=e.mergedInto;if(n<t||i<r)return!1}return!0})})}mergeCells(e){var t,n;let{minRow:r,maxRow:i,minCol:a,maxCol:o}=e,s={blocksToRelocate:[]};if(!this.canMergeCells(e))return s;let c=this.contentGrid[r][a];this.contentGrid.slice(r,i+1).forEach((e,t)=>{let n=r+t;e.slice(a,o+1).forEach((e,t)=>{var i,o;let s=a+t;n===r&&s===a||(((i=e.colspan)==null?1:i)>1||((o=e.rowspan)==null?1:o)>1)&&this.splitCellInternal(n,s)})}),(((t=c.colspan)==null?1:t)>1||((n=c.rowspan)==null?1:n)>1)&&this.splitCellInternal(r,a);let l=[];return this.contentGrid.slice(r,i+1).forEach((e,t)=>{let n=r+t;this.contentGrid[n].slice(a,o+1).forEach((e,t)=>{let i=a+t,o=this.contentGrid[n][i];for(let e of o.blocks)l.push(e),(n!==r||i!==a)&&s.blocksToRelocate.push(e);(n!==r||i!==a)&&(o.blocks=[],o.mergedInto=[r,a],delete o.colspan,delete o.rowspan)})}),c.blocks=l,c.colspan=o-a+1,c.rowspan=i-r+1,delete c.mergedInto,delete c.placement,c.colspan===1&&delete c.colspan,c.rowspan===1&&delete c.rowspan,this.rebuildBlockCellMap(),s}splitCell(e,t){var n,r;if(!this.isInBounds(e,t))return;let i=this.contentGrid[e][t];((n=i.colspan)==null?1:n)<=1&&((r=i.rowspan)==null?1:r)<=1||(this.splitCellInternal(e,t),this.rebuildBlockCellMap())}isMergedCell(e,t){var n,r;if(!this.isInBounds(e,t))return!1;let i=this.contentGrid[e][t];return((n=i.colspan)==null?1:n)>1||((r=i.rowspan)==null?1:r)>1}isSpannedCell(e,t){return this.isInBounds(e,t)?this.contentGrid[e][t].mergedInto!==void 0:!1}getCellSpan(e,t){var n,r;if(!this.isInBounds(e,t))return{colspan:1,rowspan:1};let i=this.contentGrid[e][t];return{colspan:(n=i.colspan)==null?1:n,rowspan:(r=i.rowspan)==null?1:r}}splitCellInternal(e,t){var n,r;let i=this.contentGrid[e][t],a=(n=i.colspan)==null?1:n,o=(r=i.rowspan)==null?1:r;this.contentGrid.slice(e,Math.min(e+o,this.rows)).forEach((n,r)=>{let i=e+r;this.contentGrid[i].slice(t,Math.min(t+a,this.cols)).forEach((n,r)=>{let a=t+r;if(i===e&&a===t)return;let o=this.contentGrid[i][a];delete o.mergedInto,o.blocks=[],delete o.placement})}),delete i.colspan,delete i.rowspan,delete i.placement}setWithHeadings(e){this.withHeadingsValue=e}setWithHeadingColumn(e){this.withHeadingColumnValue=e}setStretched(e){this.stretchedValue=e}setColWidths(e){this.colWidthsValue=e?[...e]:void 0}setInitialColWidth(e){this.initialColWidthValue=e}validateInvariants(){if(this.contentGrid.length>0){let e=this.contentGrid[0].length;this.contentGrid.forEach((t,n)=>{if(t.length!==e)throw Error(`Invariant violation: row ${n} has ${t.length} columns, expected ${e}`)})}if(this.colWidthsValue!==void 0&&this.contentGrid.length>0&&this.colWidthsValue.length!==this.contentGrid[0].length)throw Error(`Invariant violation: colWidths has ${this.colWidthsValue.length} entries but grid has ${this.contentGrid[0].length} columns`);let e=new Set;if(this.contentGrid.forEach((t,n)=>{t.forEach((t,r)=>{for(let i of t.blocks){if(e.has(i))throw Error(`Invariant violation: block "${i}" appears in multiple cells`);e.add(i);let t=this.blockCellMap.get(i);if(!t)throw Error(`Invariant violation: block "${i}" at [${n},${r}] not in blockCellMap`);if(t.row!==n||t.col!==r)throw Error(`Invariant violation: block "${i}" at [${n},${r}] mapped to [${t.row},${t.col}]`)}})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i;let a=(r=e.colspan)==null?1:r,o=(i=e.rowspan)==null?1:i;if(a>1||o>1){var s,c;if(t+o>this.contentGrid.length||n+a>((s=(c=this.contentGrid[0])==null?void 0:c.length)==null?0:s)){var l,u;throw Error(`Invariant violation: origin [${t},${n}] span extends beyond grid bounds (colspan=${a}, rowspan=${o}, rows=${this.contentGrid.length}, cols=${(l=(u=this.contentGrid[0])==null?void 0:u.length)==null?0:l})`)}}})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i,a,o;if(e.mergedInto===void 0)return;let[s,c]=e.mergedInto;if(s<0||s>=this.contentGrid.length||c<0||c>=((r=(i=this.contentGrid[0])==null?void 0:i.length)==null?0:r))throw Error(`Invariant violation: mergedInto at [${t},${n}] points to out-of-bounds [${s},${c}]`);let l=this.contentGrid[s][c],u=(a=l.colspan)==null?1:a,d=(o=l.rowspan)==null?1:o;if(u<=1&&d<=1)throw Error(`Invariant violation: mergedInto at [${t},${n}] points to [${s},${c}] which is not a merge origin`);if(t<s||t>=s+d||n<c||n>=c+u)throw Error(`Invariant violation: mergedInto at [${t},${n}] is outside the span of origin [${s},${c}] (colspan=${u}, rowspan=${d})`)})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i;let a=(r=e.colspan)==null?1:r,o=(i=e.rowspan)==null?1:i;a<=1&&o<=1||this.contentGrid.slice(t,t+o).forEach((e,r)=>{let i=t+r;e.slice(n,n+a).forEach((e,r)=>{let a=n+r;if(!(i===t&&a===n)&&!(e!=null&&e.mergedInto))throw Error(`Invariant violation: cell [${i},${a}] is within span of origin [${t},${n}] but has no mergedInto`)})})})}),this.blockCellMap.size!==e.size)throw Error(`Invariant violation: blockCellMap has ${this.blockCellMap.size} entries but grid has ${e.size} blocks`)}shiftMergedIntoRows(e,t){this.contentGrid.forEach((n,r)=>{this.contentGrid[r].forEach((n,i)=>{let a=this.contentGrid[r][i];a.mergedInto!==void 0&&a.mergedInto[0]>=e&&(a.mergedInto=[a.mergedInto[0]+t,a.mergedInto[1]])})})}shiftMergedIntoCols(e,t){this.contentGrid.forEach((n,r)=>{this.contentGrid[r].forEach((n,i)=>{let a=this.contentGrid[r][i];a.mergedInto!==void 0&&a.mergedInto[1]>=e&&(a.mergedInto=[a.mergedInto[0],a.mergedInto[1]+t])})})}expandSpansForInsertedRow(e){this.contentGrid.forEach((t,n)=>{this.contentGrid[n].forEach((t,r)=>{var i,a;let o=this.contentGrid[n][r],s=(i=o.rowspan)==null?1:i,c=(a=o.colspan)==null?1:a;s<=1&&c<=1||n>=e||n+s<=e||(o.rowspan=s+1,this.markInsertedRowCells(e,n,r,c))})})}markInsertedRowCells(e,t,n,r){this.contentGrid[e].slice(n,n+r).forEach((r,i)=>{let a=n+i;if(a===n&&t===e)return;let o=this.contentGrid[e][a];o.mergedInto=[t,n],o.blocks=[]})}expandSpansForInsertedCol(e){this.contentGrid.forEach((t,n)=>{this.contentGrid[n].forEach((t,r)=>{var i,a;let o=this.contentGrid[n][r],s=(i=o.rowspan)==null?1:i,c=(a=o.colspan)==null?1:a;s<=1&&c<=1||r>=e||r+c<=e||(o.colspan=c+1,this.markInsertedColCells(e,n,r,s))})})}markInsertedColCells(e,t,n,r){this.contentGrid.slice(t,t+r).forEach((r,i)=>{let a=t+i;if(a===t&&e===n)return;let o=this.contentGrid[a][e];o.mergedInto=[t,n],o.blocks=[]})}contractSpansForDeletedRow(e){this.contentGrid[e].forEach((t,n)=>{var r,i;let a=this.contentGrid[e][n];((r=a.colspan)==null?1:r)>1||((i=a.rowspan)==null?1:i)>1?this.handleOriginInDeletedRow(e,n):a.mergedInto!==void 0&&this.handleCoveredInDeletedRow(e,n)})}handleOriginInDeletedRow(e,t){var n,r;let i=this.contentGrid[e][t],a=(n=i.rowspan)==null?1:n,o=(r=i.colspan)==null?1:r;if(a<=1)return;let s=a-1,c=e+1;c<this.contentGrid.length&&this.transferOriginToNextRow(e,t,c,a,o,s),delete i.colspan,delete i.rowspan}transferOriginToNextRow(e,t,n,r,i,a){let o=this.contentGrid[e][t],s=this.contentGrid[n][t];if(s.blocks=[...o.blocks],o.blocks=[],delete s.mergedInto,a===1&&i===1){delete s.colspan,delete s.rowspan,this.clearMergedIntoRefs(n,e+r,t,t+i,e,t,n,t,void 0);return}a>1?s.rowspan=a:delete s.rowspan,i>1?s.colspan=i:delete s.colspan,this.clearMergedIntoRefs(n,e+r,t,t+i,e,t,n,t,[n,t])}handleCoveredInDeletedRow(e,t){var n,r,i;let[a,o]=this.contentGrid[e][t].mergedInto;if(a===e)return;let s=(n=this.contentGrid[a])==null?void 0:n[o];if(!s)return;let c=(r=s.rowspan)==null?1:r,l=(i=s.colspan)==null?1:i,u=c-1;u===1&&l===1?(delete s.colspan,delete s.rowspan,this.clearMergedIntoRefsForDissolve(a,a+c,o,o+l,a,o,e)):u>1?s.rowspan=u:delete s.rowspan}clearMergedIntoRefs(e,t,n,r,i,a,o,s,c){this.contentGrid.slice(e,t).forEach((t,l)=>{let u=e+l;this.contentGrid[u].slice(n,r).forEach((e,t)=>{var r,l,d;let f=n+t;if(u===o&&f===s)return;let p=(r=this.contentGrid[u])==null?void 0:r[f];(p==null||(l=p.mergedInto)==null?void 0:l[0])===i&&(p==null||(d=p.mergedInto)==null?void 0:d[1])===a&&(c===void 0?delete p.mergedInto:p.mergedInto=c)})})}clearMergedIntoRefsForDissolve(e,t,n,r,i,a,o){this.contentGrid.slice(e,t).forEach((t,s)=>{let c=e+s;c!==o&&this.contentGrid[c].slice(n,r).forEach((e,t)=>{var r;let o=n+t;if(c===i&&o===a)return;let s=(r=this.contentGrid[c])==null?void 0:r[o];s!=null&&s.mergedInto&&delete s.mergedInto})})}contractSpansForDeletedCol(e){this.contentGrid.forEach((t,n)=>{var r,i;let a=this.contentGrid[n][e];((r=a.colspan)==null?1:r)>1||((i=a.rowspan)==null?1:i)>1?this.handleOriginInDeletedCol(e,n):a.mergedInto!==void 0&&this.handleCoveredInDeletedCol(e,n)})}handleOriginInDeletedCol(e,t){var n,r,i,a;let o=this.contentGrid[t][e],s=(n=o.rowspan)==null?1:n,c=(r=o.colspan)==null?1:r;if(c<=1)return;let l=c-1,u=e+1;u<((i=(a=this.contentGrid[t])==null?void 0:a.length)==null?0:i)&&this.transferOriginToNextCol(e,t,u,s,c,l),delete o.colspan,delete o.rowspan}transferOriginToNextCol(e,t,n,r,i,a){let o=this.contentGrid[t][e],s=this.contentGrid[t][n];if(s.blocks=[...o.blocks],o.blocks=[],delete s.mergedInto,a===1&&r===1){delete s.colspan,delete s.rowspan,this.clearMergedIntoRefs(t,t+r,n,e+i,t,e,t,n,void 0);return}a>1?s.colspan=a:delete s.colspan,r>1?s.rowspan=r:delete s.rowspan,this.clearMergedIntoRefs(t,t+r,n,e+i,t,e,t,n,[t,n])}handleCoveredInDeletedCol(e,t){var n,r,i;let[a,o]=this.contentGrid[t][e].mergedInto;if(o===e)return;let s=(n=this.contentGrid[a])==null?void 0:n[o];if(!s)return;let c=(r=s.colspan)==null?1:r,l=(i=s.rowspan)==null?1:i,u=c-1;u===1&&l===1?(delete s.colspan,delete s.rowspan,this.clearMergedIntoRefsForDissolveCol(a,a+l,o,o+c,a,o,e)):u>1?s.colspan=u:delete s.colspan}clearMergedIntoRefsForDissolveCol(e,t,n,r,i,a,o){this.contentGrid.slice(e,t).forEach((t,s)=>{let c=e+s;this.contentGrid[c].slice(n,r).forEach((e,t)=>{var r;let s=n+t;if(c===i&&s===a||s===o)return;let l=(r=this.contentGrid[c])==null?void 0:r[s];l!=null&&l.mergedInto&&delete l.mergedInto})})}isRowInvolvedInMerge(e){return this.contentGrid[e].some(t=>{var n;return((n=t.rowspan)==null?1:n)>1?!0:t.mergedInto!==void 0&&t.mergedInto[0]!==e})}isColInvolvedInMerge(e){return this.contentGrid.some(t=>{var n;let r=t[e];return((n=r.colspan)==null?1:n)>1?!0:r.mergedInto!==void 0&&r.mergedInto[1]!==e})}rebuildMergedIntoRowCoordinates(e,t){let n=this.contentGrid.length,r=this.buildMoveMapping(n,e,t);this.contentGrid.forEach((e,t)=>{this.contentGrid[t].forEach((e,n)=>{let i=this.contentGrid[t][n];i.mergedInto!==void 0&&(i.mergedInto=[r[i.mergedInto[0]],i.mergedInto[1]])})})}rebuildMergedIntoColCoordinates(e,t){let n=this.cols,r=this.buildMoveMapping(n,e,t);this.contentGrid.forEach((e,t)=>{this.contentGrid[t].forEach((e,n)=>{let i=this.contentGrid[t][n];if(i.mergedInto!==void 0){let e=i.mergedInto[1];i.mergedInto=[i.mergedInto[0],r[e]]}})})}buildMoveMapping(e,t,n){return Array.from({length:e},(e,r)=>{if(r===t)return n;let i=r>t?r-1:r;return i>=n?i+1:i})}normalizeContent(e){if(!e||!Array.isArray(e))return[];let t=new Set;return e.map(e=>(e==null?[]:e).map(e=>{let n=this.normalizeCell(e);return n.blocks=n.blocks.filter(e=>t.has(e)?!1:(t.add(e),!0)),n}))}normalizeCell(e){if(R(e)){let t={blocks:[...e.blocks]};return e.color!==void 0&&En(e.color)&&(t.color=e.color),e.textColor!==void 0&&En(e.textColor)&&(t.textColor=e.textColor),e.placement!==void 0&&(t.placement=e.placement),e.colspan!==void 0&&e.colspan>1&&(t.colspan=e.colspan),e.rowspan!==void 0&&e.rowspan>1&&(t.rowspan=e.rowspan),e.mergedInto!==void 0&&(t.mergedInto=[...e.mergedInto]),t}return{blocks:[]}}rebuildBlockCellMap(){this.blockCellMap.clear(),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{for(let r of e.blocks)this.blockCellMap.set(r,{row:t,col:n})})})}isInBounds(e,t){return e>=0&&e<this.contentGrid.length&&t>=0&&(this.contentGrid.length===0||t<this.contentGrid[e].length)}isRowInBounds(e){return e>=0&&e<this.contentGrid.length}isColInBounds(e){return e>=0&&this.contentGrid.length>0&&e<this.contentGrid[0].length}collectBlocksInRow(e){let t=[];for(let n of this.contentGrid[e])t.push(...n.blocks);return t}collectBlocksInColumn(e){let t=[];for(let n of this.contentGrid)e<n.length&&t.push(...n[e].blocks);return t}},On=`data-blok-table-resize`,kn=50,An=16,jn=class{get enabled(){return this._enabled}set enabled(e){this._enabled=e;let t=e?``:`none`;this.handles.forEach(e=>{let n=e;n.style.pointerEvents=t})}constructor(e,t,n,r,i,a=!1){this._enabled=!0,this.isDragging=!1,this.dragStartX=0,this.dragColIndex=-1,this.startColWidth=0,this.dragColElements=null,this.handles=[],this.gridEl=e,this.colWidths=[...t],this.onChange=n,this.onDragStart=r==null?null:r,this.onDrag=i==null?null:i,this.needsInitialApply=a,this.boundPointerDown=this.onPointerDown.bind(this),this.boundPointerMove=this.onPointerMove.bind(this),this.boundPointerUp=this.onPointerUp.bind(this),this.gridEl.style.position=`relative`,a||this.applyWidths(),this.createHandles(),this.gridEl.addEventListener(`pointerdown`,this.boundPointerDown)}destroy(){this.gridEl.removeEventListener(`pointerdown`,this.boundPointerDown),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),this.dragColElements=null,this.handles.forEach(e=>e.remove()),this.handles=[]}createHandles(){let e=this.colWidths.length;e<2||Array.from({length:e}).forEach((e,t)=>{let n=this.createHandle(t);this.handles.push(n),this.gridEl.appendChild(n)})}createHandle(e){let t=document.createElement(`div`),n=this.getHandleLeftPx(e);return t.setAttribute(On,``),t.setAttribute(`data-col`,String(e)),t.style.position=`absolute`,t.style.top=`-1px`,t.style.bottom=`0px`,t.style.width=`${An}px`,t.style.left=`${n-An/2}px`,t.style.cursor=`col-resize`,t.style.zIndex=`2`,t.style.background=`linear-gradient(to right, transparent 7px, #3b82f6 7px, #3b82f6 9px, transparent 9px)`,t.style.opacity=`0`,t.style.transition=`opacity 150ms ease`,t.setAttribute(`contenteditable`,`false`),t.addEventListener(`mouseenter`,()=>{this.isDragging||(t.style.opacity=`1`)}),t.addEventListener(`mouseleave`,()=>{this.isDragging||(t.style.opacity=`0`)}),t}getHandleLeftPx(e){return this.colWidths.slice(0,e+1).reduce((e,t)=>e+t,0)}updateHandlePositions(){this.handles.forEach((e,t)=>{let n=this.getHandleLeftPx(t),r=e;r.style.left=`${n-An/2}px`})}onPointerDown(e){var t;if(!this._enabled)return;let n=e.target;if(!n.hasAttribute(On))return;e.preventDefault(),this.needsInitialApply&&(this.applyWidths(),this.updateHandlePositions(),this.needsInitialApply=!1);let r=n.getAttribute(`data-col`);r!==null&&(this.dragColIndex=Number(r),this.isDragging=!0,this.dragStartX=e.clientX,this.startColWidth=this.colWidths[this.dragColIndex],this.dragColElements=this.resolveColElements(),(t=this.onDragStart)==null||t.call(this),this.gridEl.style.userSelect=`none`,n.style.opacity=`1`,n.setPointerCapture&&n.setPointerCapture(e.pointerId),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp))}onPointerMove(e){var t,n;if(!this.isDragging)return;let r=e.clientX-this.dragStartX,i=this.startColWidth+r,a=Math.max(kn,i);this.colWidths[this.dragColIndex]=a,this.applyWidths((t=this.dragColElements)==null?void 0:t),this.updateHandlePositions(),(n=this.onDrag)==null||n.call(this)}onPointerUp(){if(!this.isDragging)return;this.isDragging=!1,this.gridEl.style.userSelect=``;let e=this.handles[this.dragColIndex];e&&(e.style.opacity=`0`),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),this.dragColElements=null,this.onChange([...this.colWidths])}resolveColElements(){let e=this.gridEl.querySelector(`colgroup`);return e?Array.from(e.querySelectorAll(`col`)):[]}applyWidths(e=this.resolveColElements()){let t=this.colWidths.reduce((e,t)=>e+t,0);this.gridEl.style.width=`${t+1}px`,e.forEach((e,t)=>{if(t<this.colWidths.length){let n=e;n.style.width=`${this.colWidths[t]}px`}})}},Mn=(e,t,n)=>(n.grid.addRow(e,t),H(e,n.cellBlocks),{pendingHighlight:{type:`row`,index:t},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}),Nn=(e,t,n)=>{let r=pn(e,t,n.data.colWidths,n.data.initialColWidth,n.grid);return H(e,n.cellBlocks),{pendingHighlight:{type:`col`,index:t},moveSelection:null,colWidths:r,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},Pn=(e,t,n,r)=>(r.grid.moveRow(e,t,n),{pendingHighlight:null,moveSelection:{type:`row`,index:n},colWidths:r.data.colWidths,withHeadings:r.data.withHeadings,withHeadingColumn:r.data.withHeadingColumn}),Fn=(e,t,n,r)=>(r.grid.moveColumn(e,t,n),{pendingHighlight:null,moveSelection:{type:`col`,index:n},colWidths:dn(r.data.colWidths,t,n),withHeadings:r.data.withHeadings,withHeadingColumn:r.data.withHeadingColumn}),In=(e,t,n)=>{var r,i;return(r=n.cellBlocks)==null||r.deleteBlocks((i=n.blocksToDelete)==null?[]:i),n.grid.deleteRow(e,t),{pendingHighlight:{type:`row`,index:t<n.grid.getRowCount(e)?t:t-1},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},Ln=(e,t,n)=>{var r,i;(r=n.cellBlocks)==null||r.deleteBlocks((i=n.blocksToDelete)==null?[]:i),n.grid.deleteColumn(e,t);let a=fn(n.data.colWidths,t);return a?V(e,a):un(e),{pendingHighlight:{type:`col`,index:t<n.grid.getColumnCount(e)?t:t-1},moveSelection:null,colWidths:a,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},Rn=(e,t,n)=>{switch(t.type){case`insert-row-above`:return Mn(e,t.index,n);case`insert-row-below`:return Mn(e,t.index+1,n);case`insert-col-left`:return Nn(e,t.index,n);case`insert-col-right`:return Nn(e,t.index+1,n);case`move-row`:return Pn(e,t.fromIndex,t.toIndex,n);case`move-col`:return Fn(e,t.fromIndex,t.toIndex,n);case`delete-row`:return In(e,t.index,n);case`delete-col`:return Ln(e,t.index,n);case`toggle-heading`:return{pendingHighlight:{type:`row`,index:0},moveSelection:null,colWidths:n.data.colWidths,withHeadings:!n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn};case`toggle-heading-column`:return{pendingHighlight:{type:`col`,index:0},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:!n.data.withHeadingColumn}}},zn=10,Bn=`data-blok-table-drag-ghost`,Vn=e=>{let t=e.querySelector(`colgroup`);if(t)return Array.from(t.querySelectorAll(`col`)).reduce((e,t)=>{let n=e[e.length-1],r=t.offsetWidth||parseFloat(t.style.width)||0;return[...e,n+r]},[0]);let n=e.querySelector(`[${P}]`);return n?Array.from(n.querySelectorAll(`[${F}]`)).reduce((e,t)=>{let n=e[e.length-1];return[...e,n+t.offsetWidth]},[0]):[0]},Hn=class{constructor(e){var t;this.isDragging=!1,this.dragType=null,this.dragFromIndex=-1,this.dragStartX=0,this.dragStartY=0,this.dropIndicator=null,this.dragOverlayCells=[],this.ghostEl=null,this.ghostOffsetX=0,this.ghostOffsetY=0,this.resolveTracking=null,this.grid=e.grid,this.onAction=e.onAction,this.onDragStateChange=(t=e.onDragStateChange)==null?null:t,this.boundDocPointerMove=this.handleDocPointerMove.bind(this),this.boundDocPointerUp=this.handleDocPointerUp.bind(this),this.boundDocPointerCancel=this.handleDocPointerCancel.bind(this)}beginTracking(e,t,n,r){return this.dragType=e,this.dragFromIndex=t,this.dragStartX=n,this.dragStartY=r,document.addEventListener(`pointermove`,this.boundDocPointerMove),document.addEventListener(`pointerup`,this.boundDocPointerUp),document.addEventListener(`pointercancel`,this.boundDocPointerCancel),new Promise(e=>{this.resolveTracking=e})}cleanup(){var e,t,n;this.grid.style.userSelect=``,document.body.style.cursor=``,this.dragOverlayCells.forEach(e=>{let t=e;t.style.backgroundColor=``,t.style.opacity=``}),this.dragOverlayCells=[],(e=this.dropIndicator)==null||e.remove(),this.dropIndicator=null,(t=this.ghostEl)==null||t.remove(),this.ghostEl=null,document.removeEventListener(`pointermove`,this.boundDocPointerMove),document.removeEventListener(`pointerup`,this.boundDocPointerUp),document.removeEventListener(`pointercancel`,this.boundDocPointerCancel),(n=this.onDragStateChange)==null||n.call(this,!1,null),this.isDragging=!1,this.dragType=null,this.dragFromIndex=-1,this.resolveTracking=null}handleDocPointerMove(e){let t=Math.abs(e.clientX-this.dragStartX),n=Math.abs(e.clientY-this.dragStartY);!this.isDragging&&(t>zn||n>zn)&&(this.isDragging=!0,this.startDrag()),this.isDragging&&(this.updateDragIndicator(e),this.updateGhostPosition(e))}handleDocPointerUp(e){if(document.removeEventListener(`pointermove`,this.boundDocPointerMove),document.removeEventListener(`pointerup`,this.boundDocPointerUp),document.removeEventListener(`pointercancel`,this.boundDocPointerCancel),this.isDragging){var t;this.finishDrag(e),(t=this.resolveTracking)==null||t.call(this,!0)}else{var n;(n=this.resolveTracking)==null||n.call(this,!1)}this.cleanup()}handleDocPointerCancel(){var e;(e=this.resolveTracking)==null||e.call(this,this.isDragging),this.cleanup()}startDrag(){var e;this.grid.style.userSelect=`none`,document.body.style.cursor=`grabbing`,(e=this.onDragStateChange)==null||e.call(this,!0,this.dragType),this.highlightSourceCells(),this.createDropIndicator(),this.createGhost()}highlightSourceCells(){let e=this.grid.querySelectorAll(`[${P}]`);if(this.dragType===`row`){this.highlightRowCells(e);return}this.dragType===`col`&&this.highlightColumnCells(e)}highlightRowCells(e){let t=e[this.dragFromIndex];if(!t)return;let n=this.getDragSourceBg();t.querySelectorAll(`[${F}]`).forEach(e=>{let t=e;t.style.backgroundColor=n,t.style.opacity=`0.7`,this.dragOverlayCells.push(t)})}highlightColumnCells(e){let t=this.getDragSourceBg();e.forEach(e=>{let n=e.querySelector(`[${L}="${this.dragFromIndex}"]`);n&&(n.style.backgroundColor=t,n.style.opacity=`0.7`,this.dragOverlayCells.push(n))})}getDragSourceBg(){return getComputedStyle(this.grid).getPropertyValue(`--blok-table-drag-source-bg`).trim()||`#f3f4f6`}isDarkMode(){var e,t,n;let r=document.documentElement.getAttribute(`data-blok-theme`);return r===`dark`?!0:r===`light`||(e=(t=(n=window).matchMedia)==null?void 0:t.call(n,`(prefers-color-scheme: dark)`).matches)==null?!1:e}createDropIndicator(){this.dropIndicator=document.createElement(`div`);let e=this.dropIndicator.style;if(e.position=`absolute`,e.backgroundColor=`#3b82f6`,e.borderRadius=`1.5px`,e.zIndex=`5`,e.pointerEvents=`none`,this.dropIndicator.setAttribute(`contenteditable`,`false`),this.dragType===`row`)e.height=`3px`,e.left=`-1px`,e.right=`0`,e.transition=`top 100ms ease`;else{let t=this.grid.querySelectorAll(`[${P}]`),n=t[t.length-1],r=n?n.offsetTop+n.offsetHeight:0;e.width=`3px`,e.top=`-1px`,e.height=`${r+1}px`,e.transition=`left 100ms ease`}this.grid.appendChild(this.dropIndicator)}updateDragIndicator(e){if(!this.dropIndicator)return;let t=this.grid.getBoundingClientRect();if(this.dragType===`row`){this.updateRowIndicator(e,t);return}this.dragType===`col`&&this.updateColIndicator(e,t)}updateRowIndicator(e,t){if(!this.dropIndicator)return;let n=e.clientY-t.top,r=this.getRowDropIndex(n),i=this.getRowDropTopPx(r);this.dropIndicator.style.top=`${i-1.5}px`}updateColIndicator(e,t){var n;if(!this.dropIndicator)return;let r=e.clientX-t.left,i=this.getColDropIndex(r),a=Vn(this.grid);this.dropIndicator.style.left=`${((n=a[i])==null?0:n)-1.5}px`}finishDrag(e){let t=this.grid.getBoundingClientRect();if(this.dragType===`row`){this.finishRowDrag(e,t);return}this.dragType===`col`&&this.finishColDrag(e,t)}finishRowDrag(e,t){let n=e.clientY-t.top,r=this.getRowDropIndex(n),i=r>this.dragFromIndex?r-1:r;i!==this.dragFromIndex&&this.onAction({type:`move-row`,fromIndex:this.dragFromIndex,toIndex:i})}finishColDrag(e,t){let n=e.clientX-t.left,r=this.getColDropIndex(n),i=r>this.dragFromIndex?r-1:r;i!==this.dragFromIndex&&this.onAction({type:`move-col`,fromIndex:this.dragFromIndex,toIndex:i})}createGhost(){let e=document.createElement(`div`);e.setAttribute(Bn,``),e.setAttribute(`contenteditable`,`false`);let t=e.style;t.position=`fixed`,t.pointerEvents=`none`,t.opacity=`0.5`,t.zIndex=`50`,t.borderRadius=`4px`,t.overflow=`hidden`,t.boxShadow=this.isDarkMode()?`0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08)`:`0 4px 12px rgba(0, 0, 0, 0.15)`,this.ghostEl=e;let n=this.getSourceRect();this.dragType===`row`&&this.buildRowGhost(),this.dragType===`col`&&this.buildColumnGhost(),document.body.appendChild(e),n&&(t.left=`${n.left}px`,t.top=`${n.top}px`,this.ghostOffsetX=this.dragStartX-n.left,this.ghostOffsetY=this.dragStartY-n.top)}getSourceRect(){return this.dragType===`row`?this.getRowSourceRect():this.dragType===`col`?this.getColSourceRect():null}getRowSourceRect(){var e;let t=this.grid.querySelectorAll(`[${P}]`)[this.dragFromIndex];return(e=t==null?void 0:t.getBoundingClientRect())==null?null:e}getColSourceRect(){let e=this.grid.querySelectorAll(`[${P}]`),t=e[0],n=e[e.length-1];if(!t||!n)return null;let r=t.querySelector(`[${L}="${this.dragFromIndex}"]`),i=n.querySelector(`[${L}="${this.dragFromIndex}"]`);if(!r||!i)return null;let a=r.getBoundingClientRect(),o=i.getBoundingClientRect();return new DOMRect(a.left,a.top,a.width,o.bottom-a.top)}buildRowGhost(){let e=this.grid.querySelectorAll(`[${P}]`)[this.dragFromIndex];if(!e||!this.ghostEl)return;let t=this.ghostEl.style;t.display=`flex`,t.height=`${e.offsetHeight}px`,e.querySelectorAll(`[${F}]`).forEach(e=>{var t;let n=e,r=n.cloneNode(!0);r.style.width=`${n.offsetWidth}px`,r.style.flexShrink=`0`,r.removeAttribute(`contenteditable`),(t=this.ghostEl)==null||t.appendChild(r)})}buildColumnGhost(){if(!this.ghostEl)return;let e=this.grid.querySelectorAll(`[${P}]`),t=this.ghostEl.style;t.display=`flex`,t.flexDirection=`column`,e.forEach(e=>{var t;let n=e.querySelector(`[${L}="${this.dragFromIndex}"]`);if(!n)return;let r=n.cloneNode(!0);r.style.width=`${n.offsetWidth}px`,r.style.height=`${n.offsetHeight}px`,r.removeAttribute(`contenteditable`),(t=this.ghostEl)==null||t.appendChild(r)})}updateGhostPosition(e){if(!this.ghostEl)return;let t=this.ghostEl.style;this.dragType===`row`&&(t.top=`${e.clientY-this.ghostOffsetY}px`),this.dragType===`col`&&(t.left=`${e.clientX-this.ghostOffsetX}px`)}getRowDropIndex(e){let t=Array.from(this.grid.querySelectorAll(`[${P}]`)),n=t.map(e=>e.offsetTop);if(t.length>0){let e=t[t.length-1];n.push(e.offsetTop+e.offsetHeight)}let r=n.map(t=>Math.abs(e-t)),i=Math.min(...r);return r.indexOf(i)}getRowDropTopPx(e){let t=this.grid.querySelectorAll(`[${P}]`);if(e<t.length)return t[e].offsetTop;if(t.length>0){let e=t[t.length-1];return e.offsetTop+e.offsetHeight}return 0}getColDropIndex(e){let t=Vn(this.grid).map(t=>Math.abs(e-t)),n=Math.min(...t);return t.indexOf(n)}},Un=[`flex`,`items-center`,`select-none`,`border-none`,`bg-transparent`,`rounded-md`,`p-(--item-padding)`,`text-text-primary`,`mb-px`,`cursor-pointer`,`can-hover:hover:bg-item-hover-bg`],Wn=[`flex`,`items-center`,`justify-center`,`w-[26px]`,`h-[26px]`,`mr-2`,`[&_svg]:w-icon`,`[&_svg]:h-icon`],Gn=[`mr-auto`,`truncate`,`text-sm`,`font-medium`,`leading-5`],Kn=[`relative`,`w-[30px]`,`h-[18px]`,`rounded-full`,`transition-colors`,`duration-[180ms]`,`ease-out`,`shrink-0`,`ml-2`],qn=[`absolute`,`top-[2px]`,`w-[14px]`,`h-[14px]`,`rounded-full`,`bg-white`,`transition-[left]`,`duration-[220ms]`,`[transition-timing-function:cubic-bezier(0.34,1.56,0.64,1)]`],Jn=e=>{let{icon:t,label:n,isActive:i,onToggle:a}=e,o={active:i},s=document.createElement(`div`);s.className=r.n(Un);let c=document.createElement(`div`);c.className=r.n(Wn),c.innerHTML=t,s.appendChild(c);let l=document.createElement(`span`);l.className=r.n(Gn),l.textContent=n,s.appendChild(l);let u=document.createElement(`div`);u.className=r.n(Kn);let d=document.createElement(`div`);d.className=r.n(qn),u.appendChild(d),s.appendChild(u);let f=()=>{u.style.backgroundColor=o.active?`var(--blok-toggle-on-bg)`:`var(--blok-toggle-off-bg)`,d.style.left=o.active?`14px`:`2px`,d.style.backgroundColor=o.active?`var(--blok-toggle-thumb-on-bg)`:``,d.style.boxShadow=o.active?`0 1px 3px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.04)`:`0 1px 3px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.06)`};return f(),s.addEventListener(`click`,e=>{e.stopPropagation(),o.active=!o.active,f(),a(o.active)}),s},Yn=(e,n)=>{let r=e===0?[{type:t.Ln.Html,element:Jn({icon:t.ht,label:n.i18n.t(`tools.table.headerColumn`),isActive:n.isHeadingColumn(),onToggle:()=>{n.onAction({type:`toggle-heading-column`})}})},{type:t.Ln.Separator}]:[],i=[{icon:t.wt,title:n.i18n.t(`tools.table.insertColumnLeft`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-col-left`,index:e})}},{icon:t.Tt,title:n.i18n.t(`tools.table.insertColumnRight`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-col-right`,index:e})}}],a=n.getColumnCount()>1,o=[{type:t.Ln.Separator},{icon:t.rn,title:n.i18n.t(`tools.table.deleteColumn`),isDestructive:!0,isDisabled:!a,closeOnActivate:!0,onActivate:()=>{n.onAction({type:`delete-col`,index:e})}}];return[...r,...i,...o]},Xn=(e,n)=>{let r=e===0?[{type:t.Ln.Html,element:Jn({icon:t.gt,label:n.i18n.t(`tools.table.headerRow`),isActive:n.isHeadingRow(),onToggle:()=>{n.onAction({type:`toggle-heading`})}})},{type:t.Ln.Separator}]:[],i=[{icon:t.St,title:n.i18n.t(`tools.table.insertRowAbove`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-row-above`,index:e})}},{icon:t.Ct,title:n.i18n.t(`tools.table.insertRowBelow`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-row-below`,index:e})}}],a=n.getRowCount()>1,o=[{type:t.Ln.Separator},{icon:t.rn,title:n.i18n.t(`tools.table.deleteRow`),isDestructive:!0,isDisabled:!a,closeOnActivate:!0,onActivate:()=>{n.onAction({type:`delete-row`,index:e})}}];return[...r,...i,...o]},Zn=(e,n,r,i,a)=>{a.destroyPopover(),a.clearHideTimeout();let o=e===`col`?r.col[n]:r.row[n];if(!o)return{popover:null,grip:null};let s=new t.g({items:e===`col`?Yn(n,i):Xn(n,i),trigger:o,flippable:!0});return s.on(t.v.Closed,()=>{var e;a.destroyPopover(),a.applyVisibleClasses(o),a.scheduleHideAll(),(e=a.onGripPopoverClose)==null||e.call(a)}),a.hideAllGripsExcept(o),a.applyActiveClasses(o),e===`col`?o.style.height=`16px`:o.style.width=`16px`,{popover:s,grip:o}},Qn=`data-blok-table-grip`,$n=`data-blok-table-grip-col`,er=`data-blok-table-grip-row`,tr=150,nr=24,rr=4,ir=4,ar=20,or=[`absolute`,`z-3`,`rounded-sm`,`cursor-grab`,`select-none`,`transition-[opacity,background-color,width,height]`,`duration-150`,`group`,`flex`,`items-center`,`justify-center`,`overflow-hidden`],sr=[`bg-gray-300`,`opacity-0`,`pointer-events-none`],cr=[`bg-gray-300`,`opacity-100`,`pointer-events-auto`],lr=[`bg-blue-500`,`text-white`,`opacity-100`,`pointer-events-auto`],ur=class{constructor(e){this.colGrips=[],this.rowGrips=[],this.popoverState={popover:null,grip:null},this.lockedGrip=null,this.hideTimeout=null,this.activeColGripIndex=-1,this.activeRowGripIndex=-1,this.isInsideTable=!1,this.rowResizeObserver=null,this.boundScrollHandler=null,this.grid=e.grid,this.overlay=e.overlay,this.scrollContainer=e.scrollContainer,this.getColumnCount=e.getColumnCount,this.getRowCount=e.getRowCount,this.isHeadingRow=e.isHeadingRow,this.isHeadingColumn=e.isHeadingColumn,this.onAction=e.onAction,this.onGripClick=e.onGripClick,this.onGripPopoverClose=e.onGripPopoverClose,this.i18n=e.i18n,this.drag=new Hn({grid:this.grid,onAction:this.onAction,onDragStateChange:(t,n)=>{var r;this.handleDragStateChange(t,n),(r=e.onDragStateChange)==null||r.call(e,t,n)}}),this.boundMouseOver=this.handleMouseOver.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerDown=this.handlePointerDown.bind(this),this.boundUnlockGrip=this.handleUnlockGrip.bind(this),this.createGrips(),this.grid.addEventListener(`mouseover`,this.boundMouseOver),this.grid.addEventListener(`mouseleave`,this.boundMouseLeave)}refresh(){let e=this.popoverState.grip?this.detectGripType(this.popoverState.grip):null;if(this.destroyGrips(),this.createGrips(),!e)return;let t=e.type===`col`?this.colGrips[e.index]:this.rowGrips[e.index];t&&(this.popoverState.grip=t,this.hideAllGripsExcept(t),this.applyActiveClasses(t),e.type===`col`?t.style.height=`16px`:t.style.width=`16px`)}setActiveGrip(e,t){let n=e===`col`?this.colGrips[t]:this.rowGrips[t];n&&(this.unlockGrip(),this.clearHideTimeout(),this.hideAllGripsExcept(n),this.applyActiveClasses(n),e===`col`?n.style.height=`16px`:n.style.width=`16px`,this.lockedGrip=n,document.addEventListener(`pointerdown`,this.boundUnlockGrip))}handleUnlockGrip(e){document.removeEventListener(`pointerdown`,this.boundUnlockGrip),this.lockedGrip&&(this.applyIdleClasses(this.lockedGrip),this.lockedGrip=null);let t=e.target instanceof HTMLElement?e.target:null,n=t==null?void 0:t.closest(`[${F}]`);if(n){let e=this.getCellPosition(n);e&&(this.clearHideTimeout(),this.showColGrip(e.col),this.showRowGrip(e.row),this.isInsideTable=!0)}}unlockGrip(){document.removeEventListener(`pointerdown`,this.boundUnlockGrip),this.lockedGrip=null}getVisibleGripIndices(){return this.activeColGripIndex<0&&this.activeRowGripIndex<0?null:{col:this.activeColGripIndex,row:this.activeRowGripIndex}}restoreVisibleGrips(e,t){this.isInsideTable=e>=0||t>=0,e>=0&&this.showColGrip(e),t>=0&&this.showRowGrip(t)}get isPopoverOpen(){return this.popoverState.popover!==null}destroy(){this.destroyPopover(),this.unlockGrip(),this.drag.cleanup(),this.grid.removeEventListener(`mouseover`,this.boundMouseOver),this.grid.removeEventListener(`mouseleave`,this.boundMouseLeave),this.clearHideTimeout(),this.destroyGrips()}createGrips(){var e;let t=this.getColumnCount(),n=this.getRowCount(),r=(e=this.overlay)==null?this.grid:e;Array.from({length:t}).forEach((e,t)=>{let n=this.createGripElement(`col`,t);this.colGrips.push(n),r.appendChild(n)}),Array.from({length:n}).forEach((e,t)=>{let n=this.createGripElement(`row`,t);this.rowGrips.push(n),r.appendChild(n)}),this.positionGrips(),this.observeRowHeights(),this.attachScrollListener()}attachScrollListener(){this.overlay&&this.scrollContainer&&(this.boundScrollHandler=()=>this.positionGrips(),this.scrollContainer.addEventListener(`scroll`,this.boundScrollHandler))}detachScrollListener(){this.boundScrollHandler&&this.scrollContainer&&(this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),this.boundScrollHandler=null)}destroyGrips(){var e;(e=this.rowResizeObserver)==null||e.disconnect(),this.rowResizeObserver=null,this.detachScrollListener(),this.colGrips.forEach(e=>e.remove()),this.rowGrips.forEach(e=>e.remove()),this.colGrips=[],this.rowGrips=[],this.activeColGripIndex=-1,this.activeRowGripIndex=-1,this.isInsideTable=!1}createGripElement(e,t){let n=document.createElement(`div`);n.className=r.n(or,sr),n.setAttribute(Qn,``),n.setAttribute(e===`col`?$n:er,String(t)),n.setAttribute(`contenteditable`,`false`);let i=e===`col`?nr:ir,a=e===`col`?rr:ar,o=e===`col`?rr:ir;return n.style.width=`${i}px`,n.style.height=`${a}px`,n.style.transform=`translate(-50%, -50%)`,n.style.outline=`2px solid var(--blok-table-grip-outline, transparent)`,n.appendChild(qt(e===`col`?`horizontal`:`vertical`)),n.addEventListener(`pointerdown`,this.boundPointerDown),n.addEventListener(`mouseenter`,()=>{this.overlay&&this.clearHideTimeout(),this.isGripInteractionLocked()||Jt(n,e)}),n.addEventListener(`mouseleave`,()=>{this.isGripInteractionLocked()||(Yt(n,e,o),this.overlay&&this.scheduleHideAll())}),n}positionGrips(){let e=this.grid.querySelectorAll(`[${P}]`);if(!e[0])return;let t=Vn(this.grid),n=this.overlay&&this.scrollContainer?this.scrollContainer.scrollLeft:0,r=this.overlay&&this.scrollContainer?this.scrollContainer.clientWidth:1/0;this.colGrips.forEach((e,i)=>{if(i+1>=t.length)return;let a=(t[i]+t[i+1])/2-n,o=e.style;o.top=`${-1/2}px`,o.left=`${a}px`,this.overlay&&(o.visibility=a<0||a>r?`hidden`:``)}),this.rowGrips.forEach((t,n)=>{if(n>=e.length)return;let r=e[n],i=this.grid.querySelectorAll(`[${I}="${n}"]`),a=Array.from(i).reduce((e,t)=>{let n=t,r=e===null?0:e.rowSpan||1;return(n.rowSpan||1)>r?n:e},null);if((a===null?1:a.rowSpan||1)>1&&a!==null){var o;let e=((o=this.overlay)==null?this.grid:o).getBoundingClientRect(),n=a.getBoundingClientRect(),r=n.top-e.top+n.height/2,i=t.style;i.left=`${-1/2}px`,i.top=`${r}px`}else{let e=r.offsetTop+r.offsetHeight/2,n=t.style;n.left=`${-1/2}px`,n.top=`${e}px`}})}observeRowHeights(){var e;(e=this.rowResizeObserver)==null||e.disconnect(),this.rowResizeObserver=new ResizeObserver(()=>{this.positionGrips()}),this.grid.querySelectorAll(`[${P}]`).forEach(e=>{var t;(t=this.rowResizeObserver)==null||t.observe(e)})}isGripInteractionLocked(){return this.popoverState.popover!==null||this.lockedGrip!==null}handleMouseOver(e){if(this.isGripInteractionLocked())return;let t=e.target.closest(`[${F}]`);if(!t)return;this.clearHideTimeout();let n=this.getCellPosition(t);n&&(this.showColGrip(n.col),this.showRowGrip(n.row),this.isInsideTable=!0)}handleMouseLeave(){this.isGripInteractionLocked()||this.scheduleHideAll()}getCellPosition(e){let t=e.getAttribute(I),n=e.getAttribute(L);if(t===null||n===null)return null;let r=parseInt(t,10),i=parseInt(n,10);return isNaN(r)||isNaN(i)?null:{row:r,col:i}}setGripsDisplay(e){let t=e?``:`none`;[...this.colGrips,...this.rowGrips].forEach(n=>{let r=n;!e&&n===this.popoverState.grip||(r.style.display=t)})}hideAllGrips(){this.clearHideTimeout(),this.hideColGrip(),this.hideRowGrip(),this.isInsideTable=!1}showColGrip(e){this.activeColGripIndex!==e&&(this.hideColGrip(),this.activeColGripIndex=e,this.applyVisibleClasses(this.colGrips[e]))}hideColGrip(){this.activeColGripIndex>=0&&this.activeColGripIndex<this.colGrips.length&&this.applyIdleClasses(this.colGrips[this.activeColGripIndex]),this.activeColGripIndex=-1}showRowGrip(e){this.activeRowGripIndex!==e&&(this.hideRowGrip(),this.activeRowGripIndex=e,this.applyVisibleClasses(this.rowGrips[e]))}hideRowGrip(){this.activeRowGripIndex>=0&&this.activeRowGripIndex<this.rowGrips.length&&this.applyIdleClasses(this.rowGrips[this.activeRowGripIndex]),this.activeRowGripIndex=-1}applyVisibleClasses(e){let t=e,n=t.hasAttribute($n);Wt(t,n?`col`:`row`,n?rr:ir),this.isInsideTable&&(t.style.transition=`none`),t.className=r.n(or,cr),t.setAttribute(`data-blok-table-grip-visible`,``),this.isInsideTable&&(t.offsetHeight,t.style.transition=``);let i=t.querySelector(`svg`);i&&(i.classList.remove(`text-white`,`opacity-100`),i.classList.add(`text-gray-400`,`opacity-0`))}applyActiveClasses(e){Object.assign(e,{className:r.n(or,lr)}),e.setAttribute(`data-blok-table-grip-visible`,``);let t=e.querySelector(`svg`);t&&(t.classList.remove(`text-gray-400`,`opacity-0`),t.classList.add(`text-white`,`opacity-100`))}hideAllGripsExcept(e){[...this.colGrips,...this.rowGrips].forEach(t=>{t!==e&&this.applyIdleClasses(t)})}applyIdleClasses(e){let t=e,n=t.hasAttribute($n),i=n?`col`:`row`,a=n?rr+12:ir+12;this.isInsideTable&&(t.style.transition=`none`),Wt(t,i,a),t.className=r.n(or,sr),t.removeAttribute(`data-blok-table-grip-visible`);let o=t.querySelector(`svg`);o&&(o.classList.add(`opacity-0`),o.classList.remove(`opacity-100`)),this.isInsideTable&&(t.offsetHeight,t.style.transition=``)}handleDragStateChange(e,t){[...this.colGrips,...this.rowGrips].forEach(t=>{let n=t;n.style.display=e?`none`:``})}scheduleHideAll(){this.hideTimeout=setTimeout(()=>{this.hideColGrip(),this.hideRowGrip(),this.isInsideTable=!1,this.hideTimeout=null},tr)}clearHideTimeout(){this.hideTimeout!==null&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}handlePointerDown(e){let t=e.target.closest(`[${Qn}]`);if(!t)return;e.preventDefault(),e.stopPropagation();let n=this.detectGripType(t);n&&this.drag.beginTracking(n.type,n.index,e.clientX,e.clientY).then(e=>{e||this.openPopover(n.type,n.index)})}detectGripType(e){let t=e.getAttribute($n);if(t!==null)return{type:`col`,index:Number(t)};let n=e.getAttribute(er);return n===null?null:{type:`row`,index:Number(n)}}openPopover(e,t){var n,r;this.popoverState=Zn(e,t,{col:this.colGrips,row:this.rowGrips},{getColumnCount:this.getColumnCount,getRowCount:this.getRowCount,isHeadingRow:this.isHeadingRow,isHeadingColumn:this.isHeadingColumn,onAction:this.onAction,i18n:this.i18n},{clearHideTimeout:()=>this.clearHideTimeout(),hideAllGripsExcept:e=>this.hideAllGripsExcept(e),applyActiveClasses:e=>this.applyActiveClasses(e),applyVisibleClasses:e=>this.applyVisibleClasses(e),scheduleHideAll:()=>this.scheduleHideAll(),destroyPopover:()=>this.destroyPopover(),onGripPopoverClose:this.onGripPopoverClose}),(n=this.popoverState.popover)==null||n.show(),(r=this.onGripClick)==null||r.call(this,e,t)}destroyPopover(){if(this.popoverState.popover!==null){let e=this.popoverState.popover;this.popoverState={popover:null,grip:null},e.destroy()}}},dr=`data-blok-table-corner-drag`,fr=5,pr=class{constructor(e){var t;this.dragState=null,this.wrapper=e.wrapper,this.gridEl=e.gridEl,this.getTableSize=e.getTableSize,this.onAddRow=e.onAddRow,this.onAddColumn=e.onAddColumn,this.onRemoveLastRow=e.onRemoveLastRow,this.onRemoveLastColumn=e.onRemoveLastColumn,this.onDragStart=e.onDragStart,this.onDragEnd=e.onDragEnd,this.canRemoveLastRow=e.canRemoveLastRow,this.canRemoveLastColumn=e.canRemoveLastColumn,this.onClickAdd=(t=e.onClickAdd)==null?null:t,this.hitZone=document.createElement(`div`),this.hitZone.setAttribute(dr,``),this.hitZone.setAttribute(`contenteditable`,`false`),this.hitZone.style.position=`absolute`,this.hitZone.style.width=`36px`,this.hitZone.style.height=`36px`,this.hitZone.style.cursor=`nwse-resize`,this.hitZone.style.zIndex=`2`,this.hitZone.style.pointerEvents=`auto`,this.hitZone.style.bottom=`-36px`,this.hitZone.style.right=`-16px`,this.boundMouseEnter=this.handleMouseEnter.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerDown=this.handlePointerDown.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.hitZone.addEventListener(`mouseenter`,this.boundMouseEnter),this.hitZone.addEventListener(`mouseleave`,this.boundMouseLeave),this.hitZone.addEventListener(`pointerdown`,this.boundPointerDown),this.wrapper.appendChild(this.hitZone)}updateTooltip(){let e=this.getTableSize();t.jn(this.hitZone,`${e.cols}\u00D7${e.rows}`,{placement:`bottom`})}handleMouseEnter(){this.updateTooltip()}handleMouseLeave(){this.dragState===null&&t.kn()}measureUnitHeight(){let e=this.gridEl.querySelectorAll(`[data-blok-table-row]`),t=e[e.length-1];return(t==null?void 0:t.offsetHeight)||30}measureUnitWidth(){let e=this.gridEl.querySelector(`[data-blok-table-row]`);if(!e)return 100;let t=e.querySelectorAll(`[data-blok-table-cell]`),n=t[t.length-1];return(n==null?void 0:n.offsetWidth)||100}handlePointerDown(e){this.dragState={startX:e.clientX,startY:e.clientY,unitWidth:this.measureUnitWidth(),unitHeight:this.measureUnitHeight(),addedRows:0,addedCols:0,pointerId:e.pointerId,didDrag:!1},this.updateTooltip(),this.hitZone.setPointerCapture(e.pointerId),this.hitZone.addEventListener(`pointermove`,this.boundPointerMove),this.hitZone.addEventListener(`pointerup`,this.boundPointerUp)}handlePointerMove(e){if(this.dragState===null)return;let t=e.clientX-this.dragState.startX,n=e.clientY-this.dragState.startY;if(!this.dragState.didDrag){if(Math.sqrt(t*t+n*n)<fr)return;this.dragState.didDrag=!0,document.body.style.cursor=`nwse-resize`,document.body.style.userSelect=`none`,this.onDragStart()}let{unitHeight:r,unitWidth:i}=this.dragState,a=Math.trunc(n/r),o=Math.trunc(t/i);for(;this.dragState.addedRows<a;)this.onAddRow(),this.dragState.addedRows++;for(;this.dragState.addedRows>a&&this.canRemoveLastRow();)this.onRemoveLastRow(),this.dragState.addedRows--;for(;this.dragState.addedCols<o;)this.onAddColumn(),this.dragState.addedCols++;for(;this.dragState.addedCols>o&&this.canRemoveLastColumn();)this.onRemoveLastColumn(),this.dragState.addedCols--;this.updateTooltip()}handlePointerUp(e){if(this.dragState===null)return;let{didDrag:n,pointerId:r}=this.dragState;this.dragState=null,t.kn(),this.hitZone.releasePointerCapture(r),this.hitZone.removeEventListener(`pointermove`,this.boundPointerMove),this.hitZone.removeEventListener(`pointerup`,this.boundPointerUp),n?(document.body.style.cursor=``,document.body.style.userSelect=``,this.onDragEnd()):this.onClickAdd?this.onClickAdd():(this.onAddRow(),this.onAddColumn())}setDisplay(e){this.hitZone.style.display=e?``:`none`}setInteractive(e){this.hitZone.style.pointerEvents=e?`auto`:`none`}destroy(){var e;this.hitZone.removeEventListener(`mouseenter`,this.boundMouseEnter),this.hitZone.removeEventListener(`mouseleave`,this.boundMouseLeave),this.hitZone.removeEventListener(`pointerdown`,this.boundPointerDown),this.hitZone.removeEventListener(`pointermove`,this.boundPointerMove),this.hitZone.removeEventListener(`pointerup`,this.boundPointerUp),(e=this.dragState)!=null&&e.didDrag&&(document.body.style.cursor=``,document.body.style.userSelect=``),this.dragState=null,t.kn(),this.hitZone.remove()}},mr=`data-blok-table-haze`,hr=`data-blok-table-haze-visible`,gr=1,_r=[`absolute`,`top-0`,`bottom-0`,`w-12`,`pointer-events-none`,`opacity-0`,`transition-opacity`,`duration-150`,`z-1`],vr=[`left-0`,`bg-linear-to-r`,`from-white/80`,`to-transparent`],yr=[`right-5`,`bg-linear-to-l`,`from-white/80`,`to-transparent`],br=class{constructor(){this.leftHaze=null,this.rightHaze=null,this.scrollContainer=null,this.boundOnScroll=null,this.ticking=!1}init(e,t){this.scrollContainer=t,this.leftHaze=this.createHazeElement(`left`),this.rightHaze=this.createHazeElement(`right`),e.appendChild(this.leftHaze),e.appendChild(this.rightHaze),this.boundOnScroll=()=>{this.ticking||(requestAnimationFrame(()=>{this.syncVisibility(),this.ticking=!1}),this.ticking=!0)},t.addEventListener(`scroll`,this.boundOnScroll,{passive:!0}),this.syncVisibility()}update(){this.syncVisibility()}destroy(){var e,t;this.boundOnScroll&&this.scrollContainer&&this.scrollContainer.removeEventListener(`scroll`,this.boundOnScroll),(e=this.leftHaze)==null||e.remove(),(t=this.rightHaze)==null||t.remove(),this.leftHaze=null,this.rightHaze=null,this.scrollContainer=null,this.boundOnScroll=null,this.ticking=!1}createHazeElement(e){let t=document.createElement(`div`);return t.setAttribute(mr,e),t.setAttribute(`aria-hidden`,`true`),t.classList.add(..._r,...e===`left`?vr:yr),t}syncVisibility(){let e=this.scrollContainer;if(!e)return;let{overflowX:t}=getComputedStyle(e);if(!(t===`auto`||t===`scroll`)){this.setVisible(this.leftHaze,!1),this.setVisible(this.rightHaze,!1);return}let{scrollLeft:n,scrollWidth:r,clientWidth:i}=e,a=r-i;this.setVisible(this.leftHaze,n>gr),this.setVisible(this.rightHaze,a>gr&&n<a-gr)}setVisible(e,t){e&&(t?e.setAttribute(hr,``):e.removeAttribute(hr))}},xr=3,Sr=3,Cr=[`my-2`,`pr-5`],wr=[`relative`,`mb-7`,`after:content-[""]`,`after:absolute`,`after:-bottom-10`,`after:left-0`,`after:right-0`,`after:h-10`,`after:pointer-events-none`],Tr=class{constructor({data:e,config:n,api:r,readOnly:i,block:a}){this.initialContent=null,this.resize=null,this.addControls=null,this.rowColControls=null,this.cellBlocks=null,this.cellSelection=null,this.cornerDrag=null,this.scrollHaze=null,this.element=null,this.gridElement=null,this.scrollContainer=null,this.gripOverlay=null,this.pendingHighlight=null,this.isNewTable=!1,this.unregisterRestrictedTools=null,this.gridPasteCleanup=null,this.keyboardNavCleanup=null,this.setDataGeneration=0,this.structuralOpDepth=0,this.api=r,this.readOnly=i,this.config=n==null?{}:n;let o=yn(e,this.config);this.initialContent=o.content,this.grid=new Mt({readOnly:i}),this.model=new Dn(o),this.blockId=a==null?void 0:a.id,this.config.restrictedTools!==void 0&&(this.unregisterRestrictedTools=t.rr(this.config.restrictedTools))}runStructuralOp(e,t=!1){this.structuralOpDepth++;try{return e()}finally{this.structuralOpDepth--;let e=this.structuralOpDepth===0;if(e&&t){var n;(n=this.cellBlocks)==null||n.discardDeferredEvents()}if(e&&!t){var r;(r=this.cellBlocks)==null||r.flushDeferredEvents()}}}runTransactedStructuralOp(e,t=!1){if(!this.api.blocks.transact)return this.runStructuralOp(e,t);let n={current:void 0};return this.api.blocks.transact(()=>{n.current=this.runStructuralOp(e,t)}),n.current}teardownSubsystems(){var e,t,n,r,i,a,o,s;(e=this.resize)==null||e.destroy(),this.resize=null,(t=this.addControls)==null||t.destroy(),this.addControls=null,(n=this.cornerDrag)==null||n.destroy(),this.cornerDrag=null,(r=this.rowColControls)==null||r.destroy(),this.rowColControls=null,(i=this.cellSelection)==null||i.destroy(),this.cellSelection=null,(a=this.scrollHaze)==null||a.destroy(),this.scrollHaze=null,(o=this.gridPasteCleanup)==null||o.call(this),this.gridPasteCleanup=null,(s=this.keyboardNavCleanup)==null||s.call(this),this.keyboardNavCleanup=null}rebuildTableBody(){let e=this.gridElement;if(!e)return;let t=e.querySelector(`tbody`);if(!t)return;let n=new Map;t.querySelectorAll(`[data-blok-id]`).forEach(e=>{let t=e.getAttribute(`data-blok-id`);t&&n.set(t,e)});let r=this.grid.createGridFromModel(this.model).querySelector(`tbody`);if(!r)return;let i=this.model.snapshot().content;this.mountBlockHoldersInNewTbody(i,r,n),t.replaceWith(r)}mountBlockHoldersInNewTbody(e,t,n){let r=new Set;e.forEach((e,i)=>{e.forEach((e,a)=>{if(typeof e==`string`||e.mergedInto)return;let o=t.querySelector(`[${I}="${i}"][${L}="${a}"]`);if(!o)return;let s=o.querySelector(`[${z}]`);s&&e.blocks.forEach(e=>{let t=n.get(e);t&&!r.has(e)&&(s.appendChild(t),r.add(e))})})})}modelHasMerges(){return this.model.snapshot().content.some(e=>e.some(e=>{var t,n;return typeof e!=`string`&&(((t=e.colspan)==null?1:t)>1||((n=e.rowspan)==null?1:n)>1)}))}createFlatGrid(){var e,t;let n=((e=this.initialContent)==null?void 0:e.length)||this.config.rows||xr,r=((t=this.initialContent)==null?void 0:t.reduce((e,t)=>{var n;return Math.max(e,(n=t==null?void 0:t.length)==null?0:n)},0))||this.config.cols||Sr;return this.grid.createGrid(n,r,this.model.colWidths)}initSubsystems(e){this.initResize(e),this.initAddControls(e),this.initCornerDrag(e),this.initRowColControls(e),this.initCellSelection(e),this.initGridPasteListener(e),this.initScrollHaze()}static get toolbox(){return{icon:t.Zt,titleKey:`tools.table.title`,searchTerms:[`table`,`grid`,`spreadsheet`],searchTermKeys:[`table`,`grid`,`spreadsheet`]}}static get isReadOnlySupported(){return!0}static get enableLineBreaks(){return!0}static get pasteConfig(){return{tags:[`TABLE`,`TR`,{TH:{style:!0}},{TD:{style:!0}}]}}static get sanitize(){return{content:{br:!0,b:!0,i:!0,strong:!0,em:!0,mark:e=>{let n=e.style,r=Array.from({length:n.length},(e,t)=>n.item(t));for(let e of r)t.un.has(e)||n.removeProperty(e);return n.length>0?{style:!0}:{}},a:{href:!0,target:`_blank`,rel:`nofollow`},input:{type:!0,checked:!0}}}}ensureScrollContainer(){var e;if(this.scrollContainer)return this.scrollContainer;let t=document.createElement(`div`);t.setAttribute(`data-blok-table-scroll`,``);let n=this.gridElement;return n&&this.element&&(this.element.insertBefore(t,n),t.appendChild(n)),this.scrollContainer=t,(e=this.addControls)==null||e.attachScrollContainer(t),t}render(){var e,n,i,a;let o=document.createElement(`div`);o.className=r.n(Cr,!this.readOnly&&wr),o.setAttribute(t.Pr.tool,`table`),this.readOnly&&o.setAttribute(`data-blok-table-readonly`,``),this.isNewTable=((e=(n=this.initialContent)==null?void 0:n.length)==null?0:e)===0;let s=((i=(a=this.initialContent)==null?void 0:a.length)==null?0:i)>0,c=s&&this.modelHasMerges(),l=c?this.grid.createGridFromModel(this.model):this.createFlatGrid();if(s&&!c){var u;this.grid.fillGrid(l,(u=this.initialContent)==null?[]:u)}if(this.model.colWidths&&V(l,this.model.colWidths),this.gridElement=l,this.model.colWidths||!this.readOnly){let e=document.createElement(`div`);e.setAttribute(`data-blok-table-scroll`,``);let t=this.model.colWidths?xn:[];e.classList.add(...t),e.appendChild(l),o.appendChild(e),this.scrollContainer=e}else o.appendChild(l),this.scrollContainer=null;if(!this.readOnly){let e=document.createElement(`div`);e.setAttribute(`data-blok-table-grip-overlay`,``),e.style.position=`absolute`,e.style.inset=`0`,e.style.pointerEvents=`none`,e.style.zIndex=`3`,o.appendChild(e),this.gripOverlay=e}return this.element=o,this.model.withHeadings&&Cn(this.gridElement,this.model.withHeadings),this.model.withHeadingColumn&&U(this.gridElement,this.model.withHeadingColumn),this.readOnly||(this.initCellBlocks(l),this.keyboardNavCleanup=bn(l,this.cellBlocks)),o}rendered(){if(!this.element||this.initialContent===null)return;let e=this.gridElement;if(!e)return;let t=this.initialContent;if(this.initialContent=null,this.readOnly){var r;vn(e,t,this.api,(r=this.blockId)==null?``:r);let n=this.model.snapshot();wn(e,n.content),Tn(e,n.content),this.initScrollHaze();return}if(this.runTransactedStructuralOp(()=>{var r,i;let a=(r=(i=this.cellBlocks)==null?void 0:i.initializeCells(t))==null?t:r,o=this.isNewTable&&a.length===0?Array.from(e.querySelectorAll(`[${P}]`),e=>{let t=e.querySelectorAll(`[${F}]`).length;return Array.from({length:t},()=>({blocks:[]}))}):a;this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:o})),this.isNewTable&&H(e,this.cellBlocks),this.removeGhostChildren()},!0),this.model.initialColWidth===void 0){var i;let t=(i=this.model.colWidths)==null?B(e):i;this.model.setInitialColWidth(t.length>0?hn(t):void 0)}this.initSubsystems(e);let a=this.model.snapshot();if(wn(e,a.content),Tn(e,a.content),this.isNewTable){var o;(o=this.cellSelection)==null||o.selectRange({minRow:0,maxRow:0,minCol:0,maxCol:0})}}setReadOnly(e){let t=this.element,n=this.gridElement;if(!(!t||!n))if(this.readOnly=e,e){var r,i;this.teardownSubsystems(),(r=this.cellBlocks)==null||r.destroy(),this.cellBlocks=null,this.gripOverlay&&(this.gripOverlay.remove(),this.gripOverlay=null),wr.forEach(e=>t.classList.remove(e)),t.setAttribute(`data-blok-table-readonly`,``),vn(n,this.model.snapshot().content,this.api,(i=this.blockId)==null?``:i)}else{t.removeAttribute(`data-blok-table-readonly`),wr.forEach(e=>t.classList.add(e));let e=document.createElement(`div`);e.setAttribute(`data-blok-table-grip-overlay`,``),e.style.position=`absolute`,e.style.inset=`0`,e.style.pointerEvents=`none`,e.style.zIndex=`3`,t.appendChild(e),this.gripOverlay=e,this.initCellBlocks(n),this.keyboardNavCleanup=bn(n,this.cellBlocks),this.initSubsystems(n)}}removeGhostChildren(){let e=this.blockId;if(e===void 0)return;let t=this.api.blocks.getChildren(e).filter(e=>this.model.findCellForBlock(e.id)===null).map(e=>({id:e.id,index:this.api.blocks.getBlockIndex(e.id)})).filter(e=>e.index!==void 0).sort((e,t)=>t.index-e.index);for(let{index:e}of t)this.api.blocks.delete(e)}save(e){var t;let r=this.model.snapshot(),i=(t=this.blockId)==null?``:t,a=this.gridElement;return r.content=r.content.map((e,t)=>e.map((e,r)=>{if(!R(e))return e;let o=e.blocks.filter(e=>{var t,n,r;let a=(t=(n=this.api.blocks).getById)==null?void 0:t.call(n,e);return a!=null&&((r=a.parentId)==null?``:r)===i});if(o.length===0&&a){let o=a.querySelector(`[${I}="${t}"][${L}="${r}"]`),s=o==null?void 0:o.querySelector(`[${z}]`),c=s?Array.from(s.querySelectorAll(`[data-blok-id]`)).map(e=>{var t;return(t=e.getAttribute(`data-blok-id`))==null?``:t}).filter(e=>{var t,n,r;if(!e)return!1;let a=(t=(n=this.api.blocks).getById)==null?void 0:t.call(n,e);return a!=null&&((r=a.parentId)==null?``:r)===i}):[];if(c.length>0)return n.t(n.t({},e),{},{blocks:c})}return n.t(n.t({},e),{},{blocks:o})})),r}validate(e){return e.content.length>0}setData(e){var t,r,i,a,o;this.setDataGeneration++;let s=this.setDataGeneration,c=yn(n.t(n.t({},this.model.snapshot()),e),this.config);this.initialContent=c.content,this.model.replaceAll(c),this.api.blocks.isSyncingFromYjs||this.runStructuralOp(()=>{var e;(e=this.cellBlocks)==null||e.deleteAllBlocks()},!0),(t=this.cellBlocks)==null||t.destroy();let l=this.element;if(!(l!=null&&l.parentNode)||s!==this.setDataGeneration)return;let u=(r=(i=this.cellSelection)==null?void 0:i.getSelectedRange())==null?null:r,d=(a=(o=this.rowColControls)==null?void 0:o.getVisibleGripIndices())==null?null:a;this.teardownSubsystems();let f=this.render();l.parentNode.replaceChild(f,l);let p=this.gridElement;if(!p)return;if(this.readOnly){let e=this.model.snapshot();wn(p,e.content),Tn(p,e.content);return}if(s!==this.setDataGeneration)return;let m=this.api.blocks.isSyncingFromYjs;if(this.runStructuralOp(()=>{var e,t,r,i;let a=(e=(t=(r=this.cellBlocks)==null?void 0:r.initializeCells((i=this.initialContent)==null?[]:i))==null?this.initialContent:t)==null?[]:e;if(s===this.setDataGeneration){if(this.api.blocks.isSyncingFromYjs&&a.length===0&&p){let e=Array.from(p.querySelectorAll(`[${P}]`),e=>{let t=e.querySelectorAll(`[${F}]`).length;return Array.from({length:t},()=>({blocks:[]}))});this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:e}))}else this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:a}));this.initialContent=null}},!0),s!==this.setDataGeneration)return;this.initSubsystems(p),u!==null&&this.cellSelection!==null&&this.cellSelection.selectRange(u),d!==null&&this.rowColControls!==null&&this.rowColControls.restoreVisibleGrips(d.col,d.row);let h=this.model.snapshot();if(wn(p,h.content),Tn(p,h.content),m){var g;(g=this.cellBlocks)==null||g.reclaimReferencedBlocks(),Promise.resolve().then(()=>{var e;s===this.setDataGeneration&&((e=this.cellBlocks)==null||e.reclaimReferencedBlocks())})}}onPaste(e){var r,i;let a=e.detail.data,o=a.querySelectorAll(`tr`),s=[],c=[];o.forEach(e=>{let n=e.querySelectorAll(`td, th`),r=[],i=[];n.forEach(e=>{var n;r.push(e.innerHTML);let a=(n=e.getAttribute(`style`))==null?``:n,o={},s=/background-color\s*:\s*([^;]+)/i.exec(a);s!=null&&s[1]&&(o.color=t._n(s[1].trim(),`bg`));let c=RegExp(`(?<![a-z-])color\\s*:\\s*([^;]+)`,`i`).exec(a);c!=null&&c[1]&&!t.pn(c[1].trim())&&(o.textColor=t._n(c[1].trim(),`text`)),i.push(o)}),r.length>0&&(s.push(r),c.push(i))});let l=a.querySelector(`thead`)!==null,u=((r=o[0])==null?void 0:r.querySelector(`th`))!==null,d=l||u;this.initialContent=s,this.model.setWithHeadings(d),this.model.setWithHeadingColumn(!1),this.model.setColWidths(void 0),this.runStructuralOp(()=>{var e;(e=this.cellBlocks)==null||e.deleteAllBlocks()},!0),(i=this.cellBlocks)==null||i.destroy(),this.teardownSubsystems();let f=this.element;if(!(f!=null&&f.parentNode))return;let p=this.render();f.parentNode.replaceChild(p,f);let m=this.gridElement;if(!this.readOnly&&m){this.runStructuralOp(()=>{var e,t,r,i;let a=(e=(t=(r=this.cellBlocks)==null?void 0:r.initializeCells((i=this.initialContent)==null?[]:i))==null?this.initialContent:t)==null?[]:e;this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:a})),this.initialContent=null,c.forEach((e,t)=>{e.forEach((e,n)=>{e.color!==void 0&&this.model.setCellColor(t,n,e.color),e.textColor!==void 0&&this.model.setCellTextColor(t,n,e.textColor)})})},!0),this.initSubsystems(m);let e=this.model.snapshot();wn(m,e.content),Tn(m,e.content)}}destroy(){var e,t;if((e=this.unregisterRestrictedTools)==null||e.call(this),this.unregisterRestrictedTools=null,!this.api.blocks.isSyncingFromYjs){var n;(n=this.cellBlocks)==null||n.deleteAllBlocks()}this.teardownSubsystems(),(t=this.cellBlocks)==null||t.destroy(),this.cellBlocks=null,this.gridElement=null,this.scrollContainer=null,this.element=null}deleteRowWithCleanup(e){let t=this.gridElement;t&&this.runTransactedStructuralOp(()=>{var n;let{blocksToDelete:r}=this.model.deleteRow(e);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteRow(t,e)})}deleteColumnWithCleanup(e){let t=this.gridElement;t&&this.runTransactedStructuralOp(()=>{var n;let{blocksToDelete:r}=this.model.deleteColumn(e);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteColumn(t,e)})}getBlockIdsInRow(e){return gn(this.element,this.cellBlocks,e)}getBlockIdsInColumn(e){return _n(this.element,this.cellBlocks,e)}initAddControls(e){var t;if((t=this.addControls)==null||t.destroy(),!this.element)return;let n={addedCols:0};this.addControls=new Ot({wrapper:this.element,grid:e,i18n:this.api.i18n,getTableSize:()=>({rows:this.model.rows,cols:this.model.cols}),getNewColumnWidth:()=>{var t;let n=(t=this.model.colWidths)==null?B(e):t;return this.model.initialColWidth===void 0?mn(n):Math.round(this.model.initialColWidth/2*100)/100},onAddRow:()=>{this.runTransactedStructuralOp(()=>{var t,n;this.grid.addRow(e),this.model.addRow(),H(e,this.cellBlocks),Cn(this.gridElement,this.model.withHeadings),U(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(t=this.addControls)==null||t.syncRowButtonWidth(),(n=this.rowColControls)==null||n.refresh()})},onAddColumn:()=>{this.runTransactedStructuralOp(()=>{var t,n,r;let i=(t=this.model.colWidths)==null?B(e):t,a=this.model.initialColWidth===void 0?mn(i):Math.round(this.model.initialColWidth/2*100)/100;this.grid.addColumn(e,void 0,i,a),this.model.addColumn(void 0,a),this.model.setColWidths([...i,a]),H(e,this.cellBlocks),U(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(n=this.rowColControls)==null||n.refresh(),this.scrollContainer&&(this.scrollContainer.scrollLeft=this.scrollContainer.scrollWidth),(r=this.addControls)==null||r.syncRowButtonWidth()})},onDragStart:()=>{var e,t;this.resize&&(this.resize.enabled=!1),(e=this.rowColControls)==null||e.hideAllGrips(),(t=this.rowColControls)==null||t.setGripsDisplay(!1)},onDragAddRow:()=>{this.runTransactedStructuralOp(()=>{this.grid.addRow(e),this.model.addRow(),H(e,this.cellBlocks),Cn(this.gridElement,this.model.withHeadings),U(this.gridElement,this.model.withHeadingColumn)})},onDragRemoveRow:()=>{this.runTransactedStructuralOp(()=>{let t=this.grid.getRowCount(e);if(t>1&&cn(e,t-1)){var n;let{blocksToDelete:r}=this.model.deleteRow(t-1);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteRow(e,t-1)}})},onDragAddCol:()=>{this.runTransactedStructuralOp(()=>{var t;let r=(t=this.model.colWidths)==null?B(e):t,i=this.model.initialColWidth===void 0?mn(r):Math.round(this.model.initialColWidth/2*100)/100,a=[...r,i];this.grid.addColumn(e,void 0,r,i),this.model.addColumn(void 0,i),this.model.setColWidths(a),V(e,a),H(e,this.cellBlocks),U(this.gridElement,this.model.withHeadingColumn),this.initResize(e),n.addedCols++,this.scrollContainer&&(this.scrollContainer.scrollLeft=this.scrollContainer.scrollWidth)})},onDragRemoveCol:()=>{this.runTransactedStructuralOp(()=>{var t;let r=this.grid.getColumnCount(e);if(r<=1||!ln(e,r-1))return;let{blocksToDelete:i}=this.model.deleteColumn(r-1);(t=this.cellBlocks)==null||t.deleteBlocks(i),this.grid.deleteColumn(e,r-1);let a=this.model.colWidths;a&&V(e,a),this.initResize(e),n.addedCols--})},onDragEnd:()=>{var t,r;this.initResize(e),(t=this.rowColControls)==null||t.refresh(),this.scrollContainer&&(this.scrollContainer.scrollLeft=n.addedCols>0?this.scrollContainer.scrollWidth:0),(r=this.addControls)==null||r.syncRowButtonWidth(),n.addedCols=0}}),this.scrollContainer&&this.addControls.attachScrollContainer(this.scrollContainer)}initCornerDrag(e){var t;(t=this.cornerDrag)==null||t.destroy(),this.element&&(this.cornerDrag=new pr({wrapper:this.element,gridEl:e,onAddRow:()=>{this.runStructuralOp(()=>{this.grid.addRow(e),this.model.addRow(),H(e,this.cellBlocks),Cn(this.gridElement,this.model.withHeadings),U(this.gridElement,this.model.withHeadingColumn)})},onAddColumn:()=>{this.runStructuralOp(()=>{var t;let n=(t=this.model.colWidths)==null?B(e):t,r=this.model.initialColWidth===void 0?mn(n):Math.round(this.model.initialColWidth/2*100)/100,i=[...n,r];this.grid.addColumn(e,void 0,n,r),this.model.addColumn(void 0,r),this.model.setColWidths(i),V(e,i),Sn(this.ensureScrollContainer()),H(e,this.cellBlocks),U(this.gridElement,this.model.withHeadingColumn)})},onRemoveLastRow:()=>{this.runStructuralOp(()=>{var t;let n=this.grid.getRowCount(e);if(n<=1)return;let{blocksToDelete:r}=this.model.deleteRow(n-1);(t=this.cellBlocks)==null||t.deleteBlocks(r),this.grid.deleteRow(e,n-1)})},onRemoveLastColumn:()=>{this.runStructuralOp(()=>{var t;let n=this.grid.getColumnCount(e);if(n<=1)return;let{blocksToDelete:r}=this.model.deleteColumn(n-1);(t=this.cellBlocks)==null||t.deleteBlocks(r),this.grid.deleteColumn(e,n-1);let i=this.model.colWidths;i&&V(e,i)})},onDragStart:()=>{var e,t,n;this.resize&&(this.resize.enabled=!1),(e=this.rowColControls)==null||e.hideAllGrips(),(t=this.rowColControls)==null||t.setGripsDisplay(!1),(n=this.addControls)==null||n.setDisplay(!1)},onDragEnd:()=>{var t,n,r;this.initResize(e),(t=this.rowColControls)==null||t.refresh(),(n=this.addControls)==null||n.setDisplay(!0),(r=this.addControls)==null||r.syncRowButtonWidth()},getTableSize:()=>({rows:this.model.rows,cols:this.model.cols}),canRemoveLastRow:()=>this.model.rows>1&&cn(e,this.model.rows-1),canRemoveLastColumn:()=>this.model.cols>1&&ln(e,this.model.cols-1),onClickAdd:()=>{this.runTransactedStructuralOp(()=>{var t,n,r;this.grid.addRow(e),this.model.addRow(),H(e,this.cellBlocks),Cn(this.gridElement,this.model.withHeadings),U(this.gridElement,this.model.withHeadingColumn);let i=(t=this.model.colWidths)==null?B(e):t,a=this.model.initialColWidth===void 0?mn(i):Math.round(this.model.initialColWidth/2*100)/100,o=[...i,a];this.grid.addColumn(e,void 0,i,a),this.model.addColumn(void 0,a),this.model.setColWidths(o),V(e,o),H(e,this.cellBlocks),U(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(n=this.rowColControls)==null||n.refresh(),(r=this.addControls)==null||r.syncRowButtonWidth()})}}))}initRowColControls(e){var t,n,r;(t=this.rowColControls)==null||t.destroy(),this.element&&(this.rowColControls=new ur({grid:e,overlay:(n=this.gripOverlay)==null?void 0:n,scrollContainer:(r=this.scrollContainer)==null?void 0:r,getColumnCount:()=>this.grid.getColumnCount(e),getRowCount:()=>this.grid.getRowCount(e),isHeadingRow:()=>this.model.withHeadings,isHeadingColumn:()=>this.model.withHeadingColumn,i18n:this.api.i18n,onAction:t=>this.handleRowColAction(e,t),onDragStateChange:e=>{var t,n;this.resize&&(this.resize.enabled=!e),(t=this.addControls)==null||t.setDisplay(!e),(n=this.cornerDrag)==null||n.setDisplay(!e),e&&this.api.toolbar.close({setExplicitlyClosed:!1})},onGripClick:(e,t)=>{if(e===`row`){var n;(n=this.cellSelection)==null||n.selectRow(t)}else{var r;(r=this.cellSelection)==null||r.selectColumn(t)}},onGripPopoverClose:()=>{if(this.pendingHighlight){var e;let{type:t,index:n}=this.pendingHighlight;this.pendingHighlight=null,(e=this.rowColControls)==null||e.setActiveGrip(t,n),requestAnimationFrame(()=>{if(t===`row`){var e;(e=this.cellSelection)==null||e.selectRow(n)}else{var r;(r=this.cellSelection)==null||r.selectColumn(n)}})}else{var t;(t=this.cellSelection)==null||t.clearActiveSelection()}}}))}handleRowColAction(e,t){let n=this.setDataGeneration;this.runTransactedStructuralOp(()=>{var r,i;if(n!==this.setDataGeneration||this.gridElement!==e)return;let a=this.model.colWidths,{blocksToDelete:o}=this.syncModelForAction(t),s=Rn(e,t,{grid:this.grid,data:{colWidths:a,withHeadings:this.model.withHeadings,withHeadingColumn:this.model.withHeadingColumn,initialColWidth:this.model.initialColWidth},cellBlocks:this.cellBlocks,blocksToDelete:o});if(n!==this.setDataGeneration||this.gridElement!==e)return;if(this.model.setColWidths(s.colWidths),this.model.setWithHeadings(s.withHeadings),this.model.setWithHeadingColumn(s.withHeadingColumn),this.pendingHighlight=s.pendingHighlight,Cn(this.gridElement,this.model.withHeadings),U(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(r=this.addControls)==null||r.syncRowButtonWidth(),!(t.type===`toggle-heading`||t.type===`toggle-heading-column`)){var c;(c=this.rowColControls)==null||c.refresh()}if(!s.moveSelection)return;let{type:l,index:u}=s.moveSelection;if(l===`row`){var d;(d=this.cellSelection)==null||d.selectRow(u)}else{var f;(f=this.cellSelection)==null||f.selectColumn(u)}(i=this.rowColControls)==null||i.setActiveGrip(l,u)})}syncModelForAction(e){switch(e.type){case`insert-row-above`:this.model.addRow(e.index);break;case`insert-row-below`:this.model.addRow(e.index+1);break;case`insert-col-left`:this.model.addColumn(e.index);break;case`insert-col-right`:this.model.addColumn(e.index+1);break;case`move-row`:this.model.moveRow(e.fromIndex,e.toIndex);break;case`move-col`:this.model.moveColumn(e.fromIndex,e.toIndex);break;case`delete-row`:return this.model.deleteRow(e.index);case`delete-col`:return this.model.deleteColumn(e.index);case`toggle-heading`:case`toggle-heading-column`:break}return{}}initResize(e){var t,n;(t=this.resize)==null||t.destroy();let r=this.model.colWidths===void 0,i=(n=this.model.colWidths)==null?B(e):n;r||Sn(this.ensureScrollContainer()),this.resize=new jn(e,i,e=>{var t,n,r;this.model.setColWidths(e),Sn(this.ensureScrollContainer()),(t=this.rowColControls)==null||t.positionGrips(),(n=this.addControls)==null||n.syncRowButtonWidth(),(r=this.scrollHaze)==null||r.update()},()=>{var e;(e=this.rowColControls)==null||e.hideAllGrips()},()=>{var e,t;(e=this.addControls)==null||e.syncRowButtonWidth(),(t=this.scrollHaze)==null||t.update()},r)}initCellBlocks(e){var t;this.cellBlocks=new Nt({api:this.api,gridElement:e,tableBlockId:(t=this.blockId)==null?``:t,model:this.model,isStructuralOpActive:()=>this.structuralOpDepth>0})}handleCellCopy(e,n){let r=this.collectCellBlockData(e);if(r.length===0)return;let i=t.gn(r);n.setData(`text/html`,t.dn(i)),n.setData(`text/plain`,t.fn(i))}handleCellCopyViaButton(e){let n=this.collectCellBlockData(e);if(n.length===0)return;let r=t.gn(n),i=t.dn(r),a=t.fn(r),o=new Blob([i],{type:`text/html`}),s=new Blob([a],{type:`text/plain`});navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":s})])}handleCellColorChange(e,t,n){let r=this.gridElement;r&&this.runTransactedStructuralOp(()=>{for(let i of e){let e=on(r,i);e&&(n===`backgroundColor`?(this.model.setCellColor(e.row,e.col,t==null?void 0:t),i.style.backgroundColor=t==null?``:t):(this.model.setCellTextColor(e.row,e.col,t==null?void 0:t),i.style.color=t==null?``:t))}})}handleCellPlacementChange(e,t){let n=this.gridElement;n&&this.runTransactedStructuralOp(()=>{for(let r of e){let e=on(n,r);if(!e)continue;this.model.setCellPlacement(e.row,e.col,t===`top-left`?void 0:t);let i=r.querySelector(`[${z}]`);i&&(t===`top-left`?i.removeAttribute(`data-blok-cell-placement`):i.setAttribute(`data-blok-cell-placement`,t))}})}collectCellBlockData(e){return this.gridElement?e.map(e=>{var t,r,i;let a=parseInt((t=e.getAttribute(`data-blok-table-cell-row`))==null?`0`:t,10),o=parseInt((r=e.getAttribute(`data-blok-table-cell-col`))==null?`0`:r,10),s=e.querySelector(`[${z}]`),c=[];if(!s)return{row:a,col:o,blocks:c};s.querySelectorAll(`[data-blok-id]`).forEach(e=>{let t=e.getAttribute(`data-blok-id`);if(!t)return;let r=this.api.blocks.getBlockIndex(t);if(r===void 0)return;let i=this.api.blocks.getBlockByIndex(r);i&&c.push(n.t({tool:i.name,data:i.preservedData},Object.keys(i.preservedTunes).length>0?{tunes:i.preservedTunes}:{}))});let l=c.length===0?((i=s.innerHTML)==null?``:i).trim():``;c.length===0&&l.length>0&&c.push({tool:`paragraph`,data:{text:l}});let u=this.model.getCellColor(a,o),d=this.model.getCellTextColor(a,o);return n.t(n.t({row:a,col:o,blocks:c},u===void 0?{}:{color:u}),d===void 0?{}:{textColor:d})}):[]}initCellSelection(e){var t;(t=this.cellSelection)==null||t.destroy();let n=this.api.rectangleSelection;this.cellSelection=new an({grid:e,rectangleSelection:n,i18n:this.api.i18n,isPopoverOpen:()=>{var e,t;return(e=(t=this.rowColControls)==null?void 0:t.isPopoverOpen)==null?!1:e},onPointerDragActiveChange:e=>{var t,n;(t=(n=this.api.blocks).setPointerDragActive)==null||t.call(n,e)},onSelectionActiveChange:e=>{var t,n,r;this.resize&&(this.resize.enabled=!e),(t=this.addControls)==null||t.setInteractive(!e),(n=this.cornerDrag)==null||n.setInteractive(!e),(r=this.rowColControls)==null||r.setGripsDisplay(!e)},onSelectionRangeChange:()=>{var e;(e=this.rowColControls)==null||e.setGripsDisplay(!0)},onClearContent:e=>{let t=this.cellBlocks;t&&this.runTransactedStructuralOp(()=>{let n=t.getBlockIdsFromCells(e);t.deleteBlocks(n);let r=this.gridElement;if(r)for(let t of e){let e=on(r,t);e&&(this.model.setCellColor(e.row,e.col,void 0),this.model.setCellTextColor(e.row,e.col,void 0),t.style.backgroundColor=``,t.style.color=``)}})},onCopy:(e,t)=>{this.handleCellCopy(e,t)},onCut:(e,t)=>{this.handleCellCopy(e,t)},onCopyViaButton:e=>{this.handleCellCopyViaButton(e)},onColorChange:(e,t,n)=>{this.handleCellColorChange(e,t,n)},onPlacementChange:(e,t)=>{this.handleCellPlacementChange(e,t)},getCellPlacement:(e,t)=>this.model.getCellPlacement(e,t),canMergeCells:e=>this.model.canMergeCells(e),onMergeCells:e=>{this.runTransactedStructuralOp(()=>{this.model.mergeCells(e),this.rebuildTableBody()})},isMergedCell:(e,t)=>this.model.isMergedCell(e,t),onSplitCell:(e,t)=>{this.runTransactedStructuralOp(()=>{this.model.splitCell(e,t),this.rebuildTableBody()})},getCellSpan:(e,t)=>this.model.getCellSpan(e,t)})}initScrollHaze(){var e;(e=this.scrollHaze)==null||e.destroy(),!(!this.element||!this.scrollContainer)&&(this.scrollHaze=new br,this.scrollHaze.init(this.element,this.scrollContainer))}initGridPasteListener(e){let t=t=>{this.handleGridPaste(t,e)};e.addEventListener(`paste`,t),this.gridPasteCleanup=()=>{e.removeEventListener(`paste`,t)}}handleGridPaste(e,n){var r,i;if(this.readOnly||!e.clipboardData||e.defaultPrevented)return;let a=e.clipboardData.getData(`text/html`),o=t.mn(a),s=o===null?t.hn(a):null,c=o==null?s:o;if(!c||s!==null&&new DOMParser().parseFromString(a,`text/html`).querySelectorAll(`table`).length>1)return;let l=document.activeElement;if(!l)return;let u=l.closest(`[${F}]`);if(!u||!n.contains(u)||!u.closest(`[data-blok-table-row]`))return;if(c.rows===1&&c.cols===1){e.preventDefault(),e.stopPropagation(),this.insertSingleCellPayloadInline(c.cells[0][0]);return}e.preventDefault(),e.stopPropagation();let d=parseInt((r=u.getAttribute(`data-blok-table-cell-row`))==null?`0`:r,10),f=parseInt((i=u.getAttribute(`data-blok-table-cell-col`))==null?`0`:i,10);this.pastePayloadIntoCells(n,c,d,f)}insertSingleCellPayloadInline(e){let t=e.blocks.map(e=>typeof e.data.text==`string`?e.data.text:``).filter(Boolean).join(`<br>`);if(!t)return;let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0);r.collapsed||r.deleteContents();let i=document.createDocumentFragment(),a=document.createElement(`div`);a.innerHTML=t,Array.from(a.childNodes).forEach(e=>i.appendChild(e)),i.childNodes.length===0&&i.appendChild(new Text);let o=i.lastChild;r.insertNode(i);let s=document.createRange(),c=o.nodeType===Node.TEXT_NODE?o:o.firstChild;c!==null&&c.textContent!==null&&s.setStart(c,c.textContent.length),n.removeAllRanges(),n.addRange(s)}pastePayloadIntoCells(e,t,n,r){this.runTransactedStructuralOp(()=>{var i,a;this.expandGridForPaste(e,n+t.rows,r+t.cols);let o=e.querySelectorAll(`[${P}]`);Array.from({length:t.rows},(e,t)=>t).forEach(e=>{let i=o[n+e];if(!i)return;let a=i.querySelectorAll(`[${F}]`);Array.from({length:t.cols},(e,t)=>t).forEach(i=>{let o=a[r+i];if(o){var s,c,l,u;let a=t.cells[e][i];this.pasteCellPayload(o,a);let d=(s=(c=this.cellBlocks)==null?void 0:c.getBlockIdsFromCells([o]))==null?[]:s;this.model.setCellBlocks(n+e,r+i,d);let f=n+e,p=r+i;this.model.setCellColor(f,p,a.color),o.style.backgroundColor=(l=a.color)==null?``:l,this.model.setCellTextColor(f,p,a.textColor),o.style.color=(u=a.textColor)==null?``:u}})}),this.initResize(e),(i=this.addControls)==null||i.syncRowButtonWidth(),(a=this.rowColControls)==null||a.refresh()});let i=e.querySelectorAll(`[${P}]`)[n+t.rows-1],a=i==null?void 0:i.querySelectorAll(`[${F}]`)[r+t.cols-1];if(!a||!this.cellBlocks||!this.api.caret)return;let o=this.cellBlocks.getBlockIdsFromCells([a]),s=o[o.length-1];s!==void 0&&this.api.caret.setToBlock(s,`end`)}expandGridForPaste(e,t,n){let r=this.grid.getRowCount(e),i=this.grid.getColumnCount(e);Array.from({length:Math.max(0,t-r)}).forEach(()=>{this.grid.addRow(e),this.model.addRow(),H(e,this.cellBlocks),Cn(this.gridElement,this.model.withHeadings),U(this.gridElement,this.model.withHeadingColumn)}),Array.from({length:Math.max(0,n-i)}).forEach(()=>{var t;let n=(t=this.model.colWidths)==null?B(e):t,r=this.model.initialColWidth===void 0?mn(n):Math.round(this.model.initialColWidth/2*100)/100;this.grid.addColumn(e,void 0,n,r),this.model.addColumn(void 0,r),this.model.setColWidths([...n,r]),H(e,this.cellBlocks),U(this.gridElement,this.model.withHeadingColumn)})}pasteCellPayload(e,t){if(this.cellBlocks){let t=this.cellBlocks.getBlockIdsFromCells([e]);this.cellBlocks.deleteBlocks(t)}let n=e.querySelector(`[${z}]`);if(n){if(t.blocks.length===0){var r;(r=this.cellBlocks)==null||r.ensureCellHasBlock(e);return}for(let e of t.blocks){var i;let t=this.api.blocks.insert(e.tool,e.data,{},this.api.blocks.getBlocksCount(),!1);n.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,(i=this.blockId)==null?``:i)}}}},Er=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},Dr=(e,t,n,r)=>{if(!t)return e;let i=n();return{text:i?a(i.innerHTML):e.text,isOpen:r}},Or=(e,t)=>{let{data:n,getContentElement:r}=e;n.text+=t.text;let i=r();if(i&&t.text){let n=e.parseHTML(t.text);i.appendChild(n),i.normalize()}},kr=(e,t,r)=>{let i=r();if(!i)return{newData:e,inPlace:!1};let a=n.t(n.t({},e),t);return typeof t.text==`string`&&(i.innerHTML=t.text),{newData:a,inPlace:!0}},Ar=class e{constructor({data:e,config:t,api:n,readOnly:r,block:i}){var a;this._element=null,this._contentElement=null,this._arrowElement=null,this._bodyPlaceholderElement=null,this._childContainerElement=null,this.handleChildContainerInput=()=>{S(this._element,this._childContainerElement)},this.handleBlockChanged=e=>{this.isBlockChangedPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)&&this.updateBodyPlaceholderVisibility()},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this._isOpen=(a=this._data.isOpen)==null?!0:a,i&&(this.blockId=i.id),r||this.api.events.on(`block changed`,this.handleBlockChanged)}normalizeData(e){if(typeof e==`object`&&e&&`text`in e){let t={text:typeof e.text==`string`?e.text:``};return typeof e.isOpen==`boolean`&&(t.isOpen=e.isOpen),t}if(typeof e==`object`&&e&&`title`in e){let t=e,n={text:typeof t.title==`string`?t.title:``};return typeof t.isExpanded==`boolean`&&(n.isOpen=t.isExpanded),n}return{text:``}}get placeholder(){if(this._settings.placeholder)return this._settings.placeholder;let e=this.api.i18n.t(t.l);return e===`tools.toggle.placeholder`?`Toggle`:e}render(){let e=C({data:this._data,readOnly:this.readOnly,isOpen:this._isOpen,placeholder:this.placeholder,keydownHandler:this.readOnly?null:this.handleKeyDown.bind(this),onArrowClick:()=>this.toggleOpen(),onBodyPlaceholderClick:this.readOnly?null:()=>this.handleBodyPlaceholderClick(),bodyPlaceholderText:this.api.i18n.t(t.o),ariaLabels:{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}});return this._element=e.wrapper,this._contentElement=e.contentElement,this._arrowElement=e.arrowElement,this._bodyPlaceholderElement=e.bodyPlaceholderElement,this._childContainerElement=e.childContainerElement,this._childContainerElement.addEventListener(`input`,this.handleChildContainerInput),this._element}rendered(){this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}save(){return Dr(this._data,this._element,this.getContentElement.bind(this),this._isOpen)}validate(e){return!0}merge(e){Or({data:this._data,getContentElement:this.getContentElement.bind(this),parseHTML:Er},e)}onPaste(n){let r=n.detail;if(!(`data`in r))return;let i=r.data,a=i.querySelector(`summary`),o=t.Pn(a===null?i.innerHTML:a.innerHTML,e.sanitize.text);this._data={text:o};let s=this.getContentElement();s!==null&&(s.innerHTML=o)}setData(e){let n=kr(this._data,e,this.getContentElement.bind(this));return this._data=n.newData,typeof this._data.isOpen==`boolean`&&(this._isOpen=this._data.isOpen),this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility(),n.inPlace}renderSettings(){return[]}expand(){this._isOpen||this.setOpenState(!0)}collapse(){this._isOpen&&this.setOpenState(!1)}setReadOnly(e){if(!this._element)return;let t=this.readOnly;this.readOnly=e,this._contentElement&&(this._contentElement.contentEditable=e?`false`:`true`),e&&!t?this.api.events.off(`block changed`,this.handleBlockChanged):!e&&t&&this.api.events.on(`block changed`,this.handleBlockChanged),this.updateBodyPlaceholderVisibility()}removed(){this.api.events.off(`block changed`,this.handleBlockChanged)}isBlockChangedPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}getContentElement(){return this._contentElement}setOpenState(e){this._isOpen=e,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}toggleOpen(){this.setOpenState(!this._isOpen)}updateChildrenVisibility(){this.blockId!==void 0&&T(this.api,this.blockId,this._isOpen,this._childContainerElement,this._arrowElement)}updateBodyPlaceholderVisibility(){this.blockId!==void 0&&(E(this._bodyPlaceholderElement,this.api,this.blockId,this._isOpen,this.readOnly),S(this._element,this._childContainerElement))}handleBodyPlaceholderClick(){var e;if(this.blockId===void 0)return;let t=this.api.blocks.getBlockIndex(this.blockId);if(t===void 0)return;let n=this.api.blocks.insertInsideParent(this.blockId,t+1);this.api.caret.setToBlock(n.id,`start`),(e=this._bodyPlaceholderElement)==null||e.classList.add(`hidden`)}handleKeyDown(e){if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}if(e.key===`Backspace`){this.handleBackspace(e);return}}createKeyboardContext(){return{api:this.api,blockId:this.blockId,data:this._data,element:this._element,getContentElement:this.getContentElement.bind(this),syncContentFromDOM:this.syncContentFromDOM.bind(this),isOpen:this._isOpen,setOpen:e=>{this._isOpen=e}}}async handleEnter(){var e=this;await D(e.createKeyboardContext()),e.updateBodyPlaceholderVisibility()}async handleBackspace(e){await O(this.createKeyboardContext(),e)}syncContentFromDOM(){let e=this.getContentElement();e&&(this._data.text=e.innerHTML)}static get toolbox(){return{icon:t.nn,titleKey:`toggleList`,name:t.p,searchTerms:[`toggle`,`collapse`,`expand`,`accordion`],searchTermKeys:[`toggle`,`collapse`,`expand`,`accordion`],shortcut:`>`}}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,a:{href:!0,target:`_blank`,rel:`nofollow`},b:!0,i:!0,mark:{class:!0,style:!0},code:!0}}}static get pasteConfig(){return{tags:[`DETAILS`]}}static get isReadOnlySupported(){return!0}},jr=`callout`,Mr=`tools.callout.color`,Nr=`tools.callout.editIcon`,Pr=`tools.callout.addEmoji`,Fr=`tools.callout.removeEmoji`,Ir=`tools.callout.filterEmojis`,Lr=`tools.callout.calloutEmojiCategory`,Rr=`tools.callout.noEmojisFound`,zr=`tools.callout.pickRandom`,Br=`tools.callout.skinTone`,Vr=`tools.callout.emojiCategoryPeople`,Hr=`tools.callout.emojiCategoryNature`,Ur=`tools.callout.emojiCategoryFood`,Wr=`tools.callout.emojiCategoryActivity`,Gr=`tools.callout.emojiCategoryTravel`,Kr=`tools.callout.emojiCategoryObjects`,qr=`tools.callout.emojiCategorySymbols`,Jr=`tools.callout.emojiCategoryFlags`,Yr=`💡`,Xr=`rounded-xl pl-8 pr-4 py-[5px] my-1 flex items-start gap-2 relative`,Zr=`text-[1.5rem] leading-[1] cursor-pointer bg-transparent border-0 px-0 py-[7px] h-[38px] flex-shrink-0 select-none`,Qr=`flex-1 min-w-0`;function $r(e){let{emoji:n,readOnly:r,addEmojiLabel:i}=e,a=document.createElement(`div`);a.className=Xr;let o=document.createElement(`button`);o.type=`button`,o.className=Zr,o.textContent=n||``,o.setAttribute(`aria-label`,n===``?i:n),o.setAttribute(`tabindex`,`0`),o.setAttribute(`data-blok-testid`,`callout-emoji-btn`),r&&(o.disabled=!0);let s=document.createElement(`div`);return s.className=Qr,s.setAttribute(t.u.toggleChildren,``),s.setAttribute(t.Pr.nestedBlocks,``),s.setAttribute(`data-blok-child-toolbar`,``),s.setAttribute(`data-blok-mutation-free`,`true`),a.appendChild(o),a.appendChild(s),{wrapper:a,emojiButton:o,childContainer:s}}function ei(e){return{emoji:e.emoji,textColor:e.textColor,backgroundColor:e.backgroundColor}}async function ti(e){if(e.calloutBlockId===void 0)return;let t=e.api.blocks.getChildren(e.calloutBlockId);if(e.event.preventDefault(),t.length<=1){await e.api.blocks.convert(e.calloutBlockId,`paragraph`);return}let n=e.api.blocks.getBlockIndex(e.firstChildBlockId);n!==void 0&&await e.api.blocks.delete(n);let r=e.api.blocks.getBlockIndex(e.calloutBlockId);r!==void 0&&r>0&&e.api.caret.setToBlock(r-1,`end`)}var ni=[`💡`,`👉`,`☝️`,`✅`,`⚠️`,`🔑`,`🔥`,`📌`,`✂️`,`❓`,`🚫`,`⏰`,`♻️`,`🔒`,`📖`,`👣`,`➡️`,`📢`,`🛠️`,`⚙️`],ri={data:null};function ii(e,t){let n=[];for(let r of e.emojis){let i=t[r];if(i===void 0)continue;let a=i.skins[0];a!==void 0&&n.push({native:a.native,skins:i.skins.map(e=>e.native),id:i.id,name:i.name,keywords:i.keywords,category:e.id})}return n}async function ai(){if(ri.data!==null)return ri.data;let e=await Promise.resolve().then(()=>require(`./native-Bok_u8yD.cjs`)),t=`default`in e&&e.default!==void 0?e.default:e,n=t.categories.flatMap(e=>ii(e,t.emojis));return ri.data=n,n}function oi(e,t,n){let r=t.toLowerCase();return e.filter(e=>{if(e.name.toLowerCase().includes(r)||e.keywords.some(e=>e.includes(r)))return!0;let t=n==null?void 0:n[e.native];return t===void 0?!1:t.n.toLowerCase().includes(r)||t.k!==void 0&&t.k.some(e=>e.toLowerCase().includes(r))})}function si(e){let t=new Map;for(let r of e){var n;let e=(n=t.get(r.category))==null?[]:n;e.push(r),t.set(r.category,e)}return t}var ci=new Map,li={am:()=>Promise.resolve().then(()=>require(`./am-CGgVs8Sg.cjs`)),ar:()=>Promise.resolve().then(()=>require(`./ar-nFMIw80i.cjs`)),az:()=>Promise.resolve().then(()=>require(`./az-Cb6l6ydx.cjs`)),bg:()=>Promise.resolve().then(()=>require(`./bg-BdZUTRFn.cjs`)),bn:()=>Promise.resolve().then(()=>require(`./bn-CneGelWq.cjs`)),bs:()=>Promise.resolve().then(()=>require(`./bs-XAmTKQeJ.cjs`)),cs:()=>Promise.resolve().then(()=>require(`./cs-DKYguxBC.cjs`)),da:()=>Promise.resolve().then(()=>require(`./da-DiLbdYqu.cjs`)),de:()=>Promise.resolve().then(()=>require(`./de-ClyUjm_W.cjs`)),el:()=>Promise.resolve().then(()=>require(`./el-CFVhJTIb.cjs`)),es:()=>Promise.resolve().then(()=>require(`./es-BlajxX2r.cjs`)),et:()=>Promise.resolve().then(()=>require(`./et-ggACA1d9.cjs`)),fa:()=>Promise.resolve().then(()=>require(`./fa-DuYd0CQw.cjs`)),fi:()=>Promise.resolve().then(()=>require(`./fi-D3-4SL4-.cjs`)),fil:()=>Promise.resolve().then(()=>require(`./fil-Cs84dmNe.cjs`)),fr:()=>Promise.resolve().then(()=>require(`./fr-C8Z2PE7u.cjs`)),gu:()=>Promise.resolve().then(()=>require(`./gu-CPQY3Iyq.cjs`)),he:()=>Promise.resolve().then(()=>require(`./he-BkMGwSM7.cjs`)),hi:()=>Promise.resolve().then(()=>require(`./hi-ClQSrRZz.cjs`)),hr:()=>Promise.resolve().then(()=>require(`./hr-wrh48ogh.cjs`)),hu:()=>Promise.resolve().then(()=>require(`./hu-BSVMkfs2.cjs`)),hy:()=>Promise.resolve().then(()=>require(`./hy-CwF59lJj.cjs`)),id:()=>Promise.resolve().then(()=>require(`./id-DN2KcAmG.cjs`)),it:()=>Promise.resolve().then(()=>require(`./it-CSt1S7SQ.cjs`)),ja:()=>Promise.resolve().then(()=>require(`./ja-BbwATm6F.cjs`)),ka:()=>Promise.resolve().then(()=>require(`./ka-Cqnq4zZT.cjs`)),km:()=>Promise.resolve().then(()=>require(`./km-COh3mhzp.cjs`)),kn:()=>Promise.resolve().then(()=>require(`./kn-CX062fVg.cjs`)),ko:()=>Promise.resolve().then(()=>require(`./ko-gSw_U9kC.cjs`)),ku:()=>Promise.resolve().then(()=>require(`./ku-DnvmAkID.cjs`)),lo:()=>Promise.resolve().then(()=>require(`./lo-BrwlEjmE.cjs`)),lt:()=>Promise.resolve().then(()=>require(`./lt-Bw969G31.cjs`)),lv:()=>Promise.resolve().then(()=>require(`./lv-DhwZOfiA.cjs`)),mk:()=>Promise.resolve().then(()=>require(`./mk-vuwbN_RA.cjs`)),ml:()=>Promise.resolve().then(()=>require(`./ml-DQZZm6v3.cjs`)),mn:()=>Promise.resolve().then(()=>require(`./mn-Dz3r2r3T.cjs`)),mr:()=>Promise.resolve().then(()=>require(`./mr-BDjve7Md.cjs`)),ms:()=>Promise.resolve().then(()=>require(`./ms-2boGmWFn.cjs`)),my:()=>Promise.resolve().then(()=>require(`./my-BtRZdE5q.cjs`)),ne:()=>Promise.resolve().then(()=>require(`./ne-C9oc_I3v.cjs`)),nl:()=>Promise.resolve().then(()=>require(`./nl-CkIGPyM6.cjs`)),no:()=>Promise.resolve().then(()=>require(`./no-De7tM2WX.cjs`)),pa:()=>Promise.resolve().then(()=>require(`./pa-Bm15OLTz.cjs`)),pl:()=>Promise.resolve().then(()=>require(`./pl-D80QrSlq.cjs`)),ps:()=>Promise.resolve().then(()=>require(`./ps-ySfeV5NE.cjs`)),pt:()=>Promise.resolve().then(()=>require(`./pt-Bigoi5oj.cjs`)),ro:()=>Promise.resolve().then(()=>require(`./ro-Dvtjmd-W.cjs`)),ru:()=>Promise.resolve().then(()=>require(`./ru-dq73Ra3e.cjs`)),sd:()=>Promise.resolve().then(()=>require(`./sd-BhtQCaFq.cjs`)),si:()=>Promise.resolve().then(()=>require(`./si-CWG8h4tD.cjs`)),sk:()=>Promise.resolve().then(()=>require(`./sk-Bkag9oKD.cjs`)),sl:()=>Promise.resolve().then(()=>require(`./sl-BhupPCcO.cjs`)),sq:()=>Promise.resolve().then(()=>require(`./sq-Bosym4Xb.cjs`)),sr:()=>Promise.resolve().then(()=>require(`./sr-DFPGZJ0s.cjs`)),sv:()=>Promise.resolve().then(()=>require(`./sv-CiYmSxqX.cjs`)),sw:()=>Promise.resolve().then(()=>require(`./sw-CMbHoINv.cjs`)),ta:()=>Promise.resolve().then(()=>require(`./ta-BrC1o95Z.cjs`)),te:()=>Promise.resolve().then(()=>require(`./te-DAKpWpi8.cjs`)),th:()=>Promise.resolve().then(()=>require(`./th-D0CG2M2k.cjs`)),tr:()=>Promise.resolve().then(()=>require(`./tr-Bw_nVU1b.cjs`)),ug:()=>Promise.resolve().then(()=>require(`./ug-DvC-UnxD.cjs`)),uk:()=>Promise.resolve().then(()=>require(`./uk-Cx32rUi7.cjs`)),ur:()=>Promise.resolve().then(()=>require(`./ur-BMh2seDu.cjs`)),vi:()=>Promise.resolve().then(()=>require(`./vi-4TUS0GSi.cjs`)),zh:()=>Promise.resolve().then(()=>require(`./zh-DZtmJNDR.cjs`))};async function ui(e){if(e===`en`)return null;let t=ci.get(e);if(t!==void 0)return t;let n=li[e];if(n===void 0)return null;try{let t=(await n()).default;return ci.set(e,t),t}catch(e){return null}}var di={callout:Lr,people:Vr,nature:Hr,foods:Ur,activity:Wr,places:Gr,objects:Kr,symbols:qr,flags:Jr},fi=[[`callout`,t.it],[`people`,t.nt],[`nature`,t.rt],[`foods`,t.at],[`activity`,t.Z],[`places`,t.$],[`objects`,t.tt],[`symbols`,t.et],[`flags`,t.Q]],pi=[`✋`,`✋🏻`,`✋🏼`,`✋🏽`,`✋🏾`,`✋🏿`],mi=`blok-emoji-skin-tone`;function hi(){try{let e=localStorage.getItem(mi);if(e===null)return 0;let t=parseInt(e,10);return t>=0&&t<=5?t:0}catch(e){return 0}}function gi(e){try{localStorage.setItem(mi,String(e))}catch(e){}}var _i=t.q,vi=class{constructor(e){this._localeData=null,this._open=!1,this._allEmojis=[],this._skinTone=0,this._showingEmptyState=!1,this._anchorEl=null,this._backdrop=null,this._savedOverflow=``,this._navButtons=new Map,this._sectionEls=new Map,this._activeNavId=``,this._navRafId=0,this._skinToneButtons=[],this.onSelect=e.onSelect,this.onRemove=e.onRemove,this.i18n=e.i18n,this._locale=e.locale,this._element=this.buildElement();let t=this._element.querySelector(`[data-emoji-picker-body]`),n=this._element.querySelector(`[data-emoji-picker-nav]`),r=this._element.querySelector(`input[type="text"]`);if(t===null||n===null||r===null)throw Error(`EmojiPicker: failed to build required elements`);this._body=t,this._nav=n,this._filterInput=r,this._body.addEventListener(`scroll`,()=>{cancelAnimationFrame(this._navRafId),this._navRafId=requestAnimationFrame(()=>this.updateActiveNav())},{passive:!0})}getElement(){return this._element}isOpen(){return this._open}async open(e){var t=this;t._anchorEl=e,t._open=!0,t._filterInput.value=``,t._element.setAttribute(`data-theme`,t.resolveTheme());let n=hi();if(n!==t._skinTone){t._skinTone=n,t._skinToneToggle.textContent=pi[n];for(let[e,r]of t._skinToneButtons.entries())t.applySkinToneActiveStyle(r,e===n)}if(t._allEmojis.length===0&&(t._allEmojis=await ai()),t._locale!==`en`&&t._localeData===null){let e=await ui(t._locale);e!==null&&(t._localeData=e)}t.renderEmojiGrid(t._allEmojis),t.showBackdrop(),t._element.style.animation=`none`,t._element.hidden=!1,t.position(e),t._element.offsetHeight,t._element.style.animation=``,t._filterInput.focus()}close(){var e;this._open=!1,this._element.hidden=!0,this.closeSkinTonePopover(),this.removeBackdrop(),(e=this._anchorEl)==null||e.focus()}buildElement(){let e=document.createElement(`div`);e.setAttribute(`data-blok-emoji-picker`,``),e.className=[`fixed z-50 w-[400px] overflow-hidden rounded-xl`,`border border-neutral-200/70 bg-white shadow-2xl`,`theme-dark:border-neutral-700/50 theme-dark:bg-neutral-900`].join(` `),e.hidden=!0;let n=document.createElement(`div`);n.className=`flex items-center gap-2.5 px-3 pt-3 pb-2`;let r=document.createElement(`div`);r.className=`relative flex-1 min-w-0`;let i=document.createElement(`span`);i.className=[`pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 flex items-center`,`text-neutral-400 theme-dark:text-neutral-500 [&>svg]:w-[16px] [&>svg]:h-[16px]`].join(` `),i.innerHTML=t.qt;let a=document.createElement(`input`);a.type=`text`,a.placeholder=this.i18n.t(Ir),a.className=[`w-full text-[13px] rounded-lg py-[7px] pl-8 pr-3 outline-hidden`,`bg-neutral-100 text-neutral-800 placeholder:text-neutral-400`,`theme-dark:bg-neutral-800 theme-dark:text-neutral-200 theme-dark:placeholder:text-neutral-500`,`focus:ring-2 focus:ring-neutral-300/60 theme-dark:focus:ring-neutral-600/60`,`transition-shadow duration-150`].join(` `),a.addEventListener(`input`,()=>this.handleFilterChange(a.value)),r.appendChild(i),r.appendChild(a);let o=document.createElement(`div`);o.className=`relative flex-shrink-0`;let s=document.createElement(`button`);s.type=`button`,s.setAttribute(`data-emoji-picker-skin-toggle`,``),s.setAttribute(`aria-label`,this.i18n.t(Br)),s.title=this.i18n.t(Br),s.className=[`w-[28px] h-[28px] flex items-center justify-center rounded-lg`,`text-[14px] leading-none cursor-pointer select-none`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-800`,`active:scale-90 transition-all duration-100`].join(` `),s.textContent=pi[this._skinTone],s.addEventListener(`click`,()=>this.toggleSkinTonePopover()),this._skinToneToggle=s,o.appendChild(s),this._skinTonePopover=this.buildSkinTonePopover(),o.appendChild(this._skinTonePopover);let c=document.createElement(`button`);c.type=`button`,c.setAttribute(`data-emoji-picker-random`,``),c.setAttribute(`aria-label`,this.i18n.t(zr)),c.className=[`flex-shrink-0 w-[34px] h-[34px] flex items-center justify-center rounded-lg`,`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600`,`theme-dark:hover:bg-neutral-800 theme-dark:hover:text-neutral-300`,`transition-colors duration-100 cursor-pointer`].join(` `),c.innerHTML=_i,c.addEventListener(`click`,()=>this.pickRandom()),t.An(c,this.i18n.t(zr),{placement:`bottom`});let l=document.createElement(`button`);l.type=`button`,l.setAttribute(`data-emoji-picker-remove`,``),l.setAttribute(`aria-label`,this.i18n.t(Fr)),l.className=[`flex-shrink-0 w-[34px] h-[34px] flex items-center justify-center rounded-lg`,`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600`,`theme-dark:hover:bg-neutral-800 theme-dark:hover:text-neutral-300`,`transition-colors duration-100 cursor-pointer`].join(` `),l.innerHTML=t.G,l.addEventListener(`click`,()=>{this.onRemove(),this.close()}),t.An(l,this.i18n.t(Fr),{placement:`bottom`});let u=document.createElement(`div`);u.className=`flex items-center gap-1`,u.appendChild(c),u.appendChild(l),n.appendChild(r),n.appendChild(o),n.appendChild(u),e.appendChild(n);let d=document.createElement(`div`);d.setAttribute(`data-emoji-picker-body`,``),d.className=`overflow-y-auto max-h-[260px] px-1.5 pb-2`,e.appendChild(d);let f=document.createElement(`div`);return f.setAttribute(`data-emoji-picker-nav`,``),f.className=[`flex items-center gap-1 px-2 pt-1 pb-1`,`border-t border-neutral-100 theme-dark:border-neutral-800`].join(` `),e.appendChild(f),e.addEventListener(`mousedown`,e=>{let t=e.target;!this._skinTonePopover.hidden&&!this._skinTonePopover.contains(t)&&!this._skinToneToggle.contains(t)&&this.closeSkinTonePopover()}),e.addEventListener(`keydown`,e=>{if(e.key===`Escape`){if(!this._skinTonePopover.hidden){this.closeSkinTonePopover();return}this.close()}}),e}buildSkinTonePopover(){let e=document.createElement(`div`);e.setAttribute(`data-emoji-picker-skin-tone`,``),e.className=[`absolute right-0 top-full mt-1.5 z-20`,`flex items-center gap-0.5 p-1 rounded-xl`,`bg-white border border-neutral-200/70 shadow-lg`,`theme-dark:bg-neutral-800 theme-dark:border-neutral-700/50`].join(` `),e.hidden=!0,this._skinToneButtons=[];for(let[t,n]of pi.entries()){let r=document.createElement(`button`);r.type=`button`,r.textContent=n,r.setAttribute(`aria-label`,`${this.i18n.t(Br)} ${t+1}`),r.className=[`w-[32px] h-[32px] flex items-center justify-center rounded-lg`,`text-[1.2rem] leading-none cursor-pointer select-none`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-700`,`active:scale-90 transition-all duration-100`].join(` `),this.applySkinToneActiveStyle(r,t===this._skinTone),r.addEventListener(`click`,()=>{this.setSkinTone(t),this.closeSkinTonePopover()}),e.appendChild(r),this._skinToneButtons.push(r)}return e}applySkinToneActiveStyle(e,t){let n=[`bg-neutral-100`,`theme-dark:bg-neutral-700`,`ring-2`,`ring-neutral-300/60`,`theme-dark:ring-neutral-600/60`];t?e.classList.add(...n):e.classList.remove(...n)}toggleSkinTonePopover(){this._skinTonePopover.hidden=!this._skinTonePopover.hidden,this.updateSkinToneToggleActive()}closeSkinTonePopover(){this._skinTonePopover.hidden=!0,this.updateSkinToneToggleActive()}updateSkinToneToggleActive(){let e=!this._skinTonePopover.hidden,t=[`bg-neutral-100`,`theme-dark:bg-neutral-700`];e?this._skinToneToggle.classList.add(...t):this._skinToneToggle.classList.remove(...t)}setSkinTone(e){this._skinTone=e,gi(e),this._skinToneToggle.textContent=pi[e];for(let[t,n]of this._skinToneButtons.entries())this.applySkinToneActiveStyle(n,t===e);let t=Array.from(this._body.querySelectorAll(`[data-emoji-native]`));for(let e of t){let t=e.getAttribute(`data-emoji-native`);if(t===null)continue;let n=this._allEmojis.find(e=>e.native===t);n!==void 0&&(e.textContent=this.getSkinnedNative(n))}}pickRandom(){if(this._allEmojis.length===0)return;let e=Math.floor(Math.random()*this._allEmojis.length),t=this._allEmojis[e];t!==void 0&&this.onSelect(this.getSkinnedNative(t))}buildCategoryNav(e){this._nav.innerHTML=``,this._navButtons.clear(),this._activeNavId=``;for(let[t,n]of fi){if(!e.has(t))continue;let r=this.translateCategory(t),i=document.createElement(`button`);i.type=`button`,i.innerHTML=n,i.title=r,i.setAttribute(`aria-label`,r),i.setAttribute(`data-emoji-nav`,t),i.className=[`flex-1 h-[36px] flex items-center justify-center`,`rounded-lg cursor-pointer opacity-50`,`text-neutral-500 theme-dark:text-neutral-400`,`[&>svg]:w-[20px] [&>svg]:h-[20px]`,`hover:opacity-100 hover:bg-neutral-100`,`theme-dark:hover:bg-neutral-800`,`transition-all duration-100`].join(` `),i.addEventListener(`click`,()=>this.scrollToSection(t)),this._nav.appendChild(i),this._navButtons.set(t,i)}}scrollToSection(e){let t=this._sectionEls.get(e);if(t===void 0)return;let n=this._body.getBoundingClientRect(),r=t.getBoundingClientRect();this._body.scrollTo({top:this._body.scrollTop+(r.top-n.top),behavior:`smooth`})}updateActiveNav(){let e=this._body.getBoundingClientRect().top,t=[...this._sectionEls.entries()].filter(([,t])=>t.getBoundingClientRect().top-e<=20).reduce((e,[t])=>t,``);if(t!==this._activeNavId){this._activeNavId=t;for(let[e,n]of this._navButtons)e===t?(n.classList.remove(`opacity-50`),n.classList.add(`opacity-100`,`bg-neutral-100`,`theme-dark:bg-neutral-800`)):(n.classList.remove(`opacity-100`,`bg-neutral-100`,`theme-dark:bg-neutral-800`),n.classList.add(`opacity-50`))}}getSkinnedNative(e){var t;return(t=e.skins[this._skinTone])==null?e.native:t}handleFilterChange(e){if(e.trim()===``){this._nav.hidden=!1,this.renderEmojiGrid(this._allEmojis);return}this._nav.hidden=!0;let t=oi(this._allEmojis,e,this._localeData);if(t.length===0)this._showingEmptyState||this.renderEmptyState();else{this._body.innerHTML=``,this._sectionEls.clear(),this._showingEmptyState=!1;let e=si(t);for(let[t,n]of e){let e=this.buildSection(this.translateCategory(t),n);e.setAttribute(`data-emoji-section`,t),this._sectionEls.set(t,e),this._body.appendChild(e)}}}renderEmojiGrid(e){this._body.innerHTML=``,this._sectionEls.clear(),this._showingEmptyState=!1;let t=new Set,n=ni.map(t=>e.find(e=>e.native===t)).filter(e=>e!==void 0);if(n.length>0){t.add(`callout`);let e=this.buildSection(this.translateCategory(`callout`),n);e.setAttribute(`data-emoji-section`,`callout`),this._sectionEls.set(`callout`,e),this._body.appendChild(e)}let r=new Set(ni),i=si(e.filter(e=>!r.has(e.native)));for(let[e,n]of i){t.add(e);let r=this.buildSection(this.translateCategory(e),n);r.setAttribute(`data-emoji-section`,e),this._sectionEls.set(e,r),this._body.appendChild(r)}this.buildCategoryNav(t),this._nav.hidden=!1,requestAnimationFrame(()=>this.updateActiveNav())}renderEmptyState(){this._body.innerHTML=``,this._showingEmptyState=!0,this._sectionEls.clear();let e=document.createElement(`div`);e.className=[`flex flex-col items-center justify-center py-10`,`text-neutral-400 theme-dark:text-neutral-500 select-none`,`animate-[blok-emoji-empty-in_300ms_ease-out_both]`].join(` `);let n=document.createElement(`span`);n.className=`mb-3 opacity-20 [&>svg]:w-9 [&>svg]:h-9`,n.innerHTML=t.qt;let r=document.createElement(`span`);r.className=`text-[13px] font-medium`,r.textContent=this.i18n.t(Rr),e.appendChild(n),e.appendChild(r),this._body.appendChild(e)}translateCategory(e){let t=di[e];return t===void 0?e:this.i18n.t(t)}buildSection(e,t){let n=document.createElement(`div`),r=document.createElement(`div`);return r.className=[`text-[11px] font-semibold uppercase tracking-wider px-2 pt-3 pb-1.5`,`text-neutral-400/80 theme-dark:text-neutral-500/80`,`sticky top-0 bg-white theme-dark:bg-neutral-900 z-10`].join(` `),r.textContent=e,n.appendChild(r),n.appendChild(this.buildGrid(t)),n}getDisplayName(e){var t,n;return((t=(n=this._localeData)==null||(n=n[e.native])==null?void 0:n.n)==null?e.name:t).toLocaleLowerCase()}buildGrid(e){let n=document.createElement(`div`);n.className=`grid grid-cols-10 gap-0.5 px-0.5 pt-1`;for(let r of e){let e=document.createElement(`button`);e.type=`button`,e.textContent=this.getSkinnedNative(r),e.setAttribute(`data-emoji-native`,r.native),e.className=[`aspect-square flex items-center justify-center`,`text-[1.25rem] leading-none rounded-lg cursor-pointer`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-800`,`hover:scale-110 active:scale-95`,`transition-transform duration-75`].join(` `),e.addEventListener(`click`,()=>{this.onSelect(this.getSkinnedNative(r)),this.close()}),t.An(e,this.getDisplayName(r),{placement:`bottom`}),n.appendChild(e)}return n}resolveTheme(){let e=document.documentElement.getAttribute(`data-blok-theme`);return e===`dark`?`dark`:e===`light`?`light`:window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}showBackdrop(){var e;this.removeBackdrop();let t=document.createElement(`div`);t.setAttribute(`data-blok-emoji-picker-backdrop`,``),t.style.position=`fixed`,t.style.inset=`0`,t.style.zIndex=`50`,t.addEventListener(`mousedown`,e=>{e.target===t&&this.close()}),(e=this._element.parentElement)==null||e.insertBefore(t,this._element),t.appendChild(this._element),this._backdrop=t,this._savedOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`}removeBackdrop(){var e;this._backdrop!==null&&(document.documentElement.style.overflow=this._savedOverflow,(e=this._backdrop.parentElement)==null||e.insertBefore(this._element,this._backdrop),this._backdrop.remove(),this._backdrop=null)}position(e){let t=e.getBoundingClientRect(),n=this._element.getBoundingClientRect(),r=window.innerHeight,i=window.innerWidth,a=t.bottom+n.height>r?t.top-n.height-4:t.bottom+4,o=t.left-8,s=o+n.width>i?t.right-n.width:Math.max(0,o);this._element.style.top=`${a}px`,this._element.style.left=`${s}px`}};function yi(e){return e.isEmojiVisible===!1?``:typeof e.emoji==`string`&&e.emoji.length>0?e.emoji:Yr}var bi={general:null,note:`blue`,important:`purple`,warning:`orange`,additional:`yellow`,recommendation:`green`,caution:`red`},xi=class{constructor({data:e,api:t,readOnly:n,block:r,config:i}){this._dom=null,this._emojiPicker=null,this._colorPicker=null,this._pendingChildText=null,this.api=t,this.readOnly=n;let a=typeof e.__importedText==`string`?e.__importedText:null;a!==null&&a.length>0&&(this._pendingChildText=a),this._data=this.normalizeData(e),r&&(this.blockId=r.id),this._customEmojiPicker=i==null?void 0:i.emojiPicker}normalizeData(e){let t=e;return`variant`in t||`isEmojiVisible`in t?this.normalizeLegacyData(t):{emoji:typeof e.emoji==`string`?e.emoji:Yr,textColor:typeof e.textColor==`string`?e.textColor:null,backgroundColor:typeof e.backgroundColor==`string`?e.backgroundColor:null}}normalizeLegacyData(e){let t=typeof e.variant==`string`?e.variant:`general`,n=t in bi?bi[t]:null;return{emoji:yi(e),textColor:null,backgroundColor:n==null?null:n}}render(){if(this._dom)return this._dom.wrapper;let e=$r({emoji:this._data.emoji,readOnly:this.readOnly,addEmojiLabel:this.api.i18n.t(Pr)});return this._dom=e,this.applyColors(),this.readOnly||(e.emojiButton.addEventListener(`click`,()=>this.openEmojiPicker()),e.emojiButton.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.openEmojiPicker())}),e.childContainer.addEventListener(`keydown`,e=>{e.key===`Backspace`&&this.handleChildBackspace(e)})),e.wrapper}rendered(){if(this.blockId===void 0||this._dom===null)return;let e=this.api.blocks.getChildren(this.blockId);if(x(this._dom.childContainer,e),e.length===0){let e=this.api.blocks.getBlockIndex(this.blockId);if(e!==void 0){let t=this._pendingChildText;this._pendingChildText=null;let n=t!==null&&t.length>0?{text:t}:void 0,r=this.api.blocks.insertInsideParent(this.blockId,e+1,n);this._dom.childContainer.appendChild(r.holder),this.api.caret.setToBlock(r.id,t===null?`start`:`end`)}}}save(){return ei({emoji:this._data.emoji,textColor:this._data.textColor,backgroundColor:this._data.backgroundColor})}validate(e){return!0}onPaste(e){var n;let r=(n=e.detail.data.getAttribute(`style`))==null?``:n,i=/background(?:-color)?\s*:\s*([^;]+)/i.exec(r);if(i!=null&&i[1]){let e=t.vn(i[1].trim(),`bg`);e&&(this._data.backgroundColor=e)}this.applyColors()}renderSettings(){if(this._colorPicker===null){let e=Lt({i18n:this.api.i18n,testIdPrefix:`callout-color`,modes:[{key:`color`,labelKey:`tools.marker.textColor`,presetField:`text`},{key:`background-color`,labelKey:`tools.marker.background`,presetField:`bg`}],onColorSelect:(n,r)=>{let i=n===null?null:t.vn(n,r===`color`?`text`:`bg`);r===`color`?this._data.textColor=i:this._data.backgroundColor=i,e.setActiveColor(n,r),this.applyColors()}});this._colorPicker=e}return this.syncPickerActiveColors(),[{icon:t.nt,title:this.api.i18n.t(Nr),name:`callout-edit-icon`,closeOnActivate:!0,onActivate:()=>this.openEmojiPicker()},{icon:t.zt,title:this.api.i18n.t(Mr),name:`callout-color`,children:{items:[{type:t.Ln.Html,element:this._colorPicker.element}]}}]}removed(){}setReadOnly(e){this.readOnly=e,this._dom&&(this._dom.emojiButton.disabled=e)}syncPickerActiveColors(){if(this._colorPicker===null)return;let e=this._data.textColor,n=this._data.backgroundColor;this._colorPicker.setActiveColor(e===null?null:t.Sn(e,`text`),`color`),this._colorPicker.setActiveColor(n===null?null:t.Sn(n,`bg`),`background-color`)}applyColors(){if(this._dom===null)return;let{textColor:e,backgroundColor:n}=this._data;if(e===null?this._dom.wrapper.style.color=``:this._dom.wrapper.style.color=t.Sn(e,`text`),n!==null){let e=t.Sn(n,`bg`);this._dom.wrapper.style.backgroundColor=e,this._dom.wrapper.style.border=``,this._dom.wrapper.style.setProperty(`--blok-search-input-bg`,`light-dark(color-mix(in srgb, ${e} 70%, white), color-mix(in srgb, ${e} 85%, white))`)}else this._dom.wrapper.style.backgroundColor=``,this._dom.wrapper.style.border=`1px solid var(--blok-callout-default-border, #e5e7eb)`,this._dom.wrapper.style.removeProperty(`--blok-search-input-bg`),this._dom.wrapper.style.removeProperty(`--blok-search-input-border`)}handleChildBackspace(e){if(this.blockId===void 0||this._dom===null)return;let t=this.api.blocks.getChildren(this.blockId);if(t.length===0)return;let n=t[0],r=e.target;if(!n.holder.contains(r))return;let i=window.getSelection(),a=i!==null&&i.rangeCount>0&&i.getRangeAt(0).startOffset===0&&i.getRangeAt(0).collapsed;n.holder.textContent!==``||!a||ti({api:this.api,calloutBlockId:this.blockId,firstChildBlockId:n.id,event:e})}openEmojiPicker(){if(this._dom!==null){if(this._customEmojiPicker!==void 0){this._customEmojiPicker(e=>this.setEmoji(e));return}this._emojiPicker===null&&(this._emojiPicker=new vi({onSelect:e=>this.setEmoji(e),onRemove:()=>this.setEmoji(``),i18n:this.api.i18n,locale:this.api.i18n.getLocale()}),document.body.appendChild(this._emojiPicker.getElement())),this._emojiPicker.open(this._dom.emojiButton)}}setEmoji(e){this._data.emoji=e,this._dom!==null&&(this._dom.emojiButton.textContent=e,this._dom.emojiButton.setAttribute(`aria-label`,e===``?this.api.i18n.t(Pr):e))}static get toolbox(){return{icon:t.M,titleKey:`callout`,name:jr,searchTerms:[`callout`,`note`,`info`,`warning`,`tip`,`alert`],searchTermKeys:[`callout`,`note`,`info`,`warning`,`tip`,`alert`]}}static get conversionConfig(){return{import:e=>({emoji:Yr,textColor:null,backgroundColor:null,__importedText:e})}}static get pasteConfig(){return{tags:[{ASIDE:{style:!0}}]}}static get sanitize(){return{emoji:!1,textColor:!1,backgroundColor:!1}}static get isReadOnlySupported(){return!0}},Si=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`;function Ci(e,t,n){let r=n[0];if(t!=null&&e>=t)throw Error(e+` >= `+t);if(e.slice(-1)===r||t&&t.slice(-1)===r)throw Error(`trailing zero`);if(t){let i=0;for(;(e[i]||r)===t[i];)i++;if(i>0)return t.slice(0,i)+Ci(e.slice(i),t.slice(i),n)}let i=e?n.indexOf(e[0]):0,a=t==null?n.length:n.indexOf(t[0]);return a-i>1?n[Math.round(.5*(i+a))]:t&&t.length>1?t.slice(0,1):n[i]+Ci(e.slice(1),null,n)}function wi(e){if(e.length!==Ti(e[0]))throw Error(`invalid integer part of order key: `+e)}function Ti(e){if(e>=`a`&&e<=`z`)return e.charCodeAt(0)-97+2;if(e>=`A`&&e<=`Z`)return 90-e.charCodeAt(0)+2;throw Error(`invalid order key head: `+e)}function Ei(e){let t=Ti(e[0]);if(t>e.length)throw Error(`invalid order key: `+e);return e.slice(0,t)}function Di(e,t){if(e===`A`+t[0].repeat(26))throw Error(`invalid order key: `+e);let n=Ei(e);if(e.slice(n.length).slice(-1)===t[0])throw Error(`invalid order key: `+e)}function Oi(e,t){wi(e);let[n,...r]=e.split(``),i=!0;for(let e=r.length-1;i&&e>=0;e--){let n=t.indexOf(r[e])+1;n===t.length?r[e]=t[0]:(r[e]=t[n],i=!1)}if(i){if(n===`Z`)return`a`+t[0];if(n===`z`)return null;let e=String.fromCharCode(n.charCodeAt(0)+1);return e>`a`?r.push(t[0]):r.pop(),e+r.join(``)}else return n+r.join(``)}function ki(e,t){wi(e);let[n,...r]=e.split(``),i=!0;for(let e=r.length-1;i&&e>=0;e--){let n=t.indexOf(r[e])-1;n===-1?r[e]=t.slice(-1):(r[e]=t[n],i=!1)}if(i){if(n===`a`)return`Z`+t.slice(-1);if(n===`A`)return null;let e=String.fromCharCode(n.charCodeAt(0)-1);return e<`Z`?r.push(t.slice(-1)):r.pop(),e+r.join(``)}else return n+r.join(``)}function Ai(e,t,n=Si){if(e!=null&&Di(e,n),t!=null&&Di(t,n),e!=null&&t!=null&&e>=t)throw Error(e+` >= `+t);if(e==null){if(t==null)return`a`+n[0];let e=Ei(t),r=t.slice(e.length);if(e===`A`+n[0].repeat(26))return e+Ci(``,r,n);if(e<t)return e;let i=ki(e,n);if(i==null)throw Error(`cannot decrement any more`);return i}if(t==null){let t=Ei(e),r=e.slice(t.length),i=Oi(t,n);return i==null?t+Ci(r,null,n):i}let r=Ei(e),i=e.slice(r.length),a=Ei(t),o=t.slice(a.length);if(r===a)return r+Ci(i,o,n);let s=Oi(r,n);if(s==null)throw Error(`cannot increment any more`);return s<t?s:r+Ci(i,null,n)}var ji={notStarted:[`Not`,`started`].join(` `),inProgress:[`In`,`progress`].join(` `),done:[`Do`,`ne`].join(``)},Mi=class e{constructor(t){if(this.rows=[],(t==null?void 0:t.schema)!==void 0&&t.schema.length>0?this.schema=t.schema.map(e=>n.t({},e)):this.schema=e.createDefaultSchema(),(t==null?void 0:t.views)!==void 0&&t.views.length>0)this.views=t.views.map(e=>n.t(n.t({},e),{},{sorts:[...e.sorts],filters:[...e.filters],visibleProperties:[...e.visibleProperties]}));else{let t=this.schema.find(e=>e.type===`select`);this.views=[e.createDefaultView(t==null?void 0:t.id)]}this.activeViewId=(t==null?void 0:t.activeViewId)||(this.views.length>0?this.views[0].id:``)}getSchema(){return[...this.schema]}getProperty(e){return this.schema.find(t=>t.id===e)}addProperty(e,r,i){let a=this.schema.length>0?this.schema[this.schema.length-1].position:null,o=n.t({id:t.cr(),name:e,type:r,position:Ai(a,null)},i===void 0?{}:{config:i});return this.schema.push(o),o}updateProperty(e,t){let n=this.schema.find(t=>t.id===e);n!==void 0&&(t.name!==void 0&&(n.name=t.name),t.config!==void 0&&(n.config=t.config))}deleteProperty(e){this.schema=this.schema.filter(t=>t.id!==e)}setRows(e){this.rows=e}getOrderedRows(){return[...this.rows].sort((e,t)=>e.position.localeCompare(t.position))}getRow(e){return this.rows.find(t=>t.id===e)}createRowData(e){let n=this.getOrderedRows(),r=n.length>0?n[n.length-1].position:null;return{id:t.cr(),position:Ai(r,null),properties:e==null?{}:e}}getRowsGroupedBy(e){let t=new Map,n=this.getOrderedRows();for(let r of n){let n=r.properties[e],i=this.toGroupKey(n),a=t.get(i);a===void 0?t.set(i,[r]):a.push(r)}return t}getSelectOptions(e){var t,n;let r=this.getProperty(e);return r===void 0||r.type!==`select`&&r.type!==`multiSelect`?[]:[...(t=(n=r.config)==null?void 0:n.options)==null?[]:t].sort((e,t)=>e.position<t.position?-1:1)}getViews(){return[...this.views]}getView(e){return this.views.find(t=>t.id===e)}addView(e,n,r={}){var i,a,o;let s=[...this.views].sort((e,t)=>e.position<t.position?-1:1),c=s.length>0?s[s.length-1].position:null,l={id:t.cr(),name:e,type:n,position:Ai(c,null),groupBy:r.groupBy,sorts:(i=r.sorts)==null?[]:i,filters:(a=r.filters)==null?[]:a,visibleProperties:(o=r.visibleProperties)==null?[]:o};return this.views.push(l),l}updateView(e,t){let n=this.views.find(t=>t.id===e);n!==void 0&&Object.assign(n,t)}deleteView(e){this.views=this.views.filter(t=>t.id!==e)}hydrate(e){e.schema!==void 0&&(this.schema=structuredClone(e.schema)),e.views!==void 0&&(this.views=structuredClone(e.views))}snapshot(){return{schema:structuredClone(this.schema),views:structuredClone(this.views),activeViewId:this.activeViewId}}toGroupKey(e){return e==null?``:typeof e==`string`?e:typeof e==`boolean`||typeof e==`number`?String(e):``}static positionBetween(e,t){return Ai(e,t)}static createDefaultSchema(){return[{id:t.cr(),name:`Title`,type:`title`,position:`a0`},{id:t.cr(),name:`Status`,type:`select`,position:`a1`,config:{options:[{id:t.cr(),label:ji.notStarted,color:`gray`,position:`a0`},{id:t.cr(),label:ji.inProgress,color:`blue`,position:`a1`},{id:t.cr(),label:ji.done,color:`green`,position:`a2`}]}}]}static createDefaultView(e){return{id:t.cr(),name:`Board`,type:`board`,position:`a0`,groupBy:e,sorts:[],filters:[],visibleProperties:[]}}},Ni=class{constructor({readOnly:e,i18n:t,options:n,getRows:r,titlePropertyId:i,onTitleEdit:a}){this.readOnly=e,this.i18n=t,this.options=n,this.getRows=r,this.titlePropertyId=i,this.onTitleEdit=a}createView(){let e=document.createElement(`div`);e.setAttribute(`data-blok-tool`,`database`),e.setAttribute(`role`,`region`),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.kanbanBoard`)),e.style.display=`flex`;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-board`,``),t.style.display=`flex`,t.style.overflowX=`auto`,t.style.alignItems=`flex-start`,t.style.gap=`12px`,t.style.paddingBottom=`24px`,t.style.flex=`1`,t.style.minWidth=`0`;for(let e of this.options){let n=this.createColumnElement(e,this.getRows(e.id),this.titlePropertyId);t.appendChild(n)}if(!this.readOnly){let e=document.createElement(`button`);e.setAttribute(`data-blok-database-add-column`,``),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.addColumn`)),e.textContent=`+ `+this.i18n.t(`tools.database.addColumn`),e.style.minWidth=`260px`,e.style.flex=`0 0 260px`,t.appendChild(e)}return e.appendChild(t),e}appendRow(e,t){let n=this.createCardElement(t,this.titlePropertyId);e.appendChild(n),this.updateColumnCount(e)}removeRow(e,t){let n=e.querySelector(`[data-row-id="${t}"]`),r=n==null?void 0:n.closest(`[data-blok-database-cards]`);n==null||n.remove(),r!==null&&this.updateColumnCount(r)}updateRowTitle(e,t,n){let r=e.querySelector(`[data-row-id="${t}"]`),i=r==null?void 0:r.querySelector(`[data-blok-database-card-title]`);i!=null&&(n?(i.textContent=n,i.removeAttribute(`data-placeholder`),r==null||r.removeAttribute(`data-empty`)):(i.textContent=this.i18n.t(`tools.database.cardTitlePlaceholder`),i.setAttribute(`data-placeholder`,``),r==null||r.setAttribute(`data-empty`,``)))}appendGroup(e,t){let n=this.createColumnElement(t,[],``),r=e.querySelector(`[data-blok-database-board]`),i=r==null?e:r,a=i.querySelector(`[data-blok-database-add-column]`);a?i.insertBefore(n,a):i.appendChild(n)}removeGroup(e,t){let n=e.querySelector(`[data-option-id="${t}"]`);n==null||n.remove()}createColumnElement(e,n,r){let i=document.createElement(`div`);i.setAttribute(`data-blok-database-column`,``),i.setAttribute(`data-option-id`,e.id),i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,e.label),i.style.display=`flex`,i.style.flexDirection=`column`,i.style.minWidth=`260px`,i.style.flex=`0 0 260px`,e.color!==void 0&&(i.style.backgroundColor=`var(--blok-color-${e.color}-bg)`,i.setAttribute(`data-color`,e.color));let a=document.createElement(`div`);a.setAttribute(`data-blok-database-column-header`,``),a.style.display=`flex`,a.style.alignItems=`center`,a.style.padding=`0 0 6px 0`,a.style.borderRadius=`4px`,a.style.gap=`6px`,a.style.cursor=`grab`;let o=document.createElement(`div`);if(o.setAttribute(`data-blok-database-column-pill`,``),e.color!==void 0){o.style.backgroundColor=`color-mix(in srgb, var(--blok-color-${e.color}-text) 20%, var(--blok-color-${e.color}-bg))`,o.style.color=`var(--blok-color-${e.color}-text)`;let t=document.createElement(`span`);t.setAttribute(`data-blok-database-column-dot`,``),t.style.backgroundColor=`var(--blok-color-${e.color}-text)`,o.appendChild(t)}let s=document.createElement(`div`);s.setAttribute(`data-blok-database-column-title`,``),s.textContent=e.label,o.appendChild(s),a.appendChild(o);let c=document.createElement(`span`);c.setAttribute(`data-blok-database-column-count`,``),c.textContent=String(n.length),e.color!==void 0&&(c.style.color=`var(--blok-color-${e.color}-text)`),a.appendChild(c),i.appendChild(a);let l=document.createElement(`div`);l.setAttribute(`data-blok-database-cards`,``),l.setAttribute(`role`,`list`),l.style.display=`flex`,l.style.flexDirection=`column`,l.style.gap=`8px`,l.style.paddingTop=`6px`,l.style.minHeight=`40px`;for(let e of n){let t=this.createCardElement(e,r);l.appendChild(t)}if(i.appendChild(l),!this.readOnly){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-add-card`,``),n.setAttribute(`data-option-id`,e.id),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.addCard`));let r=document.createElement(`span`);r.setAttribute(`data-blok-database-add-card-icon`,``),r.innerHTML=t.Ht,n.appendChild(r);let a=document.createElement(`span`);a.textContent=this.i18n.t(`tools.database.newPage`),n.appendChild(a),e.color!==void 0&&(n.style.borderColor=`color-mix(in srgb, var(--blok-color-${e.color}-text) 30%, transparent)`,n.style.color=`var(--blok-color-${e.color}-text)`),i.appendChild(n)}return i}createCardElement(e,n){var r;let i=document.createElement(`div`),a=(r=e.properties[n])==null?``:r;i.setAttribute(`data-blok-database-card`,``),i.setAttribute(`data-row-id`,e.id),i.setAttribute(`role`,`listitem`),i.style.padding=`10px 12px`,i.style.borderRadius=`10px`,i.style.cursor=`pointer`,i.style.position=`relative`,i.style.backgroundColor=`var(--blok-database-card-bg)`,i.style.boxShadow=`var(--blok-database-card-shadow)`;let o=document.createElement(`div`);if(o.setAttribute(`data-blok-database-card-title`,``),a?o.textContent=a:(o.textContent=this.i18n.t(`tools.database.cardTitlePlaceholder`),o.setAttribute(`data-placeholder`,``),i.setAttribute(`data-empty`,``)),i.appendChild(o),!this.readOnly){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-card-actions`,``);let r=document.createElement(`button`);r.setAttribute(`data-blok-database-edit-card`,``),r.setAttribute(`data-row-id`,e.id),r.setAttribute(`aria-label`,this.i18n.t(`tools.database.editCardTitle`)),r.innerHTML=t.Bt,r.addEventListener(`click`,t=>{t.stopPropagation(),this.startCardTitleEdit(i,e.id)});let a=document.createElement(`button`);a.setAttribute(`data-blok-database-card-menu`,``),a.setAttribute(`data-row-id`,e.id),a.setAttribute(`aria-label`,this.i18n.t(`tools.database.cardMenuLabel`)),a.innerHTML=t.Y,n.appendChild(r),n.appendChild(a),i.appendChild(n)}return i}startCardTitleEdit(e,t){var n;let r=e.querySelector(`[data-blok-database-card-title]`);if(r===null)return;let i=(n=r.textContent)==null?``:n,a=document.createElement(`input`);a.type=`text`,a.value=i,a.setAttribute(`data-blok-database-card-title-input`,``),a.setAttribute(`aria-label`,this.i18n.t(`tools.database.editCardTitle`)),a.style.width=`100%`,a.style.boxSizing=`border-box`;let o={committed:!1},s=()=>{if(o.committed)return;o.committed=!0;let n=a.value.trim()||i,r=document.createElement(`div`);if(r.setAttribute(`data-blok-database-card-title`,``),r.textContent=n,a.replaceWith(r),n!==i){var s;(s=this.onTitleEdit)==null||s.call(this,t,n)}n&&e.removeAttribute(`data-empty`)},c=()=>{if(o.committed)return;o.committed=!0;let e=document.createElement(`div`);e.setAttribute(`data-blok-database-card-title`,``),e.textContent=i,a.replaceWith(e)};a.addEventListener(`blur`,s),a.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?(a.removeEventListener(`blur`,s),s()):e.key===`Escape`&&(a.removeEventListener(`blur`,s),c())}),r.replaceWith(a),a.focus(),a.select()}updateColumnCount(e){let t=e.closest(`[data-blok-database-column]`);if(t===null)return;let n=t.querySelector(`[data-blok-database-column-count]`);if(n!==null){let t=e.querySelectorAll(`[data-blok-database-card]`).length;n.textContent=String(t)}}},Pi=class{constructor({readOnly:e,i18n:t,rows:n,titlePropertyId:r,schema:i,visiblePropertyIds:a,options:o,getRows:s}){this.readOnly=e,this.i18n=t,this.rows=n,this.titlePropertyId=r,this.schema=i,this.visiblePropertyIds=a,this.groupOptions=o,this.getGroupRows=s}createView(){let e=document.createElement(`div`);if(e.setAttribute(`data-blok-database-list`,``),this.groupOptions!==void 0&&this.groupOptions.length>0&&this.getGroupRows!==void 0)for(let t of this.groupOptions){let n=this.getGroupRows(t.id),r=this.createGroupElement(t,n);e.appendChild(r)}else{e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.listView`));for(let t of this.rows){let n=this.createRowElement(t);e.appendChild(n)}if(!this.readOnly){let t=this.createAddRowButton();e.appendChild(t)}}return e}createGroupElement(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-list-group`,``),n.setAttribute(`data-option-id`,e.id);let r=document.createElement(`div`);r.setAttribute(`data-blok-database-list-group-header`,``);let i=document.createElement(`span`);i.setAttribute(`data-blok-database-list-group-toggle`,``),i.textContent=`▼`;let a=document.createElement(`span`);a.setAttribute(`data-blok-database-list-group-dot`,``),e.color!==void 0&&(a.style.backgroundColor=`var(--blok-color-${e.color}-text)`);let o=document.createElement(`span`);o.setAttribute(`data-blok-database-list-group-title`,``),o.textContent=e.label;let s=document.createElement(`span`);s.setAttribute(`data-blok-database-list-group-count`,``),s.textContent=String(t.length),r.appendChild(i),r.appendChild(a),r.appendChild(o),r.appendChild(s);let c=document.createElement(`div`);c.setAttribute(`data-blok-database-list-rows`,``),c.setAttribute(`role`,`list`);for(let e of t){let t=this.createRowElement(e);c.appendChild(t)}let l=this.readOnly?null:this.createAddRowButton(e.id);return r.addEventListener(`click`,()=>{let e=c.style.display===`none`;c.style.display=e?``:`none`,i.textContent=e?`▼`:`▶`,l!==null&&(l.style.display=e?``:`none`)}),n.appendChild(r),n.appendChild(c),l!==null&&n.appendChild(l),n}appendRow(e,t){let n=this.createRowElement(t),r=e.querySelector(`[data-blok-database-add-row]`);r===null?e.appendChild(n):e.insertBefore(n,r)}removeRow(e,t){let n=e.querySelector(`[data-row-id="${t}"]`);n==null||n.remove()}updateRowTitle(e,t,n){let r=e.querySelector(`[data-row-id="${t}"]`),i=r==null?void 0:r.querySelector(`[data-blok-database-list-row-title]`);i!=null&&(n?(i.textContent=n,i.removeAttribute(`data-placeholder`)):(i.textContent=this.i18n.t(`tools.database.rowTitlePlaceholder`),i.setAttribute(`data-placeholder`,``)))}createRowElement(e){var t;let n=document.createElement(`div`),r=(t=e.properties[this.titlePropertyId])==null?``:t;n.setAttribute(`data-blok-database-list-row`,``),n.setAttribute(`data-row-id`,e.id),n.setAttribute(`role`,`listitem`);let i=document.createElement(`div`);i.setAttribute(`data-blok-database-list-row-title`,``),r?i.textContent=r:(i.textContent=this.i18n.t(`tools.database.rowTitlePlaceholder`),i.setAttribute(`data-placeholder`,``)),n.appendChild(i);let a=this.createPropertiesElement(e);return n.appendChild(a),n}createPropertiesElement(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-list-row-properties`,``);for(let n of this.visiblePropertyIds){let r=this.schema.find(e=>e.id===n);if(r===void 0)continue;let i=e.properties[n],a=this.createPropertyBadge(r,i);a!==null&&t.appendChild(a)}let n=document.createElement(`button`);if(n.setAttribute(`data-blok-database-list-row-open`,``),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.openRow`)),t.appendChild(n),!this.readOnly){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-delete-row`,``),n.setAttribute(`data-row-id`,e.id),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.deleteRow`)),n.textContent=`×`,t.appendChild(n)}return t}createPropertyBadge(e,t){if(t==null)return null;let n=document.createElement(`span`);if(n.setAttribute(`data-blok-database-list-row-property`,``),n.setAttribute(`data-property-id`,e.id),e.type===`select`){var r,i;let a=((r=(i=e.config)==null?void 0:i.options)==null?[]:r).find(e=>e.id===t);if(a===void 0)return null;n.textContent=a.label,a.color!==void 0&&(n.style.backgroundColor=`var(--blok-color-${a.color}-bg)`,n.style.color=`var(--blok-color-${a.color}-text)`)}else if(e.type===`checkbox`){let e=document.createElement(`input`);e.type=`checkbox`,e.checked=t===!0,n.appendChild(e)}else if(typeof t==`string`||typeof t==`number`)n.textContent=String(t);else return null;return n}createAddRowButton(e){let t=document.createElement(`button`);return t.setAttribute(`data-blok-database-add-row`,``),t.setAttribute(`aria-label`,this.i18n.t(`tools.database.addRow`)),t.textContent=`+ `+this.i18n.t(`tools.database.newRow`),e!==void 0&&t.setAttribute(`data-option-id`,e),t}},Fi=500,Ii=class{constructor(e,t){this.pendingTimers=new Map,this.pendingUpdates=new Map,this.pendingPropertyTimers=new Map,this.pendingPropertyUpdates=new Map,this.adapter=e,this.onError=t}async safeCall(e){var t=this;if(t.adapter!==void 0)try{return await e(t.adapter)}catch(e){var n;(n=t.onError)==null||n.call(t,e);return}}async syncLoadDatabase(){return this.safeCall(e=>e.loadDatabase())}async syncCreateRow(e){return this.safeCall(t=>t.createRow(e))}syncUpdateRow(e){if(this.adapter===void 0)return;let{rowId:t}=e,r=this.pendingTimers.get(t);r!==void 0&&clearTimeout(r);let i=this.pendingUpdates.get(t);this.pendingUpdates.set(t,i===void 0?e:n.t(n.t(n.t({},i),e),{},{properties:n.t(n.t({},i.properties),e.properties)})),this.pendingTimers.set(t,setTimeout(()=>{this.flushRow(t)},Fi))}async syncMoveRow(e){var t=this;return t.flushRow(e.rowId),t.safeCall(t=>t.moveRow(e))}async syncDeleteRow(e){await this.safeCall(t=>t.deleteRow(e))}async syncCreateProperty(e){return this.safeCall(t=>t.createProperty(e))}async syncUpdateProperty(e){return this.safeCall(t=>t.updateProperty(e))}syncUpdatePropertyDebounced(e){if(this.adapter===void 0)return;let{propertyId:t}=e,n=this.pendingPropertyTimers.get(t);n!==void 0&&clearTimeout(n),this.pendingPropertyUpdates.set(t,e),this.pendingPropertyTimers.set(t,setTimeout(()=>{this.flushProperty(t)},Fi))}async syncDeleteProperty(e){await this.safeCall(t=>t.deleteProperty(e))}async syncCreateView(e){return this.safeCall(t=>t.createView(e))}async syncUpdateView(e){return this.safeCall(t=>t.updateView(e))}async syncDeleteView(e){await this.safeCall(t=>t.deleteView(e))}flushPendingUpdates(){for(let e of this.pendingTimers.keys())this.flushRow(e)}flushPendingPropertyUpdates(){for(let e of this.pendingPropertyTimers.keys())this.flushProperty(e)}destroy(){for(let e of this.pendingTimers.values())clearTimeout(e);this.pendingTimers.clear(),this.pendingUpdates.clear();for(let e of this.pendingPropertyTimers.values())clearTimeout(e);this.pendingPropertyTimers.clear(),this.pendingPropertyUpdates.clear()}flushRow(e){let t=this.pendingTimers.get(e);t!==void 0&&clearTimeout(t),this.pendingTimers.delete(e);let n=this.pendingUpdates.get(e);this.pendingUpdates.delete(e),n!==void 0&&this.safeCall(e=>e.updateRow(n))}flushProperty(e){let t=this.pendingPropertyTimers.get(e);t!==void 0&&clearTimeout(t),this.pendingPropertyTimers.delete(e);let n=this.pendingPropertyUpdates.get(e);this.pendingPropertyUpdates.delete(e),n!==void 0&&this.safeCall(e=>e.updateProperty(n))}},Li=10,Ri=class{constructor(e){this.isDragging=!1,this.rowId=``,this.startX=0,this.startY=0,this.ghostEl=null,this.sourceCard=null,this.sourceCardHeight=0,this.ghostOffsetX=0,this.ghostOffsetY=0,this.gapTarget=null,this.gapContainer=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.rowId=e,this.startX=t,this.startY=n,this.isDragging=!1,this.sourceCard=this.wrapper.querySelector(`[data-row-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.wrapper.removeAttribute(`data-blok-database-dragging`),this.sourceCard&&(this.sourceCard.style.opacity=``,this.sourceCard=null),this.isDragging=!1,this.rowId=``,this.sourceCardHeight=0,this.ghostOffsetX=0,this.ghostOffsetY=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientX-this.startX),n=Math.abs(e.clientY-this.startY);!this.isDragging&&(t>Li||n>Li)&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceCard){let e=this.sourceCard.getBoundingClientRect();this.sourceCardHeight=e.height,this.ghostOffsetX=this.startX-e.left,this.ghostOffsetY=this.startY-e.top,this.sourceCard.style.opacity=`0.4`}this.wrapper.setAttribute(`data-blok-database-dragging`,``),this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`8px`,n.overflow=`hidden`,n.transform=`rotate(2deg) scale(1.02)`,n.transformOrigin=`center center`,this.sourceCard){let r=this.sourceCard.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceCard.getBoundingClientRect();n.left=`${e.clientX-this.ghostOffsetX}px`,n.top=`${e.clientY-this.ghostOffsetY}px`,n.width=`${i.width}px`}else n.left=`${e.clientX}px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.left=`${e.clientX-this.ghostOffsetX}px`,this.ghostEl.style.top=`${e.clientY-this.ghostOffsetY}px`)}updateDropIndicator(e){let t=this.findTargetColumn(e.clientX);if(!t){this.clearGap();return}let n=this.getDropPosition(t,e.clientY).beforeEl;if(n){if(n===this.gapTarget)return;this.clearGap(),n.style.marginTop=`${this.sourceCardHeight}px`,this.gapTarget=n}else{let e=t.querySelector(`[data-blok-database-cards]`);if(!e){this.clearGap();return}if(e===this.gapContainer)return;this.clearGap(),e.style.paddingBottom=`${this.sourceCardHeight}px`,this.gapContainer=e}}clearGap(){this.gapTarget&&(this.gapTarget.style.marginTop=``,this.gapTarget=null),this.gapContainer&&(this.gapContainer.style.paddingBottom=``,this.gapContainer=null)}findTargetColumn(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-column]`));for(let n of t){let t=n.getBoundingClientRect();if(e>=t.left&&e<=t.right)return n}return null}getDropPosition(e,t){let n=Array.from(e.querySelectorAll(`[data-blok-database-card]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId);for(let e of n){let n=e.getBoundingClientRect();if(t<n.top+n.height/2)return{beforeEl:e}}return{beforeEl:null}}resolveAfterRowId(e,t,n){return e?n>0?t[n-1].getAttribute(`data-row-id`):null:t.length>0?t[t.length-1].getAttribute(`data-row-id`):null}commitDrop(e){var t;let n=this.findTargetColumn(e.clientX);if(!n)return;let r=(t=n.getAttribute(`data-option-id`))==null?``:t,i=this.getDropPosition(n,e.clientY),a=Array.from(n.querySelectorAll(`[data-blok-database-card]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId),o=i.beforeEl?i.beforeEl.getAttribute(`data-row-id`):null,s=i.beforeEl?a.indexOf(i.beforeEl):-1,c=this.resolveAfterRowId(i.beforeEl,a,s);this.onDrop({rowId:this.rowId,toOptionId:r,beforeRowId:o,afterRowId:c})}},zi=10,Bi=class{constructor(e){this.isDragging=!1,this.optionId=``,this.startX=0,this.startY=0,this.ghostEl=null,this.sourceColumn=null,this.sourceColumnWidth=0,this.ghostOffsetX=0,this.gapTarget=null,this.gapContainer=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.optionId=e,this.startX=t,this.startY=n,this.isDragging=!1,this.sourceColumn=this.wrapper.querySelector(`[data-option-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.wrapper.removeAttribute(`data-blok-database-column-reordering`),this.sourceColumn&&(this.sourceColumn.style.opacity=``,this.sourceColumn=null),this.isDragging=!1,this.optionId=``,this.sourceColumnWidth=0,this.ghostOffsetX=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientX-this.startX);!this.isDragging&&t>zi&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e.clientX))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceColumn){let e=this.sourceColumn.getBoundingClientRect();this.sourceColumnWidth=e.width,this.ghostOffsetX=this.startX-e.left,this.sourceColumn.style.opacity=`0.4`}this.wrapper.setAttribute(`data-blok-database-column-reordering`,``),this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-column-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`10px`,n.overflow=`hidden`,n.transform=`rotate(1deg) scale(1.02)`,n.transformOrigin=`center center`,this.sourceColumn){let r=this.sourceColumn.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceColumn.getBoundingClientRect();n.left=`${e.clientX-this.ghostOffsetX}px`,n.top=`${i.top}px`,n.width=`${i.width}px`}else n.left=`${e.clientX}px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.left=`${e.clientX-this.ghostOffsetX}px`)}updateDropIndicator(e){let t=this.getDropPosition(e);if(t.beforeColumn){if(t.beforeColumn===this.gapTarget)return;this.clearGap(),t.beforeColumn.style.marginLeft=`${this.sourceColumnWidth}px`,this.gapTarget=t.beforeColumn}else this.applyEndGap()}applyEndGap(){let e=this.wrapper.querySelector(`[data-blok-database-board]`);!e||e===this.gapContainer||(this.clearGap(),e.style.paddingRight=`${this.sourceColumnWidth}px`,this.gapContainer=e)}clearGap(){this.gapTarget&&(this.gapTarget.style.marginLeft=``,this.gapTarget=null),this.gapContainer&&(this.gapContainer.style.paddingRight=``,this.gapContainer=null)}getDropPosition(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-column]`)).filter(e=>e.getAttribute(`data-option-id`)!==this.optionId);for(let n of t){let r=n.getBoundingClientRect();if(e<r.left+r.width/2){let e=t.indexOf(n);return{beforeColumn:n,afterColumn:e>0?t[e-1]:null}}}return{beforeColumn:null,afterColumn:t.length>0?t[t.length-1]:null}}commitDrop(e){let t=this.getDropPosition(e.clientX),n=t.beforeColumn?t.beforeColumn.getAttribute(`data-option-id`):null,r=t.afterColumn?t.afterColumn.getAttribute(`data-option-id`):null;this.onDrop({optionId:this.optionId,beforeOptionId:n,afterOptionId:r})}},Vi=class{constructor(e){this.options=e,this.i18n=e.i18n}makeEditable(e,t){let n=e.querySelector(`[data-blok-database-column-title]`);if(n){var r;let e=document.createElement(`input`);e.type=`text`,e.value=(r=n.textContent)==null?``:r,e.setAttribute(`data-blok-database-column-title-input`,``),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.renameColumn`));let i=()=>{e.size=Math.max(e.value.length,1)};i(),e.addEventListener(`input`,i),e.addEventListener(`change`,()=>{this.options.onRename(t,e.value)}),n.replaceWith(e)}this.appendDeleteButton(e,t)}appendDeleteButton(e,t){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-delete-column`,``),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.deleteColumn`)),n.setAttribute(`data-option-id`,t),n.addEventListener(`click`,()=>{this.options.onDelete(t)}),e.appendChild(n)}makePillTitleEditable(e,t){let n=e.querySelector(`[data-blok-database-column-title]`);n!==null&&(n.style.cursor=`text`,n.addEventListener(`click`,r=>{var i;r.stopPropagation();let a=(i=n.textContent)==null?``:i,o=document.createElement(`input`);o.type=`text`,o.value=a,o.setAttribute(`data-blok-database-column-title-input`,``),o.setAttribute(`aria-label`,this.i18n.t(`tools.database.renameColumn`));let s=()=>{o.size=Math.max(o.value.length,1)};s(),o.addEventListener(`input`,s),o.addEventListener(`input`,()=>{var e,n;(e=(n=this.options).onRenameInput)==null||e.call(n,t,o.value)});let c={done:!1},l=e=>{let t=document.createElement(`div`);return t.setAttribute(`data-blok-database-column-title`,``),t.style.cursor=`text`,t.textContent=e,t},u=()=>{if(c.done)return;c.done=!0;let n=o.value.trim()||a,r=l(n);if(o.replaceWith(r),this.makePillTitleEditable(e,t),n!==a){var i,s;(i=(s=this.options).onRenameCommit)==null||i.call(s,t,n),this.options.onRename(t,n)}},d=()=>{if(c.done)return;c.done=!0;let n=l(a);o.replaceWith(n),this.makePillTitleEditable(e,t)};o.addEventListener(`blur`,u),o.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?u():e.key===`Escape`&&(o.removeEventListener(`blur`,u),d())}),n.replaceWith(o),o.focus(),o.select()}))}destroy(){}},Hi=10,Ui=class{constructor(e){this.isDragging=!1,this.rowId=``,this.startY=0,this.ghostEl=null,this.sourceRow=null,this.sourceRowHeight=0,this.ghostOffsetY=0,this.gapTarget=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.rowId=e,this.startY=n,this.isDragging=!1,this.sourceRow=this.wrapper.querySelector(`[data-row-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.sourceRow&&(this.sourceRow.style.opacity=``,this.sourceRow=null),this.isDragging=!1,this.rowId=``,this.sourceRowHeight=0,this.ghostOffsetY=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientY-this.startY);!this.isDragging&&t>Hi&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceRow){let e=this.sourceRow.getBoundingClientRect();this.sourceRowHeight=e.height,this.ghostOffsetY=this.startY-e.top,this.sourceRow.style.opacity=`0.4`}this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`8px`,n.overflow=`hidden`,this.sourceRow){let r=this.sourceRow.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceRow.getBoundingClientRect();n.left=`${i.left}px`,n.top=`${e.clientY-this.ghostOffsetY}px`,n.width=`${i.width}px`}else n.left=`0px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.top=`${e.clientY-this.ghostOffsetY}px`)}updateDropIndicator(e){let t=this.getDropPosition(e.clientY).beforeEl;if(t){if(t===this.gapTarget)return;this.clearGap(),t.style.marginTop=`${this.sourceRowHeight}px`,this.gapTarget=t}else this.clearGap()}clearGap(){this.gapTarget&&(this.gapTarget.style.marginTop=``,this.gapTarget=null)}getDropPosition(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-list-row]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId);for(let n of t){let t=n.getBoundingClientRect();if(e<t.top+t.height/2)return{beforeEl:n}}return{beforeEl:null}}commitDrop(e){let t=this.getDropPosition(e.clientY),n=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-list-row]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId),r=t.beforeEl?t.beforeEl.getAttribute(`data-row-id`):null,i=t.beforeEl?n.indexOf(t.beforeEl):-1,a=this.resolveAfterRowId(t.beforeEl,n,i);this.onDrop({rowId:this.rowId,beforeRowId:r,afterRowId:a})}resolveAfterRowId(e,t,n){return e?n>0?t[n-1].getAttribute(`data-row-id`):null:t.length>0?t[t.length-1].getAttribute(`data-row-id`):null}},Wi=[{type:`text`,icon:t.Qt,labelKey:`tools.database.propertyTypeText`},{type:`number`,icon:t.mt,labelKey:`tools.database.propertyTypeNumber`},{type:`select`,icon:t.At,labelKey:`tools.database.propertyTypeSelect`},{type:`multiSelect`,icon:t.jt,labelKey:`tools.database.propertyTypeMultiSelect`},{type:`date`,icon:t.j,labelKey:`tools.database.propertyTypeDate`},{type:`checkbox`,icon:t.Mt,labelKey:`tools.database.propertyTypeCheckbox`},{type:`url`,icon:t.st,labelKey:`tools.database.propertyTypeUrl`}],Gi=class{constructor(e){this.popoverEl=null,this.boundOutsideClick=null,this.onSelect=e.onSelect,this.i18n=e.i18n}open(e){var t,n;this.close();let r=document.createElement(`div`);r.setAttribute(`data-blok-popover`,``),r.setAttribute(`data-blok-popover-opened`,``),r.setAttribute(`data-blok-database-property-type-popover`,``),r.style.position=`fixed`,r.style.zIndex=`1000`;let i=e.getBoundingClientRect();r.style.top=`${i.bottom+4}px`,r.style.left=`${i.left}px`;let a=document.createElement(`div`);a.setAttribute(`data-blok-database-property-type-heading`,``),a.textContent=(t=(n=this.i18n)==null?void 0:n.t(`tools.database.propertyTypeHeading`))==null?`tools.database.propertyTypeHeading`:t,r.appendChild(a);for(let e of Wi){var o,s;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-property-type-option`,e.type);let n=document.createElement(`div`);n.setAttribute(`data-blok-database-property-type-option-icon`,``),n.innerHTML=e.icon,t.appendChild(n);let i=document.createElement(`span`);i.textContent=(o=(s=this.i18n)==null?void 0:s.t(e.labelKey))==null?e.labelKey:o,t.appendChild(i),t.addEventListener(`click`,()=>{this.onSelect(e.type),this.close()}),r.appendChild(t)}document.body.appendChild(r),this.popoverEl=r,this.boundOutsideClick=t=>{let n=t.target;!r.contains(n)&&!e.contains(n)&&this.close()},document.addEventListener(`mousedown`,this.boundOutsideClick)}close(){this.popoverEl!==null&&(this.popoverEl.remove(),this.popoverEl=null),this.boundOutsideClick!==null&&(document.removeEventListener(`mousedown`,this.boundOutsideClick),this.boundOutsideClick=null)}destroy(){this.close()}},Ki=class{constructor(e){this.drawer=null,this.currentRowId=null,this.currentRow=null,this.blokInstance=null,this.escapeHandler=null,this.outsideClickHandler=null,this.propertyTypePopover=null,this.wrapper=e.wrapper,this.readOnly=e.readOnly,this.i18n=e.i18n,this.toolsConfig=e.toolsConfig,this.titlePropertyId=e.titlePropertyId,this.descriptionPropertyId=e.descriptionPropertyId,this.schema=e.schema,this.onTitleChange=e.onTitleChange,this.onDescriptionChange=e.onDescriptionChange,this.onClose=e.onClose,this.onAddProperty=e.onAddProperty}get isOpen(){return this.drawer!==null}open(e){var n,r,i,a,o,s,c;if(this.drawer){if(e.id===this.currentRowId)return;this.loadCard(e);return}let l=this.wrapper.querySelector(`[data-blok-database-drawer]`);l==null||l.remove(),this.currentRowId=e.id,this.currentRow=e,this.updateActiveCard(e.id);let u=(n=e.properties[this.titlePropertyId])==null?``:n,d=document.createElement(`div`);d.setAttribute(`data-blok-database-drawer`,``),d.setAttribute(`role`,`complementary`),d.setAttribute(`aria-label`,(r=(i=this.i18n)==null?void 0:i.t(`tools.database.cardDetails`))==null?`tools.database.cardDetails`:r);let f=document.createElement(`div`);f.setAttribute(`data-blok-database-drawer-toolbar`,``);let p=document.createElement(`button`);p.setAttribute(`data-blok-database-drawer-close`,``),p.setAttribute(`aria-label`,`Close`),p.innerHTML=t.L+t.L,p.addEventListener(`click`,()=>{this.close()}),f.appendChild(p),d.appendChild(f);let m=document.createElement(`div`);m.setAttribute(`data-blok-database-drawer-content`,``);let h=document.createElement(`textarea`);h.setAttribute(`data-blok-database-drawer-title`,``),h.setAttribute(`aria-label`,(a=(o=this.i18n)==null?void 0:o.t(`tools.database.cardTitle`))==null?`tools.database.cardTitle`:a),h.placeholder=(s=(c=this.i18n)==null?void 0:c.t(`tools.database.cardTitlePlaceholder`))==null?`Empty page`:s,h.value=u,h.rows=1,h.readOnly=this.readOnly,h.addEventListener(`input`,()=>{this.currentRowId!==null&&this.onTitleChange(this.currentRowId,h.value),this.autoResizeTitle(h)}),h.addEventListener(`keydown`,e=>{e.key===`Enter`&&e.preventDefault()}),m.appendChild(h);let g=this.getRenderableSchema();m.appendChild(this.buildPropsSection(g,e));let _=document.createElement(`hr`);m.appendChild(_);let v=document.createElement(`div`);v.setAttribute(`data-blok-database-drawer-editor`,``),m.appendChild(v),d.appendChild(m),this.wrapper.appendChild(d),this.drawer=d,requestAnimationFrame(()=>{d.style.width=`45%`,d.addEventListener(`transitionend`,()=>{this.autoResizeTitle(h),u||h.focus()},{once:!0})}),this.initNestedEditor(v,e),this.escapeHandler=e=>{if(e.key!==`Escape`)return;let t=e.target;t&&v.contains(t)||this.close()},document.addEventListener(`keydown`,this.escapeHandler),this.outsideClickHandler=e=>{let t=e.target;t&&d.contains(t)||t instanceof Element&&t.closest(`[data-blok-popover-opened]`)!==null||t instanceof Element&&t.closest(`[data-blok-database-tab-bar]`)!==null||this.close()},document.addEventListener(`mousedown`,this.outsideClickHandler),h.focus()}loadCard(e){var t,n,r;if(this.drawer===null)return;this.cleanupEditor(),this.currentRowId=e.id,this.currentRow=e,this.updateActiveCard(e.id);let i=(t=e.properties[this.titlePropertyId])==null?``:t,a=this.drawer.querySelector(`[data-blok-database-drawer-title]`);a!==null&&(a.value=i,this.autoResizeTitle(a),i||a.focus()),(n=this.drawer.querySelector(`[data-blok-database-drawer-props]`))==null||n.remove();let o=this.getRenderableSchema(),s=this.drawer.querySelector(`[data-blok-database-drawer-content]`),c=(r=s==null?void 0:s.querySelector(`hr`))==null?null:r;s!==null&&s.insertBefore(this.buildPropsSection(o,e),c);let l=this.drawer.querySelector(`[data-blok-database-drawer-editor]`);l!==null&&(l.innerHTML=``,this.initNestedEditor(l,e))}close(){let e=this.drawer!==null;if(this.updateActiveCard(null),this.cleanupListeners(),this.cleanupEditor(),this.drawer){let e=this.drawer;this.drawer=null,e.style.width=`0px`,e.addEventListener(`transitionend`,()=>{e.remove()},{once:!0})}this.currentRowId=null,this.currentRow=null,e&&this.onClose()}destroy(){var e;this.cleanupListeners(),this.cleanupEditor(),(e=this.propertyTypePopover)==null||e.destroy(),this.propertyTypePopover=null,this.drawer&&(this.drawer.remove(),this.drawer=null);let t=this.wrapper.querySelector(`[data-blok-database-drawer]`);t==null||t.remove(),this.currentRowId=null,this.currentRow=null}refreshSchema(e){var t,n;if(this.schema=e,this.drawer===null||this.currentRow===null)return;(t=this.drawer.querySelector(`[data-blok-database-drawer-props]`))==null||t.remove();let r=this.getRenderableSchema(),i=this.drawer.querySelector(`[data-blok-database-drawer-content]`),a=(n=i==null?void 0:i.querySelector(`hr`))==null?null:n;i!==null&&i.insertBefore(this.buildPropsSection(r,this.currentRow),a)}buildPropsSection(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-drawer-props`,``);for(let i of e){var r;n.appendChild(this.createPropertyRow(i,(r=t.properties[i.id])==null?null:r))}if(!this.readOnly){let e=document.createElement(`button`);e.setAttribute(`data-blok-database-drawer-add-prop`,``),e.textContent=`+ Add a property`,e.addEventListener(`click`,()=>{this.propertyTypePopover===null&&(this.propertyTypePopover=new Gi({onSelect:e=>{var t,n;(t=this.onAddProperty)==null||t.call(this,e),(n=this.propertyTypePopover)==null||n.close()},i18n:this.i18n})),this.propertyTypePopover.open(e)}),n.appendChild(e)}return n}getRenderableSchema(){return[...this.schema].filter(e=>e.type!==`title`&&e.type!==`richText`).sort((e,t)=>e.position<t.position?-1:e.position>t.position?1:0)}createSelectPill(e){let t=document.createElement(`span`);if(t.setAttribute(`data-blok-database-drawer-prop-pill`,``),e.color!==void 0){t.style.backgroundColor=`var(--blok-color-${e.color}-bg)`,t.style.color=`var(--blok-color-${e.color}-text)`;let n=document.createElement(`span`);n.setAttribute(`data-blok-database-drawer-prop-dot`,``),n.style.backgroundColor=`var(--blok-color-${e.color}-text)`,t.appendChild(n)}let n=document.createElement(`span`);return n.textContent=e.label,t.appendChild(n),t}createPropertyRow(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-drawer-prop-row`,``);let r=document.createElement(`span`);r.setAttribute(`data-blok-database-drawer-prop-label`,``),r.textContent=e.name,n.appendChild(r);let i=document.createElement(`span`);if(i.setAttribute(`data-blok-database-drawer-prop-value`,``),e.type===`select`){let n=e.config,r=typeof t==`string`?t:null,a=n==null?void 0:n.options.find(e=>e.id===r);a!==void 0&&i.appendChild(this.createSelectPill(a))}else if(e.type===`multiSelect`){let n=e.config;(Array.isArray(t)?t:[]).map(e=>n==null?void 0:n.options.find(t=>t.id===e)).filter(e=>e!==void 0).forEach(e=>i.appendChild(this.createSelectPill(e)))}else (typeof t==`string`||typeof t==`number`||typeof t==`boolean`)&&(i.textContent=String(t));return n.appendChild(i),n}updateActiveCard(e){let t=this.wrapper.querySelector(`[data-blok-database-card-active]`);if(t==null||t.removeAttribute(`data-blok-database-card-active`),e!==null){let t=this.wrapper.querySelector(`[data-blok-database-card][data-row-id="${e}"]`);t==null||t.setAttribute(`data-blok-database-card-active`,``)}}cleanupListeners(){this.escapeHandler&&(document.removeEventListener(`keydown`,this.escapeHandler),this.escapeHandler=null),this.outsideClickHandler&&(document.removeEventListener(`mousedown`,this.outsideClickHandler),this.outsideClickHandler=null)}cleanupEditor(){if(this.blokInstance){try{let e=this.blokInstance,t=this.currentRowId;e.save().then(n=>{t!==null&&this.onDescriptionChange(t,n),e.destroy()}).catch(()=>{e.destroy()})}catch(e){}this.blokInstance=null}}autoResizeTitle(e){let{style:t}=e;t.height=`auto`,e.scrollHeight>0&&(t.height=`${e.scrollHeight}px`)}initNestedEditor(e,t){var r=this;Promise.resolve().then(()=>require(`../blok.cjs`)).then(({Blok:i})=>{let a=t.id,o=this.descriptionPropertyId===void 0?void 0:t.properties[this.descriptionPropertyId];this.blokInstance=new i(n.t(n.t({},this.toolsConfig),{},{holder:e,data:o,readOnly:this.readOnly,onChange:async()=>{try{var e;let t=await((e=r.blokInstance)==null?void 0:e.save());t!==void 0&&r.onDescriptionChange(a,t)}catch(e){}}}))}).catch(()=>{})}},qi=class{constructor(e){this.boundKeydown=null,this.wrapper=e.wrapper,this.onEscape=e.onEscape}attach(){this.boundKeydown=e=>{e.key===`Escape`&&this.onEscape()&&e.stopPropagation()},this.wrapper.addEventListener(`keydown`,this.boundKeydown)}destroy(){this.boundKeydown&&(this.wrapper.removeEventListener(`keydown`,this.boundKeydown),this.boundKeydown=null)}},Ji=[{type:`board`,icon:t.k,labelKey:`tools.database.viewTypeBoard`,descriptionKey:`tools.database.viewTypeBoardDescription`},{type:`list`,icon:t.At,labelKey:`tools.database.viewTypeList`,descriptionKey:`tools.database.viewTypeListDescription`}],Yi=class{constructor(e){this.popover=null,this.onSelect=e.onSelect,this.onClose=e.onClose,this.api=e.api}translate(e,t){var n,r;return(n=(r=this.api)==null?void 0:r.i18n.t(e))==null?t:n}open(e){this.close();let n=document.createElement(`div`);n.setAttribute(`data-blok-database-view-popover-heading`,``),n.textContent=this.translate(`tools.database.addView`,[`Add`,`view`].join(` `)),this.popover=new t.g({items:[{type:t.Ln.Html,element:n},...Ji.map(e=>{let n=this.createViewItem(e);return{type:t.Ln.Html,element:n,closeOnActivate:!0}})],trigger:e,width:`auto`,minWidth:`200px`,flippable:!1,autoFocusFirstItem:!1}),this.popover.on(t.v.Closed,()=>{if(this.popover!==null){var e;let t=this.popover;this.popover=null,t.destroy(),(e=this.onClose)==null||e.call(this)}}),this.popover.show()}createViewItem(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-view-option`,e.type);let n=document.createElement(`div`);n.setAttribute(`data-blok-database-view-option-icon`,``),n.innerHTML=e.icon,t.appendChild(n);let r=document.createElement(`div`);r.setAttribute(`data-blok-database-view-option-text`,``);let i=document.createElement(`span`);i.setAttribute(`data-blok-database-view-option-label`,``),i.textContent=this.translate(e.labelKey,``),r.appendChild(i);let a=document.createElement(`span`);return a.setAttribute(`data-blok-database-view-option-desc`,``),a.textContent=this.translate(e.descriptionKey,``),r.appendChild(a),t.appendChild(r),t.addEventListener(`click`,()=>{this.onSelect(e.type)}),t}close(){if(this.popover!==null){var e;let t=this.popover;this.popover=null,t.destroy(),(e=this.onClose)==null||e.call(this)}}destroy(){this.close()}},Xi=10,Zi={board:t.k,list:t.At},Qi=class{constructor(e){var t;this.element=null,this.barEl=null,this.addBtnEl=null,this.viewPopover=null,this.contextPopover=null,this.overflowDropdownEl=null,this.boundOverflowClose=null,this.moreBtnEl=null,this.isDragging=!1,this.dragViewId=``,this.dragStartX=0,this.ghostEl=null,this.options=e,this.views=e.views,this.onReorder=e.onReorder,this.readOnly=(t=e.readOnly)==null?!1:t,this.boundDragMove=this.handleDragMove.bind(this),this.boundDragUp=this.handleDragUp.bind(this),this.boundDragCancel=this.cleanupDrag.bind(this),this.boundDragKeyDown=e=>{e.key===`Escape`&&this.cleanupDrag()}}render(){let e=document.createElement(`div`);e.setAttribute(`data-blok-database-tab-bar`,``),this.barEl=e,this.element=e;let n=[...this.options.views].sort((e,t)=>e.position<t.position?-1:1);for(let t of n)e.appendChild(this.createTab(t));let r=document.createElement(`button`);return r.setAttribute(`data-blok-database-add-view`,``),r.innerHTML=t.Ht,r.addEventListener(`click`,()=>{this.openViewPopover(r)}),this.addBtnEl=r,this.readOnly||e.appendChild(r),e.addEventListener(`click`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;let n=t.getAttribute(`data-view-id`);n!==null&&(t.hasAttribute(`data-active`)||this.options.onTabClick(n))}),e.addEventListener(`contextmenu`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;e.preventDefault();let n=t.getAttribute(`data-view-id`);n!==null&&this.openContextPopover(t,n)}),e.addEventListener(`dblclick`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;let n=t.getAttribute(`data-view-id`);n!==null&&this.openContextPopover(t,n)}),e.addEventListener(`pointerdown`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(t===null)return;let n=t.getAttribute(`data-view-id`);n!==null&&(this.dragViewId=n,this.dragStartX=e.clientX,this.isDragging=!1,document.addEventListener(`pointermove`,this.boundDragMove),document.addEventListener(`pointerup`,this.boundDragUp),document.addEventListener(`pointercancel`,this.boundDragCancel),document.addEventListener(`keydown`,this.boundDragKeyDown))}),typeof ResizeObserver<`u`&&new ResizeObserver(()=>{var e;if(this.element===null)return;let t=Array.from(this.element.querySelectorAll(`[data-blok-database-tab]`));for(let e of t)e.style.display=``;(e=this.moreBtnEl)==null||e.remove(),this.moreBtnEl=null;let n=this.element.clientWidth,r=t.findIndex((e,r)=>40+t.slice(0,r+1).reduce((e,t)=>e+t.offsetWidth+2,0)>n),i=r===-1?t.length:r;i<t.length&&this.handleOverflow(i)}).observe(e),e}createTab(e){var t;let n=document.createElement(`div`);n.setAttribute(`data-blok-database-tab`,``),n.setAttribute(`data-view-id`,e.id),e.id===this.options.activeViewId&&n.setAttribute(`data-active`,``);let r=document.createElement(`span`);r.innerHTML=(t=Zi[e.type])==null?``:t,n.appendChild(r);let i=document.createElement(`span`);return i.setAttribute(`data-blok-database-tab-name`,``),i.textContent=e.name,n.appendChild(i),n}openContextPopover(e,n){this.closeContextPopover();let r=this.options.views.length>1,i=(e,t)=>{var n,r;return(n=(r=this.options.api)==null?void 0:r.i18n.t(e))==null?t:n},a=[{icon:t.Bt,title:i(`tools.database.renameView`,`Rename`),closeOnActivate:!0,onActivate:()=>{this.startInlineRename(e,n)}},{icon:t.H,title:i(`tools.database.duplicateView`,`Duplicate`),closeOnActivate:!0,onActivate:()=>{this.options.onDuplicate(n)}}],o=r?[{type:t.Ln.Separator},{icon:t.rn,title:i(`tools.database.deleteView`,`Delete`),isDestructive:!0,closeOnActivate:!0,onActivate:()=>{this.options.onDelete(n)}}]:[];this.contextPopover=new t.g({trigger:e,width:`auto`,minWidth:`160px`,autoFocusFirstItem:!1,items:[...a,...o]}),this.contextPopover.on(t.v.Closed,()=>{if(this.contextPopover!==null){let e=this.contextPopover;this.contextPopover=null,e.destroy()}}),this.contextPopover.show()}closeContextPopover(){if(this.contextPopover!==null){let e=this.contextPopover;this.contextPopover=null,e.destroy()}}startInlineRename(e,t){var n;let r=e.querySelector(`[data-blok-database-tab-name]`);if(!(r instanceof HTMLElement))return;let i=(n=r.textContent)==null?``:n,a=document.createElement(`input`);a.setAttribute(`data-blok-database-tab-rename-input`,``),a.value=i,r.replaceWith(a),a.focus(),a.select();let o=()=>{let e=a.value.trim()||i,n=document.createElement(`span`);n.setAttribute(`data-blok-database-tab-name`,``),n.textContent=e,a.replaceWith(n),e!==i&&this.options.onRename(t,e)};a.addEventListener(`blur`,o),a.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`Enter`)a.blur();else if(e.key===`Escape`){a.removeEventListener(`blur`,o);let e=document.createElement(`span`);e.setAttribute(`data-blok-database-tab-name`,``),e.textContent=i,a.replaceWith(e)}})}openViewPopover(e){var t;this.viewPopover!==null&&this.viewPopover.destroy(),e.setAttribute(`data-popover-open`,``),(t=this.barEl)==null||t.setAttribute(`data-popover-open`,``),this.viewPopover=new Yi({onSelect:e=>{this.options.onAddView(e)},onClose:()=>{var t;e.removeAttribute(`data-popover-open`),(t=this.barEl)==null||t.removeAttribute(`data-popover-open`)},api:this.options.api}),this.viewPopover.open(e)}handleOverflow(e){var t;if(this.element===null)return;(t=this.moreBtnEl)==null||t.remove();let n=[...this.views].sort((e,t)=>e.position<t.position?-1:1).length-e;if(n<=0)return;let r=Array.from(this.element.querySelectorAll(`[data-blok-database-tab]`));for(let t of r.slice(e))t.style.display=`none`;let i=document.createElement(`div`);i.setAttribute(`data-blok-database-tab-more`,``),i.textContent=`${n} more...`,i.style.cursor=`pointer`,i.addEventListener(`click`,()=>{this.openOverflowDropdown(i)});let a=this.element.querySelector(`[data-blok-database-add-view]`);a===null?this.element.appendChild(i):this.element.insertBefore(i,a),this.moreBtnEl=i}openOverflowDropdown(e){var t;this.closeOverflowDropdown();let n=document.createElement(`div`);n.setAttribute(`data-blok-popover`,``),n.setAttribute(`data-blok-database-tab-overflow-dropdown`,``),n.style.position=`fixed`,n.style.zIndex=`1000`;let r=e.getBoundingClientRect();n.style.top=`${r.bottom+4}px`,n.style.left=`${r.left}px`;let i=[...this.views].sort((e,t)=>e.position<t.position?-1:1);for(let e of i){var a;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-tab-overflow-item`,``),t.setAttribute(`data-view-id`,e.id),e.id===this.options.activeViewId&&t.setAttribute(`data-active`,``);let r=document.createElement(`span`);r.innerHTML=(a=Zi[e.type])==null?``:a,t.appendChild(r);let i=document.createElement(`span`);i.textContent=e.name,t.appendChild(i),t.addEventListener(`click`,()=>{e.id!==this.options.activeViewId&&this.options.onTabClick(e.id),this.closeOverflowDropdown()}),n.appendChild(t)}let o=document.createElement(`div`);o.setAttribute(`data-blok-database-tab-overflow-separator`,``),n.appendChild(o);let s=(t=this.element)==null?void 0:t.querySelector(`[data-blok-database-add-view]`),c=document.createElement(`div`);c.setAttribute(`data-blok-database-tab-overflow-new`,``),c.textContent=`+ New view`,c.addEventListener(`click`,()=>{this.closeOverflowDropdown(),s!=null&&this.openViewPopover(s)}),n.appendChild(c),document.body.appendChild(n),this.overflowDropdownEl=n,this.boundOverflowClose=t=>{let r=t.target;!n.contains(r)&&!e.contains(r)&&this.closeOverflowDropdown()},document.addEventListener(`mousedown`,this.boundOverflowClose)}closeOverflowDropdown(){this.overflowDropdownEl!==null&&(this.overflowDropdownEl.remove(),this.overflowDropdownEl=null),this.boundOverflowClose!==null&&(document.removeEventListener(`mousedown`,this.boundOverflowClose),this.boundOverflowClose=null)}handleDragMove(e){let t=Math.abs(e.clientX-this.dragStartX);if(!(!this.isDragging&&t<Xi)){if(!this.isDragging){var n,r;this.isDragging=!0,(n=this.element)==null||n.setAttribute(`data-dragging`,``);let e=(r=this.element)==null?void 0:r.querySelector(`[data-view-id="${this.dragViewId}"]`);if(e!==null){this.ghostEl=e.cloneNode(!0),this.ghostEl.setAttribute(`data-blok-database-tab-ghost`,``),this.ghostEl.style.position=`fixed`,this.ghostEl.style.pointerEvents=`none`,this.ghostEl.style.zIndex=`50`,this.ghostEl.style.opacity=`0.7`;let t=e.getBoundingClientRect();this.ghostEl.style.top=`${t.top}px`,this.ghostEl.style.width=`${t.width}px`,document.body.appendChild(this.ghostEl),e.style.opacity=`0.4`}}this.ghostEl!==null&&(this.ghostEl.style.left=`${e.clientX-50}px`)}}handleDragUp(e){var t,n,r,i;if(!this.isDragging){this.removeDragListeners();return}let a=Array.from((t=(n=this.element)==null?void 0:n.querySelectorAll(`[data-blok-database-tab]`))==null?[]:t).filter(e=>e.getAttribute(`data-view-id`)!==this.dragViewId),o=a.findIndex(t=>{let n=t.getBoundingClientRect();return e.clientX<(n.left+n.right)/2}),s=o>=0?a[o].getAttribute(`data-view-id`):null,c=o>0?a[o-1].getAttribute(`data-view-id`):o===-1&&a.length>0?a[a.length-1].getAttribute(`data-view-id`):null,l=[...this.views].sort((e,t)=>e.position<t.position?-1:1),u=s===null?null:l.find(e=>e.id===s),d=c===null?null:l.find(e=>e.id===c),f=Ai((r=d==null?void 0:d.position)==null?null:r,(i=u==null?void 0:u.position)==null?null:i);this.cleanupDrag(),this.onReorder(this.dragViewId,f)}cleanupDrag(){var e,t;this.ghostEl!==null&&(this.ghostEl.remove(),this.ghostEl=null),(e=this.element)==null||e.removeAttribute(`data-dragging`);let n=(t=this.element)==null?void 0:t.querySelector(`[data-view-id="${this.dragViewId}"]`);n!==null&&(n.style.opacity=``),this.isDragging=!1,this.removeDragListeners()}removeDragListeners(){document.removeEventListener(`pointermove`,this.boundDragMove),document.removeEventListener(`pointerup`,this.boundDragUp),document.removeEventListener(`pointercancel`,this.boundDragCancel),document.removeEventListener(`keydown`,this.boundDragKeyDown)}setReadOnly(e){this.readOnly!==e&&(this.readOnly=e,!(this.barEl===null||this.addBtnEl===null)&&(e?this.addBtnEl.remove():this.addBtnEl.isConnected||this.barEl.appendChild(this.addBtnEl)))}destroy(){this.cleanupDrag(),this.closeContextPopover(),this.closeOverflowDropdown(),this.viewPopover!==null&&(this.viewPopover.destroy(),this.viewPopover=null)}getAddBtnEl(){return this.addBtnEl}},$i=class{constructor({data:e,config:t,api:n,block:r,readOnly:i}){var a,o;this.element=null,this.titleElement=null,this.titleRowElement=null,this.boardContainer=null,this.tabBar=null,this.cardDrag=null,this.columnDrag=null,this.columnControls=null,this.listRowDrag=null,this.cardDrawer=null,this.keyboard=null,this.cardMenuPopover=null,this.api=n,this.block=r,this.readOnly=i,this.config=t==null?{}:t,this.title=(a=e==null?void 0:e.title)==null?``:a,this.model=new Mi(e);let s=this.model.getViews();this.activeViewId=(o=e==null?void 0:e.activeViewId)==null?s.length>0?s[0].id:``:o,this.activateView(this.activeViewId)}static get toolbox(){return[{icon:t.K,titleKey:`database`,name:`database`,searchTerms:[`database`,`kanban`,`board`,`cards`,`columns`]},{icon:t.k,titleKey:`board`,name:`board`,searchTerms:[`board`,`kanban`,`cards`,`columns`,`database`]}]}static get isReadOnlySupported(){return!0}render(){let e=document.createElement(`div`);e.setAttribute(`data-blok-tool`,`database`),e.setAttribute(`data-blok-database-wrapper`,``),e.style.display=`flex`,e.style.flexDirection=`column`,this.element=e;let t=this.createTitleElement();this.titleElement=t;let n=document.createElement(`div`);n.setAttribute(`data-blok-database-title-row`,``),n.appendChild(t),this.titleRowElement=n,e.appendChild(n),this.tabBar=this.createTabBar(),e.appendChild(this.tabBar.render()),this.syncTitleRowAddBtn();let r=document.createElement(`div`);r.setAttribute(`data-blok-database-board-container`,``),r.style.overflow=`hidden`,r.style.position=`relative`,this.boardContainer=r,e.appendChild(r),this.syncRowsFromBlocks();let i=this.renderActiveView();return r.appendChild(i),this.readOnly||(this.attachViewListeners(i),this.initSubsystems(i)),e}createTitleElement(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-database-title`,``),e.textContent=this.title,e.style.fontSize=`1.5rem`,e.style.fontWeight=`600`,e.style.lineHeight=`1.3`,e.style.color=`var(--blok-text-primary)`,e.style.outline=`none`,e.style.cursor=`text`,e.style.wordBreak=`break-word`,e.className=o.join(` `),p(e,`New database`),this.readOnly||(e.setAttribute(`contenteditable`,`true`),e.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===`Tab`)&&(t.preventDefault(),e.blur())})),e}rendered(){this.block.stretched=!0;let e=this.model.getOrderedRows().length>0;this.syncRowsFromBlocks(),!e&&this.model.getOrderedRows().length>0&&this.rerenderView(),this.config.adapter!==void 0&&this.loadFromBackend()}async loadFromBackend(){var e=this;let t=await e.sync.syncLoadDatabase();if(t===void 0)return;e.model.hydrate(t);let n=e.model.getViews();n.length>0&&!n.some(t=>t.id===e.activeViewId)&&(e.activeViewId=n[0].id),e.rerenderView()}save(e){var t,r;let i=(t=(r=this.titleElement)==null?void 0:r.textContent)==null?this.title:t;return n.t(n.t({},this.model.snapshot()),{},{title:i,activeViewId:this.activeViewId})}validate(e){var t,n,r,i;let a=((t=(n=e.schema)==null?void 0:n.filter(e=>e.type===`title`).length)==null?0:t)===1,o=e.views!==void 0&&e.views.length>0,s=(r=(i=e.views)==null?void 0:i.filter(e=>e.type===`board`).every(e=>e.groupBy!==void 0))==null?!0:r;return a&&o&&s}destroy(){var e,t,n,r,i,a,o;(e=this.cardDrag)==null||e.destroy(),(t=this.columnDrag)==null||t.destroy(),(n=this.columnControls)==null||n.destroy(),(r=this.listRowDrag)==null||r.destroy(),this.listRowDrag=null,(i=this.cardDrawer)==null||i.destroy(),(a=this.keyboard)==null||a.destroy(),(o=this.tabBar)==null||o.destroy(),this.sync.flushPendingUpdates(),this.sync.flushPendingPropertyUpdates(),this.sync.destroy(),this.element=null,this.boardContainer=null,this.tabBar=null}setReadOnly(e){var t;this.readOnly!==e&&(this.readOnly=e,this.titleElement!==null&&this.titleElement.setAttribute(`contenteditable`,e?`false`:`true`),(t=this.tabBar)==null||t.setReadOnly(e),this.syncTitleRowAddBtn(),this.rerenderView())}getToolbarAnchorElement(){var e;return(e=this.element)==null?void 0:e}syncRowsFromBlocks(){let e=this.api.blocks.getChildren(this.block.id).filter(e=>e.name===`database-row`).map(e=>{var t,n,r,i;return{id:e.id,position:(t=(n=e.preservedData)==null?void 0:n.position)==null?``:t,properties:(r=(i=e.preservedData)==null?void 0:i.properties)==null?{}:r}});this.model.setRows(e)}deleteRowBlock(e){let t=this.api.blocks.getBlockIndex(e);t!==void 0&&this.api.blocks.delete(t),this.syncRowsFromBlocks()}updateRowBlock(e,t){let n=this.api.blocks.getChildren(this.block.id).find(t=>t.id===e);n!==void 0&&(n.call(`updateProperties`,t),n.dispatchChange()),this.syncRowsFromBlocks()}moveRowBlock(e,t){let n=this.api.blocks.getChildren(this.block.id).find(t=>t.id===e);n!==void 0&&(n.call(`updatePosition`,{position:t}),n.dispatchChange()),this.syncRowsFromBlocks()}activateView(e){this.model.getView(e)!==void 0&&(this.activeViewId=e,this.sync=new Ii(this.config.adapter,e=>{this.api.notifier.show({message:String(e),style:`error`})}))}switchView(e){var t,n,r,i,a;if(e===this.activeViewId||this.boardContainer===null)return;(t=this.cardDrag)==null||t.destroy(),(n=this.columnDrag)==null||n.destroy(),(r=this.columnControls)==null||r.destroy(),(i=this.listRowDrag)==null||i.destroy(),(a=this.keyboard)==null||a.destroy(),this.cardDrag=null,this.columnDrag=null,this.columnControls=null,this.listRowDrag=null,this.keyboard=null,this.sync.flushPendingUpdates(),this.sync.flushPendingPropertyUpdates(),this.sync.destroy(),this.activateView(e),this.boardContainer.innerHTML=``,this.syncRowsFromBlocks();let o=this.renderActiveView();this.boardContainer.appendChild(o),this.readOnly||(this.attachViewListeners(o),this.initSubsystems(o)),this.rebuildTabBar()}addView(e){let t=this.model.getSchema().find(e=>e.type===`select`),n=e===`list`?`List`:`Board`,r=this.model.addView(n,e,{groupBy:e===`board`?t==null?void 0:t.id:void 0});this.sync.syncCreateView({id:r.id,name:r.name,type:r.type,position:r.position,groupBy:r.groupBy}),this.switchView(r.id)}renameView(e,t){this.model.updateView(e,{name:t}),this.sync.syncUpdateView({viewId:e,changes:{name:t}})}duplicateView(e){let t=this.model.getView(e);if(t===void 0)return;let n=this.model.addView(t.name,t.type,{groupBy:t.groupBy,sorts:[...t.sorts],filters:[...t.filters],visibleProperties:[...t.visibleProperties]});this.sync.syncCreateView({id:n.id,name:n.name,type:n.type,position:n.position,groupBy:n.groupBy}),this.switchView(n.id)}deleteView(e){let t=this.model.getViews();if(t.length<=1)return;let n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=e===this.activeViewId;if(this.model.deleteView(e),this.sync.syncDeleteView({viewId:e}),r){let e=this.model.getViews(),t=Math.min(n,e.length-1);this.switchView(e[t].id)}else this.rebuildTabBar()}reorderView(e,t){this.model.updateView(e,{position:t}),this.sync.syncUpdateView({viewId:e,changes:{position:t}}),this.rebuildTabBar()}rebuildTabBar(){if(this.element===null||this.tabBar===null)return;let e=this.element.querySelector(`[data-blok-database-tab-bar]`);this.tabBar.destroy(),this.tabBar=this.createTabBar();let t=this.tabBar.render();e===null?this.element.insertBefore(t,this.boardContainer):e.replaceWith(t),this.syncTitleRowAddBtn()}syncTitleRowAddBtn(){if(this.element===null||this.titleRowElement===null||this.tabBar===null)return;let e=this.element.querySelector(`[data-blok-database-tab-bar]`),t=this.model.getViews(),n=this.tabBar.getAddBtnEl();t.length===1&&!this.readOnly&&n!==null?(this.titleRowElement.appendChild(n),this.titleRowElement.setAttribute(`data-single-view`,``),e instanceof HTMLElement&&(e.style.display=`none`)):(this.titleRowElement.removeAttribute(`data-single-view`),this.titleRowElement.querySelectorAll(`[data-blok-database-add-view]`).forEach(e=>{e.remove()}),!this.readOnly&&n!==null&&e!==null&&!e.contains(n)&&e.appendChild(n),e instanceof HTMLElement&&(e.style.display=t.length>=2?``:`none`))}createTabBar(){return new Qi({views:this.model.getViews(),activeViewId:this.activeViewId,onTabClick:e=>this.switchView(e),onAddView:e=>this.addView(e),onRename:(e,t)=>this.renameView(e,t),onDuplicate:e=>this.duplicateView(e),onDelete:e=>this.deleteView(e),onReorder:(e,t)=>this.reorderView(e,t),readOnly:this.readOnly})}renderActiveView(){var e;let t=this.model.getView(this.activeViewId),n=this.model.getSchema().find(e=>e.type===`title`),r=(e=n==null?void 0:n.id)==null?``:e,i=t==null?void 0:t.groupBy;return(t==null?void 0:t.type)===`list`?this.renderListView(r,i,t):this.renderBoardView(r,i)}renderBoardView(e,t){let n=t===void 0?[]:this.model.getSelectOptions(t),r=t===void 0?new Map:this.model.getRowsGroupedBy(t);return this.view=new Ni({readOnly:this.readOnly,i18n:this.api.i18n,options:n,getRows:e=>{var t;return(t=r.get(e))==null?[]:t},titlePropertyId:e,onTitleEdit:(e,t)=>{var n;let r=this.model.getSchema().find(e=>e.type===`title`),i=(n=r==null?void 0:r.id)==null?``:n;this.updateRowBlock(e,{[i]:t}),this.sync.syncUpdateRow({rowId:e,properties:{[i]:t}})}}),this.view.createView()}renderListView(e,t,n){let r=this.model.getSchema();if(t!==void 0){let i=this.model.getSelectOptions(t),a=this.model.getRowsGroupedBy(t);this.view=new Pi({readOnly:this.readOnly,i18n:this.api.i18n,rows:[],titlePropertyId:e,schema:r,visiblePropertyIds:n.visibleProperties,options:i,getRows:e=>{var t;return(t=a.get(e))==null?[]:t}})}else this.view=new Pi({readOnly:this.readOnly,i18n:this.api.i18n,rows:this.model.getOrderedRows(),titlePropertyId:e,schema:r,visiblePropertyIds:n.visibleProperties});return this.view.createView()}attachViewListeners(e){e.addEventListener(`click`,t=>{let n=t.target,r=n.closest(`[data-blok-database-add-card]`);if(r!==null){let t=r.getAttribute(`data-option-id`);t!==null&&this.handleAddRow(t,e);return}if(n.closest(`[data-blok-database-add-column]`)!==null){this.handleAddColumn(e);return}let i=n.closest(`[data-blok-database-card-menu]`);if(i instanceof HTMLElement){let n=i.getAttribute(`data-row-id`),r=i.closest(`[data-blok-database-card]`);n!==null&&r instanceof HTMLElement&&(t.stopPropagation(),this.openCardMenu(i,r,n,e));return}let a=n.closest(`[data-blok-database-add-row]`);if(a!==null){let t=a.getAttribute(`data-option-id`);this.handleAddListRow(t,e);return}let o=n.closest(`[data-blok-database-delete-row]`);if(o!==null){let n=o.getAttribute(`data-row-id`);n!==null&&(t.stopPropagation(),this.deleteRowBlock(n),this.view.removeRow(e,n),this.sync.syncDeleteRow({rowId:n}));return}let s=n.closest(`[data-blok-database-list-row]`);if(s!==null){let e=s.getAttribute(`data-row-id`);e!==null&&this.handleRowClick(e);return}let c=n.closest(`[data-blok-database-card]`);if(c!==null){let e=c.getAttribute(`data-row-id`);e!==null&&this.handleRowClick(e)}})}openCardMenu(e,n,r,i){n.setAttribute(`data-popover-open`,``),this.cardMenuPopover=new t.g({trigger:e,width:`auto`,minWidth:`140px`,autoFocusFirstItem:!1,items:[{type:t.Ln.Default,title:this.api.i18n.t(`tools.database.deleteCard`),icon:t.rn,onActivate:()=>{this.deleteRowBlock(r),this.view.removeRow(i,r),this.sync.syncDeleteRow({rowId:r})}}]}),this.cardMenuPopover.on(t.v.Closed,()=>{if(n.removeAttribute(`data-popover-open`),this.cardMenuPopover!==null){let e=this.cardMenuPopover;this.cardMenuPopover=null,e.destroy()}}),this.cardMenuPopover.show()}handleAddListRow(e,t){var n,r;let i=this.model.getSchema().find(e=>e.type===`title`),a=(n=i==null?void 0:i.id)==null?``:n,o=this.model.getView(this.activeViewId),s=o==null?void 0:o.groupBy,c={[a]:``};s!==void 0&&e!==null&&(c[s]=e);let l=this.model.createRowData(c),u=(r=this.api.blocks.getBlockIndex(this.block.id))==null?0:r;this.api.blocks.insert(`database-row`,{properties:l.properties,position:l.position},{},u+1,!1,!1,l.id),this.api.blocks.setBlockParent(l.id,this.block.id),this.syncRowsFromBlocks(),this.view.appendRow(t,l),this.sync.syncCreateRow({id:l.id,properties:l.properties,position:l.position})}handleAddRow(e,t){var n,r;let i=this.model.getView(this.activeViewId),a=i==null?void 0:i.groupBy;if(a===void 0)return;let o=this.model.getSchema().find(e=>e.type===`title`),s=(n=o==null?void 0:o.id)==null?``:n,c=this.model.createRowData({[s]:``,[a]:e}),l=(r=this.api.blocks.getBlockIndex(this.block.id))==null?0:r;this.api.blocks.insert(`database-row`,{properties:c.properties,position:c.position},{},l+1,!1,!1,c.id),this.api.blocks.setBlockParent(c.id,this.block.id),this.syncRowsFromBlocks();let u=t.querySelector(`[data-option-id="${e}"][data-blok-database-column]`);if(u===null)return;let d=u.querySelector(`[data-blok-database-cards]`);d!==null&&(this.view.appendRow(d,c),this.sync.syncCreateRow({id:c.id,properties:c.properties,position:c.position}))}handleAddColumn(e){var n,r;let i=this.model.getView(this.activeViewId),a=i==null?void 0:i.groupBy;if(a===void 0)return;let o=this.model.getProperty(a);if((o==null?void 0:o.config)===void 0)return;let s=o.config.options,c=s.length>0?s[s.length-1].position:null,l={id:t.cr(),label:this.api.i18n.t(`tools.database.columnTitlePlaceholder`),position:Mi.positionBetween(c,null)};this.model.updateProperty(a,{config:{options:[...s,l]}}),(n=(r=this.view).appendGroup)==null||n.call(r,e,l),this.sync.syncUpdateProperty({propertyId:a,changes:{config:{options:[...s,l]}}})}initSubsystems(e){var t;if(this.element===null)return;let r=this.model.getView(this.activeViewId),i=(r==null?void 0:r.type)===`list`,a=this.model.getSchema().find(e=>e.type===`title`),o=(t=a==null?void 0:a.id)==null?``:t,s=this.model.getSchema().find(e=>e.type===`richText`),c=s==null?void 0:s.id;i?this.listRowDrag=new Ui({wrapper:e,onDrop:e=>this.handleListRowDrop(e)}):(this.cardDrag=new Ri({wrapper:e,onDrop:e=>this.handleRowDrop(e)}),this.columnDrag=new Bi({wrapper:e,onDrop:e=>this.handleGroupDrop(e)}),this.columnControls=new Vi({i18n:this.api.i18n,onRename:(e,t)=>this.handleOptionRename(e,t),onDelete:t=>this.handleOptionDelete(t,e),onRenameInput:(e,t)=>{this.handleOptionRename(e,t)},onRenameCommit:(e,t)=>{let r=this.model.getView(this.activeViewId),i=r==null?void 0:r.groupBy;if(i===void 0)return;let a=this.model.getProperty(i);if((a==null?void 0:a.config)===void 0)return;let o=a.config.options.map(r=>r.id===e?n.t(n.t({},r),{},{label:t}):r);this.sync.syncUpdatePropertyDebounced({propertyId:i,changes:{config:{options:o}}})}}),this.makeColumnHeadersEditable(e)),this.cardDrawer===null&&(this.cardDrawer=new Ki({wrapper:this.element,readOnly:this.readOnly,i18n:this.api.i18n,toolsConfig:this.api.tools.getToolsConfig(),titlePropertyId:o,descriptionPropertyId:c,schema:this.model.getSchema(),onTitleChange:(e,t)=>{var n,r,i;this.updateRowBlock(e,{[o]:t});let a=(n=(r=this.boardContainer)==null?void 0:r.querySelector(`[data-blok-database-board]`))==null?(i=this.boardContainer)==null?void 0:i.querySelector(`[data-blok-database-list]`):n;a!=null&&this.view.updateRowTitle(a,e,t),this.sync.syncUpdateRow({rowId:e,properties:{[o]:t}})},onDescriptionChange:(e,t)=>{c!==void 0&&(this.updateRowBlock(e,{[c]:t}),this.sync.syncUpdateRow({rowId:e,properties:{[c]:t}}))},onClose:()=>{},onAddProperty:e=>{var t;let n=this.model.addProperty(`Property`,e);this.sync.syncCreateProperty({id:n.id,name:n.name,type:n.type,position:n.position}),(t=this.cardDrawer)==null||t.refreshSchema(this.model.getSchema())}})),this.keyboard=new qi({wrapper:e,onEscape:()=>{var e;return(e=this.cardDrawer)!=null&&e.isOpen?(this.cardDrawer.close(),!0):!1}}),this.keyboard.attach(),e.addEventListener(`pointerdown`,e=>{let t=e.target,n=t.closest(`[data-blok-database-column-header]`);if(n!==null){var r;if(t.closest(`[data-blok-database-column-pill]`)!==null)return;let a=n.closest(`[data-blok-database-column]`),o=(r=a==null?void 0:a.getAttribute(`data-option-id`))==null?null:r;if(o!==null){var i;e.preventDefault(),e.stopPropagation(),(i=this.columnDrag)==null||i.beginTracking(o,e.clientX,e.clientY)}return}let a=t.closest(`[data-blok-database-card]`);if(a!==null){let t=a.getAttribute(`data-row-id`);if(t!==null){var o;e.preventDefault(),e.stopPropagation(),(o=this.cardDrag)==null||o.beginTracking(t,e.clientX,e.clientY)}return}let s=t.closest(`[data-blok-database-list-row]`);if(s!==null){let t=s.getAttribute(`data-row-id`);if(t!==null){var c;e.preventDefault(),e.stopPropagation(),(c=this.listRowDrag)==null||c.beginTracking(t,e.clientX,e.clientY)}}})}makeColumnHeadersEditable(e){if(this.columnControls===null)return;let t=Array.from(e.querySelectorAll(`[data-blok-database-column-header]`));for(let e of t){let t=e.closest(`[data-blok-database-column]`),n=t==null?void 0:t.getAttribute(`data-option-id`);n!=null&&(this.columnControls.makePillTitleEditable(e,n),this.columnControls.appendDeleteButton(e,n))}}handleListRowDrop(e){var t,n;let{rowId:r,beforeRowId:i,afterRowId:a}=e,o=i===null?void 0:this.model.getRow(i),s=a===null?void 0:this.model.getRow(a),c=Mi.positionBetween((t=s==null?void 0:s.position)==null?null:t,(n=o==null?void 0:o.position)==null?null:n);this.moveRowBlock(r,c),this.rerenderView(),this.sync.syncMoveRow({rowId:r,position:c})}handleRowDrop(e){var t,n;let{rowId:r,toOptionId:i,beforeRowId:a,afterRowId:o}=e,s=this.model.getView(this.activeViewId),c=s==null?void 0:s.groupBy;if(c===void 0)return;let l=a===null?void 0:this.model.getRow(a),u=o===null?void 0:this.model.getRow(o),d=Mi.positionBetween((t=u==null?void 0:u.position)==null?null:t,(n=l==null?void 0:l.position)==null?null:n);this.updateRowBlock(r,{[c]:i}),this.moveRowBlock(r,d),this.rerenderView(),this.sync.syncUpdateRow({rowId:r,properties:{[c]:i}}),this.sync.syncMoveRow({rowId:r,position:d})}handleGroupDrop(e){var t,r;let{optionId:i,beforeOptionId:a,afterOptionId:o}=e,s=this.model.getView(this.activeViewId),c=s==null?void 0:s.groupBy;if(c===void 0)return;let l=this.model.getProperty(c);if((l==null?void 0:l.config)===void 0)return;let u=[...l.config.options],d=u.findIndex(e=>e.id===i);if(d===-1)return;let f=a===null?void 0:u.find(e=>e.id===a),p=o===null?void 0:u.find(e=>e.id===o),m=Mi.positionBetween((t=p==null?void 0:p.position)==null?null:t,(r=f==null?void 0:f.position)==null?null:r);u[d]=n.t(n.t({},u[d]),{},{position:m}),this.model.updateProperty(c,{config:{options:u}}),this.moveColumnInDom(i,a),this.sync.syncUpdateProperty({propertyId:c,changes:{config:{options:u}}})}moveColumnInDom(e,t){var n;let r=(n=this.boardContainer)==null?void 0:n.querySelector(`[data-blok-database-board]`);if(r==null)return;let i=r.querySelector(`[data-option-id="${e}"]`);if(i!==null)if(t!==null){let e=r.querySelector(`[data-option-id="${t}"]`);e!==null&&r.insertBefore(i,e)}else{let e=r.querySelector(`[data-blok-database-add-column]`);e===null?r.appendChild(i):r.insertBefore(i,e)}}handleOptionRename(e,t){let r=this.model.getView(this.activeViewId),i=r==null?void 0:r.groupBy;if(i===void 0)return;let a=this.model.getProperty(i);if((a==null?void 0:a.config)===void 0)return;let o=a.config.options.map(r=>r.id===e?n.t(n.t({},r),{},{label:t}):r);this.model.updateProperty(i,{config:{options:o}}),this.sync.syncUpdateProperty({propertyId:i,changes:{config:{options:o}}})}handleOptionDelete(e,t){var n,r,i;let a=this.model.getView(this.activeViewId),o=a==null?void 0:a.groupBy;if(o===void 0)return;let s=this.model.getProperty(o);if((s==null?void 0:s.config)===void 0||s.config.options.length<=1)return;let c=(n=this.model.getRowsGroupedBy(o).get(e))==null?[]:n;for(let e of c)this.deleteRowBlock(e.id),this.sync.syncDeleteRow({rowId:e.id});let l=s.config.options.filter(t=>t.id!==e);this.model.updateProperty(o,{config:{options:l}}),(r=(i=this.view).removeGroup)==null||r.call(i,t,e),this.sync.syncUpdateProperty({propertyId:o,changes:{config:{options:l}}})}handleRowClick(e){var t;let n=this.model.getRow(e);n!==void 0&&((t=this.cardDrawer)==null||t.open(n))}rerenderView(){var e,t,n,r,i,a,o,s,c,l;if(this.boardContainer===null)return;let u=(e=(t=(n=this.boardContainer.querySelector(`[data-blok-database-board]`))==null?void 0:n.closest(`[data-blok-tool]`))==null?this.boardContainer.querySelector(`[data-blok-database-list]`):t)==null?this.boardContainer.firstElementChild:e,d=this.boardContainer.querySelector(`[data-blok-database-board]`),f=(r=d==null?void 0:d.scrollLeft)==null?0:r;(i=this.cardDrag)==null||i.destroy(),(a=this.columnDrag)==null||a.destroy(),(o=this.columnControls)==null||o.destroy(),(s=this.listRowDrag)==null||s.destroy(),this.listRowDrag=null,(c=this.cardDrawer)==null||c.destroy(),this.cardDrawer=null,(l=this.keyboard)==null||l.destroy(),this.syncRowsFromBlocks();let p=this.renderActiveView();u==null?this.boardContainer.appendChild(p):u.replaceWith(p);let m=p.querySelector(`[data-blok-database-board]`);m!==null&&(m.scrollLeft=f),this.attachViewListeners(p),this.initSubsystems(p)}},ea=class{constructor({data:e}){var t,n;this._data={properties:(t=e.properties)==null?{}:t,position:(n=e.position)==null?`a0`:n}}render(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-tool`,`database-row`),e}save(e){return{properties:this._data.properties,position:this._data.position}}validate(e){return e.properties!==null&&e.properties!==void 0&&typeof e.properties==`object`}updateProperties(e){Object.assign(this._data.properties,e)}updatePosition(e){this._data.position=e.position}getProperties(){return this._data.properties}getPosition(){return this._data.position}static get isReadOnlySupported(){return!0}setReadOnly(e){}},ta=class{constructor(e){this.element=null}render(){let e=document.createElement(`div`);e.className=r.n(`py-3`,`leading-[1px]`);let t=document.createElement(`hr`);return t.className=r.n(`border-t`,`border-border-primary`,`border-b-0`,`border-l-0`,`border-r-0`),e.appendChild(t),this.element=e,e}save(){return{}}validate(e){return!0}static get toolbox(){return{icon:t.J,titleKey:`divider`,shortcut:`---`,searchTerms:[`hr`,`line`,`separator`,`rule`,`---`,`divider`,`delimiter`,`splitter`],searchTermKeys:[`divider`,`separator`,`delimiter`,`splitter`]}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`HR`],patterns:{divider:/^-{3,}$/}}}onPaste(e){}setReadOnly(e){}static get sanitize(){return{}}},na=`tools.quote.placeholder`,ra=[`border-l-[3px]`,`border-current`,`pl-[0.9em]`,`pr-[0.9em]`,`py-[0.2em]`,`leading-[1.5]`,`outline-hidden`,`mt-[0.3em]`,`mb-[0.3em]`],ia=`text-[1.2em]`,aa=class{constructor({data:e,api:t,readOnly:n}){var r,i;this.placeholderCleanup=null,this._element=null,this.api=t,this.readOnly=n,this._data={text:(r=e==null?void 0:e.text)==null?``:r,size:(i=e==null?void 0:e.size)==null?`default`:i},this.onKeyUp=this.onKeyUp.bind(this)}onKeyUp(e){e.code!==`Backspace`&&e.code!==`Delete`||this._element&&this._element.textContent===``&&(this._element.innerHTML=``)}drawView(){let e=document.createElement(`blockquote`);return e.className=r.n(this.api.styles.block,ra,c,this._data.size===`large`?ia:``),e.setAttribute(t.Pr.tool,`quote`),e.contentEditable=`false`,this._data.text?e.innerHTML=this._data.text:this.readOnly&&(e.innerHTML=`<br>`),this.readOnly||(e.contentEditable=`true`,e.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(e,this.api.i18n.t(na),`data-blok-placeholder-active`)),e}render(){return this._element||(this._element=this.drawView()),this._element}setReadOnly(e){this._element&&(this.readOnly=e,e?(this._element.contentEditable=`false`,this._element.removeEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null),u(this._element)&&(this._element.innerHTML=`<br>`)):(this._element.contentEditable=`true`,this._element.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(this._element,this.api.i18n.t(na),`data-blok-placeholder-active`),this._element.innerHTML===`<br>`&&(this._element.innerHTML=``)))}save(e){return{text:a(e.innerHTML),size:this._data.size}}validate(e){return e.text.trim()!==``}merge(e){if(!this._element)return;this._data.text+=e.text;let t=document.createElement(`div`);t.innerHTML=e.text.trim();let n=document.createDocumentFragment();n.append(...Array.from(t.childNodes)),this._element.appendChild(n),this._element.normalize()}renderSettings(){return[{icon:t.Wt,title:this.api.i18n.t(`tools.quote.size`),name:`quote-size`,children:{items:[{icon:t.Wt,title:this.api.i18n.t(`tools.quote.defaultSize`),onActivate:()=>this.setSize(`default`),closeOnActivate:!0,isActive:this._data.size===`default`},{icon:t.Wt,title:this.api.i18n.t(`tools.quote.largeSize`),onActivate:()=>this.setSize(`large`),closeOnActivate:!0,isActive:this._data.size===`large`}]}}]}setSize(e){this._data.size=e,this._element&&(this._element.className=r.n(this.api.styles.block,ra,c,e===`large`?ia:``))}onPaste(e){let t=e.detail;`data`in t&&(this._data={text:t.data.innerHTML,size:this._data.size},this._element&&(this._element.innerHTML=this._data.text||``))}static get toolbox(){return{icon:t.Wt,titleKey:`quote`,shortcut:`"`,searchTerms:[`quote`,`blockquote`,`citation`],searchTermKeys:[`quote`,`blockquote`,`citation`]}}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,b:!0,i:!0,a:!0,mark:{style:!0}}}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`BLOCKQUOTE`]}}},oa=`tools.code.language`,sa=`tools.code.copied`,ca=`tools.code.copyCode`,la=`tools.code.searchLanguage`,ua=`plain text`,da=[{id:`plain text`,name:`Plain Text`},{id:`javascript`,name:`JavaScript`},{id:`typescript`,name:`TypeScript`},{id:`python`,name:`Python`},{id:`java`,name:`Java`},{id:`c`,name:`C`},{id:`cpp`,name:`C++`},{id:`csharp`,name:`C#`},{id:`go`,name:`Go`},{id:`rust`,name:`Rust`},{id:`ruby`,name:`Ruby`},{id:`php`,name:`PHP`},{id:`swift`,name:`Swift`},{id:`kotlin`,name:`Kotlin`},{id:`latex`,name:`LaTeX`},{id:`mermaid`,name:`Mermaid`},{id:`sql`,name:`SQL`},{id:`html`,name:`HTML`},{id:`css`,name:`CSS`},{id:`json`,name:`JSON`},{id:`yaml`,name:`YAML`},{id:`markdown`,name:`Markdown`},{id:`bash`,name:`Bash`},{id:`shell`,name:`Shell`},{id:`dockerfile`,name:`Dockerfile`},{id:`xml`,name:`XML`},{id:`graphql`,name:`GraphQL`},{id:`r`,name:`R`},{id:`scala`,name:`Scala`},{id:`dart`,name:`Dart`},{id:`lua`,name:`Lua`}],fa=`group/code flex flex-col rounded-xl border border-border-secondary bg-bg-secondary overflow-hidden my-2`,pa=`flex items-center gap-1 px-3 py-1.5 text-xs text-gray-text`,ma=`inline-flex items-center px-1.5 py-0.5 rounded cursor-pointer bg-transparent border-0 text-xs text-gray-text font-medium transition-colors can-hover:hover:bg-item-hover-bg select-none`,ha=`flex items-center gap-1 opacity-0 group-hover/code:opacity-100 transition-opacity`,ga=`p-1 rounded cursor-pointer bg-transparent border-0 text-gray-text transition-colors can-hover:hover:bg-item-hover-bg flex items-center justify-center`,_a=`p-1.5 rounded-lg cursor-pointer bg-transparent border-0 text-gray-text transition-colors can-hover:hover:bg-item-hover-bg flex items-center justify-center`,va=`block px-4 py-3 font-mono text-sm leading-relaxed outline-hidden whitespace-pre-wrap overflow-x-auto min-h-[1.5em] caret-text-primary`,ya=`text-xs text-gray-text font-medium select-none`,ba=new Set([`latex`,`mermaid`]),xa=`tools.code.codeTab`,Sa=`tools.code.previewTab`,Ca=`px-4 py-3 overflow-x-auto min-h-[1.5em] flex justify-center`,wa=`tools.code.sideBySide`,Ta=`flex items-center rounded-lg border border-border-secondary p-0.5 gap-0.5`,Ea=`p-1 rounded cursor-pointer bg-transparent border-0 text-gray-text transition-colors flex items-center justify-center`,Da=`p-1 rounded cursor-pointer bg-item-hover-bg border-0 text-primary transition-colors flex items-center justify-center`,Oa=`p-[6px] rounded cursor-pointer bg-transparent border-0 text-gray-text transition-colors flex items-center justify-center`,ka=`p-[6px] rounded cursor-pointer bg-item-hover-bg border-0 text-primary transition-colors flex items-center justify-center`,Aa=`flex flex-col overflow-hidden`,ja=`flex flex-row overflow-hidden`,Ma=`flex-1 min-w-0 overflow-hidden`,Na=new Set(da.map(e=>e.id).filter(e=>e!==ua)),Pa=`flex overflow-hidden`,Fa=`select-none text-right pl-4 pr-3 py-3 font-mono text-sm leading-relaxed text-gray-text/40 shrink-0`,Ia=`leading-relaxed cursor-text`;function La(e){let n=document.createElement(`div`);n.className=Ta,n.setAttribute(`role`,`group`),n.setAttribute(`data-blok-testid`,`code-view-mode`);let r=[{mode:`code`,icon:t.z,label:e.code},{mode:`preview`,icon:t.Ut,label:e.preview},{mode:`split`,icon:t.Yt,label:e.split}];for(let{mode:e,icon:t,label:i}of r){let r=document.createElement(`button`),a=e===`preview`;r.type=`button`,r.className=a?Oa:Ea,r.innerHTML=t,r.setAttribute(`aria-label`,i),r.setAttribute(`aria-pressed`,`false`),r.setAttribute(`data-blok-testid`,`code-mode-${e}`),r.setAttribute(`data-mode`,e),n.appendChild(r)}let i=document.createElement(`div`);i.className=Ca,i.setAttribute(`data-blok-testid`,`code-preview`);let a=document.createElement(`div`);return a.className=Aa,a.setAttribute(`data-blok-testid`,`code-split-container`),{viewModeContainer:n,previewElement:i,splitContainer:a}}function Ra(e,t){let n=Array.from(e.querySelectorAll(`[data-mode]`));for(let e of n){let n=e.getAttribute(`data-mode`)===t,r=e.getAttribute(`data-mode`)===`preview`;e.setAttribute(`aria-pressed`,String(n)),r?e.className=n?ka:Oa:e.className=n?Da:Ea}}function za(e){var n,r,i;let{code:a,languageName:o,readOnly:s,copyLabel:c,previewable:l,viewModeLabels:u}=e,d=document.createElement(`div`);d.className=fa;let f=document.createElement(`div`);f.className=pa;let p=document.createElement(`button`);p.type=`button`,p.className=ma,p.setAttribute(`aria-haspopup`,`listbox`),p.setAttribute(`data-blok-testid`,`code-language-btn`);let m=document.createElement(`span`);m.textContent=o,p.appendChild(m);let h=document.createElement(`span`);h.className=`inline-flex items-center ml-0.5 -mr-0.5`,h.innerHTML=t.F,p.appendChild(h);let g=document.createElement(`div`);g.className=`flex-1`;let _=!s&&u?La(u):null,v=(n=_==null?void 0:_.viewModeContainer)==null?null:n,y=(r=_==null?void 0:_.previewElement)==null?null:r,b=(i=_==null?void 0:_.splitContainer)==null?null:i;v&&(v.hidden=!l);let x=document.createElement(`button`);x.type=`button`,x.className=l?_a:ga,x.innerHTML=t.H,x.setAttribute(`aria-label`,c),x.setAttribute(`data-blok-testid`,`code-copy-btn`);let S=document.createElement(`code`);S.className=va,S.setAttribute(`data-blok-testid`,`code-content`),a&&(S.textContent=a),s||(S.setAttribute(`contenteditable`,`plaintext-only`),S.setAttribute(`spellcheck`,`false`));let C=document.createElement(`div`);C.className=Fa,C.setAttribute(`aria-hidden`,`true`),C.setAttribute(`data-blok-testid`,`code-gutter`);let w=a?a.split(`
2
+ `).length:1;Array.from({length:w},(e,t)=>{let n=document.createElement(`div`);n.className=Ia,n.textContent=String(t+1),n.setAttribute(`data-line-index`,String(t)),C.appendChild(n)}),f.appendChild(p),f.appendChild(g);let T=document.createElement(`div`);T.className=ha,v&&T.appendChild(v),T.appendChild(x),f.appendChild(T);let E=document.createElement(`pre`);E.className=`flex-1 min-w-0`,E.appendChild(S);let D=document.createElement(`div`);if(D.className=Pa,D.appendChild(C),D.appendChild(E),d.appendChild(f),b&&y){let e=document.createElement(`div`);e.className=Ma,e.appendChild(D);let t=document.createElement(`div`);t.className=Ma,t.appendChild(y),b.appendChild(e),b.appendChild(t),d.appendChild(b)}else d.appendChild(D);return{wrapper:d,languageButton:p,copyButton:x,preElement:E,codeElement:S,gutterElement:C,viewModeContainer:v,previewElement:y,splitContainer:b}}function Ba(e,t,n){return e.key===`Enter`&&e.shiftKey?(n(),!0):e.key===`Enter`?(Ha(t),!0):e.key===`Tab`&&!e.shiftKey?(Ga(),!0):e.key===`Tab`&&e.shiftKey?(qa(t),!0):!1}var Va={"{":`}`,"(":`)`,"[":`]`};function Ha(e){var t;let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0),i=Wa(e,r.startContainer,r.startOffset),a=Wa(e,r.endContainer,r.endOffset),o=(t=e.textContent)==null?``:t,s=o.substring(0,i),c=o.substring(a),l=s.lastIndexOf(`
3
+ `)+1,u=s.substring(l).match(/^[ \t]*/),d=u?u[0]:``,f=Va[s.length>0?s.charAt(s.length-1):``],p=c.charAt(0),{inserted:m,caretDelta:h}=Ua({indent:d,afterOpener:f!==void 0,betweenMatchedPair:f!==void 0&&p===f});for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(s+m+c)),Ja(e,i+h)}function Ua(e){let{indent:t,afterOpener:n,betweenMatchedPair:r}=e;return r?{inserted:`\n${t} \n${t}`,caretDelta:1+t.length+2}:n?{inserted:`\n${t} `,caretDelta:1+t.length+2}:{inserted:`\n${t}`,caretDelta:1+t.length}}function Wa(e,t,n){let r=document.createRange();return r.selectNodeContents(e),r.setEnd(t,n),r.toString().length}function Ga(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);t.deleteContents();let n=document.createTextNode(` `);t.insertNode(n),t.setStartAfter(n),t.collapse(!0),e.removeAllRanges(),e.addRange(t)}function Ka(e){let t=Math.min(2,e.length),n=e.substring(0,t).match(/^ */);return n?n[0].length:0}function qa(e){var t;let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0),i=(t=e.textContent)==null?``:t,a=r.cloneRange();a.selectNodeContents(e),a.setEnd(r.startContainer,r.startOffset);let o=a.toString().length,s=i.lastIndexOf(`
4
+ `,o-1)+1,c=Ka(i.substring(s));if(c===0)return;let l=i.substring(0,s)+i.substring(s+c);for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(l)),Ja(e,Math.max(s,o-c))}function Ja(e,t){let n=window.getSelection();if(!n)return;let r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),i=e=>{var a;let o=r.nextNode();if(!o)return;let s=((a=o.textContent)==null?``:a).length;if(e+s>=t){let r=document.createRange();r.setStart(o,t-e),r.collapse(!0),n.removeAllRanges(),n.addRange(r);return}i(e+s)};i(0)}var Ya={katexPromise:null,cssInjected:!1};function Xa(){if(Ya.cssInjected)return;Ya.cssInjected=!0;let e=document.createElement(`link`);e.rel=`stylesheet`,e.setAttribute(`data-katex-css`,``),e.href=`https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css`,document.head.appendChild(e)}async function Za(){return Ya.katexPromise||(Ya.katexPromise=Promise.resolve().then(()=>require(`./katex-D_RH6O9V.cjs`)).then(e=>e.n).then(e=>e.default)),Ya.katexPromise}async function Qa(e){Xa();try{return(await Za()).renderToString(e,{throwOnError:!1,displayMode:!0})}catch(e){return`<span class="text-red-500 text-sm">${e instanceof Error?e.message:`Unknown error`}</span>`}}var $a={mermaidPromise:null,initialized:!1};async function eo(){$a.mermaidPromise||($a.mermaidPromise=Promise.resolve().then(()=>require(`./mermaid.core-C66G0J-z.cjs`)).then(e=>e.default));let e=await $a.mermaidPromise;return $a.initialized||($a.initialized=!0,e.initialize({startOnLoad:!1,securityLevel:`strict`})),e}async function to(e){try{let t=await eo();if(await t.parse(e,{suppressErrors:!0})===!1)return`<span class="text-red-500 text-sm">Invalid Mermaid syntax</span>`;let n=`mermaid-${crypto.randomUUID()}`;return(await t.render(n,e)).svg}catch(e){return`<span class="text-red-500 text-sm">${e instanceof Error?e.message:`Unknown error`}</span>`}}var no=e.t(((e,t)=>{var n=function(e){var t=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,n=0,r={},i={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function e(t){return t instanceof a?new a(t.type,e(t.content),t.alias):Array.isArray(t)?t.map(e):t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/\u00a0/g,` `)},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,`__id`,{value:++n}),e.__id},clone:function e(t,n){n=n||{};var r,a;switch(i.util.type(t)){case`Object`:if(a=i.util.objId(t),n[a])return n[a];for(var o in r={},n[a]=r,t)t.hasOwnProperty(o)&&(r[o]=e(t[o],n));return r;case`Array`:return a=i.util.objId(t),n[a]?n[a]:(r=[],n[a]=r,t.forEach(function(t,i){r[i]=e(t,n)}),r);default:return t}},getLanguage:function(e){for(;e;){var n=t.exec(e.className);if(n)return n[1].toLowerCase();e=e.parentElement}return`none`},setLanguage:function(e,n){e.className=e.className.replace(RegExp(t,`gi`),``),e.classList.add(`language-`+n)},currentScript:function(){if(typeof document>`u`)return null;if(document.currentScript&&document.currentScript.tagName===`SCRIPT`)return document.currentScript;try{throw Error()}catch(r){var e=(/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(r.stack)||[])[1];if(e){var t=document.getElementsByTagName(`script`);for(var n in t)if(t[n].src==e)return t[n]}return null}},isActive:function(e,t,n){for(var r=`no-`+t;e;){var i=e.classList;if(i.contains(t))return!0;if(i.contains(r))return!1;e=e.parentElement}return!!n}},languages:{plain:r,plaintext:r,text:r,txt:r,extend:function(e,t){var n=i.util.clone(i.languages[e]);for(var r in t)n[r]=t[r];return n},insertBefore:function(e,t,n,r){r=r||i.languages;var a=r[e],o={};for(var s in a)if(a.hasOwnProperty(s)){if(s==t)for(var c in n)n.hasOwnProperty(c)&&(o[c]=n[c]);n.hasOwnProperty(s)||(o[s]=a[s])}var l=r[e];return r[e]=o,i.languages.DFS(i.languages,function(t,n){n===l&&t!=e&&(this[t]=o)}),o},DFS:function e(t,n,r,a){a=a||{};var o=i.util.objId;for(var s in t)if(t.hasOwnProperty(s)){n.call(t,s,t[s],r||s);var c=t[s],l=i.util.type(c);l===`Object`&&!a[o(c)]?(a[o(c)]=!0,e(c,n,null,a)):l===`Array`&&!a[o(c)]&&(a[o(c)]=!0,e(c,n,s,a))}}},plugins:{},highlightAll:function(e,t){i.highlightAllUnder(document,e,t)},highlightAllUnder:function(e,t,n){var r={callback:n,container:e,selector:`code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code`};i.hooks.run(`before-highlightall`,r),r.elements=Array.prototype.slice.apply(r.container.querySelectorAll(r.selector)),i.hooks.run(`before-all-elements-highlight`,r);for(var a=0,o;o=r.elements[a++];)i.highlightElement(o,t===!0,r.callback)},highlightElement:function(t,n,r){var a=i.util.getLanguage(t),o=i.languages[a];i.util.setLanguage(t,a);var s=t.parentElement;s&&s.nodeName.toLowerCase()===`pre`&&i.util.setLanguage(s,a);var c={element:t,language:a,grammar:o,code:t.textContent};function l(e){c.highlightedCode=e,i.hooks.run(`before-insert`,c),c.element.innerHTML=c.highlightedCode,i.hooks.run(`after-highlight`,c),i.hooks.run(`complete`,c),r&&r.call(c.element)}if(i.hooks.run(`before-sanity-check`,c),s=c.element.parentElement,s&&s.nodeName.toLowerCase()===`pre`&&!s.hasAttribute(`tabindex`)&&s.setAttribute(`tabindex`,`0`),!c.code){i.hooks.run(`complete`,c),r&&r.call(c.element);return}if(i.hooks.run(`before-highlight`,c),!c.grammar){l(i.util.encode(c.code));return}if(n&&e.Worker){var u=new Worker(i.filename);u.onmessage=function(e){l(e.data)},u.postMessage(JSON.stringify({language:c.language,code:c.code,immediateClose:!0}))}else l(i.highlight(c.code,c.grammar,c.language))},highlight:function(e,t,n){var r={code:e,grammar:t,language:n};if(i.hooks.run(`before-tokenize`,r),!r.grammar)throw Error(`The language "`+r.language+`" has no grammar.`);return r.tokens=i.tokenize(r.code,r.grammar),i.hooks.run(`after-tokenize`,r),a.stringify(i.util.encode(r.tokens),r.language)},tokenize:function(e,t){var n=t.rest;if(n){for(var r in n)t[r]=n[r];delete t.rest}var i=new c;return l(i,i.head,e),s(e,i,t,i.head,0),d(i)},hooks:{all:{},add:function(e,t){var n=i.hooks.all;n[e]=n[e]||[],n[e].push(t)},run:function(e,t){var n=i.hooks.all[e];if(!(!n||!n.length))for(var r=0,a;a=n[r++];)a(t)}},Token:a};e.Prism=i;function a(e,t,n,r){this.type=e,this.content=t,this.alias=n,this.length=(r||``).length|0}a.stringify=function e(t,n){if(typeof t==`string`)return t;if(Array.isArray(t)){var r=``;return t.forEach(function(t){r+=e(t,n)}),r}var a={type:t.type,content:e(t.content,n),tag:`span`,classes:[`token`,t.type],attributes:{},language:n},o=t.alias;o&&(Array.isArray(o)?Array.prototype.push.apply(a.classes,o):a.classes.push(o)),i.hooks.run(`wrap`,a);var s=``;for(var c in a.attributes)s+=` `+c+`="`+(a.attributes[c]||``).replace(/"/g,`&quot;`)+`"`;return`<`+a.tag+` class="`+a.classes.join(` `)+`"`+s+`>`+a.content+`</`+a.tag+`>`};function o(e,t,n,r){e.lastIndex=t;var i=e.exec(n);if(i&&r&&i[1]){var a=i[1].length;i.index+=a,i[0]=i[0].slice(a)}return i}function s(e,t,n,r,c,d){for(var f in n)if(!(!n.hasOwnProperty(f)||!n[f])){var p=n[f];p=Array.isArray(p)?p:[p];for(var m=0;m<p.length;++m){if(d&&d.cause==f+`,`+m)return;var h=p[m],g=h.inside,_=!!h.lookbehind,v=!!h.greedy,y=h.alias;if(v&&!h.pattern.global){var b=h.pattern.toString().match(/[imsuy]*$/)[0];h.pattern=RegExp(h.pattern.source,b+`g`)}for(var x=h.pattern||h,S=r.next,C=c;S!==t.tail&&!(d&&C>=d.reach);C+=S.value.length,S=S.next){var w=S.value;if(t.length>e.length)return;if(!(w instanceof a)){var T=1,E;if(v){if(E=o(x,C,e,_),!E||E.index>=e.length)break;var D=E.index,O=E.index+E[0].length,k=C;for(k+=S.value.length;D>=k;)S=S.next,k+=S.value.length;if(k-=S.value.length,C=k,S.value instanceof a)continue;for(var A=S;A!==t.tail&&(k<O||typeof A.value==`string`);A=A.next)T++,k+=A.value.length;T--,w=e.slice(C,k),E.index-=C}else if(E=o(x,0,w,_),!E)continue;var D=E.index,j=E[0],M=w.slice(0,D),N=w.slice(D+j.length),ee=C+w.length;d&&ee>d.reach&&(d.reach=ee);var te=S.prev;M&&(te=l(t,te,M),C+=M.length),u(t,te,T);var ne=new a(f,g?i.tokenize(j,g):j,y,j);if(S=l(t,te,ne),N&&l(t,S,N),T>1){var re={cause:f+`,`+m,reach:ee};s(e,t,n,S.prev,C,re),d&&re.reach>d.reach&&(d.reach=re.reach)}}}}}}function c(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0}function l(e,t,n){var r=t.next,i={value:n,prev:t,next:r};return t.next=i,r.prev=i,e.length++,i}function u(e,t,n){for(var r=t.next,i=0;i<n&&r!==e.tail;i++)r=r.next;t.next=r,r.prev=t,e.length-=i}function d(e){for(var t=[],n=e.head.next;n!==e.tail;)t.push(n.value),n=n.next;return t}if(!e.document)return e.addEventListener&&(i.disableWorkerMessageHandler||e.addEventListener(`message`,function(t){var n=JSON.parse(t.data),r=n.language,a=n.code,o=n.immediateClose;e.postMessage(i.highlight(a,i.languages[r],r)),o&&e.close()},!1)),i;var f=i.util.currentScript();f&&(i.filename=f.src,f.hasAttribute(`data-manual`)&&(i.manual=!0));function p(){i.manual||i.highlightAll()}if(!i.manual){var m=document.readyState;m===`loading`||m===`interactive`&&f&&f.defer?document.addEventListener(`DOMContentLoaded`,p):window.requestAnimationFrame?window.requestAnimationFrame(p):window.setTimeout(p,16)}return i}(typeof window<`u`?window:typeof WorkerGlobalScope<`u`&&self instanceof WorkerGlobalScope?self:{});t!==void 0&&t.exports&&(t.exports=n),typeof global<`u`&&(global.Prism=n),n.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:`attr-equals`},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:`named-entity`},/&#x?[\da-f]{1,8};/i]},n.languages.markup.tag.inside[`attr-value`].inside.entity=n.languages.markup.entity,n.languages.markup.doctype.inside[`internal-subset`].inside=n.languages.markup,n.hooks.add(`wrap`,function(e){e.type===`entity`&&(e.attributes.title=e.content.replace(/&amp;/,`&`))}),Object.defineProperty(n.languages.markup.tag,`addInlined`,{value:function(e,t){var r={};r[`language-`+t]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:n.languages[t]},r.cdata=/^<!\[CDATA\[|\]\]>$/i;var i={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:r}};i[`language-`+t]={pattern:/[\s\S]+/,inside:n.languages[t]};var a={};a[e]={pattern:RegExp(`(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[\\s\\S])*?(?=<\\/__>)`.replace(/__/g,function(){return e}),`i`),lookbehind:!0,greedy:!0,inside:i},n.languages.insertBefore(`markup`,`cdata`,a)}}),Object.defineProperty(n.languages.markup.tag,`addAttribute`,{value:function(e,t){n.languages.markup.tag.inside[`special-attr`].push({pattern:RegExp(`(^|["'\\s])(?:`+e+`)\\s*=\\s*(?:"[^"]*"|'[^']*'|[^\\s'">=]+(?=[\\s>]))`,`i`),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,`language-`+t],inside:n.languages[t]},punctuation:[{pattern:/^=/,alias:`attr-equals`},/"|'/]}}}})}}),n.languages.html=n.languages.markup,n.languages.mathml=n.languages.markup,n.languages.svg=n.languages.markup,n.languages.xml=n.languages.extend(`markup`,{}),n.languages.ssml=n.languages.xml,n.languages.atom=n.languages.xml,n.languages.rss=n.languages.xml,(function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp(`@[\\w-](?:[^;{\\s"']|\\s+(?!\\s)|`+t.source+`)*?(?:;|(?=\\s*\\{))`),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:`selector`},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp(`\\burl\\((?:`+t.source+`|(?:[^\\\\\\r\\n()"']|\\\\[\\s\\S])*)\\)`,`i`),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp(`^`+t.source+`$`),alias:`url`}}},selector:{pattern:RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|`+t.source+`)*(?=\\s*\\{)`),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined(`style`,`css`),n.tag.addAttribute(`style`,`css`))})(n),n.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/},n.languages.javascript=n.languages.extend(`clike`,{"class-name":[n.languages.clike[`class-name`],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(`(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])`),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),n.languages.javascript[`class-name`][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,n.languages.insertBefore(`javascript`,`keyword`,{regex:{pattern:RegExp(`((?:^|[^$\\w\\xA0-\\uFFFF."'\\])\\s]|\\b(?:return|yield))\\s*)\\/(?:(?:\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/)*(?:$|[\\r\\n,.;:})\\]]|\\/\\/))`),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:`language-regex`,inside:n.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:`function`},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:n.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:n.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:n.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:n.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),n.languages.insertBefore(`javascript`,`string`,{hashbang:{pattern:/^#!.*/,greedy:!0,alias:`comment`},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:`string`},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:`punctuation`},rest:n.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:`property`}}),n.languages.insertBefore(`javascript`,`operator`,{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:`property`}}),n.languages.markup&&(n.languages.markup.tag.addInlined(`script`,`javascript`),n.languages.markup.tag.addAttribute(`on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)`,`javascript`)),n.languages.js=n.languages.javascript,(function(){if(n===void 0||typeof document>`u`)return;Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector);var e=`Loading…`,t=function(e,t){return`✖ Error `+e+` while fetching file: `+t},r=`✖ Error: File does not exist or is empty`,i={js:`javascript`,py:`python`,rb:`ruby`,ps1:`powershell`,psm1:`powershell`,sh:`bash`,bat:`batch`,h:`c`,tex:`latex`},a=`data-src-status`,o=`loading`,s=`loaded`,c=`failed`,l=`pre[data-src]:not([`+a+`="`+s+`"]):not([`+a+`="`+o+`"])`;function u(e,n,i){var a=new XMLHttpRequest;a.open(`GET`,e,!0),a.onreadystatechange=function(){a.readyState==4&&(a.status<400&&a.responseText?n(a.responseText):a.status>=400?i(t(a.status,a.statusText)):i(r))},a.send(null)}function d(e){var t=/^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(e||``);if(t){var n=Number(t[1]),r=t[2],i=t[3];return r?i?[n,Number(i)]:[n,void 0]:[n,n]}}n.hooks.add(`before-highlightall`,function(e){e.selector+=`, `+l}),n.hooks.add(`before-sanity-check`,function(t){var r=t.element;if(r.matches(l)){t.code=``,r.setAttribute(a,o);var f=r.appendChild(document.createElement(`CODE`));f.textContent=e;var p=r.getAttribute(`data-src`),m=t.language;if(m===`none`){var h=(/\.(\w+)$/.exec(p)||[,`none`])[1];m=i[h]||h}n.util.setLanguage(f,m),n.util.setLanguage(r,m);var g=n.plugins.autoloader;g&&g.loadLanguages(m),u(p,function(e){r.setAttribute(a,s);var t=d(r.getAttribute(`data-range`));if(t){var i=e.split(/\r\n?|\n/g),o=t[0],c=t[1]==null?i.length:t[1];o<0&&(o+=i.length),o=Math.max(0,Math.min(o-1,i.length)),c<0&&(c+=i.length),c=Math.max(0,Math.min(c,i.length)),e=i.slice(o,c).join(`
5
+ `),r.hasAttribute(`data-start`)||r.setAttribute(`data-start`,String(o+1))}f.textContent=e,n.highlightElement(f)},function(e){r.setAttribute(a,c),f.textContent=e})}}),n.plugins.fileHighlight={highlight:function(e){for(var t=(e||document).querySelectorAll(l),r=0,i;i=t[r++];)n.highlightElement(i)}};var f=!1;n.fileHighlight=function(){f||(console.warn("Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead."),f=!0),n.plugins.fileHighlight.highlight.apply(this,arguments)}})()})),ro=e.o(no());function io(){ro.default.languages.mermaid||(ro.default.languages.mermaid={directive:{pattern:/%%\{[\s\S]*?\}%%/,greedy:!0},comment:{pattern:/%%[^\n]*/,greedy:!0},"edge-label":{pattern:/\|[^|\n]*\|/,greedy:!0,inside:{"edge-delimiter":/^\||\|$/,"edge-label":/[^|]+/}},"node-definition":{pattern:/(?:\(\[|\[\[|\[\(|\[|\(+|>|\{|\(\()(?:[^\[\]{}()\n])*(?:\]\)|\]\]|\)\]|\]|\)+|\}|\)\))/,greedy:!0,inside:{"node-bracket":/^\(?[\[{(>]|[\]})]\)?$/,string:/[^\[\]{}()\n]+/}},"diagram-name":/^\s*(?:flowchart|graph|sequenceDiagram|classDiagram|erDiagram|stateDiagram(?:-v2)?|gitGraph|pie(?:\s+title)?|mindmap|timeline|quadrantChart|requirementDiagram|xychart-beta|C4Context|C4Container|C4Component)\b/m,keyword:/\b(?:TD|TB|LR|RL|BT|subgraph|end|direction|participant|actor|as|activate|deactivate|loop|alt|else|opt|par|and|rect|critical|note|over|title|section|classDef|class|linkStyle|style|click|left of|right of)\b/,operator:/[xo<]?(?:={2,}|(?:-\.{1,3}|-{2,5}))(?:[xo>]?>{0,2})|~{3}/,variable:/\b(?!(?:TD|TB|LR|RL|BT|end|subgraph|direction|participant|actor|as|activate|deactivate|loop|alt|else|opt|par|and|rect|critical|note|over|title|section|classDef|class|linkStyle|style|click)\b)[-\w]+\b/})}var ao={javascript:{grammar:`javascript`,importer:()=>Promise.resolve().then(()=>require(`./prism-javascript-UQPp4ffL.cjs`))},typescript:{grammar:`typescript`,importer:()=>Promise.resolve().then(()=>require(`./prism-typescript-Cuqi9QKv.cjs`))},python:{grammar:`python`,importer:()=>Promise.resolve().then(()=>require(`./prism-python-vAqxHcox.cjs`))},java:{grammar:`java`,importer:()=>Promise.resolve().then(()=>require(`./prism-java-DQn4zrh0.cjs`))},c:{grammar:`c`,importer:()=>Promise.resolve().then(()=>require(`./prism-c-1g9CdJOp.cjs`))},cpp:{grammar:`cpp`,importer:()=>Promise.resolve().then(()=>require(`./prism-cpp-CORR584T.cjs`))},csharp:{grammar:`csharp`,importer:()=>Promise.resolve().then(()=>require(`./prism-csharp-BqZp_TTb.cjs`))},go:{grammar:`go`,importer:()=>Promise.resolve().then(()=>require(`./prism-go-DsEyoP6D.cjs`))},rust:{grammar:`rust`,importer:()=>Promise.resolve().then(()=>require(`./prism-rust-C65Pn3Oc.cjs`))},ruby:{grammar:`ruby`,importer:()=>Promise.resolve().then(()=>require(`./prism-ruby-D7wGSPCx.cjs`))},php:{grammar:`php`,prereqs:[`markup`,`markup-templating`],importer:()=>Promise.resolve().then(()=>require(`./prism-php-D8NgAYtH.cjs`))},swift:{grammar:`swift`,importer:()=>Promise.resolve().then(()=>require(`./prism-swift-2HH6IALG.cjs`))},kotlin:{grammar:`kotlin`,importer:()=>Promise.resolve().then(()=>require(`./prism-kotlin-DmCIViWe.cjs`))},sql:{grammar:`sql`,importer:()=>Promise.resolve().then(()=>require(`./prism-sql-DHhl_Wd1.cjs`))},html:{grammar:`markup`,importer:()=>Promise.resolve().then(()=>require(`./prism-markup-OdaHxDBn.cjs`))},css:{grammar:`css`,importer:()=>Promise.resolve().then(()=>require(`./prism-css-DmF38Kcs.cjs`))},json:{grammar:`json`,importer:()=>Promise.resolve().then(()=>require(`./prism-json-B-63BF6R.cjs`))},yaml:{grammar:`yaml`,importer:()=>Promise.resolve().then(()=>require(`./prism-yaml-BT2oArqa.cjs`))},markdown:{grammar:`markdown`,importer:()=>Promise.resolve().then(()=>require(`./prism-markdown-BY8dZr_8.cjs`))},bash:{grammar:`bash`,importer:()=>Promise.resolve().then(()=>require(`./prism-bash-OGjZLOVe.cjs`))},shell:{grammar:`bash`,importer:()=>Promise.resolve().then(()=>require(`./prism-bash-OGjZLOVe.cjs`))},dockerfile:{grammar:`docker`,importer:()=>Promise.resolve().then(()=>require(`./prism-docker-BOsXo4aW.cjs`))},xml:{grammar:`markup`,importer:()=>Promise.resolve().then(()=>require(`./prism-markup-OdaHxDBn.cjs`))},graphql:{grammar:`graphql`,importer:()=>Promise.resolve().then(()=>require(`./prism-graphql-DqXh7GRP.cjs`))},r:{grammar:`r`,importer:()=>Promise.resolve().then(()=>require(`./prism-r-BsUW1w_m.cjs`))},scala:{grammar:`scala`,importer:()=>Promise.resolve().then(()=>require(`./prism-scala-DuAsLUh6.cjs`))},dart:{grammar:`dart`,importer:()=>Promise.resolve().then(()=>require(`./prism-dart-CFseeodJ.cjs`))},lua:{grammar:`lua`,importer:()=>Promise.resolve().then(()=>require(`./prism-lua-DyMxrgA_.cjs`))},latex:{grammar:`latex`,importer:()=>Promise.resolve().then(()=>require(`./prism-latex-Bcpg2uQr.cjs`))},mermaid:{grammar:`mermaid`,importer:()=>Promise.resolve(io())}},oo={markup:()=>Promise.resolve().then(()=>require(`./prism-markup-OdaHxDBn.cjs`)),"markup-templating":()=>Promise.resolve().then(()=>require(`./prism-markup-templating-Cnde-rJf.cjs`))},so=new Set;function co(e){return Na.has(e)}async function lo(e){if(so.has(e))return;let t=oo[e];if(t)try{await t(),so.add(e)}catch(t){console.warn(`[blok] Failed to load Prism prerequisite grammar "${e}":`,t)}}async function uo(e){let t=ao[e];if(!t)return!1;let n=t.grammar;if(so.has(n))return!0;if(t.prereqs)for(let e of t.prereqs)await lo(e);try{return await t.importer(),so.add(n),!0}catch(t){return console.warn(`[blok] Failed to load Prism grammar for "${e}":`,t),!1}}async function fo(e,t){if(!co(t))return null;let n=ao[t];if(!n||!await uo(t))return null;let r=ro.default.languages[n.grammar];if(!r)return null;try{return ro.default.highlight(e,r,n.grammar)}catch(e){return console.warn(`[blok] Prism highlight error for "${t}":`,e),null}}var po=null,mo=`
6
+ .blok-code .token.comment,
7
+ .blok-code .token.prolog,
8
+ .blok-code .token.doctype,
9
+ .blok-code .token.cdata { color: #6b7280; }
10
+
11
+ .blok-code .token.keyword,
12
+ .blok-code .token.operator,
13
+ .blok-code .token.important { color: #7c3aed; }
14
+
15
+ .blok-code .token.string,
16
+ .blok-code .token.attr-value,
17
+ .blok-code .token.char,
18
+ .blok-code .token.regex { color: #059669; }
19
+
20
+ .blok-code .token.number,
21
+ .blok-code .token.boolean,
22
+ .blok-code .token.constant,
23
+ .blok-code .token.symbol { color: #d97706; }
24
+
25
+ .blok-code .token.function,
26
+ .blok-code .token.class-name { color: #2563eb; }
27
+
28
+ .blok-code .token.builtin,
29
+ .blok-code .token.tag,
30
+ .blok-code .token.selector { color: #db2777; }
31
+
32
+ .blok-code .token.attr-name,
33
+ .blok-code .token.property,
34
+ .blok-code .token.variable { color: #ea580c; }
35
+
36
+ .blok-code .token.punctuation { color: #374151; }
37
+
38
+ /* Mermaid-specific tokens — scoped to lang-mermaid to avoid polluting other languages.
39
+ * Colors use Atom One Light palette:
40
+ * @hue-1 = #0184bc (cyan)
41
+ * @hue-6-2 = #c18401 (amber/gold — node IDs)
42
+ * @hue-4 = #50a14f (green — edge labels)
43
+ */
44
+ .blok-code.lang-mermaid .token.diagram-name { color: #0184bc; }
45
+ .blok-code.lang-mermaid .token.node-bracket { color: #0184bc; }
46
+ .blok-code.lang-mermaid .token.edge-delimiter { color: #0184bc; }
47
+ .blok-code.lang-mermaid .token.edge-label { color: #50a14f; }
48
+ .blok-code.lang-mermaid .token.variable { color: #c18401; }
49
+ .blok-code.lang-mermaid .token.keyword,
50
+ .blok-code.lang-mermaid .token.operator,
51
+ .blok-code.lang-mermaid .token.string { color: inherit; }
52
+ `,ho=`
53
+ .dark .blok-code .token.comment,
54
+ .dark .blok-code .token.prolog,
55
+ .dark .blok-code .token.doctype,
56
+ .dark .blok-code .token.cdata { color: #9ca3af; }
57
+
58
+ .dark .blok-code .token.keyword,
59
+ .dark .blok-code .token.operator,
60
+ .dark .blok-code .token.important { color: #a78bfa; }
61
+
62
+ .dark .blok-code .token.string,
63
+ .dark .blok-code .token.attr-value,
64
+ .dark .blok-code .token.char,
65
+ .dark .blok-code .token.regex { color: #34d399; }
66
+
67
+ .dark .blok-code .token.number,
68
+ .dark .blok-code .token.boolean,
69
+ .dark .blok-code .token.constant,
70
+ .dark .blok-code .token.symbol { color: #fbbf24; }
71
+
72
+ .dark .blok-code .token.function,
73
+ .dark .blok-code .token.class-name { color: #60a5fa; }
74
+
75
+ .dark .blok-code .token.builtin,
76
+ .dark .blok-code .token.tag,
77
+ .dark .blok-code .token.selector { color: #f472b6; }
78
+
79
+ .dark .blok-code .token.attr-name,
80
+ .dark .blok-code .token.property,
81
+ .dark .blok-code .token.variable { color: #fb923c; }
82
+
83
+ .dark .blok-code .token.punctuation { color: #d1d5db; }
84
+
85
+ /* Mermaid-specific tokens — dark mode.
86
+ * Colors use Atom One Dark palette:
87
+ * @hue-1 = #56b5c2 (cyan)
88
+ * @hue-6-2 = #e4bf7a (amber/yellow — node IDs)
89
+ * @hue-4 = #97c279 (green — edge labels)
90
+ */
91
+ .dark .blok-code.lang-mermaid .token.diagram-name { color: #56b5c2; }
92
+ .dark .blok-code.lang-mermaid .token.node-bracket { color: #56b5c2; }
93
+ .dark .blok-code.lang-mermaid .token.edge-delimiter { color: #56b5c2; }
94
+ .dark .blok-code.lang-mermaid .token.edge-label { color: #97c279; }
95
+ .dark .blok-code.lang-mermaid .token.variable { color: #e4bf7a; }
96
+ .dark .blok-code.lang-mermaid .token.keyword,
97
+ .dark .blok-code.lang-mermaid .token.operator,
98
+ .dark .blok-code.lang-mermaid .token.string { color: inherit; }
99
+ `;function go(){var e;if(po)return;po=new CSSStyleSheet,po.replaceSync(mo+ho);let t=(e=document.adoptedStyleSheets)==null?[]:e;document.adoptedStyleSheets=[...t,po]}function _o(e){let t=window.getSelection();if(!t||t.rangeCount===0)return-1;let n=t.getRangeAt(0).cloneRange();return n.selectNodeContents(e),n.setEnd(t.getRangeAt(0).endContainer,t.getRangeAt(0).endOffset),n.toString().length}function vo(e,t){if(t<0)return;let n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=t,i=null;for(;n.nextNode();){let e=n.currentNode;if(e.length>=r){i=e;break}r-=e.length}if(!i)return;let a=document.createRange();a.setStart(i,r),a.collapse(!0);let o=window.getSelection();o==null||o.removeAllRanges(),o==null||o.addRange(a)}function yo(e,t,n){var r;go();let i=(r=e.textContent)==null?``:r,a=_o(e);return e.classList.add(`blok-code`),n&&e.classList.add(`lang-${n}`),e.innerHTML=t,vo(e,a),()=>{e.innerHTML=i,e.classList.remove(`blok-code`),n&&e.classList.remove(`lang-${n}`)}}function bo(){var e;if(!po)return;let t=(e=document.adoptedStyleSheets)==null?[]:e;document.adoptedStyleSheets=t.filter(e=>e!==po),po=null}var xo=[`javascript`,`typescript`,`python`,`java`,`html`,`css`,`json`,`bash`,`sql`,`rust`,`go`,`cpp`,`yaml`,`markdown`,`php`],So=20,Co=2,wo=.2;async function To(e,t){var n;let r=await fo(e,t);if(!r)return null;let i=(n=r.match(/class="token ([^"]+)"/g))==null?[]:n;if(i.length===0)return null;let a=new Set(i.flatMap(e=>e.slice(13,-1).split(` `)));return a.size<Co?null:a.size/i.length}async function Eo(e){if(e.length<So)return null;let t=(await Promise.all(xo.map(async t=>({lang:t,score:await To(e,t)})))).reduce((e,{lang:t,score:n})=>n===null?e:n>e.score?{lang:t,score:n}:e,{lang:null,score:-1/0});return t.lang===null||t.score<wo?null:t.lang}var Do=1500;function Oo(e,t){var n;let r=((n=e.ownerDocument)==null?document:n).createTreeWalker(e,NodeFilter.SHOW_TEXT),i=n=>{var a,o;let s=r.nextNode();if(!s)return{node:e,offset:0};let c=(a=(o=s.nodeValue)==null?void 0:o.length)==null?0:a;return n+c>=t?{node:s,offset:t-n}:i(n+c)};return i(0)}var ko=class{constructor({data:e,api:t,readOnly:n}){var r,i,a;this._dom=null,this._lineNumbers=!0,this._picker=null,this._viewMode=`preview`,this._previewContainer=null,this._highlightRafId=null,this._detectedLanguage=null,this._detectionTimeoutId=null,this._highlightCleanup=null,this._highlightedLang=null,this.api=t,this.readOnly=n,this._data={code:(r=e==null?void 0:e.code)==null?``:r,language:(i=e==null?void 0:e.language)==null?ua:i,lineNumbers:e==null?void 0:e.lineNumbers},this._lineNumbers=(a=e==null?void 0:e.lineNumbers)==null?!0:a}render(){let e=ba.has(this._data.language),n=za({code:this._data.code,languageName:this.getLanguageName(this._data.language),readOnly:this.readOnly,copyLabel:this.api.i18n.t(ca),previewable:this.readOnly?!1:e,viewModeLabels:this.readOnly?void 0:{code:this.api.i18n.t(xa),preview:this.api.i18n.t(Sa),split:this.api.i18n.t(wa)}});if(this._dom=n,n.gutterElement.hidden=!this._lineNumbers,this.readOnly&&e){let e=document.createElement(`div`);e.className=Ca,e.setAttribute(`data-blok-testid`,`code-preview`),n.wrapper.appendChild(e),n.preElement.hidden=!0,n.gutterElement.hidden=!0,this._previewContainer=e,this.renderPreview()}if(!this.readOnly&&e&&n.previewElement&&(this._viewMode=`preview`,this._previewContainer=n.previewElement,this.applyViewMode(),this.renderPreview()),!this.readOnly&&n.viewModeContainer){let e=Array.from(n.viewModeContainer.querySelectorAll(`[data-mode]`));for(let n of e){var r;t.An(n,(r=n.getAttribute(`aria-label`))==null?``:r,{placement:`bottom`}),n.addEventListener(`click`,()=>{let e=n.getAttribute(`data-mode`);e&&e!==this._viewMode&&this.setViewMode(e)})}}return this.readOnly||(n.gutterElement.addEventListener(`mousedown`,e=>{var t;let n=(t=e.target)==null?void 0:t.closest(`[data-line-index]`);if(!n)return;let r=Number(n.getAttribute(`data-line-index`));e.preventDefault(),this.focusLineEnd(r)}),n.codeElement.addEventListener(`keydown`,e=>{Ba(e,n.codeElement,()=>this.exitBlock())&&(e.preventDefault(),this.syncTrailingBr(),this.updateGutter(),this.scheduleHighlight(),this.scheduleDetection())}),n.codeElement.addEventListener(`input`,()=>{this.syncTrailingBr(),this.updateGutter(),this.scheduleHighlight(),this.scheduleDetection()}),n.codeElement.addEventListener(`paste`,()=>{requestAnimationFrame(()=>{this.syncTrailingBr(),this.updateGutter(),this.scheduleHighlight(),this.scheduleDetection()})})),n.copyButton.addEventListener(`click`,()=>this.copyCode()),t.An(n.copyButton,this.api.i18n.t(ca),{placement:`bottom`}),this.readOnly||(this._picker=this.buildLanguagePicker(n.languageButton,n.wrapper),n.languageButton.addEventListener(`click`,()=>{var e;if((e=this._picker)!=null&&e.isShown)this._picker.hide();else{var t;(t=this._picker)==null||t.show()}})),n.wrapper}getToolbarAnchorElement(){var e;return(e=this._dom)==null?void 0:e.wrapper}rendered(){this.highlightCode()}setViewMode(e){this._viewMode=e,this.applyViewMode(),(e===`preview`||e===`split`)&&this.renderPreview()}applyViewMode(){var e,t;if(!((e=this._dom)!=null&&e.previewElement)||!this._dom.viewModeContainer||!this._dom.splitContainer)return;Ra(this._dom.viewModeContainer,this._viewMode);let n=(t=this._dom.preElement.parentElement)==null?void 0:t.parentElement;switch(this._viewMode){case`code`:this._dom.preElement.hidden=!1,this._dom.gutterElement.hidden=!this._lineNumbers,this._dom.previewElement.hidden=!0,n&&(n.hidden=!1),this._dom.splitContainer.className=Aa;break;case`preview`:this._dom.preElement.hidden=!0,this._dom.gutterElement.hidden=!0,this._dom.previewElement.hidden=!1,n&&(n.hidden=!0),this._dom.splitContainer.className=Aa;break;case`split`:this._dom.preElement.hidden=!1,this._dom.gutterElement.hidden=!this._lineNumbers,this._dom.previewElement.hidden=!1,n&&(n.hidden=!1),this._dom.splitContainer.className=ja;break}}async renderPreview(){var e=this,t,n;let r=e._previewContainer;if(!r)return;let i=(t=(n=e._dom)==null?void 0:n.codeElement.textContent)==null?e._data.code:t;r.innerHTML=e._data.language===`mermaid`?await to(i):await Qa(i)}setReadOnly(e){this.readOnly=e,this._dom&&(e?(this._dom.codeElement.setAttribute(`contenteditable`,`false`),this._dom.codeElement.removeAttribute(`spellcheck`)):(this._dom.codeElement.setAttribute(`contenteditable`,`plaintext-only`),this._dom.codeElement.setAttribute(`spellcheck`,`false`)))}save(e){var t,n;return{code:(t=(n=this._dom)==null?void 0:n.codeElement.textContent)==null?``:t,language:this._data.language,lineNumbers:this._lineNumbers}}setData(e){var t,n,r;let i=this._data.language;return this._data={code:(t=e.code)==null?``:t,language:(n=e.language)==null?ua:n,lineNumbers:e.lineNumbers},this._dom?(this._dom.codeElement.textContent=this._data.code,this.syncTrailingBr(),this._lineNumbers=(r=e.lineNumbers)==null?!0:r,this._dom.gutterElement.hidden=!this._lineNumbers,this.updateGutter(),e.language===i?(this._viewMode===`preview`||this._viewMode===`split`)&&this.renderPreview():this.applyLanguageChange(this._data.language),this.highlightCode(),!0):!0}applyLanguageChange(e){if(!this._dom)return;let t=this._dom.languageButton.querySelector(`span`);t&&(t.textContent=this.getLanguageName(e));let n=ba.has(e);this._dom.viewModeContainer&&(this._dom.viewModeContainer.hidden=!n),n&&this._dom.previewElement?(this._previewContainer=this._dom.previewElement,(this._viewMode===`preview`||this._viewMode===`split`)&&this.renderPreview()):n||(this._previewContainer=null,this._viewMode!==`code`&&(this._viewMode=`code`,this.applyViewMode())),this._picker&&this._picker.destroy(),this._picker=this.buildLanguagePicker(this._dom.languageButton,this._dom.wrapper)}validate(e){return e.code.trim()!==``}merge(e){this._data.code+=`
100
+ `+e.code,this._dom&&(this._dom.codeElement.textContent=this._data.code,this.syncTrailingBr(),this.updateGutter()),this.highlightCode()}renderSettings(){let e=this._data.language,n=this._detectedLanguage,r=n!==null&&n!==e,i=[];if(r){let e=da.find(e=>e.id===n);e&&(i.push({title:e.name,secondaryLabel:`auto`,icon:t.on,onActivate:()=>this.setLanguage(e.id),closeOnActivate:!0,isActive:()=>this._data.language===e.id}),i.push({type:t.Ln.Separator}))}return i.push(...da.map(n=>({title:n.name,trailingIcon:n.id===e?t.P:void 0,onActivate:()=>this.setLanguage(n.id),closeOnActivate:!0}))),[{icon:t.B,title:this.api.i18n.t(oa),name:`code-language`,children:{items:i}}]}onPaste(e){let t=e.detail;if(`data`in t){let e=t.data;if(e instanceof HTMLElement){var n;this._data.code=(n=e.textContent)==null?``:n}else if(typeof e==`string`){let t=e.replace(/^```[^\n]*\n?/,``).replace(/\n?```$/,``);this._data.code=t}}this._dom&&(this._dom.codeElement.textContent=this._data.code,this.syncTrailingBr(),this.updateGutter()),this.highlightCode()}setLanguage(e){this._data.language=e;let t=ba.has(e);if(this._dom){let n=this._dom.languageButton.querySelector(`span`);n&&(n.textContent=this.getLanguageName(e)),this._dom.viewModeContainer&&(this._dom.viewModeContainer.hidden=!t),t&&this._dom.previewElement&&(this._previewContainer=this._dom.previewElement,this._viewMode=`preview`,this.applyViewMode(),this.renderPreview()),t||(this._previewContainer=null,this._viewMode=`code`,this.applyViewMode()),this._picker&&this._picker.destroy(),this._picker=this.buildLanguagePicker(this._dom.languageButton,this._dom.wrapper)}this.highlightCode()}buildLanguagePickerItems(){let e=this._data.language,n=this._detectedLanguage,r=n!==null&&n!==e,i=[];if(r){let e=da.find(e=>e.id===n);e&&(i.push({title:e.name,name:e.id,icon:t.on,toggle:`language`,isActive:()=>this._data.language===e.id,closeOnActivate:!0,onActivate:()=>this.setLanguage(e.id)}),i.push({type:t.Ln.Separator}))}return i.push(...da.map(n=>({title:n.name,name:n.id,trailingIcon:n.id===e?t.P:void 0,toggle:`language`,closeOnActivate:!0,onActivate:()=>this.setLanguage(n.id)}))),i}buildLanguagePicker(e,n){return new t.g({items:this.buildLanguagePickerItems(),trigger:e,leftAlignElement:n,searchable:!0,width:`200px`,messages:{search:this.api.i18n.t(la)}})}getLanguageName(e){let t=da.find(t=>t.id===e);return t?t.name:e}copyCode(){var e,t;let n=(e=(t=this._dom)==null?void 0:t.codeElement.textContent)==null?``:e;navigator.clipboard.writeText(n).then(()=>{if(!this._dom)return;let e=this._dom.copyButton,t=e.innerHTML;e.innerHTML=`<span class="${ya}">${this.api.i18n.t(sa)}</span>`,setTimeout(()=>{e.innerHTML=t},Do)}).catch(()=>{})}updateGutter(){var e;if(!this._dom)return;let t=(e=this._dom.codeElement.textContent)==null?``:e,n=t?t.split(`
101
+ `).length:1,r=this._dom.gutterElement;r.children.length!==n&&(r.innerHTML=``,Array.from({length:n},(e,t)=>{let n=document.createElement(`div`);n.className=Ia,n.textContent=String(t+1),n.setAttribute(`data-line-index`,String(t)),r.appendChild(n)}))}syncTrailingBr(){var e;if(!this._dom)return;let t=this._dom.codeElement,n=(e=t.textContent)==null?``:e,r=t.lastChild instanceof HTMLBRElement;n.endsWith(`
102
+ `)&&!r?t.appendChild(document.createElement(`br`)):!n.endsWith(`
103
+ `)&&r&&t.lastChild.remove()}scheduleHighlight(){this._highlightRafId===null&&(this._highlightRafId=requestAnimationFrame(()=>{this._highlightRafId=null,this.highlightCode()}))}scheduleDetection(){this._detectionTimeoutId!==null&&clearTimeout(this._detectionTimeoutId),this._detectionTimeoutId=setTimeout(()=>{var e,t;this._detectionTimeoutId=null,Eo((e=(t=this._dom)==null?void 0:t.codeElement.textContent)==null?``:e).then(e=>{e!==this._detectedLanguage&&(this._detectedLanguage=e,this._dom&&(this._picker&&this._picker.destroy(),this._picker=this.buildLanguagePicker(this._dom.languageButton,this._dom.wrapper)))})},600)}async highlightCode(){var e=this,t,n;let r=e._data.language;if(!co(r))return;let i=(t=(n=e._dom)==null?void 0:n.codeElement.textContent)==null?``:t;if(!i.trim())return;let a=await fo(i,r);!a||!e._dom||e._dom.codeElement.textContent===i&&(e._highlightCleanup&&e._highlightedLang!==r&&(e._highlightCleanup(),e._highlightCleanup=null),e._highlightCleanup=yo(e._dom.codeElement,a,r),e._highlightedLang=r,e.syncTrailingBr())}focusLineEnd(e){var t;if(!this._dom)return;let n=this._dom.codeElement,r=((t=n.textContent)==null?``:t).split(`
104
+ `),i=Math.max(0,Math.min(e,r.length-1)),a=Oo(n,r.slice(0,i).reduce((e,t)=>e+t.length+1,0)+r[i].length),o=n.ownerDocument.createRange();o.setStart(a.node,a.offset),o.setEnd(a.node,a.offset);let s=n.ownerDocument.getSelection();s&&(s.removeAllRanges(),s.addRange(o)),n.focus({preventScroll:!0})}exitBlock(){let e=this.api.blocks.getCurrentBlockIndex();this.api.blocks.insert(void 0,void 0,void 0,e+1)}removed(){this._highlightCleanup&&(this._highlightCleanup(),this._highlightCleanup=null),this._highlightedLang=null,bo(),this._highlightRafId!==null&&(cancelAnimationFrame(this._highlightRafId),this._highlightRafId=null),this._detectionTimeoutId!==null&&(clearTimeout(this._detectionTimeoutId),this._detectionTimeoutId=null),this._picker&&(this._picker.destroy(),this._picker=null),this._dom=null}static get toolbox(){return{icon:t.B,titleKey:`code`,shortcut:"```",searchTerms:[`code`,`pre`,`snippet`,`program`],searchTermKeys:[`code`,`pre`,`snippet`,`program`]}}static get conversionConfig(){return{export:`code`,import:`code`}}static get sanitize(){return{code:!0}}static get isReadOnlySupported(){return!0}static get enableLineBreaks(){return!0}static get pasteConfig(){return{tags:[`PRE`],patterns:{code:/^```/}}}},Ao=[`image/jpeg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`],jo=10*1024*1024,Mo=`Write a caption…`,No=/^https?:\/\/\S+\.(jpe?g|png|gif|webp|svg)(\?\S*)?$/i;function W(e,t){var n;return e!=null&&e.has(t)?e.t(t):(n=i.n[t])==null?t:n}var Po={"image/jpeg":`JPG`,"image/jpg":`JPG`,"image/png":`PNG`,"image/gif":`GIF`,"image/webp":`WebP`,"image/svg+xml":`SVG`,"image/avif":`AVIF`,"image/heic":`HEIC`,"image/heif":`HEIF`,"image/bmp":`BMP`,"image/tiff":`TIFF`,"image/x-icon":`ICO`};function Fo(e){let t=e.toLowerCase().trim();if(Po[t])return Po[t];let n=t.indexOf(`/`);return(n>=0?t.slice(n+1):t).replace(/^x-/,``).split(`+`)[0].toUpperCase()}function Io(e){let t=new Set,n=[];for(let r of e){let e=Fo(r);t.has(e)||(t.add(e),n.push(e))}return n.join(` · `)}function Lo(e){if(!Number.isFinite(e)||e<=0)return``;if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${Math.round(t)} KB`;let n=t/1024;if(n<1024)return n<10?`${n.toFixed(1)} MB`:`${Math.round(n)} MB`;let r=n/1024;return r<10?`${r.toFixed(1)} GB`:`${Math.round(r)} GB`}function Ro(e){let t=document.createElement(`span`);return t.className=`blok-image-empty__tile`,t.setAttribute(`aria-hidden`,`true`),t.innerHTML=e,t}function zo(){return Math.random().toString(36).slice(2,9)}function Bo(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=`blok-image-empty__tab`,i.id=`blok-image-empty-tab-${zo()}`,i.setAttribute(`data-src`,e),i.setAttribute(`data-tab`,e),i.setAttribute(`role`,`tab`),i.setAttribute(`aria-controls`,n),i.setAttribute(`aria-selected`,r?`true`:`false`),i.tabIndex=r?0:-1,r&&i.setAttribute(`aria-current`,`true`),i.textContent=t,i}function Vo(e){return e instanceof Element?e.closest(`button, a, input, textarea, select, [role="button"], [role="tab"]`)!==null:!1}function Ho(e){var n,r,i,a,o;let s=(n=e.acceptTypes)==null?[...Ao]:n,c=s.join(`,`),l=Io(s),u=e.maxSize===void 0?``:Lo(e.maxSize),d=(r=e.uploadLabel)==null?W(e.i18n,`tools.image.emptyUpload`):r,f=(i=e.embedLabel)==null?W(e.i18n,`tools.image.emptyLink`):i,p=(a=e.embedPlaceholder)==null?W(e.i18n,`tools.image.emptyUrlPlaceholder`):a,m=(o=e.submitLabel)==null?W(e.i18n,`tools.image.emptyInsert`):o,h=W(e.i18n,`tools.image.emptyAddImage`),g=document.createElement(`div`);g.className=`blok-image-empty`,g.setAttribute(`data-blok-image-empty-state`,``);let _=document.createElement(`div`);_.className=`blok-image-empty__card`,_.tabIndex=0,_.setAttribute(`role`,`group`),_.setAttribute(`aria-label`,h);let v=document.createElement(`span`);v.className=`blok-image-empty__label`,v.textContent=h;let y=document.createElement(`div`);y.className=`blok-image-empty__panel`,y.id=`blok-image-empty-panel-${zo()}`,y.setAttribute(`data-panel-host`,``),y.setAttribute(`role`,`tabpanel`);let b=document.createElement(`div`);b.className=`blok-image-empty__tabs`,b.setAttribute(`role`,`tablist`),b.setAttribute(`aria-label`,W(e.i18n,`tools.image.emptySourceAria`));let x=Bo(`upload`,d,y.id,!0),S=Bo(`embed`,f,y.id,!1);b.append(x,S),y.setAttribute(`aria-labelledby`,x.id);let C=[x,S],w=[`upload`,`embed`],T=document.createElement(`div`);T.className=`blok-image-empty__drop-overlay`,T.setAttribute(`aria-hidden`,`true`);let E=document.createElement(`div`);E.className=`blok-image-empty__drop-inner`,E.innerHTML=`<span class="blok-image-empty__drop-icon">${t.D}</span><span>${W(e.i18n,`tools.image.emptyDropToUpload`)}</span>`,T.appendChild(E);let D=document.createElement(`div`);D.className=`blok-image-empty__error`,D.setAttribute(`data-role`,`error`),D.hidden=!0;let O=document.createElement(`input`);O.type=`file`,O.accept=c,O.hidden=!0,O.addEventListener(`change`,()=>{var t;let n=(t=O.files)==null?void 0:t[0];n&&e.onFile(n)});let k=()=>{var n;y.replaceChildren(),y.appendChild(Ro(t.an));let r=document.createElement(`div`);r.className=`blok-image-empty__content`;let i=document.createElement(`div`);i.className=`blok-image-empty__primary`;let a=document.createElement(`button`);a.type=`button`,a.className=`blok-image-empty__choose`,a.setAttribute(`data-action`,`choose-file`),a.innerHTML=`<span class="blok-image-empty__choose-icon">${t.O}</span><span>${W(e.i18n,`tools.image.emptyChooseFile`)}</span>`,a.addEventListener(`click`,e=>{e.stopPropagation(),O.click()});let o=document.createElement(`span`);o.className=`blok-image-empty__hint`,o.textContent=W(e.i18n,`tools.image.emptyOrDropHere`),i.append(a,o);let s=document.createElement(`div`);s.className=`blok-image-empty__meta`;let c=[];l&&c.push(l),u&&c.push((n=e.i18n)!=null&&n.has(`tools.image.emptyMaxSize`)?e.i18n.t(`tools.image.emptyMaxSize`,{size:u}):`max ${u}`),s.textContent=c.join(` · `),r.append(i),c.length&&r.append(s),y.append(r,O)},A=()=>{y.replaceChildren();let n=document.createElement(`div`);n.className=`blok-image-empty__embed-bar`,n.setAttribute(`data-valid`,`false`);let r=document.createElement(`span`);r.className=`blok-image-empty__embed-icon`,r.setAttribute(`aria-hidden`,`true`),r.innerHTML=t.kt;let i=document.createElement(`input`);i.type=`url`,i.className=`blok-image-empty__embed-input`,i.placeholder=p,i.setAttribute(`aria-label`,W(e.i18n,`tools.image.emptyUrlAria`)),i.autocomplete=`off`,i.spellcheck=!1;let a=document.createElement(`button`);a.type=`button`,a.className=`blok-image-empty__embed-submit`,a.setAttribute(`data-action`,`submit-url`);let o=document.createElement(`span`);o.className=`blok-image-empty__embed-submit-label`,o.textContent=m;let s=document.createElement(`kbd`);s.className=`blok-image-empty__embed-kbd`,s.setAttribute(`aria-hidden`,`true`),s.textContent=`↵`,a.append(o,s);let c=e=>{let t=e.trim();if(!t)return!1;try{let e=new URL(t);return e.protocol===`http:`||e.protocol===`https:`}catch(e){return/^[\w-]+(\.[\w-]+)+([/?#].*)?$/i.test(t)}},l=()=>{let e=c(i.value);n.setAttribute(`data-valid`,e?`true`:`false`),a.setAttribute(`aria-disabled`,e?`false`:`true`)},u=()=>{let t=i.value.trim();t&&e.onUrl(t)};a.addEventListener(`click`,e=>{e.stopPropagation(),c(i.value)&&u()}),i.addEventListener(`click`,e=>e.stopPropagation()),i.addEventListener(`input`,l),i.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),c(i.value)&&u())}),n.append(r,i,a),y.appendChild(n),l(),queueMicrotask(()=>i.focus())},j=e=>{let t=C[w.indexOf(e)];for(let e of C){let n=e===t;e.setAttribute(`aria-selected`,n?`true`:`false`),e.tabIndex=n?0:-1,n?e.setAttribute(`aria-current`,`true`):e.removeAttribute(`aria-current`)}y.setAttribute(`aria-labelledby`,t.id),_.setAttribute(`data-active-tab`,e),e===`upload`?k():A()};C.forEach((e,t)=>{e.addEventListener(`click`,n=>{n.stopPropagation(),j(w[t]),e.focus()}),e.addEventListener(`keydown`,e=>{if(e.key===`ArrowRight`||e.key===`ArrowLeft`){e.preventDefault();let n=(t+(e.key===`ArrowRight`?1:-1)+C.length)%C.length;j(w[n]),C[n].focus()}else if(e.key===`Home`)e.preventDefault(),j(w[0]),C[0].focus();else if(e.key===`End`){e.preventDefault();let t=C.length-1;j(w[t]),C[t].focus()}})}),y.addEventListener(`click`,e=>{_.getAttribute(`data-active-tab`)===`upload`&&(Vo(e.target)||O.click())}),_.addEventListener(`keydown`,e=>{e.target===_&&_.getAttribute(`data-active-tab`)===`upload`&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),O.click())}),_.addEventListener(`paste`,t=>{if(_.getAttribute(`data-active-tab`)!==`upload`)return;let n=t.clipboardData;if(n)for(let r of Array.from(n.items)){if(r.kind!==`file`)continue;let n=r.getAsFile();if(n&&s.some(e=>n.type===e||e===n.type)){t.preventDefault(),e.onFile(n);return}}});let M={depth:0};_.addEventListener(`dragenter`,e=>{var t;(t=e.dataTransfer)!=null&&t.types.includes(`Files`)&&(e.preventDefault(),M.depth+=1,_.classList.add(`is-dragover`))}),_.addEventListener(`dragover`,e=>{let t=e.dataTransfer;t!=null&&t.types.includes(`Files`)&&(e.preventDefault(),t.dropEffect=`copy`)}),_.addEventListener(`dragleave`,()=>{M.depth=Math.max(0,M.depth-1),M.depth===0&&_.classList.remove(`is-dragover`)}),_.addEventListener(`drop`,t=>{var n;t.preventDefault(),M.depth=0,_.classList.remove(`is-dragover`);let r=(n=t.dataTransfer)==null||(n=n.files)==null?void 0:n[0];r&&e.onFile(r)});let N=document.createElement(`div`);return N.className=`blok-image-empty__header`,N.append(v,b),_.append(N,y,T),g.append(_,D),j(`upload`),g.setError=e=>{if(!e){D.hidden=!0,D.textContent=``;return}D.hidden=!1,D.textContent=e},g}function Uo(e){var n,r;let i=document.createElement(`div`);i.className=`blok-image-error`,i.setAttribute(`data-role`,`error-state`);let a=document.createElement(`div`);a.className=`blok-image-error__icon`,a.setAttribute(`aria-hidden`,`true`),a.innerHTML=t.xt;let o=document.createElement(`div`);o.className=`blok-image-error__body`;let s=document.createElement(`div`);s.className=`blok-image-error__title`,s.textContent=(n=e.title)==null?W(e.i18n,`tools.image.errorDefaultTitle`):n;let c=document.createElement(`div`);if(c.className=`blok-image-error__msg`,c.textContent=(r=e.message)==null?W(e.i18n,`tools.image.errorDefaultMessage`):r,o.append(s,c),i.append(a,o),e.onTryAgain||e.onSwap){let t=document.createElement(`div`);if(t.className=`blok-image-error__actions`,e.onTryAgain){let n=document.createElement(`button`);n.type=`button`,n.className=`blok-image-error__btn`,n.setAttribute(`data-action`,`retry`),n.textContent=W(e.i18n,`tools.image.errorRetry`),n.addEventListener(`click`,()=>{var t;(t=e.onTryAgain)==null||t.call(e)}),t.appendChild(n)}if(e.onSwap){let n=document.createElement(`button`);n.type=`button`,n.className=`blok-image-error__btn`,n.setAttribute(`data-action`,`replace`),n.textContent=W(e.i18n,`tools.image.errorReplace`),n.addEventListener(`click`,()=>{var t;(t=e.onSwap)==null||t.call(e)}),t.appendChild(n)}i.appendChild(t)}return i}var Wo=class extends Error{constructor(e,t){super(`${e}: ${t}`),this.name=`ImageError`,this.code=e,this.detail=t}};function Go(e){return e===`left`?0:e===`right`?1:.5}function Ko(e){return e<10?10:e>100?100:e}function qo(e){var t;if(e.containerWidth<=0)return Ko(0);let n=(t=e.alignFrac)==null?0:t,r=e.edge===`right`?1-n:n,i=r===0?1:1/r,a=e.currentX-e.startX,o=i*(e.edge===`right`?a:-a),s=e.startWidth+o;return Ko(Math.round(s/e.containerWidth*100))}function Jo(e){var t;let n={active:!1,startX:0,startWidth:0,containerWidth:0,lastPercent:void 0},r=Go((t=e.alignment)==null?`center`:t),i=t=>{n.active=!0,n.startX=t.clientX,n.startWidth=e.figure.getBoundingClientRect().width,n.containerWidth=e.container.getBoundingClientRect().width,n.lastPercent=void 0,e.handle.setPointerCapture(t.pointerId),t.preventDefault()},a=t=>{if(!n.active)return;let i=qo({edge:e.edge,containerWidth:n.containerWidth,startWidth:n.startWidth,startX:n.startX,currentX:t.clientX,alignFrac:r});n.lastPercent=i,e.onPreview(i)},o=t=>{n.active&&(n.active=!1,e.handle.releasePointerCapture(t.pointerId),n.lastPercent!==void 0&&e.onCommit(n.lastPercent))};return e.handle.addEventListener(`pointerdown`,i),e.handle.addEventListener(`pointermove`,a),e.handle.addEventListener(`pointerup`,o),e.handle.addEventListener(`pointercancel`,o),()=>{e.handle.removeEventListener(`pointerdown`,i),e.handle.removeEventListener(`pointermove`,a),e.handle.removeEventListener(`pointerup`,o),e.handle.removeEventListener(`pointercancel`,o)}}var Yo={x:0,y:0,w:100,h:100},Xo=5;function Zo(e){return e.x===0&&e.y===0&&e.w===100&&e.h===100}function Qo(e){let{x:t,y:n,w:r,h:i}=e,a=Math.max(Xo,Math.min(100,r)),o=Math.max(Xo,Math.min(100,i));return{x:Math.max(0,Math.min(100-a,t)),y:Math.max(0,Math.min(100-o,n)),w:a,h:o}}function $o(e,t,n,r){let{x:i,y:a,w:o,h:s}=e,c=t.includes(`w`),l=t.includes(`e`),u=t.includes(`n`),d=t.includes(`s`),f=i+o,p=a+s,m=c?Math.max(0,Math.min(f-Xo,i+n)):i,h=l?Math.max(i+Xo,Math.min(100,f+n)):f,g=u?Math.max(0,Math.min(p-Xo,a+r)):a,_=d?Math.max(a+Xo,Math.min(100,p+r)):p;return{x:m,y:g,w:h-m,h:_-g}}function es(e,t,n){let r=t?t.w/t.h:1,i=n?n.w/n.h:1;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return e;let a=i/r*e,o=Math.max(10,Math.min(100,a));return Math.round(o*100)/100}function ts(e,t,n){var r,i,a,o;if(t===null||!Number.isFinite(t)||t<=0)return e;let s=e.w,c=s/t,l=c>e.h?e.h*t:s,u=c>e.h?e.h:c,d=(r=n==null?void 0:n.includes(`w`))==null?!1:r,f=(i=n==null?void 0:n.includes(`e`))==null?!1:i,p=(a=n==null?void 0:n.includes(`n`))==null?!1:a,m=(o=n==null?void 0:n.includes(`s`))==null?!1:o,h=e.x+e.w/2,g=e.y+e.h/2;return Qo({x:n===void 0?h-l/2:d&&!f?e.x+e.w-l:f&&!d?e.x:h-l/2,y:n===void 0?g-u/2:p&&!m?e.y+e.h-u:m&&!p?e.y:g-u/2,w:l,h:u})}var ns=.55;function rs(e,t){return e===0?0:(e<0?-1:1)*(1-1/(Math.abs(e)/t*ns+1))*t}function is(e,t,n){return e>=-t&&e<=t?e:(e<0?-1:1)*(t+rs(Math.abs(e)-t,n))}var as={left:`left`,center:`center`,right:`right`},os={left:t.yt,center:t.vt,right:t.bt};function ss(e,t,n,r){let i=t,a=()=>{let t=e.naturalWidth,a=e.naturalHeight;t>0&&a>0&&(i.style.aspectRatio=`${n*t} / ${r*a}`)};e.complete?a():e.addEventListener(`load`,a,{once:!0})}function cs(e,t){switch(t){case`left`:return W(e,`tools.image.alignmentLeftAria`);case`center`:return W(e,`tools.image.alignmentCenterAria`);case`right`:return W(e,`tools.image.alignmentRightAria`)}}function ls(e){var t,n;let r=(t=e.alignment)==null?`center`:t,i=document.createElement(`figure`);i.className=`blok-image-inner`,i.setAttribute(`data-role`,`image-figure`),i.style.margin=`0`,i.style.textAlign=as[r],i.style.position=`relative`,e.width!==void 0&&(i.style.width=`${e.width}%`);let a=document.createElement(`img`);if(a.setAttribute(`src`,e.url),a.setAttribute(`alt`,(n=e.alt)==null?``:n),a.draggable=!1,e.crop){let{x:t,y:n,w:r,h:o,shape:s}=e.crop,c=document.createElement(`div`);c.className=`blok-image-crop`,c.setAttribute(`data-role`,`image-crop`),c.style.overflow=`hidden`,c.style.position=`relative`,c.style.aspectRatio=`${r} / ${o}`,c.style.width=`100%`,s&&c.setAttribute(`data-shape`,s),(s===`circle`||s===`ellipse`)&&(c.style.borderRadius=`50%`),a.style.display=`block`,a.style.maxWidth=`none`,a.style.width=`${100/r*100}%`,a.style.transform=`translate(-${t}%, -${n}%)`,ss(a,c,r,o),c.appendChild(a),i.appendChild(c)}else i.appendChild(a);return i}function us(e){let t=document.createElement(`div`);return t.className=`blok-image-caption`,t.setAttribute(`role`,`textbox`),t.setAttribute(`contenteditable`,e.readOnly?`false`:`true`),t.setAttribute(`data-placeholder`,e.placeholder),t.textContent=e.value,t.style.outline=`none`,t.style.textAlign=`left`,t}function ds(e){let t=document.createElement(`div`);if(t.className=`blok-image-caption-row`,t.appendChild(us(e.caption)),e.onAlt){let n=W(e.i18n,`tools.image.altEdit`),r=document.createElement(`button`);r.type=`button`,r.className=`blok-image-caption-row__alt`,r.setAttribute(`data-action`,`alt-edit`),r.setAttribute(`aria-label`,n),r.setAttribute(`title`,n),r.setAttribute(`aria-pressed`,e.hasAlt?`true`:`false`),r.textContent=W(e.i18n,`tools.image.altButton`),r.addEventListener(`click`,t=>{var n;t.stopPropagation(),(n=e.onAlt)==null||n.call(e)}),t.appendChild(r)}return t}var fs=360,ps=280,ms=`cubic-bezier(0.22, 1, 0.36, 1)`,hs=`cubic-bezier(0.4, 0, 0.2, 1)`;function gs(e,t){let n=t.width>0?e.width/t.width:1,r=t.height>0?e.height/t.height:1,i=e.left+e.width/2,a=e.top+e.height/2,o=t.left+t.width/2,s=t.top+t.height/2;return{tx:i-o,ty:a-s,sx:n,sy:r}}function _s(e){return`translate(${e.tx}px, ${e.ty}px) scale(${e.sx}, ${e.sy})`}function vs(e){return typeof e.animate==`function`}var ys=.25,bs=4,xs=.25,Ss=Math.log(1+xs)/100;function Cs(e){var t;let n=document.activeElement instanceof HTMLElement?document.activeElement:null,r=document.createElement(`div`);r.setAttribute(`role`,`dialog`),r.setAttribute(`aria-modal`,`true`),r.setAttribute(`aria-label`,W(e.i18n,`tools.image.preview`)),r.className=`blok-image-lightbox`;let i=document.createElement(`div`);i.className=`blok-image-lightbox__backdrop`,i.setAttribute(`aria-hidden`,`true`),r.appendChild(i);let a=document.createElement(`img`);a.setAttribute(`src`,e.url),a.setAttribute(`alt`,(t=e.alt)==null?``:t),a.draggable=!1;let o=(()=>{let t=e.crop;if(!t)return a.className=`blok-image-lightbox__image`,a;let{x:n,y:r,w:i,h:o,shape:s}=t,c=document.createElement(`div`);return c.className=`blok-image-lightbox__image blok-image-lightbox__crop`,c.setAttribute(`data-role`,`lightbox-crop`),c.style.overflow=`hidden`,c.style.aspectRatio=`${i} / ${o}`,s&&c.setAttribute(`data-shape`,s),(s===`circle`||s===`ellipse`)&&(c.style.borderRadius=`50%`),a.style.display=`block`,a.style.maxWidth=`none`,a.style.width=`${100/i*100}%`,a.style.transform=`translate(-${n}%, -${r}%)`,ss(a,c,i,o),c.appendChild(a),c})(),s={value:1},c={x:0,y:0},l=()=>{o.style.transform=`translate(${c.x}px, ${c.y}px) scale(${s.value})`};function u(){let e=o.getBoundingClientRect();return{maxX:e.width/2,maxY:e.height/2,width:e.width,height:e.height}}function d(e){let{maxX:t,maxY:n}=u();return{x:Math.max(-t,Math.min(t,e.x)),y:Math.max(-n,Math.min(n,e.y))}}function f(e){let{maxX:t,maxY:n,width:r,height:i}=u();return{x:is(e.x,t,r),y:is(e.y,n,i)}}let p=(e,t={})=>{if(s.value=Math.min(bs,Math.max(ys,e)),t.preservePan){let e=d(c);c.x=e.x,c.y=e.y}else c.x=0,c.y=0;l(),h()};l();let m=ws({i18n:e.i18n,getZoom:()=>s.value,setZoom:p,onDownload:()=>{var t;let n=document.createElement(`a`);n.href=e.url,n.download=(t=e.fileName)==null?``:t,n.target=`_blank`,n.rel=`noopener`,document.body.appendChild(n),n.click(),n.remove()},onCopyUrl:()=>{let t=navigator.clipboard;t==null||t.writeText(e.url)},onCollapse:()=>T()}),h=()=>{let e=m.querySelector(`[data-action="zoom-reset"]`);e&&(e.textContent=`${Math.round(s.value*100)}%`)};r.appendChild(o),r.appendChild(m),document.body.appendChild(r);let g={img:null,backdrop:null,toolbar:null,closing:!1},_=e.origin&&e.origin.isConnected?e.origin:null,v=_?_.style.opacity:``,y=()=>{var e,t,n;(e=g.img)==null||e.cancel(),(t=g.backdrop)==null||t.cancel(),(n=g.toolbar)==null||n.cancel(),g.img=null,g.backdrop=null,g.toolbar=null},b=(e,t,n)=>vs(m)?m.animate([{opacity:e.opacity,transform:`translate(-50%, ${e.y}px)`},{opacity:t.opacity,transform:`translate(-50%, ${t.y}px)`}],n):null,x=()=>{if(_&&vs(o)){let e=_.getBoundingClientRect(),t=o.getBoundingClientRect();if(e.width>0&&e.height>0&&t.width>0&&t.height>0){let n=_s(gs(e,t));_.style.opacity=`0`,g.img=o.animate([{transform:n},{transform:`translate(0px, 0px) scale(1)`}],{duration:fs,easing:ms,fill:`backwards`})}}vs(i)&&(g.backdrop=i.animate([{opacity:0},{opacity:1}],{duration:260,easing:`linear`,fill:`backwards`})),g.toolbar=b({opacity:0,y:12},{opacity:1,y:0},{duration:320,delay:140,easing:ms,fill:`both`})},S=()=>{var e;document.removeEventListener(`keydown`,E),r.remove(),_&&(_.style.opacity=v),n==null||(e=n.focus)==null||e.call(n)},C=()=>{if(!vs(i)){S();return}let e=i.animate([{opacity:1},{opacity:0}],{duration:180,easing:`linear`,fill:`forwards`});e.onfinish=S,e.oncancel=S,b({opacity:1,y:0},{opacity:0,y:12},{duration:180,easing:hs,fill:`forwards`})},w=e=>{let t=e.getBoundingClientRect();if(t.width===0||t.height===0){S();return}o.style.transition=`none`;let n=o.style.transform||`translate(0px, 0px) scale(1)`;o.style.transform=`none`;let r=o.getBoundingClientRect();o.style.transform=n;let a=_s(gs(t,r));o.style.transform=a;let s=o.animate([{transform:n},{transform:a}],{duration:ps,easing:hs,fill:`forwards`});s.onfinish=S,s.oncancel=S,vs(i)&&i.animate([{opacity:1},{opacity:0}],{duration:ps,easing:`linear`,fill:`forwards`}),b({opacity:1,y:0},{opacity:0,y:12},{duration:200,easing:hs,fill:`forwards`})},T=()=>{g.closing||(g.closing=!0,y(),_&&vs(o)?w(_):C())};x();let E=e=>{if(e.key===`Escape`||e.key===` `){e.preventDefault(),T();return}if(e.key===`+`||e.key===`=`){e.preventDefault(),p(s.value+xs);return}if(e.key===`-`){e.preventDefault(),p(s.value-xs);return}},D={pointerDown:!1,dragging:!1,startX:0,startY:0,originX:0,originY:0};r.addEventListener(`pointerdown`,e=>{e.target instanceof Node&&m.contains(e.target)||(D.pointerDown=!0,D.dragging=!1,D.startX=e.clientX,D.startY=e.clientY,D.originX=c.x,D.originY=c.y,r.setPointerCapture(e.pointerId))}),r.addEventListener(`pointermove`,e=>{if(!D.pointerDown)return;let t=e.clientX-D.startX,n=e.clientY-D.startY;if(!D.dragging&&Math.hypot(t,n)>3&&(D.dragging=!0,r.classList.add(`is-dragging`)),!D.dragging)return;let i=f({x:D.originX+t,y:D.originY+n});c.x=i.x,c.y=i.y,l()});let O=()=>{if(D.pointerDown&&(D.pointerDown=!1,r.classList.remove(`is-dragging`),D.dragging)){D.dragging=!1;let e=d(c);c.x=e.x,c.y=e.y,l();let t=e=>{e.target instanceof Node&&m.contains(e.target)||(e.stopPropagation(),r.removeEventListener(`click`,t,!0))};r.addEventListener(`click`,t,!0)}};r.addEventListener(`pointerup`,O),r.addEventListener(`pointercancel`,O);let k={timer:null};return r.addEventListener(`wheel`,e=>{e.preventDefault();let t=Math.exp(-e.deltaY*Ss),n=s.value,i=Math.min(bs,Math.max(ys,n*t)),a=i/n,o=r.getBoundingClientRect(),l=e.clientX-(o.left+o.width/2),u=e.clientY-(o.top+o.height/2);c.x=l*(1-a)+c.x*a,c.y=u*(1-a)+c.y*a,r.classList.add(`is-wheel-zooming`),k.timer!==null&&clearTimeout(k.timer),k.timer=setTimeout(()=>{r.classList.remove(`is-wheel-zooming`),k.timer=null},120),p(i,{preservePan:!0})},{passive:!1}),r.addEventListener(`click`,e=>{e.target instanceof Node&&m.contains(e.target)||T()}),document.addEventListener(`keydown`,E),r.focus(),T}function ws(e){let n=document.createElement(`div`);n.setAttribute(`data-role`,`lightbox-toolbar`),n.setAttribute(`role`,`toolbar`),n.setAttribute(`aria-label`,W(e.i18n,`tools.image.previewControls`)),n.className=`blok-image-lightbox__bar`,n.addEventListener(`click`,e=>e.stopPropagation());let r=t.ln,i=t.cn,a=t.X,o=t.Ot,s=t.V;return Ds(n,{action:`zoom-out`,label:W(e.i18n,`tools.image.zoomOut`),shortcut:`−`,html:r,onClick:()=>e.setZoom(e.getZoom()-xs)}),Ds(n,{action:`zoom-reset`,label:W(e.i18n,`tools.image.resetZoom`),html:`100%`,onClick:()=>e.setZoom(1),extraClass:`blok-image-lightbox__zoom-label`}),Ds(n,{action:`zoom-in`,label:W(e.i18n,`tools.image.zoomIn`),shortcut:`+`,html:i,onClick:()=>e.setZoom(e.getZoom()+xs)}),Ts(n),Ds(n,{action:`lightbox-download`,label:W(e.i18n,`tools.image.download`),html:a,onClick:e.onDownload}),Ds(n,{action:`lightbox-copy-url`,label:W(e.i18n,`tools.image.copyUrl`),html:o,onClick:e.onCopyUrl}),Ds(n,{action:`lightbox-collapse`,label:W(e.i18n,`tools.image.exitFullscreen`),shortcut:`Esc`,html:s,onClick:e.onCollapse}),n}function Ts(e){let t=document.createElement(`div`);t.className=`blok-image-lightbox__divider`,t.setAttribute(`aria-hidden`,`true`),e.appendChild(t)}function Es(e,t){if(t===void 0)return e;let n=document.createElement(`span`);n.className=`blok-image-lightbox-tooltip`,n.append(document.createTextNode(e));let r=document.createElement(`span`);return r.className=`blok-image-lightbox-tooltip__shortcut`,r.textContent=t,n.appendChild(r),n}function Ds(e,n){let r=document.createElement(`button`);r.type=`button`,r.setAttribute(`data-action`,n.action),r.setAttribute(`aria-label`,n.label),r.className=n.extraClass?`blok-image-lightbox__btn ${n.extraClass}`:`blok-image-lightbox__btn`,r.innerHTML=n.html,t.An(r,Es(n.label,n.shortcut),{placement:`top`}),r.addEventListener(`click`,e=>{e.stopPropagation(),t.kn(),n.onClick()}),e.appendChild(r)}function Os(e,t,n=230){t>0&&t<n?e.setAttribute(`data-compact`,`true`):e.removeAttribute(`data-compact`)}function ks(e){let n=document.createElement(`div`);n.setAttribute(`data-role`,`image-overlay`),n.className=`blok-image-toolbar`,As(n,e),js(n),Ms(n,{action:`caption-toggle`,label:W(e.i18n,`tools.image.toggleCaption`),pressed:e.state.captionVisible,icon:t.N,onClick:e.onToggleCaption}),Ms(n,{action:`replace`,label:W(e.i18n,`tools.image.replace`),icon:t.Kt,onClick:e.onReplace}),Ms(n,{action:`crop`,label:W(e.i18n,`tools.image.crop`),icon:t.U,onClick:e.onCrop}),Ms(n,{action:`fullscreen`,label:W(e.i18n,`tools.image.viewFullscreen`),icon:t.ot,onClick:e.onFullscreen}),Ms(n,{action:`download`,label:W(e.i18n,`tools.image.downloadOriginal`),icon:t.X,onClick:e.onDownload}),js(n);let r=W(e.i18n,`tools.image.moreOptions`),i=document.createElement(`button`);i.type=`button`,i.setAttribute(`data-action`,`more`),i.setAttribute(`aria-label`,r),i.setAttribute(`aria-haspopup`,`menu`),i.innerHTML=t.Rt,t.An(i,r),n.appendChild(i);let a=document.createElement(`button`);return a.type=`button`,a.setAttribute(`data-action`,`delete`),a.setAttribute(`aria-label`,W(e.i18n,`blockSettings.delete`)),a.className=`blok-image-toolbar__alias is-danger`,a.style.display=`none`,a.addEventListener(`click`,t=>{t.stopPropagation(),e.onDelete()}),n.appendChild(a),n}function As(e,n){let r=document.createElement(`div`);r.className=`blok-image-toolbar__align`,r.style.position=`relative`;let i=n.state.alignment,a=W(n.i18n,`tools.image.alignment`),o=document.createElement(`button`);o.type=`button`,o.setAttribute(`data-action`,`align-trigger`),o.setAttribute(`data-current`,i),o.setAttribute(`aria-label`,a),o.setAttribute(`aria-haspopup`,`true`),o.setAttribute(`aria-expanded`,`false`),o.innerHTML=os[i],t.An(o,a),r.appendChild(o);let s=document.createElement(`div`);s.setAttribute(`data-role`,`align-popover`),s.setAttribute(`role`,`group`),s.setAttribute(`aria-label`,a),s.className=`blok-image-toolbar__align-popover`,s.hidden=!0;for(let e of[`left`,`center`,`right`]){let r=cs(n.i18n,e),a=document.createElement(`button`);a.type=`button`,a.setAttribute(`data-action`,`align-${e}`),a.setAttribute(`aria-label`,r),a.setAttribute(`aria-pressed`,i===e?`true`:`false`),a.innerHTML=os[e],t.An(a,r),a.addEventListener(`click`,r=>{r.stopPropagation(),t.kn(),f(),n.onAlign(e)}),s.appendChild(a)}r.appendChild(s),e.appendChild(r);let c=e=>{e.key===`Escape`&&!s.hidden&&(e.stopPropagation(),f())},l=e=>{if(s.hidden)return;let t=e.target;t&&r.contains(t)||f()},u=()=>r.closest(`[data-blok-tool="image"]`),d=()=>{var e;s.hidden&&(s.hidden=!1,s.setAttribute(`data-blok-popover-opened`,`true`),(e=u())==null||e.setAttribute(`data-align-open`,`true`),o.setAttribute(`aria-expanded`,`true`),t.kn(),document.addEventListener(`keydown`,c),document.addEventListener(`mousedown`,l))};function f(){var e;s.hidden||(s.hidden=!0,s.removeAttribute(`data-blok-popover-opened`),(e=u())==null||e.removeAttribute(`data-align-open`),o.setAttribute(`aria-expanded`,`false`),document.removeEventListener(`keydown`,c),document.removeEventListener(`mousedown`,l))}o.addEventListener(`click`,e=>{e.stopPropagation(),s.hidden?d():f()})}function js(e){let t=document.createElement(`div`);t.className=`blok-image-toolbar__divider`,t.setAttribute(`aria-hidden`,`true`),e.appendChild(t)}function Ms(e,n){let r=document.createElement(`button`);r.type=`button`,r.setAttribute(`aria-label`,n.label),r.setAttribute(`data-action`,n.action),n.pressed!==void 0&&r.setAttribute(`aria-pressed`,n.pressed?`true`:`false`),r.innerHTML=n.icon,t.An(r,n.label),r.addEventListener(`click`,e=>{e.stopPropagation(),t.kn(),n.onClick()}),e.appendChild(r)}var Ns=[`nw`,`n`,`ne`,`e`,`se`,`s`,`sw`,`w`],Ps=new Set([`nw`,`ne`,`se`,`sw`]),Fs=[{label:`Free`,i18nKey:`tools.image.cropRatioFree`,key:`free`,value:null,shape:`rect`},{label:`1:1`,i18nKey:`tools.image.cropRatio1to1`,key:`1`,value:1,shape:`rect`},{label:`4:3`,i18nKey:`tools.image.cropRatio4to3`,key:`1.3333333333333333`,value:4/3,shape:`rect`},{label:`16:9`,i18nKey:`tools.image.cropRatio16to9`,key:`1.7777777777777777`,value:16/9,shape:`rect`},{label:`Circle`,i18nKey:`tools.image.cropRatioCircle`,key:`circle`,value:1,shape:`circle`},{label:`Oval`,i18nKey:`tools.image.cropRatioOval`,key:`ellipse`,value:null,shape:`ellipse`}];function Is(e,t){if(!e)throw Error(`CropEditor: missing ${t}`);return e}function Ls(e){let t=document.createElement(`span`);return t.setAttribute(`data-handle`,e),t.className=`blok-image-crop-editor__handle blok-image-crop-editor__handle--${Ps.has(e)?`corner`:`edge`} blok-image-crop-editor__handle--${e}`,Ps.has(e)&&(t.appendChild(Rs(`a`)),t.appendChild(Rs(`b`))),t}function Rs(e){let t=document.createElement(`i`);return t.className=`blok-image-crop-editor__handle-stroke blok-image-crop-editor__handle-stroke--${e}`,t}function zs(e,t){var r,i,a,o;let s=(r=(i=t.initial)==null?void 0:i.shape)==null?`rect`:r,c=(a=Fs.find(e=>e.shape===s&&e.shape!==`rect`))==null?Fs[0]:a,l={rect:t.initial?Qo(t.initial):n.t({},Yo),ratio:c.value,ratioKey:c.key,shape:c.shape},u=document.createElement(`div`);u.className=`blok-image-crop-editor`,u.setAttribute(`role`,`region`),u.setAttribute(`aria-label`,W(t.i18n,`tools.image.cropDialogLabel`));let d=document.createElement(`div`);d.className=`blok-image-crop-editor__stage`;let f=document.createElement(`div`);f.className=`blok-image-crop-editor__frame`,d.appendChild(f);let p=document.createElement(`img`);p.className=`blok-image-crop-editor__source`,p.src=t.url,p.alt=(o=t.alt)==null?``:o,p.draggable=!1,f.appendChild(p);let m=document.createElement(`div`);m.className=`blok-image-crop-editor__mask`,f.appendChild(m);let h=document.createElement(`div`);h.className=`blok-image-crop-editor__shape-mask-clip`,h.setAttribute(`aria-hidden`,`true`),f.appendChild(h);let g=document.createElement(`div`);g.className=`blok-image-crop-editor__shape-mask`,g.setAttribute(`data-shape`,l.shape),h.appendChild(g);let _=document.createElement(`div`);_.className=`blok-image-crop-editor__rect`,_.setAttribute(`data-shape`,l.shape),f.appendChild(_);for(let e of[`v-1`,`v-2`,`h-1`,`h-2`]){let t=document.createElement(`i`);t.className=`blok-image-crop-editor__grid-line blok-image-crop-editor__grid-line--${e}`,_.appendChild(t)}let v=document.createElement(`div`);v.className=`blok-image-crop-editor__size-pill`,v.hidden=!0,f.appendChild(v);let y={};for(let e of Ns){let t=Ls(e);_.appendChild(t),y[e]=t}let b=document.createElement(`div`);b.className=`blok-image-crop-editor__toolbar blok-image-crop-editor__toolbar--footer`,b.setAttribute(`role`,`toolbar`);let x=document.createElement(`div`);x.className=`blok-image-crop-editor__ratio-group`,x.setAttribute(`role`,`radiogroup`),x.setAttribute(`aria-label`,W(t.i18n,`tools.image.cropAspectRatio`)),x.setAttribute(`data-action`,`ratio`);let S={};for(let e of Fs){let n=document.createElement(`button`);n.type=`button`,n.className=`blok-image-crop-editor__ratio-chip`,n.setAttribute(`role`,`radio`),n.setAttribute(`data-ratio`,e.key),n.setAttribute(`data-active`,String(e.key===l.ratioKey)),n.setAttribute(`aria-checked`,String(e.key===l.ratioKey)),n.textContent=W(t.i18n,e.i18nKey),n.addEventListener(`click`,t=>{t.stopPropagation(),k(e)}),x.appendChild(n),S[e.key]=n}let C=document.createElement(`div`);C.className=`blok-image-crop-editor__actions`,C.innerHTML=`
105
+ <button type="button" class="blok-image-crop-editor__btn blok-image-crop-editor__btn--ghost" data-action="reset">${W(t.i18n,`tools.image.cropReset`)}</button>
106
+ <button type="button" class="blok-image-crop-editor__btn blok-image-crop-editor__btn--ghost" data-action="cancel">${W(t.i18n,`tools.image.cropCancel`)}</button>
107
+ <button type="button" class="blok-image-crop-editor__btn blok-image-crop-editor__btn--primary" data-action="done">${W(t.i18n,`tools.image.cropDone`)}</button>
108
+ `,b.appendChild(x),b.appendChild(C),u.appendChild(d),u.appendChild(b),e.appendChild(u);function w(){let e=p.naturalWidth,t=p.naturalHeight;if(!e||!t){v.hidden=!0;return}v.hidden=!1,v.textContent=`${Math.round(l.rect.w/100*e)} × ${Math.round(l.rect.h/100*t)} px`}function T(){let{rect:e}=l;_.style.left=`${e.x}%`,_.style.top=`${e.y}%`,_.style.width=`${e.w}%`,_.style.height=`${e.h}%`,v.style.left=`${e.x+e.w/2}%`,v.style.top=`${e.y}%`,g.style.left=`${e.x}%`,g.style.top=`${e.y}%`,g.style.width=`${e.w}%`,g.style.height=`${e.h}%`,m.style.clipPath=`polygon(
109
+ 0 0, 100% 0, 100% 100%, 0 100%, 0 0,
110
+ ${e.x}% ${e.y}%,
111
+ ${e.x}% ${e.y+e.h}%,
112
+ ${e.x+e.w}% ${e.y+e.h}%,
113
+ ${e.x+e.w}% ${e.y}%,
114
+ ${e.x}% ${e.y}%
115
+ )`,w()}T(),p.complete&&p.naturalWidth>0&&w(),p.addEventListener(`load`,w);function E(e,t){l.rect=ts(Qo(e),l.ratio,t),T()}function D(){for(let[e,t]of Object.entries(S)){let n=e===l.ratioKey;t.setAttribute(`data-active`,String(n)),t.setAttribute(`aria-checked`,String(n))}}function O(){let e=l.ratio===null;for(let t of Ns)Ps.has(t)||(y[t].hidden=!e)}O();function k(e){l.ratio=e.value,l.ratioKey=e.key,l.shape=e.shape,_.setAttribute(`data-shape`,e.shape),g.setAttribute(`data-shape`,e.shape),D(),O(),E(l.rect)}for(let e of Ns)y[e].addEventListener(`pointerdown`,t=>j(t,e));_.addEventListener(`pointerdown`,e=>{e.target.closest(`[data-handle]`)||M(e)});function A(e,t){let n=f.getBoundingClientRect();return{x:(e-n.left)/n.width*100,y:(t-n.top)/n.height*100}}function j(e,t){e.preventDefault(),e.stopPropagation();let r=n.t({},l.rect),i=A(e.clientX,e.clientY),a=e=>{let n=A(e.clientX,e.clientY);E($o(r,t,n.x-i.x,n.y-i.y),t)},o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)}function M(e){e.preventDefault();let t=n.t({},l.rect),r=A(e.clientX,e.clientY),i=e=>{let i=A(e.clientX,e.clientY);E(n.t(n.t({},t),{},{x:t.x+(i.x-r.x),y:t.y+(i.y-r.y)}))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a)}function N(){let e=l.shape;if(e===`circle`||e===`ellipse`){t.onApply(n.t(n.t({},l.rect),{},{shape:e}));return}t.onApply(Zo(l.rect)?null:l.rect)}Is(C.querySelector(`[data-action="done"]`),`done button`).addEventListener(`click`,N),Is(C.querySelector(`[data-action="cancel"]`),`cancel button`).addEventListener(`click`,()=>t.onCancel()),Is(C.querySelector(`[data-action="reset"]`),`reset button`).addEventListener(`click`,()=>E(n.t({},Yo)));let ee=e=>{e.key===`Escape`?(e.preventDefault(),t.onCancel()):e.key===`Enter`&&(e.preventDefault(),N())};return document.addEventListener(`keydown`,ee),()=>{document.removeEventListener(`keydown`,ee),p.removeEventListener(`load`,w),u.remove()}}function Bs(e){let n=document.activeElement instanceof HTMLElement?document.activeElement:null,r=document.createElement(`div`);r.className=`blok-image-crop-modal-backdrop`,r.setAttribute(`role`,`presentation`),r.setAttribute(`data-blok-testid`,`image-crop-backdrop`);let i=document.createElement(`div`);i.className=`blok-image-crop-modal-dialog`,i.setAttribute(`role`,`dialog`),i.setAttribute(`aria-modal`,`true`),i.setAttribute(`aria-label`,W(e.i18n,`tools.image.cropDialogLabel`)),i.tabIndex=-1;let a=document.createElement(`div`);a.className=`blok-image-crop-modal-body`,i.appendChild(a),r.appendChild(i),document.body.appendChild(r),t.Mn(r);let o={detached:!1,editorDetach:null},s={downOnBackdrop:!1},c=()=>{var e,i;o.detached||(o.detached=!0,r.removeEventListener(`mousedown`,l),r.removeEventListener(`click`,u),(e=o.editorDetach)==null||e.call(o),o.editorDetach=null,t.Nn(r),r.remove(),n==null||(i=n.focus)==null||i.call(n))},l=e=>{s.downOnBackdrop=e.target===r},u=t=>{let n=t.target===r&&s.downOnBackdrop;s.downOnBackdrop=!1,n&&(c(),e.onCancel())};r.addEventListener(`mousedown`,l),r.addEventListener(`click`,u),o.editorDetach=zs(a,{url:e.url,alt:e.alt,initial:e.initial,i18n:e.i18n,onApply:t=>{c(),e.onApply(t)},onCancel:()=>{c(),e.onCancel()}});let d=i.querySelector(`[data-action="done"]`);return d==null||d.focus(),c}function Vs(e){let n=document.createElement(`div`);n.className=`blok-image-alt-popover`,n.setAttribute(`data-role`,`image-alt-popover`),n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-label`,W(e.i18n,`tools.image.altEdit`));let r=document.createElement(`p`);r.className=`blok-image-alt-popover__description`,r.textContent=W(e.i18n,`tools.image.altDescription`),n.appendChild(r);let i=document.createElement(`textarea`);i.className=`blok-image-alt-popover__input`,i.rows=2,i.value=e.value,i.placeholder=W(e.i18n,`tools.image.altPlaceholder`),n.appendChild(i),document.body.appendChild(n),t.Mn(n),Hs(n,e.anchor),i.focus(),i.setSelectionRange(i.value.length,i.value.length);let a={detached:!1},o=()=>{a.detached||(a.detached=!0,document.removeEventListener(`keydown`,l),document.removeEventListener(`mousedown`,u),window.removeEventListener(`resize`,d),window.removeEventListener(`scroll`,d,!0),t.Nn(n),n.remove())},s=()=>{let t=i.value;o(),e.onSave(t)},c=()=>{o(),e.onCancel()},l=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),c();return}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.stopPropagation(),s())},u=t=>{let r=t.target;r&&(n.contains(r)||e.anchor.contains(r))||s()};function d(){a.detached||Hs(n,e.anchor)}return i.addEventListener(`keydown`,l),document.addEventListener(`mousedown`,u),window.addEventListener(`resize`,d),window.addEventListener(`scroll`,d,!0),o}function Hs(e,t){let n=t.getBoundingClientRect(),{style:r}=e;r.position=`fixed`,r.top=`${n.bottom+8}px`,r.right=`${Math.max(8,window.innerWidth-n.right)}px`,r.left=`auto`}function Us(e){return!Number.isFinite(e)||e<0?0:e>100?100:e}function Ws(e){var n;let r=document.createElement(`div`);r.className=`blok-image-uploading`,r.setAttribute(`data-role`,`uploading`);let i=document.createElement(`div`);i.className=`blok-image-uploading__card`;let a=document.createElement(`div`);a.className=`blok-image-uploading__header`;let o=document.createElement(`span`);o.className=`blok-image-uploading__label`,o.textContent=W(e.i18n,`tools.image.uploadingLabel`);let s=document.createElement(`span`);s.className=`blok-image-uploading__filename`,s.setAttribute(`data-role`,`filename`),s.textContent=e.fileName,s.title=e.fileName;let c=document.createElement(`button`);c.type=`button`,c.className=`blok-image-uploading__cancel`,c.setAttribute(`data-action`,`cancel`),c.setAttribute(`aria-label`,W(e.i18n,`tools.image.cancelUpload`)),c.innerHTML=t.R,c.addEventListener(`click`,()=>{var t;(t=e.onCancel)==null||t.call(e)}),a.append(o,s,c);let l=document.createElement(`div`);l.className=`blok-image-uploading__panel`;let u=document.createElement(`span`);u.className=`blok-image-uploading__tile`,u.setAttribute(`aria-hidden`,`true`),u.innerHTML=t._t;let d=document.createElement(`div`);d.className=`blok-image-uploading__content`;let f=document.createElement(`div`);f.className=`blok-image-uploading__sub`;let p=document.createElement(`span`);p.className=`blok-image-uploading__pct`,p.setAttribute(`data-role`,`pct`),p.textContent=`0%`;let m=document.createElement(`span`);m.className=`blok-image-uploading__sep`,m.setAttribute(`aria-hidden`,`true`),m.textContent=`·`;let h=document.createElement(`span`);h.className=`blok-image-uploading__size`,h.setAttribute(`data-role`,`size`),h.textContent=(n=e.sizeLabel)==null?``:n,f.append(p,m,h);let g=document.createElement(`div`);g.className=`blok-image-uploading__bar`,g.setAttribute(`role`,`progressbar`),g.setAttribute(`aria-valuemin`,`0`),g.setAttribute(`aria-valuemax`,`100`),g.setAttribute(`aria-valuenow`,`0`),g.setAttribute(`aria-label`,W(e.i18n,`tools.image.uploadProgress`));let _=document.createElement(`div`);return _.className=`blok-image-uploading__bar-fill`,_.setAttribute(`data-role`,`fill`),_.style.width=`0%`,g.appendChild(_),d.append(f,g),l.append(u,d),i.append(a,l),r.append(i),r.setProgress=(e,t)=>{let n=Us(e);_.style.width=`${n}%`,p.textContent=`${Math.round(n)}%`,g.setAttribute(`aria-valuenow`,String(Math.round(n))),t!==void 0&&(h.textContent=t)},r}function Gs(e){try{return new URL(e)}catch(e){return null}}var Ks=class{constructor(e){this.config=e}async handleUrl(e){var t=this,n;return t.validateUrl(e),(n=t.config.uploader)!=null&&n.uploadByUrl?t.config.uploader.uploadByUrl(e):{url:e}}async handleFile(e){var t=this,n;return t.validateFile(e),(n=t.config.uploader)!=null&&n.uploadByFile?t.config.uploader.uploadByFile(e):{url:URL.createObjectURL(e),fileName:e.name}}validateUrl(e){let t=Gs(e);if(!t)throw new Wo(`INVALID_URL`,e);if(t.protocol!==`http:`&&t.protocol!==`https:`)throw new Wo(`INVALID_URL`,t.protocol)}validateFile(e){var t,n;let r=(t=this.config.types)==null?[...Ao]:t,i=(n=this.config.maxSize)==null?jo:n;if(!r.includes(e.type))throw new Wo(`UNSUPPORTED_TYPE`,e.type||`unknown`);if(e.size>i)throw new Wo(`FILE_TOO_LARGE`,`${e.size} > ${i}`)}},qs=class{constructor(e){var t,r,i;this.root=null,this.state=`EMPTY`,this.emptyStateEl=null,this.uploadingEl=null,this.resizeDetach=[],this.overlayResizeObserver=null,this.cropDetach=null,this.altPopoverDetach=null,this.errorMessage=null,this.lastFileName=null,this.lastSource=null,this.brokenImage=!1,this.retrying=!1,this.api=e.api,this.block=e.block,this.config=(t=e.config)==null?{}:t,this.readOnly=e.readOnly,this.data=n.t(n.t({},e.data),{},{url:(r=(i=e.data)==null?void 0:i.url)==null?``:r}),this.state=this.data.url?`RENDERED`:`EMPTY`,this.uploader=new Ks(this.config)}render(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-tool`,`image`),this.root=e,this.renderState(),e}save(e){let t={url:this.data.url};if(this.data.caption!==void 0&&(t.caption=this.data.caption),this.data.width!==void 0&&(t.width=this.data.width),this.data.alignment!==void 0&&(t.alignment=this.data.alignment),this.data.alt!==void 0&&(t.alt=this.data.alt),this.data.fileName!==void 0&&(t.fileName=this.data.fileName),this.data.size!==void 0&&(t.size=this.data.size),this.data.frame!==void 0&&(t.frame=this.data.frame),this.data.rounded!==void 0&&(t.rounded=this.data.rounded),this.data.captionVisible!==void 0&&(t.captionVisible=this.data.captionVisible),this.data.crop!==void 0){let{x:e,y:n,w:r,h:i,shape:a}=this.data.crop,o=e===0&&n===0&&r===100&&i===100,s=a===`circle`||a===`ellipse`;(!o||s)&&(t.crop=s?{x:e,y:n,w:r,h:i,shape:a}:{x:e,y:n,w:r,h:i})}return t}validate(e){return typeof e.url==`string`&&e.url.length>0}static get toolbox(){return{icon:t._t,titleKey:`image`,searchTerms:[`image`,`img`,`picture`,`photo`,`media`]}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{patterns:{image:No},files:{mimeTypes:[`image/*`]}}}onPaste(e){if(e.type===`pattern`){let t=e.detail;this.applyResult({url:t.data});return}if(e.type===`file`){let t=e.detail;this.startUpload(t.file)}}startUpload(e){this.lastFileName=e.name,this.lastSource={kind:`file`,file:e},this.state=`LOADING`,this.errorMessage=null,this.brokenImage=!1,this.renderState(),this.uploader.handleFile(e).then(e=>this.applyResult(e)).catch(e=>this.applyError(e))}startUrl(e){this.lastFileName=null,this.lastSource={kind:`url`,url:e},this.state=`LOADING`,this.errorMessage=null,this.brokenImage=!1,this.renderState(),this.uploader.handleUrl(e).then(e=>this.applyResult(e)).catch(e=>this.applyError(e))}retryLastSource(){var e;let t=this.lastSource;if(!t){this.transitionToEmpty();return}this.retrying=!0,this.syncRetryingAttribute();let n=(e=this.root)==null?void 0:e.querySelector(`[data-role="error-state"] [data-action="retry"]`);n&&(n.disabled=!0),(t.kind===`file`?this.uploader.handleFile(t.file):this.uploader.handleUrl(t.url)).then(e=>this.applyResult(e)).catch(e=>this.applyError(e))}applyResult(e){var t;this.data=n.t(n.t({},this.data),{},{url:e.url,fileName:(t=e.fileName)==null?this.data.fileName:t}),this.state=`RENDERED`,this.errorMessage=null,this.brokenImage=!1,this.retrying=!1,this.renderState(),this.block.dispatchChange()}applyError(e){this.state=`ERROR`,this.errorMessage=e instanceof Error?e.message:this.api.i18n.t(`tools.image.errorUploadFailed`),this.brokenImage=!1,this.retrying=!1,this.renderState(),e instanceof Wo||console.error(`[image] upload failed`,e)}applyBrokenImage(){this.state===`ERROR`&&this.brokenImage||(this.state=`ERROR`,this.brokenImage=!0,this.errorMessage=this.api.i18n.t(`tools.image.errorSourceOffline`),this.renderState())}retryBrokenImage(){this.brokenImage=!1,this.errorMessage=null,this.state=`RENDERED`,this.renderState()}setReadOnly(e){this.readOnly=e,this.renderState()}getToolbarAnchorElement(){var e,t;return(e=(t=this.root)==null?void 0:t.querySelector(`.blok-image-inner`))==null?void 0:e}getContentOffset(e){let t=this.root,n=t==null?void 0:t.querySelector(`.blok-image-inner`);if(!t||!n)return;let r=n.getBoundingClientRect().left-t.getBoundingClientRect().left;return r>0?{left:r}:void 0}renderSettings(){var e,n,r;let i=this.api.i18n,a=(e=this.data.alignment)==null?`center`:e,o=this.data.captionVisible!==!1,s=[{value:`left`,title:i.t(`tools.image.alignmentLeft`),icon:t.yt},{value:`center`,title:i.t(`tools.image.alignmentCenter`),icon:t.vt},{value:`right`,title:i.t(`tools.image.alignmentRight`),icon:t.bt}],c=(n=(r=s.find(e=>e.value===a))==null?void 0:r.icon)==null?s[1].icon:n,l=t.N,u=t.Kt,d=t.U,f=t.ot,p=t.X;return[{icon:c,title:i.t(`tools.image.alignment`),name:`image-alignment`,children:{items:s.map(e=>({icon:e.icon,title:e.title,name:`image-alignment-${e.value}`,isActive:a===e.value,closeOnActivate:!0,onActivate:()=>this.setAlignment(e.value)}))}},{icon:l,title:i.t(`tools.image.caption`),name:`image-caption`,isActive:o,closeOnActivate:!0,onActivate:()=>this.toggleCaption()},{icon:u,title:i.t(`tools.image.replace`),name:`image-replace`,closeOnActivate:!0,onActivate:()=>this.transitionToEmpty()},{icon:d,title:i.t(`tools.image.crop`),name:`image-crop`,closeOnActivate:!0,onActivate:()=>this.enterCrop()},{icon:f,title:i.t(`tools.image.viewFullscreen`),name:`image-fullscreen`,closeOnActivate:!0,onActivate:()=>this.openFullscreen()},{icon:p,title:i.t(`tools.image.downloadOriginal`),name:`image-download`,closeOnActivate:!0,onActivate:()=>this.download()},{icon:t.H,title:i.t(`tools.image.copyUrl`),name:`image-copy-url`,closeOnActivate:!0,onActivate:()=>this.copyUrl()}]}openFullscreen(){var e,t,n;let r=(e=this.root)==null?void 0:e.querySelector(`.blok-image-inner`),i=(t=(n=r==null?void 0:r.querySelector(`.blok-image-crop`))==null?r==null?void 0:r.querySelector(`img`):n)==null?void 0:t;Cs({url:this.data.url,alt:this.data.alt,fileName:this.data.fileName,crop:this.data.crop,origin:i,i18n:this.api.i18n})}enterCrop(){this.cropDetach||(this.closeAlignmentPopover(),this.cropDetach=Bs({url:this.data.url,alt:this.data.alt,initial:this.data.crop,onApply:e=>this.applyCrop(e),onCancel:()=>this.cancelCrop(),i18n:this.api.i18n}))}applyCrop(e){this.cropDetach=null;let t=this.data.crop;this.data.width!==void 0&&(this.data.width=es(this.data.width,t,e)),e===null?delete this.data.crop:this.data.crop=e,this.block.dispatchChange(),this.renderState()}cancelCrop(){this.cropDetach=null}detachCrop(){var e;(e=this.cropDetach)==null||e.call(this),this.cropDetach=null}closeAlignmentPopover(){var e;if(!this.root)return;let t=this.root.querySelector(`[data-role="align-popover"]:not([hidden])`);t&&(t.hidden=!0,t.removeAttribute(`data-blok-popover-opened`),this.root.removeAttribute(`data-align-open`),(e=this.root.querySelector(`[data-action="align-trigger"]`))==null||e.setAttribute(`aria-expanded`,`false`))}removed(){var e;this.detachResize(),this.detachCrop(),(e=this.altPopoverDetach)==null||e.call(this),this.altPopoverDetach=null,this.data.url.startsWith(`blob:`)&&URL.revokeObjectURL(this.data.url)}detachResize(){for(var e;this.resizeDetach.length>0;){let e=this.resizeDetach.pop();e&&e()}(e=this.overlayResizeObserver)==null||e.disconnect(),this.overlayResizeObserver=null}syncRootAttributes(){var e,t,n;if(!this.root)return;let r=this.root;r.setAttribute(`data-state`,this.state.toLowerCase()),r.setAttribute(`data-size`,(e=this.data.size)==null?`md`:e),r.setAttribute(`data-align`,(t=this.data.alignment)==null?`center`:t),r.setAttribute(`data-frame`,(n=this.data.frame)==null?`none`:n),r.setAttribute(`data-rounded`,this.data.rounded===!1?`off`:`on`),r.setAttribute(`data-caption`,this.data.captionVisible===!1?`off`:`on`),r.setAttribute(`data-alt`,this.data.alt?`set`:`none`),r.setAttribute(`data-selected`,`false`),r.removeAttribute(`data-align-open`),this.syncRetryingAttribute()}syncRetryingAttribute(){this.root&&(this.retrying?this.root.setAttribute(`data-retrying`,`true`):this.root.removeAttribute(`data-retrying`))}renderState(){if(this.root){if(this.detachResize(),this.root.replaceChildren(),this.syncRootAttributes(),this.state===`EMPTY`){this.renderEmpty();return}if(this.state===`LOADING`){this.renderLoading();return}if(this.state===`ERROR`){this.renderError();return}this.renderRendered()}}renderEmpty(){if(!this.root)return;let e=Ho({onFile:e=>this.startUpload(e),onUrl:e=>this.startUrl(e),acceptTypes:this.config.types,maxSize:this.config.maxSize,i18n:this.api.i18n});this.emptyStateEl=e,this.root.appendChild(e)}renderLoading(){var e;if(!this.root)return;let t=Ws({fileName:(e=this.lastFileName)==null?this.api.i18n.t(`tools.image.uploading`):e,onCancel:()=>this.transitionToEmpty(),i18n:this.api.i18n});this.uploadingEl=t,this.root.appendChild(t)}renderError(){var e;if(!this.root)return;let t=this.brokenImage,n=Uo({title:t?this.api.i18n.t(`tools.image.errorUnavailable`):void 0,message:(e=this.errorMessage)==null?void 0:e,onTryAgain:t?()=>this.retryBrokenImage():()=>this.retryLastSource(),onSwap:()=>this.transitionToEmpty(),i18n:this.api.i18n});this.root.appendChild(n)}renderRendered(){var e,t,n,r;if(!this.root)return;let i=ls(this.data),a=i.querySelector(`img`),o=(e=(t=i.querySelector(`.blok-image-crop`))==null?a:t)==null?void 0:e;if(a&&(a.style.cursor=`zoom-in`,a.addEventListener(`click`,()=>Cs({url:this.data.url,alt:this.data.alt,fileName:this.data.fileName,crop:this.data.crop,origin:o,i18n:this.api.i18n})),a.addEventListener(`error`,()=>this.applyBrokenImage(),{once:!0}),a.complete&&a.naturalWidth===0)){this.applyBrokenImage();return}if(!this.readOnly){var s,c;let e=ks({state:{alignment:(s=this.data.alignment)==null?`center`:s,captionVisible:this.data.captionVisible!==!1,size:(c=this.data.size)==null?`md`:c},onAlign:e=>this.setAlignment(e),onSize:e=>this.setSize(e),onReplace:()=>this.transitionToEmpty(),onDelete:()=>this.deleteBlock(),onDownload:()=>this.download(),onFullscreen:()=>Cs({url:this.data.url,alt:this.data.alt,fileName:this.data.fileName,crop:this.data.crop,origin:o,i18n:this.api.i18n}),onCopyUrl:()=>this.copyUrl(),onToggleCaption:()=>this.toggleCaption(),onCrop:()=>this.enterCrop(),i18n:this.api.i18n});i.appendChild(e);let t=e.querySelector(`[data-action="more"]`);t==null||t.addEventListener(`click`,e=>{e.stopPropagation(),this.openBlockSettings(t)}),this.observeOverlayWidth(i,e)}let l=(n=this.config.captionPlaceholder)==null?Mo:n,u=this.data.captionVisible!==!1,d=ds({caption:{value:(r=this.data.caption)==null?``:r,placeholder:l,readOnly:this.readOnly},onAlt:this.readOnly||!u?void 0:()=>this.promptAlt(),hasAlt:!!this.data.alt,i18n:this.api.i18n}),f=d.querySelector(`.blok-image-caption`);f==null||f.addEventListener(`blur`,()=>{var e;let t=(e=f.textContent)==null?``:e;t!==this.data.caption&&(this.data.caption=t,this.block.dispatchChange())}),i.appendChild(d),this.root.appendChild(i),this.readOnly||this.attachResizeHandles(i)}openBlockSettings(e){var t;let n=this.api.toolbar;if(!(n!=null&&n.toggleBlockSettings))return;(t=this.root)==null||t.setAttribute(`data-settings-open`,`true`);let r=()=>{var e;(e=this.root)==null||e.removeAttribute(`data-settings-open`),this.api.events.off(`block-settings-closed`,r)};this.api.events.on(`block-settings-closed`,r),n.toggleBlockSettings(!0,e,{placeLeftOfAnchor:!1})}observeOverlayWidth(e,t){let n=()=>Os(t,e.clientWidth);n(),!(typeof ResizeObserver>`u`)&&(this.overlayResizeObserver=new ResizeObserver(n),this.overlayResizeObserver.observe(e))}attachResizeHandles(e){for(let r of[`left`,`right`]){var t,n;let i=this.createResizeHandle(r);e.appendChild(i);let a=Jo({handle:i,figure:e,container:(t=e.parentElement)==null?e:t,edge:r,alignment:(n=this.data.alignment)==null?`center`:n,onPreview:t=>{e.style.setProperty(`width`,`${t}%`)},onCommit:e=>{this.data.width=e,this.block.dispatchChange()}});this.resizeDetach.push(a)}}createResizeHandle(e){let t=document.createElement(`div`);return t.setAttribute(`data-role`,`resize-handle`),t.setAttribute(`data-edge`,e),t}setAlignment(e){var t,n;if(this.data.alignment===e)return;let r=(t=this.root)==null?void 0:t.querySelector(`.blok-image-inner`),i=r==null?void 0:r.getBoundingClientRect();if(this.data.alignment=e,this.block.dispatchChange(),this.renderState(),!i)return;let a=(n=this.root)==null?void 0:n.querySelector(`.blok-image-inner`);if(!a)return;let o=a.getBoundingClientRect(),s=i.left-o.left;if(Math.abs(s)<.5)return;a.style.transition=`none`,a.style.transform=`translateX(${s}px)`,a.offsetWidth,a.style.transition=`transform 320ms cubic-bezier(0.22, 1, 0.36, 1)`,a.style.transform=`translateX(0)`;let c=()=>{a.style.transition=``,a.style.transform=``,a.removeEventListener(`transitionend`,c)};a.addEventListener(`transitionend`,c)}setSize(e){this.data.size!==e&&(this.data.size=e,this.block.dispatchChange(),this.renderState())}setFrame(e){this.data.frame!==e&&(this.data.frame=e,this.block.dispatchChange(),this.renderState())}setRounded(e){this.data.rounded!==e&&(this.data.rounded=e,this.block.dispatchChange(),this.renderState())}toggleCaption(){this.data.captionVisible=this.data.captionVisible===!1,this.block.dispatchChange(),this.renderState()}transitionToEmpty(){this.data=n.t(n.t({},this.data),{},{url:``}),this.state=`EMPTY`,this.errorMessage=null,this.brokenImage=!1,this.lastSource=null,this.lastFileName=null,this.renderState(),this.block.dispatchChange()}promptAlt(){var e;if(this.altPopoverDetach||!this.root)return;let t=this.root.querySelector(`.blok-image-caption-row [data-action="alt-edit"]`);t&&(this.closeAlignmentPopover(),t.setAttribute(`aria-expanded`,`true`),this.root.setAttribute(`data-alt-open`,`true`),this.altPopoverDetach=Vs({anchor:t,value:(e=this.data.alt)==null?``:e,i18n:this.api.i18n,onSave:e=>{var n,r;this.altPopoverDetach=null,t.setAttribute(`aria-expanded`,`false`),(n=this.root)==null||n.removeAttribute(`data-alt-open`);let i=e.trim();i!==((r=this.data.alt)==null?``:r)&&(i===``?delete this.data.alt:this.data.alt=i,this.block.dispatchChange(),this.renderState())},onCancel:()=>{var e;this.altPopoverDetach=null,t.setAttribute(`aria-expanded`,`false`),(e=this.root)==null||e.removeAttribute(`data-alt-open`)}}))}deleteBlock(){var e;let t=this.api.blocks;t==null||(e=t.delete)==null||e.call(t,this.block.id)}download(){var e;let t=document.createElement(`a`);t.href=this.data.url,t.download=(e=this.data.fileName)==null?``:e,t.target=`_blank`,t.rel=`noopener`,document.body.appendChild(t),t.click(),t.remove()}copyUrl(){let e=navigator.clipboard;e&&typeof e.writeText==`function`&&e.writeText(this.data.url)}},G=e=>{let t=e.tagName;return t===`B`||t===`STRONG`},Js=e=>!!(e&&e.nodeType===Node.ELEMENT_NODE&&G(e)),Ys=e=>e.textContent.length===0,K=e=>e?e.nodeType===Node.ELEMENT_NODE&&G(e)?q(e):K(e.parentNode):null,q=e=>{if(e.tagName===`STRONG`)return e;let t=document.createElement(`strong`);for(e.hasAttributes()&&Array.from(e.attributes).forEach(e=>{t.setAttribute(e.name,e.value)});e.firstChild;)t.appendChild(e.firstChild);return e.replaceWith(t),t},Xs=e=>{let t=e.nextSibling;if((t==null?void 0:t.nodeType)===Node.TEXT_NODE)return t;let n=e.parentNode;if(!n)return null;let r=e.ownerDocument.createTextNode(``);return n.insertBefore(r,t),r},Zs=e=>{if(!e.boldElement.isConnected)return null;let t=q(e.boldElement),n=e.boundary,r=n.isConnected&&n.previousSibling===t?n:Xs(t);return r?{boundary:r,boldElement:t}:null},Qs=(e,t)=>e?e===t||t.contains(e):!1,$s,J={COLLAPSED_LENGTH:`data-blok-bold-collapsed-length`,COLLAPSED_ACTIVE:`data-blok-bold-collapsed-active`,PREV_LENGTH:`data-blok-bold-prev-length`,LEADING_WHITESPACE:`data-blok-bold-leading-ws`},Y=class e{constructor(){this.records=new Set}static getInstance(){return e.instance||(e.instance=new e),e.instance}static reset(){e.instance&&e.instance.records.clear(),e.instance=null}hasActiveRecords(){return this.records.size>0}isActivePlaceholder(e){return e.getAttribute(J.COLLAPSED_ACTIVE)===`true`||e.hasAttribute(J.COLLAPSED_LENGTH)}static get ATTR(){return J}enter(e,t){if(!e.collapsed)return;let n=document.createElement(`strong`),r=document.createTextNode(``);n.appendChild(r),n.setAttribute(J.COLLAPSED_ACTIVE,`true`);let i=e.startContainer,a=e.startOffset;if(!(i.nodeType===Node.TEXT_NODE?this.insertCollapsedBoldIntoText(i,n,a):i.nodeType===Node.ELEMENT_NODE&&(this.insertCollapsedBoldIntoElement(i,n,a),!0)))return;let o=document.createRange();o.setStart(r,0),o.collapse(!0);let s=t(n);return s.firstChild instanceof Text?(()=>{let e=document.createRange();return e.setStart(s.firstChild,s.firstChild.textContent.length),e.collapse(!0),e})():o}insertCollapsedBoldIntoText(e,t,n){let r=e.parentNode;if(!r)return!1;let i=e.textContent,a=i.slice(0,n),o=i.slice(n);e.textContent=a;let s=o.length?document.createTextNode(o):null;return s&&r.insertBefore(s,e.nextSibling),r.insertBefore(t,s==null?e.nextSibling:s),t.setAttribute(J.PREV_LENGTH,a.length.toString()),!0}insertCollapsedBoldIntoElement(e,t,n){var r;let i=(r=e.childNodes[n])==null?null:r;e.insertBefore(t,i),t.setAttribute(J.PREV_LENGTH,`0`)}exit(e,t){let n=q(t),r=n.parentNode;if(r)return Ys(n)?this.removeEmptyBoldElement(e,n,r):this.exitBoldWithContent(e,n,r)}removeEmptyBoldElement(e,t,n){let r=document.createRange();return r.setStartBefore(t),r.collapse(!0),n.removeChild(t),e.removeAllRanges(),e.addRange(r),r}exitBoldWithContent(e,t,n){t.setAttribute(J.COLLAPSED_LENGTH,t.textContent.length.toString()),t.removeAttribute(J.PREV_LENGTH),t.removeAttribute(J.COLLAPSED_ACTIVE),t.removeAttribute(J.LEADING_WHITESPACE);let r=t.nextSibling,i=!r||r.nodeType!==Node.TEXT_NODE,a=i?document.createTextNode(`​`):null;a&&n.insertBefore(a,r);let o=a==null?r:a;!i&&o.textContent.length===0&&(o.textContent=`​`);let s=document.createRange(),c=o.textContent.startsWith(`​`)?1:0;return s.setStart(o,c),s.collapse(!0),e.removeAllRanges(),e.addRange(s),this.records.add({boundary:o,boldElement:t,allowedLength:t.textContent.length,hasLeadingSpace:!1,hasTypedContent:!1,leadingWhitespace:``}),s}maintain(){if(!(typeof document>`u`))for(let e of Array.from(this.records)){let t=Zs(e);if(!t){this.records.delete(e);continue}e.boundary=t.boundary,e.boldElement=t.boldElement,this.enforceTextBoundary(e),this.cleanupZeroWidthSpace(e),this.updateRecordState(e),this.checkForRecordDeletion(e)}}enforceTextBoundary(e){let{boundary:t,boldElement:n,allowedLength:r}=e,i=n.textContent;if(i.length>r){let e=i.slice(0,r),a=i.slice(r);n.textContent=e,t.textContent=a+t.textContent}}cleanupZeroWidthSpace(e){let{boundary:t}=e,n=t.textContent;n.length>1&&n.startsWith(`​`)&&(t.textContent=n.slice(1))}updateRecordState(e){let{boundary:t}=e,n=t.textContent.replace(/\u200B/g,``),r=n.match(/^\s+/),i=/\S/.test(n);r&&(e.hasLeadingSpace=!0,e.leadingWhitespace=r[0]),i&&(e.hasTypedContent=!0)}checkForRecordDeletion(e){let{boundary:t,boldElement:n,allowedLength:r}=e,i=t.textContent,a=i.replace(/\u200B/g,``),o=i.startsWith(`​`),s=/^\s/.test(a),c=e.hasTypedContent&&!o&&n.textContent.length<=r,l=e.hasLeadingSpace&&e.hasTypedContent&&!s;if(c&&l){let n=i.replace(/^[\u200B\s]+/,``);t.textContent=`${e.leadingWhitespace||` `}${n}`}c&&this.records.delete(e)}synchronize(e){var n,r;let i=(n=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:n,a=i&&i.nodeType===Node.ELEMENT_NODE?i:i==null?void 0:i.parentElement,o=(r=a==null?void 0:a.closest(t.Fr(t.Pr.editor)))==null?a==null?void 0:a.ownerDocument:r;if(!o)return;let s=`strong[${J.COLLAPSED_ACTIVE}="true"]`;o.querySelectorAll(s).forEach(t=>{var n;let r=t.getAttribute(J.PREV_LENGTH),i=t.previousSibling;if(!r||!i||i.nodeType!==Node.TEXT_NODE)return;let a=Number(r);if(!Number.isFinite(a))return;let o=i,s=o.textContent;if(s.length<=a)return;let c=s.slice(0,a),l=s.slice(a);o.textContent=c;let u=l.match(/^[\u00A0\s]+/);if(u&&!t.hasAttribute(J.LEADING_WHITESPACE)&&t.setAttribute(J.LEADING_WHITESPACE,u[0]),l.length===0)return;let d=t.textContent,f=d+l,p=(n=t.getAttribute(J.LEADING_WHITESPACE))==null?``:n,m=p.length>0&&d.length===0&&!f.startsWith(p)?p+f:f,h=document.createTextNode(m);for(;t.firstChild;)t.removeChild(t.firstChild);if(t.appendChild(h),!(e!=null&&e.isCollapsed)||!Qs(e.focusNode,o))return;let g=document.createRange(),_=h.textContent.length;g.setStart(h,_),g.collapse(!0),e.removeAllRanges(),e.addRange(g)})}enforceLengths(e){var n;let r=(n=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:n;if(!r)return;let i=r.nodeType===Node.ELEMENT_NODE?r:r.parentElement,a=i==null?void 0:i.closest(t.Fr(t.Pr.editor));a&&a.querySelectorAll(`strong[${J.COLLAPSED_LENGTH}]`).forEach(t=>{var n;let r=t.getAttribute(J.COLLAPSED_LENGTH);if(!r)return;let i=Number(r),a=t.textContent;if(!Number.isFinite(i))return;let o=a.length>i,s=o?this.splitCollapsedBoldText(t,i,a):null,c=t.getAttribute(J.PREV_LENGTH),l=c?Number(c):NaN,u=t.previousSibling,d=(u==null?void 0:u.nodeType)===Node.TEXT_NODE?u:null,f=(n=d==null?void 0:d.textContent)==null?``:n,p=!!(c&&Number.isFinite(l)&&d&&f.length>l);if(p&&d){var m;let e=f.slice(0,l),n=f.slice(l);d.textContent=e;let r=document.createTextNode(n);(m=t.parentNode)==null||m.insertBefore(r,t.nextSibling)}if(p&&t.removeAttribute(J.PREV_LENGTH),e!=null&&e.isCollapsed&&s&&Qs(e.focusNode,t)){let t=document.createRange(),n=s.textContent.length;t.setStart(s,n),t.collapse(!0),e.removeAllRanges(),e.addRange(t)}o&&t.removeAttribute(J.COLLAPSED_LENGTH)})}splitCollapsedBoldText(e,t,n){let r=e.parentNode;if(!r)return null;let i=n.slice(0,t),a=n.slice(t);e.textContent=i;let o=document.createTextNode(a);return r.insertBefore(o,e.nextSibling),o}guardBoundaryKeydown(e){if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey||e.key.length!==1)return;let t=window.getSelection();if(!t||!t.isCollapsed||t.rangeCount===0)return;let n=t.getRangeAt(0);if(n.startContainer.nodeType!==Node.TEXT_NODE)return;let r=n.startContainer,i=r.textContent;if(i.length===0||n.startOffset!==0)return;let a=r.previousSibling;if(!a||a.nodeType!==Node.ELEMENT_NODE)return;let o=a;o.tagName!==`STRONG`&&o.tagName!==`B`||/^\s/.test(i)&&this.setCaret(t,r,i.length)}setCaret(e,t,n){let r=document.createRange();r.setStart(t,n),r.collapse(!0),e.removeAllRanges(),e.addRange(r)}moveCaretAfterBoundaryBold(e){if(!e.rangeCount)return;let t=e.getRangeAt(0);if(!t.collapsed)return;let n=K(t.startContainer);(n==null?void 0:n.getAttribute(J.COLLAPSED_ACTIVE))!==`true`&&(this.moveCaretFromElementContainer(e,t)||this.moveCaretFromTextContainer(e,t))}moveCaretFromElementContainer(e,t){if(t.startContainer.nodeType!==Node.ELEMENT_NODE)return!1;let n=t.startContainer;return this.moveCaretAfterPreviousBold(e,n,t.startOffset)?!0:this.moveCaretBeforeNextBold(e,n,t.startOffset)}moveCaretAfterPreviousBold(e,t,n){var r;let i=n>0?(r=t.childNodes[n-1])==null?null:r:null;if(!this.isBoldElement(i)||!i)return!1;let a=this.ensureFollowingTextNode(i,i.nextSibling);if(!a)return!1;let o=a.textContent.length;return this.setCaret(e,a,o),!0}moveCaretBeforeNextBold(e,t,n){var r;let i=(r=t.childNodes[n])==null?null:r;if(!this.isBoldElement(i))return!1;let a=this.ensureFollowingTextNode(i,i.nextSibling);return a?(this.setCaret(e,a,0),!0):(this.setCaretAfterNode(e,i),!0)}moveCaretFromTextContainer(e,t){if(t.startContainer.nodeType!==Node.TEXT_NODE)return;let n=t.startContainer,r=n.previousSibling,i=n.textContent,a=/^\s/.test(i);if(t.startOffset===0&&this.isBoldElement(r)&&(i.length===0||a)){this.setCaret(e,n,i.length);return}let o=K(n);if(!o||t.startOffset!==n.textContent.length)return;let s=this.ensureFollowingTextNode(o,o.nextSibling);if(s){this.setCaret(e,s,0);return}this.setCaretAfterNode(e,o)}setCaretAfterNode(e,t){if(!t)return;let n=document.createRange();n.setStartAfter(t),n.collapse(!0),e.removeAllRanges(),e.addRange(n)}ensureFollowingTextNode(e,t){let n=e.parentNode;if(!n)return null;if(t&&t.nodeType===Node.TEXT_NODE)return t;let r=document.createTextNode(``);return n.insertBefore(r,t),r}isBoldElement(e){if(!e||e.nodeType!==Node.ELEMENT_NODE)return!1;let t=e;return t.tagName===`STRONG`||t.tagName===`B`}};$s=Y,$s.instance=null;var ec={convertLegacyTags:!0,normalizeWhitespace:!0,removeEmpty:!0,mergeAdjacent:!0,preserveNode:null},X=class e{constructor(e){this.options=n.t(n.t({},ec),e)}run(e){if(typeof document>`u`)return;let{bElements:t,strongElements:n}=this.traverseAndNormalize(e);this.processCollectedElements(t,n)}static normalizeAroundSelection(t,n){let r=e.findScopeFromSelection(t);r&&new e(n).run(r)}traverseAndNormalize(e){let t=[],n=[],r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT,null);for(let e=r.currentNode;e;e=r.nextNode())this.processNode(e,t,n);return{bElements:t,strongElements:n}}processNode(e,t,n){if(e.nodeType===Node.TEXT_NODE&&this.options.normalizeWhitespace){this.replaceNbspInTextNode(e);return}if(e.nodeType!==Node.ELEMENT_NODE)return;let r=e;if(this.options.convertLegacyTags&&r.tagName===`B`){t.push(r);return}r.tagName===`STRONG`&&n.push(r)}processCollectedElements(e,t){this.options.convertLegacyTags&&e.forEach(e=>{if(e.isConnected){let n=q(e);t.push(n)}}),t.forEach(e=>{if(e.isConnected){if(this.options.removeEmpty&&this.isEmptyAndSafe(e)){e.remove();return}this.options.mergeAdjacent&&this.mergeWithAdjacent(e)}})}replaceNbspInTextNode(e){let t=e.textContent;t.includes(`\xA0`)&&(e.textContent=t.replace(/\u00A0/g,` `))}isEmptyAndSafe(e){return e.textContent.length!==0||Y.getInstance().isActivePlaceholder(e)?!1:!(this.options.preserveNode&&Qs(this.options.preserveNode,e))}mergeWithAdjacent(e){let t=e.previousSibling;if(t&&Js(t)){this.mergeStrongNodes(t,e);return}let n=e.nextSibling;n&&Js(n)&&this.mergeStrongNodes(e,n)}mergeStrongNodes(e,t){let n=q(e),r=q(t);for(;r.firstChild;)n.appendChild(r.firstChild);r.remove()}static findScopeFromSelection(e){var n,r;let i=(n=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:n;if(!i)return null;let a=i.nodeType===Node.ELEMENT_NODE?i:i.parentElement;return a?((r=a.closest(`[data-blok-component="paragraph"]`))==null?a.closest(t.Fr(t.Pr.elementContent)):r)||a.closest(t.Fr(t.Pr.editor)):null}},tc,nc=class e{constructor(){this.handlers=new Map,this.listenersRegistered=!1,this.handleSelectionChange=()=>{let e=this.getSelection();e&&this.handlers.forEach(t=>{var n;t.isRelevant&&!t.isRelevant(e)||(n=t.onSelectionChange)==null||n.call(t,e)})},this.handleInput=e=>{let t=this.getSelection();t&&this.handlers.forEach(n=>{var r;n.isRelevant&&!n.isRelevant(t)||(r=n.onInput)==null||r.call(n,e,t)})},this.handleBeforeInput=e=>{let t=e,n=this.getSelection();n&&this.handlers.forEach(r=>{var i;r.isRelevant&&!r.isRelevant(n)||(i=r.onBeforeInput)!=null&&i.call(r,t,n)&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation())})},this.handleKeydown=e=>{let t=this.getSelection();!t||!t.rangeCount||this.handlers.forEach(n=>{!n.shortcut||!n.onShortcut||this.matchesShortcut(e,n.shortcut)&&(n.isRelevant&&!n.isRelevant(t)||(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),n.onShortcut(e,t)))})},this.initializeListeners()}static getInstance(){return e.instance||(e.instance=new e),e.instance}static reset(){e.instance&&(e.instance.removeListeners(),e.instance.handlers.clear()),e.instance=null}register(e,t){this.handlers.set(e,t)}unregister(e){this.handlers.delete(e)}hasHandler(e){return this.handlers.has(e)}initializeListeners(){typeof document>`u`||this.listenersRegistered||(document.addEventListener(`selectionchange`,this.handleSelectionChange,!0),document.addEventListener(`input`,this.handleInput,!0),document.addEventListener(`beforeinput`,this.handleBeforeInput,!0),document.addEventListener(`keydown`,this.handleKeydown,!0),this.listenersRegistered=!0)}removeListeners(){typeof document>`u`||!this.listenersRegistered||(document.removeEventListener(`selectionchange`,this.handleSelectionChange,!0),document.removeEventListener(`input`,this.handleInput,!0),document.removeEventListener(`beforeinput`,this.handleBeforeInput,!0),document.removeEventListener(`keydown`,this.handleKeydown,!0),this.listenersRegistered=!1)}getSelection(){return typeof window<`u`?window.getSelection():null}matchesShortcut(e,t){if(e.key.toLowerCase()!==t.key.toLowerCase()||e.altKey)return!1;let n=(typeof navigator<`u`?navigator.userAgent.toLowerCase():``).includes(`mac`)?e.metaKey:e.ctrlKey;return!(t.meta&&!n||t.ctrl&&!e.ctrlKey)}};tc=nc,tc.instance=null;var rc=(e,t)=>{try{return e.intersectsNode(t)}catch(n){let r=document.createRange();r.selectNodeContents(t);let i=e.compareBoundaryPoints(Range.END_TO_START,r)>0,a=e.compareBoundaryPoints(Range.START_TO_END,r)<0;return i&&a}},ic=e=>{var t;let n=e.commonAncestorContainer,r=n.nodeType===Node.TEXT_NODE?(t=n.parentNode)==null?n:t:n;return document.createTreeWalker(r,NodeFilter.SHOW_TEXT,{acceptNode:t=>rc(e,t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT})},Z=(e,t,n)=>!e||e===n?null:e.nodeType===Node.ELEMENT_NODE&&t(e)?e:Z(e.parentNode,t,n),ac=(e,t)=>Z(e,t)!==null,oc=(e,t,n={})=>{if(e.collapsed)return Z(e.startContainer,t)!==null;let r=ic(e),i=[];for(;r.nextNode();){let e=r.currentNode,t=e.textContent;n.ignoreWhitespace&&t.trim().length===0||t.length!==0&&i.push(e)}return i.length===0?Z(e.startContainer,t)!==null:i.every(e=>ac(e,t))},sc=e=>{let t=e.lastChild;return t===null?e.nodeType===Node.TEXT_NODE?e:null:sc(t)},cc=e=>{var t;let n=e.endContainer;if(n.nodeType===Node.TEXT_NODE){var r;let t=(r=n.textContent)==null?``:r,i=e.endOffset;if(i>=t.length)return;let a=t.slice(i);a.length>0&&a.trim().length===0&&e.setEnd(n,t.length);return}let i=sc(n);if(i===null)return;let a=(t=i.textContent)==null?``:t;a.length!==0&&/\s+$/.test(a)&&e.setEnd(i,a.length)},Q=(e,t)=>{let n=new Set,r=ic(e);for(;r.nextNode();){let e=Z(r.currentNode,t);e&&n.add(e)}return Array.from(n)},$,lc=class e{static get sanitize(){return{strong:{},b:{}}}constructor(){typeof document>`u`||(e.instances.add(this),e.initializeGlobalListeners())}static initializeGlobalListeners(){if(typeof document>`u`)return!1;let t=nc.getInstance();return t.hasHandler(`bold`)?!0:(t.register(`bold`,{shortcut:{key:`b`,meta:!0},onShortcut:(t,n)=>{let r=e.instances.values().next().value;r&&r.toggleBold()},onSelectionChange:t=>{e.refreshSelectionState(`selectionchange`)},onInput:(t,n)=>{e.refreshSelectionState(`input`)},onBeforeInput:e=>e.inputType===`formatBold`?(X.normalizeAroundSelection(window.getSelection()),!0):!1,isRelevant:t=>e.isSelectionInsideBlok(t)}),e.guardKeydownListenerRegistered||(document.addEventListener(`keydown`,e=>{Y.getInstance().guardBoundaryKeydown(e)},!0),e.guardKeydownListenerRegistered=!0),e.ensureMutationObserver(),!0)}static mergeStrongNodes(e,t){let n=q(e),r=q(t);for(;r.firstChild;)n.appendChild(r.firstChild);return r.remove(),n}render(){return{icon:t.A,name:`bold`,onActivate:()=>{this.toggleBold()},isActive:()=>{let e=window.getSelection();return e?this.isSelectionVisuallyBold(e):!1}}}toggleBold(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed){this.toggleCollapsedSelection();return}this.isRangeBold(t,{ignoreWhitespace:!0})?this.unwrapBoldTags(t):this.wrapWithBold(t)}isSelectionVisuallyBold(e){if(e.rangeCount===0)return!1;let t=e.getRangeAt(0);return this.isRangeBold(t,{ignoreWhitespace:!0})}wrapWithBold(e){cc(e);let t=this.getRangeHtmlWithoutBold(e),n=this.replaceRangeWithHtml(e,`<strong>${t}</strong>`),r=window.getSelection();r&&n&&(r.removeAllRanges(),r.addRange(n));let i=this.findBoldElementFromRangeOrSelection(n,r);if(!i){X.normalizeAroundSelection(r),this.notifySelectionChange();return}let a=this.mergeAdjacentBold(i);this.selectElementContents(a),X.normalizeAroundSelection(r),this.notifySelectionChange()}unwrapBoldTags(t){let n=this.collectBoldAncestors(t),r=window.getSelection();if(!r)return;let i=document.createElement(`span`),a=t.extractContents();i.setAttribute(`data-blok-bold-marker`,`unwrap-${e.markerSequence++}`),i.appendChild(a),this.removeNestedBold(i),t.insertNode(i);let o=document.createRange();for(o.selectNodeContents(i),r.removeAllRanges(),r.addRange(o);;){let e=K(i);if(!e)break;this.moveMarkerOutOfBold(i,e)}let s=i.firstChild,c=i.lastChild;this.unwrapElement(i),s&&c&&(()=>{let e=document.createRange();return e.setStartBefore(s),e.setEndAfter(c),r.removeAllRanges(),r.addRange(e),e})()||r.removeAllRanges(),X.normalizeAroundSelection(r),n.forEach(e=>{e.isConnected&&(Ys(e)?e.remove():e.textContent.trim().length===0&&this.unwrapElement(e))}),this.notifySelectionChange()}replaceRangeWithHtml(t,n){var r,i;let a=e.createFragmentFromHtml(n),o=(r=a.firstChild)==null?null:r,s=(i=a.lastChild)==null?null:i;if(t.deleteContents(),!o||!s)return;t.insertNode(a);let c=document.createRange();return c.setStartBefore(o),c.setEndAfter(s),c}moveMarkerOutOfBold(e,t){let n=t.parentNode;if(!n)return;if(Array.from(t.childNodes).forEach(e=>{var t;e.nodeType===Node.TEXT_NODE&&((t=e.textContent)==null?``:t).length===0&&e.remove()}),t.childNodes.length===1&&t.firstChild===e){t.replaceWith(e);return}if(t.firstChild===e){n.insertBefore(e,t);return}if(t.lastChild===e){n.insertBefore(e,t.nextSibling);return}let r=t.cloneNode(!1);for(;e.nextSibling;)r.appendChild(e.nextSibling);n.insertBefore(r,t.nextSibling),n.insertBefore(e,r)}selectElementContents(e){let t=window.getSelection();if(!t)return;let n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}isRangeBold(e,t){return oc(e,G,t)}removeNestedBold(e){e.querySelectorAll(`b,strong`).forEach(e=>{this.unwrapElement(e)})}unwrapElement(e){let t=e.parentNode;if(!t){e.remove();return}for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}findBoldElementFromRangeOrSelection(e,t){return e?K(e.startContainer)||K(e.commonAncestorContainer)||(e.startContainer.nodeType===Node.ELEMENT_NODE&&G(e.startContainer)?e.startContainer:null):t?K(t.focusNode):null}mergeAdjacentBold(t){let n=q(t),r=n.previousSibling,i=r&&r.nodeType===Node.ELEMENT_NODE&&G(r)?e.mergeStrongNodes(r,n):n,a=i.nextSibling;return a&&a.nodeType===Node.ELEMENT_NODE&&G(a)?e.mergeStrongNodes(i,a):i}toggleCollapsedSelection(){let t=window.getSelection();if(!t||t.rangeCount===0)return;let n=t.getRangeAt(0),r=K(n.startContainer),i=(()=>{if(r&&r.getAttribute(Y.ATTR.COLLAPSED_ACTIVE)!==`true`)return Y.getInstance().exit(t,r);let i=r==null?e.getBoundaryBold(n):r;return i?Y.getInstance().exit(t,i):this.startCollapsedBold(n)})();document.dispatchEvent(new Event(`selectionchange`)),i&&(t.removeAllRanges(),t.addRange(i)),X.normalizeAroundSelection(t),this.notifySelectionChange()}startCollapsedBold(e){let t=Y.getInstance().enter(e,e=>this.mergeAdjacentBold(e)),n=window.getSelection();return X.normalizeAroundSelection(n),n&&t&&(n.removeAllRanges(),n.addRange(t)),this.notifySelectionChange(),t}notifySelectionChange(){Y.getInstance().enforceLengths(window.getSelection()),document.dispatchEvent(new Event(`selectionchange`)),this.updateToolbarButtonState()}updateToolbarButtonState(){let e=window.getSelection();if(!e)return;let n=e.anchorNode,r=(n==null?void 0:n.nodeType)===Node.ELEMENT_NODE?n:n==null?void 0:n.parentElement,i=r==null?void 0:r.closest(t.Fr(t.Pr.editor));if(!i)return;let a=i.querySelector(`[data-blok-testid=inline-toolbar]`);if(!(a instanceof HTMLElement))return;let o=a.querySelector(`[data-blok-item-name="bold"]`);o instanceof HTMLElement&&(this.isSelectionVisuallyBold(e)?o.setAttribute(`data-blok-popover-item-active`,`true`):o.removeAttribute(`data-blok-popover-item-active`))}static refreshSelectionState(e){let t=window.getSelection();Y.getInstance().enforceLengths(t),Y.getInstance().maintain(),Y.getInstance().synchronize(t),X.normalizeAroundSelection(t,{normalizeWhitespace:!1}),e===`input`&&t&&Y.getInstance().moveCaretAfterBoundaryBold(t)}static ensureMutationObserver(){if(typeof MutationObserver>`u`||e.mutationObserver)return;let t=new MutationObserver(t=>{if(!e.isProcessingMutation){e.isProcessingMutation=!0;try{let n=e=>{e&&new X({mergeAdjacent:!1,removeEmpty:!1,normalizeWhitespace:!1}).run(e)};t.forEach(t=>{t.addedNodes.forEach(t=>{n(e.findBlokScopeFromNode(t))}),t.type===`characterData`&&n(e.findBlokScopeFromNode(t.target))})}finally{e.isProcessingMutation=!1}}});t.observe(document.body,{subtree:!0,childList:!0,characterData:!0}),e.mutationObserver=t}static findBlokScopeFromNode(e){let n=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return!n||typeof n.closest!=`function`?null:n.closest(`${t.Fr(t.Pr.interface)}, ${t.Fr(t.Pr.editor)}`)}static getBoundaryBold(t){let n=t.startContainer;return n.nodeType===Node.TEXT_NODE?e.getBoundaryBoldForText(t,n):n.nodeType===Node.ELEMENT_NODE?e.getBoundaryBoldForElement(t,n):null}static getBoundaryBoldForText(e,t){let n=t.textContent.length;if(e.startOffset===n)return K(t);if(e.startOffset!==0)return null;let r=t.previousSibling;return Js(r)?r:null}static getBoundaryBoldForElement(e,t){if(e.startOffset<=0)return null;let n=t.childNodes[e.startOffset-1];return Js(n)?n:null}static isSelectionInsideBlok(e){let n=e.anchorNode;if(!n)return!1;let r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return!!(r!=null&&r.closest(t.Fr(t.Pr.editor)))}getRangeHtmlWithoutBold(e){let t=e.cloneContents();this.removeNestedBold(t);let n=document.createElement(`div`);return n.appendChild(t),n.innerHTML}static createFragmentFromHtml(e){let t=document.createElement(`template`);return t.innerHTML=e,t.content}collectBoldAncestors(e){return Q(e,G)}};$=lc,$.isInline=!0,$.title=`Bold`,$.titleKey=`bold`,$.markerSequence=0,$.isProcessingMutation=!1,$.instances=new Set,$.guardKeydownListenerRegistered=!1,$.shortcut=`CMD+B`;var uc,dc=e=>{let t=e.tagName;return t===`I`||t===`EM`},fc=class{static get sanitize(){return{i:{},em:{}}}render(){return{icon:t.Et,name:`italic`,onActivate:()=>{this.toggleItalic()},isActive:()=>{let e=window.getSelection();return e?this.isSelectionVisuallyItalic(e):!1}}}toggleItalic(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed){this.toggleCollapsedItalic(t,e);return}this.isRangeItalic(t,{ignoreWhitespace:!0})?this.unwrapItalicTags(t):this.wrapWithItalic(t)}toggleCollapsedItalic(e,t){if(this.isRangeItalic(e,{ignoreWhitespace:!0})){let n=document.createTextNode(`​`);e.insertNode(n),e.selectNode(n),this.unwrapItalicTags(e);let r=document.createRange();r.setStart(n,1),r.setEnd(n,1),t.removeAllRanges(),t.addRange(r)}else{let n=document.createElement(`i`),r=document.createTextNode(`​`);n.appendChild(r),e.insertNode(n);let i=document.createRange();i.setStart(r,1),i.setEnd(r,1),t.removeAllRanges(),t.addRange(i)}}isSelectionVisuallyItalic(e){if(e.rangeCount===0)return!1;let t=e.getRangeAt(0);return this.isRangeItalic(t,{ignoreWhitespace:!0})}isRangeItalic(e,t){return oc(e,dc,t)}wrapWithItalic(e){cc(e);let t=this.getRangeHtmlWithoutItalic(e),n=this.replaceRangeWithHtml(e,`<i>${t}</i>`),r=window.getSelection();if(r&&n){let e=n.startContainer.childNodes[n.startOffset],t=document.createRange();e?(this.normalizeNbspInElement(e),t.selectNodeContents(e)):(t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)),r.removeAllRanges(),r.addRange(t)}}normalizeNbspInElement(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(;;){var n;let e=t.nextNode();if(e===null)break;(n=e.textContent)!=null&&n.includes(`\xA0`)&&(e.textContent=e.textContent.replace(/\u00A0/g,` `))}}unwrapItalicTags(e){let t=this.collectItalicAncestors(e),n=window.getSelection();if(!n)return;let r=document.createElement(`span`),i=e.extractContents();r.appendChild(i),this.removeNestedItalic(r),e.insertNode(r);let a=document.createRange();for(a.selectNodeContents(r),n.removeAllRanges(),n.addRange(a);;){let e=this.findItalicElement(r);if(!e)break;this.moveMarkerOutOfItalic(r,e)}let o=r.firstChild,s=r.lastChild;this.unwrapElement(r),o&&s&&(()=>{let e=document.createRange();return e.setStartBefore(o),e.setEndAfter(s),n.removeAllRanges(),n.addRange(e),e})()||n.removeAllRanges(),t.forEach(e=>{e.textContent.length===0&&e.remove()})}hasItalicParent(e){return ac(e,dc)}findItalicElement(e){return Z(e,dc)}collectItalicAncestors(e){return Q(e,dc)}getRangeHtmlWithoutItalic(e){let t=e.cloneContents();this.removeNestedItalic(t);let n=document.createElement(`div`);return n.appendChild(t),n.innerHTML}removeNestedItalic(e){e.querySelectorAll(`i,em`).forEach(e=>{this.unwrapElement(e)})}unwrapElement(e){let t=e.parentNode;if(!t){e.remove();return}for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}replaceRangeWithHtml(e,t){var n,r;let i=this.createFragmentFromHtml(t),a=(n=i.firstChild)==null?null:n,o=(r=i.lastChild)==null?null:r;if(e.deleteContents(),!a||!o)return;e.insertNode(i);let s=document.createRange();return s.setStartBefore(a),s.setEndAfter(o),s}createFragmentFromHtml(e){let t=document.createElement(`template`);return t.innerHTML=e,t.content}moveMarkerOutOfItalic(e,t){let n=t.parentNode;if(!n)return;if(Array.from(t.childNodes).forEach(e=>{var t;e.nodeType===Node.TEXT_NODE&&((t=e.textContent)==null?``:t).length===0&&e.remove()}),t.childNodes.length===1&&t.firstChild===e){t.replaceWith(e);return}if(t.firstChild===e){n.insertBefore(e,t);return}if(t.lastChild===e){n.insertBefore(e,t.nextSibling);return}let r=t.cloneNode(!1);for(;e.nextSibling;)r.appendChild(e.nextSibling);n.insertBefore(r,t.nextSibling),n.insertBefore(e,r)}};uc=fc,uc.isInline=!0,uc.title=`Italic`,uc.titleKey=`italic`,uc.shortcut=`CMD+I`;var pc,mc=`flex items-center gap-2 w-full mt-0.5 px-1.5 py-1.5 rounded-md text-left cursor-pointer can-hover:hover:bg-item-hover-bg transition-colors`,hc=`flex items-center gap-2 w-full mt-0.5 px-1.5 py-1.5 rounded-md text-left pointer-events-none`,gc=class{static get sanitize(){return{a:{href:!0,target:`_blank`,rel:`nofollow`}}}constructor({api:e}){this.INPUT_BASE_CLASSES=`hidden w-[200px] m-0 px-2 py-1 text-sm leading-[22px] font-medium text-text-primary bg-item-hover-bg border border-link-input-border rounded-lg! outline-hidden box-border appearance-none font-[inherit] placeholder:text-gray-text mobile:text-[15px] mobile:font-medium`,this.DATA_ATTRIBUTES={buttonActive:`data-blok-link-tool-active`,buttonUnlink:`data-blok-link-tool-unlink`,inputOpened:`data-blok-link-tool-input-opened`},this.nodes={input:null,inputWrapper:null,suggestion:null,button:null},this.inputOpened=!1,this.unlinkAvailable=!1,this.handleButtonClick=e=>{!this.inputOpened||!this.unlinkAvailable||(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),this.restoreSelection(),this.unlink(),this.inlineToolbar.close())},this.toolbar=e.toolbar,this.inlineToolbar=e.inlineToolbar,this.notifier=e.notifier,this.i18n=e.i18n,this.selection=new t.Rn,this.nodes.input=this.createInput(),this.nodes.suggestion=this.createSuggestion(),this.nodes.inputWrapper=document.createElement(`div`),this.nodes.inputWrapper.append(this.nodes.input,this.nodes.suggestion)}render(){return{icon:t.Dt,name:`link`,isActive:()=>!!this.selection.findParentTag(`A`),children:{hideChevron:!0,items:[{type:t.Ln.Html,element:this.nodes.inputWrapper}],onOpen:()=>{this.openActions(!0)},onClose:()=>{this.closeActions()}}}}createInput(){let e=document.createElement(`input`);return e.placeholder=this.i18n.t(`tools.link.addLink`),e.enterKeyHint=`done`,e.className=this.INPUT_BASE_CLASSES,e.setAttribute(`data-blok-testid`,`inline-tool-input`),this.setBooleanStateAttribute(e,this.DATA_ATTRIBUTES.inputOpened,!1),e.addEventListener(`keydown`,e=>{e.key===`Enter`&&this.enterPressed(e)}),e.addEventListener(`paste`,()=>{requestAnimationFrame(()=>{this.updateSuggestion(e.value)})}),e.addEventListener(`input`,()=>{this.updateSuggestion(e.value)}),e}createSuggestion(){let e=document.createElement(`div`);e.className=`hidden`,e.setAttribute(`data-link-suggestion`,``);let t=document.createElement(`div`);t.className=`mt-1 mb-0.5 h-px bg-link-input-border`;let n=document.createElement(`button`);n.type=`button`,n.className=mc,n.setAttribute(`data-link-suggestion-row`,``);let r=document.createElement(`span`);r.className=`text-gray-text shrink-0 flex [&>svg]:size-7`,r.setAttribute(`data-link-suggestion-icon`,``);let i=document.createElement(`span`);i.className=`flex-1 min-w-0`;let a=document.createElement(`span`);a.className=`block text-xs font-medium text-text-primary truncate`,a.setAttribute(`data-link-suggestion-url`,``);let o=document.createElement(`span`);return o.className=`block text-[10.5px] text-gray-text leading-tight mt-px`,o.setAttribute(`data-link-suggestion-type`,``),i.append(a,o),n.append(r,i),e.append(t,n),n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>this.confirmLink()),e}updateSuggestion(e){if(!this.nodes.suggestion)return;let t=e.trim();if(!t){this.nodes.suggestion.classList.add(`hidden`);return}let n=this.isLinkComplete(t),{icon:r,label:i}=this.getLinkTypeInfo(t),a=this.nodes.suggestion.querySelector(`[data-link-suggestion-icon]`),o=this.nodes.suggestion.querySelector(`[data-link-suggestion-url]`),s=this.nodes.suggestion.querySelector(`[data-link-suggestion-type]`),c=this.nodes.suggestion.querySelector(`[data-link-suggestion-row]`);a&&(a.innerHTML=r,a.className=`${n?`text-gray-text`:`text-gray-text opacity-40`} shrink-0 flex [&>svg]:size-7`),o&&(o.textContent=t,o.className=`block text-xs font-medium truncate ${n?`text-text-primary`:`text-gray-text`}`),s&&(s.textContent=n?i:`Keep typing to add a link`,s.className=`block text-[10.5px] text-gray-text leading-tight mt-px`),c&&(c.className=n?mc:hc),this.nodes.suggestion.classList.remove(`hidden`)}isLinkComplete(e){return/^https?:\/\//i.test(e)?e.replace(/^https?:\/\//i,``).length>0:/^\w+:\/\//.test(e)?e.replace(/^\w+:\/\//,``).length>0:/^\w+:/.test(e)?e.slice(e.indexOf(`:`)+1).length>0:e.startsWith(`//`)?e.slice(2).length>0:e.startsWith(`#`)?e.length>1:e.startsWith(`/`)?!0:/\.[a-zA-Z]{2,}/.test(e)||/^\d{1,3}(\.\d{1,3}){3}/.test(e)}getLinkTypeInfo(e){return e.startsWith(`mailto:`)?{icon:t.Pt,label:`Email address`}:e.startsWith(`#`)?{icon:t.mt,label:`Jump to section`}:{icon:t.st,label:`Link to web page`}}confirmLink(){if(!this.nodes.input)return;let e=this.nodes.input.value||``;if(!e.trim()||!this.isLinkComplete(e.trim()))return;if(!this.validateURL(e)){this.notifier.show({message:this.i18n.t(`tools.link.invalidLink`),style:`error`});return}let t=this.prepareLink(e);this.selection.removeFakeBackground(),this.selection.restore(),this.insertLink(t),this.selection.collapseToEnd(),this.inlineToolbar.close()}openActions(e=!1){if(!this.nodes.input)return;let t=this.selection.findParentTag(`A`),n=!!t;if(this.updateButtonStateAttributes(n),this.unlinkAvailable=n,t){let e=t.getAttribute(`href`);this.nodes.input.value=e===null?``:e}else this.nodes.input.value=``;this.updateSuggestion(this.nodes.input.value),this.nodes.input.className=r.n(this.INPUT_BASE_CLASSES,`block`),this.setBooleanStateAttribute(this.nodes.input,this.DATA_ATTRIBUTES.inputOpened,!0),this.selection.setFakeBackground(),this.selection.save(),e&&this.focusInputWithRetry(),this.inputOpened=!0}focusInputWithRetry(){this.nodes.input&&(this.nodes.input.focus(),!(typeof window>`u`||typeof document>`u`)&&window.setTimeout(()=>{if(document.activeElement!==this.nodes.input){var e;(e=this.nodes.input)==null||e.focus()}},0))}getButtonElement(){let e=document.querySelector(`${t.Fr(t.Pr.interface,t.Vn)} [data-blok-item-name="link"]`);return e&&e!==this.nodes.button&&(e.addEventListener(`click`,this.handleButtonClick,!0),this.nodes.button=e),e}updateButtonStateAttributes(e){let t=this.getButtonElement();if(!t)return;let n=typeof e==`boolean`?e:!!this.selection.findParentTag(`A`);this.setBooleanStateAttribute(t,this.DATA_ATTRIBUTES.buttonActive,n),this.setBooleanStateAttribute(t,this.DATA_ATTRIBUTES.buttonUnlink,n)}closeActions(e=!0){var t;(this.selection.isFakeBackgroundEnabled||e&&this.selection.savedSelectionRange)&&this.restoreSelection(),this.nodes.input&&(this.nodes.input.className=this.INPUT_BASE_CLASSES,this.setBooleanStateAttribute(this.nodes.input,this.DATA_ATTRIBUTES.inputOpened,!1),this.nodes.input.value=``,(t=this.nodes.suggestion)==null||t.classList.add(`hidden`),this.updateButtonStateAttributes(!1),this.unlinkAvailable=!1,e&&this.selection.clearSaved(),this.inputOpened=!1)}restoreSelection(){let e=new t.Rn,n=t.Rn.isAtBlok;if(n&&e.save(),this.selection.removeFakeBackground(),this.selection.restore(),!n&&this.selection.savedSelectionRange){let e=this.selection.savedSelectionRange.commonAncestorContainer,t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;t==null||t.focus()}if(!n)return;e.restore();let r=e.savedSelectionRange;if(r){let e=r.commonAncestorContainer,t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;t==null||t.focus()}}enterPressed(e){if(!this.nodes.input)return;let n=this.nodes.input.value||``;if(!n.trim()){this.selection.restore(),this.unlink(),e.preventDefault(),this.closeActions(),this.inlineToolbar.close();return}if(!this.validateURL(n)){this.notifier.show({message:this.i18n.t(`tools.link.invalidLink`),style:`error`}),t.Or(`Incorrect Link pasted`,`warn`,n);return}let r=this.prepareLink(n);this.selection.removeFakeBackground(),this.selection.restore(),this.insertLink(r),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),this.selection.collapseToEnd(),this.inlineToolbar.close()}validateURL(e){return!/\s/.test(e)}prepareLink(e){return this.addProtocol(e.trim())}addProtocol(e){if(/^(\w+):(\/\/)?/.test(e))return e;let t=/^\/[^/\s]/.test(e),n=e.substring(0,1)===`#`,r=/^\/\/[^/\s]/.test(e);return!t&&!n&&!r?`http://`+e:e}insertLink(e){let n=this.selection.findParentTag(`A`);if(n instanceof HTMLAnchorElement){this.selection.expandToTag(n),n.href=e,n.target=`_blank`,n.rel=`nofollow`;return}let r=t.Rn.range;if(!r)return;let i=document.createElement(`a`);i.href=e,i.target=`_blank`,i.rel=`nofollow`,i.appendChild(r.extractContents()),r.insertNode(i),this.selection.expandToTag(i)}unlink(){let e=this.selection.findParentTag(`A`);e&&(this.unwrap(e),this.updateButtonStateAttributes(!1),this.unlinkAvailable=!1)}unwrap(e){var t;let n=document.createDocumentFragment();for(;e.firstChild;)n.appendChild(e.firstChild);(t=e.parentNode)==null||t.replaceChild(n,e)}setBooleanStateAttribute(e,t,n){e&&e.setAttribute(t,n?`true`:`false`)}};pc=gc,pc.isInline=!0,pc.title=`Link`,pc.titleKey=`link`,pc.shortcut=`CMD+K`;var _c=e=>e.tagName===`MARK`,vc=e=>Z(e,_c),yc,bc={color:`background-color`,"background-color":`color`},xc=class e{static get sanitize(){return{mark:t=>{let n=t.style,r=Array.from({length:n.length},(e,t)=>n.item(t));for(let t of r)e.ALLOWED_STYLE_PROPS.has(t)||n.removeProperty(t);return n.getPropertyValue(`color`)&&!n.getPropertyValue(`background-color`)&&n.setProperty(`background-color`,`transparent`),n.length>0?{style:!0}:{}}}}constructor({api:e}){this.colorMode=`color`,this.activeTextColor=null,this.activeBgColor=null,this.i18n=e.i18n,this.inlineToolbar=e.inlineToolbar,this.selection=new t.Rn,this.picker=Lt({i18n:this.i18n,testIdPrefix:`marker`,modes:[{key:`color`,labelKey:`tools.marker.textColor`,presetField:`text`},{key:`background-color`,labelKey:`tools.marker.background`,presetField:`bg`}],onColorSelect:(e,t)=>{this.colorMode=t,e===null?this.removeColor(this.colorMode):this.applyColor(this.colorMode,e),t===`color`?this.activeTextColor=e:this.activeBgColor=e,this.picker.setActiveColor(e,t),this.updateToolbarColors(this.activeTextColor,this.activeBgColor),this.selection.setFakeBackground(),this.selection.save()}})}render(){return{icon:t.Ft,name:`marker`,isActive:()=>{let e=window.getSelection();if(!e||e.rangeCount===0)return!1;let t=e.getRangeAt(0),n=oc(t,_c,{ignoreWhitespace:!0});if(n){let e=this.detectBothSelectionColors(t);this.updateToolbarColors(e.text,e.bg)}return n},children:{hideChevron:!0,items:[{type:t.Ln.Html,element:this.picker.element}],onOpen:()=>{this.onPickerOpen()},onClose:()=>{this.onPickerClose()}}}}applyColor(e,t){this.restoreSelectionIfSaved();let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0);if(r.collapsed)return;let i=this.resolveToVar(t,e),a=this.findContainingMark(r);if(a){let t=document.createRange();if(t.selectNodeContents(a),r.compareBoundaryPoints(Range.START_TO_START,t)<=0&&r.compareBoundaryPoints(Range.END_TO_END,t)>=0){a.style.setProperty(e,i),this.ensureTransparentBg(a);return}this.splitMarkAroundRange(a,r,e,i);return}this.splitMarksAtBoundaries(r),this.removeNestedMarkStyle(r,e);let o=document.createElement(`mark`);o.style.setProperty(e,i),this.ensureTransparentBg(o),o.appendChild(r.extractContents()),r.insertNode(o),n.removeAllRanges();let s=document.createRange();s.selectNodeContents(o),n.addRange(s)}removeColor(e){var t,n;this.restoreSelectionIfSaved();let r=window.getSelection();if(!r||r.rangeCount===0)return;let i=r.getRangeAt(0),a=i.startContainer,o=i.startOffset,s=i.endContainer,c=i.endOffset,l=i.toString(),u=i.commonAncestorContainer,d=u.nodeType===Node.ELEMENT_NODE?u:u.parentElement,f=d!=null&&d.closest(`mark`)?(t=(n=d.closest(`mark`))==null?void 0:n.parentElement)==null?d:t:d;this.splitMarksAtBoundaries(i);let p=Q(i,_c);for(let t of p){t.style.removeProperty(e);let n=bc[e],r=t.style.getPropertyValue(n);r!==``&&r!==`transparent`?this.ensureTransparentBg(t):this.unwrapElement(t)}let m=a.isConnected,h=s.isConnected;if(m&&h)try{let e=document.createRange();e.setStart(a,o),e.setEnd(s,c),r.removeAllRanges(),r.addRange(e)}catch(e){this.restoreSelectionByText(r,f,l)}else this.restoreSelectionByText(r,f,l)}onPickerOpen(){this.activeTextColor=null,this.activeBgColor=null,this.picker.reset();let e=this.detectBothSelectionComputedColors();e.text!==null&&(this.picker.setActiveColor(e.text,`color`),this.activeTextColor=e.text),e.bg!==null&&(this.picker.setActiveColor(e.bg,`background-color`),this.activeBgColor=e.bg),this.updateToolbarColors(this.activeTextColor,this.activeBgColor),this.selection.setFakeBackground(),this.selection.save()}updateToolbarColors(e,t){let n=document.querySelector(`[data-blok-item-name="marker"]`);if(!n)return;e===null?t===null?n.style.removeProperty(`color`):n.style.setProperty(`color`,`var(--blok-text-primary)`):n.style.setProperty(`color`,e);let r=n.querySelector(`svg rect`);t===null?e===null?(r&&(r.style.fill=``),n.style.removeProperty(`background-color`)):(r&&(r.style.fill=`var(--blok-swatch-neutral-bg)`),n.style.setProperty(`background-color`,`transparent`)):(r&&(r.style.fill=t),n.style.setProperty(`background-color`,`transparent`))}onPickerClose(){this.selection.removeFakeBackground(),this.selection.savedSelectionRange&&this.selection.restore(),this.selection.clearSaved()}detectBothSelectionColors(e){let t=vc(e.startContainer);if(!t)return{text:null,bg:null};let n=e=>{let n=t.style.getPropertyValue(e);return n&&n!==`transparent`?n:null};return{text:n(`color`),bg:n(`background-color`)}}detectBothSelectionComputedColors(){let e=window.getSelection();if(!e||e.rangeCount===0)return{text:null,bg:null};let t=vc(e.getRangeAt(0).startContainer);if(!t)return{text:null,bg:null};let n=window.getComputedStyle(t),r=e=>{let r=t.style.getPropertyValue(e);if(!r||r===`transparent`)return null;let i=n.getPropertyValue(e);return i&&i!==`transparent`?i:null};return{text:r(`color`),bg:r(`background-color`)}}restoreSelectionIfSaved(){this.selection.savedSelectionRange&&(this.selection.removeFakeBackground(),this.selection.restore(),this.selection.clearSaved())}findContainingMark(e){let t=vc(e.startContainer),n=vc(e.endContainer);return t&&t===n?t:null}removeNestedMarkStyle(e,t){let n=Q(e,_c);for(let e of n){e.style.removeProperty(t);let n=bc[t],r=e.style.getPropertyValue(n);r!==``&&r!==`transparent`?this.ensureTransparentBg(e):this.unwrapElement(e)}}splitMarkAroundRange(e,t,n,r){let i=e.parentNode;if(!i)return;let a=document.createRange();a.setStart(e,0),a.setEnd(t.startContainer,t.startOffset);let o=document.createRange();o.setStart(t.endContainer,t.endOffset),o.setEnd(e,e.childNodes.length);let s=a.extractContents(),c=t.extractContents(),l=o.extractContents(),u=document.createElement(`mark`);u.style.cssText=e.style.cssText,u.style.setProperty(n,r),this.ensureTransparentBg(u),u.appendChild(c);let d=document.createDocumentFragment();if(s.textContent){let t=document.createElement(`mark`);t.style.cssText=e.style.cssText,this.ensureTransparentBg(t),t.appendChild(s),d.appendChild(t)}if(d.appendChild(u),l.textContent){let t=document.createElement(`mark`);t.style.cssText=e.style.cssText,this.ensureTransparentBg(t),t.appendChild(l),d.appendChild(t)}i.replaceChild(d,e);let f=window.getSelection();if(f){f.removeAllRanges();let e=document.createRange();e.selectNodeContents(u),f.addRange(e)}}splitMarksAtBoundaries(e){let t=Q(e,_c);for(let n of t){let t=document.createRange();t.selectNodeContents(n);let r=e.compareBoundaryPoints(Range.START_TO_START,t)<=0,i=e.compareBoundaryPoints(Range.END_TO_END,t)>=0;r&&i||n.parentNode&&(i||this.extractTrailingMark(n,e.endContainer,e.endOffset),r||this.extractLeadingMark(n,e.startContainer,e.startOffset))}}extractTrailingMark(e,t,n){let r=document.createRange();r.setStart(t,n),r.setEnd(e,e.childNodes.length);let i=r.extractContents();if(!i.textContent)return;let a=document.createElement(`mark`);a.style.cssText=e.style.cssText,a.appendChild(i),e.after(a)}extractLeadingMark(e,t,n){let r=document.createRange();r.setStart(e,0),r.setEnd(t,n);let i=r.extractContents();if(!i.textContent)return;let a=document.createElement(`mark`);a.style.cssText=e.style.cssText,a.appendChild(i),e.before(a)}restoreSelectionByText(e,t,n){var r;if(!t||n.length===0)return;let i=((r=t.textContent)==null?``:r).indexOf(n);if(i===-1)return;let a=i+n.length,{startNode:o,startNodeOffset:s,endNode:c,endNodeOffset:l}=this.findTextBoundaries(t,i,a);if(o&&c){let t=document.createRange();t.setStart(o,s),t.setEnd(c,l),e.removeAllRanges(),e.addRange(t)}}findTextBoundaries(e,t,n){let r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),i={startNode:null,startNodeOffset:0,endNode:null,endNodeOffset:0},a={value:0};for(;r.nextNode();){var o,s;let e=r.currentNode,c=(o=(s=e.textContent)==null?void 0:s.length)==null?0:o;if(i.startNode===null&&a.value+c>t&&(i.startNode=e,i.startNodeOffset=t-a.value),a.value+c>=n){i.endNode=e,i.endNodeOffset=n-a.value;break}a.value+=c}return i}unwrapElement(e){let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}}ensureTransparentBg(e){e.style.getPropertyValue(`color`)&&!e.style.getPropertyValue(`background-color`)&&e.style.setProperty(`background-color`,`transparent`)}resolveToVar(e,n){if(e.startsWith(`var(`))return e;let r=n===`color`?`text`:`bg`,i=t.vn(e,r);return i===null?e:t.Sn(i,r)}};yc=xc,yc.isInline=!0,yc.title=`Color`,yc.titleKey=`marker`,yc.shortcut=`CMD+SHIFT+H`,yc.ALLOWED_STYLE_PROPS=new Set([`color`,`background-color`]);var Sc,Cc=e=>e.tagName===`U`,wc=class{static get sanitize(){return{u:{}}}render(){return{icon:t.in,name:`underline`,onActivate:()=>{this.toggleUnderline()},isActive:()=>{let e=window.getSelection();return e?this.isSelectionVisuallyUnderline(e):!1}}}toggleUnderline(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed){this.toggleCollapsedUnderline(t,e);return}this.isRangeUnderline(t,{ignoreWhitespace:!0})?this.unwrapUnderlineTags(t):this.wrapWithUnderline(t)}toggleCollapsedUnderline(e,t){if(this.isRangeUnderline(e,{ignoreWhitespace:!0})){let n=document.createTextNode(`​`);e.insertNode(n),e.selectNode(n),this.unwrapUnderlineTags(e);let r=document.createRange();r.setStart(n,1),r.setEnd(n,1),t.removeAllRanges(),t.addRange(r)}else{let n=document.createElement(`u`),r=document.createTextNode(`​`);n.appendChild(r),e.insertNode(n);let i=document.createRange();i.setStart(r,1),i.setEnd(r,1),t.removeAllRanges(),t.addRange(i)}}isSelectionVisuallyUnderline(e){if(e.rangeCount===0)return!1;let t=e.getRangeAt(0);return this.isRangeUnderline(t,{ignoreWhitespace:!0})}isRangeUnderline(e,t){return oc(e,Cc,t)}wrapWithUnderline(e){cc(e);let t=this.getRangeHtmlWithoutUnderline(e),n=this.replaceRangeWithHtml(e,`<u>${t}</u>`),r=window.getSelection();if(r&&n){let e=n.startContainer.childNodes[n.startOffset],t=document.createRange();e?(this.normalizeNbspInElement(e),t.selectNodeContents(e)):(t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)),r.removeAllRanges(),r.addRange(t)}}normalizeNbspInElement(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(;;){var n;let e=t.nextNode();if(e===null)break;(n=e.textContent)!=null&&n.includes(`\xA0`)&&(e.textContent=e.textContent.replace(/\u00A0/g,` `))}}unwrapUnderlineTags(e){let t=this.collectUnderlineAncestors(e),n=window.getSelection();if(!n)return;let r=document.createElement(`span`),i=e.extractContents();r.appendChild(i),this.removeNestedUnderline(r),e.insertNode(r);let a=document.createRange();for(a.selectNodeContents(r),n.removeAllRanges(),n.addRange(a);;){let e=this.findUnderlineElement(r);if(!e)break;this.moveMarkerOutOfUnderline(r,e)}let o=r.firstChild,s=r.lastChild;this.unwrapElement(r),o&&s&&(()=>{let e=document.createRange();return e.setStartBefore(o),e.setEndAfter(s),n.removeAllRanges(),n.addRange(e),e})()||n.removeAllRanges(),t.forEach(e=>{e.textContent.length===0&&e.remove()})}hasUnderlineParent(e){return ac(e,Cc)}findUnderlineElement(e){return Z(e,Cc)}collectUnderlineAncestors(e){return Q(e,Cc)}getRangeHtmlWithoutUnderline(e){let t=e.cloneContents();this.removeNestedUnderline(t);let n=document.createElement(`div`);return n.appendChild(t),n.innerHTML}removeNestedUnderline(e){e.querySelectorAll(`u`).forEach(e=>{this.unwrapElement(e)})}unwrapElement(e){let t=e.parentNode;if(!t){e.remove();return}for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}replaceRangeWithHtml(e,t){var n,r;let i=this.createFragmentFromHtml(t),a=(n=i.firstChild)==null?null:n,o=(r=i.lastChild)==null?null:r;if(e.deleteContents(),!a||!o)return;e.insertNode(i);let s=document.createRange();return s.setStartBefore(a),s.setEndAfter(o),s}createFragmentFromHtml(e){let t=document.createElement(`template`);return t.innerHTML=e,t.content}moveMarkerOutOfUnderline(e,t){let n=t.parentNode;if(!n)return;if(Array.from(t.childNodes).forEach(e=>{var t;e.nodeType===Node.TEXT_NODE&&((t=e.textContent)==null?``:t).length===0&&e.remove()}),t.childNodes.length===1&&t.firstChild===e){t.replaceWith(e);return}if(t.firstChild===e){n.insertBefore(e,t);return}if(t.lastChild===e){n.insertBefore(e,t.nextSibling);return}let r=t.cloneNode(!1);for(;e.nextSibling;)r.appendChild(e.nextSibling);n.insertBefore(r,t.nextSibling),n.insertBefore(e,r)}};Sc=wc,Sc.isInline=!0,Sc.title=`Underline`,Sc.titleKey=`underline`,Sc.shortcut=`CMD+U`;var Tc,Ec=e=>e.tagName===`S`,Dc=class{static get sanitize(){return{s:{}}}render(){return{icon:t.Xt,name:`strikethrough`,onActivate:()=>{this.toggleStrikethrough()},isActive:()=>{let e=window.getSelection();return e?this.isSelectionVisuallyStrikethrough(e):!1}}}toggleStrikethrough(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed){this.toggleCollapsedStrikethrough(t,e);return}this.isRangeStrikethrough(t,{ignoreWhitespace:!0})?this.unwrapStrikethroughTags(t):this.wrapWithStrikethrough(t)}toggleCollapsedStrikethrough(e,t){if(this.isRangeStrikethrough(e,{ignoreWhitespace:!0})){let n=document.createTextNode(`​`);e.insertNode(n),e.selectNode(n),this.unwrapStrikethroughTags(e);let r=document.createRange();r.setStart(n,1),r.setEnd(n,1),t.removeAllRanges(),t.addRange(r)}else{let n=document.createElement(`s`),r=document.createTextNode(`​`);n.appendChild(r),e.insertNode(n);let i=document.createRange();i.setStart(r,1),i.setEnd(r,1),t.removeAllRanges(),t.addRange(i)}}isSelectionVisuallyStrikethrough(e){if(e.rangeCount===0)return!1;let t=e.getRangeAt(0);return this.isRangeStrikethrough(t,{ignoreWhitespace:!0})}isRangeStrikethrough(e,t){return oc(e,Ec,t)}wrapWithStrikethrough(e){cc(e);let t=this.getRangeHtmlWithoutStrikethrough(e),n=this.replaceRangeWithHtml(e,`<s>${t}</s>`),r=window.getSelection();if(r&&n){let e=n.startContainer.childNodes[n.startOffset],t=document.createRange();e?(this.normalizeNbspInElement(e),t.selectNodeContents(e)):(t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)),r.removeAllRanges(),r.addRange(t)}}normalizeNbspInElement(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(;;){var n;let e=t.nextNode();if(e===null)break;(n=e.textContent)!=null&&n.includes(`\xA0`)&&(e.textContent=e.textContent.replace(/\u00A0/g,` `))}}unwrapStrikethroughTags(e){let t=this.collectStrikethroughAncestors(e),n=window.getSelection();if(!n)return;let r=document.createElement(`span`),i=e.extractContents();r.appendChild(i),this.removeNestedStrikethrough(r),e.insertNode(r);let a=document.createRange();for(a.selectNodeContents(r),n.removeAllRanges(),n.addRange(a);;){let e=this.findStrikethroughElement(r);if(!e)break;this.moveMarkerOutOfStrikethrough(r,e)}let o=r.firstChild,s=r.lastChild;this.unwrapElement(r),o&&s&&(()=>{let e=document.createRange();return e.setStartBefore(o),e.setEndAfter(s),n.removeAllRanges(),n.addRange(e),e})()||n.removeAllRanges(),t.forEach(e=>{e.textContent.length===0&&e.remove()})}hasStrikethroughParent(e){return ac(e,Ec)}findStrikethroughElement(e){return Z(e,Ec)}collectStrikethroughAncestors(e){return Q(e,Ec)}getRangeHtmlWithoutStrikethrough(e){let t=e.cloneContents();this.removeNestedStrikethrough(t);let n=document.createElement(`div`);return n.appendChild(t),n.innerHTML}removeNestedStrikethrough(e){e.querySelectorAll(`s`).forEach(e=>{this.unwrapElement(e)})}unwrapElement(e){let t=e.parentNode;if(!t){e.remove();return}for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}replaceRangeWithHtml(e,t){var n,r;let i=this.createFragmentFromHtml(t),a=(n=i.firstChild)==null?null:n,o=(r=i.lastChild)==null?null:r;if(e.deleteContents(),!a||!o)return;e.insertNode(i);let s=document.createRange();return s.setStartBefore(a),s.setEndAfter(o),s}createFragmentFromHtml(e){let t=document.createElement(`template`);return t.innerHTML=e,t.content}moveMarkerOutOfStrikethrough(e,t){let n=t.parentNode;if(!n)return;if(Array.from(t.childNodes).forEach(e=>{var t;e.nodeType===Node.TEXT_NODE&&((t=e.textContent)==null?``:t).length===0&&e.remove()}),t.childNodes.length===1&&t.firstChild===e){t.replaceWith(e);return}if(t.firstChild===e){n.insertBefore(e,t);return}if(t.lastChild===e){n.insertBefore(e,t.nextSibling);return}let r=t.cloneNode(!1);for(;e.nextSibling;)r.appendChild(e.nextSibling);n.insertBefore(r,t.nextSibling),n.insertBefore(e,r)}};Tc=Dc,Tc.isInline=!0,Tc.title=`Strikethrough`,Tc.titleKey=`strikethrough`,Tc.shortcut=`CMD+SHIFT+S`;var Oc,kc=e=>e.tagName===`CODE`,Ac=class{static get sanitize(){return{code:{}}}render(){return{icon:t.z,name:`inlineCode`,onActivate:()=>{this.toggleCode()},isActive:()=>{let e=window.getSelection();return e?this.isSelectionVisuallyCode(e):!1}}}toggleCode(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed){this.toggleCollapsedCode(t,e);return}this.isRangeCode(t,{ignoreWhitespace:!0})?this.unwrapCodeTags(t):this.wrapWithCode(t)}toggleCollapsedCode(e,t){if(this.isRangeCode(e,{ignoreWhitespace:!0})){let n=document.createTextNode(`​`);e.insertNode(n),e.selectNode(n),this.unwrapCodeTags(e);let r=document.createRange();r.setStart(n,1),r.setEnd(n,1),t.removeAllRanges(),t.addRange(r)}else{let n=document.createElement(`code`),r=document.createTextNode(`​`);n.appendChild(r),e.insertNode(n);let i=document.createRange();i.setStart(r,1),i.setEnd(r,1),t.removeAllRanges(),t.addRange(i)}}isSelectionVisuallyCode(e){if(e.rangeCount===0)return!1;let t=e.getRangeAt(0);return this.isRangeCode(t,{ignoreWhitespace:!0})}isRangeCode(e,t){return oc(e,kc,t)}wrapWithCode(e){cc(e);let t=this.getRangeHtmlWithoutCode(e),n=this.replaceRangeWithHtml(e,`<code>${t}</code>`),r=window.getSelection();if(r&&n){let e=n.startContainer.childNodes[n.startOffset],t=document.createRange();e?(this.normalizeNbspInElement(e),t.selectNodeContents(e)):(t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)),r.removeAllRanges(),r.addRange(t)}}normalizeNbspInElement(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(;;){var n;let e=t.nextNode();if(e===null)break;(n=e.textContent)!=null&&n.includes(`\xA0`)&&(e.textContent=e.textContent.replace(/\u00A0/g,` `))}}unwrapCodeTags(e){let t=this.collectCodeAncestors(e),n=window.getSelection();if(!n)return;let r=document.createElement(`span`),i=e.extractContents();r.appendChild(i),this.removeNestedCode(r),e.insertNode(r);let a=document.createRange();for(a.selectNodeContents(r),n.removeAllRanges(),n.addRange(a);;){let e=this.findCodeElement(r);if(!e)break;this.moveMarkerOutOfCode(r,e)}let o=r.firstChild,s=r.lastChild;this.unwrapElement(r),o&&s&&(()=>{let e=document.createRange();return e.setStartBefore(o),e.setEndAfter(s),n.removeAllRanges(),n.addRange(e),e})()||n.removeAllRanges(),t.forEach(e=>{e.textContent.length===0&&e.remove()})}findCodeElement(e){return Z(e,kc)}collectCodeAncestors(e){return Q(e,kc)}getRangeHtmlWithoutCode(e){let t=e.cloneContents();this.removeNestedCode(t);let n=document.createElement(`div`);return n.appendChild(t),n.innerHTML}removeNestedCode(e){e.querySelectorAll(`code`).forEach(e=>{this.unwrapElement(e)})}unwrapElement(e){let t=e.parentNode;if(!t){e.remove();return}for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}replaceRangeWithHtml(e,t){var n,r;let i=this.createFragmentFromHtml(t),a=(n=i.firstChild)==null?null:n,o=(r=i.lastChild)==null?null:r;if(e.deleteContents(),!a||!o)return;e.insertNode(i);let s=document.createRange();return s.setStartBefore(a),s.setEndAfter(o),s}createFragmentFromHtml(e){let t=document.createElement(`template`);return t.innerHTML=e,t.content}moveMarkerOutOfCode(e,t){let n=t.parentNode;if(!n)return;if(Array.from(t.childNodes).forEach(e=>{var t;e.nodeType===Node.TEXT_NODE&&((t=e.textContent)==null?``:t).length===0&&e.remove()}),t.childNodes.length===1&&t.firstChild===e){t.replaceWith(e);return}if(t.firstChild===e){n.insertBefore(e,t);return}if(t.lastChild===e){n.insertBefore(e,t.nextSibling);return}let r=t.cloneNode(!1);for(;e.nextSibling;)r.appendChild(e.nextSibling);n.insertBefore(r,t.nextSibling),n.insertBefore(e,r)}};Oc=Ac,Oc.isInline=!0,Oc.title=`Code`,Oc.titleKey=`inlineCode`,Oc.shortcut=`CMD+E`;var jc={paragraph:{preserveBlank:!0},header:{},list:{},table:{},toggle:{},callout:{},database:{},"database-row":{},divider:{},quote:{},code:{inlineToolbar:!1},image:{}},Mc={bold:{},italic:{},link:{},marker:{},underline:{},strikethrough:{},inlineCode:{}};Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return Ar}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return wc}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return fc}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return ko}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return aa}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return xi}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return $i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return Dc}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return lc}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return ea}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Mc}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return xc}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return ta}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Ac}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return gc}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return jc}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return qs}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return Tr}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return yt}});