@jackuait/blok 0.15.0 → 0.15.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.
- package/dist/blok.cjs +1 -1
- package/dist/blok.iife.js +1 -1
- package/dist/blok.mjs +2 -2
- package/dist/chunks/{blok-CEYQZt_c.cjs → blok-By8CgA9B.cjs} +1 -1
- package/dist/chunks/{blok-CLpOs5vp.mjs → blok-D8WF1Faf.mjs} +1 -1
- package/dist/chunks/{constants-Dsh6wwb1.mjs → constants-B7YKRGs2.mjs} +1 -1
- package/dist/chunks/{constants-D5cYHg42.cjs → constants-Cz29UuPH.cjs} +1 -1
- package/dist/chunks/{tools-D834YyD8.mjs → tools-D5QTbJRM.mjs} +1 -1
- package/dist/chunks/{tools-D_HqQ7wn.cjs → tools-PKGRD99i.cjs} +1 -1
- package/dist/full.cjs +1 -1
- package/dist/full.mjs +3 -3
- package/dist/react.cjs +1 -1
- package/dist/react.mjs +1 -1
- package/dist/tools.cjs +1 -1
- package/dist/tools.mjs +2 -2
- package/package.json +1 -1
- package/types/tools-entry.d.ts +4 -0
package/dist/blok.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/blok-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/blok-By8CgA9B.cjs`),t=require(`./chunks/constants-Cz29UuPH.cjs`);exports.Blok=e.t,exports.DATA_ATTR=t.hi,exports.version=e.n;
|
package/dist/blok.iife.js
CHANGED
|
@@ -266,7 +266,7 @@ var BlokEditor=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`M
|
|
|
266
266
|
<path d="M11.25 2.5v3.75H15" stroke="currentColor" stroke-width="1.25" stroke-linejoin="round"/>
|
|
267
267
|
<path d="M7.5 10.5h5M7.5 13h5" stroke="currentColor" stroke-width="1.25" stroke-linecap="round"/>
|
|
268
268
|
</svg>
|
|
269
|
-
`}));v(),Be();var Ve=e=>{let t=e.tagName;return t===`B`||t===`STRONG`},He=e=>!!(e&&e.nodeType===Node.ELEMENT_NODE&&Ve(e)),Ue=e=>e.textContent.length===0,We=e=>e?e.nodeType===Node.ELEMENT_NODE&&Ve(e)?Ge(e):We(e.parentNode):null,Ge=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},Ke=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},qe=e=>{if(!e.boldElement.isConnected)return null;let t=Ge(e.boldElement),n=e.boundary,r=n.isConnected&&n.previousSibling===t?n:Ke(t);return r?{boundary:r,boldElement:t}:null},Je=(e,t)=>e?e===t||t.contains(e):!1,Ye,Xe={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`},Ze=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(Xe.COLLAPSED_ACTIVE)===`true`||e.hasAttribute(Xe.COLLAPSED_LENGTH)}static get ATTR(){return Xe}enter(e,t){if(!e.collapsed)return;let n=document.createElement(`strong`),r=document.createTextNode(``);n.appendChild(r),n.setAttribute(Xe.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(Xe.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(Xe.PREV_LENGTH,`0`)}exit(e,t){let n=Ge(t),r=n.parentNode;if(r)return Ue(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(Xe.COLLAPSED_LENGTH,t.textContent.length.toString()),t.removeAttribute(Xe.PREV_LENGTH),t.removeAttribute(Xe.COLLAPSED_ACTIVE),t.removeAttribute(Xe.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(``);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=qe(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 t,n;let r=(t=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:t,i=r&&r.nodeType===Node.ELEMENT_NODE?r:r==null?void 0:r.parentElement,a=(n=i==null?void 0:i.closest(p(f.editor)))==null?i==null?void 0:i.ownerDocument:n;if(!a)return;let o=`strong[${Xe.COLLAPSED_ACTIVE}="true"]`;a.querySelectorAll(o).forEach(t=>{var n;let r=t.getAttribute(Xe.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(Xe.LEADING_WHITESPACE)&&t.setAttribute(Xe.LEADING_WHITESPACE,u[0]),l.length===0)return;let d=t.textContent,f=d+l,p=(n=t.getAttribute(Xe.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)||!Je(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 t;let n=(t=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:t;if(!n)return;let r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement,i=r==null?void 0:r.closest(p(f.editor));i&&i.querySelectorAll(`strong[${Xe.COLLAPSED_LENGTH}]`).forEach(t=>{var n;let r=t.getAttribute(Xe.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(Xe.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(Xe.PREV_LENGTH),e!=null&&e.isCollapsed&&s&&Je(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(Xe.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=We(t.startContainer);(n==null?void 0:n.getAttribute(Xe.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=We(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`}};Ye=Ze,Ye.instance=null;function Qe(e){"@babel/helpers - typeof";return Qe=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Qe(e)}var $e=s((()=>{}));function et(e,t){if(Qe(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Qe(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var tt=s((()=>{$e()}));function nt(e){var t=et(e,`string`);return Qe(t)==`symbol`?t:t+``}var rt=s((()=>{$e(),tt()}));function it(e,t,n){return(t=nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var at=s((()=>{rt()}));function ot(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function T(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ot(Object(n),!0).forEach(function(t){it(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ot(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var E=s((()=>{at()}));v(),E();var st={convertLegacyTags:!0,normalizeWhitespace:!0,removeEmpty:!0,mergeAdjacent:!0,preserveNode:null},ct=class e{constructor(e){this.options=T(T({},st),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=Ge(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||Ze.getInstance().isActivePlaceholder(e)?!1:!(this.options.preserveNode&&Je(this.options.preserveNode,e))}mergeWithAdjacent(e){let t=e.previousSibling;if(t&&He(t)){this.mergeStrongNodes(t,e);return}let n=e.nextSibling;n&&He(n)&&this.mergeStrongNodes(e,n)}mergeStrongNodes(e,t){let n=Ge(e),r=Ge(t);for(;r.firstChild;)n.appendChild(r.firstChild);r.remove()}static findScopeFromSelection(e){var t,n;let r=(t=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:t;if(!r)return null;let i=r.nodeType===Node.ELEMENT_NODE?r:r.parentElement;return i?((n=i.closest(`[data-blok-component="paragraph"]`))==null?i.closest(p(f.elementContent)):n)||i.closest(p(f.editor)):null}},lt,ut=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)}};lt=ut,lt.instance=null;var dt=(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}},ft=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=>dt(e,t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT})},pt=(e,t,n)=>!e||e===n?null:e.nodeType===Node.ELEMENT_NODE&&t(e)?e:pt(e.parentNode,t,n),mt=(e,t)=>pt(e,t)!==null,ht=(e,t,n={})=>{if(e.collapsed)return pt(e.startContainer,t)!==null;let r=ft(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?pt(e.startContainer,t)!==null:i.every(e=>mt(e,t))},gt=e=>{let t=e.lastChild;return t===null?e.nodeType===Node.TEXT_NODE?e:null:gt(t)},_t=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=gt(n);if(i===null)return;let a=(t=i.textContent)==null?``:t;a.length!==0&&/\s+$/.test(a)&&e.setEnd(i,a.length)},vt=(e,t)=>{let n=new Set,r=ft(e);for(;r.nextNode();){let e=pt(r.currentNode,t);e&&n.add(e)}return Array.from(n)};v();var yt,bt=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=ut.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`?(ct.normalizeAroundSelection(window.getSelection()),!0):!1,isRelevant:t=>e.isSelectionInsideBlok(t)}),e.guardKeydownListenerRegistered||(document.addEventListener(`keydown`,e=>{Ze.getInstance().guardBoundaryKeydown(e)},!0),e.guardKeydownListenerRegistered=!0),e.ensureMutationObserver(),!0)}static mergeStrongNodes(e,t){let n=Ge(e),r=Ge(t);for(;r.firstChild;)n.appendChild(r.firstChild);return r.remove(),n}render(){return{icon:y,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){_t(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){ct.normalizeAroundSelection(r),this.notifySelectionChange();return}let a=this.mergeAdjacentBold(i);this.selectElementContents(a),ct.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=We(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(),ct.normalizeAroundSelection(r),n.forEach(e=>{e.isConnected&&(Ue(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 ht(e,Ve,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?We(e.startContainer)||We(e.commonAncestorContainer)||(e.startContainer.nodeType===Node.ELEMENT_NODE&&Ve(e.startContainer)?e.startContainer:null):t?We(t.focusNode):null}mergeAdjacentBold(t){let n=Ge(t),r=n.previousSibling,i=r&&r.nodeType===Node.ELEMENT_NODE&&Ve(r)?e.mergeStrongNodes(r,n):n,a=i.nextSibling;return a&&a.nodeType===Node.ELEMENT_NODE&&Ve(a)?e.mergeStrongNodes(i,a):i}toggleCollapsedSelection(){let t=window.getSelection();if(!t||t.rangeCount===0)return;let n=t.getRangeAt(0),r=We(n.startContainer),i=(()=>{if(r&&r.getAttribute(Ze.ATTR.COLLAPSED_ACTIVE)!==`true`)return Ze.getInstance().exit(t,r);let i=r==null?e.getBoundaryBold(n):r;return i?Ze.getInstance().exit(t,i):this.startCollapsedBold(n)})();document.dispatchEvent(new Event(`selectionchange`)),i&&(t.removeAllRanges(),t.addRange(i)),ct.normalizeAroundSelection(t),this.notifySelectionChange()}startCollapsedBold(e){let t=Ze.getInstance().enter(e,e=>this.mergeAdjacentBold(e)),n=window.getSelection();return ct.normalizeAroundSelection(n),n&&t&&(n.removeAllRanges(),n.addRange(t)),this.notifySelectionChange(),t}notifySelectionChange(){Ze.getInstance().enforceLengths(window.getSelection()),document.dispatchEvent(new Event(`selectionchange`)),this.updateToolbarButtonState()}updateToolbarButtonState(){let e=window.getSelection();if(!e)return;let t=e.anchorNode,n=(t==null?void 0:t.nodeType)===Node.ELEMENT_NODE?t:t==null?void 0:t.parentElement,r=n==null?void 0:n.closest(p(f.editor));if(!r)return;let i=r.querySelector(`[data-blok-testid=inline-toolbar]`);if(!(i instanceof HTMLElement))return;let a=i.querySelector(`[data-blok-item-name="bold"]`);a instanceof HTMLElement&&(this.isSelectionVisuallyBold(e)?a.setAttribute(`data-blok-popover-item-active`,`true`):a.removeAttribute(`data-blok-popover-item-active`))}static refreshSelectionState(e){let t=window.getSelection();Ze.getInstance().enforceLengths(t),Ze.getInstance().maintain(),Ze.getInstance().synchronize(t),ct.normalizeAroundSelection(t,{normalizeWhitespace:!1}),e===`input`&&t&&Ze.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 ct({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 t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return!t||typeof t.closest!=`function`?null:t.closest(`${p(f.interface)}, ${p(f.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 We(t);if(e.startOffset!==0)return null;let r=t.previousSibling;return He(r)?r:null}static getBoundaryBoldForElement(e,t){if(e.startOffset<=0)return null;let n=t.childNodes[e.startOffset-1];return He(n)?n:null}static isSelectionInsideBlok(e){let t=e.anchorNode;if(!t)return!1;let n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;return!!(n!=null&&n.closest(p(f.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 vt(e,Ve)}};yt=bt,yt.isInline=!0,yt.title=`Bold`,yt.titleKey=`bold`,yt.markerSequence=0,yt.isProcessingMutation=!1,yt.instances=new Set,yt.guardKeydownListenerRegistered=!1,yt.shortcut=`CMD+B`,Be();var xt,St=e=>{let t=e.tagName;return t===`I`||t===`EM`},Ct=class{static get sanitize(){return{i:{},em:{}}}render(){return{icon:b,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 ht(e,St,t)}wrapWithItalic(e){_t(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 mt(e,St)}findItalicElement(e){return pt(e,St)}collectItalicAncestors(e){return vt(e,St)}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)}};xt=Ct,xt.isInline=!0,xt.title=`Italic`,xt.titleKey=`italic`,xt.shortcut=`CMD+I`;var D,wt,Tt=s((()=>{D={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,ESC:27,SPACE:32,LEFT:37,UP:38,DOWN:40,RIGHT:39,DELETE:46,NUMBER_KEY_MIN:47,NUMBER_KEY_MAX:58,LETTER_KEY_MIN:64,LETTER_KEY_MAX:91,META:91,NUMPAD_KEY_MIN:95,NUMPAD_KEY_MAX:112,PUNCTUATION_KEY_MIN:185,PUNCTUATION_KEY_MAX:193,BRACKET_KEY_MIN:218,BRACKET_KEY_MAX:223,PROCESSING_KEY:229,SLASH:191},wt={LEFT:0,WHEEL:1,RIGHT:2,BACKWARD:3,FORWARD:4}})),Et,Dt=s((()=>{Et=()=>`0.15.0`})),Ot,kt,At,jt,Mt,Nt=s((()=>{Dt(),Ot=function(e){return e.VERBOSE=`VERBOSE`,e.INFO=`INFO`,e.WARN=`WARN`,e.ERROR=`ERROR`,e}({}),kt=(e,t,n=`log`,r,i=`color: inherit`)=>{let a=typeof console>`u`?void 0:console;if(!a||typeof a[n]!=`function`)return;let o=[`info`,`log`,`warn`,`error`].includes(n),s=[];switch(kt.logLevel){case Ot.VERBOSE:break;case Ot.ERROR:if(n!==`error`)return;break;case Ot.WARN:if(![`error`,`warn`].includes(n))return;break;case Ot.INFO:if(!o||e)return;break}r&&s.push(r);let c=`Blok ${Et()}`,l=e?o?(s.unshift(`line-height: 1em;
|
|
269
|
+
`}));v(),Be();var Ve=e=>{let t=e.tagName;return t===`B`||t===`STRONG`},He=e=>!!(e&&e.nodeType===Node.ELEMENT_NODE&&Ve(e)),Ue=e=>e.textContent.length===0,We=e=>e?e.nodeType===Node.ELEMENT_NODE&&Ve(e)?Ge(e):We(e.parentNode):null,Ge=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},Ke=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},qe=e=>{if(!e.boldElement.isConnected)return null;let t=Ge(e.boldElement),n=e.boundary,r=n.isConnected&&n.previousSibling===t?n:Ke(t);return r?{boundary:r,boldElement:t}:null},Je=(e,t)=>e?e===t||t.contains(e):!1,Ye,Xe={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`},Ze=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(Xe.COLLAPSED_ACTIVE)===`true`||e.hasAttribute(Xe.COLLAPSED_LENGTH)}static get ATTR(){return Xe}enter(e,t){if(!e.collapsed)return;let n=document.createElement(`strong`),r=document.createTextNode(``);n.appendChild(r),n.setAttribute(Xe.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(Xe.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(Xe.PREV_LENGTH,`0`)}exit(e,t){let n=Ge(t),r=n.parentNode;if(r)return Ue(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(Xe.COLLAPSED_LENGTH,t.textContent.length.toString()),t.removeAttribute(Xe.PREV_LENGTH),t.removeAttribute(Xe.COLLAPSED_ACTIVE),t.removeAttribute(Xe.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(``);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=qe(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 t,n;let r=(t=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:t,i=r&&r.nodeType===Node.ELEMENT_NODE?r:r==null?void 0:r.parentElement,a=(n=i==null?void 0:i.closest(p(f.editor)))==null?i==null?void 0:i.ownerDocument:n;if(!a)return;let o=`strong[${Xe.COLLAPSED_ACTIVE}="true"]`;a.querySelectorAll(o).forEach(t=>{var n;let r=t.getAttribute(Xe.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(Xe.LEADING_WHITESPACE)&&t.setAttribute(Xe.LEADING_WHITESPACE,u[0]),l.length===0)return;let d=t.textContent,f=d+l,p=(n=t.getAttribute(Xe.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)||!Je(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 t;let n=(t=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:t;if(!n)return;let r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement,i=r==null?void 0:r.closest(p(f.editor));i&&i.querySelectorAll(`strong[${Xe.COLLAPSED_LENGTH}]`).forEach(t=>{var n;let r=t.getAttribute(Xe.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(Xe.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(Xe.PREV_LENGTH),e!=null&&e.isCollapsed&&s&&Je(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(Xe.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=We(t.startContainer);(n==null?void 0:n.getAttribute(Xe.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=We(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`}};Ye=Ze,Ye.instance=null;function Qe(e){"@babel/helpers - typeof";return Qe=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Qe(e)}var $e=s((()=>{}));function et(e,t){if(Qe(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Qe(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var tt=s((()=>{$e()}));function nt(e){var t=et(e,`string`);return Qe(t)==`symbol`?t:t+``}var rt=s((()=>{$e(),tt()}));function it(e,t,n){return(t=nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var at=s((()=>{rt()}));function ot(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function T(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ot(Object(n),!0).forEach(function(t){it(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ot(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var E=s((()=>{at()}));v(),E();var st={convertLegacyTags:!0,normalizeWhitespace:!0,removeEmpty:!0,mergeAdjacent:!0,preserveNode:null},ct=class e{constructor(e){this.options=T(T({},st),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=Ge(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||Ze.getInstance().isActivePlaceholder(e)?!1:!(this.options.preserveNode&&Je(this.options.preserveNode,e))}mergeWithAdjacent(e){let t=e.previousSibling;if(t&&He(t)){this.mergeStrongNodes(t,e);return}let n=e.nextSibling;n&&He(n)&&this.mergeStrongNodes(e,n)}mergeStrongNodes(e,t){let n=Ge(e),r=Ge(t);for(;r.firstChild;)n.appendChild(r.firstChild);r.remove()}static findScopeFromSelection(e){var t,n;let r=(t=e==null?void 0:e.anchorNode)==null?e==null?void 0:e.focusNode:t;if(!r)return null;let i=r.nodeType===Node.ELEMENT_NODE?r:r.parentElement;return i?((n=i.closest(`[data-blok-component="paragraph"]`))==null?i.closest(p(f.elementContent)):n)||i.closest(p(f.editor)):null}},lt,ut=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)}};lt=ut,lt.instance=null;var dt=(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}},ft=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=>dt(e,t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT})},pt=(e,t,n)=>!e||e===n?null:e.nodeType===Node.ELEMENT_NODE&&t(e)?e:pt(e.parentNode,t,n),mt=(e,t)=>pt(e,t)!==null,ht=(e,t,n={})=>{if(e.collapsed)return pt(e.startContainer,t)!==null;let r=ft(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?pt(e.startContainer,t)!==null:i.every(e=>mt(e,t))},gt=e=>{let t=e.lastChild;return t===null?e.nodeType===Node.TEXT_NODE?e:null:gt(t)},_t=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=gt(n);if(i===null)return;let a=(t=i.textContent)==null?``:t;a.length!==0&&/\s+$/.test(a)&&e.setEnd(i,a.length)},vt=(e,t)=>{let n=new Set,r=ft(e);for(;r.nextNode();){let e=pt(r.currentNode,t);e&&n.add(e)}return Array.from(n)};v();var yt,bt=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=ut.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`?(ct.normalizeAroundSelection(window.getSelection()),!0):!1,isRelevant:t=>e.isSelectionInsideBlok(t)}),e.guardKeydownListenerRegistered||(document.addEventListener(`keydown`,e=>{Ze.getInstance().guardBoundaryKeydown(e)},!0),e.guardKeydownListenerRegistered=!0),e.ensureMutationObserver(),!0)}static mergeStrongNodes(e,t){let n=Ge(e),r=Ge(t);for(;r.firstChild;)n.appendChild(r.firstChild);return r.remove(),n}render(){return{icon:y,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){_t(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){ct.normalizeAroundSelection(r),this.notifySelectionChange();return}let a=this.mergeAdjacentBold(i);this.selectElementContents(a),ct.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=We(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(),ct.normalizeAroundSelection(r),n.forEach(e=>{e.isConnected&&(Ue(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 ht(e,Ve,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?We(e.startContainer)||We(e.commonAncestorContainer)||(e.startContainer.nodeType===Node.ELEMENT_NODE&&Ve(e.startContainer)?e.startContainer:null):t?We(t.focusNode):null}mergeAdjacentBold(t){let n=Ge(t),r=n.previousSibling,i=r&&r.nodeType===Node.ELEMENT_NODE&&Ve(r)?e.mergeStrongNodes(r,n):n,a=i.nextSibling;return a&&a.nodeType===Node.ELEMENT_NODE&&Ve(a)?e.mergeStrongNodes(i,a):i}toggleCollapsedSelection(){let t=window.getSelection();if(!t||t.rangeCount===0)return;let n=t.getRangeAt(0),r=We(n.startContainer),i=(()=>{if(r&&r.getAttribute(Ze.ATTR.COLLAPSED_ACTIVE)!==`true`)return Ze.getInstance().exit(t,r);let i=r==null?e.getBoundaryBold(n):r;return i?Ze.getInstance().exit(t,i):this.startCollapsedBold(n)})();document.dispatchEvent(new Event(`selectionchange`)),i&&(t.removeAllRanges(),t.addRange(i)),ct.normalizeAroundSelection(t),this.notifySelectionChange()}startCollapsedBold(e){let t=Ze.getInstance().enter(e,e=>this.mergeAdjacentBold(e)),n=window.getSelection();return ct.normalizeAroundSelection(n),n&&t&&(n.removeAllRanges(),n.addRange(t)),this.notifySelectionChange(),t}notifySelectionChange(){Ze.getInstance().enforceLengths(window.getSelection()),document.dispatchEvent(new Event(`selectionchange`)),this.updateToolbarButtonState()}updateToolbarButtonState(){let e=window.getSelection();if(!e)return;let t=e.anchorNode,n=(t==null?void 0:t.nodeType)===Node.ELEMENT_NODE?t:t==null?void 0:t.parentElement,r=n==null?void 0:n.closest(p(f.editor));if(!r)return;let i=r.querySelector(`[data-blok-testid=inline-toolbar]`);if(!(i instanceof HTMLElement))return;let a=i.querySelector(`[data-blok-item-name="bold"]`);a instanceof HTMLElement&&(this.isSelectionVisuallyBold(e)?a.setAttribute(`data-blok-popover-item-active`,`true`):a.removeAttribute(`data-blok-popover-item-active`))}static refreshSelectionState(e){let t=window.getSelection();Ze.getInstance().enforceLengths(t),Ze.getInstance().maintain(),Ze.getInstance().synchronize(t),ct.normalizeAroundSelection(t,{normalizeWhitespace:!1}),e===`input`&&t&&Ze.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 ct({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 t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return!t||typeof t.closest!=`function`?null:t.closest(`${p(f.interface)}, ${p(f.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 We(t);if(e.startOffset!==0)return null;let r=t.previousSibling;return He(r)?r:null}static getBoundaryBoldForElement(e,t){if(e.startOffset<=0)return null;let n=t.childNodes[e.startOffset-1];return He(n)?n:null}static isSelectionInsideBlok(e){let t=e.anchorNode;if(!t)return!1;let n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;return!!(n!=null&&n.closest(p(f.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 vt(e,Ve)}};yt=bt,yt.isInline=!0,yt.title=`Bold`,yt.titleKey=`bold`,yt.markerSequence=0,yt.isProcessingMutation=!1,yt.instances=new Set,yt.guardKeydownListenerRegistered=!1,yt.shortcut=`CMD+B`,Be();var xt,St=e=>{let t=e.tagName;return t===`I`||t===`EM`},Ct=class{static get sanitize(){return{i:{},em:{}}}render(){return{icon:b,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 ht(e,St,t)}wrapWithItalic(e){_t(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 mt(e,St)}findItalicElement(e){return pt(e,St)}collectItalicAncestors(e){return vt(e,St)}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)}};xt=Ct,xt.isInline=!0,xt.title=`Italic`,xt.titleKey=`italic`,xt.shortcut=`CMD+I`;var D,wt,Tt=s((()=>{D={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,ESC:27,SPACE:32,LEFT:37,UP:38,DOWN:40,RIGHT:39,DELETE:46,NUMBER_KEY_MIN:47,NUMBER_KEY_MAX:58,LETTER_KEY_MIN:64,LETTER_KEY_MAX:91,META:91,NUMPAD_KEY_MIN:95,NUMPAD_KEY_MAX:112,PUNCTUATION_KEY_MIN:185,PUNCTUATION_KEY_MAX:193,BRACKET_KEY_MIN:218,BRACKET_KEY_MAX:223,PROCESSING_KEY:229,SLASH:191},wt={LEFT:0,WHEEL:1,RIGHT:2,BACKWARD:3,FORWARD:4}})),Et,Dt=s((()=>{Et=()=>`0.15.1`})),Ot,kt,At,jt,Mt,Nt=s((()=>{Dt(),Ot=function(e){return e.VERBOSE=`VERBOSE`,e.INFO=`INFO`,e.WARN=`WARN`,e.ERROR=`ERROR`,e}({}),kt=(e,t,n=`log`,r,i=`color: inherit`)=>{let a=typeof console>`u`?void 0:console;if(!a||typeof a[n]!=`function`)return;let o=[`info`,`log`,`warn`,`error`].includes(n),s=[];switch(kt.logLevel){case Ot.VERBOSE:break;case Ot.ERROR:if(n!==`error`)return;break;case Ot.WARN:if(![`error`,`warn`].includes(n))return;break;case Ot.INFO:if(!o||e)return;break}r&&s.push(r);let c=`Blok ${Et()}`,l=e?o?(s.unshift(`line-height: 1em;
|
|
270
270
|
color: #006FEA;
|
|
271
271
|
display: inline-block;
|
|
272
272
|
font-size: 11px;
|
package/dist/blok.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as e, t } from "./chunks/blok-
|
|
2
|
-
import { hi as n } from "./chunks/constants-
|
|
1
|
+
import { n as e, t } from "./chunks/blok-D8WF1Faf.mjs";
|
|
2
|
+
import { hi as n } from "./chunks/constants-B7YKRGs2.mjs";
|
|
3
3
|
export { t as Blok, n as DATA_ATTR, e as version };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./chunk-BL1yB9zm.cjs`),t=require(`./constants-D5cYHg42.cjs`),n=require(`./objectSpread2-iNkE6aJh.cjs`),r=require(`./tw-fzSjDKon.cjs`),i=require(`./types-BQNH-yx9.cjs`),a=require(`./lightweight-i18n-CNdX4sc2.cjs`);e.t(((e,t)=>{function n(){}t.exports=Object.assign(n,{default:n,register:n,revert:function(){},__esModule:!0})}))();var o=class extends Error{},s=class e{get isDestroyed(){return this._isDestroyed}markDestroyed(){this._isDestroyed=!0}constructor({config:n,eventsDispatcher:r}){if(this.nodes={},this._isDestroyed=!1,this.listeners=new t.Ar,this.readOnlyMutableListeners={on:(e,t,n,r=!1)=>{let i=this.listeners.on(e,t,n,r);i&&this.mutableListenerIds.push(i)},clearAll:()=>{for(let e of this.mutableListenerIds)this.listeners.offById(e);this.mutableListenerIds=[]}},this.mutableListenerIds=[],new.target===e)throw TypeError(`Constructors for abstract class Module are not allowed.`);this.config=n,this.eventsDispatcher=r,this.Blok={}}set state(e){this.Blok=e}removeAllNodes(){for(let e in this.nodes){let t=this.nodes[e];t instanceof HTMLElement&&t.remove()}}get isRtl(){var e;return((e=this.config.i18n)==null?void 0:e.direction)===`rtl`}},c=function(e){return Object.setPrototypeOf(this,{get id(){return e.id},get name(){return e.name},get config(){return e.config},get holder(){return e.holder},get parentId(){return e.parentId},get isEmpty(){return e.isEmpty},get selected(){return e.selected},get preservedData(){return e.preservedData},get preservedTunes(){return e.preservedTunes},set stretched(t){e.setStretchState(t)},get stretched(){return e.stretched},get focusable(){return e.focusable},call(t,n){return e.call(t,n)},save(){return e.save()},validate(t){return e.validate(t)},dispatchChange(){e.dispatchChange()},getActiveToolboxEntry(){return e.getActiveToolboxEntry()}}),Object.defineProperties(this,{id:{get(){return e.id},enumerable:!0,configurable:!0},name:{get(){return e.name},enumerable:!0,configurable:!0}}),this},l=class{constructor(e,t,n,r,i,a,o,s,c,l){this.toolInstance=e,this.getToolRenderedElement=t,this.tunesManager=n,this.name=r,this.getIsEmpty=i,this.inputManager=a,this.callToolUpdated=o,this.toggleEmptyMark=s,this.lastSavedDataInternal=c,this.lastSavedTunesInternal=l}async save(){var e=this;let t=await e.extractToolData();if(t===void 0)return;let r=window.performance.now(),i=e.tunesManager.extractTunesData();e.lastSavedDataInternal=t,e.lastSavedTunesInternal=n.t({},i);let a=window.performance.now();return{id:e.name,tool:e.name,data:t,tunes:i,time:a-r}}async setData(e){var n=this;let r=n.toolInstance.setData;if(typeof r==`function`)try{return await r.call(n.toolInstance,e),n.lastSavedDataInternal=e,!0}catch(e){return t.li(`Tool ${n.name} setData failed: ${e instanceof Error?e.message:String(e)}`,`warn`),!1}let i=n.getToolRenderedElement();if(!i)return!1;let a=i.getAttribute(`contenteditable`)===`true`,o=e.text,s=typeof o==`string`,c=Object.keys(e).length===0&&n.name===`paragraph`;return a&&(s||c)?(i.innerHTML=s?o:``,n.lastSavedDataInternal=e,n.inputManager.dropCache(),n.toggleEmptyMark(),n.callToolUpdated(),!0):!1}async validate(e){var t=this;return t.toolInstance.validate instanceof Function?await t.toolInstance.validate(e):!0}async exportDataAsString(e){return t.xr(await this.data,e)}get data(){return this.save().then(e=>e&&!t.ri(e.data)?e.data:{})}get lastSavedData(){return this.lastSavedDataInternal}get lastSavedTunes(){return this.lastSavedTunesInternal}get preservedData(){return this.lastSavedDataInternal}get preservedTunes(){return this.lastSavedTunesInternal}async extractToolData(){var e=this;try{let t=e.getToolRenderedElement();if(t===null)return;let r=await e.toolInstance.save(t);if(!e.getIsEmpty())return r;if(r==null)return;if(typeof r!=`object`)return r;let i=n.t({},r);return e.sanitizeEmptyFields(i),i}catch(n){let r=n instanceof Error?n:Error(String(n));t.li(`Saving process for ${e.name} tool failed due to the ${r}`,`log`,r);return}}sanitizeEmptyFields(e){let n=n=>{let r=e[n];if(typeof r!=`string`)return;let i=document.createElement(`div`);i.innerHTML=r,t.Fr.isEmpty(i)&&(e[n]=``)};n(`text`),n(`html`)}},u=class{constructor(e,t){this.holder=e,this.onInputEvent=t,this.cachedInputs=[],this.inputIndex=0,this.handleFocus=()=>{this.dropCache(),this.updateCurrentInput()}}get inputs(){if(this.cachedInputs.length!==0)return this.cachedInputs;let e=t.Fr.findAllInputs(this.holder);return e.length>0&&this.inputIndex>e.length-1&&(this.inputIndex=e.length-1),this.cachedInputs=e,e}get currentInput(){return this.inputs[this.inputIndex]}set currentInput(e){if(e===void 0)return;let t=this.inputs.findIndex(t=>t===e||t.contains(e));t!==-1&&(this.inputIndex=t)}get currentInputIndex(){return this.inputIndex}get firstInput(){return this.inputs[0]}get lastInput(){let e=this.inputs;return e[e.length-1]}get nextInput(){return this.inputs[this.inputIndex+1]}get previousInput(){return this.inputs[this.inputIndex-1]}updateCurrentInput(){var e;let n=t.mr.anchorNode,r=document.activeElement,i=e=>{if(!e)return;let n=e instanceof HTMLElement?e:e.parentElement;if(n===null)return;let r=this.inputs.find(e=>e===n||e.contains(n));if(r!==void 0)return r;let i=n.closest(t.Fr.allInputsSelector);if(i instanceof HTMLElement)return this.inputs.find(e=>e===i)};if(t.Fr.isNativeInput(r)){this.currentInput=r;return}let a=(e=i(n))==null?r instanceof HTMLElement?i(r):void 0:e;if(a!==void 0){this.currentInput=a;return}r instanceof HTMLElement&&this.inputs.includes(r)&&(this.currentInput=r)}dropCache(){this.cachedInputs=[]}addInputEvents(){this.inputs.forEach(e=>{e.addEventListener(`focus`,this.handleFocus),t.Fr.isNativeInput(e)&&e.addEventListener(`input`,this.onInputEvent)})}removeInputEvents(){this.inputs.forEach(e=>{e.removeEventListener(`focus`,this.handleFocus),t.Fr.isNativeInput(e)&&e.removeEventListener(`input`,this.onInputEvent)})}destroy(){this.removeInputEvents(),this.cachedInputs=[]}},d=`block changed`,f=`block-settings-closed`,p=`block-settings-opened`,m=`blok mobile layout toggled`,h=`fake cursor is about to be toggled`,g=`fake cursor have been set`,_=`redactor dom changed`,v=(e,t)=>{let{type:n,target:r,addedNodes:i,removedNodes:a}=e;return e.type===`attributes`&&(e.attributeName===`data-blok-empty`||e.attributeName===`data-blok-toggle-open`)?!1:t.contains(r)?!0:n===`childList`?Array.from(i).some(e=>e===t)?!0:Array.from(a).some(e=>e===t):!1},y=class{constructor(e,t,n){this.getToolElement=e,this.blokEventBus=t,this.onMutation=n,this.redactorDomChangedCallback=null}watch(){var e;this.redactorDomChangedCallback=e=>{let{mutations:t}=e,n=this.getToolElement();if(n===null)return;let r=t.filter(e=>v(e,n));r.length>0&&this.onMutation(r)},(e=this.blokEventBus)==null||e.on(`redactor dom changed`,this.redactorDomChangedCallback)}unwatch(){if(this.redactorDomChangedCallback){var e;(e=this.blokEventBus)==null||e.off(`redactor dom changed`,this.redactorDomChangedCallback),this.redactorDomChangedCallback=null}}handleMutation(e){let t=e===void 0,n=e instanceof InputEvent,r=!t&&!n?this.detectToolRootChange(e):null;return{shouldFireUpdate:this.shouldFireUpdate(e),newToolRoot:r}}detectToolRootChange(e){let t=this.getToolElement();if(t===null)return null;for(let n of e){if(!Array.from(n.removedNodes).includes(t))continue;let e=n.addedNodes[n.addedNodes.length-1];if(e instanceof HTMLElement)return e}return null}destroy(){this.unwatch()}shouldFireUpdate(e){let n=e===void 0,r=e instanceof InputEvent;if(n||r)return!0;let i=this.getToolElement();return!(e.length>0&&e.every(e=>{let{addedNodes:n,removedNodes:r,target:a}=e,o=[...Array.from(n),...Array.from(r),a],s=e=>{if(!t.Fr.isElement(e)){var n;return(n=e.parentElement)==null?t.Fr.isElement(a)?a:null:n}return e.isConnected?e:t.Fr.isElement(a)?a:null};return o.every(e=>{let t=s(e);if(t===null)return!1;let n=t.closest(`[data-blok-mutation-free="true"]`);return n!==null&&i!==null&&i.contains(n)})}))}},b=class{constructor(e,t,n,r,i){this.holder=e,this.getContentElement=t,this.getStretched=n,this.blokEventBus=r,this.styleManager=i}set selected(e){var n,r;e?this.holder.setAttribute(t.hi.selected,`true`):this.holder.removeAttribute(t.hi.selected),this.handleFakeCursor(e);let i=e&&t.mr.isRangeInsideContainer(this.holder),a=!e&&t.mr.isFakeCursorInsideContainer(this.holder);!i&&!a||((n=this.blokEventBus)==null||n.emit(`fake cursor is about to be toggled`,{state:e}),i&&t.mr.addFakeCursor(),a&&t.mr.removeFakeCursor(this.holder),(r=this.blokEventBus)==null||r.emit(`fake cursor have been set`,{state:e}))}get selected(){return this.holder.getAttribute(t.hi.selected)===`true`}handleFakeCursor(e){let t=this.getContentElement(),n=this.getStretched();t&&this.styleManager.updateContentState(e,n)}},x,S=class e{constructor(e,t){this.holder=e,this.contentElement=t}static get wrapperStyles(){return e.styles.wrapper}static get contentStyles(){return e.styles.content}setStretchState(e,n=!1){e?this.holder.setAttribute(t.hi.stretched,`true`):this.holder.removeAttribute(t.hi.stretched),this.contentElement&&!n&&this.updateContentState(!1,e)}get stretched(){return this.holder.getAttribute(t.hi.stretched)===`true`}updateContentState(e,t){this.contentElement&&(this.contentElement.className=this.getContentClasses(e,t))}getContentClasses(t,n){return t&&n?r.n(e.styles.content,e.styles.contentSelected,e.styles.contentStretched):t?r.n(e.styles.content,e.styles.contentSelected):n?r.n(e.styles.content,e.styles.contentStretched):e.styles.content}};x=S,x.styles={wrapper:`relative opacity-100 first:mt-0 last:pb-0 last:mb-0 [&_a]:cursor-pointer [&_a]:underline [&_a]:text-link [&_b]:font-bold [&_i]:italic`,content:`relative mx-auto transition-colors duration-150 ease-out max-w-blok-content`,contentSelected:`bg-selection rounded-[4px] **:[[contenteditable]]:select-none [&_img]:opacity-55 **:data-[blok-tool=stub]:opacity-55`,contentStretched:`max-w-none`};var ee=class{constructor(e,t,n,r,i){this.toolInstance=e,this.name=t,this.id=n,this.tunesManager=r,this.config=i,this.toolRenderedElementInternal=null,this.contentElementInternal=null,this.readyResolver=null,this.ready=new Promise(e=>{this.readyResolver=e})}get toolRenderedElement(){return this.toolRenderedElementInternal}set toolRenderedElement(e){this.toolRenderedElementInternal=e}get contentElement(){return this.contentElementInternal}get pluginsContent(){if(this.toolRenderedElementInternal===null)throw Error(`Block pluginsContent is not yet initialized`);return this.toolRenderedElementInternal}compose(){let e=t.Fr.make(`div`,this.getWrapperStyles()),n=t.Fr.make(`div`,this.getContentStyles());this.contentElementInternal=n,e.setAttribute(t.hi.element,``),n.setAttribute(t.hi.elementContent,``),n.setAttribute(`data-blok-testid`,`block-content`),e.setAttribute(`data-blok-testid`,`block-wrapper`),this.name&&!e.hasAttribute(`data-blok-component`)&&e.setAttribute(`data-blok-component`,this.name),e.setAttribute(`data-blok-id`,this.id);let r=this.toolInstance.render();r instanceof Promise?this.handleAsyncRender(r,n,e):this.handleSyncRender(r,n,e);let i=this.tunesManager.wrapContent(n);return e.appendChild(i),e}refreshToolRootElement(e){let n=e.querySelector(`[${t.hi.elementContent}]`);if(!n)return;let r=n.firstElementChild;r&&r!==this.toolRenderedElementInternal&&(this.toolRenderedElementInternal=r)}handleSyncRender(e,t,n){this.toolRenderedElementInternal=e,this.addToolDataAttributes(e,n),t.appendChild(e),this.invokeRenderedLifecycle()}handleAsyncRender(e,n,r){e.then(e=>{this.toolRenderedElementInternal=e,this.addToolDataAttributes(e,r),n.appendChild(e),this.invokeRenderedLifecycle()}).catch(e=>{var n;t.li(`Tool render promise rejected: %o`,`error`,e),(n=this.readyResolver)==null||n.call(this)})}invokeRenderedLifecycle(){let e=this.toolInstance.rendered;if(typeof e==`function`){let n=this.readyResolver,r=this.toolInstance,i=this.name;requestAnimationFrame(()=>{try{e.call(r)}catch(e){t.li(`${i}: rendered() threw: ${e instanceof Error?e.message:String(e)}`,`warn`)}finally{n==null||n()}})}else{var n;(n=this.readyResolver)==null||n.call(this)}}addToolDataAttributes(e,t){this.name&&!t.hasAttribute(`data-blok-component`)&&t.setAttribute(`data-blok-component`,this.name);let n=`data-blok-placeholder`,r=this.config.placeholder,i=typeof r==`string`?r.trim():``;if(this.name===`paragraph`)return;let a=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-blok-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-blok-placeholder)]`];if(i.length>0){e.setAttribute(n,i),e.classList.add(...a);return}r===!1&&e.hasAttribute(n)&&e.removeAttribute(n)}getWrapperStyles(){return S.wrapperStyles}getContentStyles(){return S.contentStyles}},te=class{constructor(e,t,n){this.tunes=e,this.blockAPI=n,this.tunesInstances=new Map,this.defaultTunesInstances=new Map,this.unavailableTunesData={},this.composeTunes(t)}getMenuConfig(e){let n=[],r=[],i=(e,n)=>{if(e){if(t.Fr.isElement(e)){n.push({type:t.pr.Html,element:e});return}if(Array.isArray(e)){n.push(...e);return}n.push(e)}};return i(e,n),[...this.tunesInstances.values(),...this.defaultTunesInstances.values()].map(e=>e.render()).forEach(e=>{i(e,r)}),{toolTunes:n,commonTunes:r}}wrapContent(e){return[...this.tunesInstances.values(),...this.defaultTunesInstances.values()].reduce((e,n)=>{if(t.ii(n.wrap))try{return n.wrap(e)}catch(r){return t.li(`Tune ${n.constructor.name} wrap method throws an Error %o`,`warn`,r),e}return e},e)}extractTunesData(){let e=n.t({},this.unavailableTunesData);return[...this.tunesInstances.entries(),...this.defaultTunesInstances.entries()].forEach(([n,r])=>{if(t.ii(r.save))try{e[n]=r.save()}catch(e){t.li(`Tune ${r.constructor.name} save method throws an Error %o`,`warn`,e)}}),e}get userTunes(){return this.tunesInstances}get defaultTunes(){return this.defaultTunesInstances}composeTunes(e){Array.from(this.tunes.values()).forEach(t=>{(t.isInternal?this.defaultTunesInstances:this.tunesInstances).set(t.name,t.create(e[t.name],this.blockAPI))}),Object.entries(e).forEach(([e,t])=>{this.tunesInstances.has(e)||(this.unavailableTunesData[e]=t)})}},C=function(e){return e.RENDERED=`rendered`,e.MOVED=`moved`,e.UPDATED=`updated`,e.REMOVED=`removed`,e.ON_PASTE=`onPaste`,e}({}),ne=class extends t.yr{constructor({id:e=t.Hr(),data:n,tool:r,readOnly:i,tunesData:a,parentId:o,contentIds:s,bindMutationWatchersImmediately:d=!1,lastEditedAt:f,lastEditedBy:p},m){super(),this.blokEventBus=null,this.draggableCleanup=null,this.destroyCallbacks=new Set,this.didMutated=(e=void 0)=>{let t=this.mutationHandler.handleMutation(e);t.newToolRoot&&(this.toolRenderer.toolRenderedElement=t.newToolRoot),t.shouldFireUpdate&&(this.inputManager.dropCache(),this.inputManager.updateCurrentInput(),this.toggleInputsEmptyMark(),this.call(C.UPDATED),this.emit(`didMutated`,this))};let h=e===``?t.Hr():e;if(this.name=r.name,this.id=h,this.parentId=o==null?null:o,this.contentIds=s==null?[]:s,this.lastEditedAt=f==null?Date.now():f,this.lastEditedBy=p==null?null:p,this.settings=r.settings,this.config=this.settings,this.blokEventBus=m||null,this.blockAPI=new c(this),this.readOnly=i,this.tool=r,this.toolInstance=r.create(n,this.blockAPI,i),this.tunes=r.tunes,this.tunesManager=new te(this.tunes,a,this.blockAPI),this.toolRenderer=new ee(this.toolInstance,this.name,this.id,this.tunesManager,this.config),this.holder=this.toolRenderer.compose(),this.ready=this.toolRenderer.ready,this.styleManager=new S(this.holder,this.toolRenderer.contentElement),this.selectionManager=new b(this.holder,()=>this.toolRenderer.contentElement,()=>this.styleManager.stretched,this.blokEventBus,this.styleManager),this.inputManager=new u(this.holder,()=>this.didMutated()),this.mutationHandler=new y(()=>this.toolRenderer.toolRenderedElement,this.blokEventBus,e=>this.didMutated(e)),this.dataPersistenceManager=new l(this.toolInstance,()=>this.toolRenderer.toolRenderedElement,this.tunesManager,this.name,()=>this.isEmpty,this.inputManager,()=>this.call(C.UPDATED),()=>this.toggleInputsEmptyMark(),n,a),!i){let e=()=>{this.mutationHandler.watch(),this.inputManager.addInputEvents(),this.toggleInputsEmptyMark()};d?e():window.requestIdleCallback(e)}}setupDraggable(e,t){this.cleanupDraggable(),this.draggableCleanup=t.setupDragHandle(e,this)}cleanupDraggable(){this.draggableCleanup&&(this.draggableCleanup(),this.draggableCleanup=null)}call(e,n){let r=this.toolInstance[e];if(t.ii(r))try{r.call(this.toolInstance,n)}catch(n){t.li(`Error during '${e}' call: ${n instanceof Error?n.message:String(n)}`,`error`)}}async mergeWith(e){var n=this;if(!t.ii(n.toolInstance.merge))throw Error(`Block tool "${n.name}" does not support merging`);await n.toolInstance.merge(e)}getContentOffset(e){if(typeof this.toolInstance.getContentOffset==`function`)return this.toolInstance.getContentOffset(e)}getToolbarAnchorElement(){if(typeof this.toolInstance.getToolbarAnchorElement==`function`)return this.toolInstance.getToolbarAnchorElement()}async save(){var e=this;let t=await e.dataPersistenceManager.save();if(t!==void 0)return t.id=e.id,t}async validate(e){return this.dataPersistenceManager.validate(e)}getTunes(){let e=typeof this.toolInstance.renderSettings==`function`?this.toolInstance.renderSettings():[];return this.tunesManager.getMenuConfig(e)}updateCurrentInput(){this.inputManager.updateCurrentInput()}dispatchChange(){this.didMutated()}async setData(e){return this.dataPersistenceManager.setData(e)}addDestroyCallback(e){return this.destroyCallbacks.add(e),()=>{this.destroyCallbacks.delete(e)}}destroy(){let e=Array.from(this.destroyCallbacks);this.destroyCallbacks.clear(),e.forEach(e=>e()),this.mutationHandler.destroy(),this.inputManager.destroy(),this.draggableCleanup&&(this.draggableCleanup(),this.draggableCleanup=null),super.destroy(),t.ii(this.toolInstance.destroy)&&this.toolInstance.destroy()}setReadOnly(e){this.readOnly!==e&&(this.readOnly=e,e?(this.inputManager.removeInputEvents(),this.mutationHandler.unwatch()):(this.inputManager.addInputEvents(),this.mutationHandler.watch()),typeof this.toolInstance.setReadOnly==`function`&&this.toolInstance.setReadOnly(e))}async getActiveToolboxEntry(){var e=this;let n=e.tool.toolbox;if(!n)return;if(n.length===1)return Promise.resolve(n[0]);let r=await e.data;return n.find(e=>e.data!==void 0&&t.Er(e.data,r))}async exportDataAsString(){var e=this,t;return e.dataPersistenceManager.exportDataAsString((t=e.tool.conversionConfig)==null?{}:t)}get inputs(){return this.inputManager.inputs}get currentInput(){return this.inputManager.currentInput}get currentInputIndex(){return this.inputManager.currentInputIndex}set currentInput(e){this.inputManager.currentInput=e}get firstInput(){return this.inputManager.firstInput}get lastInput(){return this.inputManager.lastInput}get nextInput(){return this.inputManager.nextInput}get previousInput(){return this.inputManager.previousInput}get data(){return this.dataPersistenceManager.data}get preservedData(){return this.dataPersistenceManager.preservedData}get preservedTunes(){return this.dataPersistenceManager.preservedTunes}get sanitize(){return this.tool.sanitizeConfig}get mergeable(){return t.ii(this.toolInstance.merge)}get focusable(){return this.inputs.length!==0}get isEmpty(){let e=t.Fr.isEmpty(this.pluginsContent,`/`),n=!this.hasMedia;return e&&n}get hasMedia(){return!!this.holder.querySelector([`img`,`iframe`,`video`,`audio`,`source`,`input`,`textarea`,`twitterwidget`].join(`,`))}set selected(e){this.selectionManager.selected=e}get selected(){return this.selectionManager.selected}setStretchState(e){this.styleManager.setStretchState(e,this.selected)}set stretched(e){this.setStretchState(e)}get stretched(){return this.styleManager.stretched}get pluginsContent(){return this.toolRenderer.pluginsContent}unwatchBlockMutations(){this.mutationHandler.unwatch()}refreshToolRootElement(){this.toolRenderer.refreshToolRootElement(this.holder),this.inputManager.dropCache()}toggleInputsEmptyMark(){this.inputs.forEach(t.Lr)}};function re(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function ie(e,t){if(e==null)return{};var n,r,i=re(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var ae=[`file`,`withBorder`,`withBackground`,`stretched`],oe=[`parent`,`content`],se={general:null,note:`blue`,important:`purple`,warning:`orange`,additional:`yellow`,recommendation:`green`,caution:`red`},ce={blue:`note`,purple:`important`,orange:`warning`,yellow:`additional`,green:`recommendation`,red:`caution`},le=`💡`,ue=e=>typeof e==`object`&&`text`in e&&!(`content`in e),de=e=>typeof e==`string`?{content:e}:ue(e)?{content:e.text,checked:e.checked}:e,fe=e=>e.some(e=>{let t=de(e);return t.items!==void 0&&t.items.length>0}),pe=e=>typeof e==`object`&&!!e&&`text`in e&&typeof e.text==`string`,me=e=>typeof e==`object`&&!!e&&`checked`in e&&typeof e.checked==`boolean`,he=e=>typeof e==`object`&&!!e&&`style`in e&&typeof e.style==`string`,ge=e=>typeof e==`object`&&!!e&&`start`in e&&typeof e.start==`number`,_e=e=>typeof e==`object`&&!!e&&`items`in e,ve=e=>typeof e==`object`&&!!e&&`style`in e&&`items`in e&&Array.isArray(e.items),ye=e=>e.type===`list`&&ve(e.data),be=e=>{if(e.type!==`toggleList`)return!1;let t=e.data;return typeof t==`object`&&!!t&&`title`in t},xe=e=>{if(e.type!==`callout`)return!1;let t=e.data;return typeof t==`object`&&!!t&&`body`in t},Se=e=>{if(e.type!==`image`)return!1;let t=e.data;if(typeof t!=`object`||!t)return!1;let n=t.file;return typeof n!=`object`||!n?!1:typeof n.url==`string`},Ce=e=>{if(!ye(e))return!1;let t=e.data.items;return fe(t)},we=e=>e.parent!==void 0||e.content!==void 0&&e.content.length>0,Te=e=>{let t=e.some(we),n=e.some(ye),r=e.some(be),i=e.some(xe),a=e.some(Se),o=n||r||i||a;return t&&!o?{format:`hierarchical`,hasHierarchy:!0}:o?{format:`legacy`,hasHierarchy:t||e.some(Ce)||e.some(e=>{var t;return be(e)&&((t=e.data.body)==null?void 0:t.blocks)!==void 0&&e.data.body.blocks.length>0})||e.some(e=>{var t;return xe(e)&&((t=e.data.body)==null?void 0:t.blocks)!==void 0&&e.data.body.blocks.length>0})}:{format:`flat`,hasHierarchy:!1}},Ee=(e,r,i,a,o,s,c)=>{let l=[];return e.forEach((e,u)=>{let d=de(e),f=t.Hr();l.push(f);let p=a===`ordered`&&i===0&&u===0&&o!==void 0&&o!==1,m=d.items&&d.items.length>0,h=n.t(n.t({id:f,type:`list`,data:n.t(n.t({text:d.content,checked:d.checked,style:a},i>0?{depth:i}:{}),p?{start:o}:{})},s===void 0?{}:{tunes:s}),r===void 0?{}:{parent:r});if(c.push(h),!m||!d.items)return;let g=Ee(d.items,f,i+1,a,void 0,s,c);g.length>0&&(h.content=g)}),l},De=(e,t)=>{let n=[],r=e.style,i=e.start;return Ee(e.items,void 0,0,r,i,t,n),n},Oe=(e,r,i,a)=>{var o;if(e.parent!==void 0){a.push(e);return}let s=(o=e.id)==null?t.Hr():o;i.push(s),a.push(n.t(n.t({},e),{},{id:s,parent:r}))},ke=(e,t)=>{let n=[],r=[];for(let i of e){let e=Ne([i]);for(let i of e)Oe(i,t,n,r)}for(let e of r){let r=e.parent!==void 0,a=e.id!==void 0&&n.includes(e.id);if(!r&&!a){var i;throw Error(`expandLegacyBodyBlocks: orphaned block emitted (type=${e.type}, id=${(i=e.id)==null?`<none>`:i}). Every root-level expansion must be re-parented to ${t}.`)}}return{childIds:n,childBlocks:r}},Ae=e=>{var r,i,a;let o=[],s=(r=e.id)==null?t.Hr():r,{childIds:c,childBlocks:l}=ke((i=(a=e.data.body)==null?void 0:a.blocks)==null?[]:i,s),u=n.t(n.t({id:s},e.tunes===void 0?{}:{tunes:e.tunes}),c.length>0?{content:c}:{}),d=typeof e.data.isExpanded==`boolean`?{isOpen:e.data.isExpanded}:{};return typeof e.data.titleVariant==`number`?o.push(n.t(n.t({},u),{},{type:`header`,data:n.t({text:e.data.title,level:e.data.titleVariant,isToggleable:!0},d)})):o.push(n.t(n.t({},u),{},{type:`toggle`,data:n.t({text:e.data.title},d)})),o.push(...l),o},je=e=>{var r,i,a,o,s;let c=[],l=(r=e.id)==null?t.Hr():r,{childIds:u,childBlocks:d}=ke((i=(a=e.data.body)==null?void 0:a.blocks)==null?[]:i,l),f=(o=e.data.variant)==null?`general`:o,p=f in se?se[f]:null,m=e.data.isEmojiVisible===!1?``:(s=e.data.emoji)==null?le:s;return c.push(n.t(n.t({id:l,type:`callout`,data:{emoji:m,textColor:null,backgroundColor:p}},e.tunes===void 0?{}:{tunes:e.tunes}),u.length>0?{content:u}:{})),c.push(...d),c},Me=e=>{var r,i;let a=(r=e.data)==null?{}:r,{file:o,withBorder:s,withBackground:c,stretched:l}=a,u=ie(a,ae),d=typeof o==`object`&&o?o.url:void 0,f=typeof d==`string`?d:``;return n.t(n.t({},e),{},{id:(i=e.id)==null?t.Hr():i,data:n.t(n.t(n.t({url:f},u),s===!0?{frame:`border`}:{}),l===!0?{size:`full`}:{})})},Ne=e=>{let r=[];for(let a of e)if(ye(a)){let e=De(a.data,a.tunes);r.push(...e)}else if(be(a)){let e=Ae(a);r.push(...e)}else if(xe(a)){let e=je(a);r.push(...e)}else if(Se(a))r.push(Me(a));else{var i;r.push(n.t(n.t({},a),{},{id:(i=a.id)==null?t.Hr():i}))}return r},Pe=(e,t)=>{e&&t.add(e)},Fe=e=>{let{parent:t,content:n}=e;return ie(e,oe)},Ie=(e,t,n)=>{let r=[];for(let i of e){let e=t.get(i);if(e&&e.type===`list`){let i=Le(e,t,n);r.push(...i)}}return r},Le=(e,t,n)=>{let r=[];e.id&&n.add(e.id);let i=e.data,a={content:pe(i)?i.text:``,checked:me(i)?i.checked:void 0},o=e.content;return o!==void 0&&o.length>0&&(a.items=Ie(o,t,n)),a.items!==void 0&&a.items.length===0&&delete a.items,r.push(a),r},Re=(e,t,r)=>{let i=Le(e,t,r),a=e.data,o=he(a)?a.style:`unordered`,s=ge(a)?a.start:void 0;return n.t({id:e.id,type:`list`,data:n.t({style:o,items:i},o===`ordered`&&s!==void 0&&s!==1?{start:s}:{})},e.tunes===void 0?{}:{tunes:e.tunes})};function ze(e,t,n){let r=[];for(let i of e){if(n.has(i))continue;let e=t.get(i);if(e!==void 0){if(We(e)){r.push(Re(e,t,n));continue}if(Ve(e)){r.push(Be(e,t,n));continue}if(He(e)){r.push(Ue(e,t,n));continue}if(Ge(e)){r.push(Ke(e,t,n));continue}Pe(e.id,n),r.push(Fe(e))}}return r}var Be=(e,t,r)=>{var i;Pe(e.id,r);let a=e.data,o=pe(a)?a.text:``,s=typeof(a==null?void 0:a.isOpen)==`boolean`?a.isOpen:void 0,c=ze((i=e.content)==null?[]:i,t,r);return n.t({id:e.id,type:`toggleList`,data:n.t(n.t({title:o},s===void 0?{}:{isExpanded:s}),c.length>0?{body:{blocks:c}}:{})},e.tunes===void 0?{}:{tunes:e.tunes})},Ve=e=>e.type===`toggle`,He=e=>{if(e.type!==`header`)return!1;let t=e.data;return typeof t==`object`&&!!t&&t.isToggleable===!0},Ue=(e,t,r)=>{var i;Pe(e.id,r);let a=e.data,o=pe(a)?a.text:``,s=typeof(a==null?void 0:a.level)==`number`?a.level:void 0,c=typeof(a==null?void 0:a.isOpen)==`boolean`?a.isOpen:void 0,l=ze((i=e.content)==null?[]:i,t,r);return n.t({id:e.id,type:`toggleList`,data:n.t(n.t(n.t({title:o},s===void 0?{}:{titleVariant:s}),c===void 0?{}:{isExpanded:c}),l.length>0?{body:{blocks:l}}:{})},e.tunes===void 0?{}:{tunes:e.tunes})},We=e=>{if(e.type!==`list`)return!1;let t=e.data,n=pe(t),r=_e(t);return n&&!r},Ge=e=>{if(e.type!==`callout`)return!1;let t=e.data;return typeof t==`object`&&!!t&&!(`body`in t)},Ke=(e,t,r)=>{var i,a;Pe(e.id,r);let o=e.data,s=o.backgroundColor,c=s==null||(i=ce[s])==null?`general`:i,l=o.emoji,u=typeof l==`string`&&l.length>0,d=u?l:null,f=ze((a=e.content)==null?[]:a,t,r);return n.t({id:e.id,type:`callout`,data:n.t({title:``,variant:c,emoji:d,isEmojiVisible:u},f.length>0?{body:{blocks:f}}:{})},e.tunes===void 0?{}:{tunes:e.tunes})},qe=(e,t,n)=>{if(!e.id||!e.parent||!t.has(e.parent))return;let r=n.get(e.parent);if(r===void 0){n.set(e.parent,[e.id]);return}r.push(e.id)},Je=(e,t,n)=>{let r=(Array.isArray(e)?e:[]).filter(e=>n.has(e));for(let e of t)r.includes(e)||r.push(e);return r},Ye=e=>{let t=e.map(e=>n.t({},e)),r=new Map;for(let e of t)e.id&&r.set(e.id,e);let i=new Map;for(let e of t)qe(e,r,i);for(let[e,t]of i){let n=r.get(e);n!==void 0&&(n.content=Je(n.content,t,r))}let a=new Map;for(let e of t)e.id&&a.set(e.id,e);let o=t.some(We),s=t.some(Ve),c=t.some(e=>He(e)&&!e.parent),l=t.some(Ge);if(!o&&!s&&!c&&!l)return t.map(Fe);let u=[],d=new Set;for(let e of t){if(e.id&&d.has(e.id))continue;let t=We(e),n=t&&!e.parent,r=Ve(e),i=r&&!e.parent,o=He(e),s=o&&!e.parent,c=Ge(e),l=c&&!e.parent,f=!t&&!r&&!o&&!c;if(n){let t=Re(e,a,d);u.push(t)}if(i){let t=Be(e,a,d);u.push(t)}if(s){let t=Ue(e,a,d);u.push(t)}if(l){let t=Ke(e,a,d);u.push(t)}f&&(u.push(Fe(e)),Pe(e.id,d))}return u},Xe=e=>typeof e==`object`&&!!e&&Array.isArray(e.blocks),Ze=e=>{if(typeof e!=`object`||!e)return null;let t=e.content;return Array.isArray(t)?t:null},Qe=(e,t,n)=>{if(Xe(e))for(let r of e.blocks)typeof r!=`string`||n.has(r)||n.set(r,t)},$e=(e,t,n)=>{Array.isArray(e)&&e.forEach(e=>Qe(e,t,n))},et=(e,t)=>{if(e.id===void 0||e.id===null)return;let n=Ze(e.data);if(n===null)return;let r=e.id;n.forEach(e=>$e(e,r,t))},tt=e=>{let t=new Map;return e.filter(e=>e.type===`table`).forEach(e=>et(e,t)),t.size===0?e:e.map(e=>{if(e.id===void 0||e.id===null)return e;let r=t.get(e.id);return r===void 0||e.parent!==void 0&&e.parent!==null?e:n.t(n.t({},e),{},{parent:r})})},nt=/^cell-([1-9]\d*)-([1-9]\d*)$/,rt=e=>{if(typeof e!=`string`)return null;let t=nt.exec(e);if(t===null)return null;let n=Number(t[1])-1,r=Number(t[2])-1;return n<0||r<0?null:{row:n,col:r}},it=(e,t,n)=>{let r=Ze(e.data);if(r===null)return!1;let i=r[t];if(!Array.isArray(i))return!1;let a=i[n];return Xe(a)&&a.blocks.length===0},at=e=>{let t=new Set;return e.filter(e=>e.type===`table`).forEach(e=>{let n=Ze(e.data);n==null||n.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{Xe(e)&&e.blocks.forEach(e=>{typeof e==`string`&&t.add(e)})})})}),t},ot=e=>{let t=e.filter(e=>e.type===`table`&&e.id!==void 0&&e.id!==null);if(t.length!==1)return e;let r=at(e),i=new Map;for(let t of e)if(t.id!==void 0&&t.id!==null){var a;i.set(t.id,((a=i.get(t.id))==null?0:a)+1)}let o=new Map,s=new Map;for(let a of e){var c,l;if(a.id===void 0||a.id===null||a.parent!==void 0&&a.parent!==null||r.has(a.id)||((c=i.get(a.id))==null?0:c)>1)continue;let e=rt(a.id);if(e===null)continue;let u=t.filter(t=>it(t,e.row,e.col));if(u.length!==1)continue;let d=u[0].id;o.set(a.id,d);let f=(l=s.get(d))==null?[]:l;f.push(n.t(n.t({},e),{},{id:a.id})),s.set(d,f)}return o.size===0?e:e.map(e=>{if(e.id!==void 0&&e.id!==null&&o.has(e.id))return n.t(n.t({},e),{},{parent:o.get(e.id)});if(e.type===`table`&&e.id!==void 0&&e.id!==null&&s.has(e.id)){var t;let r=(t=s.get(e.id))==null?[]:t,i=Ze(e.data);if(i===null)return e;let a=i.map((e,t)=>Array.isArray(e)?e.map((e,i)=>{let a=r.find(e=>e.row===t&&e.col===i);return a===void 0||!Xe(e)?e:n.t(n.t({},e),{},{blocks:[...e.blocks,a.id]})}):e);return n.t(n.t({},e),{},{data:n.t(n.t({},e.data),{},{content:a})})}return e})},st=(e,t)=>t===`legacy`?e!==`legacy`:!1,ct=(e,t)=>e===`legacy`||e===`auto`&&t===`legacy`,lt=`blok-block--target`,ut=1800;function dt(e){e.classList.remove(lt),e.offsetWidth,e.classList.add(lt);let t={removed:!1},n=()=>{t.removed||(t.removed=!0,e.classList.remove(lt),e.removeEventListener(`animationend`,r))},r=t=>{t.target===e&&n()};e.addEventListener(`animationend`,r),window.setTimeout(n,ut)}var ft=class extends s{constructor(...e){var n;super(...e),n=this,this.insert=(e,n={},r={},i,a,o,s)=>{let l=e==null?this.config.defaultBlock:e,u=(()=>{if(!l)return l;let e=i==null?this.Blok.BlockManager.currentBlockIndex:i,n=this.Blok.BlockManager.getBlockByIndex(e);return n!==void 0&&t.Mr(n)&&t.Nr(l)?`paragraph`:l})();return new c(this.Blok.BlockManager.insert({id:s,tool:u,data:n,index:i,needToFocus:a,replace:o}))},this.composeBlockData=async e=>{let t=n.Blok.Tools.blockTools.get(e);if(t===void 0)throw Error(`Block Tool with type "${e}" not found`);return new ne({tool:t,api:n.Blok.API,readOnly:!0,data:{},tunesData:{}}).data},this.update=async(e,t,r)=>{let{BlockManager:i}=n.Blok,a=i.getBlockById(e);if(a===void 0)throw Error(`Block with id "${e}" not found`);return new c(await i.update(a,t,r))},this.convert=async(e,r,i)=>{var a,o;let{BlockManager:s,Tools:l}=n.Blok,u=s.getBlockById(e);if(!u)throw Error(`Block with id "${e}" not found`);let d=l.blockTools.get(u.name),f=l.blockTools.get(r);if(!f)throw Error(`Block Tool with type "${r}" not found`);let p=(d==null||(a=d.conversionConfig)==null?void 0:a.export)!==void 0,m=((o=f.conversionConfig)==null?void 0:o.import)!==void 0;if(p&&m)return new c(await s.convert(u,r,i));{let e=[p?!1:t.qr(u.name),m?!1:t.qr(r)].filter(Boolean).join(` and `);throw Error(`Conversion from "${u.name}" to "${r}" is not possible. ${e} tool(s) should provide a "conversionConfig"`)}},this.insertMany=(e,t=this.Blok.BlockManager.blocks.length-1)=>{this.validateIndex(t);let n=tt(e).map(({id:e,type:t,data:n,tunes:r,parent:i,content:a,lastEditedAt:o,lastEditedBy:s})=>this.Blok.BlockManager.composeBlock({id:e,tool:t||this.config.defaultBlock,data:n,tunes:r,parentId:i,contentIds:a,lastEditedAt:o,lastEditedBy:s}));return this.Blok.BlockManager.insertMany(n,t),n.map(e=>new c(e))},this.insertInsideParent=(e,t,n)=>(this.Blok.BlockManager.suppressStopCapturing||this.Blok.YjsManager.stopCapturing(),new c(this.Blok.BlockManager.insertInsideParent(e,t,n))),this.splitBlock=(e,t,n,r,i)=>{this.Blok.YjsManager.stopCapturing();let a=this.Blok.BlockManager.splitBlockWithData(e,t,n,r,i);return queueMicrotask(()=>{this.Blok.YjsManager.stopCapturing()}),new c(a)}}get methods(){let e=this;return{get isSyncingFromYjs(){return e.Blok.BlockManager.isSyncingFromYjs},clear:()=>this.clear(),render:e=>this.render(e),renderFromHTML:e=>this.renderFromHTML(e),delete:e=>this.delete(e),move:(e,t)=>this.move(e,t),getBlockByIndex:e=>this.getBlockByIndex(e),getById:e=>this.getById(e),getCurrentBlockIndex:()=>this.getCurrentBlockIndex(),getBlockIndex:e=>this.getBlockIndex(e),getBlocksCount:()=>this.getBlocksCount(),getBlockByElement:e=>this.getBlockByElement(e),getChildren:e=>this.getChildren(e),insert:this.insert,insertMany:this.insertMany,update:this.update,composeBlockData:this.composeBlockData,convert:this.convert,setBlockParent:(e,t)=>this.setBlockParent(e,t),stopBlockMutationWatching:e=>this.stopBlockMutationWatching(e),splitBlock:this.splitBlock,insertInsideParent:this.insertInsideParent,transact:e=>this.transact(e),transactWithoutCapture:e=>this.transactWithoutCapture(e),setPointerDragActive:e=>this.setPointerDragActive(e)}}getBlocksCount(){return this.Blok.BlockManager.blocks.length}getCurrentBlockIndex(){return this.Blok.BlockManager.currentBlockIndex}getBlockIndex(e){let n=this.Blok.BlockManager.getBlockById(e);if(!n){t.ui("There is no block with id `"+e+"`",`warn`);return}return this.Blok.BlockManager.getBlockIndex(n)}getBlockByIndex(e){let n=this.Blok.BlockManager.getBlockByIndex(e);if(n===void 0){t.ui("There is no block at index `"+e+"`",`warn`);return}return new c(n)}getById(e){let n=this.Blok.BlockManager.getBlockById(e);return n===void 0?(t.ui("There is no block with id `"+e+"`",`warn`),null):new c(n)}getBlockByElement(e){let n=this.Blok.BlockManager.getBlock(e);if(n===void 0){var r,i;t.ui(`There is no block corresponding to element <${(r=(i=e.tagName)==null?void 0:i.toLowerCase())==null?`unknown`:r}>`,`warn`);return}return new c(n)}getChildren(e){return this.Blok.BlockManager.blocks.filter(t=>t.parentId===e).map(e=>new c(e))}move(e,t){this.Blok.BlockManager.move(e,t)}async delete(e=this.Blok.BlockManager.currentBlockIndex){var n=this;let r=n.Blok.BlockManager.getBlockByIndex(e);if(r===void 0){t.ui(`There is no block at index \`${e}\``,`warn`);return}try{await n.Blok.BlockManager.removeBlock(r)}catch(e){t.ui(e,`warn`);return}n.Blok.BlockManager.currentBlock&&n.Blok.Caret.setToBlock(n.Blok.BlockManager.currentBlock,n.Blok.Caret.positions.END),n.Blok.Toolbar.close()}async clear(){var e=this;await e.Blok.BlockManager.clear(!0),e.Blok.InlineToolbar.close()}async render(e){var t=this;if(e===void 0||e.blocks===void 0)throw Error(`Incorrect data passed to the render() method`);t.Blok.ModificationsObserver.disable(),t.Blok.Renderer.markRenderStart();try{await t.Blok.BlockManager.clear(),await t.Blok.Renderer.render(e.blocks)}finally{t.Blok.Renderer.markRenderEnd()}t.Blok.ModificationsObserver.enable(),t.processPendingHashScroll()}async renderFromHTML(e){var t=this;t.Blok.Renderer.markRenderStart();try{return await t.Blok.BlockManager.clear(),t.Blok.Paste.processText(e,!0)}finally{t.Blok.Renderer.markRenderEnd()}}async importMarkdown(e,t){var n=this;let{markdownToBlocks:r}=await Promise.resolve().then(()=>require(`../markdown.cjs`)),i={blocks:await r(e,t)};return await n.render(i),i}setBlockParent(e,n){let r=this.Blok.BlockManager.getBlockById(e);if(r===void 0){t.ui("There is no block with id `"+e+"`",`warn`);return}this.Blok.BlockManager.setBlockParent(r,n)}stopBlockMutationWatching(e){let t=this.Blok.BlockManager.getBlockByIndex(e);t!==void 0&&t.unwatchBlockMutations()}transact(e){this.Blok.BlockManager.transactForTool(e)}transactWithoutCapture(e){this.Blok.YjsManager.transactWithoutCapture(e)}setPointerDragActive(e){this.Blok.BlockManager.setPointerDragActive(e)}validateIndex(e){if(typeof e!=`number`)throw Error(`Index should be a number`);if(e<0)throw Error(`Index should be greater than or equal to 0`)}processPendingHashScroll(){var e,t;let n=this.Blok.Renderer.pendingHashScroll;if(n===null)return;this.Blok.Renderer.pendingHashScroll=null;let r=document.querySelector(`[data-blok-id="${CSS.escape(n)}"]`);if(r===null)return;let i=(e=(t=this.config.scrollToBlock)==null?void 0:t.topOffset)==null?0:e,a=r.getBoundingClientRect().top+window.scrollY-i;window.scrollTo({top:a,behavior:`smooth`});let o=this.Blok.BlockManager.getBlockById(n);o!==void 0&&this.Blok.BlockSelection.selectBlock(o),dt(r)}},pt=(e,t)=>typeof e==`number`?t.BlockManager.getBlockByIndex(e):typeof e==`string`?t.BlockManager.getBlockById(e):t.BlockManager.getBlockById(e.id),mt=class extends s{constructor(...e){super(...e),this.setToFirstBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.firstBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.firstBlock,e,t),!0):!1,this.setToLastBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.lastBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.lastBlock,e,t),!0):!1,this.setToPreviousBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.previousBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.previousBlock,e,t),!0):!1,this.setToNextBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.nextBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.nextBlock,e,t),!0):!1,this.setToBlock=(e,t=this.Blok.Caret.positions.DEFAULT,n=0)=>{let r=pt(e,this.Blok);return r===void 0?!1:(this.Blok.Caret.setToBlock(r,t,n),!0)},this.focus=(e=!1)=>e?this.setToLastBlock(this.Blok.Caret.positions.END):this.setToFirstBlock(this.Blok.Caret.positions.START),this.updateLastCaretAfterPosition=()=>{this.Blok.YjsManager.updateLastCaretAfterPosition()}}get methods(){return{setToFirstBlock:this.setToFirstBlock,setToLastBlock:this.setToLastBlock,setToPreviousBlock:this.setToPreviousBlock,setToNextBlock:this.setToNextBlock,setToBlock:this.setToBlock,focus:this.focus,updateLastCaretAfterPosition:this.updateLastCaretAfterPosition}}},ht=class extends s{get methods(){return{emit:(e,t)=>this.emit(e,t),off:(e,t)=>this.off(e,t),on:(e,t)=>this.on(e,t)}}on(e,t){this.eventsDispatcher.on(e,t)}emit(e,t){this.eventsDispatcher.emit(e,t)}off(e,t){this.eventsDispatcher.off(e,t)}},gt=class extends s{get methods(){return{undo:()=>this.undo(),redo:()=>this.redo(),canUndo:()=>this.canUndo(),canRedo:()=>this.canRedo(),clear:()=>this.clear()}}undo(){this.Blok.YjsManager.undo()}redo(){this.Blok.YjsManager.redo()}canUndo(){return this.Blok.YjsManager.canUndo()}canRedo(){return this.Blok.YjsManager.canRedo()}clear(){this.Blok.YjsManager.clear()}},_t=class extends s{constructor(...e){super(...e),this.cachedMethods=null}get methods(){return this.cachedMethods===null&&(this.cachedMethods={t:e=>this.Blok.I18n.t(e),has:e=>this.Blok.I18n.has(e),getEnglishTranslation:e=>this.Blok.I18n.getEnglishTranslation(e),getLocale:()=>this.Blok.I18n.getLocale()}),this.cachedMethods}},vt=class extends s{get methods(){return{blocks:this.Blok.BlocksAPI.methods,caret:this.Blok.CaretAPI.methods,tools:this.Blok.ToolsAPI.methods,events:this.Blok.EventsAPI.methods,history:this.Blok.HistoryAPI.methods,listeners:this.Blok.ListenersAPI.methods,notifier:this.Blok.NotifierAPI.methods,sanitizer:this.Blok.SanitizerAPI.methods,saver:this.Blok.SaverAPI.methods,selection:this.Blok.SelectionAPI.methods,styles:this.Blok.StylesAPI.classes,toolbar:this.Blok.ToolbarAPI.methods,inlineToolbar:this.Blok.InlineToolbarAPI.methods,tooltip:this.Blok.TooltipAPI.methods,i18n:this.Blok.I18nAPI.methods,readOnly:this.Blok.ReadOnlyAPI.methods,ui:this.Blok.UiAPI.methods,theme:this.Blok.ThemeAPI.methods,rectangleSelection:this.Blok.RectangleSelection}}},yt=class extends s{get methods(){return{close:()=>this.close(),open:()=>this.open()}}open(){this.Blok.InlineToolbar.tryToShow()}close(){this.Blok.InlineToolbar.close()}},bt=class extends s{get methods(){return{on:(e,t,n,r)=>this.on(e,t,n,r),off:(e,t,n,r)=>this.off(e,t,n,r),offById:e=>this.offById(e)}}on(e,t,n,r){return this.listeners.on(e,t,n,r)}off(e,t,n,r){this.listeners.off(e,t,n,r)}offById(e){this.listeners.offById(e)}},xt=class{constructor(e=i.t){this.notifierModule=null,this.loadingPromise=null,this.position=e}loadNotifierModule(){return this.notifierModule===null?(this.loadingPromise===null&&(this.loadingPromise=Promise.resolve().then(()=>require(`./notifier-r5L-xyuz.cjs`)).then(e=>{let t=e;if(!this.isNotifierModule(t))throw Error(`notifier module does not expose a "show" method.`);return this.notifierModule=t,t}).catch(e=>{throw this.loadingPromise=null,e})),this.loadingPromise):Promise.resolve(this.notifierModule)}show(e){this.loadNotifierModule().then(t=>{t.show(e,this.position)}).catch(e=>{console.error(`[Blok] Failed to display notification. Reason:`,e)})}isNotifierModule(e){return typeof e==`object`&&!!e&&`show`in e&&typeof e.show==`function`}},St=class extends s{constructor({config:e,eventsDispatcher:t}){var n;super({config:e,eventsDispatcher:t}),this.builtInNotifier=new xt((n=e.notifierPosition)==null?i.t:n),this.customNotifier=e.notifier}get methods(){return{show:e=>this.show(e)}}show(e){if(this.customNotifier!==void 0){this.customNotifier(e);return}this.builtInNotifier.show(e)}},Ct=class extends s{get methods(){let e=()=>this.isEnabled;return{toggle:e=>this.toggle(e),set:e=>this.set(e),get isEnabled(){return e()}}}toggle(e){return this.Blok.ReadOnly.toggle(e)}set(e){return this.Blok.ReadOnly.set(e)}get isEnabled(){return this.Blok.ReadOnly.isEnabled}},wt=class extends s{get methods(){return{clean:(e,t)=>this.clean(e,t)}}clean(e,n){return t.ur(e,n)}},Tt=class extends s{get methods(){return{save:()=>this.save()}}async save(){var e=this,n,r;let i=`Blok's content can not be saved in read-only mode`;if(e.Blok.ReadOnly.isEnabled)throw t.ui(i,`warn`),Error(i);let a=await e.Blok.Saver.save();if(a!==void 0)return a;let o=(n=(r=e.Blok.Saver).getLastSaveError)==null?void 0:n.call(r);throw o instanceof Error?o:Error(o===void 0?`Blok's content can not be saved because collecting data failed`:String(o))}},Et=class extends s{constructor(...e){super(...e),this.selectionUtils=new t.mr}get methods(){return{findParentTag:(e,t)=>this.findParentTag(e,t),expandToTag:e=>this.expandToTag(e),save:()=>this.selectionUtils.save(),restore:()=>this.selectionUtils.restore(),setFakeBackground:()=>this.selectionUtils.setFakeBackground(),removeFakeBackground:()=>this.selectionUtils.removeFakeBackground(),clearFakeBackground:()=>this.selectionUtils.clearFakeBackground()}}findParentTag(e,t){return this.selectionUtils.findParentTag(e,t)}expandToTag(e){this.selectionUtils.expandToTag(e)}},Dt=class extends s{get classes(){return{block:`blok-block`,inlineToolButton:`blok-inline-tool-button`,inlineToolButtonActive:`blok-inline-tool-button--active`,input:`blok-input`,loader:`blok-loader`,button:`blok-button`,settingsButton:`blok-settings-button`,settingsButtonActive:`blok-settings-button--active`,settingsButtonFocused:`blok-settings-button--focused`,settingsButtonFocusedAnimated:`blok-settings-button--focused-animated`}}},Ot=class extends s{get methods(){return{close:e=>this.close(e),open:()=>this.open(),toggleBlockSettings:(e,t,n)=>this.toggleBlockSettings(e,t,n),toggleToolbox:e=>this.toggleToolbox(e)}}open(){this.Blok.Toolbar.moveAndOpen()}close(e){this.Blok.Toolbar.close(e)}toggleBlockSettings(e,n,r){if(this.Blok.BlockManager.currentBlockIndex===-1){t.ui(`Could't toggle the Toolbar because there is no block selected `,`warn`);return}(e==null?!this.Blok.BlockSettings.opened:e)?(this.Blok.Toolbar.moveAndOpen(),this.Blok.BlockSettings.open(void 0,n,r)):this.Blok.BlockSettings.close()}toggleToolbox(e){if(this.Blok.BlockManager.currentBlockIndex===-1){t.ui(`Could't toggle the Toolbox because there is no block selected `,`warn`);return}(e==null?!this.Blok.Toolbar.toolbox.opened:e)?(this.Blok.Toolbar.moveAndOpen(),this.Blok.Toolbar.toolbox.open()):this.Blok.Toolbar.toolbox.close()}},kt=class extends s{get methods(){return{getBlockTools:()=>Array.from(this.Blok.Tools.blockTools.values()),getToolsConfig:()=>{let e={tools:this.config.tools};return this.config.inlineToolbar!==void 0&&(e.inlineToolbar=this.config.inlineToolbar),this.config.tunes!==void 0&&(e.tunes=this.config.tunes),this.config.theme!==void 0&&(e.theme=this.config.theme),e}}}},At=class extends s{constructor({config:e,eventsDispatcher:t}){super({config:e,eventsDispatcher:t})}get methods(){return{show:(e,t,n)=>this.show(e,t,n),hide:()=>this.hide(),onHover:(e,t,n)=>this.onHover(e,t,n)}}show(e,n,r){t.sr(e,n,r)}hide(){t.ar()}onHover(e,n,r){t.or(e,n,r)}},jt=class extends s{get methods(){let e=this.Blok.UI;return{nodes:this.blokNodes,get isMobile(){return e.isMobile}}}get blokNodes(){return{wrapper:this.Blok.UI.nodes.wrapper,redactor:this.Blok.UI.nodes.redactor}}},Mt=class extends s{get methods(){let e=this.Blok.ThemeManager;return{get:()=>e.getMode(),set:t=>e.setMode(t),getResolved:()=>e.getResolved()}}},w=()=>new Map,Nt=e=>{let t=w();return e.forEach((e,n)=>{t.set(n,e)}),t},Pt=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Ft=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},It=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Lt=()=>new Set,Rt=e=>e[e.length-1],zt=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Bt=Array.from,Vt=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Ht=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Ut=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},Wt=Array.isArray,Gt=class{constructor(){this._observers=w()}on(e,t){return Pt(this._observers,e,Lt).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Bt((this._observers.get(e)||w()).values()).forEach(e=>e(...t))}destroy(){this._observers=w()}},T=Math.floor,Kt=Math.abs,qt=(e,t)=>e<t?e:t,Jt=(e,t)=>e>t?e:t;Number.isNaN;var Yt=e=>e===0?1/e<0:e<0,Xt=2**53-1,Zt=-(2**53-1),Qt=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&T(e)===e);Number.isNaN,Number.parseInt;var $t=String.fromCharCode;String.fromCodePoint,$t(65535);var en=e=>e.toLowerCase(),tn=/^\s*/g,nn=e=>e.replace(tn,``),rn=/([A-Z])/g,an=(e,t)=>nn(e.replace(rn,e=>`${t}${en(e)}`)),on=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},sn=typeof TextEncoder<`u`?new TextEncoder:null,cn=sn?e=>sn.encode(e):on,ln=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});ln&&ln.decode(new Uint8Array).length===1&&(ln=null);var un=(e,t)=>Ut(t,()=>e).join(``),dn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},fn=()=>new dn,pn=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},E=e=>{let t=new Uint8Array(pn(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},mn=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Jt(n,t)*2),e.cpos=0)},D=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},hn=D,O=(e,t)=>{for(;t>127;)D(e,128|127&t),t=T(t/128);D(e,127&t)},gn=(e,t)=>{let n=Yt(t);for(n&&(t=-t),D(e,(t>63?128:0)|(n?64:0)|63&t),t=T(t/64);t>0;)D(e,(t>127?128:0)|127&t),t=T(t/128)},_n=new Uint8Array(3e4),vn=_n.length/3,yn=sn&&sn.encodeInto?(e,t)=>{if(t.length<vn){let n=sn.encodeInto(t,_n).written||0;O(e,n);for(let t=0;t<n;t++)D(e,_n[t])}else k(e,cn(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;O(e,r);for(let t=0;t<r;t++)D(e,n.codePointAt(t))},bn=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=qt(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Jt(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},k=(e,t)=>{O(e,t.byteLength),bn(e,t)},xn=(e,t)=>{mn(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Sn=(e,t)=>xn(e,4).setFloat32(0,t,!1),Cn=(e,t)=>xn(e,8).setFloat64(0,t,!1),wn=(e,t)=>xn(e,8).setBigInt64(0,t,!1),Tn=new DataView(new ArrayBuffer(4)),En=e=>(Tn.setFloat32(0,e),Tn.getFloat32(0)===e),Dn=(e,t)=>{switch(typeof t){case`string`:D(e,119),yn(e,t);break;case`number`:Qt(t)&&Kt(t)<=2147483647?(D(e,125),gn(e,t)):En(t)?(D(e,124),Sn(e,t)):(D(e,123),Cn(e,t));break;case`bigint`:D(e,122),wn(e,t);break;case`object`:if(t===null)D(e,126);else if(Wt(t)){D(e,117),O(e,t.length);for(let n=0;n<t.length;n++)Dn(e,t[n])}else if(t instanceof Uint8Array)D(e,116),k(e,t);else{D(e,118);let n=Object.keys(t);O(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];yn(e,i),Dn(e,t[i])}}break;case`boolean`:D(e,t?120:121);break;default:D(e,127)}},On=class extends dn{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&O(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},kn=e=>{e.count>0&&(gn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&O(e.encoder,e.count-2))},An=class{constructor(){this.encoder=new dn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(kn(this),this.count=1,this.s=e)}toUint8Array(){return kn(this),E(this.encoder)}},jn=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);gn(e.encoder,t),e.count>1&&O(e.encoder,e.count-2)}},Mn=class{constructor(){this.encoder=new dn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(jn(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return jn(this),E(this.encoder)}},Nn=class{constructor(){this.sarr=[],this.s=``,this.lensE=new An}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new dn;return this.sarr.push(this.s),this.s=``,yn(e,this.sarr.join(``)),bn(e,this.lensE.toUint8Array()),E(e)}},A=e=>Error(e),j=()=>{throw A(`Method unimplemented`)},M=()=>{throw A(`Unexpected case`)};crypto.subtle;var Pn=crypto.getRandomValues.bind(crypto),Fn=()=>Pn(new Uint32Array(1))[0],In=`10000000-1000-4000-8000-100000000000`,Ln=()=>In.replace(/[018]/g,e=>(e^Fn()&15>>e/4).toString(16)),Rn=Date.now,zn=e=>new Promise(e);Promise.all.bind(Promise);var Bn=e=>e===void 0?null:e,Vn=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Vn=localStorage)}catch(e){}var Hn=Vn,Un=Symbol(`Equality`),Wn=(e,t)=>{var n;return e===t||!!(!(e==null||(n=e[Un])==null)&&n.call(e,t))||!1},Gn=e=>typeof e==`object`,Kn=Object.assign,qn=Object.keys,Jn=(e,t)=>{for(let n in e)t(e[n],n)},Yn=e=>qn(e).length,Xn=e=>{for(let t in e)return!1;return!0},Zn=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Qn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),$n=(e,t)=>e===t||Yn(e)===Yn(t)&&Zn(e,(e,n)=>(e!==void 0||Qn(t,n))&&Wn(t[n],e)),er=Object.freeze,tr=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&tr(e[t])}return er(e)},nr=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&nr(e,t,n+1)}},rr=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Un]!=null)return e[Un](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!rr(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Yn(e)!==Yn(t))return!1;for(let n in e)if(!Qn(e,n)||!rr(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!rr(e[n],t[n]))return!1;break;default:return!1}return!0},ir=(e,t)=>t.includes(e),ar=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`;typeof navigator<`u`&&/Mac/.test(navigator.platform);var N,or=[],sr=()=>{if(N===void 0)if(ar){N=w();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&N.set(t,``),t=r):t===null?or.push(r):(N.set(t,r),t=null)}t!==null&&N.set(t,``)}else typeof location==`object`?(N=w(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);N.set(`--${an(t,`-`)}`,n),N.set(`-${an(t,`-`)}`,n)}})):N=w();return N},cr=e=>sr().has(e),lr=e=>Bn(ar?process.env[e.toUpperCase().replaceAll(`-`,`_`)]:Hn.getItem(e)),ur=e=>cr(`--`+e)||lr(e)!==null,dr=ur(`production`),fr=ar&&ir(process.env.FORCE_COLOR,[`true`,`1`,`2`])||!cr(`--no-colors`)&&!ur(`no-color`)&&(!ar||process.stdout.isTTY)&&(!ar||cr(`--color`)||lr(`COLORTERM`)!==null||(lr(`TERM`)||``).includes(`color`)),pr=class{constructor(e,t){this.left=e,this.right=t}},P=(e,t)=>new pr(e,t),mr=e=>e.next()>=.5,hr=(e,t,n)=>T(e.next()*(n+1-t)+t),gr=(e,t,n)=>T(e.next()*(n+1-t)+t),_r=(e,t,n)=>gr(e,t,n),vr=e=>$t(_r(e,97,122)),yr=(e,t=0,n=20)=>{let r=_r(e,t,n),i=``;for(let t=0;t<r;t++)i+=vr(e);return i},br=(e,t)=>t[_r(e,0,t.length-1)],xr,Sr=Symbol(`0schema`),Cr=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(un(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
1
|
+
const e=require(`./chunk-BL1yB9zm.cjs`),t=require(`./constants-Cz29UuPH.cjs`),n=require(`./objectSpread2-iNkE6aJh.cjs`),r=require(`./tw-fzSjDKon.cjs`),i=require(`./types-BQNH-yx9.cjs`),a=require(`./lightweight-i18n-CNdX4sc2.cjs`);e.t(((e,t)=>{function n(){}t.exports=Object.assign(n,{default:n,register:n,revert:function(){},__esModule:!0})}))();var o=class extends Error{},s=class e{get isDestroyed(){return this._isDestroyed}markDestroyed(){this._isDestroyed=!0}constructor({config:n,eventsDispatcher:r}){if(this.nodes={},this._isDestroyed=!1,this.listeners=new t.Ar,this.readOnlyMutableListeners={on:(e,t,n,r=!1)=>{let i=this.listeners.on(e,t,n,r);i&&this.mutableListenerIds.push(i)},clearAll:()=>{for(let e of this.mutableListenerIds)this.listeners.offById(e);this.mutableListenerIds=[]}},this.mutableListenerIds=[],new.target===e)throw TypeError(`Constructors for abstract class Module are not allowed.`);this.config=n,this.eventsDispatcher=r,this.Blok={}}set state(e){this.Blok=e}removeAllNodes(){for(let e in this.nodes){let t=this.nodes[e];t instanceof HTMLElement&&t.remove()}}get isRtl(){var e;return((e=this.config.i18n)==null?void 0:e.direction)===`rtl`}},c=function(e){return Object.setPrototypeOf(this,{get id(){return e.id},get name(){return e.name},get config(){return e.config},get holder(){return e.holder},get parentId(){return e.parentId},get isEmpty(){return e.isEmpty},get selected(){return e.selected},get preservedData(){return e.preservedData},get preservedTunes(){return e.preservedTunes},set stretched(t){e.setStretchState(t)},get stretched(){return e.stretched},get focusable(){return e.focusable},call(t,n){return e.call(t,n)},save(){return e.save()},validate(t){return e.validate(t)},dispatchChange(){e.dispatchChange()},getActiveToolboxEntry(){return e.getActiveToolboxEntry()}}),Object.defineProperties(this,{id:{get(){return e.id},enumerable:!0,configurable:!0},name:{get(){return e.name},enumerable:!0,configurable:!0}}),this},l=class{constructor(e,t,n,r,i,a,o,s,c,l){this.toolInstance=e,this.getToolRenderedElement=t,this.tunesManager=n,this.name=r,this.getIsEmpty=i,this.inputManager=a,this.callToolUpdated=o,this.toggleEmptyMark=s,this.lastSavedDataInternal=c,this.lastSavedTunesInternal=l}async save(){var e=this;let t=await e.extractToolData();if(t===void 0)return;let r=window.performance.now(),i=e.tunesManager.extractTunesData();e.lastSavedDataInternal=t,e.lastSavedTunesInternal=n.t({},i);let a=window.performance.now();return{id:e.name,tool:e.name,data:t,tunes:i,time:a-r}}async setData(e){var n=this;let r=n.toolInstance.setData;if(typeof r==`function`)try{return await r.call(n.toolInstance,e),n.lastSavedDataInternal=e,!0}catch(e){return t.li(`Tool ${n.name} setData failed: ${e instanceof Error?e.message:String(e)}`,`warn`),!1}let i=n.getToolRenderedElement();if(!i)return!1;let a=i.getAttribute(`contenteditable`)===`true`,o=e.text,s=typeof o==`string`,c=Object.keys(e).length===0&&n.name===`paragraph`;return a&&(s||c)?(i.innerHTML=s?o:``,n.lastSavedDataInternal=e,n.inputManager.dropCache(),n.toggleEmptyMark(),n.callToolUpdated(),!0):!1}async validate(e){var t=this;return t.toolInstance.validate instanceof Function?await t.toolInstance.validate(e):!0}async exportDataAsString(e){return t.xr(await this.data,e)}get data(){return this.save().then(e=>e&&!t.ri(e.data)?e.data:{})}get lastSavedData(){return this.lastSavedDataInternal}get lastSavedTunes(){return this.lastSavedTunesInternal}get preservedData(){return this.lastSavedDataInternal}get preservedTunes(){return this.lastSavedTunesInternal}async extractToolData(){var e=this;try{let t=e.getToolRenderedElement();if(t===null)return;let r=await e.toolInstance.save(t);if(!e.getIsEmpty())return r;if(r==null)return;if(typeof r!=`object`)return r;let i=n.t({},r);return e.sanitizeEmptyFields(i),i}catch(n){let r=n instanceof Error?n:Error(String(n));t.li(`Saving process for ${e.name} tool failed due to the ${r}`,`log`,r);return}}sanitizeEmptyFields(e){let n=n=>{let r=e[n];if(typeof r!=`string`)return;let i=document.createElement(`div`);i.innerHTML=r,t.Fr.isEmpty(i)&&(e[n]=``)};n(`text`),n(`html`)}},u=class{constructor(e,t){this.holder=e,this.onInputEvent=t,this.cachedInputs=[],this.inputIndex=0,this.handleFocus=()=>{this.dropCache(),this.updateCurrentInput()}}get inputs(){if(this.cachedInputs.length!==0)return this.cachedInputs;let e=t.Fr.findAllInputs(this.holder);return e.length>0&&this.inputIndex>e.length-1&&(this.inputIndex=e.length-1),this.cachedInputs=e,e}get currentInput(){return this.inputs[this.inputIndex]}set currentInput(e){if(e===void 0)return;let t=this.inputs.findIndex(t=>t===e||t.contains(e));t!==-1&&(this.inputIndex=t)}get currentInputIndex(){return this.inputIndex}get firstInput(){return this.inputs[0]}get lastInput(){let e=this.inputs;return e[e.length-1]}get nextInput(){return this.inputs[this.inputIndex+1]}get previousInput(){return this.inputs[this.inputIndex-1]}updateCurrentInput(){var e;let n=t.mr.anchorNode,r=document.activeElement,i=e=>{if(!e)return;let n=e instanceof HTMLElement?e:e.parentElement;if(n===null)return;let r=this.inputs.find(e=>e===n||e.contains(n));if(r!==void 0)return r;let i=n.closest(t.Fr.allInputsSelector);if(i instanceof HTMLElement)return this.inputs.find(e=>e===i)};if(t.Fr.isNativeInput(r)){this.currentInput=r;return}let a=(e=i(n))==null?r instanceof HTMLElement?i(r):void 0:e;if(a!==void 0){this.currentInput=a;return}r instanceof HTMLElement&&this.inputs.includes(r)&&(this.currentInput=r)}dropCache(){this.cachedInputs=[]}addInputEvents(){this.inputs.forEach(e=>{e.addEventListener(`focus`,this.handleFocus),t.Fr.isNativeInput(e)&&e.addEventListener(`input`,this.onInputEvent)})}removeInputEvents(){this.inputs.forEach(e=>{e.removeEventListener(`focus`,this.handleFocus),t.Fr.isNativeInput(e)&&e.removeEventListener(`input`,this.onInputEvent)})}destroy(){this.removeInputEvents(),this.cachedInputs=[]}},d=`block changed`,f=`block-settings-closed`,p=`block-settings-opened`,m=`blok mobile layout toggled`,h=`fake cursor is about to be toggled`,g=`fake cursor have been set`,_=`redactor dom changed`,v=(e,t)=>{let{type:n,target:r,addedNodes:i,removedNodes:a}=e;return e.type===`attributes`&&(e.attributeName===`data-blok-empty`||e.attributeName===`data-blok-toggle-open`)?!1:t.contains(r)?!0:n===`childList`?Array.from(i).some(e=>e===t)?!0:Array.from(a).some(e=>e===t):!1},y=class{constructor(e,t,n){this.getToolElement=e,this.blokEventBus=t,this.onMutation=n,this.redactorDomChangedCallback=null}watch(){var e;this.redactorDomChangedCallback=e=>{let{mutations:t}=e,n=this.getToolElement();if(n===null)return;let r=t.filter(e=>v(e,n));r.length>0&&this.onMutation(r)},(e=this.blokEventBus)==null||e.on(`redactor dom changed`,this.redactorDomChangedCallback)}unwatch(){if(this.redactorDomChangedCallback){var e;(e=this.blokEventBus)==null||e.off(`redactor dom changed`,this.redactorDomChangedCallback),this.redactorDomChangedCallback=null}}handleMutation(e){let t=e===void 0,n=e instanceof InputEvent,r=!t&&!n?this.detectToolRootChange(e):null;return{shouldFireUpdate:this.shouldFireUpdate(e),newToolRoot:r}}detectToolRootChange(e){let t=this.getToolElement();if(t===null)return null;for(let n of e){if(!Array.from(n.removedNodes).includes(t))continue;let e=n.addedNodes[n.addedNodes.length-1];if(e instanceof HTMLElement)return e}return null}destroy(){this.unwatch()}shouldFireUpdate(e){let n=e===void 0,r=e instanceof InputEvent;if(n||r)return!0;let i=this.getToolElement();return!(e.length>0&&e.every(e=>{let{addedNodes:n,removedNodes:r,target:a}=e,o=[...Array.from(n),...Array.from(r),a],s=e=>{if(!t.Fr.isElement(e)){var n;return(n=e.parentElement)==null?t.Fr.isElement(a)?a:null:n}return e.isConnected?e:t.Fr.isElement(a)?a:null};return o.every(e=>{let t=s(e);if(t===null)return!1;let n=t.closest(`[data-blok-mutation-free="true"]`);return n!==null&&i!==null&&i.contains(n)})}))}},b=class{constructor(e,t,n,r,i){this.holder=e,this.getContentElement=t,this.getStretched=n,this.blokEventBus=r,this.styleManager=i}set selected(e){var n,r;e?this.holder.setAttribute(t.hi.selected,`true`):this.holder.removeAttribute(t.hi.selected),this.handleFakeCursor(e);let i=e&&t.mr.isRangeInsideContainer(this.holder),a=!e&&t.mr.isFakeCursorInsideContainer(this.holder);!i&&!a||((n=this.blokEventBus)==null||n.emit(`fake cursor is about to be toggled`,{state:e}),i&&t.mr.addFakeCursor(),a&&t.mr.removeFakeCursor(this.holder),(r=this.blokEventBus)==null||r.emit(`fake cursor have been set`,{state:e}))}get selected(){return this.holder.getAttribute(t.hi.selected)===`true`}handleFakeCursor(e){let t=this.getContentElement(),n=this.getStretched();t&&this.styleManager.updateContentState(e,n)}},x,S=class e{constructor(e,t){this.holder=e,this.contentElement=t}static get wrapperStyles(){return e.styles.wrapper}static get contentStyles(){return e.styles.content}setStretchState(e,n=!1){e?this.holder.setAttribute(t.hi.stretched,`true`):this.holder.removeAttribute(t.hi.stretched),this.contentElement&&!n&&this.updateContentState(!1,e)}get stretched(){return this.holder.getAttribute(t.hi.stretched)===`true`}updateContentState(e,t){this.contentElement&&(this.contentElement.className=this.getContentClasses(e,t))}getContentClasses(t,n){return t&&n?r.n(e.styles.content,e.styles.contentSelected,e.styles.contentStretched):t?r.n(e.styles.content,e.styles.contentSelected):n?r.n(e.styles.content,e.styles.contentStretched):e.styles.content}};x=S,x.styles={wrapper:`relative opacity-100 first:mt-0 last:pb-0 last:mb-0 [&_a]:cursor-pointer [&_a]:underline [&_a]:text-link [&_b]:font-bold [&_i]:italic`,content:`relative mx-auto transition-colors duration-150 ease-out max-w-blok-content`,contentSelected:`bg-selection rounded-[4px] **:[[contenteditable]]:select-none [&_img]:opacity-55 **:data-[blok-tool=stub]:opacity-55`,contentStretched:`max-w-none`};var ee=class{constructor(e,t,n,r,i){this.toolInstance=e,this.name=t,this.id=n,this.tunesManager=r,this.config=i,this.toolRenderedElementInternal=null,this.contentElementInternal=null,this.readyResolver=null,this.ready=new Promise(e=>{this.readyResolver=e})}get toolRenderedElement(){return this.toolRenderedElementInternal}set toolRenderedElement(e){this.toolRenderedElementInternal=e}get contentElement(){return this.contentElementInternal}get pluginsContent(){if(this.toolRenderedElementInternal===null)throw Error(`Block pluginsContent is not yet initialized`);return this.toolRenderedElementInternal}compose(){let e=t.Fr.make(`div`,this.getWrapperStyles()),n=t.Fr.make(`div`,this.getContentStyles());this.contentElementInternal=n,e.setAttribute(t.hi.element,``),n.setAttribute(t.hi.elementContent,``),n.setAttribute(`data-blok-testid`,`block-content`),e.setAttribute(`data-blok-testid`,`block-wrapper`),this.name&&!e.hasAttribute(`data-blok-component`)&&e.setAttribute(`data-blok-component`,this.name),e.setAttribute(`data-blok-id`,this.id);let r=this.toolInstance.render();r instanceof Promise?this.handleAsyncRender(r,n,e):this.handleSyncRender(r,n,e);let i=this.tunesManager.wrapContent(n);return e.appendChild(i),e}refreshToolRootElement(e){let n=e.querySelector(`[${t.hi.elementContent}]`);if(!n)return;let r=n.firstElementChild;r&&r!==this.toolRenderedElementInternal&&(this.toolRenderedElementInternal=r)}handleSyncRender(e,t,n){this.toolRenderedElementInternal=e,this.addToolDataAttributes(e,n),t.appendChild(e),this.invokeRenderedLifecycle()}handleAsyncRender(e,n,r){e.then(e=>{this.toolRenderedElementInternal=e,this.addToolDataAttributes(e,r),n.appendChild(e),this.invokeRenderedLifecycle()}).catch(e=>{var n;t.li(`Tool render promise rejected: %o`,`error`,e),(n=this.readyResolver)==null||n.call(this)})}invokeRenderedLifecycle(){let e=this.toolInstance.rendered;if(typeof e==`function`){let n=this.readyResolver,r=this.toolInstance,i=this.name;requestAnimationFrame(()=>{try{e.call(r)}catch(e){t.li(`${i}: rendered() threw: ${e instanceof Error?e.message:String(e)}`,`warn`)}finally{n==null||n()}})}else{var n;(n=this.readyResolver)==null||n.call(this)}}addToolDataAttributes(e,t){this.name&&!t.hasAttribute(`data-blok-component`)&&t.setAttribute(`data-blok-component`,this.name);let n=`data-blok-placeholder`,r=this.config.placeholder,i=typeof r==`string`?r.trim():``;if(this.name===`paragraph`)return;let a=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-blok-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-blok-placeholder)]`];if(i.length>0){e.setAttribute(n,i),e.classList.add(...a);return}r===!1&&e.hasAttribute(n)&&e.removeAttribute(n)}getWrapperStyles(){return S.wrapperStyles}getContentStyles(){return S.contentStyles}},te=class{constructor(e,t,n){this.tunes=e,this.blockAPI=n,this.tunesInstances=new Map,this.defaultTunesInstances=new Map,this.unavailableTunesData={},this.composeTunes(t)}getMenuConfig(e){let n=[],r=[],i=(e,n)=>{if(e){if(t.Fr.isElement(e)){n.push({type:t.pr.Html,element:e});return}if(Array.isArray(e)){n.push(...e);return}n.push(e)}};return i(e,n),[...this.tunesInstances.values(),...this.defaultTunesInstances.values()].map(e=>e.render()).forEach(e=>{i(e,r)}),{toolTunes:n,commonTunes:r}}wrapContent(e){return[...this.tunesInstances.values(),...this.defaultTunesInstances.values()].reduce((e,n)=>{if(t.ii(n.wrap))try{return n.wrap(e)}catch(r){return t.li(`Tune ${n.constructor.name} wrap method throws an Error %o`,`warn`,r),e}return e},e)}extractTunesData(){let e=n.t({},this.unavailableTunesData);return[...this.tunesInstances.entries(),...this.defaultTunesInstances.entries()].forEach(([n,r])=>{if(t.ii(r.save))try{e[n]=r.save()}catch(e){t.li(`Tune ${r.constructor.name} save method throws an Error %o`,`warn`,e)}}),e}get userTunes(){return this.tunesInstances}get defaultTunes(){return this.defaultTunesInstances}composeTunes(e){Array.from(this.tunes.values()).forEach(t=>{(t.isInternal?this.defaultTunesInstances:this.tunesInstances).set(t.name,t.create(e[t.name],this.blockAPI))}),Object.entries(e).forEach(([e,t])=>{this.tunesInstances.has(e)||(this.unavailableTunesData[e]=t)})}},C=function(e){return e.RENDERED=`rendered`,e.MOVED=`moved`,e.UPDATED=`updated`,e.REMOVED=`removed`,e.ON_PASTE=`onPaste`,e}({}),ne=class extends t.yr{constructor({id:e=t.Hr(),data:n,tool:r,readOnly:i,tunesData:a,parentId:o,contentIds:s,bindMutationWatchersImmediately:d=!1,lastEditedAt:f,lastEditedBy:p},m){super(),this.blokEventBus=null,this.draggableCleanup=null,this.destroyCallbacks=new Set,this.didMutated=(e=void 0)=>{let t=this.mutationHandler.handleMutation(e);t.newToolRoot&&(this.toolRenderer.toolRenderedElement=t.newToolRoot),t.shouldFireUpdate&&(this.inputManager.dropCache(),this.inputManager.updateCurrentInput(),this.toggleInputsEmptyMark(),this.call(C.UPDATED),this.emit(`didMutated`,this))};let h=e===``?t.Hr():e;if(this.name=r.name,this.id=h,this.parentId=o==null?null:o,this.contentIds=s==null?[]:s,this.lastEditedAt=f==null?Date.now():f,this.lastEditedBy=p==null?null:p,this.settings=r.settings,this.config=this.settings,this.blokEventBus=m||null,this.blockAPI=new c(this),this.readOnly=i,this.tool=r,this.toolInstance=r.create(n,this.blockAPI,i),this.tunes=r.tunes,this.tunesManager=new te(this.tunes,a,this.blockAPI),this.toolRenderer=new ee(this.toolInstance,this.name,this.id,this.tunesManager,this.config),this.holder=this.toolRenderer.compose(),this.ready=this.toolRenderer.ready,this.styleManager=new S(this.holder,this.toolRenderer.contentElement),this.selectionManager=new b(this.holder,()=>this.toolRenderer.contentElement,()=>this.styleManager.stretched,this.blokEventBus,this.styleManager),this.inputManager=new u(this.holder,()=>this.didMutated()),this.mutationHandler=new y(()=>this.toolRenderer.toolRenderedElement,this.blokEventBus,e=>this.didMutated(e)),this.dataPersistenceManager=new l(this.toolInstance,()=>this.toolRenderer.toolRenderedElement,this.tunesManager,this.name,()=>this.isEmpty,this.inputManager,()=>this.call(C.UPDATED),()=>this.toggleInputsEmptyMark(),n,a),!i){let e=()=>{this.mutationHandler.watch(),this.inputManager.addInputEvents(),this.toggleInputsEmptyMark()};d?e():window.requestIdleCallback(e)}}setupDraggable(e,t){this.cleanupDraggable(),this.draggableCleanup=t.setupDragHandle(e,this)}cleanupDraggable(){this.draggableCleanup&&(this.draggableCleanup(),this.draggableCleanup=null)}call(e,n){let r=this.toolInstance[e];if(t.ii(r))try{r.call(this.toolInstance,n)}catch(n){t.li(`Error during '${e}' call: ${n instanceof Error?n.message:String(n)}`,`error`)}}async mergeWith(e){var n=this;if(!t.ii(n.toolInstance.merge))throw Error(`Block tool "${n.name}" does not support merging`);await n.toolInstance.merge(e)}getContentOffset(e){if(typeof this.toolInstance.getContentOffset==`function`)return this.toolInstance.getContentOffset(e)}getToolbarAnchorElement(){if(typeof this.toolInstance.getToolbarAnchorElement==`function`)return this.toolInstance.getToolbarAnchorElement()}async save(){var e=this;let t=await e.dataPersistenceManager.save();if(t!==void 0)return t.id=e.id,t}async validate(e){return this.dataPersistenceManager.validate(e)}getTunes(){let e=typeof this.toolInstance.renderSettings==`function`?this.toolInstance.renderSettings():[];return this.tunesManager.getMenuConfig(e)}updateCurrentInput(){this.inputManager.updateCurrentInput()}dispatchChange(){this.didMutated()}async setData(e){return this.dataPersistenceManager.setData(e)}addDestroyCallback(e){return this.destroyCallbacks.add(e),()=>{this.destroyCallbacks.delete(e)}}destroy(){let e=Array.from(this.destroyCallbacks);this.destroyCallbacks.clear(),e.forEach(e=>e()),this.mutationHandler.destroy(),this.inputManager.destroy(),this.draggableCleanup&&(this.draggableCleanup(),this.draggableCleanup=null),super.destroy(),t.ii(this.toolInstance.destroy)&&this.toolInstance.destroy()}setReadOnly(e){this.readOnly!==e&&(this.readOnly=e,e?(this.inputManager.removeInputEvents(),this.mutationHandler.unwatch()):(this.inputManager.addInputEvents(),this.mutationHandler.watch()),typeof this.toolInstance.setReadOnly==`function`&&this.toolInstance.setReadOnly(e))}async getActiveToolboxEntry(){var e=this;let n=e.tool.toolbox;if(!n)return;if(n.length===1)return Promise.resolve(n[0]);let r=await e.data;return n.find(e=>e.data!==void 0&&t.Er(e.data,r))}async exportDataAsString(){var e=this,t;return e.dataPersistenceManager.exportDataAsString((t=e.tool.conversionConfig)==null?{}:t)}get inputs(){return this.inputManager.inputs}get currentInput(){return this.inputManager.currentInput}get currentInputIndex(){return this.inputManager.currentInputIndex}set currentInput(e){this.inputManager.currentInput=e}get firstInput(){return this.inputManager.firstInput}get lastInput(){return this.inputManager.lastInput}get nextInput(){return this.inputManager.nextInput}get previousInput(){return this.inputManager.previousInput}get data(){return this.dataPersistenceManager.data}get preservedData(){return this.dataPersistenceManager.preservedData}get preservedTunes(){return this.dataPersistenceManager.preservedTunes}get sanitize(){return this.tool.sanitizeConfig}get mergeable(){return t.ii(this.toolInstance.merge)}get focusable(){return this.inputs.length!==0}get isEmpty(){let e=t.Fr.isEmpty(this.pluginsContent,`/`),n=!this.hasMedia;return e&&n}get hasMedia(){return!!this.holder.querySelector([`img`,`iframe`,`video`,`audio`,`source`,`input`,`textarea`,`twitterwidget`].join(`,`))}set selected(e){this.selectionManager.selected=e}get selected(){return this.selectionManager.selected}setStretchState(e){this.styleManager.setStretchState(e,this.selected)}set stretched(e){this.setStretchState(e)}get stretched(){return this.styleManager.stretched}get pluginsContent(){return this.toolRenderer.pluginsContent}unwatchBlockMutations(){this.mutationHandler.unwatch()}refreshToolRootElement(){this.toolRenderer.refreshToolRootElement(this.holder),this.inputManager.dropCache()}toggleInputsEmptyMark(){this.inputs.forEach(t.Lr)}};function re(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function ie(e,t){if(e==null)return{};var n,r,i=re(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var ae=[`file`,`withBorder`,`withBackground`,`stretched`],oe=[`parent`,`content`],se={general:null,note:`blue`,important:`purple`,warning:`orange`,additional:`yellow`,recommendation:`green`,caution:`red`},ce={blue:`note`,purple:`important`,orange:`warning`,yellow:`additional`,green:`recommendation`,red:`caution`},le=`💡`,ue=e=>typeof e==`object`&&`text`in e&&!(`content`in e),de=e=>typeof e==`string`?{content:e}:ue(e)?{content:e.text,checked:e.checked}:e,fe=e=>e.some(e=>{let t=de(e);return t.items!==void 0&&t.items.length>0}),pe=e=>typeof e==`object`&&!!e&&`text`in e&&typeof e.text==`string`,me=e=>typeof e==`object`&&!!e&&`checked`in e&&typeof e.checked==`boolean`,he=e=>typeof e==`object`&&!!e&&`style`in e&&typeof e.style==`string`,ge=e=>typeof e==`object`&&!!e&&`start`in e&&typeof e.start==`number`,_e=e=>typeof e==`object`&&!!e&&`items`in e,ve=e=>typeof e==`object`&&!!e&&`style`in e&&`items`in e&&Array.isArray(e.items),ye=e=>e.type===`list`&&ve(e.data),be=e=>{if(e.type!==`toggleList`)return!1;let t=e.data;return typeof t==`object`&&!!t&&`title`in t},xe=e=>{if(e.type!==`callout`)return!1;let t=e.data;return typeof t==`object`&&!!t&&`body`in t},Se=e=>{if(e.type!==`image`)return!1;let t=e.data;if(typeof t!=`object`||!t)return!1;let n=t.file;return typeof n!=`object`||!n?!1:typeof n.url==`string`},Ce=e=>{if(!ye(e))return!1;let t=e.data.items;return fe(t)},we=e=>e.parent!==void 0||e.content!==void 0&&e.content.length>0,Te=e=>{let t=e.some(we),n=e.some(ye),r=e.some(be),i=e.some(xe),a=e.some(Se),o=n||r||i||a;return t&&!o?{format:`hierarchical`,hasHierarchy:!0}:o?{format:`legacy`,hasHierarchy:t||e.some(Ce)||e.some(e=>{var t;return be(e)&&((t=e.data.body)==null?void 0:t.blocks)!==void 0&&e.data.body.blocks.length>0})||e.some(e=>{var t;return xe(e)&&((t=e.data.body)==null?void 0:t.blocks)!==void 0&&e.data.body.blocks.length>0})}:{format:`flat`,hasHierarchy:!1}},Ee=(e,r,i,a,o,s,c)=>{let l=[];return e.forEach((e,u)=>{let d=de(e),f=t.Hr();l.push(f);let p=a===`ordered`&&i===0&&u===0&&o!==void 0&&o!==1,m=d.items&&d.items.length>0,h=n.t(n.t({id:f,type:`list`,data:n.t(n.t({text:d.content,checked:d.checked,style:a},i>0?{depth:i}:{}),p?{start:o}:{})},s===void 0?{}:{tunes:s}),r===void 0?{}:{parent:r});if(c.push(h),!m||!d.items)return;let g=Ee(d.items,f,i+1,a,void 0,s,c);g.length>0&&(h.content=g)}),l},De=(e,t)=>{let n=[],r=e.style,i=e.start;return Ee(e.items,void 0,0,r,i,t,n),n},Oe=(e,r,i,a)=>{var o;if(e.parent!==void 0){a.push(e);return}let s=(o=e.id)==null?t.Hr():o;i.push(s),a.push(n.t(n.t({},e),{},{id:s,parent:r}))},ke=(e,t)=>{let n=[],r=[];for(let i of e){let e=Ne([i]);for(let i of e)Oe(i,t,n,r)}for(let e of r){let r=e.parent!==void 0,a=e.id!==void 0&&n.includes(e.id);if(!r&&!a){var i;throw Error(`expandLegacyBodyBlocks: orphaned block emitted (type=${e.type}, id=${(i=e.id)==null?`<none>`:i}). Every root-level expansion must be re-parented to ${t}.`)}}return{childIds:n,childBlocks:r}},Ae=e=>{var r,i,a;let o=[],s=(r=e.id)==null?t.Hr():r,{childIds:c,childBlocks:l}=ke((i=(a=e.data.body)==null?void 0:a.blocks)==null?[]:i,s),u=n.t(n.t({id:s},e.tunes===void 0?{}:{tunes:e.tunes}),c.length>0?{content:c}:{}),d=typeof e.data.isExpanded==`boolean`?{isOpen:e.data.isExpanded}:{};return typeof e.data.titleVariant==`number`?o.push(n.t(n.t({},u),{},{type:`header`,data:n.t({text:e.data.title,level:e.data.titleVariant,isToggleable:!0},d)})):o.push(n.t(n.t({},u),{},{type:`toggle`,data:n.t({text:e.data.title},d)})),o.push(...l),o},je=e=>{var r,i,a,o,s;let c=[],l=(r=e.id)==null?t.Hr():r,{childIds:u,childBlocks:d}=ke((i=(a=e.data.body)==null?void 0:a.blocks)==null?[]:i,l),f=(o=e.data.variant)==null?`general`:o,p=f in se?se[f]:null,m=e.data.isEmojiVisible===!1?``:(s=e.data.emoji)==null?le:s;return c.push(n.t(n.t({id:l,type:`callout`,data:{emoji:m,textColor:null,backgroundColor:p}},e.tunes===void 0?{}:{tunes:e.tunes}),u.length>0?{content:u}:{})),c.push(...d),c},Me=e=>{var r,i;let a=(r=e.data)==null?{}:r,{file:o,withBorder:s,withBackground:c,stretched:l}=a,u=ie(a,ae),d=typeof o==`object`&&o?o.url:void 0,f=typeof d==`string`?d:``;return n.t(n.t({},e),{},{id:(i=e.id)==null?t.Hr():i,data:n.t(n.t(n.t({url:f},u),s===!0?{frame:`border`}:{}),l===!0?{size:`full`}:{})})},Ne=e=>{let r=[];for(let a of e)if(ye(a)){let e=De(a.data,a.tunes);r.push(...e)}else if(be(a)){let e=Ae(a);r.push(...e)}else if(xe(a)){let e=je(a);r.push(...e)}else if(Se(a))r.push(Me(a));else{var i;r.push(n.t(n.t({},a),{},{id:(i=a.id)==null?t.Hr():i}))}return r},Pe=(e,t)=>{e&&t.add(e)},Fe=e=>{let{parent:t,content:n}=e;return ie(e,oe)},Ie=(e,t,n)=>{let r=[];for(let i of e){let e=t.get(i);if(e&&e.type===`list`){let i=Le(e,t,n);r.push(...i)}}return r},Le=(e,t,n)=>{let r=[];e.id&&n.add(e.id);let i=e.data,a={content:pe(i)?i.text:``,checked:me(i)?i.checked:void 0},o=e.content;return o!==void 0&&o.length>0&&(a.items=Ie(o,t,n)),a.items!==void 0&&a.items.length===0&&delete a.items,r.push(a),r},Re=(e,t,r)=>{let i=Le(e,t,r),a=e.data,o=he(a)?a.style:`unordered`,s=ge(a)?a.start:void 0;return n.t({id:e.id,type:`list`,data:n.t({style:o,items:i},o===`ordered`&&s!==void 0&&s!==1?{start:s}:{})},e.tunes===void 0?{}:{tunes:e.tunes})};function ze(e,t,n){let r=[];for(let i of e){if(n.has(i))continue;let e=t.get(i);if(e!==void 0){if(We(e)){r.push(Re(e,t,n));continue}if(Ve(e)){r.push(Be(e,t,n));continue}if(He(e)){r.push(Ue(e,t,n));continue}if(Ge(e)){r.push(Ke(e,t,n));continue}Pe(e.id,n),r.push(Fe(e))}}return r}var Be=(e,t,r)=>{var i;Pe(e.id,r);let a=e.data,o=pe(a)?a.text:``,s=typeof(a==null?void 0:a.isOpen)==`boolean`?a.isOpen:void 0,c=ze((i=e.content)==null?[]:i,t,r);return n.t({id:e.id,type:`toggleList`,data:n.t(n.t({title:o},s===void 0?{}:{isExpanded:s}),c.length>0?{body:{blocks:c}}:{})},e.tunes===void 0?{}:{tunes:e.tunes})},Ve=e=>e.type===`toggle`,He=e=>{if(e.type!==`header`)return!1;let t=e.data;return typeof t==`object`&&!!t&&t.isToggleable===!0},Ue=(e,t,r)=>{var i;Pe(e.id,r);let a=e.data,o=pe(a)?a.text:``,s=typeof(a==null?void 0:a.level)==`number`?a.level:void 0,c=typeof(a==null?void 0:a.isOpen)==`boolean`?a.isOpen:void 0,l=ze((i=e.content)==null?[]:i,t,r);return n.t({id:e.id,type:`toggleList`,data:n.t(n.t(n.t({title:o},s===void 0?{}:{titleVariant:s}),c===void 0?{}:{isExpanded:c}),l.length>0?{body:{blocks:l}}:{})},e.tunes===void 0?{}:{tunes:e.tunes})},We=e=>{if(e.type!==`list`)return!1;let t=e.data,n=pe(t),r=_e(t);return n&&!r},Ge=e=>{if(e.type!==`callout`)return!1;let t=e.data;return typeof t==`object`&&!!t&&!(`body`in t)},Ke=(e,t,r)=>{var i,a;Pe(e.id,r);let o=e.data,s=o.backgroundColor,c=s==null||(i=ce[s])==null?`general`:i,l=o.emoji,u=typeof l==`string`&&l.length>0,d=u?l:null,f=ze((a=e.content)==null?[]:a,t,r);return n.t({id:e.id,type:`callout`,data:n.t({title:``,variant:c,emoji:d,isEmojiVisible:u},f.length>0?{body:{blocks:f}}:{})},e.tunes===void 0?{}:{tunes:e.tunes})},qe=(e,t,n)=>{if(!e.id||!e.parent||!t.has(e.parent))return;let r=n.get(e.parent);if(r===void 0){n.set(e.parent,[e.id]);return}r.push(e.id)},Je=(e,t,n)=>{let r=(Array.isArray(e)?e:[]).filter(e=>n.has(e));for(let e of t)r.includes(e)||r.push(e);return r},Ye=e=>{let t=e.map(e=>n.t({},e)),r=new Map;for(let e of t)e.id&&r.set(e.id,e);let i=new Map;for(let e of t)qe(e,r,i);for(let[e,t]of i){let n=r.get(e);n!==void 0&&(n.content=Je(n.content,t,r))}let a=new Map;for(let e of t)e.id&&a.set(e.id,e);let o=t.some(We),s=t.some(Ve),c=t.some(e=>He(e)&&!e.parent),l=t.some(Ge);if(!o&&!s&&!c&&!l)return t.map(Fe);let u=[],d=new Set;for(let e of t){if(e.id&&d.has(e.id))continue;let t=We(e),n=t&&!e.parent,r=Ve(e),i=r&&!e.parent,o=He(e),s=o&&!e.parent,c=Ge(e),l=c&&!e.parent,f=!t&&!r&&!o&&!c;if(n){let t=Re(e,a,d);u.push(t)}if(i){let t=Be(e,a,d);u.push(t)}if(s){let t=Ue(e,a,d);u.push(t)}if(l){let t=Ke(e,a,d);u.push(t)}f&&(u.push(Fe(e)),Pe(e.id,d))}return u},Xe=e=>typeof e==`object`&&!!e&&Array.isArray(e.blocks),Ze=e=>{if(typeof e!=`object`||!e)return null;let t=e.content;return Array.isArray(t)?t:null},Qe=(e,t,n)=>{if(Xe(e))for(let r of e.blocks)typeof r!=`string`||n.has(r)||n.set(r,t)},$e=(e,t,n)=>{Array.isArray(e)&&e.forEach(e=>Qe(e,t,n))},et=(e,t)=>{if(e.id===void 0||e.id===null)return;let n=Ze(e.data);if(n===null)return;let r=e.id;n.forEach(e=>$e(e,r,t))},tt=e=>{let t=new Map;return e.filter(e=>e.type===`table`).forEach(e=>et(e,t)),t.size===0?e:e.map(e=>{if(e.id===void 0||e.id===null)return e;let r=t.get(e.id);return r===void 0||e.parent!==void 0&&e.parent!==null?e:n.t(n.t({},e),{},{parent:r})})},nt=/^cell-([1-9]\d*)-([1-9]\d*)$/,rt=e=>{if(typeof e!=`string`)return null;let t=nt.exec(e);if(t===null)return null;let n=Number(t[1])-1,r=Number(t[2])-1;return n<0||r<0?null:{row:n,col:r}},it=(e,t,n)=>{let r=Ze(e.data);if(r===null)return!1;let i=r[t];if(!Array.isArray(i))return!1;let a=i[n];return Xe(a)&&a.blocks.length===0},at=e=>{let t=new Set;return e.filter(e=>e.type===`table`).forEach(e=>{let n=Ze(e.data);n==null||n.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{Xe(e)&&e.blocks.forEach(e=>{typeof e==`string`&&t.add(e)})})})}),t},ot=e=>{let t=e.filter(e=>e.type===`table`&&e.id!==void 0&&e.id!==null);if(t.length!==1)return e;let r=at(e),i=new Map;for(let t of e)if(t.id!==void 0&&t.id!==null){var a;i.set(t.id,((a=i.get(t.id))==null?0:a)+1)}let o=new Map,s=new Map;for(let a of e){var c,l;if(a.id===void 0||a.id===null||a.parent!==void 0&&a.parent!==null||r.has(a.id)||((c=i.get(a.id))==null?0:c)>1)continue;let e=rt(a.id);if(e===null)continue;let u=t.filter(t=>it(t,e.row,e.col));if(u.length!==1)continue;let d=u[0].id;o.set(a.id,d);let f=(l=s.get(d))==null?[]:l;f.push(n.t(n.t({},e),{},{id:a.id})),s.set(d,f)}return o.size===0?e:e.map(e=>{if(e.id!==void 0&&e.id!==null&&o.has(e.id))return n.t(n.t({},e),{},{parent:o.get(e.id)});if(e.type===`table`&&e.id!==void 0&&e.id!==null&&s.has(e.id)){var t;let r=(t=s.get(e.id))==null?[]:t,i=Ze(e.data);if(i===null)return e;let a=i.map((e,t)=>Array.isArray(e)?e.map((e,i)=>{let a=r.find(e=>e.row===t&&e.col===i);return a===void 0||!Xe(e)?e:n.t(n.t({},e),{},{blocks:[...e.blocks,a.id]})}):e);return n.t(n.t({},e),{},{data:n.t(n.t({},e.data),{},{content:a})})}return e})},st=(e,t)=>t===`legacy`?e!==`legacy`:!1,ct=(e,t)=>e===`legacy`||e===`auto`&&t===`legacy`,lt=`blok-block--target`,ut=1800;function dt(e){e.classList.remove(lt),e.offsetWidth,e.classList.add(lt);let t={removed:!1},n=()=>{t.removed||(t.removed=!0,e.classList.remove(lt),e.removeEventListener(`animationend`,r))},r=t=>{t.target===e&&n()};e.addEventListener(`animationend`,r),window.setTimeout(n,ut)}var ft=class extends s{constructor(...e){var n;super(...e),n=this,this.insert=(e,n={},r={},i,a,o,s)=>{let l=e==null?this.config.defaultBlock:e,u=(()=>{if(!l)return l;let e=i==null?this.Blok.BlockManager.currentBlockIndex:i,n=this.Blok.BlockManager.getBlockByIndex(e);return n!==void 0&&t.Mr(n)&&t.Nr(l)?`paragraph`:l})();return new c(this.Blok.BlockManager.insert({id:s,tool:u,data:n,index:i,needToFocus:a,replace:o}))},this.composeBlockData=async e=>{let t=n.Blok.Tools.blockTools.get(e);if(t===void 0)throw Error(`Block Tool with type "${e}" not found`);return new ne({tool:t,api:n.Blok.API,readOnly:!0,data:{},tunesData:{}}).data},this.update=async(e,t,r)=>{let{BlockManager:i}=n.Blok,a=i.getBlockById(e);if(a===void 0)throw Error(`Block with id "${e}" not found`);return new c(await i.update(a,t,r))},this.convert=async(e,r,i)=>{var a,o;let{BlockManager:s,Tools:l}=n.Blok,u=s.getBlockById(e);if(!u)throw Error(`Block with id "${e}" not found`);let d=l.blockTools.get(u.name),f=l.blockTools.get(r);if(!f)throw Error(`Block Tool with type "${r}" not found`);let p=(d==null||(a=d.conversionConfig)==null?void 0:a.export)!==void 0,m=((o=f.conversionConfig)==null?void 0:o.import)!==void 0;if(p&&m)return new c(await s.convert(u,r,i));{let e=[p?!1:t.qr(u.name),m?!1:t.qr(r)].filter(Boolean).join(` and `);throw Error(`Conversion from "${u.name}" to "${r}" is not possible. ${e} tool(s) should provide a "conversionConfig"`)}},this.insertMany=(e,t=this.Blok.BlockManager.blocks.length-1)=>{this.validateIndex(t);let n=tt(e).map(({id:e,type:t,data:n,tunes:r,parent:i,content:a,lastEditedAt:o,lastEditedBy:s})=>this.Blok.BlockManager.composeBlock({id:e,tool:t||this.config.defaultBlock,data:n,tunes:r,parentId:i,contentIds:a,lastEditedAt:o,lastEditedBy:s}));return this.Blok.BlockManager.insertMany(n,t),n.map(e=>new c(e))},this.insertInsideParent=(e,t,n)=>(this.Blok.BlockManager.suppressStopCapturing||this.Blok.YjsManager.stopCapturing(),new c(this.Blok.BlockManager.insertInsideParent(e,t,n))),this.splitBlock=(e,t,n,r,i)=>{this.Blok.YjsManager.stopCapturing();let a=this.Blok.BlockManager.splitBlockWithData(e,t,n,r,i);return queueMicrotask(()=>{this.Blok.YjsManager.stopCapturing()}),new c(a)}}get methods(){let e=this;return{get isSyncingFromYjs(){return e.Blok.BlockManager.isSyncingFromYjs},clear:()=>this.clear(),render:e=>this.render(e),renderFromHTML:e=>this.renderFromHTML(e),delete:e=>this.delete(e),move:(e,t)=>this.move(e,t),getBlockByIndex:e=>this.getBlockByIndex(e),getById:e=>this.getById(e),getCurrentBlockIndex:()=>this.getCurrentBlockIndex(),getBlockIndex:e=>this.getBlockIndex(e),getBlocksCount:()=>this.getBlocksCount(),getBlockByElement:e=>this.getBlockByElement(e),getChildren:e=>this.getChildren(e),insert:this.insert,insertMany:this.insertMany,update:this.update,composeBlockData:this.composeBlockData,convert:this.convert,setBlockParent:(e,t)=>this.setBlockParent(e,t),stopBlockMutationWatching:e=>this.stopBlockMutationWatching(e),splitBlock:this.splitBlock,insertInsideParent:this.insertInsideParent,transact:e=>this.transact(e),transactWithoutCapture:e=>this.transactWithoutCapture(e),setPointerDragActive:e=>this.setPointerDragActive(e)}}getBlocksCount(){return this.Blok.BlockManager.blocks.length}getCurrentBlockIndex(){return this.Blok.BlockManager.currentBlockIndex}getBlockIndex(e){let n=this.Blok.BlockManager.getBlockById(e);if(!n){t.ui("There is no block with id `"+e+"`",`warn`);return}return this.Blok.BlockManager.getBlockIndex(n)}getBlockByIndex(e){let n=this.Blok.BlockManager.getBlockByIndex(e);if(n===void 0){t.ui("There is no block at index `"+e+"`",`warn`);return}return new c(n)}getById(e){let n=this.Blok.BlockManager.getBlockById(e);return n===void 0?(t.ui("There is no block with id `"+e+"`",`warn`),null):new c(n)}getBlockByElement(e){let n=this.Blok.BlockManager.getBlock(e);if(n===void 0){var r,i;t.ui(`There is no block corresponding to element <${(r=(i=e.tagName)==null?void 0:i.toLowerCase())==null?`unknown`:r}>`,`warn`);return}return new c(n)}getChildren(e){return this.Blok.BlockManager.blocks.filter(t=>t.parentId===e).map(e=>new c(e))}move(e,t){this.Blok.BlockManager.move(e,t)}async delete(e=this.Blok.BlockManager.currentBlockIndex){var n=this;let r=n.Blok.BlockManager.getBlockByIndex(e);if(r===void 0){t.ui(`There is no block at index \`${e}\``,`warn`);return}try{await n.Blok.BlockManager.removeBlock(r)}catch(e){t.ui(e,`warn`);return}n.Blok.BlockManager.currentBlock&&n.Blok.Caret.setToBlock(n.Blok.BlockManager.currentBlock,n.Blok.Caret.positions.END),n.Blok.Toolbar.close()}async clear(){var e=this;await e.Blok.BlockManager.clear(!0),e.Blok.InlineToolbar.close()}async render(e){var t=this;if(e===void 0||e.blocks===void 0)throw Error(`Incorrect data passed to the render() method`);t.Blok.ModificationsObserver.disable(),t.Blok.Renderer.markRenderStart();try{await t.Blok.BlockManager.clear(),await t.Blok.Renderer.render(e.blocks)}finally{t.Blok.Renderer.markRenderEnd()}t.Blok.ModificationsObserver.enable(),t.processPendingHashScroll()}async renderFromHTML(e){var t=this;t.Blok.Renderer.markRenderStart();try{return await t.Blok.BlockManager.clear(),t.Blok.Paste.processText(e,!0)}finally{t.Blok.Renderer.markRenderEnd()}}async importMarkdown(e,t){var n=this;let{markdownToBlocks:r}=await Promise.resolve().then(()=>require(`../markdown.cjs`)),i={blocks:await r(e,t)};return await n.render(i),i}setBlockParent(e,n){let r=this.Blok.BlockManager.getBlockById(e);if(r===void 0){t.ui("There is no block with id `"+e+"`",`warn`);return}this.Blok.BlockManager.setBlockParent(r,n)}stopBlockMutationWatching(e){let t=this.Blok.BlockManager.getBlockByIndex(e);t!==void 0&&t.unwatchBlockMutations()}transact(e){this.Blok.BlockManager.transactForTool(e)}transactWithoutCapture(e){this.Blok.YjsManager.transactWithoutCapture(e)}setPointerDragActive(e){this.Blok.BlockManager.setPointerDragActive(e)}validateIndex(e){if(typeof e!=`number`)throw Error(`Index should be a number`);if(e<0)throw Error(`Index should be greater than or equal to 0`)}processPendingHashScroll(){var e,t;let n=this.Blok.Renderer.pendingHashScroll;if(n===null)return;this.Blok.Renderer.pendingHashScroll=null;let r=document.querySelector(`[data-blok-id="${CSS.escape(n)}"]`);if(r===null)return;let i=(e=(t=this.config.scrollToBlock)==null?void 0:t.topOffset)==null?0:e,a=r.getBoundingClientRect().top+window.scrollY-i;window.scrollTo({top:a,behavior:`smooth`});let o=this.Blok.BlockManager.getBlockById(n);o!==void 0&&this.Blok.BlockSelection.selectBlock(o),dt(r)}},pt=(e,t)=>typeof e==`number`?t.BlockManager.getBlockByIndex(e):typeof e==`string`?t.BlockManager.getBlockById(e):t.BlockManager.getBlockById(e.id),mt=class extends s{constructor(...e){super(...e),this.setToFirstBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.firstBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.firstBlock,e,t),!0):!1,this.setToLastBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.lastBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.lastBlock,e,t),!0):!1,this.setToPreviousBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.previousBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.previousBlock,e,t),!0):!1,this.setToNextBlock=(e=this.Blok.Caret.positions.DEFAULT,t=0)=>this.Blok.BlockManager.nextBlock?(this.Blok.Caret.setToBlock(this.Blok.BlockManager.nextBlock,e,t),!0):!1,this.setToBlock=(e,t=this.Blok.Caret.positions.DEFAULT,n=0)=>{let r=pt(e,this.Blok);return r===void 0?!1:(this.Blok.Caret.setToBlock(r,t,n),!0)},this.focus=(e=!1)=>e?this.setToLastBlock(this.Blok.Caret.positions.END):this.setToFirstBlock(this.Blok.Caret.positions.START),this.updateLastCaretAfterPosition=()=>{this.Blok.YjsManager.updateLastCaretAfterPosition()}}get methods(){return{setToFirstBlock:this.setToFirstBlock,setToLastBlock:this.setToLastBlock,setToPreviousBlock:this.setToPreviousBlock,setToNextBlock:this.setToNextBlock,setToBlock:this.setToBlock,focus:this.focus,updateLastCaretAfterPosition:this.updateLastCaretAfterPosition}}},ht=class extends s{get methods(){return{emit:(e,t)=>this.emit(e,t),off:(e,t)=>this.off(e,t),on:(e,t)=>this.on(e,t)}}on(e,t){this.eventsDispatcher.on(e,t)}emit(e,t){this.eventsDispatcher.emit(e,t)}off(e,t){this.eventsDispatcher.off(e,t)}},gt=class extends s{get methods(){return{undo:()=>this.undo(),redo:()=>this.redo(),canUndo:()=>this.canUndo(),canRedo:()=>this.canRedo(),clear:()=>this.clear()}}undo(){this.Blok.YjsManager.undo()}redo(){this.Blok.YjsManager.redo()}canUndo(){return this.Blok.YjsManager.canUndo()}canRedo(){return this.Blok.YjsManager.canRedo()}clear(){this.Blok.YjsManager.clear()}},_t=class extends s{constructor(...e){super(...e),this.cachedMethods=null}get methods(){return this.cachedMethods===null&&(this.cachedMethods={t:e=>this.Blok.I18n.t(e),has:e=>this.Blok.I18n.has(e),getEnglishTranslation:e=>this.Blok.I18n.getEnglishTranslation(e),getLocale:()=>this.Blok.I18n.getLocale()}),this.cachedMethods}},vt=class extends s{get methods(){return{blocks:this.Blok.BlocksAPI.methods,caret:this.Blok.CaretAPI.methods,tools:this.Blok.ToolsAPI.methods,events:this.Blok.EventsAPI.methods,history:this.Blok.HistoryAPI.methods,listeners:this.Blok.ListenersAPI.methods,notifier:this.Blok.NotifierAPI.methods,sanitizer:this.Blok.SanitizerAPI.methods,saver:this.Blok.SaverAPI.methods,selection:this.Blok.SelectionAPI.methods,styles:this.Blok.StylesAPI.classes,toolbar:this.Blok.ToolbarAPI.methods,inlineToolbar:this.Blok.InlineToolbarAPI.methods,tooltip:this.Blok.TooltipAPI.methods,i18n:this.Blok.I18nAPI.methods,readOnly:this.Blok.ReadOnlyAPI.methods,ui:this.Blok.UiAPI.methods,theme:this.Blok.ThemeAPI.methods,rectangleSelection:this.Blok.RectangleSelection}}},yt=class extends s{get methods(){return{close:()=>this.close(),open:()=>this.open()}}open(){this.Blok.InlineToolbar.tryToShow()}close(){this.Blok.InlineToolbar.close()}},bt=class extends s{get methods(){return{on:(e,t,n,r)=>this.on(e,t,n,r),off:(e,t,n,r)=>this.off(e,t,n,r),offById:e=>this.offById(e)}}on(e,t,n,r){return this.listeners.on(e,t,n,r)}off(e,t,n,r){this.listeners.off(e,t,n,r)}offById(e){this.listeners.offById(e)}},xt=class{constructor(e=i.t){this.notifierModule=null,this.loadingPromise=null,this.position=e}loadNotifierModule(){return this.notifierModule===null?(this.loadingPromise===null&&(this.loadingPromise=Promise.resolve().then(()=>require(`./notifier-r5L-xyuz.cjs`)).then(e=>{let t=e;if(!this.isNotifierModule(t))throw Error(`notifier module does not expose a "show" method.`);return this.notifierModule=t,t}).catch(e=>{throw this.loadingPromise=null,e})),this.loadingPromise):Promise.resolve(this.notifierModule)}show(e){this.loadNotifierModule().then(t=>{t.show(e,this.position)}).catch(e=>{console.error(`[Blok] Failed to display notification. Reason:`,e)})}isNotifierModule(e){return typeof e==`object`&&!!e&&`show`in e&&typeof e.show==`function`}},St=class extends s{constructor({config:e,eventsDispatcher:t}){var n;super({config:e,eventsDispatcher:t}),this.builtInNotifier=new xt((n=e.notifierPosition)==null?i.t:n),this.customNotifier=e.notifier}get methods(){return{show:e=>this.show(e)}}show(e){if(this.customNotifier!==void 0){this.customNotifier(e);return}this.builtInNotifier.show(e)}},Ct=class extends s{get methods(){let e=()=>this.isEnabled;return{toggle:e=>this.toggle(e),set:e=>this.set(e),get isEnabled(){return e()}}}toggle(e){return this.Blok.ReadOnly.toggle(e)}set(e){return this.Blok.ReadOnly.set(e)}get isEnabled(){return this.Blok.ReadOnly.isEnabled}},wt=class extends s{get methods(){return{clean:(e,t)=>this.clean(e,t)}}clean(e,n){return t.ur(e,n)}},Tt=class extends s{get methods(){return{save:()=>this.save()}}async save(){var e=this,n,r;let i=`Blok's content can not be saved in read-only mode`;if(e.Blok.ReadOnly.isEnabled)throw t.ui(i,`warn`),Error(i);let a=await e.Blok.Saver.save();if(a!==void 0)return a;let o=(n=(r=e.Blok.Saver).getLastSaveError)==null?void 0:n.call(r);throw o instanceof Error?o:Error(o===void 0?`Blok's content can not be saved because collecting data failed`:String(o))}},Et=class extends s{constructor(...e){super(...e),this.selectionUtils=new t.mr}get methods(){return{findParentTag:(e,t)=>this.findParentTag(e,t),expandToTag:e=>this.expandToTag(e),save:()=>this.selectionUtils.save(),restore:()=>this.selectionUtils.restore(),setFakeBackground:()=>this.selectionUtils.setFakeBackground(),removeFakeBackground:()=>this.selectionUtils.removeFakeBackground(),clearFakeBackground:()=>this.selectionUtils.clearFakeBackground()}}findParentTag(e,t){return this.selectionUtils.findParentTag(e,t)}expandToTag(e){this.selectionUtils.expandToTag(e)}},Dt=class extends s{get classes(){return{block:`blok-block`,inlineToolButton:`blok-inline-tool-button`,inlineToolButtonActive:`blok-inline-tool-button--active`,input:`blok-input`,loader:`blok-loader`,button:`blok-button`,settingsButton:`blok-settings-button`,settingsButtonActive:`blok-settings-button--active`,settingsButtonFocused:`blok-settings-button--focused`,settingsButtonFocusedAnimated:`blok-settings-button--focused-animated`}}},Ot=class extends s{get methods(){return{close:e=>this.close(e),open:()=>this.open(),toggleBlockSettings:(e,t,n)=>this.toggleBlockSettings(e,t,n),toggleToolbox:e=>this.toggleToolbox(e)}}open(){this.Blok.Toolbar.moveAndOpen()}close(e){this.Blok.Toolbar.close(e)}toggleBlockSettings(e,n,r){if(this.Blok.BlockManager.currentBlockIndex===-1){t.ui(`Could't toggle the Toolbar because there is no block selected `,`warn`);return}(e==null?!this.Blok.BlockSettings.opened:e)?(this.Blok.Toolbar.moveAndOpen(),this.Blok.BlockSettings.open(void 0,n,r)):this.Blok.BlockSettings.close()}toggleToolbox(e){if(this.Blok.BlockManager.currentBlockIndex===-1){t.ui(`Could't toggle the Toolbox because there is no block selected `,`warn`);return}(e==null?!this.Blok.Toolbar.toolbox.opened:e)?(this.Blok.Toolbar.moveAndOpen(),this.Blok.Toolbar.toolbox.open()):this.Blok.Toolbar.toolbox.close()}},kt=class extends s{get methods(){return{getBlockTools:()=>Array.from(this.Blok.Tools.blockTools.values()),getToolsConfig:()=>{let e={tools:this.config.tools};return this.config.inlineToolbar!==void 0&&(e.inlineToolbar=this.config.inlineToolbar),this.config.tunes!==void 0&&(e.tunes=this.config.tunes),this.config.theme!==void 0&&(e.theme=this.config.theme),e}}}},At=class extends s{constructor({config:e,eventsDispatcher:t}){super({config:e,eventsDispatcher:t})}get methods(){return{show:(e,t,n)=>this.show(e,t,n),hide:()=>this.hide(),onHover:(e,t,n)=>this.onHover(e,t,n)}}show(e,n,r){t.sr(e,n,r)}hide(){t.ar()}onHover(e,n,r){t.or(e,n,r)}},jt=class extends s{get methods(){let e=this.Blok.UI;return{nodes:this.blokNodes,get isMobile(){return e.isMobile}}}get blokNodes(){return{wrapper:this.Blok.UI.nodes.wrapper,redactor:this.Blok.UI.nodes.redactor}}},Mt=class extends s{get methods(){let e=this.Blok.ThemeManager;return{get:()=>e.getMode(),set:t=>e.setMode(t),getResolved:()=>e.getResolved()}}},w=()=>new Map,Nt=e=>{let t=w();return e.forEach((e,n)=>{t.set(n,e)}),t},Pt=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Ft=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},It=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Lt=()=>new Set,Rt=e=>e[e.length-1],zt=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Bt=Array.from,Vt=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Ht=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Ut=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},Wt=Array.isArray,Gt=class{constructor(){this._observers=w()}on(e,t){return Pt(this._observers,e,Lt).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Bt((this._observers.get(e)||w()).values()).forEach(e=>e(...t))}destroy(){this._observers=w()}},T=Math.floor,Kt=Math.abs,qt=(e,t)=>e<t?e:t,Jt=(e,t)=>e>t?e:t;Number.isNaN;var Yt=e=>e===0?1/e<0:e<0,Xt=2**53-1,Zt=-(2**53-1),Qt=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&T(e)===e);Number.isNaN,Number.parseInt;var $t=String.fromCharCode;String.fromCodePoint,$t(65535);var en=e=>e.toLowerCase(),tn=/^\s*/g,nn=e=>e.replace(tn,``),rn=/([A-Z])/g,an=(e,t)=>nn(e.replace(rn,e=>`${t}${en(e)}`)),on=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},sn=typeof TextEncoder<`u`?new TextEncoder:null,cn=sn?e=>sn.encode(e):on,ln=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});ln&&ln.decode(new Uint8Array).length===1&&(ln=null);var un=(e,t)=>Ut(t,()=>e).join(``),dn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},fn=()=>new dn,pn=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},E=e=>{let t=new Uint8Array(pn(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},mn=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Jt(n,t)*2),e.cpos=0)},D=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},hn=D,O=(e,t)=>{for(;t>127;)D(e,128|127&t),t=T(t/128);D(e,127&t)},gn=(e,t)=>{let n=Yt(t);for(n&&(t=-t),D(e,(t>63?128:0)|(n?64:0)|63&t),t=T(t/64);t>0;)D(e,(t>127?128:0)|127&t),t=T(t/128)},_n=new Uint8Array(3e4),vn=_n.length/3,yn=sn&&sn.encodeInto?(e,t)=>{if(t.length<vn){let n=sn.encodeInto(t,_n).written||0;O(e,n);for(let t=0;t<n;t++)D(e,_n[t])}else k(e,cn(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;O(e,r);for(let t=0;t<r;t++)D(e,n.codePointAt(t))},bn=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=qt(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Jt(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},k=(e,t)=>{O(e,t.byteLength),bn(e,t)},xn=(e,t)=>{mn(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Sn=(e,t)=>xn(e,4).setFloat32(0,t,!1),Cn=(e,t)=>xn(e,8).setFloat64(0,t,!1),wn=(e,t)=>xn(e,8).setBigInt64(0,t,!1),Tn=new DataView(new ArrayBuffer(4)),En=e=>(Tn.setFloat32(0,e),Tn.getFloat32(0)===e),Dn=(e,t)=>{switch(typeof t){case`string`:D(e,119),yn(e,t);break;case`number`:Qt(t)&&Kt(t)<=2147483647?(D(e,125),gn(e,t)):En(t)?(D(e,124),Sn(e,t)):(D(e,123),Cn(e,t));break;case`bigint`:D(e,122),wn(e,t);break;case`object`:if(t===null)D(e,126);else if(Wt(t)){D(e,117),O(e,t.length);for(let n=0;n<t.length;n++)Dn(e,t[n])}else if(t instanceof Uint8Array)D(e,116),k(e,t);else{D(e,118);let n=Object.keys(t);O(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];yn(e,i),Dn(e,t[i])}}break;case`boolean`:D(e,t?120:121);break;default:D(e,127)}},On=class extends dn{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&O(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},kn=e=>{e.count>0&&(gn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&O(e.encoder,e.count-2))},An=class{constructor(){this.encoder=new dn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(kn(this),this.count=1,this.s=e)}toUint8Array(){return kn(this),E(this.encoder)}},jn=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);gn(e.encoder,t),e.count>1&&O(e.encoder,e.count-2)}},Mn=class{constructor(){this.encoder=new dn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(jn(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return jn(this),E(this.encoder)}},Nn=class{constructor(){this.sarr=[],this.s=``,this.lensE=new An}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new dn;return this.sarr.push(this.s),this.s=``,yn(e,this.sarr.join(``)),bn(e,this.lensE.toUint8Array()),E(e)}},A=e=>Error(e),j=()=>{throw A(`Method unimplemented`)},M=()=>{throw A(`Unexpected case`)};crypto.subtle;var Pn=crypto.getRandomValues.bind(crypto),Fn=()=>Pn(new Uint32Array(1))[0],In=`10000000-1000-4000-8000-100000000000`,Ln=()=>In.replace(/[018]/g,e=>(e^Fn()&15>>e/4).toString(16)),Rn=Date.now,zn=e=>new Promise(e);Promise.all.bind(Promise);var Bn=e=>e===void 0?null:e,Vn=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Vn=localStorage)}catch(e){}var Hn=Vn,Un=Symbol(`Equality`),Wn=(e,t)=>{var n;return e===t||!!(!(e==null||(n=e[Un])==null)&&n.call(e,t))||!1},Gn=e=>typeof e==`object`,Kn=Object.assign,qn=Object.keys,Jn=(e,t)=>{for(let n in e)t(e[n],n)},Yn=e=>qn(e).length,Xn=e=>{for(let t in e)return!1;return!0},Zn=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Qn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),$n=(e,t)=>e===t||Yn(e)===Yn(t)&&Zn(e,(e,n)=>(e!==void 0||Qn(t,n))&&Wn(t[n],e)),er=Object.freeze,tr=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&tr(e[t])}return er(e)},nr=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&nr(e,t,n+1)}},rr=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Un]!=null)return e[Un](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!rr(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Yn(e)!==Yn(t))return!1;for(let n in e)if(!Qn(e,n)||!rr(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!rr(e[n],t[n]))return!1;break;default:return!1}return!0},ir=(e,t)=>t.includes(e),ar=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`;typeof navigator<`u`&&/Mac/.test(navigator.platform);var N,or=[],sr=()=>{if(N===void 0)if(ar){N=w();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&N.set(t,``),t=r):t===null?or.push(r):(N.set(t,r),t=null)}t!==null&&N.set(t,``)}else typeof location==`object`?(N=w(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);N.set(`--${an(t,`-`)}`,n),N.set(`-${an(t,`-`)}`,n)}})):N=w();return N},cr=e=>sr().has(e),lr=e=>Bn(ar?process.env[e.toUpperCase().replaceAll(`-`,`_`)]:Hn.getItem(e)),ur=e=>cr(`--`+e)||lr(e)!==null,dr=ur(`production`),fr=ar&&ir(process.env.FORCE_COLOR,[`true`,`1`,`2`])||!cr(`--no-colors`)&&!ur(`no-color`)&&(!ar||process.stdout.isTTY)&&(!ar||cr(`--color`)||lr(`COLORTERM`)!==null||(lr(`TERM`)||``).includes(`color`)),pr=class{constructor(e,t){this.left=e,this.right=t}},P=(e,t)=>new pr(e,t),mr=e=>e.next()>=.5,hr=(e,t,n)=>T(e.next()*(n+1-t)+t),gr=(e,t,n)=>T(e.next()*(n+1-t)+t),_r=(e,t,n)=>gr(e,t,n),vr=e=>$t(_r(e,97,122)),yr=(e,t=0,n=20)=>{let r=_r(e,t,n),i=``;for(let t=0;t<r;t++)i+=vr(e);return i},br=(e,t)=>t[_r(e,0,t.length-1)],xr,Sr=Symbol(`0schema`),Cr=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(un(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
2
2
|
`)}},wr=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Un]?Wn(e,t):Wt(e)?Vt(e,e=>Ht(t,t=>wr(e,t))):Gn(e)?Zn(e,(e,n)=>wr(e,t[n])):!1;xr=Un;var F=class{extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),wr(t,n)}equals(e){return this.constructor===e.constructor&&rr(this.shape,e.shape)}[Sr](){return!0}[xr](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){j()}get nullable(){return ti(this,gi)}get optional(){return new Nr(this)}cast(e){return bi(e,this),e}expect(e){return bi(e,this),e}};n.n(F,`_dilutes`,!1);var Tr=class extends F{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=(e==null?void 0:e.constructor)===this.shape&&(this._c==null||this._c(e));return!n&&(t==null||t.extend(null,this.shape.name,e==null?void 0:e.constructor.name,(e==null?void 0:e.constructor)===this.shape?`Check failed`:`Constructor match failed`)),n}},I=(e,t=null)=>new Tr(e,t);I(Tr);var Er=class extends F{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&(t==null||t.extend(null,`custom prop`,e==null?void 0:e.constructor.name,`failed to check custom prop`)),n}},L=e=>new Er(e);I(Er);var Dr=class extends F{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&(t==null||t.extend(null,this.shape.join(` | `),e.toString())),n}},Or=(...e)=>new Dr(e),kr=I(Dr),Ar=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),jr=e=>{if(di.check(e))return[Ar(e)];if(kr.check(e))return e.shape.map(e=>e+``);if(ui.check(e))return[`[+-]?\\d+.?\\d*`];if(fi.check(e))return[`.*`];if(ni.check(e))return e.shape.map(jr).flat(1);M()};I(class extends F{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(jr).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&(t==null||t.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`)),n}});var Mr=Symbol(`optional`),Nr=class extends F{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&(t==null||t.extend(null,`undefined (optional)`,`()`)),n}get[Mr](){return!0}},Pr=I(Nr),Fr=class extends F{check(e,t){return t==null||t.extend(null,`never`,typeof e),!1}};new Fr,I(Fr);var Ir=class e extends F{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t==null||t.extend(null,`object`,`null`),!1):Zn(this.shape,(n,r)=>{let i=this._isPartial&&!Qn(e,r)||n.check(e[r],t);return!i&&(t==null||t.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`)),i})}};n.n(Ir,`_dilutes`,!0);var Lr=e=>new Ir(e),Rr=I(Ir),zr=L(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Br=class extends F{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Zn(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&(t==null||t.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`)),i&&this.shape.values.check(n,t)})}},Vr=(e,t)=>new Br(e,t),Hr=I(Br),Ur=class extends F{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Zn(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&(t==null||t.extend(r.toString(),`Tuple`,typeof n)),i})}},Wr=(...e)=>new Ur(e);I(Ur);var Gr=class extends F{constructor(e){super(),this.shape=e.length===1?e[0]:new ei(e)}check(e,t){let n=Wt(e)&&Vt(e,e=>this.shape.check(e));return!n&&(t==null||t.extend(null,`Array`,``)),n}},Kr=(...e)=>new Gr(e),qr=I(Gr),Jr=L(e=>Wt(e)),Yr=class extends F{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&(t==null||t.extend(null,this.shape.name,e==null?void 0:e.constructor.name)),n}},Xr=(e,t=null)=>new Yr(e,t);I(Yr);var Zr=Xr(F),Qr=I(class extends F{constructor(e){super(),this.len=e.length-1,this.args=Wr(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&(t==null||t.extend(null,`function`,typeof e)),n}}),$r=L(e=>typeof e==`function`);I(class extends F{constructor(e){super(),this.shape=e}check(e,t){let n=Vt(this.shape,n=>n.check(e,t));return!n&&(t==null||t.extend(null,`Intersectinon`,typeof e)),n}},e=>e.shape.length>0);var ei=class extends F{constructor(e){super(),this.shape=e}check(e,t){let n=Ht(this.shape,n=>n.check(e,t));return t==null||t.extend(null,`Union`,typeof e),n}};n.n(ei,`_dilutes`,!0);var ti=(...e)=>e.findIndex(e=>ni.check(e))>=0?ti(...e.map(e=>yi(e)).map(e=>ni.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new ei(e),ni=I(ei),ri=()=>!0,ii=L(ri),ai=I(Er,e=>e.shape===ri),oi=L(e=>typeof e==`bigint`),si=L(e=>e===oi),ci=L(e=>typeof e==`symbol`);L(e=>e===ci);var li=L(e=>typeof e==`number`),ui=L(e=>e===li),di=L(e=>typeof e==`string`),fi=L(e=>e===di),pi=L(e=>typeof e==`boolean`),mi=L(e=>e===pi),hi=Or(void 0);I(Dr,e=>e.shape.length===1&&e.shape[0]===void 0),Or(void 0);var gi=Or(null),_i=I(Dr,e=>e.shape.length===1&&e.shape[0]===null);I(Uint8Array),I(Tr,e=>e.shape===Uint8Array);var vi=ti(li,di,gi,hi,oi,pi,ci);(()=>{let e=Kr(ii),t=Vr(di,ii),n=ti(li,di,gi,pi,e,t);return e.shape=n,t.shape.values=n,n})();var yi=e=>{if(Zr.check(e))return e;if(zr.check(e)){let t={};for(let n in e)t[n]=yi(e[n]);return Lr(t)}else if(Jr.check(e))return ti(...e.map(yi));else if(vi.check(e))return Or(e);else if($r.check(e))return I(e);M()},bi=dr?()=>{}:(e,t)=>{let n=new Cr;if(!t.check(e,n))throw A(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},xi=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:yi(e),h:t}),this}else(e){return this.if(ii,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw A(`Unhandled pattern`)}}},Si=(e=>new xi(e))(ii).if(ui,(e,t)=>hr(t,Zt,Xt)).if(fi,(e,t)=>yr(t)).if(mi,(e,t)=>mr(t)).if(si,(e,t)=>BigInt(hr(t,Zt,Xt))).if(ni,(e,t)=>Ci(t,br(t,e.shape))).if(Rr,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Pr.check(i)){if(mr(t))continue;i=i.shape}n[r]=Si(i,t)}return n}).if(qr,(e,t)=>{let n=[],r=gr(t,0,42);for(let i=0;i<r;i++)n.push(Ci(t,e.shape));return n}).if(kr,(e,t)=>br(t,e.shape)).if(_i,(e,t)=>null).if(Qr,(e,t)=>{let n=Ci(t,e.res);return()=>n}).if(ai,(e,t)=>Ci(t,br(t,[li,di,gi,hi,oi,pi,Kr(li),Vr(ti(`a`,`b`,`c`),li)]))).if(Hr,(e,t)=>{let n={},r=hr(t,0,3);for(let i=0;i<r;i++){let r=Ci(t,e.shape.keys);n[r]=Ci(t,e.shape.values)}return n}).done(),Ci=(e,t)=>Si(yi(t),e),wi=typeof document<`u`?document:{};L(e=>e.nodeType===ki),typeof DOMParser<`u`&&new DOMParser,L(e=>e.nodeType===Ei),L(e=>e.nodeType===Di);var Ti=e=>Ft(e,(e,t)=>`${t}:${e};`).join(``),Ei=wi.ELEMENT_NODE,Di=wi.TEXT_NODE;wi.CDATA_SECTION_NODE,wi.COMMENT_NODE;var Oi=wi.DOCUMENT_NODE;wi.DOCUMENT_TYPE_NODE;var ki=wi.DOCUMENT_FRAGMENT_NODE;L(e=>e.nodeType===Oi);var R=Symbol,Ai=R(),ji=R(),Mi=R(),Ni=R(),Pi=R(),Fi=R(),Ii=R(),Li=R(),Ri=R(),zi=e=>{var t;e.length===1&&((t=e[0])==null?void 0:t.constructor)===Function&&(e=e[0]());let n=[],r=[],i=0;for(;i<e.length;i++){let t=e[i];if(t===void 0)break;if(t.constructor===String||t.constructor===Number)n.push(t);else if(t.constructor===Object)break}for(i>0&&r.push(n.join(``));i<e.length;i++){let t=e[i];t instanceof Symbol||r.push(t)}return r};Rn();var Bi={[Ai]:P(`font-weight`,`bold`),[ji]:P(`font-weight`,`normal`),[Mi]:P(`color`,`blue`),[Pi]:P(`color`,`green`),[Ni]:P(`color`,`grey`),[Fi]:P(`color`,`red`),[Ii]:P(`color`,`purple`),[Li]:P(`color`,`orange`),[Ri]:P(`color`,`black`)},Vi=fr?e=>{var t;e.length===1&&((t=e[0])==null?void 0:t.constructor)===Function&&(e=e[0]());let n=[],r=[],i=w(),a=[],o=0;for(;o<e.length;o++){let t=e[o],a=Bi[t];if(a!==void 0)i.set(a.left,a.right);else{if(t===void 0)break;if(t.constructor===String||t.constructor===Number){let e=Ti(i);o>0||e.length>0?(n.push(`%c`+t),r.push(e)):n.push(t)}else break}}for(o>0&&(a=r,a.unshift(n.join(``)));o<e.length;o++){let t=e[o];t instanceof Symbol||a.push(t)}return a}:zi,Hi=(...e)=>{console.log(...Vi(e)),Wi.forEach(t=>t.print(e))},Ui=(...e)=>{console.warn(...Vi(e)),e.unshift(Li),Wi.forEach(t=>t.print(e))},Wi=Lt(),Gi=e=>({[Symbol.iterator](){return this},next:e}),Ki=(e,t)=>Gi(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),qi=(e,t)=>Gi(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),Ji=class{constructor(e,t){this.clock=e,this.len=t}},Yi=class{constructor(){this.clients=new Map}},Xi=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])Ma(e,i,o.clock,o.len,n)}}),Zi=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=T((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},Qi=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&Zi(n,t.clock)!==null},$i=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new Ji(r.clock,Jt(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},ea=e=>{let t=new Yi;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)zt(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return $i(t),t},ta=(e,t,n,r)=>{Pt(e.clients,t,()=>[]).push(new Ji(n,r))},na=()=>new Yi,ra=(e,t)=>{O(e.restEncoder,t.clients.size),Bt(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),O(e.restEncoder,t);let r=n.length;O(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},ia=Fn,aa=class e extends Gt{constructor({guid:e=Ln(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=ia(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ta,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=zn(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>zn(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&U(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Bt(this.subdocs).map(e=>e.guid))}transact(e,t=null){return U(this,e,t)}get(e,t=G){let n=Pt(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==G&&r!==t)if(r===G){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=``){return this.get(e,So)}getText(e=``){return this.get(e,zo)}getMap(e=``){return this.get(e,K)}getXmlElement(e=``){return this.get(e,Ho)}getXmlFragment(e=``){return this.get(e,Vo)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Bt(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let r=t.content;r.doc=new e(n.t(n.t({guid:this.guid},r.opts),{},{shouldLoad:!1})),r.doc._item=t,U(t.parent.doc,e=>{let n=r.doc;t.deleted||e.subdocsAdded.add(n),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},oa=class{constructor(){this.restEncoder=fn()}toUint8Array(){return E(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){O(this.restEncoder,e)}writeDsLen(e){O(this.restEncoder,e)}},sa=class extends oa{writeLeftID(e){O(this.restEncoder,e.client),O(this.restEncoder,e.clock)}writeRightID(e){O(this.restEncoder,e.client),O(this.restEncoder,e.clock)}writeClient(e){O(this.restEncoder,e)}writeInfo(e){hn(this.restEncoder,e)}writeString(e){yn(this.restEncoder,e)}writeParentInfo(e){O(this.restEncoder,+!!e)}writeTypeRef(e){O(this.restEncoder,e)}writeLen(e){O(this.restEncoder,e)}writeAny(e){Dn(this.restEncoder,e)}writeBuf(e){k(this.restEncoder,e)}writeJSON(e){yn(this.restEncoder,JSON.stringify(e))}writeKey(e){yn(this.restEncoder,e)}},ca=class{constructor(){this.restEncoder=fn(),this.dsCurrVal=0}toUint8Array(){return E(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,O(this.restEncoder,t)}writeDsLen(e){e===0&&M(),O(this.restEncoder,e-1),this.dsCurrVal+=e}},la=class extends ca{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Mn,this.clientEncoder=new An,this.leftClockEncoder=new Mn,this.rightClockEncoder=new Mn,this.infoEncoder=new On(hn),this.stringEncoder=new Nn,this.parentInfoEncoder=new On(hn),this.typeRefEncoder=new An,this.lenEncoder=new An}toUint8Array(){let e=fn();return O(e,0),k(e,this.keyClockEncoder.toUint8Array()),k(e,this.clientEncoder.toUint8Array()),k(e,this.leftClockEncoder.toUint8Array()),k(e,this.rightClockEncoder.toUint8Array()),k(e,E(this.infoEncoder)),k(e,this.stringEncoder.toUint8Array()),k(e,E(this.parentInfoEncoder)),k(e,this.typeRefEncoder.toUint8Array()),k(e,this.lenEncoder.toUint8Array()),bn(e,E(this.restEncoder)),E(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){Dn(this.restEncoder,e)}writeBuf(e){k(this.restEncoder,e)}writeJSON(e){Dn(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},ua=(e,t,n,r)=>{r=Jt(r,t[0].id.clock);let i=V(t,r);O(e.restEncoder,t.length-i),e.writeClient(n),O(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},da=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{B(t,n)>e&&r.set(n,e)}),Ea(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),O(e.restEncoder,r.size),Bt(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{ua(e,t.clients.get(n),n,r)})},fa=(e,t)=>da(e,t.doc.store,t.beforeState),pa=class{constructor(){this.l=[]}},ma=()=>new pa,ha=(e,t)=>e.l.push(t),ga=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},_a=(e,t,n)=>nr(e.l,[t,n]),va=class{constructor(e,t){this.client=e,this.clock=t}},ya=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,z=(e,t)=>new va(e,t),ba=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw M()},xa=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Sa=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new Sa(e,t))(na(),new Map);var Ca=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Qi(t.ds,e.id),wa=(e,t)=>{let n=Pt(e.meta,wa,Lt),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<B(r,n)&&H(e,z(n,t))}),Xi(e,t.ds,e=>{}),n.add(t))},Ta=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ea=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},B=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},Da=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw M()}n.push(t)},V=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=T(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=T((n+r)/2)}throw M()},Oa=(e,t)=>{let n=e.clients.get(t.client);return n[V(n,t.clock)]},ka=(e,t,n)=>{let r=V(t,n),i=t[r];return i.id.clock<n&&i instanceof Y?(t.splice(r+1,0,ls(e,i,n-i.id.clock)),r+1):r},H=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[ka(e,n,t.clock)]},Aa=(e,t,n)=>{let r=t.clients.get(n.client),i=V(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==Ko&&r.splice(i+1,0,ls(e,a,n.clock-a.id.clock+1)),a},ja=(e,t,n)=>{let r=e.clients.get(t.id.client);r[V(r,t.id.clock)]=n},Ma=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=ka(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&ka(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Na=class{constructor(e,t,n){this.doc=e,this.deleteSet=new Yi,this.beforeState=Ea(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Pa=(e,t)=>t.deleteSet.clients.size===0&&!It(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:($i(t.deleteSet),fa(e,t),ra(e,t.deleteSet),!0),Fa=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Pt(e.changed,t,Lt).add(n)},Ia=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0;n=r,r=e[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof Y&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let a=t-i;return a&&e.splice(t+1-a,a),a},La=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=V(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof Y&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Ra=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=qt(r.length-1,1+V(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Ia(r,e)}})},za=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{$i(a),n.afterState=Ea(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{_a(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Io(n)})}),nr(e,[])}finally{r.gc&&La(a,i,r.gcFilter),Ra(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=Jt(V(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Ia(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=V(r,n);a+1<r.length&&Ia(r,a+1)>1||a>0&&Ia(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Hi(Li,Ai,`[yjs] `,ji,Fi,`Changed the client-id because another client seems to be using it.`),r.clientID=ia()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new sa;Pa(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new la;Pa(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid==null&&(e.collectionid=r.collectionid),r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):za(e,t+1)}}},U=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Na(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&za(i,0)}}return o},Ba=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Va=(e,t,n)=>{Xi(e,n.deletions,n=>{n instanceof Y&&t.scope.some(t=>t===e.doc||xa(t,n))&&cs(n,!1)})},Ha=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;U(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;Xi(n,o.insertions,e=>{if(e instanceof Y){if(e.redone!==null){let{item:t,diff:i}=ss(r,e.id);i>0&&(t=H(n,z(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||xa(t,e))&&c.push(e)}}),Xi(n,o.deletions,e=>{e instanceof Y&&a.some(t=>t===n.doc||xa(t,e))&&!Qi(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=ds(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Ua=class extends Gt{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=Wt(e)?e[0].doc:e instanceof aa?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new Yi;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&ta(i,n,r,a)});let a=Rn(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=ea([t.deletions,e.deleteSet]),t.insertions=ea([t.insertions,i])}else r.push(new Ba(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),Xi(e,e.deleteSet,t=>{t instanceof Y&&this.scope.some(n=>n===e.doc||xa(n,t))&&cs(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,()=>{this.destroy()})}addToScope(e){let t=new Set(this.scope);e=Wt(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof G?e.doc!==this.doc:e!==this.doc)&&Ui(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Va(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Va(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Ha(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Ha(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),super.destroy()}},Wa=`You must not compute changes after the event-handler fired.`,Ga=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Ka(this.currentTarget,this.target))}deletes(e){return Qi(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw A(Wa);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r))if(e!==null&&this.deletes(e))i=`delete`,a=Rt(e.content.getContent());else return;else e!==null&&this.deletes(e)?(i=`update`,a=Rt(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Rt(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw A(Wa);let t=this.target,n=Lt(),r=Lt(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},Ka=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},W=()=>{Ui(`Invalid access: Add Yjs type to a document before reading data.`)},qa=80,Ja=0,Ya=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Ja++}},Xa=e=>{e.timestamp=Ja++},Za=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Ja++},Qa=(e,t,n)=>{if(e.length>=qa){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Za(r,t,n),r}else{let r=new Ya(t,n);return e.push(r),r}},$a=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>Kt(t-e.index)<Kt(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Xa(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&Kt(n.index-i)<r.parent.length/qa?(Za(n,r,i),n):Qa(e._searchMarker,r,i)},eo=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=Jt(t,i.index+n))}},to=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;Pt(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;_a(r._eH,n,t)},G=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ma(),this._dEH=ma(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw j()}clone(){throw j()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){ha(this._eH,e)}observeDeep(e){ha(this._dEH,e)}unobserve(e){ga(this._eH,e)}unobserveDeep(e){ga(this._dEH,e)}toJSON(){}},no=(e,t,n)=>{e.doc!=null||W(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},ro=e=>{e.doc!=null||W();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},io=(e,t)=>{let n=0,r=e._start;for(e.doc!=null||W();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},ao=(e,t)=>{let n=[];return io(e,(r,i)=>{n.push(t(r,i,e))}),n},oo=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},so=(e,t)=>{e.doc!=null||W();let n=$a(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},co=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Y(z(o,B(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new $o(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Y(z(o,B(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new qo(new Uint8Array(n))),i.integrate(e,0);break;case aa:i=new Y(z(o,B(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Xo(n)),i.integrate(e,0);break;default:if(n instanceof G)i=new Y(z(o,B(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new os(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},lo=()=>A(`Length exceeded!`),uo=(e,t,n,r)=>{if(n>t._length)throw lo();if(n===0)return t._searchMarker&&eo(t._searchMarker,n,r.length),co(e,t,null,r);let i=n,a=$a(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&H(e,z(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&eo(t._searchMarker,i,r.length),co(e,t,o,r)},fo=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return co(e,t,r,n)},po=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=$a(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&H(e,z(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&H(e,z(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw lo();t._searchMarker&&eo(t._searchMarker,i,-a+r)},mo=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},ho=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new $o([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new $o([r]);break;case Uint8Array:s=new qo(r);break;case aa:s=new Xo(r);break;default:if(r instanceof G)s=new os(r);else throw Error(`Unexpected content type`)}new Y(z(o,B(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},go=(e,t)=>{e.doc!=null||W();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},_o=e=>{let t={};return e.doc!=null||W(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},vo=(e,t)=>{e.doc!=null||W();let n=e._map.get(t);return n!==void 0&&!n.deleted},yo=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&Ca(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},bo=e=>(e.doc!=null||W(),Ki(e._map.entries(),e=>!e[1].deleted)),xo=class extends Ga{},So=class e extends G{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof G?e.clone():e)),t}get length(){return this.doc!=null||W(),this._length}_callObserver(e,t){super._callObserver(e,t),to(this,e,new xo(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):U(this.doc,n=>{uo(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):U(this.doc,t=>{fo(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):U(this.doc,n=>{po(n,this,e,t)})}get(e){return so(this,e)}toArray(){return ro(this)}slice(e=0,t=this.length){return no(this,e,t)}toJSON(){return this.map(e=>e instanceof G?e.toJSON():e)}map(e){return ao(this,e)}forEach(e){io(this,e)}[Symbol.iterator](){return oo(this)}_write(e){e.writeTypeRef(ts)}},Co=class extends Ga{constructor(e,t,n){super(e,t),this.keysChanged=n}},K=class e extends G{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof G?e.clone():e)}),t}_callObserver(e,t){to(this,e,new Co(this,e,t))}toJSON(){this.doc!=null||W();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof G?r.toJSON():r}}),e}get size(){return[...bo(this)].length}keys(){return qi(bo(this),e=>e[0])}values(){return qi(bo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return qi(bo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc!=null||W(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):U(this.doc,t=>{mo(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):U(this.doc,n=>{ho(n,this,e,t)}),t}get(e){return go(this,e)}has(e){return vo(this,e)}clear(){this.doc===null?this._prelimContent.clear():U(this.doc,e=>{this.forEach(function(t,n,r){mo(e,r,n)})})}_write(e){e.writeTypeRef(ns)}},q=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&$n(e,t),wo=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&M(),this.right.content.constructor){case J:this.right.deleted||Oo(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},To=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case J:t.right.deleted||Oo(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&H(e,z(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Eo=(e,t,n,r)=>{let i=new Map,a=r?$a(t,n):null;return a?To(e,new wo(a.p.left,a.p,a.index,i),n-a.index):To(e,new wo(null,t._start,0,i),n)},Do=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===J&&q(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Y(z(a,B(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new J(o,r));l.integrate(e,0),n.right=l,n.forward()})},Oo=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},ko=(e,t)=>{for(;;){var n;if(e.right===null||!(e.right.deleted||e.right.content.constructor===J&&q((n=t[e.right.content.key])==null?null:n,e.right.content.value)))break;e.forward()}},Ao=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let c in r){var s;let l=r[c],u=(s=n.currentAttributes.get(c))==null?null:s;if(!q(u,l)){o.set(c,u);let{left:r,right:s}=n;n.right=new Y(z(a,B(i.store,a)),r,r&&r.lastId,s,s&&s.id,t,null,new J(c,l)),n.right.integrate(e,0),n.forward()}}return o},jo=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;ko(n,i);let s=Ao(e,t,n,i),c=r.constructor===String?new es(r):r instanceof G?new os(r):new Zo(r),{left:l,right:u,index:d}=n;t._searchMarker&&eo(t._searchMarker,n.index,c.getLength()),u=new Y(z(o,B(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Do(e,t,n,s)},Mo=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;ko(n,i);let s=Ao(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===J));){if(!n.right.deleted)switch(n.right.content.constructor){case J:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(q(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&H(e,z(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`
|
|
3
3
|
`;n.right=new Y(z(o,B(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new es(i)),n.right.integrate(e,0),n.forward()}Do(e,t,n,s)},No=(e,t,n,r,i)=>{let a=t,o=w();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===J){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case J:{var l;let{key:a,value:d}=n,f=(l=r.get(a))==null?null:l;if(o.get(a)!==n||f===d){var u;t.delete(e),s++,!c&&((u=i.get(a))==null?null:u)===d&&f!==d&&(f===null?i.delete(a):i.set(a,f))}!c&&!t.deleted&&Oo(i,n);break}}}t=t.right}return s},Po=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===J){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Fo=e=>{let t=0;return U(e.doc,n=>{let r=e._start,i=e._start,a=w(),o=Nt(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case J:Oo(o,i.content);break;default:t+=No(n,r,i,a,o),a=Nt(o),r=i;break}i=i.right}}),t},Io=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&Ma(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===J&&e.constructor!==Ko&&t.add(e.parent)})}U(n,n=>{Xi(e,e.deleteSet,e=>{if(e instanceof Ko||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===J?t.add(r):Po(n,e)});for(let e of t)Fo(e)})},Lo=(e,t,n)=>{let r=n,i=Nt(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case os:case Zo:case es:n<t.right.length&&H(e,z(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}a&&No(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&eo(o._searchMarker,t.index,-r+n),t},Ro=class extends Ga{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];U(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},Xn(o)||(e.attributes=Kn({},o))),c=0;break}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case os:case Zo:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case es:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case J:{let{key:t,value:s}=i.content;if(this.adds(i)){if(!this.deletes(i)){var d;if(q((d=n.get(t))==null?null:d,s))s!==null&&i.delete(e);else{var f;a===`retain`&&u(),q(s,(f=r.get(t))==null?null:f)?delete o[t]:o[t]=s}}}else if(this.deletes(i)){var p;r.set(t,s);let e=(p=n.get(t))==null?null:p;q(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(q(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Oo(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},zo=class e extends G{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc!=null||W(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Ro(this,e,t);to(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc!=null||W();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===es&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):U(this.doc,n=>{let r=new wo(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
|
|
4
4
|
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&jo(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Lo(n,r,a.delete):Mo(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc!=null||W();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(Ca(s,e)||t!==void 0&&Ca(s,t))switch(s.content.constructor){case es:{let r=i.get(`ychange`);e!==void 0&&!Ca(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!Ca(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case os:case Zo:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case J:Ca(s,e)&&(c(),Oo(i,s.content));break}s=s.right}c()};return e||t?U(a,n=>{e&&wa(n,e),t&&wa(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):U(r,r=>{let i=Eo(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),jo(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):U(r,r=>{let i=Eo(r,this,e,!n);jo(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):U(n,n=>{Lo(n,Eo(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):U(r,r=>{let i=Eo(r,this,e,!1);i.right!==null&&Mo(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):U(this.doc,t=>{mo(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):U(this.doc,n=>{ho(n,this,e,t)})}getAttribute(e){return go(this,e)}getAttributes(){return _o(this)}_write(e){e.writeTypeRef(rs)}},Bo=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc!=null||W()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Ho||t.constructor===Vo)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}else e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},Vo=class e extends G{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof G?e.clone():e)),t}get length(){return this.doc!=null||W(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Bo(this,e)}querySelector(e){e=e.toUpperCase();let t=new Bo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Bt(new Bo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){to(this,e,new Uo(this,t,e))}toString(){return ao(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),io(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):U(this.doc,n=>{uo(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)U(this.doc,n=>{let r=e&&e instanceof G?e._item:e;co(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw A(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):U(this.doc,n=>{po(n,this,e,t)})}toArray(){return ro(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return so(this,e)}slice(e=0,t=this.length){return no(this,e,t)}forEach(e){io(this,e)}_write(e){e.writeTypeRef(as)}},Ho=class e extends Vo{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Jn(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof G?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):U(this.doc,t=>{mo(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):U(this.doc,n=>{ho(n,this,e,t)})}getAttribute(e){return go(this,e)}hasAttribute(e){return vo(this,e)}getAttributes(e){return e?yo(this,e):_o(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return io(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(is),e.writeKey(this.nodeName)}},Uo=class extends Ga{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},Wo=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw j()}mergeWith(e){return!1}write(e,t,n){throw j()}integrate(e,t){throw j()}},Go=0,Ko=class extends Wo{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Da(e.doc.store,this)}write(e,t){e.writeInfo(Go),e.writeLen(this.length-t)}getMissing(e,t){return null}},qo=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw j()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},Jo=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){ta(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},Yo=(e,t)=>new aa(n.t(n.t({guid:e},t),{},{shouldLoad:t.shouldLoad||t.autoLoad||!1})),Xo=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(Yo(this.doc.guid,this.opts))}splice(e){throw j()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},Zo=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw j()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},J=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw j()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},Qo=lr(`node_env`)===`development`,$o=class e{constructor(e){this.arr=e,Qo&&tr(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},es=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},ts=0,ns=1,rs=2,is=3,as=4,os=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw j()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},ss=(e,t)=>{let n=t,r=0,i;do r>0&&(n=z(n.client,n.clock+r)),i=Oa(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Y);return{item:i,diff:r}},cs=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},ls=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Y(z(r,i+n),t,z(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=z(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},us=(e,t)=>Ht(e,e=>Qi(e.deletions,t)),ds=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return H(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||ds(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=H(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:H(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:H(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||Qi(r,d.right.id)||us(a.undoStack,d.right.id)||us(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=H(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;let m=z(c,B(s,c)),h=new Y(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,cs(h,!0),h.integrate(e,0),h},Y=class e extends Wo{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===va&&this.id.client!==this.parent.client&&this.parent.clock>=B(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Aa(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=H(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Ko||this.right&&this.right.constructor===Ko)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===va){let e=Oa(n,this.parent);e.constructor===Ko?this.parent=null:this.parent=e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Aa(e,e.doc.store,z(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),ya(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(ya(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(Oa(e.doc.store,n.origin)))r.has(Oa(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Da(e.doc.store,this),this.content.integrate(e,this),Fa(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new Ko(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:z(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ya(e.origin,this.lastId)&&this.right===e&&ya(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),ta(e.deleteSet,this.id.client,this.id.clock,this.length),Fa(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw M();this.content.gc(e),t?ja(e,this,new Ko(this.id,this.length)):this.content=new Jo(this.length)}write(e,t){let n=t>0?z(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=ba(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===va?(e.writeParentInfo(!1),e.writeLeftID(t)):M();i!==null&&e.writeString(i)}this.content.write(e,t)}},fs=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},ps=`__ $YJS$ __`;fs[ps]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),fs[ps]=!0;var ms=[`local`,`load`,`no-capture`,`move`,`move-undo`,`move-redo`],hs=class{constructor(){this.changeCallbacks=[],this.yblocks=null,this.undoManager=null}observe(e,t){this.yblocks=e,this.undoManager=t,this.yblocks.observeDeep((e,t)=>{let n=this.mapTransactionOrigin(t.origin);for(let t of e)this.handleYjsEvent(t,n)})}onBlocksChanged(e){return this.changeCallbacks.push(e),()=>{let t=this.changeCallbacks.indexOf(e);t!==-1&&this.changeCallbacks.splice(t,1)}}mapTransactionOrigin(e){if(this.undoManager&&e===this.undoManager)return this.undoManager.undoing?`undo`:`redo`;if(!this.isLocalOriginTag(e))return`remote`;switch(e){case`local`:return`local`;case`load`:return`load`;case`no-capture`:return`local`;case`move`:return`local`;case`move-undo`:return`undo`;case`move-redo`:return`redo`;default:return e}}isLocalOriginTag(e){return typeof e==`string`&&ms.includes(e)}handleYjsEvent(e,t){if(this.yblocks!==null){if(e.target===this.yblocks){this.handleArrayEvent(e,t);return}e.target instanceof K&&this.handleMapEvent(e.target,t)}}handleArrayEvent(e,t){let n=[],r=[];e.changes.added.forEach(e=>{let t=e.content.getContent();for(let e of t){if(!(e instanceof K))continue;let t=e.get(`id`);typeof t==`string`&&n.push(t)}}),e.changes.deleted.forEach(e=>{let t=this.extractBlockIdFromDeletedItem(e);t!==void 0&&r.push(t)});let i=new Set(n),a=new Set(r),o=n.filter(e=>a.has(e)),s=n.filter(e=>!a.has(e)),c=r.filter(e=>!i.has(e));for(let e of o)this.emitChange({type:`move`,blockId:e,origin:t});s.length===1&&this.emitChange({type:`add`,blockId:s[0],origin:t}),s.length>1&&this.emitChange({type:`batch-add`,blockIds:s,origin:t});for(let e of c)this.emitChange({type:`remove`,blockId:e,origin:t})}extractBlockIdFromDeletedItem(e){var t;let n=e.content.getContent();if(n.length===0)return;let r=n[0];if(!(r instanceof K))return;let i=r._map.get(`id`),a=i instanceof Y&&((t=i.content)==null?void 0:t.getContent()[0]);return typeof a==`string`?a:void 0}handleMapEvent(e,t){if(this.yblocks===null)return;if(this.isTopLevelYblock(e)){let n=e.get(`id`);typeof n==`string`&&this.emitChange({type:`update`,blockId:n,origin:t});return}let n=this.findParentBlock(e);n!==void 0&&this.emitChange({type:`update`,blockId:n.get(`id`),origin:t})}isTopLevelYblock(e){return this.yblocks===null?!1:this.yblocks.toArray().includes(e)}findParentBlock(e){if(this.yblocks!==null)return this.yblocks.toArray().find(t=>{let n=t.get(`data`),r=t.get(`tunes`);return n===e||r===e})}emitChange(e){for(let t of this.changeCallbacks)t(e)}destroy(){this.changeCallbacks=[],this.yblocks=null,this.undoManager=null}},gs=class{constructor(e){this.ydoc=new aa,this.yblocks=this.ydoc.getArray(`blocks`),this.serializer=e}fromJSON(e){this.ydoc.transact(()=>{this.yblocks.delete(0,this.yblocks.length);for(let t of e){let e=this.serializer.outputDataToYBlock(t);this.yblocks.push([e])}},`load`)}toJSON(){return this.yblocks.toArray().map(e=>this.serializer.yBlockToOutputData(e))}addBlock(e,t){let n=this.serializer.outputDataToYBlock(e);return this.transact(()=>{let e=Math.max(0,Math.min(t==null?this.yblocks.length:t,this.yblocks.length));this.yblocks.insert(e,[n])},`local`),n}removeBlock(e){let t=this.findBlockIndex(e);t!==-1&&this.transact(()=>{this.yblocks.delete(t,1)},`local`)}moveBlock(e,t,n){let r=this.findBlockIndex(e);if(r===-1||r===t)return;let i=n===`local`?`move`:n;this.transact(()=>{let e=this.yblocks.get(r),n=this.serializer.yBlockToOutputData(e);this.yblocks.delete(r,1);let i=Math.max(0,Math.min(t,this.yblocks.length));this.yblocks.insert(i,[this.serializer.outputDataToYBlock(n)])},i)}getBlockById(e){let t=this.findBlockIndex(e);if(t!==-1)return this.yblocks.get(t)}updateBlockData(e,n,r){let i=this.getBlockById(e);if(i===void 0)return!1;let a=i.get(`data`);return t.Gr(a.get(n),r)?!1:(this.transact(()=>{a.set(n,r)},`local`),!0)}updateBlockTune(e,t,n){let r=this.getBlockById(e);r!==void 0&&this.transact(()=>{this.getOrCreateTunesMap(r).set(t,n)},`local`)}updateBlockMetadata(e,t,n){let r=this.getBlockById(e);if(r===void 0)return!1;let i=r.get(`lastEditedAt`),a=r.get(`lastEditedBy`);return i===t&&(n===null||a===n)?!1:(this.transact(()=>{r.set(`lastEditedAt`,t),n!==null&&r.set(`lastEditedBy`,n)},`local`),!0)}findBlockIndex(e){return this.yblocks.toArray().findIndex(t=>t.get(`id`)===e)}transact(e,t){this.ydoc.transact(e,t)}transactWithoutCapture(e){this.ydoc.transact(e,`no-capture`)}getOrCreateTunesMap(e){let t=e.get(`tunes`);if(t!==void 0)return t;let n=new K;return e.set(`tunes`,n),n}destroy(){this.ydoc.destroy()}},_s=new Set([` `,` `,`.`,`?`,`!`,`,`,`;`,`:`]),vs=e=>_s.has(e),ys=class{outputDataToYBlock(e){let t=new K;t.set(`id`,e.id),t.set(`type`,e.type);let n=this.normalizeBlockData(e.type,e.data);return t.set(`data`,this.objectToYMap(n)),e.tunes!==void 0&&t.set(`tunes`,this.objectToYMap(e.tunes)),e.parent!==void 0&&t.set(`parentId`,e.parent),e.content!==void 0&&t.set(`contentIds`,So.from(e.content)),e.lastEditedAt!==void 0&&t.set(`lastEditedAt`,e.lastEditedAt),e.lastEditedBy!==void 0&&t.set(`lastEditedBy`,e.lastEditedBy),t}yBlockToOutputData(e){let t=e.get(`id`),n=e.get(`type`),r=e.get(`data`);if(typeof t!=`string`)throw Error(`Block id must be a string`);if(typeof n!=`string`)throw Error(`Block type must be a string`);if(!(r instanceof K))throw Error(`Block data must be a Y.Map`);let i={id:t,type:n,data:this.yMapToObject(r)},a=e.get(`tunes`);a instanceof K&&a.size>0&&(i.tunes=this.yMapToObject(a));let o=e.get(`parentId`);typeof o==`string`&&(i.parent=o);let s=e.get(`contentIds`);s instanceof So&&s.length>0&&(i.content=s.toArray());let c=e.get(`lastEditedAt`);typeof c==`number`&&(i.lastEditedAt=c);let l=e.get(`lastEditedBy`);return typeof l==`string`&&(i.lastEditedBy=l),i}objectToYMap(e){let t=new K;for(let[n,r]of Object.entries(e))typeof r==`object`&&r&&!Array.isArray(r)?t.set(n,this.objectToYMap(r)):t.set(n,r);return t}yMapToObject(e){let t={};return e.forEach((e,n)=>{e instanceof K?t[n]=this.yMapToObject(e):t[n]=e}),t}normalizeBlockData(e,t){return e===`paragraph`&&Object.keys(t).length===0?{text:``}:t}},bs=(e,t=!1)=>{let n=document.createTextNode(``);t?e.insertBefore(n,e.firstChild):e.appendChild(n);let r=document.createRange();r.setStart(n,0),r.setEnd(n,0);let i=window.getSelection();i&&(i.removeAllRanges(),i.addRange(r))},xs=(e,t)=>e===null?null:e.nodeType===Node.TEXT_NODE?e:xs(t?e.firstChild:e.lastChild,t),Ss=(e,n,r)=>{e.focus();let i=window.getSelection();if(!i)return;let a=r?t.Fr.getDeepestNode(e,!1):t.Fr.getDeepestNode(e,!0);if(!a)return;let o=document.createRange(),s=r?0:t.Fr.getContentLength(a);try{o.setStart(a,s),o.setEnd(a,s),i.removeAllRanges(),i.addRange(o)}catch(t){Cs(e,r)}},Cs=(e,n=!0)=>{var r,i,a,o;if(t.Fr.isNativeInput(e)){e.focus();let t=n?0:e.value.length;e.setSelectionRange(t,t);return}e.focus();let s=document.createRange(),c=window.getSelection();if(!c)return;let l=e.childNodes,u=n?(r=l[0])==null?null:r:(i=l[l.length-1])==null?null:i,d=xs(u,n);if(u===null){bs(e),c.removeAllRanges(),c.addRange(s);return}if(d===null||d.nodeType!==Node.TEXT_NODE){bs(e,n),c.removeAllRanges(),c.addRange(s);return}let f=(a=(o=d.textContent)==null?void 0:o.length)==null?0:a,p=n?0:f;s.setStart(d,p),s.setEnd(d,p),c.removeAllRanges(),c.addRange(s)},ws=(e,t)=>{let n=e.getBoundingClientRect();if(n.height!==0||n.top!==0)return n;let r=e.startContainer,i=r.nodeType===Node.ELEMENT_NODE?r:r.parentElement;if(!i)return t.getBoundingClientRect();let a=i.getBoundingClientRect();return a.height!==0||a.top!==0?a:t.getBoundingClientRect()},Ts=e=>{if(t.Fr.isNativeInput(e)&&e.tagName===`INPUT`)return!0;if(t.Fr.isNativeInput(e)){var n;let t=e,r=(n=t.selectionStart)==null?0:n;return!t.value.substring(0,r).includes(`
|