@ones-editor/editor 1.1.32-beta.2 → 1.1.32-beta.3

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/index.js CHANGED
@@ -21,14 +21,14 @@ Available method signatures are:
21
21
  `).map((i,o)=>{const l=o===0&&(t==null?void 0:t.firstLineAsTitle)?{heading:1}:void 0;return no(i,l)})},meta:{},comments:{}}}function K1(n){const t=n.blocks.root;if(t.length!==1)return!1;const e=t[0];return!(!e.text||$n(e.text))}function CB(n,t){const e=it();return n.localInsertChildContainers([{containerId:e,blocks:t}]),e}function Yo(n,t){return CB(n,[F0(t)])}const w8="\u200B",S8=D("to-plain-text");function Re(n,t){let e="";return n.forEach(r=>{if(p(S8,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){if(t!=null&&t.boxReplacement){e+=t.boxReplacement;return}if(r.attributes.text){e+=r.attributes.text;return}e+=" "}e+=r.insert}),e}function V1(n){return Re(n,{boxReplacement:" "})}function EB(n){return typeof n.offset=="number"}function K0(n){return EB(n.anchor)}function L8(n){return K0(n)&&n.anchor.offset===n.focus.offset&&n.anchor.blockId===n.focus.blockId}function AB(n,t){return{blockId:n,offset:t}}function V0(n,t){const e=AB(n,t);return{anchor:e,focus:e}}function xB(n,t){return{blockId:n,childContainerId:t}}function I8(n,t){const e=xB(n,t);return{anchor:e,focus:e}}const D8=D("block-to-text");function _8(n,t,e){let r="";return t.forEach(i=>{if(p(D8,typeof i.insert=="string","invalid op"),i.attributes&&i.attributes.box===!0){const o=i.attributes,s=n.editorBoxes.getBoxClass(o.type);if(s!=null&&s.convertTo){r+=s.convertTo(n,o,e,"text");return}if(i.attributes.text){r+=i.attributes.text;return}r+=`[${o.type}]`}r+=i.insert}),r}const M8=D("block-to-text");function U8(n,t,e){let r="";return t.forEach(i=>{if(p(M8,typeof i.insert=="string","invalid op"),i.attributes&&i.attributes.box===!0){const s=i.attributes,l=n.editorBoxes.getBoxClass(s.type);if(l!=null&&l.convertTo){r+=l.convertTo(n,s,e,"markdown");return}if(i.attributes.text){r+=i.attributes.text;return}r+=`[${s.type}]`}const o=i.attributes;if(o){let s=i.insert;o.link&&(s=`[${s}](${o.link})`);const l=[];o["style-code"]?l.push("`"):(o["style-bold"]&&l.push("**"),o["style-italic"]&&l.push("*"),o["style-underline"]&&l.push("__"),o["style-strikethrough"]&&l.push("~~"));const c=l.join("");r.endsWith(c.substring(0,1))&&(r+=" ");const d=l.reverse().join("");r+=c+s+d;return}r+=i.insert}),r}function O8(n,t,e){const r=t.text||[];let o=U8(n,r,e);if(t.heading){const s=t.heading;o=`${"#".repeat(s)} ${o}`}return t.quoted&&(o=`> ${o}`),t.type==="text"&&(o=`${o}
22
22
  `),o}function N8(n){switch(n){case"style-color-0":return"#e52727";case"style-color-1":return"#eb6414";case"style-color-2":return"#f0a100";case"style-color-3":return"#24b47e";case"style-color-4":return"#0064ff";case"style-color-5":return"#9678d3";case"style-color-6":return"#909090";default:return}}function P8(n){switch(n){case"style-bg-color-0":return"#fad4d4";case"style-bg-color-1":return"#fbe0d0";case"style-bg-color-2":return"#fceccc";case"style-bg-color-3":return"#d3f0e5";case"style-bg-color-4":return"#d6e9fa";case"style-bg-color-5":return"#eae4f6";case"style-bg-color-6":return"#dedede";case"style-bg-color-7":return"#e52727";case"style-bg-color-8":return"#eb6414";case"style-bg-color-9":return"#f0a100";case"style-bg-color-10":return"#24b47e";case"style-bg-color-11":return"#0064ff";case"style-bg-color-12":return"#9678d3";case"style-bg-color-13":return"#909090";case"style-bg-color-14":return"#e8e8e8";default:return}}const F8=D("block-to-text");function K8(n,t,e){let r="";return t.forEach(i=>{if(p(F8,typeof i.insert=="string","invalid op"),i.attributes&&i.attributes.box===!0){const s=i.attributes,l=n.editorBoxes.getBoxClass(s.type);if(l!=null&&l.convertTo){r+=l.convertTo(n,s,e,"html");return}if(i.attributes.text){r+=i.attributes.text;return}r+=`[${s.type}]`}const o=i.attributes;if(o){let s=i.insert;const l=[];let c="";o["style-bold"]&&l.push("strong"),o["style-italic"]&&l.push("em"),o["style-underline"]&&l.push("u"),o["style-strikethrough"]&&l.push("s"),o["style-code"]&&l.push("code");const d=Object.keys(o).find(A=>A.startsWith("style-bg-color-"));d&&(c+=`background-color: ${P8(d)};`);const h=Object.keys(o).find(A=>A.startsWith("style-color-"));h&&(c+=`color: ${N8(h)};`),o.link&&(s=`<a href="${o.link}">${s}</a>`);let C=l.map(A=>`<${A}>`).join(""),E=l.reverse().map(A=>`</${A}>`).join("");c&&(o.link?s=`<a href="${o.link}" style="${c}">${i.insert}</a>`:C?C=C.replace(">",` style="${c}">`):(C=`<span style="${c}">`,E="</span>")),r+=C+s+E;return}r+=i.insert}),r||(r="<br>"),`<p>${r}</p>`}const zc=D("text-block");function V8(n,t,e,r,i){const{text:o}=i;p(zc,o,"no text for text block");const s=fa(r,"div");return D0(n,t,i.id,s,o),s}function $8(n,t,e){p(zc,e,"no text to update");const r=fa(null,"div");D0(n,el(t),ut(t),r,e);const i=zt(t);Bf(i,r)}function H8(n,t,e){return WD(n,t,e)}function bB(n,t){let e="";return t.forEach(r=>{var i,o,s;if(!!r.insert){if(r.attributes&&r.attributes.box===!0){const l=n.getBoxById(r.attributes.id),c=(o=(i=n.editorBoxes.getBoxClass(r.attributes.type)).getBoxProperties)==null?void 0:o.call(i,n,l);e+=(s=c==null?void 0:c.abstract)!=null?s:" ";return}e+=r.insert}}),e.trim()}function j8(n,t){p(zc,st(n,t),"block in not textBlock");const e=n.selection.range;let r="";if(e.isCollapsed()){const i=n.getBlockText(t);r=bB(n,i)}else{const i=ut(t),o=Zi(n,{simpleBlockOnly:!0}).find(s=>ut(s.block)===i);if(o&&!Be(n,o.block)){p(zc,o.block===t,"block not match");const s=n.getBlockText(t),{start:l,end:c}=o,d=l.offset,h=c.offset-d;if(h>0){const{middle:C}=ln(s,d,h);r=bB(n,C)}}}return{abstract:r.trim()}}function z8(n,t,e,r){return p(zc,t.text,"no text for text block"),r==="text"?_8(n,t.text,e):r==="markdown"?O8(n,t,e):K8(n,t.text,e)}function G8(n,t){const e=Et.default(t);e.id=it();const{text:r}=e;return p(zc,r,"no text for text block"),r.forEach(i=>{i.insert&&i.attributes&&i.attributes.box===!0&&(i.attributes.id=it())}),{blocks:{root:[e]},meta:{},comments:{}}}const ar={blockType:"text",blockKind:"text",createBlockContent:V8,getBlockTextLength:Of,getRangeFromPoint:x8,moveCaret:E8,updateSelection:qD,clearSelection:XD,getCaretRect:kr,getClientRects:H8,setBlockText:$8,getBlockProperties:j8,convertTo:z8,blockToDoc:G8},W8=D0,$0=D("action-helper");function Qo(n,t){const e=at(t),r=pt(e),i=Rt(t);return n.doc.getBlockData(r,i)}function Yn(n,t){p($0,st(n,t),"not a text kind block");const r=Qo(n,t).text;return p($0,r,"no text in block"),r}function H0(n,t,e){return sr(Yn(n,t),e).left}function vB(n,t){const e=et(t);p($0,e,"no parent block");const r=Yn(n,e),i=Nv(t),o=r.find(s=>{const l=s.attributes;return l?l.box&&l.id===i:!1});return p($0,o,"failed to find box"),o.attributes}const Fe=D("block-text");function q8(n,t,e){p(Fe,st(n,t),"not a text kind block"),p(Fe,lr(t,e),"not a valid offset"),p(Fe,e>=0&&e<Ct(n,t),`invalid offset: ${e}`);const i=ga(t,e)-e;i===0&&p(Fe,!1,`no text after offset: ${e}`);const o=Yn(n,t),{middle:s}=ln(o,e,i);p(Fe,s.length===1,"failed to split text to 3 parts");const l=s[0];return zo(l)?" ":(p(Fe,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function X8(n,t,e){p(Fe,st(n,t),"not a text kind block"),p(Fe,lr(t,e),"not a valid offset"),p(Fe,e>0&&e<=Ct(n,t),`invalid offset: ${e}`);const r=il(t,e),i=e-r;i===0&&p(Fe,!1,`no text before offset: ${e}`);const o=Yn(n,t),{middle:s}=ln(o,r,i);p(Fe,s.length===1,"failed to split text to 3 parts");const l=s[0];return zo(l)?" ":(p(Fe,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function j0(n,t,e){p(Fe,st(n,t),"not a text kind block"),p(Fe,lr(t,e),"not a valid offset"),p(Fe,e>0&&e<=Ct(n,t),`invalid offset: ${e}`);const r=il(t,e),i=e-r;i===0&&p(Fe,!1,`no text before offset: ${e}`);const o=Yn(n,t),{middle:s}=ln(o,r,i);p(Fe,s.length===1,"failed to split text to 3 parts");const l=s[0];return zo(l)?{op:l,charType:"box",offset:r,length:1}:{op:l,charType:g0(l.insert)?"space":"text",offset:r,length:l.insert.length}}function Vf(n,t,e){p(Fe,st(n,t),"not a text kind block"),p(Fe,lr(t,e),"not a valid offset"),p(Fe,e>=0&&e<Ct(n,t),`invalid offset: ${e}`);const i=ga(t,e)-e;i===0&&p(Fe,!1,`no text after offset: ${e}`);const o=Yn(n,t),{middle:s}=ln(o,e,i);p(Fe,s.length===1,"failed to split text to 3 parts");const l=s[0];return zo(l)?{op:l,charType:"box",offset:e,length:1}:{op:l,charType:g0(l.insert)?"space":"text",offset:e,length:l.insert.length}}function Y8(n,t,e,r){let i=e;for(;i>0;){const o=j0(n,t,i);if(o.charType===r)return o;i-=o.length}return null}function Q8(n,t,e,r){const i=Ct(n,t);let o=e;for(;o<i;){const s=Vf(n,t,o);if(s.charType===r)return s;o+=s.length}return null}function $1(n,t,e,r){let i=e;for(;i>0;){const o=j0(n,t,i);if(o.charType!==r)return o;i-=o.length}return null}function H1(n,t,e,r){const i=Ct(n,t);let o=e;for(;o<i;){const s=Vf(n,t,o);if(s.charType!==r)return s;o+=s.length}return null}function j1(n,t,e){if(p(Fe,st(n,t),"invalid blok type"),Be(n,t))return 0;const r=j0(n,t,e);if(r.charType==="box")return e-1;let i=e;if(r.charType==="space"){const s=$1(n,t,i,"space");if(!s||s.offset===0)return 0;if(s.charType==="box")return s.offset;i=s.offset}const o=$1(n,t,i,"text");return o?o.offset+o.length:0}function z1(n,t,e){if(p(Fe,st(n,t),"invalid blok type"),Be(n,t))return 0;const r=Vf(n,t,e);if(r.charType==="box")return e+1;let i=e;if(r.charType==="space"){const s=H1(n,t,i,"space");if(!s||s.offset===0)return Ct(n,t);if(s.charType==="box")return s.offset;i=s.offset}const o=H1(n,t,i,"text");return o?o.offset:Ct(n,t)}const BB=D("text-box");function J8(n,t,e,r){p(BB,r.text,`no text for text box data: ${JSON.stringify(r)}`),p(BB,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(r)}`),B("span",[],e,r.text)}function Z8(n,t,e,r){var i;return(i=t.text)!=null?i:""}const yB={boxType:"text",updateBoxContent:J8,convertTo:Z8},t_="data:image/svg+xml;base64,Cjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBkPSJNMTguMjQ0NSA2QzE3LjgyNzQgNiAxNy41MzYzIDYuMjkxMTcgMTcuNTM2MyA2LjcwODI2QzE3LjUzNjMgNi45ODM3IDE3LjU1OTkgNy4yMzU1MyAxNy41NTk5IDcuNjEzMjdDMTcuNTU5OSAxMC4yODExIDE2LjYyMzQgMTEuMzc0OSAxMy45NzkyIDExLjM3NDlIOC45NDI2Nkw3LjEyNDc5IDExLjQ4NTFMOS41NDA3NSA5LjI4MTYyTDExLjE5MzQgNy41OTc1M0MxMS4zMjcxIDcuNDcxNjEgMTEuMzk4IDcuMjgyNzQgMTEuMzk4IDcuMDkzODdDMTEuMzk4IDYuNjkyNTIgMTEuMDk4OSA2LjQwMTM1IDEwLjY5NzYgNi40MDEzNUMxMC41MDg3IDYuNDAxMzUgMTAuMzM1NiA2LjQ3MjE4IDEwLjE3ODIgNi42MjE3TDUuMjQzOTYgMTEuNTQ4MUM1LjA4NjU3IDExLjcwNTUgNSAxMS44OTQzIDUgMTIuMDkxMUM1IDEyLjI4NzggNS4wODY1NyAxMi40NzY3IDUuMjQzOTYgMTIuNjI2MkwxMC4xNjI1IDE3LjUzNjhDMTAuMzM1NiAxNy43MDk5IDEwLjUwODcgMTcuNzgwOCAxMC42OTc2IDE3Ljc4MDhDMTEuMDk4OSAxNy43ODA4IDExLjM5OCAxNy40ODk2IDExLjM5OCAxNy4wODgzQzExLjM5OCAxNi44OTE1IDExLjMyNzEgMTYuNzEwNSAxMS4xOTM0IDE2LjU4NDZMOS41NDA3NSAxNC45MDA1TDcuMTMyNjYgMTIuNjk3TDguOTQyNjYgMTIuODA3MkgxNC4wNTc5QzE3LjU1OTkgMTIuODA3MiAxOSAxMS4yNDExIDE5IDcuNjc2MjJDMTkgNy4yMzU1MyAxOC45OTIxIDYuODY1NjUgMTguOTM3IDYuNjEzODNDMTguODc0MSA2LjI5OTA0IDE4LjY3NzMgNiAxOC4yNDQ1IDZaIiBmaWxsPSIjQjJCQ0NEIi8+Cjwvc3ZnPgo=";function e_(n,t,e,r){_p(t_,[],e),B("br",[],e)}function n_(n,t,e,r){return r==="text"?`
23
23
  `:r==="html"?"<br>":r==="markdown"?`
24
- `:""}const TB={boxType:"br",updateBoxContent:e_,convertTo:n_},kB=D("editor-boxes");class RB{constructor(t){m(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,r=this.boxes.get(e);p(kB,!r,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return p(kB,e,`unknown box type: ${t}`),e}createBox(t,e){const r=Ov(e),i=Pv(r);return this.getBoxClass(e.type).updateBoxContent(this.editor,r,i,e),r}forEach(t){this.boxes.forEach(t)}}function r_(n,t,e,r){const i=r,{width:o,height:s,src:l}=i,c=["editor-box-image"];i.link&&c.push("editor-box-image-link");const d=B("img",c,e);o&&(d.style.width=`${o}px`),s&&(d.style.height=`${s}px`),d.src=n.doc.buildResourceUrl(l)}const wB={boxType:"image",updateBoxContent:r_},i_="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9InJnYigxNzgsIDE4OCwgMjA1KSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0ibTE3IDE1IDEuNTUgMS41NWMtLjk2IDEuNjktMy4zMyAzLjA0LTUuNTUgMy4zN1YxMWgzVjloLTNWNy44MkMxNC4xNiA3LjQgMTUgNi4zIDE1IDVjMC0xLjY1LTEuMzUtMy0zLTNTOSAzLjM1IDkgNWMwIDEuMy44NCAyLjQgMiAyLjgyVjlIOHYyaDN2OC45MmMtMi4yMi0uMzMtNC41OS0xLjY4LTUuNTUtMy4zN0w3IDE1bC00LTN2M2MwIDMuODggNC45MiA3IDkgN3M5LTMuMTIgOS03di0zbC00IDN6TTEyIDRjLjU1IDAgMSAuNDUgMSAxcy0uNDUgMS0xIDEtMS0uNDUtMS0xIC40NS0xIDEtMXoiPjwvcGF0aD4KPC9zdmc+Cg==";function o_(n,t,e){q(e,"editor-box-anchor"),_p(i_,[],e)}const SB={boxType:"anchor",updateBoxContent:o_};function s_(n,t,e,r){B("span",[],e,r.text)}const LB={insertionType:"inputting",updateInsertionContent:s_},IB=D("editor-insertion");class DB{constructor(t){m(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,r=this.insertions.get(e);p(IB,!r,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return p(IB,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const r=Fv(e.type,e.id,e.attributes),i=Vv(r);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,r,i,e),r}}class l_{constructor(t){m(this,"cursors",new Map);m(this,"timer");this.editor=t,this.timer=this.startTimer()}add(t,e){this.cursors.set(t,e)}startTimer(){return setInterval(()=>{const t=Date.now();Array.from(this.cursors).forEach(([e,r])=>{if(t-r>3e3){const i=Kv(this.editor,e);i&&ct(i,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function a_(n,t,e,r){var l;const i=r;Date.now()-i.time<5*1e3&&(n.addCustom("active-cursors",d=>new l_(d)).add(i.id,i.time),q(t,"active")),B("span",[],e,"|").setAttribute("data-cursor-name",i.name),t.style.setProperty("--cursor-color",n.getColor((l=i.rainbowIndex)!=null?l:0))}const G1={insertionType:"remote-cursor",updateInsertionContent:a_};class _B{constructor(t){m(this,"decorators",[]);this.editor=t}registerDecorator(t){this.decorators.push(t)}decorateBlock(t,e){let r=e;return this.decorators.forEach(i=>{if(i.decorateBlock){const o=i.decorateBlock(this.editor,t,e);o&&(r=Et.default(o))}}),r}decorateText(t,e){let r=e;const i=new Map;return this.decorators.forEach(o=>{if(o.decorateText){const s=o.decorateText(this.editor,t,e);if(s){const{insertions:l,text:c}=s;l&&Array.from(l.entries()).forEach(([d,h])=>{const C=i.get(d);C?C.push(...h):i.set(d,h)}),c&&(r=Et.default(c))}}}),{insertions:i,text:r}}}const W1=D("editor-input");class c_{constructor(t,e){m(this,"editor");m(this,"composing",!1);m(this,"callbacks");m(this,"inputElement");m(this,"handleWindowBlur",()=>{this.editor.emit("blur",this.editor),this.callbacks.onBlur()});m(this,"handleWindowFocus",()=>{document.activeElement===this.inputElement&&this.focus()});m(this,"handleDocumentClick",t=>{const e=this.editor.contentElement,r=t.target,i=this.isInDisableScrollMask(r);if(r&&(i||e.contains(r))){!i&&!Oc(r)&&(this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus());return}this.isInCommandBar(r)||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())});m(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&(this.editor.contains(t)||this.isInDisableScrollMask(t)||this.isInCommandBar(t))||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});m(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});m(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});m(this,"handleCompositionstart",t=>{!this.editor.isWritable()||(this.composing=!0,this.callbacks.onCompositionStart(t))});m(this,"handleCompositionend",t=>{ta()?setTimeout(()=>{this.composing=!1},100):this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});m(this,"handleInput",t=>{if(t instanceof InputEvent&&!!t.data){if(this.editor.readonly||!this.editor.isWritable()){this.inputElement.value="";return}this.composing?this.callbacks.onUpdateCompositionText(t,t.data,!1):(this.callbacks.onInsertText(t,t.data),this.inputElement.value="")}});m(this,"handleKeyDown",t=>{if(!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}!this.editor.isWritable()||setTimeout(()=>{this.composing||(this.inputElement.value="")})}});m(this,"handleCopy",t=>{this.callbacks.onCopy(t)});m(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onCut(t),W1.debug("on cut")});m(this,"handlePaste",t=>{if(!(t.isTrusted&&(!(t.target instanceof HTMLTextAreaElement)||this.inputElement!==t.target))){if(this.editor.readonly||this.inputElement!==t.target){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)}});m(this,"handlePasteText",(t,e)=>{this.callbacks.onPasteText(t,e)});this.editor=t,this.callbacks=e;const r=B("textarea",["editor-input"],t.contentElement);r.name="editor-input",r.onkeydown=this.handleKeyDown,r.oninput=this.handleInput,r.oncopy=this.handleCopy,document.addEventListener("paste",this.handlePaste),r.oncut=this.handleCut,r.addEventListener("compositionstart",this.handleCompositionstart),r.addEventListener("compositionend",this.handleCompositionend),this.inputElement=r,document.addEventListener("click",this.handleDocumentClick),document.addEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.addListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged),window.addEventListener("blur",this.handleWindowBlur),window.addEventListener("focus",this.handleWindowFocus)}isInCommandBar(t){let e=t;return e===null?!1:(e.nodeType===3&&(e=e.parentElement),!!(e!=null&&e.closest("div[data-command-bar-id]"))||!!(e!=null&&e.closest("[data-keep-editor-focus]")))}destroy(){this.callbacks.destroy(),document.removeEventListener("click",this.handleDocumentClick),document.removeEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.removeListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged);const t=this.inputElement;t.removeEventListener("compositionstart",this.handleCompositionstart),t.removeEventListener("compositionend",this.handleCompositionend),t.onkeydown=null,t.oninput=null,t.oncopy=null,document.removeEventListener("paste",this.handlePaste),window.removeEventListener("blur",this.handleWindowBlur),window.removeEventListener("focus",this.handleWindowFocus),t.oncut=null}getInput(){return this.inputElement}focus(){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),me.isMobileSafari?(this.inputElement.focus(),this.callbacks.onFocus()):setTimeout(()=>{this.inputElement.focus(),this.callbacks.onFocus()})}isInDisableScrollMask(t){let e=t;return e===null?!1:(e.nodeType===3&&(e=e.parentElement),!!(e!=null&&e.closest(".editor-disable-scroll")))}handleChanged(t){this.callbacks.onChanged(t)}handleRemoteChanged(t){this.callbacks.onRemoteChanged(t)}addHandler(t){this.callbacks.addHandler(t)}removeHandler(t){this.callbacks.removeHandler(t)}defaultInsertText(t,e,r,i,o){p(W1,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,r,i,o)}defaultHandleKeydown(t,e){return p(W1,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}forEach(t){this.callbacks.forEach(t)}}function MB(n){const t=n.rootElement,e=t.getBoundingClientRect(),r=jr(t),i=window.innerWidth,o=window.innerHeight,s=e.left<0?0:e.left,l=e.top<0?0:e.top,c=e.right>i?i:e.right,d=e.bottom>o?o:e.bottom,h=(s+c)/2,C=(l+d)/2,E=0-e.left+h,A=0-e.top+C,v=n.input.inputElement;v.style.left=`${E/r}px`,v.style.top=`${A/r}px`}const q1=D("editor-caret");function u_(){const t=window.navigator.userAgent.match(/Firefox\/(\d+)\./);return t?Number.parseInt(t[1],10):null}class f_{constructor(t){m(this,"editor");m(this,"caretElem");m(this,"handleReadOnlyChanged",()=>{this.update()});if(this.editor=t,this.caretElem=B("div",["editor-cursor"],this.editor.contentElement),me.isFirefox){const e=u_();e&&e<=79&&(this.caretElem.style.transition="none")}this.editor.on("readonlyChanged",this.handleReadOnlyChanged)}destroy(){this.editor.off("readonlyChanged",this.handleReadOnlyChanged)}visible(){const t=window.getComputedStyle(this.caretElem);return t.display!=="none"&&t.opacity!=="0"}hasCaret(){if(this.editor.readonly||!this.editor.selection.range.isCollapsed())return!1;const t=this.editor.selection.range.start;if(!(t instanceof pn))return!1;const e=this.editor.getBlockById(t.blockId);return!!st(this.editor,e)}update(){if(Af(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",MB(this.editor);return}const{range:e}=this.editor.selection;p(q1,e.isCollapsed,"range is not collapsed");const r=e.start;p(q1,r instanceof pn,"only simple block position can has caret");const i=this.editor.getBlockById(r.blockId);p(q1,st(this.editor,i),"only text kind block can has caret");let o;const s=i.querySelector("span.inputting-insertion");s?(o=na(s),o=new DOMRect(o.right,o.top,1,o.height)):o=kr(i,r);const l=this.editor.contentElement.getBoundingClientRect(),c=o.left-l.left,d=o.top-l.top;t.style.left=`${c}px`,t.style.top=`${d}px`,t.style.height=`${o.height}px`;const h=this.editor.input.inputElement;h.style.left=`${c}px`,h.style.top=`${d+o.height-24}px`,me.isMobileSafari&&(h.style.left=`${c-4}px`,h.style.height=`${o.height}px`);const E=gn(i,{horizontal:!0}).getBoundingClientRect(),A=E.left-l.left,v=A+E.width;c<A||c>v?(MB(this.editor),t.style.display="none"):t.style.display=""}}function UB(n){$v(n),n.selection.range.getSelectedBlocks().forEach(t=>Hv(n,t.block,t.start,t.end))}const d_=D("editor-dom");function z0(n){return gn(n.rootContainer).clientHeight}function $f(n){const e=gn(n.rootContainer).getBoundingClientRect(),r=e.x<0?0:e.x,i=e.y<0?0:e.y,o=e.right>window.innerWidth?window.innerWidth:e.right,s=e.bottom>window.innerHeight?window.innerHeight:e.bottom;return new DOMRect(r,i,o-r,s-i)}function h_(n,t){const e=$f(n),r=n.getBlockById(t.blockId),o=tl(n,r,t);return oa(e,o.x,o.y)&&oa(e,o.right,o.bottom)}function OB(n,t){const e=$f(n),r=t.getBoundingClientRect();return r.top>=e.top&&r.top<=e.bottom||r.bottom<=e.bottom&&r.bottom>=e.top}function m_(n,t){const e=$f(n),r=t.getBoundingClientRect();if(r.top>=e.top&&r.top<=e.bottom&&r.bottom<=e.bottom&&r.bottom>=e.top)return 100;const i=Math.max(0,Math.min(r.right,e.right)-Math.max(r.left,e.left)),o=Math.max(0,Math.min(r.bottom,e.bottom)-Math.max(r.top,e.top)),s=i*o,l=r.width*r.height;return s/l*100}function g_(n,t){const e=$f(n),r=t.getBoundingClientRect();return oa(e,r.x,r.y)||oa(e,r.right,r.bottom)}function p_(n,t){const e=$f(n),r=t.getBoundingClientRect();return r.right>e.right||r.left<e.left}function Hf(n,t,e){!t||(e!=null&&e.animation?(p_(n,t)&&ia(t,{elementToScroll:gn(t,{horizontal:!0}),disableHorizontal:!1}),ia(t,{elementToScroll:gn(t),disableHorizontal:!0,verticalOffset:e==null?void 0:e.verticalOffset})):t.scrollIntoView&&t.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"}))}function C_(n){if(!d0(n.rootContainer)){d_.warn("editorScrollIntoView: editor is not visible");return}const t=n.rootContainer.getBoundingClientRect();if(t.height<1&&t.width<1)return;const e=n.selection,r=e.range.focus;if(!r.isSimple()){const C=r,E=n.getContainerById(C.childContainerId);g_(n,E)||E.scrollIntoView();return}if(e.range.start.blockId===e.range.end.blockId){const C=n.getBlockById(e.range.start.blockId);if(Le(C)&&OB(n,C)&&m_(n,C)>=95||Pt(n,C)&&OB(n,C))return}const i=r,o=n.getBlockById(i.blockId);if(h_(n,i))return;if(Le(o)){const C=ae(o);if(C){["image"].includes(sn(o))?setTimeout(()=>{Hf(n,C,{animation:!0})},500):Hf(n,C,{animation:!0});return}}const s=tl(n,o,i),l=o.getBoundingClientRect(),c=ve(o),d=B("div",["editor-block-anchor"],c),h=jr(o);d.style.top=`${(s.top-l.top)/h}px`,Hf(n,d,{animation:!0}),setTimeout(()=>{d.remove()},200)}function E_(n,t){if(t.isCollapsed())return!1;const e=Me(n.rootContainer),r=Ge(n.rootContainer),{start:i,end:o}=t;return i.blockId===ut(e)&&i.offset===0&&o.blockId===ut(r)&&o.offset===Ct(n,r)}const NB=D("range-in-block");function PB(n,t){const e=t.getEditor(),r=e.getBlockById(t.start.blockId),i=e.getBlockById(t.end.blockId),o=r===n||Ee(n,r),s=i===n||Ee(n,i);return!!(o||s)}function FB(n,t){const e=n.doc.toJSON(),r=new Set(Object.values(e.blocks).map(s=>s.map(l=>l.id)).flat());let i,o=Gr(t);if(o){for(;o&&!r.has(ut(o));)o=Gr(o);p(NB,o,"no prev block while deleting a block"),i=Ie(n,o,Ct(n,o))}else{const s=Wr(t);p(NB,s,"no prev and next block while deleting a block"),i=Ie(n,s,0)}return i}const A_=D("block-to-html");function X1(n,t,e,r){const i=aa(n,t.type);if(i.convertTo)return i.convertTo(n,t,e,"html",r);if(i.blockKind!=="text")return`[${t.type}]`;p(A_,t.text,"no text");const o=Re(t.text);return`<div>${m0(o)}</div>`}const KB=D("block-to-text");function x_(n,t,e){let r="";return t.forEach(i=>{if(p(KB,typeof i.insert=="string","invalid op"),i.attributes&&i.attributes.box===!0){const o=i.attributes,s=n.editorBoxes.getBoxClass(o.type);if(s!=null&&s.convertTo){r+=s.convertTo(n,o,e,"text");return}if(i.attributes.text){r+=i.attributes.text;return}r+=`[${o.type}]`}r+=i.insert}),r}function G0(n,t,e,r){const i=aa(n,t.type);return i.convertTo?i.convertTo(n,t,e,"text",r):i.blockKind!=="text"?`[${t.type}]`:(p(KB,t.text,"no text"),x_(n,t.text,e))}function W0(n,t,e,r){const i=aa(n,t.type);return i.convertTo?i.convertTo(n,t,e,"markdown",r):G0(n,t,e,r)}function jf(n,t){return t.blocks.root.map((i,o)=>X1(n,i,t,[{containerId:"root",blockIndex:o}])).join(`
24
+ `:""}const TB={boxType:"br",updateBoxContent:e_,convertTo:n_},kB=D("editor-boxes");class RB{constructor(t){m(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,r=this.boxes.get(e);p(kB,!r,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return p(kB,e,`unknown box type: ${t}`),e}createBox(t,e){const r=Ov(e),i=Pv(r);return this.getBoxClass(e.type).updateBoxContent(this.editor,r,i,e),r}forEach(t){this.boxes.forEach(t)}}function r_(n,t,e,r){const i=r,{width:o,height:s,src:l}=i,c=["editor-box-image"];i.link&&c.push("editor-box-image-link");const d=B("img",c,e);o&&(d.style.width=`${o}px`),s&&(d.style.height=`${s}px`),d.src=n.doc.buildResourceUrl(l)}const wB={boxType:"image",updateBoxContent:r_},i_="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9InJnYigxNzgsIDE4OCwgMjA1KSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0ibTE3IDE1IDEuNTUgMS41NWMtLjk2IDEuNjktMy4zMyAzLjA0LTUuNTUgMy4zN1YxMWgzVjloLTNWNy44MkMxNC4xNiA3LjQgMTUgNi4zIDE1IDVjMC0xLjY1LTEuMzUtMy0zLTNTOSAzLjM1IDkgNWMwIDEuMy44NCAyLjQgMiAyLjgyVjlIOHYyaDN2OC45MmMtMi4yMi0uMzMtNC41OS0xLjY4LTUuNTUtMy4zN0w3IDE1bC00LTN2M2MwIDMuODggNC45MiA3IDkgN3M5LTMuMTIgOS03di0zbC00IDN6TTEyIDRjLjU1IDAgMSAuNDUgMSAxcy0uNDUgMS0xIDEtMS0uNDUtMS0xIC40NS0xIDEtMXoiPjwvcGF0aD4KPC9zdmc+Cg==";function o_(n,t,e){q(e,"editor-box-anchor"),_p(i_,[],e)}const SB={boxType:"anchor",updateBoxContent:o_};function s_(n,t,e,r){B("span",[],e,r.text)}const LB={insertionType:"inputting",updateInsertionContent:s_},IB=D("editor-insertion");class DB{constructor(t){m(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,r=this.insertions.get(e);p(IB,!r,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return p(IB,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const r=Fv(e.type,e.id,e.attributes),i=Vv(r);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,r,i,e),r}}class l_{constructor(t){m(this,"cursors",new Map);m(this,"timer");this.editor=t,this.timer=this.startTimer()}add(t,e){this.cursors.set(t,e)}startTimer(){return setInterval(()=>{const t=Date.now();Array.from(this.cursors).forEach(([e,r])=>{if(t-r>3e3){const i=Kv(this.editor,e);i&&ct(i,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function a_(n,t,e,r){var l;const i=r;Date.now()-i.time<5*1e3&&(n.addCustom("active-cursors",d=>new l_(d)).add(i.id,i.time),q(t,"active")),B("span",[],e,"|").setAttribute("data-cursor-name",i.name),t.style.setProperty("--cursor-color",n.getColor((l=i.rainbowIndex)!=null?l:0))}const G1={insertionType:"remote-cursor",updateInsertionContent:a_};class _B{constructor(t){m(this,"decorators",[]);this.editor=t}registerDecorator(t){this.decorators.push(t)}decorateBlock(t,e){let r=e;return this.decorators.forEach(i=>{if(i.decorateBlock){const o=i.decorateBlock(this.editor,t,e);o&&(r=Et.default(o))}}),r}decorateText(t,e){let r=e;const i=new Map;return this.decorators.forEach(o=>{if(o.decorateText){const s=o.decorateText(this.editor,t,e);if(s){const{insertions:l,text:c}=s;l&&Array.from(l.entries()).forEach(([d,h])=>{const C=i.get(d);C?C.push(...h):i.set(d,h)}),c&&(r=Et.default(c))}}}),{insertions:i,text:r}}}const W1=D("editor-input");class c_{constructor(t,e){m(this,"editor");m(this,"composing",!1);m(this,"callbacks");m(this,"inputElement");m(this,"handleWindowBlur",()=>{this.editor.emit("blur",this.editor),this.callbacks.onBlur()});m(this,"handleWindowFocus",()=>{document.activeElement===this.inputElement&&this.focus()});m(this,"handleDocumentClick",t=>{const e=this.editor.contentElement,r=t.target,i=this.isInDisableScrollMask(r);if(r&&(i||e.contains(r))){!i&&!Oc(r)&&(this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus());return}this.isInCommandBar(r)||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())});m(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&(this.editor.contains(t)||this.isInDisableScrollMask(t)||this.isInCommandBar(t))||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});m(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});m(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});m(this,"handleCompositionstart",t=>{!this.editor.isWritable()||(this.composing=!0,this.callbacks.onCompositionStart(t))});m(this,"handleCompositionend",t=>{ta()?setTimeout(()=>{this.composing=!1},100):this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});m(this,"handleInput",t=>{if(t instanceof InputEvent&&!!t.data){if(this.editor.readonly||!this.editor.isWritable()){this.inputElement.value="";return}this.composing?this.callbacks.onUpdateCompositionText(t,t.data,!1):(this.callbacks.onInsertText(t,t.data),this.inputElement.value="")}});m(this,"handleKeyDown",t=>{if(!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}!this.editor.isWritable()||setTimeout(()=>{this.composing||(this.inputElement.value="")})}});m(this,"handleCopy",t=>{this.callbacks.onCopy(t)});m(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onCut(t),W1.debug("on cut")});m(this,"handlePaste",t=>{if(!(t.isTrusted&&(!(t.target instanceof HTMLTextAreaElement)||this.inputElement!==t.target))){if(this.editor.readonly||this.inputElement!==t.target){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)}});m(this,"handlePasteText",(t,e)=>{this.callbacks.onPasteText(t,e)});this.editor=t,this.callbacks=e;const r=B("textarea",["editor-input"],t.contentElement);r.name="editor-input",r.onkeydown=this.handleKeyDown,r.oninput=this.handleInput,r.oncopy=this.handleCopy,document.addEventListener("paste",this.handlePaste),r.oncut=this.handleCut,r.addEventListener("compositionstart",this.handleCompositionstart),r.addEventListener("compositionend",this.handleCompositionend),this.inputElement=r,document.addEventListener("click",this.handleDocumentClick),document.addEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.addListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged),window.addEventListener("blur",this.handleWindowBlur),window.addEventListener("focus",this.handleWindowFocus)}isInCommandBar(t){let e=t;return e===null?!1:(e.nodeType===3&&(e=e.parentElement),!!(e!=null&&e.closest("div[data-command-bar-id]"))||!!(e!=null&&e.closest("[data-keep-editor-focus]")))}destroy(){this.callbacks.destroy(),document.removeEventListener("click",this.handleDocumentClick),document.removeEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.removeListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged);const t=this.inputElement;t.removeEventListener("compositionstart",this.handleCompositionstart),t.removeEventListener("compositionend",this.handleCompositionend),t.onkeydown=null,t.oninput=null,t.oncopy=null,document.removeEventListener("paste",this.handlePaste),window.removeEventListener("blur",this.handleWindowBlur),window.removeEventListener("focus",this.handleWindowFocus),t.oncut=null}getInput(){return this.inputElement}focus(t){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),me.isMobileSafari?(this.inputElement.focus(t),this.callbacks.onFocus()):setTimeout(()=>{this.inputElement.focus(t),this.callbacks.onFocus()})}isInDisableScrollMask(t){let e=t;return e===null?!1:(e.nodeType===3&&(e=e.parentElement),!!(e!=null&&e.closest(".editor-disable-scroll")))}handleChanged(t){this.callbacks.onChanged(t)}handleRemoteChanged(t){this.callbacks.onRemoteChanged(t)}addHandler(t){this.callbacks.addHandler(t)}removeHandler(t){this.callbacks.removeHandler(t)}defaultInsertText(t,e,r,i,o){p(W1,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,r,i,o)}defaultHandleKeydown(t,e){return p(W1,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}forEach(t){this.callbacks.forEach(t)}}function MB(n){const t=n.rootElement,e=t.getBoundingClientRect(),r=jr(t),i=window.innerWidth,o=window.innerHeight,s=e.left<0?0:e.left,l=e.top<0?0:e.top,c=e.right>i?i:e.right,d=e.bottom>o?o:e.bottom,h=(s+c)/2,C=(l+d)/2,E=0-e.left+h,A=0-e.top+C,v=n.input.inputElement;v.style.left=`${E/r}px`,v.style.top=`${A/r}px`}const q1=D("editor-caret");function u_(){const t=window.navigator.userAgent.match(/Firefox\/(\d+)\./);return t?Number.parseInt(t[1],10):null}class f_{constructor(t){m(this,"editor");m(this,"caretElem");m(this,"handleReadOnlyChanged",()=>{this.update()});if(this.editor=t,this.caretElem=B("div",["editor-cursor"],this.editor.contentElement),me.isFirefox){const e=u_();e&&e<=79&&(this.caretElem.style.transition="none")}this.editor.on("readonlyChanged",this.handleReadOnlyChanged)}destroy(){this.editor.off("readonlyChanged",this.handleReadOnlyChanged)}visible(){const t=window.getComputedStyle(this.caretElem);return t.display!=="none"&&t.opacity!=="0"}hasCaret(){if(this.editor.readonly||!this.editor.selection.range.isCollapsed())return!1;const t=this.editor.selection.range.start;if(!(t instanceof pn))return!1;const e=this.editor.getBlockById(t.blockId);return!!st(this.editor,e)}update(){if(Af(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",MB(this.editor);return}const{range:e}=this.editor.selection;p(q1,e.isCollapsed,"range is not collapsed");const r=e.start;p(q1,r instanceof pn,"only simple block position can has caret");const i=this.editor.getBlockById(r.blockId);p(q1,st(this.editor,i),"only text kind block can has caret");let o;const s=i.querySelector("span.inputting-insertion");s?(o=na(s),o=new DOMRect(o.right,o.top,1,o.height)):o=kr(i,r);const l=this.editor.contentElement.getBoundingClientRect(),c=o.left-l.left,d=o.top-l.top;t.style.left=`${c}px`,t.style.top=`${d}px`,t.style.height=`${o.height}px`;const h=this.editor.input.inputElement;h.style.left=`${c}px`,h.style.top=`${d+o.height-24}px`,me.isMobileSafari&&(h.style.left=`${c-4}px`,h.style.height=`${o.height}px`);const E=gn(i,{horizontal:!0}).getBoundingClientRect(),A=E.left-l.left,v=A+E.width;c<A||c>v?(MB(this.editor),t.style.display="none"):t.style.display=""}}function UB(n){$v(n),n.selection.range.getSelectedBlocks().forEach(t=>Hv(n,t.block,t.start,t.end))}const d_=D("editor-dom");function z0(n){return gn(n.rootContainer).clientHeight}function $f(n){const e=gn(n.rootContainer).getBoundingClientRect(),r=e.x<0?0:e.x,i=e.y<0?0:e.y,o=e.right>window.innerWidth?window.innerWidth:e.right,s=e.bottom>window.innerHeight?window.innerHeight:e.bottom;return new DOMRect(r,i,o-r,s-i)}function h_(n,t){const e=$f(n),r=n.getBlockById(t.blockId),o=tl(n,r,t);return oa(e,o.x,o.y)&&oa(e,o.right,o.bottom)}function OB(n,t){const e=$f(n),r=t.getBoundingClientRect();return r.top>=e.top&&r.top<=e.bottom||r.bottom<=e.bottom&&r.bottom>=e.top}function m_(n,t){const e=$f(n),r=t.getBoundingClientRect();if(r.top>=e.top&&r.top<=e.bottom&&r.bottom<=e.bottom&&r.bottom>=e.top)return 100;const i=Math.max(0,Math.min(r.right,e.right)-Math.max(r.left,e.left)),o=Math.max(0,Math.min(r.bottom,e.bottom)-Math.max(r.top,e.top)),s=i*o,l=r.width*r.height;return s/l*100}function g_(n,t){const e=$f(n),r=t.getBoundingClientRect();return oa(e,r.x,r.y)||oa(e,r.right,r.bottom)}function p_(n,t){const e=$f(n),r=t.getBoundingClientRect();return r.right>e.right||r.left<e.left}function Hf(n,t,e){!t||(e!=null&&e.animation?(p_(n,t)&&ia(t,{elementToScroll:gn(t,{horizontal:!0}),disableHorizontal:!1}),ia(t,{elementToScroll:gn(t),disableHorizontal:!0,verticalOffset:e==null?void 0:e.verticalOffset})):t.scrollIntoView&&t.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"}))}function C_(n){if(!d0(n.rootContainer)){d_.warn("editorScrollIntoView: editor is not visible");return}const t=n.rootContainer.getBoundingClientRect();if(t.height<1&&t.width<1)return;const e=n.selection,r=e.range.focus;if(!r.isSimple()){const C=r,E=n.getContainerById(C.childContainerId);g_(n,E)||E.scrollIntoView();return}if(e.range.start.blockId===e.range.end.blockId){const C=n.getBlockById(e.range.start.blockId);if(Le(C)&&OB(n,C)&&m_(n,C)>=95||Pt(n,C)&&OB(n,C))return}const i=r,o=n.getBlockById(i.blockId);if(h_(n,i))return;if(Le(o)){const C=ae(o);if(C){["image"].includes(sn(o))?setTimeout(()=>{Hf(n,C,{animation:!0})},500):Hf(n,C,{animation:!0});return}}const s=tl(n,o,i),l=o.getBoundingClientRect(),c=ve(o),d=B("div",["editor-block-anchor"],c),h=jr(o);d.style.top=`${(s.top-l.top)/h}px`,Hf(n,d,{animation:!0}),setTimeout(()=>{d.remove()},200)}function E_(n,t){if(t.isCollapsed())return!1;const e=Me(n.rootContainer),r=Ge(n.rootContainer),{start:i,end:o}=t;return i.blockId===ut(e)&&i.offset===0&&o.blockId===ut(r)&&o.offset===Ct(n,r)}const NB=D("range-in-block");function PB(n,t){const e=t.getEditor(),r=e.getBlockById(t.start.blockId),i=e.getBlockById(t.end.blockId),o=r===n||Ee(n,r),s=i===n||Ee(n,i);return!!(o||s)}function FB(n,t){const e=n.doc.toJSON(),r=new Set(Object.values(e.blocks).map(s=>s.map(l=>l.id)).flat());let i,o=Gr(t);if(o){for(;o&&!r.has(ut(o));)o=Gr(o);p(NB,o,"no prev block while deleting a block"),i=Ie(n,o,Ct(n,o))}else{const s=Wr(t);p(NB,s,"no prev and next block while deleting a block"),i=Ie(n,s,0)}return i}const A_=D("block-to-html");function X1(n,t,e,r){const i=aa(n,t.type);if(i.convertTo)return i.convertTo(n,t,e,"html",r);if(i.blockKind!=="text")return`[${t.type}]`;p(A_,t.text,"no text");const o=Re(t.text);return`<div>${m0(o)}</div>`}const KB=D("block-to-text");function x_(n,t,e){let r="";return t.forEach(i=>{if(p(KB,typeof i.insert=="string","invalid op"),i.attributes&&i.attributes.box===!0){const o=i.attributes,s=n.editorBoxes.getBoxClass(o.type);if(s!=null&&s.convertTo){r+=s.convertTo(n,o,e,"text");return}if(i.attributes.text){r+=i.attributes.text;return}r+=`[${o.type}]`}r+=i.insert}),r}function G0(n,t,e,r){const i=aa(n,t.type);return i.convertTo?i.convertTo(n,t,e,"text",r):i.blockKind!=="text"?`[${t.type}]`:(p(KB,t.text,"no text"),x_(n,t.text,e))}function W0(n,t,e,r){const i=aa(n,t.type);return i.convertTo?i.convertTo(n,t,e,"markdown",r):G0(n,t,e,r)}function jf(n,t){return t.blocks.root.map((i,o)=>X1(n,i,t,[{containerId:"root",blockIndex:o}])).join(`
25
25
  `)}function VB(n,t){return`<!doctype html><html><head><meta charset="utf8" /></head><body>${jf(n,t)}</body></html>`}function ol(n,t){return t.blocks.root.map((i,o)=>G0(n,i,t,[{containerId:"root",blockIndex:o}])).join(`
26
26
  `)}function $B(n,t){const e=t.blocks.root.map((i,o)=>W0(n,i,t,[{containerId:"root",blockIndex:o}]));return e[e.length-1]=e[e.length-1].trimEnd(),e.join(`
27
27
  `)}const b_=D("get-text-position");function Gc(n,t){const e=t!=null?t:n.selection.range.start;e instanceof pn||p(b_,!1,`invalid insert pos type: ${typeof e}`);const{blockId:r}=e,i=n.getBlockById(r),o=Rt(i),s=at(i),l=pt(s),{offset:c}=e;return{block:i,container:s,containerId:l,blockIndex:o,offset:c}}const Wc=D("insert-text");function Y1(n,t,e,r){var s;const i=n.doc.getBlockData(t,e);if(p(Wc,i,"no block data"),p(Wc,i.text,"no block text"),$n(i.text)===0)return p(Wc,r===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,i.id);if(r===0)return;const o=ln(i.text,r-1,1).middle;if(!((s=o[0].attributes)!=null&&s.box))return o[0].attributes}function v_(n,t,e){const r=at(t),i=pt(r),o=Rt(t);return Y1(n,i,o,e)}function HB(n,t,e,r,i){const o=at(t),s=pt(o),l=Rt(t),c=v_(n,t,e),d=N0(e,r,c!=null?c:null);return n.doc.localUpdateBlockText(s,l,d,i),Yn(n,t)}function jB(n,t,e,r){const i=at(t),o=pt(i),s=Rt(t),l=N0(e," ",r);return n.doc.localUpdateBlockText(o,s,l),Yn(n,t)}function B_(n,t){let e=0;if(t===0)return!1;for(let r=0;r<n.length;r++){const i=n[r];p(Wc,typeof i.insert=="string","invalid text op, no insert");const o=e+L0(i);if(o===t)return!1;if(o>t)return!0;e=o}return!1}function Q1(n,t,e,r,i){const o=n.doc.getBlockData(e,r);p(Wc,o,"no block data"),p(Wc,o.text,"no block text");const s=Y1(n,e,r,i);s&&Object.keys(s).includes("link")&&(B_(o.text,i)||delete s.link);const l=N0(i,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,r,l),Yn(n,n.getBlockById(o.id))}function J1(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:r,offset:i}=Gc(n);Q1(n,t,e,r,i)}const q0=D("update-composition-text");function zB(n){const t=n.selection.range.start;t instanceof pn||p(q0,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,r=n.getBlockById(e);p(q0,st(n,r),"not a text kind block");const i=at(r),o=pt(i),s=Rt(r),l=n.doc.getBlockData(o,s);p(q0,l,"no block data in doc"),p(q0,l.text,"no text data in text block");const c=zt(r);D0(n,el(r),e,c,l.text)}function Z1(n){HD(n)}function qc(n,t,e,r,i,o){return n.doc.localInsertBlock(t,e,r,i,o),n.getBlockById(r.id)}const zf=D("delete-block-text");function tC(n,t,e,r,i){if(!n.isBlockWritable(t))return zf.error("block is not writable"),0;p(zf,st(n,t),"block is not a text kind block");const o=at(t),s=pt(o),l=Rt(t),c=n.doc.getBlockData(s,l);p(zf,c,"no block data in doc"),p(zf,c.text,"no text data in text block");let d=e;lr(t,e)||(d=il(t,d));let h=e+r;p(zf,h<=Ct(n,t),`invalid offset and count: ${e}, ${r}`),lr(t,h)||(h=ga(t,h));const C=h-d,E=uB(d,C);return n.doc.localUpdateBlockText(s,l,E,i),C}const eC=D("break-text-block");function GB(n,t){const r=n.getBlockData(t).quoted;return r?{quoted:r}:{}}function Xc(n,t,e,r){p(eC,st(n,t),`block is not a text kind block: ${Ot(t)}`),p(eC,e>=0&&e<=Ct(n,t),`invalid offset: ${e}`);const i=at(t),o=pt(i),s=Rt(t),l=r!=null&&r.copyBlockAttributes?GB(n,t):{};if(!(r!=null&&r.forceInsertAfter)&&(e===0||e===Ct(n,t))){let w=s;if(e!==0){let V=Wr(t);V?w=Rt(V):(V=Ge(i),w=Rt(V)+1)}const S={...no(""),...l,...r==null?void 0:r.newBlockData},U=Ie(n,t.id,0),M=qc(n,o,w,S,U);return{block:t,newBlock:M}}p(eC,lr(t,e),"not a valid offset");const c=Yn(n,t),{right:d}=sr(c,e),h=$n(d);h>0&&tC(n,t,e,h);let C=Wr(t),E;C?E=Rt(C):(C=Ge(i),E=Rt(C)+1);const A={...no(d),...l,...r==null?void 0:r.newBlockData},v=qc(n,o,E,A,Ie(n,A.id,0));return{block:t,newBlock:v}}const y_=D("prepare-insert-new-block");function T_(n,t,e){if(t&&e!==void 0&&e!==null){const d=n.getContainerById(t),h=ke(d);return p(y_,e>=0&&e<=h.length,`invalid blockIndex: ${e}`),{containerId:t,blockIndex:e}}const r=n.selection.range.start;if(!r.isSimple())return null;const i=n.getBlockById(r.blockId);if(t=pt(at(i)),e=Rt(i),!st(n,i))return{containerId:t,blockIndex:e+1};const s=r.offset;if(s===0||s===Ct(n,i))return{containerId:t,blockIndex:s===0?e:e+1};const c=Xc(n,i,s).newBlock;return{containerId:t,blockIndex:Rt(c)}}const k_=D("auto-insert-block");function WB(n,t,e,r,i,o){const s=T_(n,e,r);p(k_,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},c={anchor:l,focus:l};return qc(n,s.containerId,s.blockIndex,t,i!=null?i:c,o)}const R_=D("delete-block");function X0(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(r=>{n.getChildContainerData(r).forEach(o=>{X0(n,o,e)})}))}function Y0(n,t,e){const r=at(t),i=pt(r),o=Rt(t),s=n.doc.getBlockData(i,o);return p(R_,s,"no block data in doc"),n.doc.localDeleteBlock(i,o,Cn(n,{anchor:e.start,focus:e.end})),s}function nC(n,t,e){return n.undoManager.runInGroup(()=>{const r=at(t);Xi(r)===1&&n.insertTextBlock("",pt(r),0);let i=e?nl(n,e):null;if(!i){const l=n.selection.range;PB(t,l)?i=FB(n,t):i=l}const o=Y0(n,t,i),s=[];return X0(n,o,s),s.length>0&&n.doc.localDeleteChildContainers(s),o})}function w_(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(i=>{X0(n,i,e)}),n.doc.localDeleteChildContainers(e)}function qB(n,t){const e=[...t];t.forEach(r=>{n.doc.getContainerBlocks(r).forEach(o=>{X0(n,o,e)})}),n.doc.localDeleteChildContainers(e)}const rC=D("merge-text-block");function XB(n,t,e){p(rC,st(n,t),"only text block can be merged"),p(rC,st(n,e),"only text block can be merged");const r=Qo(n,t),i=Qo(n,e),o=r.text,s=i.text;p(rC,o&&s,"block data has no text");const l=at(t),c=pt(l),d=Rt(t),h=Ct(n,t),C=Q1(n,s,c,d,h),E=Ie(n,t,$n(o));return nC(n,e,E),C}const ro=D("clear-selected-contents");function Q0(n,t){p(ro,st(n,t.block),"not a text kind block");const{start:e,end:r}=t;p(ro,e.isSimple(),"not a simple block position"),p(ro,r.isSimple(),"not a simple block position");const i=e.offset,o=r.offset;p(ro,i<=o,`invalid delete text offset: ${i}, ${o}`),i!==o&&n.deleteTextFromBlock(t.block,i,o-i)}function YB(n,t,e){const r=pt(t),i=ke(t),o=e.focus?void 0:n.selection.range.toDocRange(),s=n.insertTextBlock("",r,0,{newRange:o});e.focus&&n.selection.selectBlock(s,0),i.reverse().forEach(l=>{n.deleteBlock(l)})}function S_(n,t){const{block:e,start:r,end:i}=t;if(st(n,e)){Q0(n,t);return}if(Le(e)||r.isSimple()){p(ro,i.isSimple(),"invalid range");const s=at(e),l=Rt(e),c=n.insertTextBlock("",pt(s),l);n.selection.selectBlock(c,0),n.deleteBlock(e);return}p(ro,Pt(n,e),"invalid block kind"),p(ro,!r.isSimple()&&!i.isSimple(),"invalid range"),Pc(n,e,r,i),n.selection.range.getSelectedContainers().forEach((s,l)=>{YB(n,s,{focus:l===0})})}function L_(n){if(!n.isWritable())return;const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(p(ro,e.length>0,"no selected block"),e.length===1){S_(n,e[0]);return}const r=e[0],i=r.block,o=at(i);p(ro,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(st(n,i)){Q0(n,r);const h=Ie(n,r.block,r.start.offset);if(e.slice(1,e.length-1).reverse().forEach(E=>n.deleteBlock(E.block)),st(n,l)){Q0(n,s),n.mergeTextBlock(i,l,{focus:!0}),n.selection.setRange(h);return}n.deleteBlock(l),n.selection.setRange(h);return}if(st(n,l)){Q0(n,s),e.slice(0,e.length-1).reverse().forEach(h=>n.deleteBlock(h.block)),n.selection.selectBlock(s.block,0);return}if(e.length===Xi(o)){YB(n,o,{focus:!0});return}const c=He(i),d=ae(l);p(ro,c||d,"no prev or next block"),e.forEach(h=>n.deleteBlock(h.block))}function J0(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),L_(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}const I_=D("core");function QB(n,t,e,r){const i=at(t),o=pt(i),s=Rt(t);return n.doc.localUpdateBlockText(o,s,e,r),setTimeout(()=>{n.selection.updateSelection(null)}),Yn(n,t)}function JB(n,t,e,r){if(!n.isBlockWritable(t)){I_.error("block is not writable");return}const i=n.getBlockText(t),o=Hn.diff(i,e);QB(n,t,o,r)}function Z0(n,t,e){const r=Yn(n,t),i=typeof e=="string"?Ca(e):e,o=Hn.diff(r,i);return QB(n,t,o)}const Gf=D("update-block-data");function tm(n,t,e,r,i){const o=at(t),s=pt(o),l=Rt(t),c=n.doc.getBlockData(s,l),d={insert:{},delete:[]},h=new Set(Object.keys(c)),C=new Set(Object.keys(e));return h.forEach(A=>{if(!C.has(A)){if(A==="id"||A==="type"||A==="text")return;Gf.debug(`delete key: ${A}`),d.delete.push(A)}}),Object.entries(e).forEach(([A,v])=>{p(Gf,A!=="id"&&A!=="type",`invalid block data delta, ${A}`);const w=c[A];if(v==null){w!=null&&(Gf.debug(`delete key: ${A}`),d.delete.push(A));return}w!==v&&(Cf.default(w,v)||A==="text"&&Hn.diff(w,v).length===0||(h.has(A)?(Gf.debug(`replace key: ${A}`),d.delete.push(A)):Gf.debug(`insert key: ${A}`),d.insert[A]=v))}),n.doc.localUpdateBlockData(s,l,d,r,i),Qo(n,t)}function ZB(n,t,e,r){const o={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,o,r)}function iC(n,t,e){if(!Pt(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const i=zr(n,t).getChildContainers(n,t)[0],o=Me(i);iC(n,o,e)}function Ea(n){const t=[];let e={};return n.forEach(r=>{t.push(...r.blocks.root);const{root:i,...o}=r.blocks;e={...e,...o}}),{blocks:{...e,root:t},meta:{},comments:{}}}const Wf=D("clone-block");function sl(n,t,e,r){var C;const i=n.getBlockClass(e.type);if(i.blockToDoc)return i.blockToDoc(t,e,(E,A)=>(p(Wf,e!==A,"invalid child block"),sl(n,E,e,r)));let o={};const s=new Map,l=Et.default(e),c=E=>{if(s.has(E))return s.get(E);const A=it(),v=t.blocks[E];p(Wf,Array.isArray(v),"invalid child blocks");const w=v.map(V=>sl(n,t,V,r)),S=Ea(w),{root:U,...M}=S.blocks;return o={...o,...M},o[A]=S.blocks.root,s.set(E,A),A};l.children&&(l.children=l.children.map(c)),(C=l.exportSpec)==null||C.forEach(E=>{E.type==="block"&&(E.data=E.data.map(c))});const d=Array.from(s.entries()),h=E=>{for(const A of d){const[v,w]=A;{const S=`${v}/`;if(E.startsWith(S)){const U=E.substring(S.length),M=`${w}/${U}`;return Wf.debug(`replace key: ${E} -> ${M}`),M}}{const S=`${v}_`;if(E.startsWith(S)){const U=E.substring(S.length),M=`${w}_${U}`;return Wf.debug(`replace key: ${E} -> ${M}`),M}}}return E};return Array.from(Object.entries(l)).forEach(([E,A])=>{const v=h(E);v!==E&&delete l.key,l[v]=A}),l.id=it(),r&&(r.blockIdMap.set(e.id,l.id),s.forEach((E,A)=>r.containerIdMap.set(A,E))),{blocks:{root:[l],...o},meta:{},comments:{}}}function oC(n,t,e,r){const i=t.blocks[e];p(Wf,Array.isArray(i),"invalid child blocks");const o=i.map(l=>sl(n,t,l,r));return Ea(o)}function sC(n,t,e){const r=t.blocks.root.map(i=>sl(n.editorBlocks,t,i,e));return Et.default(Ea(r))}const t5=D("insert-doc");function e5(n,t,e,r,i){if(Pt(n,t)){t5.warn("failed to insert doc into a complex block");return}const o=sC(n,r,i),s=at(t),l=Rt(t),c=pt(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var V,nt,Y;const d=[];Object.entries(o.blocks).forEach(([X,ft])=>{X!=="root"&&d.push({containerId:X,blocks:ft})}),d.length>0&&n.doc.localInsertChildContainers(d);const h=o.blocks.root;if(Le(t)){n.deleteBlock(t);let X;h.reverse().forEach(ft=>{const xt=n.insertBlock(c,l,ft,void 0,{noFocus:!0});X||(X=xt)}),X&&n.selection.selectBlock(X,Ct(n,X));return}if(p(t5,st(n,t),"not a text block"),Be(n,t)){const X=Rt(t);let ft,xt=!1;for(let bt=0;bt<h.length;bt++){if(bt===0){const Tt=n.findBlockByIndex(c,X),ie=h[bt].type==="text"||h[bt].type==="list";if(Tt&&st(n,Tt)&&Be(n,Tt)&&ie){const xe=n.getBlockData(Tt),fe=xe.type==="list"||h[bt].type==="list"?"list":"text",Dr={...xe,...h[bt],type:fe},dr=n.insertBlock(c,X,Dr,void 0,{noFocus:!0});xt=!0,bt===h.length-1&&(ft=dr);continue}Tt&&Ko(Tt)&&(xt=!0)}const wt=n.insertBlock(c,X+bt,h[bt],void 0,{noFocus:!0});bt===h.length-1&&(ft=wt)}ft&&n.selection.selectBlock(ft,Ct(n,ft)),xt&&n.deleteBlock(t);return}if(h.length===1){const X=h[0];if(Sf(n,X.type)){n.insertTextToBlock(t,e,(V=X.text)!=null?V:[]);return}n.breakTextBlock(t,e),n.insertBlock(c,l+1,X);return}const C=e===Ct(n,t),E=e===0,A=h[0],v=h[h.length-1];let w;!C&&!E?w=n.breakTextBlock(t,e,{forceInsertAfter:!0}):w=t;const S=E?l:l+1;C?(w=n.insertBlock(c,l+1,v),n.selection.selectBlock(w,Ct(n,w))):(n.selection.selectBlock(w,0),Sf(n,v.type)?n.insertTextToBlock(w,0,(nt=v.text)!=null?nt:[]):n.insertBlock(c,S,v));const U=n.selection.range;let M=S;Sf(n,A.type)?E?(n.insertBlock(c,S,A),M+=1):n.insertTextToBlock(t,e,(Y=A.text)!=null?Y:[]):(n.insertBlock(c,S,A),M+=1),h.slice(1,h.length-1).reverse().forEach(X=>{n.insertBlock(c,M,X)}),n.selection.setRange(U)}),n.doc.endBatchUpdate()}function lC(n,t,e,r,i){const o=sC(n,r,i),s=pt(t),l=[];return n.undoManager.runInGroup(()=>{const c=[];Object.entries(o.blocks).forEach(([h,C])=>{h!=="root"&&c.push({containerId:h,blocks:C})}),n.doc.localInsertChildContainers(c),o.blocks.root.reverse().forEach(h=>{const C=n.insertBlock(s,e,h,void 0,{noFocus:!0,noScroll:!0});l.push(C)})}),l}function n5(n,t,e,r){const i=Xi(t);lC(n,t,i,e,r);for(let o=0;o<i;o++){const s=Me(t);n.deleteBlock(s)}}const qf=D("add-text-attribute");function D_(n,t,e,r){const{start:i,end:o}=e;p(qf,i.blockId===o.blockId&&i.blockId===ut(t),"invalid range"),p(qf,r,"invalid attribute name");const s=n.getBlockText(t),l=$c(i.offset,o.offset-i.offset,s,r,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function r5(n,t,e,r,i){const{start:o,end:s}=e;p(qf,o.blockId===s.blockId&&o.blockId===ut(t),"invalid range"),p(qf,r,"invalid attribute name");const l=n.getBlockText(t),c=Pf(o.offset,s.offset-o.offset,l,r,i);return n.setBlockText(t,c),c}function Yc(n,t,e,r,i){const{start:o,end:s}=e;p(qf,o.blockId===s.blockId&&o.blockId===ut(t),"invalid range");const l=n.getBlockText(t),c=Y3(o.offset,s.offset-o.offset,l,r,i);return n.setBlockText(t,c),c}function i5(n,t,e,r){const i=Zi(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{i.forEach(o=>{const{block:s,start:l,end:c}=o;if(!st(n,s))return;if(Be(n,s)){r(n,ut(s),t,e);return}const d=Cn(n,{anchor:l,focus:c});t==="color"||t==="backgroundColor"?Yc(n,s,d,t,e):(Yc(n,s,d,"color",null),Yc(n,s,d,"backgroundColor",null))})})}function o5(n,t,e){const r=Zi(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:o,start:s,end:l}=i;if(!st(n,o))return;if(Be(n,o)){(t==="clearColor"||t==="clearAll")&&e(n,ut(o),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,ut(o),"backgroundColor",null);return}const c=Cn(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Yc(n,o,c,"color",null),(t==="clearBackground"||t==="clearAll")&&Yc(n,o,c,"backgroundColor",null)})})}function s5(n,t,e){const r=t.getSelectedBlocks().filter(l=>st(n,l.block));if(r.length===0)return[null,null];const i=l=>{if(Ct(n,l.block)===0)return e(n,ut(l.block));const c=l.start,d=l.end,h=n.getBlockText(l.block);return Z3(c.offset,d.offset-c.offset,h)};let[o,s]=i(r[0]);return o===null&&s===null?[o,s]:(r.forEach(l=>{const[c,d]=i(l);c===null||o===null?o=null:o=c===o?o:null,d===null||s===null?s=null:s=d===s?s:null}),[o,s])}const Rr=D("adjust-selection-pos");function l5(n){const t=[];for(;n;){const e=at(n);if(t.unshift(e),re(e))return t;const r=et(e);p(Rr,r,"child container has not parent container"),n=r}p(Rr,!1,"should not come here: getParentContainers")}function a5(n,t){for(;t;){const e=at(t);if(e===n)return t;const r=et(e);p(Rr,r,"could not find parent block for a child container"),t=r}p(Rr,!1,"no parent block in specified container")}function __(n,t){const e=l5(n),r=l5(t);p(Rr,e.length>0&&r.length>0,"block has not parent container"),p(Rr,e[0]===r[0],"root container does not equal");let i=e[0];for(let l=1;l<e.length||r.length;l++)if(e[l]!==r[l]){i=e[l-1];break}const o=a5(i,n),s=a5(i,t);return{parentContainer:i,newBlock1:o,newBlock2:s}}function c5(n,t){let e=et(t);for(p(Rr,e,"element is not in a block");e;){const r=at(e);p(Rr,pi(r),"not a child container");const i=et(r);if(p(Rr,i,"child container has not parent block"),i===n)return r;e=i}p(Rr,!1,"failed to find parent container in complex block")}function em(n,t,e){const r=n.getBlockById(t.blockId),i=n.getBlockById(e.blockId);if(r===i)return t instanceof pn&&e instanceof pn?{anchor:t,focus:e}:t instanceof xi&&e instanceof xi?w0(n,r,t,e):null;const o=at(r),s=at(i);if(o===s)return t instanceof xi&&(t=ht(r,0,"home")),e instanceof xi&&(e=ht(i,Ct(n,i),"end")),p(Rr,t instanceof pn,"not valid position type"),p(Rr,e instanceof pn,"not valid position type"),{anchor:t,focus:e};if(r.contains(s))return null;if(i.contains(o)){if(t instanceof pn&&e instanceof xi){const v=n.getContainerById(e.childContainerId);if(v===o)return{anchor:e,focus:e};const w=et(o);if(w&&w===et(v)){const S=Ue(w,pt(o)),U=Ue(w,pt(v));return w0(n,w,S,U)}}return null}const l=u0(r,i)>0,{newBlock1:c,newBlock2:d}=__(r,i);if(c===d){const v=c,w=c5(v,r),S=c5(v,i);return t=Ue(c,pt(w)),e=Ue(c,pt(S)),Rr.debug(`select in complex block: ${w.id}, ${S.id}`),w0(n,v,t,e)}let h=l?Ct(n,c):0;c===r&&t instanceof pn&&(h=t.offset);let E=l?0:Ct(n,d);return d===i&&e instanceof pn&&(E=e.offset),t=ht(c,h,l?"end":"home"),e=ht(d,E,l?"home":"end"),{anchor:t,focus:e}}const M_=D("move-complex-block-position");function U_(n,t,e){const r=n.getBlockById(t.blockId);p(M_,Pt(n,r),"is not a complex block");const i=zr(n,r),o=n.getContainerById(t.childContainerId),s=i.getNextContainer(n,r,o,e,{noWrap:!0});return s?Ue(r,pt(s)):null}const ll=D("move-simple-block-position");function u5(n,t){const e=Dn(n,t,{visibleOnly:!0});if(e.length===0)return ll.warn("complex block has not any child container, not loaded?"),null;p(ll,e.length>0,"complex block has not any child container");const r=e[0];return Me(r)}function f5(n,t){const e=Dn(n,t,{visibleOnly:!0});if(e.length===0)return ll.warn("complex block has not any child container, not loaded?"),null;p(ll,e.length>0,"complex block has not any child container");const r=e[e.length-1];return Ge(r)}function d5(n,t,e){const r=e?u5(n,t):f5(n,t);return r?Pt(n,r)?d5(n,r,e):r:null}function O_(n,t,e){const r=n.getBlockById(t.blockId);return e==="move"&&Pt(n,r)&&t.offset===0?u5(n,r):Wr(r)}function N_(n,t,e){const r=n.getBlockById(t.blockId);return e==="move"&&Pt(n,r)&&t.offset===1?f5(n,r):Gr(r)}function aC(n){return n==="ArrowLeft"||n==="ArrowUp"}function cC(n,t,e){const r=at(t);if(re(r))return null;const i=et(r);p(ll,i,"child container has not parent block"),p(ll,Pt(n,i),"is not a complex block");const o=zr(n,i).getNextContainer(n,i,r,e);return o?aC(e)?Ge(o):Me(o):cC(n,i,e)}function P_(n,t,e){const r=at(t);if(re(r))return null;const i=et(r);if(p(ll,i,"child container has not parent block"),aC(e)){const l=He(i);if(l)return l}else{const l=ae(i);if(l)return l}const o=cC(n,i,e);if(o)return o;let s=i;for(;!re(at(s));)s=et(at(s));return aC(e)?He(s):ae(s)}function F_(n,t,e){if(!Pt(n,t)||zr(n,t).enableKeyboardSelect)return t;const i=d5(n,t,e==="ArrowDown"||e==="ArrowRight");return i||t}function K_(n,t,e,r){const i=n.getBlockById(t.blockId),s=le(n,i).moveCaret(n,i,t,e);if(s)return s;let l=e==="ArrowDown"||e==="ArrowRight"?O_(n,t,r):N_(n,t,r);if(l||(l=cC(n,i,e),l||(l=P_(n,i,e))),l||Pt(n,i)&&Dn(n,i).length===0&&(ll.warn("complex block has not any child container, not loaded?"),l=e==="ArrowDown"||e==="ArrowRight"?Wr(i):Gr(i)),!l){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!re(at(i)))return null;const c=n.insertTextBlock("",pt(n.rootContainer),Xi(n.rootContainer));return ht(c,0,"home")}return null}if(l=F_(n,l,e),st(n,l)){const c=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return d8(n,l,i,t,c);if(e==="ArrowUp")return f8(n,l,i,t,c)}return e==="ArrowLeft"||e==="ArrowUp"?ht(l,Ct(n,l),"end"):e==="ArrowRight"||e==="ArrowDown"?ht(l,0,"home"):null}function V_(n,t,e){if(t==="ArrowLeft")return e.start;const r=e.end,i=n.getBlockById(r.blockId);if(st(n,i))return r;const o=ae(i);if(o)return ht(o,0,"home");if(!re(at(i))||n.readonly)return r;const s=n.insertTextBlock("",pt(n.rootContainer),Xi(n.rootContainer));return ht(s,0,"home")}function $_(n,t,e){const r=n.selection.range;let i;if(r instanceof vn)e==="move"&&!r.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?i=V_(n,t,r):i=K_(n,r.getFocusedPos(),t,e);else if(i=U_(n,r.focus,t),e==="move"){const o=i!=null?i:r.focus,s=n.getContainerById(o.childContainerId);if(t==="ArrowLeft"||t==="ArrowUp"){const l=Ge(s);i=ht(l,0,"home")}else{const l=Me(s);i=ht(l,Ct(n,l),"end")}}return i?e==="move"?{anchor:i,focus:i}:em(n,r.anchor,i):null}function al(n,t,e){const r=$_(n,t,e);if(!r)return!1;const{anchor:i,focus:o}=r;return n.selection.setSelection(i,o),(t==="ArrowLeft"||t==="ArrowRight")&&n.selection.updateLastCaretRect(),!0}function h5(n){return al(n,"ArrowLeft","move"),!0}function m5(n){return al(n,"ArrowRight","move"),!0}function g5(n){return al(n,"ArrowUp","move"),!0}function p5(n){if(al(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=at(t);if(re(e)||Ge(e)!==t)return!0;const r=n.rootContainer;return n.insertTextBlock("",pt(r),Xi(r)),!0}function C5(n){return al(n,"ArrowDown","select"),!0}function E5(n){return al(n,"ArrowLeft","select"),!0}function A5(n){return al(n,"ArrowRight","select"),!0}function x5(n){return al(n,"ArrowUp","select"),!0}const b5=D("word-offset");function uC(n,t){const e=n.selection.range.focus;p(b5,e.isSimple(),"invalid range type");const r=n.getBlockById(e.blockId);if(Be(n,r))return ht(r,0,"home");if(e.offset===0||!st(n,r)){const s=He(r);if(!s)return null;const l=ht(s,Ct(n,s),"end");if(t==="select"&&st(n,s)){const c=j1(n,s,l.offset);return ht(s,c,"normal")}return l}const i=j1(n,r,e.offset);return ht(r,i,"normal")}function fC(n,t){const e=n.selection.range.focus;p(b5,e.isSimple(),"invalid range type");const r=n.getBlockById(e.blockId);if(Be(n,r))return ht(r,0,"end");if(e.offset===Ct(n,r)||!st(n,r)){const s=ae(r);if(!s)return null;const l=ht(s,0,"home");if(t==="select"&&st(n,s)){const c=z1(n,s,l.offset);return ht(s,c,"end")}return l}const i=z1(n,r,e.offset);return ht(r,i,"normal")}function v5(n){if(!n.selection.range.focus.isSimple())return!1;const e=uC(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function B5(n){if(!n.selection.range.focus.isSimple())return!1;const e=fC(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function y5(n){if(!n.selection.range.focus.isSimple())return!1;const e=uC(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function T5(n){if(!n.selection.range.focus.isSimple())return!1;const e=fC(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}D("find-block");function dC(n,t){if(!Pt(n,t))return t;const r=zr(n,t).getChildContainers(n,t)[0],o=ke(r)[0];return dC(n,o)}function hC(n,t){if(!Pt(n,t))return t;const e=zr(n,t).getChildContainers(n,t),r=e[e.length-1],i=ke(r),o=i[i.length-1];return hC(n,o)}function mC(n){const t=hC(n,Ge(n.rootContainer)),e=ht(t,Ct(n,t),"end");return n.selection.setSelection(e),!0}function k5(n){const t=dC(n,n.getFirstBlock()),e=ht(t,0,"home");return n.selection.setSelection(e),!0}function R5(n){const t=dC(n,n.getFirstBlock()),e=ht(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function gC(n){const t=hC(n,Ge(n.rootContainer)),e=ht(t,Ct(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const w5=D("line-offset");function S5(n){const t=n.selection.range.focus;p(w5,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!st(n,e))return ht(e,0,"home");let i=iB(e,t).start;const{next:o}=Mf(e,i);return o&&Tr(o)&&Lf(o)==="br"&&(i+=1),ht(e,i,"home")}function L5(n){const t=n.selection.range.focus;p(w5,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===Ct(n,e)||!st(n,e))return ht(e,Ct(n,e),"end");const r=iB(e,t);return ht(e,r.end,"end")}function I5(n){if(!n.selection.range.focus.isSimple())return!1;const e=S5(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function D5(n){if(!n.selection.range.focus.isSimple())return!1;const e=L5(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function _5(n){if(!n.selection.range.focus.isSimple())return!1;const e=S5(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function M5(n){if(!n.selection.range.focus.isSimple())return!1;const e=L5(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}D("find-block-position"),D("page-offset");function U5(n,t){const r=le(n,t).getBlockTextLength(t),i=ht(t,r,"normal"),o=em(n,n.selection.getAnchorPos(),i);if(!o)return!1;const{anchor:s,focus:l}=o;return n.selection.setSelection(s,l,{noScroll:!0}),n.selection.updateLastCaretRect(),!0}function O5(n,t){const e=ht(t,0,"normal"),r=em(n,n.selection.getAnchorPos(),e);if(!r)return!1;const{anchor:i,focus:o}=r;return n.selection.setSelection(i,o,{noScroll:!0}),n.selection.updateLastCaretRect(),!0}async function N5(n){const t=z0(n)*.9,e=gn(n.rootContainer);await ia(Math.min(e.scrollTop+t*2,e.scrollHeight),{elementToScroll:e})}async function P5(n){const t=z0(n)*.9,e=gn(n.rootContainer);await ia(Math.max(e.scrollTop-t,0),{elementToScroll:e})}function F5(n){return P5(n),!0}function K5(n){return N5(n),!0}const H_=D("table-scroll");class V5{constructor(t,e,r,i,o){m(this,"handleEvent",t=>{this.handler(this.editor,t,this.data)});this.editor=t,this.dom=e,this.name=r,this.handler=i,this.data=o,e.addEventListener(r,this.handleEvent)}destroy(){this.dom.removeEventListener(this.name,this.handleEvent)}}class j_{constructor(t){m(this,"handlers",new Map);this.editor=t}destroy(){Array.from(this.handlers.entries()).forEach(([t,e])=>{e.forEach(r=>r.destroy()),this.handlers.delete(t)})}addEventListener(t,e,r,i){const o=this.handlers.get(t);if(o){if(o.find(s=>s.handler===r&&s.name===e)){H_.warn(`event has already registered: ${e}`);return}o.push(new V5(this.editor,t,e,r,i))}else{const s=new V5(this.editor,t,e,r,i);this.handlers.set(t,[s])}}removeEventListener(t,e,r){if(!t){for(const[o,s]of Array.from(this.handlers.entries()))for(let l=s.length-1;l>=0;l--){const c=s[l];if(e)e===c.name&&r===c.handler&&s.splice(l,1);else if(r===c.handler){s.splice(l,1),c.destroy(),s.length===0&&this.handlers.delete(o);continue}}return}const i=this.handlers.get(t);if(i){const o=i.findIndex(s=>s.handler===r&&s.name===e);if(o!==-1){const s=i[o];i.splice(o,1),s.destroy(),i.length===0&&this.handlers.delete(t)}}}removeAllListeners(t,e){const r=this.handlers.get(t);if(r)if(e)for(let i=0;i<r.length;i++){const o=r[i];o.name===e&&(r.splice(i,1),o.destroy())}else r.forEach(i=>{i.destroy()}),this.handlers.delete(t)}}function $5(n){if(!n.selection.range.focus.isSimple())return!1;const e=gn(n.rootContainer);return e.scrollTop===0?O5(n,n.getFirstBlock()):(P5(n).then(()=>{const r=e.getBoundingClientRect(),i=r.left+r.width/2,o=r.top+z0(n)*.1,s=Pe(i,o);if(s){const l=et(s);l&&O5(n,l)}}),!0)}function H5(n){if(!n.selection.range.focus.isSimple())return!1;const e=gn(n.rootContainer);return e.scrollTop+e.clientHeight>=e.scrollHeight?U5(n,n.getLastBlock()):(N5(n).then(()=>{const r=z0(n)*.9,i=e.getBoundingClientRect(),o=i.left+i.width/2,s=i.top+r,l=Pe(o,s);if(l){const c=et(l);c&&U5(n,c)}}),!0)}const Xf=D("select-all");function j5(n,t){const e=Me(n),r=Ge(n);return t.start.offset===0&&t.start.blockId===ut(e)&&t.end.offset===Ct(t.getEditor(),r)&&t.end.blockId===ut(r)}function z_(n,t){const e=t.getEditor(),r=zr(e,n).getChildContainers(e,n),i=r[0],o=r[r.length-1],s=ut(n);return t.start.blockId===s&&t.start.childContainerId===pt(i)&&t.end.blockId===s&&t.end.childContainerId===pt(o)}function G_(n,t){p(Xf,t,"no parent block"),p(Xf,Pt(n,t),"not a complex block");const e=zr(n,t).getChildContainers(n,t),r=e[0],i=e[e.length-1];n.selection.setRange(Cn(n,{anchor:Ue(t,pt(r)),focus:Ue(t,pt(i))}))}function z5(n,t){const e=at(t);nm(n,e)}function pC(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&st(n,t)){const i=e.start,o=e.end,s=Ct(n,t);if(i.offset>0||o.offset<s)return n.selection.selectBlock(t,0,s),!1}return q(n.rootContainer,"select-all"),z5(n,Me(n.rootContainer)),!1}return p(Xf,!e.isSimple(),"invalid range type"),z_(t,e)?(z5(n,t),!1):(p(Xf,t,"no parent block"),p(Xf,Pt(n,t),"not a complex block"),G_(n,t),!0)}function nm(n,t){const e=ke(t),r=e[0],i=e[e.length-1],o=ht(r,0,"home"),s=ht(i,Ct(n,i),"end");n.selection.setSelection(o,s,{noScroll:!0})}function W_(n){gC(n),n.focus()}function q_(n){const t=[];return n.forEach(e=>{var r;((r=e.attributes)==null?void 0:r.box)===!0?(t.length>0&&t[t.length-1].length===0&&t.pop(),t.push([e]),t.push([])):t.length>0?t[t.length-1].push(e):t.push([e])}),t.length>0&&t[t.length-1].length===0&&t.pop(),t}function CC(n,t,e,r=!1){var c;if(!e)return[];const i=e.length;e=e.toLowerCase();const o=[];let s=0;const l=q_(t);for(const d of l){if(((c=d[0].attributes)==null?void 0:c.box)===!0){const E=d[0].attributes,A=n.editorBoxes.getBoxClass(E.type);(A==null?void 0:A.matchText)&&!r&&A.matchText(n,E,e)&&o.push({start:s,end:s+1}),s+=1;continue}const h=Re(d,{boxReplacement:" "}).toLowerCase();let C=h.indexOf(e,0);for(;C!==-1;)o.push({start:C+s,end:C+i+s}),C=h.indexOf(e,C+i);s+=h.length}return o}function G5(n,t,e,r,i){const o=CC(n,t,e,!0);let s=Et.default(t);return o.length===0||(o.reverse().forEach(l=>{s=P0(s,l.start,l.end,r)}),i&&(i.count=o.length)),s}const EC=D("selected-block-to-doc");function W5(n,t,e){!t.children||t.children.forEach(r=>{const i=n.getChildContainerData(r);i.forEach(o=>{W5(n,o,e)}),e.blocks[r]=Et.default(i)})}function rm(n,t){const e=le(n,t.block);if(e.selectionToDoc)return e.selectionToDoc(n,t);const r=Et.default(Qo(n,t.block));if(st(n,t.block)){const o=t.start,s=t.end;if(p(EC,r.text,"no block text"),o.offset===s.offset)return{blocks:{root:[{...r,text:[]}]},meta:{},comments:{}};const{middle:l}=ln(r.text,o.offset,s.offset-o.offset);return{blocks:{root:[{...r,text:l}]},meta:{},comments:{}}}if(Le(t.block))return{blocks:{root:[r]},meta:{},comments:{}};p(EC,Pt(n,t.block),"not complex block"),p(EC,r.children,"no children");const i={blocks:{root:[r]},meta:{},comments:{}};return W5(n,r,i),i}function AC(n,t){const e=ht(t,0,"normal"),r=ht(t,Ct(n,t),"end");return rm(n,{block:t,start:e,end:r})}const X_=D("block-to-doc");function q5(n,t){p(X_,t.length>0,"invalid params, no blocks");const e=t.map(r=>AC(n,r));return Ea(e)}function Qc(n){const e=n.selection.range.getSelectedBlocks().map(r=>rm(n,r));return Ea(e)}function X5(n,t){const e=n.getContainerById(t),o=ke(e).map(s=>({start:ht(s,0,"home"),end:ht(s,Ct(n,s),"end"),block:s})).map(s=>rm(n,s));return Ea(o)}const Y5=D("ensure-block-visible");function Y_(n,t){var e;for(;t;){const r=at(t);if(re(r)){n.emit("resize",n);return}const i=et(r);p(Y5,i,"no parent block");const o=le(n,i);o.isChildContainerVisible&&!((e=o.isChildContainerVisible)!=null&&e.call(o,n,i,r))&&(p(Y5,o.showChildContainer,"no showChildContainer method"),o.showChildContainer(n,i,r)),t=i}}const im=D("editor-selection");class Q_{constructor(t){m(this,"editor");m(this,"caret");m(this,"_range");m(this,"lastCaretRect");m(this,"handleBlockDelete",(t,e,r,i)=>{if(r||i.child)return;const o=this.range;if(PB(e,o)){im.debug("adjust selection because remote deleted current block");const s=FB(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),r=ut(e);this.caret=new f_(t);const i=ht(r,0,"normal");this._range=Cn(t,{anchor:i,focus:i}),this.lastCaretRect=null,this.editor.addListener("blockDeleted",this.handleBlockDelete),setTimeout(()=>{this.updateFocusedBlock(null)})}destroy(){this.caret.destroy()}get range(){return this._range}get focusedBlock(){return this.getFocusedBlock()}get startBlock(){return this.getStartBlock()}get endBlock(){return this.getEndBlock()}getFocusedBlock(){const t=this.range.focus;return this.editor.getBlockById(t.blockId)}getStartBlock(){const t=this.range.start;return this.editor.getBlockById(t.blockId)}getEndBlock(){const t=this.range.end;return this.editor.getBlockById(t.blockId)}selectBlock(t,e,r,i){const o=ht(t,e,"normal");let s;r&&(s=ht(t,r,"normal")),this.setSelection(o,s,i)}setSelection(t,e,r){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const i=this.editor.getBlockById(t.blockId);Y_(this.editor,i);const o=Cn(this.editor,{anchor:t,focus:e});if(this.range.isEqual(o))return this.range;const s=this._range;return this._range=o,this.selectionChanged(),this.updateFocusedBlock(s),Mt(this.editor.rootContainer,"select-all")&&(!o.isSimple()||!E_(this.editor,o))&&ct(this.editor.rootContainer,"select-all"),r!=null&&r.noScroll||this.scrollIntoView(),this.range}setRange(t,e){return this.setSelection(t.anchor,t.focus,e)}updateSelection(t,e){this.caret.update(),UB(this.editor),e!=null&&e.focusBlockChanged&&this.updateFocusedBlock(t)}getFocusedPos(){return this.range.focus}getAnchorPos(){return this.range.anchor}selectionChanging(t,e){return!0}selectionChanged(){this.caret.update(),UB(this.editor),this.editor.emit("selectionChanged",this.editor)}updateLastCaretRect(){const t=this.range.focus;if(!bi(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=tl(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){C_(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=Ct(this.editor,e)||p(im,!1,"invalid block position, out of range");else{const r=t.childContainerId;!!this.editor.getContainerById(r)||p(im,!1,"invalid complex block position, no container found")}}updateFocusedBlock(t){if(t&&this.range.start.blockId===t.start.blockId)return;let e;t&&t.start.blockId===t.end.blockId&&(e=this.editor.findBlockById(t.start.blockId));let r;(this.range.isCollapsed()||!this.range.isSimple()||this.range.start.blockId===this.range.end.blockId)&&(r=this.editor.getBlockById(this.range.start.blockId));let i=!1;e&&Mt(e,"focused")&&(ct(e,"focused"),i=!0),this.removeAllBlockFocusedClass(),r&&this.setBlockFocused(r)&&(i=!0),i&&this.editor.emit("focusBlockChanged",this.editor,r!=null?r:null,e!=null?e:null)}verify(){this.verifyPos(this._range.start),this.verifyPos(this._range.end)}to(t){const e=Qc(this.editor);return t==="text"?ol(this.editor,e):t==="markdown"?$B(this.editor,e):VB(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{ct(t,"focused"),ct(t,"child-focused")})}setBlockFocused(t){if(Mt(t,"focused"))return!1;q(t,"focused");let e=at(t);for(;pi(e);){const r=et(e);p(im,r,"parent block not found"),q(r,"child-focused"),e=at(r)}return!0}}function J_(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,Ct(n,e))}function Z_(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!st(n,e))return;let r=uC(n,"select"),i=fC(n,"select");if(!r||!i)return;const o=t.blockId;r.blockId!==o&&(r=ht(e,0,"home")),i.blockId!==o&&(i=ht(e,Ct(n,e),"end")),n.selection.setSelection(r,i)}class tM{constructor(t){m(this,"editor");m(this,"startPos",null);m(this,"lastCaretRect");m(this,"mouseDownEvent",null);m(this,"autoScroll",null);m(this,"handleMouseDown",(t,e)=>{var i;this.mouseDownEvent=t;const r=x1(this.editor,t.x,t.y);if(r){if(r instanceof Ji)return;if(!this.autoScroll&&e.autoScroll){const s=r.getSelectedBlocks(),l=gn(s[0].block);this.autoScroll=new b0({scrollElement:l,edge:{top:50,bottom:50}})}const o=this.editor.selection.range;if(t.shiftKey&&o.isSimple()){const s=o.anchor;this.editor.selection.setSelection(s,r.focus),this.startPos=r.start}else this.editor.selection.setSelection(r.anchor,r.focus),this.startPos=r.start;this.editor.selection.updateLastCaretRect(),e.autoScroll&&((i=this.autoScroll)==null||i.active())}});m(this,"handleMouseMove",t=>{if(!this.startPos||!this.mouseDownEvent||Math.abs(this.mouseDownEvent.x-t.x)<3&&Math.abs(this.mouseDownEvent.y-t.y)<3)return;const e=S0(this.editor,t.x,t.y);if(!e)return;const r=em(this.editor,this.startPos,e.end);if(!r)return;const{anchor:i,focus:o}=r;this.editor.selection.setSelection(i,o)});m(this,"handleMouseUp",t=>{var e;(e=this.autoScroll)==null||e.inactive(),this.startPos=null});this.editor=t,this.startPos=null,this.lastCaretRect=new DOMRect}isSelecting(){return this.startPos!==null}stopSelection(){this.startPos=null}handleDblClick(t){Z_(this.editor)}handleTripleClick(t){J_(this.editor)}}function eM(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function nM(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const Q5=D("delete-text");function J5(n,t,e,r){const i=r!=null?r:n.selection.range.start;i instanceof pn||p(Q5,!1,`invalid insert pos type: ${typeof i}`);const{blockId:o}=i,s=n.getBlockById(o);p(Q5,st(n,s),"block is not a text kind block");let{offset:l}=i;if(t==="backward"){if(l-e<0)return 0;if(!lr(s,l-e)){const c=il(s,l);e=l-c}}else if(t==="forward"&&l+e>Ct(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function Z5(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const rM=D("handle-backspace");function xC(n,t){if(!Be(n,t))return;const e=at(t);Xi(e)!==1&&n.deleteBlock(t)}function iM(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,r=n.getBlockById(e.blockId);if(st(n,r))if(e.offset===0){if(Z5(n,r))return;const i=Gr(r);if(i){if(!n.isBlockWritable(i))return;if(st(n,i))n.mergeTextBlock(i,r,{focus:!0});else if(Pt(n,i)){xC(n,r);const o=Fc(n,i);o?n.selection.selectBlock(o,Ct(n,o)):n.selection.selectBlock(i,0,Ct(n,i))}else xC(n,r),p(rM,Le(i),"prev block is not embed block"),n.selection.selectBlock(i,1)}else{const o=at(r);if(pi(o)){const s=m3(n,o,{visibleOnly:!0});if(s){if(!n.isBlockWritable(s))return;xC(n,r),n.selection.selectBlock(s,Ct(n,s))}}}}else J5(n,"backward",1,null),n.selection.updateLastCaretRect();else{const i=Rt(r),o=at(r);n.insertTextBlock("",pt(o),i),n.deleteBlock(r)}}function oM(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,r=n.getBlockById(e.blockId);if(st(n,r))if(e.offset===Ct(n,r)){const i=ae(r);if(i){if(!n.isBlockWritable(i))return;st(n,i)?n.mergeTextBlock(r,i,{focus:!0}):Be(n,r)?n.deleteBlock(r,Ie(n,i,0)):n.deleteBlock(i)}}else J5(n,"forward",1,null);else{const i=Rt(r),o=at(r);n.insertTextBlock("",pt(o),i),n.deleteBlock(r)}}function sM(n){const{range:t}=n.selection,{start:e,end:r}=t,i=n.getBlockById(e.blockId),o=n.getBlockById(r.blockId);if(i!==o||!Pt(n,i))return!1;if(bi(e))return!0;const s=Pc(n,i,e,r),l=Dn(n,i);return s.length===l.length}function lM(n,t){if(sM(n)){const s=n.getFocusedBlock(),l=Rt(s),c=pt(at(s));n.insertTextBlock("",c,l+1);return}const e=n.getFocusedBlock(),{start:r,end:i}=n.selection.range,o=r.blockId===i.blockId&&Le(e);if(!n.selection.range.isCollapsed()&&!o&&n.clearSelectedContents(),st(n,e)){if(Be(n,e)&&Z5(n,e))return;const s=n.selection.range.start,l=n.breakTextBlock(e,s.offset,{copyBlockAttributes:!0});s.offset!==0?n.selection.selectBlock(l,0):n.selection.scrollIntoView()}else{const s=n.insertTextBlock();n.selection.selectBlock(s,0)}}function aM(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:r}=e;if(!st(n,r))return!1;const i=e.end;return n.insertBoxToBlock(r,i.offset,{type:"br",id:it(),box:!0,created:Date.now()}),!0}function bC(n,t,e,r){if(e.type==="embed"){const l=e.embedData.src;if(l&&typeof l=="string")for(const c of l.split("|"))r.add(c);return}const i=e.text;i&&i.forEach(s=>{if(s.attributes&&s.attributes.src&&typeof s.attributes.src=="string")if(zo(s)){const l=n.editorBoxes.getBoxClass(s.attributes.type);if(l.getResources){const c=l.getResources(n,s.attributes);c?c.forEach(d=>{r.add(d)}):r.add(s.attributes.src)}else r.add(s.attributes.src)}else r.add(s.attributes.src)});const o=e.children;o&&o.forEach(s=>{t.blocks[s].forEach(c=>{bC(n,t,c,r)})})}function cM(n,t){const e=new Set;return t.blocks.root.forEach(i=>{const o=n.editorBlocks.getBlockClass(i.type);if(o.getResources){const s=o.getResources(n,i);s?s.forEach(l=>{e.add(l)}):bC(n,t,i,e)}else bC(n,t,i,e)}),Array.from(e)}function Yf(n,t){return me.isFirefox?`<!doctype html><html><head><meta charset="utf8" /></head><body><span data-editor-doc="${qi(JSON.stringify(t))}" id="ones-editor-doc">${_c}</span>${n}</body></html>`:`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${qi(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function Qf(n,t){var o,s,l;const e=(l=(s=(o=n.doc).getServerMeta)==null?void 0:s.call(o))!=null?l:{},r=cM(n,t),i={};r.forEach(c=>{const d=n.doc.buildResourceUrl(c,{withToken:!0});i[c]=d}),t.meta={...e,resources:i}}function uM(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let r=Qc(n);const i=e==null?void 0:e(n,t,r);if(i===!0)return;typeof i=="object"&&i!==null&&(r=i),Qf(n,r);const o=jf(n,r),s=ol(n,r),l=Yf(o,r);t.clipboardData.setData("text/html",l),t.clipboardData.setData("text/plain",s),t.clipboardData.setData("text/x-ones-editor-doc",JSON.stringify(r))}function om(n,t){Qf(n,t);const e=jf(n,t),r=Yf(e,t),i=ol(n,t),o=new Blob([r],{type:"text/html"});yf([{type:"text/plain",data:new Blob([i],{type:"text/plain"})},{type:"text/html",data:o}])}function fM(n,t){if(n.selection.range.isCollapsed())return;let e=Qc(n);const r=t==null?void 0:t(n,new ClipboardEvent("mock-event"),e);r!==!0&&(typeof r=="object"&&r!==null&&(e=r),om(n,e))}async function vC(n,t){if(!window.isSecureContext)throw new Error("Can't copy block in insecure context.");const e=AC(n,t);om(n,e)}const dM=D("input-handler-actions");function ty(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(lM(n),!0))}function ey(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(oM(n),!0))}function ny(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(iM(n),!0))}function ry(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(aM(n),!0))}function iy(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t,{toPlainText:!0})}).catch(t=>{dM.error(t)}),!0)}function oy(n){return n.selection.range.getSelectedBlocks().every(e=>{const r=e.block,i=at(r);if(re(i))return!1;const o=et(i);return o&&Ot(o)==="code"})}function sy(n,t){const e=n.selection.range.getSelectedBlocks(),r=at(e[0].block),i=et(r);return i?`\`\`\`${n.getBlockData(i).language}
28
28
  ${t}
29
29
  \`\`\`
30
30
  `:""}function BC(n){if(!window.isSecureContext||n.selection.range.isCollapsed())return!1;const t=Qc(n);Qf(n,t);const e=jf(n,t);Yf(e,t);let r="";if(oy(n)){const i=n.selection.range.getSelectedBlocks()[0],o=at(i.block);et(o)&&(r=sy(n,ol(n,t)))}else{const i=[];t.blocks.root.forEach((o,s)=>{i.push(W0(n,o,t,[{containerId:"root",blockIndex:s}]))}),i[i.length-1]=i[i.length-1].trimEnd(),r=i.join(`
31
- `)}return yf([{type:"text/plain",data:new Blob([r],{type:"text/plain"})}]),!0}const hM=Object.freeze(Object.defineProperty({__proto__:null,editorHandleEnter:ty,editorHandleDelete:ey,editorHandleBackspace:ny,editorHandleInsertBr:ry,editorHandlePastePlainText:iy,isSelectedCodeTextBlock:oy,getSelectedCodeBlockMarkdown:sy,editorHandleCopyMarkdown:BC},Symbol.toStringTag,{value:"Module"})),sm={ArrowDown:p5,ArrowUp:g5,ArrowLeft:h5,ArrowRight:m5,"Shift+ArrowDown":C5,"Shift+ArrowUp":x5,"Shift+ArrowLeft":E5,"Shift+ArrowRight":A5,"CtrlOrCmd+ArrowLeft":v5,"CtrlOrCmd+ArrowRight":B5,"CtrlOrCmd+Shift+ArrowLeft":y5,"CtrlOrCmd+Shift+ArrowRight":T5,"CtrlOrCmd+ArrowUp":k5,"CtrlOrCmd+ArrowDown":mC,"CtrlOrCmd+Shift+ArrowUp":R5,"CtrlOrCmd+Shift+ArrowDown":gC,"CtrlOrCmd+A":pC,Home:_5,End:M5,"Shift+Home":I5,"Shift+End":D5,PageUp:F5,PageDown:K5,"Shift+PageUp":$5,"Shift+PageDown":H5,"CtrlOrCmd+Z":eM,"CtrlOrCmd+Shift+Z":nM,Enter:ty,Delete:ey,Backspace:ny,"Shift+Enter":ry,"CtrlOrCmd+Shift+V":iy,"CtrlOrCmd+Shift+C":BC};function ly(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function ay(n,t,e){if(t.type==="embed"){const o=t.embedData,s=o.src;if(s&&typeof s=="string"){const l=e.get(s);if(l)o.src=l;else{let c="";s.split("|").forEach(h=>{const C=e.get(h);C&&(c+=c?`|${C}`:`${C}`)}),c&&(o.src=c)}}return}const r=t.text;r&&r.forEach(o=>{if(o.attributes&&o.attributes.src&&typeof o.attributes.src=="string"){const s=e.get(o.attributes.src);s&&(o.attributes.src=s)}});const i=t.children;i&&i.forEach(o=>{n.blocks[o].forEach(l=>{ay(n,l,e)})})}function cy(n,t,e){if(e.size===0)return;t.blocks.root.forEach(i=>{const o=n.editorBlocks.getBlockClass(i.type);o.replaceResources?o.replaceResources(i,e):ay(t,i,e)})}async function mM(n,t){let e=t.filter(s=>s.indexOf(":")===-1);const r=[];e.forEach(s=>{const l=s.split("|");r.push(...l)}),e=Array.from(new Set(r)),e=r;const i=await n.doc.addResources(e),o=new Map;if(e.length!==i.length)return o;for(let s=0;s<e.length;s++)o.set(e[s],i[s]);return o}function gM(n,t){var l,c,d,h;const r=t.meta.serverId;if(!r||typeof r!="string")return!1;const i=(c=(l=n.doc).getServerMeta)==null?void 0:c.call(l);if(!i)return!1;const o=/.*(?=\/)/;return((d=(i.serverId||"").match(o))==null?void 0:d[0])===((h=r.match(o))==null?void 0:h[0])}async function yC(n,t){const r=t.meta.resources;if(!r||Object.keys(r).length===0)return;let i=new Map;if(gM(n,t)){const s=Array.from(Object.keys(r));i=await mM(n,s),cy(n,t,i)}const o=new Map;Object.entries(r).forEach(([s,l])=>{i.get(s)===void 0&&s!==l&&o.set(s,l)}),o.size!==0&&cy(n,t,o)}async function pM(n,t,e){await yC(n,t),n.undoManager.runInGroup(()=>{const{start:r,end:i}=n.selection.range,o=n.getBlockById(r.blockId);if(r.blockId===i.blockId&&Le(o)){const s=at(o),l=n.getBlockIndex(o),[c]=n.insertDocAt(s,l+1,t,e);c&&n.selection.selectBlock(c,Ct(n,c))}else{n.clearSelectedContents();const{block:s,offset:l}=Gc(n);n.insertDoc(s,l,t,e)}})}const CM=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function EM(n){let t;for(const e of CM)if(t=n[e],t)break;return t||null}class AM{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"hookExecutionAttempt",(t,e,r)=>{for(let i=0;i<this.handlers.length;i++){const o=this.handlers[i];if(o.handleBeforeCopy){const s=o.handleBeforeCopy(this.editor,e,r);if(s===!0)return!0;if(typeof s=="object"&&s!=null)return s}}});m(this,"onPasteText",async(t,e)=>{const r=new DataTransfer;r.setData("text/plain",t);const i=await this.editor.dataConverter.fromData(this.editor,r,e);if(i){const o=[];this.pasteDocs(i,null,o)}});m(this,"onBlur",Ne.default(()=>{const t=this.editor.selection.range;if(!t.isCollapsed()){let e=null;if(ha(t.anchor)){const r=t.anchor.childContainerId,i=Ci(this.editor,r);e=h3(this.editor,i)}else e=this.editor.getBlockById(t.anchor.blockId);if(e){let r=t.start;t.isSimple()||(r=ht(e,0,"normal")),this.editor.selection.setSelection(r,void 0,{noScroll:!0})}}this.removeActiveForBlur()},200));m(this,"removeActiveForBlur",Ne.default(()=>{ct(this.editor.rootElement,"active")},200));this.editor=t}onInsertText(t,e){if(!st(this.editor,this.editor.getFocusedBlock()))return;const{containerId:r,blockIndex:i,offset:o}=Gc(this.editor);this.handleBeforeInsertText(r,i,o,e)||(this.defaultInsertText(this.editor,r,i,o,e),this.handleAfterInsertText(r,i,o,e),this.editor.selection.updateLastCaretRect())}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleChanged&&r.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleRemoteChanged&&r.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){if(!st(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:r,offset:i}=Gc(this.editor);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,r,i)}}onUpdateCompositionText(t,e,r){if(!st(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText(e,r),this.editor.selection.caret.update();const{containerId:i,blockIndex:o,offset:s}=Gc(this.editor);for(let l=0;l<this.handlers.length;l++){const c=this.handlers[l];c.handleUpdateCompositionText&&c.handleUpdateCompositionText(this.editor,i,o,s,r)}this.editor.selection.updateLastCaretRect()}onCopy(t){uM(this.editor,t,this.hookExecutionAttempt)}onCopyWithoutEvent(){fM(this.editor,this.hookExecutionAttempt)}onCut(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeCut&&i.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const r=this.editor.selection.focusedBlock;Le(r)&&this.editor.deleteBlock(r)}else J0(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;const e=this.editor.dataConverter.fromData(this.editor,t.clipboardData),r=Array.from(t.clipboardData.files);e.then(async i=>{i&&this.pasteDocs(i,t,r)})}onFocus(){q(this.editor.rootElement,"active"),this.onBlur.cancel(),this.removeActiveForBlur.cancel()}addHandler(t){this.handlers.push(t),this.handlers=this.handlers.sort((e,r)=>{var s,l;const i=(s=e.order)!=null?s:1;return((l=r.order)!=null?l:1)-i})}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,r,i))return!0}return!1}handleAfterInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,r,i))return!0}return!1}handleBeforeKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,r,i,o){J1(this.editor,o)}defaultHandleKeydown(t,e){return ly(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePasteDoc&&await i.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map,boxIdMap:new Map};await pM(this.editor,t,e);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPasteDoc&&await i.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e,r){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforePaste&&await s.handleBeforePaste(this.editor,e,t,r))return}const i=EM(t);if(!!i){await this.pasteDoc(i);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterPaste&&await s.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}forEach(t){this.handlers.forEach(t)}}function xM(n,t,e){const r=Js(t,e);return r.remove(),r}D("copy-dom-attributes");const uy=["onabort","onanimationcancel","onanimationend","onanimationiteration","onanimationstart","onauxclick","onblur","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","ongotpointercapture","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onlostpointercapture","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onpause","onplay","onplaying","onpointercancel","onpointerdown","onpointerenter","onpointerleave","onpointermove","onpointerout","onpointerover","onpointerup","onprogress","onratechange","onreset","onresize","onscroll","onsecuritypolicyviolation","onseeked","onseeking","onselect","onselectionchange","onselectstart","onslotchange","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","ontransitioncancel","ontransitionend","ontransitionrun","ontransitionstart","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel"];function bM(n,t){for(let l=0;l<uy.length;l++){const c=uy[l];t[c]=n[c]}const e=n.attributes,r=t.attributes,i=[],o=[];for(let l=0;l<e.length;l++){const c=e[l],d=r.getNamedItem(c.name);d?d.value!==c.value&&(d.value=c.value,o.push(c)):i.push(c)}const s=[];for(let l=0;l<r.length;l++){const c=r[l];e.getNamedItem(c.name)||s.push(c)}i.forEach(l=>{t.setAttribute(l.name,l.value)}),o.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function fy(n){const t=Array.from(n.childNodes).filter(e=>!_v(e));return t.forEach(e=>{e.remove()}),t}function dy(n,t,e){var d;const r=n.getContainerById(t),i=Js(r,e),o=el(i),s=n.doc.getBlockData(t,e),l=le(n,i);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,i,s))n.editorBlockRenders.updateBlock(n,o,i,s);else{const h=n.editorBlocks.createBlock(o,r,s),C=fy(h);fy(i),C.forEach(A=>{i.appendChild(A)});const E=y0(h);if(E){const A=y0(i);A&&A.remove(),i.appendChild(E)}bM(h,i)}zv(n,i,s),n.blockHooks.forEach(h=>{var C;(C=h.update)==null||C.call(h,n,o,r,i,s)}),setTimeout(()=>{n.selection.updateSelection(null,{focusBlockChanged:!0})})}const vM=D("transform-selection");function hy(n,t,e,r){const{range:i}=n.selection,{anchor:o,focus:s}=i;if(o.blockId!==t&&s.blockId!==t)return i;p(vM,o.isSimple()&&s.isSimple(),"invalid text pos type");let l=o;if(o.blockId===t){const d=Hn.transformCursor(o.offset,e,r);l=ht(t,d,"normal")}let c=s;if(s.blockId===t){const d=Hn.transformCursor(s.offset,e,r);c=ht(t,d,"normal")}return Cn(n,{anchor:l,focus:c})}const BM=D("handle-block-text-changed");function yM(n,t,e,r,i){const o=n.getContainerById(t),s=Js(o,e),l=n.doc.getBlockData(t,e);if(p(BM,l.text,"no block text"),Sv(n,s).setBlockText(n,s,l.text),!i){const c=hy(n,l.id,r,i);n.selection.setRange(c,{noScroll:!0})}}function TM(n,t){const e=Et.default(n);return t.delete.forEach(i=>{delete e[i]}),{...e,...t.insert}}function my(n,t,e,r){const i=le(n,t);i.handleDeleteBlock&&i.handleDeleteBlock(n,t,e,r),n.emit("blockDeleted",n,t,e,r)}function kM(n,t,e,r){const i=n.getBlockByIndex(t,e);i.querySelectorAll('[data-type="editor-block"]').forEach(o=>{my(n,o,r,{child:!0})}),my(n,i,r,{child:!1})}const Bi=D("editor-doc");class RM extends Lc{constructor(e,r,i){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=r,this.externalDoc.registerCallback(this),this.registerLocalEvents(i)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var r,i;return(i=(r=this.externalDoc).getVersionHelper)==null?void 0:i.call(r)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}findContainerBlocks(e){return this.externalDoc.findContainerBlocks(e)}getBlockData(e,r){return this.externalDoc.getBlockData(e,r)}verifyBlockWritable(e,r){const i=this.editor.getBlockByIndex(e,r);p(Bi,this.editor.isBlockWritable(i),`block is not writable, ${e}, ${r}`)}localUpdateBlockText(e,r,i,o){p(Bi,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const s=this.getBlockData(e,r),l=s.text;p(Bi,l,`no text, ${e}, ${r}`);const c=hy(this.editor,s.id,i,!0),d=Hn.apply(l,i);this.localEvents.forEach(C=>C.onBeforeUpdateBlockText(e,s.id,l,d,c.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,r,i);return this.editor.selection.setRange(c,o),h}localUpdateBlockData(e,r,i,o,s){p(Bi,!this.editor.readonly,"editor is readonly");const l=this.editor.getBlockByIndex(e,r);if(!this.editor.isBlockWritable(l)){const C=Array.from(i.delete).filter(A=>A!=="comments"),E=Object.keys(i.insert).filter(A=>A!=="comments");(C.length>0||E.length>0)&&p(Bi,!1,`block is not writable, comment supported only, ${JSON.stringify(i)}}`)}const c=Et.default(this.getBlockData(e,r)),d=Et.default(TM(c,i));this.localEvents.forEach(C=>C.onBeforeUpdateBlockData(e,c.id,c,d,o));const h=this.externalDoc.localUpdateBlockData(e,r,i,o);return this.editor.selection.setRange(nl(this.editor,o),s),h}localInsertBlock(e,r,i,o,s){p(Bi,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(c=>c.onBeforeInsertBlock(e,r,i,o));const l=this.externalDoc.localInsertBlock(e,r,i,o);return s!=null&&s.noFocus||this.editor.selection.setRange(nl(this.editor,o),s),l}localDeleteBlock(e,r,i){p(Bi,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const o=Et.default(this.getBlockData(e,r));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,r,o,i));const s=this.externalDoc.localDeleteBlock(e,r,i);return this.editor.selection.setRange(nl(this.editor,i)),s}localDeleteChildContainers(e){return p(Bi,!this.editor.readonly,"editor is readonly"),e.forEach(r=>{const i=Et.default(this.getContainerBlocks(r));this.localEvents.forEach(o=>o.onBeforeDeleteChildContainer(r,i))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainers(e){p(Bi,!this.editor.readonly,"editor is readonly");const r=Et.default(e);r.forEach(i=>{this.localEvents.forEach(o=>o.onBeforeInsertChildContainer(i.containerId,i.blocks))}),this.externalDoc.localInsertChildContainers(r)}onRequestReload(e){Bi.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(i=>{var o;return(o=i.onRequestReload)==null?void 0:o.call(i,e)});const r=!1;this.editor.emit("docChanged",this.editor,r)}onUpdateBlockText(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,r,i,o)}),yM(this.editor,e,r,i,o),this.editor.emit("docChanged",this.editor,o)}onUpdateBlockData(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,o)}),dy(this.editor,e,r),this.editor.emit("docChanged",this.editor,o)}onInsertBlock(e,r,i,o){this.callbacks.forEach(l=>{var c;return(c=l.onInsertBlock)==null?void 0:c.call(l,e,r,i,o)});const s=this.editor.getContainerById(e);HI(this.editor,s,r,i),this.editor.emit("docChanged",this.editor,o)}onDeleteBlock(e,r,i){kM(this.editor,e,r,i),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,i)});const o=this.editor.getContainerById(e);xM(this.editor,o,r),this.editor.emit("docChanged",this.editor,i)}onInsertChildContainer(e,r,i){this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,e,r,i)})}onDeleteChildContainer(e,r){this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,e)})}onStatusChanged(e){this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)})}onError(e){this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}uploadResource(e,r){return this.externalDoc.uploadResource(e,r)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,r){return this.externalDoc.buildResourceUrl(e,r)}request(e,r){return this.externalDoc.request(e,r)}broadcastMessage(e){return this.externalDoc.broadcastMessage(e)}getUser(){return this.externalDoc.getUser()}getRemoteUsers(){return this.externalDoc.getRemoteUsers()}triggerReAuth(e=!1){var r,i;(i=(r=this.externalDoc).triggerReAuth)==null||i.call(r,e)}destroy(){this.externalDoc.destroy(),this.clearCallbacks()}getServerMeta(){var e,r,i;return(i=(r=(e=this.externalDoc).getServerMeta)==null?void 0:r.call(e))!=null?i:{}}reset(e){Bi.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function gy(n,t){if(n.length===0){n.push(t);return}const e=n[n.length-1];if(!e.combinable(t)){n.push(t);return}e.combine(t)}const lm=D("undo-action");class Jc{constructor(t,e,r){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=r}undo(t){return!1}redo(t){return!1}combinable(t){return p(lm,t,"no other action"),!1}combine(t){p(lm,!1,"no other")}setAfterRange(t){this.afterRange&&lm.warn("after range has already set"),this.afterRange=t}hasDocContainerId(t,e){return!!t.doc.findContainerBlocks(e)}findDocBlockById(t,e){const r=t.doc.findContainerBlocks(this.containerId);if(!!r)return r.find(i=>i.id===e)}checkBlockData(t,e){if(Array.isArray(e.children)){const r=t.doc.toJSON();for(let i=0;i<e.children.length;i++){const o=e.children[i];if(!r.blocks[o])return lm.warn(`container (${o}) not found, deleted by others?`),!1}}return!0}}const am=D("block-action");class py extends Jc{constructor(e,r,i,o,s){super(e,r,s);m(this,"blockData");m(this,"blockIndex");this.blockData=Et.default(o),this.blockIndex=i}deleteBlock(e,r){if(!this.hasDocContainerId(e,this.containerId))return am.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const o=e.findBlockById(this.blockData.id);return o?(Y0(e,o,nl(e,r)),!0):!1}insertBlock(e,r){return this.hasDocContainerId(e,this.containerId)?this.checkBlockData(e,this.blockData)?e.findBlockByIndex(this.containerId,Math.max(0,this.blockIndex-1))?e.findBlockById(this.blockData.id)?(am.warn(`block (${this.blockData.id}) already exists, inserted by others?`),!1):(qc(e,this.containerId,this.blockIndex,Et.default(this.blockData),r),!0):(am.warn(`block (${Math.max(0,this.blockIndex-1)}) not found, deleted by others?`),!1):!1:(am.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}}D("insert-block-action");class wM extends py{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class SM extends py{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class LM extends Jc{constructor(e){super(e,pt(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){gy(this.actions,e),this.afterRange=e.afterRange}undo(e){let r=!1;for(const i of this.actions.concat().reverse())if(i.undo(e))r=!0;else break;return r}redo(e){let r=!1;for(const i of this.actions)if(i.redo(e))r=!0;else break;return r}setAfterRange(e){this.afterRange=e;const r=this.actions[this.actions.length-1];!r||r instanceof Jc&&(r.afterRange||r.setAfterRange(e))}}const cl=D("update-block-data-action");class cm extends Jc{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=i,p(cl,this.blockId===o.id,"invalid block id"),p(cl,this.blockId===s.id,"invalid block id"),this.beforeBlockData=Et.default(o),this.afterBlockData=Et.default(s),p(cl,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){if(!e.findBlockById(this.blockId))return cl.warn(`block (${this.blockId}) not found, deleted by others?`),!1;const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(cl,i,"no container"),tm(e,r,cm.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){if(!e.findBlockById(this.blockId))return cl.warn(`block (${this.blockId}) not found, deleted by others?`),!1;p(cl,e,"no editor");const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(cl,i,"no container"),tm(e,r,cm.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const r=Et.default(e);return delete r.id,delete r.type,r}}const Aa=D("update-block-text-action");class Jf extends Jc{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=i,this.beforeRichTextData=Et.default(o),this.afterRichTextData=Et.default(s),this.type=Jf.calType(o,s)}static calType(e,r){p(Aa,e,"no old data"),p(Aa,r,"no new data");const o=Hn.diff(e,r),s=new Set;let l=!1;const c=h=>ev(h)?`cjk_${h}`:Zb(h)?"number":g0(h)?"space":tv(h)?"letter":"unknown";let d=!1;return o.forEach(h=>{h.insert?h.insert===" "?s.add("insert_letter"):typeof h.insert=="string"&&h.insert.startsWith(" ")&&h.insert.length>1?(l=!0,d=!0,s.add(`insert_${c(h.insert.substr(1))}`)):s.add(`insert_${c(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!this.hasDocContainerId(e,this.containerId))return Aa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findDocBlockById(e,this.blockId))return Aa.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Z0(e,i,this.beforeRichTextData),!0):!1}redo(e){if(!this.hasDocContainerId(e,this.containerId))return Aa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findDocBlockById(e,this.blockId))return Aa.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Z0(e,i,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof Jf)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const r=e.beforeRange,i=r.anchor;if(!i.isSimple())return!1;const o=this.afterRange;if(!o)return!1;const s=o.anchor;return!(!s.isSimple()||s.blockId!==r.anchor.blockId||s.offset!==i.offset)}combine(e){p(Aa,e instanceof Jf,"invalid action type");const r=e;this.afterRichTextData=r.afterRichTextData,this.afterRange=e.afterRange}}const Cy=D("child-container-action");class Ey extends Jc{constructor(t,e,r){super(t,e,t.selection.range.toDocRange()),this.blocks=r}deleteChildContainer(t){return this.hasDocContainerId(t,this.containerId)?(t.doc.localDeleteChildContainers([this.containerId]),!0):(Cy.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}insertChildContainer(t){return this.hasDocContainerId(t,this.containerId)?(Cy.warn(`container (${this.containerId}) already exists`),!1):(t.doc.localInsertChildContainers([{containerId:this.containerId,blocks:Et.default(this.blocks)}]),!0)}}class IM extends Ey{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class DM extends Ey{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Qn=D("undo");class _M{constructor(t){m(this,"editor");m(this,"actions",[]);m(this,"undoCursor");m(this,"currentGroup",null);m(this,"groupCounter",0);m(this,"undoRedoing",!1);m(this,"handleSelectionChange",t=>{if(this.currentGroup){this.currentGroup.setAfterRange(t.selection.range.toDocRange());return}const e=this.actions[this.actions.length-1];!e||e.afterRange||e.setAfterRange(t.selection.range.toDocRange())});this.editor=t,this.undoCursor=-1,this.editor.addListener("selectionChanged",this.handleSelectionChange)}reset(){this.actions=[],this.undoCursor=-1}prepareSaveUndoState(){this.undoCursor!==-1&&(this.actions.splice(this.undoCursor),this.undoCursor=-1)}addAction(t){this.currentGroup?this.currentGroup.addAction(t):(gy(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(p(Qn,!this.currentGroup,"current group already exists"),this.currentGroup=new LM(this.editor),this.groupCounter=1):(p(Qn,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){p(Qn,this.currentGroup,"current group not exists"),p(Qn,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Qn.warn("empty undo group, skip it"):(this.actions.push(this.currentGroup),this.editor.input.handleChanged(this.currentGroup)),this.currentGroup=null)}hasGroup(){return this.groupCounter>0}runInGroup(t){this.beginGroup();try{const e=t();return setTimeout(()=>this.editor.selection.caret.update()),e}catch(e){throw Qn.error(`failed to run action: ${e.message}`),e}finally{this.endGroup()}}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=Ct(this.editor,e)||p(Qn,!1,"invalid block position, out of range");else{const r=t.childContainerId;!!this.editor.getContainerById(r)||p(Qn,!1,"invalid complex block position, no container found")}}checkRange(){const{start:t,end:e}=this.editor.selection.range;try{this.verifyPos(t),this.verifyPos(e)}catch(r){Qn.error(`undo: failed to restore caret pos: ${r.message}`);const i=this.editor.getFirstBlock();this.editor.selection.setRange(Ie(this.editor,i,0),{noScroll:!0})}}undo(){this.undoCursor===-1&&(this.undoCursor=this.actions.length);try{for(this.undoRedoing=!0;this.undoCursor>0;){this.undoCursor-=1;const t=this.actions[this.undoCursor];if(t.undo(this.editor)){try{this.editor.selection.setRange(nl(this.editor,t.beforeRange))}catch(e){Qn.error(`undo: failed to restore caret pos: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}catch(t){return Qn.error(`failed to undo: ${t.message}`),!1}finally{this.undoRedoing=!1,this.checkRange()}}redo(){this.undoCursor===-1&&(this.undoCursor=this.actions.length);try{for(this.undoRedoing=!0;this.undoCursor<this.actions.length;){const t=this.actions[this.undoCursor];if(this.undoCursor+=1,t.redo(this.editor)){try{const e=t.afterRange;e?this.editor.selection.setRange(nl(this.editor,e)):Qn.warn("no after range")}catch(e){Qn.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1,this.checkRange()}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,r,i,o){this.undoRedoing||(this.prepareSaveUndoState(),Hn.diff(r,i).length!==0&&this.addAction(new Jf(this.editor,t,e,r,i,o)))}onBeforeUpdateBlockData(t,e,r,i,o){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new cm(this.editor,t,e,r,i,o);this.addAction(s)}onBeforeInsertBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),p(Qn,e>=0,"invalid block index"),p(Qn,r,"no block data"),this.addAction(new wM(this.editor,t,e,r,i)))}onBeforeDeleteBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new SM(this.editor,t,e,r,i)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new IM(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new DM(this.editor,t,e)))}}class MM{async fromData(t,e){const r=e.getData("text/x-ones-editor-doc");if(r)return{"text/x-ones-editor-doc":JSON.parse(r)}}}class UM{constructor(){m(this,"converters",[]);m(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new MM)}prepareData(t){const e=new DataTransfer;for(let r=0;r<this.converterTypes.length;r++)e.setData(this.converterTypes[r],t.getData(this.converterTypes[r]));return e}async fromData(t,e,r){let i={};const o=this.prepareData(e);for(const s of this.converters){const l=await s.fromData(t,o,r);l&&(i={...i,...l})}return i}addConverter(t){this.converters.push(t)}}function OM(n){n.editorBlocks.registerBlockClass(ar),n.editorBlocks.registerBlockClass(d3),n.editorBoxes.registerBoxClass(yB),n.editorBoxes.registerBoxClass(TB),n.editorBoxes.registerBoxClass(wB),n.editorBoxes.registerBoxClass(SB),n.editorInsertions.registerInsertionClass(LB),n.editorBlockRenders.registerRender(new Dv)}function NM(n,t){OM(n),t!=null&&t.blocks&&t.blocks.forEach(e=>n.editorBlocks.registerBlockClass(e)),t!=null&&t.boxes&&t.boxes.forEach(e=>n.editorBoxes.registerBoxClass(e)),t!=null&&t.embeds&&t.embeds.forEach(e=>n.editorEmbeds.registerEmbedClass(e)),t!=null&&t.insertions&&t.insertions.forEach(e=>n.editorInsertions.registerInsertionClass(e)),t!=null&&t.decorators&&t.decorators.forEach(e=>n.editorDecorators.registerDecorator(e)),t!=null&&t.dataConverters&&t.dataConverters.forEach(e=>n.dataConverter.addConverter(e)),t!=null&&t.commandProviders&&t.commandProviders.forEach(e=>n.editorCommandProviders.registerCommandProvider(e)),t!=null&&t.textRenders&&t.textRenders.forEach(e=>n.editorBlockRenders.registerRender(e))}const um=D("range-commands");function Ay(n,t){n.forEach(e=>{e.source=t,e.children&&Ay(e.children,t)})}function xy(n,t){n.forEach(e=>{e.group=t,e.children&&xy(e.children,t)})}function by(n,t,e,r){const i=ut(t);p(um,i===e.start.blockId,"invalid start range"),p(um,i===e.end.blockId,"invalid end range");const o=n.editorCommandProviders.getCommandProviders();let s=[];if(o.forEach(l=>{const c=l.getAvailableCommands(n,t,e);Ay(c,r),xy(c,l.id),s.push(...c)}),o.forEach(l=>{if(l.filterCommands){const c=l.filterCommands(n,t,e,s);c&&(s=c)}}),Pt(n,t)){if(!ha(e.start))return s;p(um,!e.start.isSimple(),"invalid start pos"),p(um,!e.end.isSimple(),"invalid end pos");const l=e.start.childContainerId,c=Ci(n,l),h=ke(c)[0];if(h){const C=Ct(n,h),E=Cn(n,{anchor:ht(h,0,"home"),focus:ht(h,C,"end")}),A=by(n,h,E,r);s.push(...A)}}return s}function vy(n,t){const e=n.getEditor(),r=n.getSelectedBlocks(),i=[],o=n.isReverse()?r[0]:r[r.length-1],s=Cn(e,{anchor:o.start,focus:o.end});return by(e,o.block,s,t).forEach(c=>{i.push(c)}),i}function By(n,t,e,r,i,o){var h;const s=n.editorCommandProviders.getCommandProviders();for(let C=0;C<s.length;C++){const E=s[C];if(E.beforeExecuteCommand&&E.beforeExecuteCommand(n,t,e,r,i))return!1}const l=n.editorCommandProviders.getCommandProvider(r.group),c={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,r,i,{}))return o[ut(t)]=c,!0;let d=!1;return Pt(n,t)&&Pc(n,t,e.start,e.end).forEach(E=>{ke(E).forEach(v=>{const w=Ct(n,v),S=Cn(n,{anchor:ht(v,0,"home"),focus:ht(v,w,"end")});By(n,v,S,r,i,o)&&(d=!0)})}),s.forEach(C=>{C.afterExecuteCommand&&C.afterExecuteCommand(n,t,e,r,i,o)}),d}function yy(n,t,e){const r=n.getEditor(),i={},o=r.editorCommandProviders.getCommandProvider(t.group);return o.executeRangeCommand&&o.executeRangeCommand(r,n,t,e,i)||(n.getSelectedBlocks().forEach(l=>{const c=Cn(r,{anchor:l.start,focus:l.end});By(r,l.block,c,t,e,i)}),r.focus()),i}const PM=D("command-providers");class Ty{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(r=>r.id===t);return p(PM,e,`no command provider, id=${t}`),e}getCommands(t,e){return vy(t,e)}executeCommand(t,e,r){return this.editor.emit("beforeExecCommand",this.editor,e,{source:e.source}),this.editor.undoManager.runInGroup(()=>yy(t,e,r))}getEmptyBlockTextAttributes(t,e){let r={};if(this.providers.forEach(i=>{var s;const o=(s=i.getEmptyBlockTextAttributes)==null?void 0:s.call(i,t,e);o&&(r={...r,...o})}),Object.keys(r).length!==0)return r}}function FM(n,t){const e=at(t),r=pt(e),i=Rt(t);dy(n,r,i)}const ky=D("update-block-text");function KM(n,t,e){const r=n.getBoxById(t.id),i=et(r);p(ky,i,"no parent block"),p(ky,st(n,i),"not a text block");const o=n.getBlockText(i),s=pB(o,"id",t.id,t);JB(n,i,s,e)}function VM(n,t){for(const e of n.blockHooks)if(e.writable){const r=e.writable(n,t);if(typeof r=="boolean")return r}return!0}function $M(n){if(n.readonly)return!1;const t=Zi(n);return!!n.isBlockWritable(t.map(e=>e.block))}class HM{constructor(t){this.editor=t}getKey(t){return`${this.editor.id}-${t}`}getItem(t){return window.localStorage.getItem(this.getKey(t))}setItem(t,e){if(!e){this.removeItem(t);return}window.localStorage.setItem(this.getKey(t),e)}removeItem(t){window.localStorage.removeItem(this.getKey(t))}}class jM{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const r=this.shortcuts;for(const i of r){const o=Object.entries(i);for(const[s,l]of o)if(Wi(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const Jo=D("editor");class zM extends Ve.TypedEmitter{constructor(e,r,i){var o,s,l,c,d,h,C,E,A;super();m(this,"parent");m(this,"rootElement");m(this,"contentElement");m(this,"rootContainerObject");m(this,"rootContainer");m(this,"input");m(this,"selection");m(this,"selectionHandler");m(this,"doc");m(this,"id");m(this,"clientId");m(this,"compositingText","");m(this,"undoManager");m(this,"shortcuts",new jM);m(this,"dataConverter",new UM);m(this,"editorBlocks",new a3(this));m(this,"editorBoxes",new RB(this));m(this,"editorInsertions",new DB(this));m(this,"editorEmbeds",new u3(this));m(this,"editorDecorators",new _B(this));m(this,"editorCommandProviders",new Ty(this));m(this,"editorBlockRenders",new _I(this));m(this,"blockHooks",[]);m(this,"domEvents",new j_(this));m(this,"customs",new Map);m(this,"options");m(this,"version","");m(this,"inputHandlers",new AM(this));m(this,"settingsProvider");m(this,"_readonly",!1);m(this,"getColor",e=>{const r=this.options.colors;return r.length===0?"#FF1A75":r[e%r.length]});Jo.debug("create editor"),this.setMaxListeners(100),this.options={colors:(o=i==null?void 0:i.colors)!=null?o:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"],componentsOptions:(l=(s=i==null?void 0:i.components)==null?void 0:s.options)!=null?l:{},scrollContainer:i==null?void 0:i.scrollContainer,enableComments:(c=i==null?void 0:i.enableComments)!=null?c:!0,enableContextMenu:(d=i==null?void 0:i.enableContextMenu)!=null?d:!0},this.settingsProvider=(h=i==null?void 0:i.settingsProvider)!=null?h:new HM(this),NM(this,i==null?void 0:i.components),this.blockHooks.push(...(E=(C=i==null?void 0:i.components)==null?void 0:C.blockHooks)!=null?E:[]),this.id=(A=i==null?void 0:i.id)!=null?A:it(),this.clientId=it(),this.undoManager=new _M(this),this.doc=new RM(this,r,this.undoManager),this.parent=e,this.rootElement=B("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=B("div",["editor-content"],this.rootElement),this.rootContainerObject=o3(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new c_(this,this.inputHandlers),this.selection=new Q_(this),this.selectionHandler=new tM(this),i!=null&&i.shortcuts&&this.shortcuts.shortcuts.push(...i.shortcuts),me.isMobile&&q(this.rootElement,"mobile"),me.isSafari&&q(this.rootElement,"safari"),this._readonly&&q(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?q(this.rootElement,"readonly"):ct(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:gn(this.rootContainer)}addCustom(e,r){const i=this.customs.get(e);if(i)return i;const o=r(this);return this.customs.set(e,o),o}getCustom(e){const r=this.customs.get(e);return p(Jo,r,`${e} does not exists`),r}replaceCustom(e,r){const i=this.customs.get(e);return i&&i.destroy(),this.customs.set(e,r),r}findCustom(e){return this.customs.get(e)}findCustomByType(e){const r=this.customs.values();for(const i of r)if(i instanceof e)return i;return null}destroyCustom(e){const r=this.customs.get(e);r&&(this.customs.delete(e),r.destroy())}getComponentOptions(e){return this.options.componentsOptions[e]}registerLocalEvents(e){this.doc.registerLocalEvents(e)}reload(){this.rootContainerObject.reload(),this.emit("load",this,!0)}createBlock(e,r,i){return this.editorBlocks.createBlock(e,r,i)}createBox(e,r){return this.editorBoxes.createBox(e,r)}createInsertion(e,r){return this.editorInsertions.createInsertion(e,r)}destroy(){Jo.debug("destroy editor"),this.emit("destroy",this),this.input.destroy(),this.rootContainerObject.destroy(),this.rootElement.remove(),this.doc.destroy(),this.customs.forEach(e=>e.destroy()),this.customs.clear(),this.selection.destroy(),this.domEvents.destroy(),this.removeAllListeners(),this.inputHandlers.destroy()}focus(){this.input.focus()}focusToBlock(e,r){iC(this,e,r)}isWritable(){return $M(this)}isBlockWritable(e){return VM(this,e)}getChildContainerData(e){const r=this.doc.getContainerBlocks(e);return(!r||!Array.isArray(r))&&(p(Jo,r,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),p(Jo,Array.isArray(r),`container data is not an array: ${JSON.stringify(r)}`)),r}createChildContainer(e,r,i){return s3(this,e,r,i)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(Jo,ca(r),"not an valid block element"),r!=null?r:null}findBoxById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(Jo,T0(r),"not an valid box element"),r!=null?r:null}getBlockById(e){const r=this.findBlockById(e);return p(Jo,r,`no block, id=${e}`),r}getBoxById(e){const r=this.findBoxById(e);return p(Jo,r,`no box, id=${e}`),r}getBlockByIndex(e,r){const i=this.getContainerById(e);return Js(i,r)}findBlockByIndex(e,r){const i=this.getContainerById(e);return Rv(i,r)}getBlockIndex(e){if(typeof e=="string"){const r=this.getBlockById(e);return Rt(r)}return Rt(e)}getContainerById(e){return Ci(this,e)}getParentContainer(e){return at(e)}reloadBlock(e){FM(this,e)}contains(e){const r=e instanceof Element?e:e.parentElement;return r?r.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,r,i,o,s){const l={blockId:i.id,offset:0},c={anchor:l,focus:l};return qc(this,e,r,i,o!=null?o:c,s)}insertEmbed(e,r,i,o,s,l){const c={id:it(),type:"embed",embedType:i,embedData:o,...l};return this.insertBlock(e,r,c,s)}deleteBlock(e,r){nC(this,e,r)}mergeTextBlock(e,r){return XB(this,e,r)}breakTextBlock(e,r,i){return Xc(this,e,r,i).newBlock}getTextPosition(){return Gc(this)}getBlockString(e,r){const i=this.getBlockText(e);return Re(i,r)}getBlockData(e){return Qo(this,e)}getBoxData(e){return vB(this,e)}getBlockText(e){return Yn(this,e)}setBlockText(e,r){JB(this,e,r)}deleteTextFromBlock(e,r,i,o){return tC(this,e,r,i,o)}insertTextToBlock(e,r,i,o){return HB(this,e,r,i,o)}insertBoxToBlock(e,r,i){return jB(this,e,r,i)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,r,i,o){e5(this,e,r,i,o)}insertDocAt(e,r,i,o){return lC(this,e,r,i,o)}deleteChildContainers(e){qB(this,e)}replaceBlockText(e,r){return Z0(this,e,r)}updateBlockData(e,r,i,o){const s={...this.getBlockData(e),...r},{id:l,type:c,...d}=s;return tm(this,e,d,(i!=null?i:this.selection.range).toDocRange(),o)}updateEmbedData(e,r,i){return ZB(this,e,r,i)}updateBoxData(e,r){KM(this,e,r)}getSelectedText(){const e=Qc(this);return ol(this,e)}clearSelectedContents(){J0(this)}insertTextBlock(e,r,i,o,s){const l=no(e!=null?e:"",s);return WB(this,l,r,i,o==null?void 0:o.newRange,o==null?void 0:o.insertBlockOptions)}updateCompositionText(e,r){if(e&&!r&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!r){Z1(this);return}r?(this.compositingText="",Ef()?e||Z1(this):J1(this,e)):(this.compositingText=e,zB(this))}}function Zf(n,t,e){return new zM(n,t,e)}function GM(n){const t=(r,i)=>{const o=r.findIndex(l=>l.id===i.id);if(o===-1){r.push(i);return}const s=r[o];if(s.value!==i.value){r.splice(o,1);return}if(!!s.states){if(!i.states){s.states=[];return}s.states=Lp.default(s.states,i.states)}},e=[];return n.forEach(r=>{r.forEach(i=>{t(e,i)})}),e}const WM=["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"];class td extends Ve.TypedEmitter{constructor(e){super();m(this,"users",new Map);m(this,"cursors",new Map);m(this,"addingUser",!1);m(this,"colors");this.colors=e&&e.length>0?e:WM}setCursor(e){this.addUser(e.user);const r=this.cursors.get(e.user.userId);if(r&&Cf.default(r,e))return;this.cursors.set(e.user.userId,e);const i=new Set([e.range.anchor.blockId,e.range.focus.blockId]),o=new Set(i);r&&new Set([r.range.anchor.blockId,r.range.focus.blockId]).forEach(l=>{i.has(l)||o.add(l)}),this.emit("remote-carets-change",[...o])}addUsers(e){this.addingUser=!0,e.forEach(r=>this.addUser(r)),this.addingUser=!1,this.emit("change",Array.from(this.users.values()))}addUser(e){this.users.set(e.userId,e),this.addingUser||this.emit("change",Array.from(this.users.values()))}findUser(e){var r;return(r=this.users.get(e))!=null?r:null}removeUser(e){this.users.delete(e),this.emit("change",Array.from(this.users.values()));const r=this.cursors.get(e);if(r){const i=new Set(new Set([r==null?void 0:r.range.anchor.blockId,r==null?void 0:r.range.focus.blockId]));this.cursors.delete(e),this.emit("remote-carets-change",[...i])}}updateUsers(e){this.users.forEach(r=>{e.find(i=>i.userId===r.userId)||this.removeUser(r.userId)}),this.users.clear(),this.addingUser=!0;try{e.forEach(r=>{this.addUser(r)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const r=new Map;return Array.from(this.cursors.values()).filter(i=>i.range.anchor.blockId===e&&K0(i.range)).forEach(i=>{const o=i.range.focus.offset;let s=r.get(o);s||(s=[],r.set(o,s)),s.push(i)}),r}getCursors(e){return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e||r.range.focus.blockId===e)}onUpdateBlockText(e,r,i){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(K0(l.range)){const{anchor:c,focus:d}=l.range;c.blockId===e.id&&(c.offset=Hn.transformCursor(c.offset,r,i)),d.blockId===e.id&&(d.offset=Hn.transformCursor(d.offset,r,i))}})}getFixedUserColor(e,r){let i=0;Array.from(e).forEach(s=>{i+=s.charCodeAt(0)});const o=i%this.colors.length;return this.colors[o]}destroy(){this.removeAllListeners()}}const _n=D("local-doc");class TC extends Lc{constructor(e,r){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[no("")]}},this.serviceUrl=(r==null?void 0:r.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return Et.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}findContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,r){const i=this.getContainerBlocks(e);p(_n,i,`no container data: ${e}`);const o=i[r];return p(_n,o,`no block data: ${r}`),o}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(_n,o.text,"no text for data");const s=Hn.apply(o.text,i);return o.text=s,p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var c;return(c=l.onUpdateBlockText)==null?void 0:c.call(l,e,r,i,!0)}),s}localUpdateBlockData(e,r,i){const o=this.getBlockData(e,r);return i.delete.forEach(s=>delete o[s]),Object.entries(i.insert).forEach(([s,l])=>{o[s]=l}),p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,!0)}),o}localInsertBlock(e,r,i){const o=this.getContainerBlocks(e);return p(_n,o,`no container data: ${e}`),p(_n,r>=0&&r<=o.length,`invalid block index: ${r}, ${o.length}`),o.splice(r,0,i),p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,r,i,!0)}),i}localDeleteBlock(e,r){const i=this.getContainerBlocks(e);p(_n,i,`no container data: ${e}`),p(_n,r>=0&&r<=i.length,`invalid block index: ${r}, ${i.length}`);const o=i[r];return i.splice(r,1),p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,!0)}),o}localInsertChildContainers(e){e.forEach(({containerId:r,blocks:i})=>{this.doc.blocks[r]=i,p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,r,i,!0)})})}localDeleteChildContainers(e){_n.debug(`delete child containers: ${e}`),e.forEach(r=>{p(_n,this.doc.blocks[r],`no child container: ${r}`),delete this.doc.blocks[r]}),e.forEach(r=>{p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,r,!0)})})}uploadResource(e,r){p(_n,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,r){p(_n,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new td}setDoc(e){this.doc=Et.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,"change doc")})}destroy(){this.clearCallbacks()}}class qM{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function kC(n,t,e){n.addCustom(t,()=>{var o;const r=(o=e())!=null?o:void 0;return new qM(r)})}const Ry=D("find-block");function wy(n,t){const e=Gr(t);if(!e){if(qr(t))return null;const r=ua(t);return p(Ry,r,"no parent block"),wy(n,r)}return Pt(n,e)?Fc(n,e,{visibleOnly:!0}):e}function Sy(n,t){const e=Wr(t);if(!e){if(qr(t))return null;const r=ua(t);return p(Ry,r,"no parent block"),Sy(n,r)}return Pt(n,e)?E1(n,e,{visibleOnly:!0}):e}const XM=D("remote-cursor");class YM{constructor(){m(this,"remoteUsers",new td)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const r=e;this.handleUpdateUsers(r.users)}else e.type==="caret"?this.handleUpdateCaret(e):XM.debug(`unknown remote message received: ${t}`)}handleUpdateUsers(t){this.remoteUsers.updateUsers(t)}handleUpdateCaret(t){const e=this.remoteUsers.findUser(t.userId);!e||this.remoteUsers.setCursor({oneseditor:"cursor",user:e,range:t.range,time:Date.now()})}destroy(){this.remoteUsers.destroy()}}function QM(n){const{blocks:t,meta:e,comments:r,...i}=n;return{rootBlocks:t,meta:e,comments:r,childBlocks:i}}function JM(n){const{blocks:t,meta:e,comments:r}=n,{root:i,...o}=t;return{blocks:i,meta:e,comments:r,...o}}function Zo(n){const{childBlocks:t,meta:e,comments:r,rootBlocks:i}=QM(Et.default(n));return{blocks:{root:i,...t},meta:e,comments:r}}function ts(n){return n==="root"?"blocks":n}function Zc(n){return n==="blocks"?"root":n}const ZM={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new Vn.default(n)},apply(n,t){const e=new Vn.default(n),r=new Vn.default(t);return e.compose(r).ops},compose(n,t){const e=new Vn.default(n),r=new Vn.default(t);return e.compose(r).ops},diff(n,t){const e=new Vn.default(n),r=new Vn.default(t);return e.diff(r).ops},transform(n,t,e){const r=new Vn.default(n);return new Vn.default(t).transform(r,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const r=new Vn.default(t),i=this.transformCursor(n.index,r,e),o=this.transformCursor(n.index+n.length,r,e);return{...n,index:i,length:o-i}}}};var ul={},RC=Sp.default.EventEmitter;ul.EventEmitter=RC,ul.mixin=tU;function tU(n){for(var t in RC.prototype)n.prototype[t]=RC.prototype[t]}var Ly=["info","warn","error"];function Iy(){var n={};Ly.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var eU=Iy;Iy.prototype.setMethods=function(n){n=n||{};var t=this;Ly.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var nU=eU,rU=new nU,Dy=rU;function xa(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,xa):this.stack=new Error().stack}xa.prototype=Object.create(Error.prototype),xa.prototype.constructor=xa,xa.prototype.name="ShareDBError",xa.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_FIXUP_IS_ONLY_VALID_ON_APPLY:"ERR_FIXUP_IS_ONLY_VALID_ON_APPLY",ERR_CANNOT_FIXUP_DELETION:"ERR_CANNOT_FIXUP_DELETION",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_CHANNEL_MISSING:"ERR_QUERY_CHANNEL_MISSING",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE:"ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var fm=xa,ed={},_y=iU;function iU(n,t,e,r){var i=function(s,l,c,d){t(c,s,l,"left"),t(d,l,s,"right")},o=n.transformX=function(s,l){e(s),e(l);for(var c=[],d=0;d<l.length;d++){for(var h=l[d],C=[],E=0;E<s.length;){var A=[];if(i(s[E],h,C,A),E++,A.length===1)h=A[0];else if(A.length===0){for(var v=E;v<s.length;v++)r(C,s[v]);h=null;break}else{for(var w=o(s.slice(E),A),S=0;S<w[0].length;S++)r(C,w[0][S]);for(var U=0;U<w[1].length;U++)r(c,w[1][U]);h=null;break}}h!=null&&r(c,h),s=C}return[s,c]};n.transform=function(s,l,c){if(!(c==="left"||c==="right"))throw new Error("type must be 'left' or 'right'");return l.length===0?s:s.length===1&&l.length===1?t([],s[0],l[0],c):c==="left"?o(s,l)[0]:o(l,s)[1]}}var My={exports:{}},fl=My.exports={name:"text0",uri:"http://sharejs.org/types/textv0",create:function(n){if(n!=null&&typeof n!="string")throw new Error("Initial data must be a string");return n||""}},wC=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},SC=function(n){if(typeof n.p!="number")throw new Error("component missing position field");if(typeof n.i=="string"==(typeof n.d=="string"))throw new Error("component needs an i or d field");if(n.p<0)throw new Error("position cannot be negative")},dm=function(n){for(var t=0;t<n.length;t++)SC(n[t])};fl.apply=function(n,t){var e;dm(t);for(var r=0;r<t.length;r++){var i=t[r];if(i.i!=null)n=wC(n,i.p,i.i);else{if(e=n.slice(i.p,i.p+i.d.length),i.d!==e)throw new Error("Delete component '"+i.d+"' does not match deleted text '"+e+"'");n=n.slice(0,i.p)+n.slice(i.p+i.d.length)}}return n};var es=fl._append=function(n,t){if(!(t.i===""||t.d===""))if(n.length===0)n.push(t);else{var e=n[n.length-1];e.i!=null&&t.i!=null&&e.p<=t.p&&t.p<=e.p+e.i.length?n[n.length-1]={i:wC(e.i,t.p-e.p,t.i),p:e.p}:e.d!=null&&t.d!=null&&t.p<=e.p&&e.p<=t.p+t.d.length?n[n.length-1]={d:wC(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};fl.compose=function(n,t){dm(n),dm(t);for(var e=n.slice(),r=0;r<t.length;r++)es(e,t[r]);return e},fl.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=0),es(t,r)}return t};var LC=function(n,t,e){return t.i!=null?t.p<n||t.p===n&&e?n+t.i.length:n:n<=t.p?n:n<=t.p+t.d.length?t.p:n-t.d.length};fl.transformCursor=function(n,t,e){for(var r=e==="right",i=0;i<t.length;i++)n=LC(n,t[i],r);return n};var oU=fl._tc=function(n,t,e,r){if(SC(t),SC(e),t.i!=null)es(n,{i:t.i,p:LC(t.p,e,r==="right")});else if(e.i!=null){var i=t.d;t.p<e.p&&(es(n,{d:i.slice(0,e.p-t.p),p:t.p}),i=i.slice(e.p-t.p)),i!==""&&es(n,{d:i,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)es(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)es(n,t);else{var o={d:"",p:t.p};t.p<e.p&&(o.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(o.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),c=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(c!==d)throw new Error("Delete ops delete different text in the same region of the document");o.d!==""&&(o.p=LC(o.p,e),es(n,o))}return n},sU=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};fl.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=sU(n[t]);return n},_y(fl,oU,dm,es);var hm=function(n){return Object.prototype.toString.call(n)=="[object Array]"},lU=function(n){return!!n&&n.constructor===Object},yi=function(n){return JSON.parse(JSON.stringify(n))},Ft={name:"json0",uri:"http://sharejs.org/types/JSONv0"},ns={};Ft.registerSubtype=function(n){ns[n.name]=n},Ft.create=function(n){return n===void 0?null:yi(n)},Ft.invertComponent=function(n){var t={p:n.p};return n.t&&ns[n.t]&&(t.t=n.t,t.o=ns[n.t].invert(n.o)),n.si!==void 0&&(t.sd=n.si),n.sd!==void 0&&(t.si=n.sd),n.oi!==void 0&&(t.od=n.oi),n.od!==void 0&&(t.oi=n.od),n.li!==void 0&&(t.ld=n.li),n.ld!==void 0&&(t.li=n.ld),n.na!==void 0&&(t.na=-n.na),n.lm!==void 0&&(t.lm=n.p[n.p.length-1],t.p=n.p.slice(0,n.p.length-1).concat([n.lm])),t},Ft.invert=function(n){for(var t=n.slice().reverse(),e=[],r=0;r<t.length;r++)e.push(Ft.invertComponent(t[r]));return e},Ft.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!hm(n[t].p))throw new Error("Missing path")},Ft.checkList=function(n){if(!hm(n))throw new Error("Referenced element not a list")},Ft.checkObj=function(n){if(!lU(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function nd(n){n.t="text0";var t={p:n.p.pop()};n.si!=null&&(t.i=n.si),n.sd!=null&&(t.d=n.sd),n.o=[t]}function rd(n){n.p.push(n.o[0].p),n.o[0].i!=null&&(n.si=n.o[0].i),n.o[0].d!=null&&(n.sd=n.o[0].d),delete n.t,delete n.o}Ft.apply=function(n,t){Ft.checkValidOp(t),t=yi(t);for(var e={data:n},r=0;r<t.length;r++){var i=t[r];(i.si!=null||i.sd!=null)&&nd(i);for(var o=null,s=e,l="data",c=0;c<i.p.length;c++){var d=i.p[c];if(o=s,s=s[l],l=d,o==null)throw new Error("Path invalid")}if(i.t&&i.o!==void 0&&ns[i.t])s[l]=ns[i.t].apply(s[l],i.o);else if(i.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=i.na}else if(i.li!==void 0&&i.ld!==void 0)Ft.checkList(s),s[l]=i.li;else if(i.li!==void 0)Ft.checkList(s),s.splice(l,0,i.li);else if(i.ld!==void 0)Ft.checkList(s),s.splice(l,1);else if(i.lm!==void 0){if(Ft.checkList(s),i.lm!=l){var h=s[l];s.splice(l,1),s.splice(i.lm,0,h)}}else if(i.oi!==void 0)Ft.checkObj(s),s[l]=i.oi;else if(i.od!==void 0)Ft.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},Ft.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},Ft.incrementalApply=function(n,t,e){for(var r=0;r<t.length;r++){var i=[t[r]];n=Ft.apply(n,i),e(i,n)}return n};var aU=Ft.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var r=0;r<n.length;r++)if(n[r]!==t[r]&&(!e||r!==n.length-1))return!1;return!0};Ft.append=function(n,t){if(t=yi(t),n.length===0){n.push(t);return}var e=n[n.length-1];if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(nd(t),nd(e)),aU(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&ns[t.t]){if(e.o=ns[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var r=t.p,i=0;i<e.o.length-1;i++)t.o=[e.o.pop()],t.p=r.slice(),rd(t),n.push(t);rd(e)}}else e.na!=null&&t.na!=null?n[n.length-1]={p:e.p,na:e.na+t.na}:e.li!==void 0&&t.li===void 0&&t.ld===e.li?e.ld!==void 0?delete e.li:n.pop():e.od!==void 0&&e.oi===void 0&&t.oi!==void 0&&t.od===void 0?e.oi=t.oi:e.oi!==void 0&&t.od!==void 0?t.oi!==void 0?e.oi=t.oi:e.od!==void 0?delete e.oi:n.pop():t.lm!==void 0&&t.p[t.p.length-1]===t.lm||n.push(t);else(t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(rd(t),rd(e)),n.push(t)},Ft.compose=function(n,t){Ft.checkValidOp(n),Ft.checkValidOp(t);for(var e=yi(n),r=0;r<t.length;r++)Ft.append(e,t[r]);return e},Ft.normalize=function(n){var t=[];n=hm(n)?n:[n];for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=[]),Ft.append(t,r)}return t},Ft.commonLengthForOps=function(n,t){var e=n.p.length,r=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&r++,e===0)return-1;if(r===0)return null;e--,r--;for(var i=0;i<e;i++){var o=n.p[i];if(i>=r||o!==t.p[i])return null}return e},Ft.canOpAffectPath=function(n,t){return Ft.commonLengthForOps({p:t},n)!=null},Ft.transformComponent=function(n,t,e,r){t=yi(t);var i=Ft.commonLengthForOps(e,t),o=Ft.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,o!=null&&l>s&&t.p[o]==e.p[o]){if(t.ld!==void 0){var c=yi(e);c.p=c.p.slice(s),t.ld=Ft.apply(yi(t.ld),[c])}else if(t.od!==void 0){var c=yi(e);c.p=c.p.slice(s),t.od=Ft.apply(yi(t.od),[c])}}if(i!=null){var d=s==l,c=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(nd(t),c=yi(e),nd(c)),c.t&&ns[c.t]){if(t.t&&t.t===c.t){var h=ns[t.t].transform(t.o,c.o,r);if(t.si!=null||t.sd!=null)for(var C=t.p,E=0;E<h.length;E++)t.o=[h[E]],t.p=C.slice(),rd(t),Ft.append(n,t);else(!hm(h)||h.length>0)&&(t.o=h,Ft.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[i]===t.p[i])if(d){if(t.ld!==void 0)if(t.li!==void 0&&r==="left")t.ld=yi(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&d&&t.p[i]===e.p[i]?r==="right"&&t.p[i]++:e.p[i]<=t.p[i]&&t.p[i]++,t.lm!==void 0&&d&&e.p[i]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[i]===t.p[i])return n;var C=e.p[i],A=t.p[i],v=t.lm;(C<v||C===v&&A<v)&&t.lm--}if(e.p[i]<t.p[i])t.p[i]--;else if(e.p[i]===t.p[i]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var A=t.p[i],v=t.lm,w=e.p[i],S=e.lm;if(w!==S)if(A===w)if(r==="left")t.p[i]=S,A===v&&(t.lm=S);else return n;else A>w&&t.p[i]--,A>S?t.p[i]++:A===S&&w>S&&(t.p[i]++,A===v&&t.lm++),(v>w||v===w&&v>A)&&t.lm--,v>S?t.lm++:v===S&&(S>w&&v>A||S<w&&v<A?r==="right"&&t.lm++:v>A?t.lm++:v===w&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var A=e.p[i],v=e.lm;C=t.p[i],C>A&&t.p[i]--,C>v&&t.p[i]++}else{var A=e.p[i],v=e.lm;C=t.p[i],C===A?t.p[i]=v:(C>A&&t.p[i]--,(C>v||C===v&&A>v)&&t.p[i]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[i]===e.p[i])if(t.oi!==void 0&&d){if(r==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[i]===e.p[i])if(r==="left")Ft.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[i]==e.p[i]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return Ft.append(n,t),n},_y(Ft,Ft.transformComponent,Ft.checkValidOp,Ft.append);var cU=My.exports;Ft.registerSubtype(cU);var uU=Ft,fU={type:uU};(function(n){n.defaultType=fU.type,n.map={},n.register=function(t){t.name&&(n.map[t.name]=t),t.uri&&(n.map[t.uri]=t)},n.register(n.defaultType)})(ed);var Qr={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var r in e)return!0;return!1},n.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e},n.isValidVersion=function(e){return e===null?!0:n.isInteger(e)&&e>=0},n.isValidTimestamp=function(e){return n.isValidVersion(e)},n.MAX_SAFE_INTEGER=9007199254740991,n.dig=function(){for(var e=arguments[0],r=1;r<arguments.length;r++){var i=arguments[r];e=e[i]||(r===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],r=arguments[arguments.length-1],i=1;i<arguments.length-1;i++){var o=arguments[i];e=e[o]||(e[o]=i===arguments.length-2?r():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],r=[e],i=1;i<arguments.length-1;i++){var o=arguments[i];if(!e.hasOwnProperty(o))break;e=e[o],r.push(e)}for(var i=r.length-1;i>=0;i--){var s=r[i],o=arguments[i+1],l=s[o];(i===r.length-1||!n.hasKeys(l))&&delete s[o]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,r){var i=!1;return e.forEach(function(o){o&&(o(r),i=!0)}),i},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];setTimeout(function(){e.apply(null,r)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(Qr);var Uy=Array.isArray,Oy=Object.keys,dU=Object.prototype.hasOwnProperty,hU=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=Uy(t),i=Uy(e),o,s,l;if(r&&i){if(s=t.length,s!=e.length)return!1;for(o=s;o--!==0;)if(!n(t[o],e[o]))return!1;return!0}if(r!=i)return!1;var c=t instanceof Date,d=e instanceof Date;if(c!=d)return!1;if(c&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,C=e instanceof RegExp;if(h!=C)return!1;if(h&&C)return t.toString()==e.toString();var E=Oy(t);if(s=E.length,s!==Oy(e).length)return!1;for(o=s;o--!==0;)if(!dU.call(e,E[o]))return!1;for(o=s;o--!==0;)if(l=E[o],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},dl={};dl.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",fixup:"fixup",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var Ny=ul,mU=Dy,wr=fm,mm=ed,Ti=Qr,gU=Ti.clone,pU=hU,IC=dl.ACTIONS,cr=wr.CODES,CU=Xt;function Xt(n,t,e){Ny.EventEmitter.call(this),this.connection=n,this.collection=t,this.id=e,this.version=null,this.type=null,this.data=void 0,this.inflightFetch=[],this.inflightSubscribe=null,this.pendingFetch=[],this.pendingSubscribe=[],this.subscribed=!1,this.wantSubscribe=!1,this._wantsDestroy=!1,this.inflightOp=null,this.pendingOps=[],this.type=null,this.applyStack=null,this.preventCompose=!1,this.submitSource=!1,this.paused=!1,this._dataStateVersion=0}Ny.mixin(Xt),Xt.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this;t.whenNothingPending(function(){t.wantSubscribe?t.unsubscribe(function(e){if(e)return n?n(e):t.emit("error",e);t.connection._destroyDoc(t),n&&n()}):(t.connection._destroyDoc(t),n&&n())})},Xt.prototype._setType=function(n){if(typeof n=="string"&&(n=mm.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new wr(cr.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Xt.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Xt.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new wr(cr.ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION,"Missing version in ingested snapshot. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}if(this.type||this.hasWritePending()){if(this.version==null){if(this.hasWritePending())return t&&this.once("no write pending",t);var e=new wr(cr.ERR_DOC_MISSING_VERSION,"Cannot ingest snapshot in doc with null version. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}return n.v>this.version?this.fetch(t):t&&t()}if(this.version>n.v)return t&&t();this.version=n.v;var r=n.type===void 0?mm.defaultType:n.type;this._setType(r),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},Xt.prototype.whenNothingPending=function(n){var t=this;Ti.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Xt.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Xt.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Xt.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Xt.prototype._emitResponseError=function(n,t){if(n&&n.code===cr.ERR_SNAPSHOT_READ_SILENT_REJECTION){this.wantSubscribe=!1,t&&t(),this._emitNothingPending();return}if(t){t(n),this._emitNothingPending();return}this._emitNothingPending(),this.emit("error",n)},Xt.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var r=this.inflightFetch.shift();if(r&&e.push(r),e.length&&(r=function(i){Ti.callEach(e,i)}),n)return this._emitResponseError(n,r);this.ingestSnapshot(t,r),this._emitNothingPending()},Xt.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var r=this.pendingFetch;this.pendingFetch=[],e.callback&&r.push(e.callback);var i;if(r.length&&(i=function(o){Ti.callEach(r,o)}),n)return this._emitResponseError(n,i);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,i):i&&i(),this._emitNothingPending(),this._flushSubscribe()},Xt.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===cr.ERR_OP_SUBMIT_REJECTED&&(n=null),this._rollback(n)):this.emit("error",n);if(this.inflightOp&&t.src===this.inflightOp.src&&t.seq===this.inflightOp.seq){this._opAcknowledged(t);return}if(this.version==null||t.v>this.version){this.fetch();return}if(!(t.v<this.version)){if(this.inflightOp){var e=id(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var r=0;r<this.pendingOps.length;r++){var e=id(this.pendingOps[r],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}}},Xt.prototype._onConnectionStateChanged=function(){this.connection.canSend?(this.flush(),this._resubscribe()):(this.inflightOp&&(this.pendingOps.unshift(this.inflightOp),this.inflightOp=null),this.subscribed=!1,this.inflightSubscribe&&(this.inflightSubscribe.wantSubscribe?(this.pendingSubscribe.unshift(this.inflightSubscribe),this.inflightSubscribe=null):this._handleSubscribe()),this.inflightFetch.length&&(this.pendingFetch=this.pendingFetch.concat(this.inflightFetch),this.inflightFetch.length=0))},Xt.prototype._resubscribe=function(){if(!this.pendingSubscribe.length&&this.wantSubscribe)return this.subscribe();var n=this.pendingSubscribe.some(function(t){return t.wantSubscribe});!n&&this.pendingFetch.length&&this.fetch(),this._flushSubscribe()},Xt.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);EU(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Xt.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Xt.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Xt.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,r=e&&e.wantSubscribe===n;if(r){e.callback=AU([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Xt.prototype._flushSubscribe=function(){if(!(this.inflightSubscribe||!this.pendingSubscribe.length)){if(this.connection.canSend){this.inflightSubscribe=this.pendingSubscribe.shift(),this.wantSubscribe=this.inflightSubscribe.wantSubscribe,this.wantSubscribe?this.connection.sendSubscribe(this):(this.subscribed=!1,this.connection.sendUnsubscribe(this));return}if(!this.pendingSubscribe[0].wantSubscribe){this.inflightSubscribe=this.pendingSubscribe.shift();var n=this;Ti.nextTick(function(){n._handleSubscribe()})}}};function EU(n,t,e){if(t){var r=n.pop();n.push(function(i){r&&r(i),e&&e(i)})}else n.push(e)}function AU(n){return n=n.filter(Ti.truthy),n.length?function(t){Ti.callEach(n,t)}:null}Xt.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function xU(n){delete n.op,delete n.create,delete n.del}function id(n,t){if(n.del)return xU(t);if(t.del)return new wr(cr.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new wr(cr.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new wr(cr.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var r=n.type.transform(n.op,t.op,"left"),i=n.type.transform(t.op,n.op,"right");n.op=r,t.op=i}}}Xt.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new wr(cr.ERR_DOC_DOES_NOT_EXIST,"Cannot apply op to uncreated document. "+this.collection+"."+this.id);if(this.emit("before op batch",n.op,t),!t&&this.type===mm.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,r=0;r<n.op.length;r++){var i=n.op[r],o={op:[i]};this.emit("before op",o.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=id(this.applyStack[s],o);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,o.op)),this.emit("op",o.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var c=this.data;this._setType(null),this.emit("del",c,t);return}},Xt.prototype._sendOp=function(){if(!!this.connection.canSend){var n=this.connection.id;this.inflightOp||(this.inflightOp=this.pendingOps.shift());var t=this.inflightOp;if(!t){var e=new wr(cr.ERR_INFLIGHT_OP_MISSING,"No op to send on call to _sendOp");return this.emit("error",e)}if(t.sentAt=Date.now(),t.retries=t.retries==null?0:t.retries+1,t.seq==null){if(this.connection.seq>=Ti.MAX_SAFE_INTEGER)return this.emit("error",new wr(cr.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW,"Connection seq has exceeded the max safe integer, maybe from being open for too long"));t.seq=this.connection.seq++}this.connection.sendOp(this,t),t.src==null&&(t.src=n)}},Xt.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var r=new wr(cr.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(r):this.emit("error",r)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(o){return this._hardRollback(o)}var i=this;Ti.nextTick(function(){i.flush()})},Xt.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var r=this._tryCompose(n);if(r){r.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},Xt.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var r=this.pendingOps.splice(e),e=0;e<r.length;e++){var t=r[e],i=this._tryCompose(t);i?i.callbacks=i.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},Xt.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!pU(n.source,t.source))){if(t.create&&"op"in n)return t.create.data=this.type.apply(t.create.data,n.op),t;if("op"in t&&"op"in n&&this.type.compose)return t.op=this.type.compose(t.op,n.op),t}}},Xt.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var r={op:n},i=t&&t.source;this._submit(r,i,e)},Xt.prototype.create=function(n,t,e,r){if(typeof t=="function"?(r=t,e=null,t=null):typeof e=="function"&&(r=e,e=null),t||(t=mm.defaultType.uri),this.type){var i=new wr(cr.ERR_DOC_ALREADY_CREATED,"Document already exists");return r?r(i):this.emit("error",i)}var o={create:{type:t,data:n}},s=e&&e.source;this._submit(o,s,r)},Xt.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new wr(cr.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var r={del:!0},i=n&&n.source;this._submit(r,i,t)},Xt.prototype.pause=function(){this.paused=!0},Xt.prototype.resume=function(){this.paused=!1,this.flush()},Xt.prototype.toSnapshot=function(){return{v:this.version,data:gU(this.data),type:this.type.uri}},Xt.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return mU.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();if(n[IC.fixup])for(var t=0;t<n[IC.fixup].length;t++){for(var e=n[IC.fixup][t],r=0;r<this.pendingOps.length;r++){var i=id(this.pendingOps[t],e);if(i)return this._hardRollback(i)}try{this._otApply(e,!1)}catch(o){return this._hardRollback(o)}}this.version++,this._clearInflightOp()},Xt.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var r=id(this.pendingOps[e],t);if(r)return this._hardRollback(r)}try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}this._clearInflightOp(n);return}this._hardRollback(n)},Xt.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var r=!!t.length,i=0;i<t.length;i++)r=Ti.callEach(t[i].callbacks,n)&&r;if(n&&!r)return e.emit("error",n)})},Xt.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=Ti.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var Py=ul,Fy=dl.ACTIONS,bU=Qr,vU=ur;function ur(n,t,e,r,i,o,s){Py.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=r,this.query=i,this.results=null,o&&o.results&&(this.results=o.results,delete o.results),this.extra=void 0,this.options=o,this.callback=s,this.ready=!1,this.sent=!1}Py.mixin(ur),ur.prototype.hasPending=function(){return!this.ready},ur.prototype.send=function(){if(!!this.connection.canSend){var n={a:this.action,id:this.id,c:this.collection,q:this.query};if(this.options&&(n.o=this.options),this.results){for(var t=[],e=0;e<this.results.length;e++){var r=this.results[e];t.push([r.id,r.version])}n.r=t}this.connection.send(n),this.sent=!0}},ur.prototype.destroy=function(n){this.connection.canSend&&this.action===Fy.querySubscribe&&this.connection.send({a:Fy.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&bU.nextTick(n)},ur.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},ur.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},ur.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},ur.prototype._handleResponse=function(n,t,e){var r=this.callback;if(this.callback=null,n)return this._finishResponse(n,r);if(!t)return this._finishResponse(null,r);var i=this,o=1,s=function(h){if(h)return i._finishResponse(h,r);--o||i._finishResponse(null,r)};if(Array.isArray(t))o+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){o++;var c=t[l],d=this.connection.get(c.c||this.collection,l);d.ingestSnapshot(c,s)}s()},ur.prototype._ingestSnapshots=function(n,t){for(var e=[],r=0;r<n.length;r++){var i=n[r],o=this.connection.get(i.c||this.collection,i.d);o.ingestSnapshot(i,t),e.push(o)}return e},ur.prototype._finishResponse=function(n,t){if(this.emit("ready"),this.ready=!0,n)return this.connection._destroyQuery(this),t?t(n):this.emit("error",n);t&&t(null,this.results,this.extra)},ur.prototype._handleError=function(n){this.emit("error",n)},ur.prototype._handleDiff=function(n){for(var t=0;t<n.length;t++){var e=n[t];e.type==="insert"&&(e.values=this._ingestSnapshots(e.values))}for(var t=0;t<n.length;t++){var e=n[t];switch(e.type){case"insert":var r=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(r)),this.emit("insert",r,e.index);break;case"remove":var o=e.howMany||1,i=this.results.splice(e.index,o);this.emit("remove",i,e.index);break;case"move":var o=e.howMany||1,s=this.results.splice(e.from,o);Array.prototype.splice.apply(this.results,[e.to,0].concat(s)),this.emit("move",s,e.from,e.to);break}}this.emit("changed",this.results)},ur.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var Ky=ul,BU=dl.ACTIONS,yU=Qr,Vy=io;function io(n,t){if(Ky.EventEmitter.call(this),!t||typeof t!="string")throw new Error("LocalPresence presenceId must be a string");this.presence=n,this.presenceId=t,this.connection=n.connection,this.presenceVersion=0,this.value=null,this._pendingMessages=[],this._callbacksByPresenceVersion={}}Ky.mixin(io),io.prototype.submit=function(n,t){this.value=n,this.send(t)},io.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},io.prototype.destroy=function(n){var t=this;this.submit(null,function(e){if(e)return t._callbackOrEmit(e,n);delete t.presence.localPresences[t.presenceId],n&&n()})},io.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},io.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},io.prototype._message=function(){return{a:BU.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},io.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},io.prototype._callbackOrEmit=function(n,t){if(t)return yU.nextTick(t,n);n&&this.emit("error",n)};var TU=Qr,$y=DC;function DC(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}DC.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},DC.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&TU.nextTick(n)};var _C={exports:{}};(function(n,t){(function(e,r){r(t)})(yn,function(e){function r(T,I){I=I|0;for(var O=Math.max(T.length-I,0),F=Array(O),z=0;z<O;z++)F[z]=T[I+z];return F}var i=function(T){var I=r(arguments,1);return function(){var O=r(arguments);return T.apply(null,I.concat(O))}},o=function(T){return function(){var I=r(arguments),O=I.pop();T.call(this,I,O)}};function s(T){var I=typeof T;return T!=null&&(I=="object"||I=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function d(T){setTimeout(T,0)}function h(T){return function(I){var O=r(arguments,1);T(function(){I.apply(null,O)})}}var C;l?C=setImmediate:c?C=process.nextTick:C=d;var E=h(C);function A(T){return o(function(I,O){var F;try{F=T.apply(this,I)}catch(z){return O(z)}s(F)&&typeof F.then=="function"?F.then(function(z){v(O,null,z)},function(z){v(O,z.message?z:new Error(z))}):O(null,F)})}function v(T,I,O){try{T(I,O)}catch(F){E(w,F)}}function w(T){throw T}var S=typeof Symbol=="function";function U(T){return S&&T[Symbol.toStringTag]==="AsyncFunction"}function M(T){return U(T)?A(T):T}function V(T){return function(I){var O=r(arguments,1),F=o(function(z,j){var J=this;return T(I,function(rt,mt){M(rt).apply(J,z.concat(mt))},j)});return O.length?F.apply(this,O):F}}var nt=typeof yn=="object"&&yn&&yn.Object===Object&&yn,Y=typeof self=="object"&&self&&self.Object===Object&&self,X=nt||Y||Function("return this")(),ft=X.Symbol,xt=Object.prototype,bt=xt.hasOwnProperty,wt=xt.toString,Tt=ft?ft.toStringTag:void 0;function ie(T){var I=bt.call(T,Tt),O=T[Tt];try{T[Tt]=void 0;var F=!0}catch{}var z=wt.call(T);return F&&(I?T[Tt]=O:delete T[Tt]),z}var xe=Object.prototype,fe=xe.toString;function Dr(T){return fe.call(T)}var dr="[object Null]",je="[object Undefined]",Tn=ft?ft.toStringTag:void 0;function tr(T){return T==null?T===void 0?je:dr:Tn&&Tn in Object(T)?ie(T):Dr(T)}var hr="[object AsyncFunction]",mr="[object Function]",uh="[object GeneratorFunction]",fh="[object Proxy]";function dh(T){if(!s(T))return!1;var I=tr(T);return I==mr||I==uh||I==hr||I==fh}var Ao=9007199254740991;function cs(T){return typeof T=="number"&&T>-1&&T%1==0&&T<=Ao}function us(T){return T!=null&&cs(T.length)&&!dh(T)}var te={};function Gt(){}function ri(T){return function(){if(T!==null){var I=T;T=null,I.apply(this,arguments)}}}var On=typeof Symbol=="function"&&Symbol.iterator,fs=function(T){return On&&T[On]&&T[On]()};function Oa(T,I){for(var O=-1,F=Array(T);++O<T;)F[O]=I(O);return F}function kn(T){return T!=null&&typeof T=="object"}var xo="[object Arguments]";function Na(T){return kn(T)&&tr(T)==xo}var er=Object.prototype,Pu=er.hasOwnProperty,hh=er.propertyIsEnumerable,ds=Na(function(){return arguments}())?Na:function(T){return kn(T)&&Pu.call(T,"callee")&&!hh.call(T,"callee")},Oe=Array.isArray;function hs(){return!1}var ms=typeof e=="object"&&e&&!e.nodeType&&e,Fu=ms&&!0&&n&&!n.nodeType&&n,gs=Fu&&Fu.exports===ms,Ku=gs?X.Buffer:void 0,ps=Ku?Ku.isBuffer:void 0,bo=ps||hs,Cs=9007199254740991,Pa=/^(?:0|[1-9]\d*)$/;function Fa(T,I){var O=typeof T;return I=I==null?Cs:I,!!I&&(O=="number"||O!="symbol"&&Pa.test(T))&&T>-1&&T%1==0&&T<I}var Es="[object Arguments]",Ka="[object Array]",Va="[object Boolean]",vo="[object Date]",As="[object Error]",Dl="[object Function]",Vu="[object Map]",_r="[object Number]",Bo="[object Object]",$u="[object RegExp]",$a="[object Set]",Hu="[object String]",mh="[object WeakMap]",gh="[object ArrayBuffer]",ph="[object DataView]",_l="[object Float32Array]",xs="[object Float64Array]",Ha="[object Int8Array]",yo="[object Int16Array]",bs="[object Int32Array]",vs="[object Uint8Array]",ja="[object Uint8ClampedArray]",Ch="[object Uint16Array]",Eh="[object Uint32Array]",be={};be[_l]=be[xs]=be[Ha]=be[yo]=be[bs]=be[vs]=be[ja]=be[Ch]=be[Eh]=!0,be[Es]=be[Ka]=be[gh]=be[Va]=be[ph]=be[vo]=be[As]=be[Dl]=be[Vu]=be[_r]=be[Bo]=be[$u]=be[$a]=be[Hu]=be[mh]=!1;function Ah(T){return kn(T)&&cs(T.length)&&!!be[tr(T)]}function Ml(T){return function(I){return T(I)}}var Ul=typeof e=="object"&&e&&!e.nodeType&&e,To=Ul&&!0&&n&&!n.nodeType&&n,Oi=To&&To.exports===Ul,Ol=Oi&&nt.process,ju=function(){try{var T=To&&To.require&&To.require("util").types;return T||Ol&&Ol.binding&&Ol.binding("util")}catch{}}(),zu=ju&&ju.isTypedArray,xh=zu?Ml(zu):Ah,bh=Object.prototype,Mr=bh.hasOwnProperty;function vh(T,I){var O=Oe(T),F=!O&&ds(T),z=!O&&!F&&bo(T),j=!O&&!F&&!z&&xh(T),J=O||F||z||j,rt=J?Oa(T.length,String):[],mt=rt.length;for(var yt in T)(I||Mr.call(T,yt))&&!(J&&(yt=="length"||z&&(yt=="offset"||yt=="parent")||j&&(yt=="buffer"||yt=="byteLength"||yt=="byteOffset")||Fa(yt,mt)))&&rt.push(yt);return rt}var Nl=Object.prototype;function Bh(T){var I=T&&T.constructor,O=typeof I=="function"&&I.prototype||Nl;return T===O}function Pl(T,I){return function(O){return T(I(O))}}var yh=Pl(Object.keys,Object),Ur=Object.prototype,Th=Ur.hasOwnProperty;function Gu(T){if(!Bh(T))return yh(T);var I=[];for(var O in Object(T))Th.call(T,O)&&O!="constructor"&&I.push(O);return I}function Fl(T){return us(T)?vh(T):Gu(T)}function Wu(T){var I=-1,O=T.length;return function(){return++I<O?{value:T[I],key:I}:null}}function kh(T){var I=-1;return function(){var F=T.next();return F.done?null:(I++,{value:F.value,key:I})}}function Bs(T){var I=Fl(T),O=-1,F=I.length;return function z(){var j=I[++O];return j==="__proto__"?z():O<F?{value:T[j],key:j}:null}}function Rh(T){if(us(T))return Wu(T);var I=fs(T);return I?kh(I):Bs(T)}function gr(T){return function(){if(T===null)throw new Error("Callback was already called.");var I=T;T=null,I.apply(this,arguments)}}function Nn(T){return function(I,O,F){if(F=ri(F||Gt),T<=0||!I)return F(null);var z=Rh(I),j=!1,J=0,rt=!1;function mt(gt,Lt){if(J-=1,gt)j=!0,F(gt);else{if(Lt===te||j&&J<=0)return j=!0,F(null);rt||yt()}}function yt(){for(rt=!0;J<T&&!j;){var gt=z();if(gt===null){j=!0,J<=0&&F(null);return}J+=1,O(gt.value,gt.key,gr(mt))}rt=!1}yt()}}function ii(T,I,O,F){Nn(I)(T,M(O),F)}function Xe(T,I){return function(O,F,z){return T(O,I,F,z)}}function za(T,I,O){O=ri(O||Gt);var F=0,z=0,j=T.length;j===0&&O(null);function J(rt,mt){rt?O(rt):(++z===j||mt===te)&&O(null)}for(;F<j;F++)I(T[F],F,gr(J))}var wh=Xe(ii,1/0),Or=function(T,I,O){var F=us(T)?za:wh;F(T,M(I),O)};function Nr(T){return function(I,O,F){return T(Or,I,M(O),F)}}function ko(T,I,O,F){F=F||Gt,I=I||[];var z=[],j=0,J=M(O);T(I,function(rt,mt,yt){var gt=j++;J(rt,function(Lt,he){z[gt]=he,yt(Lt)})},function(rt){F(rt,z)})}var ys=Nr(ko),Ga=V(ys);function Ni(T){return function(I,O,F,z){return T(Nn(O),I,M(F),z)}}var pr=Ni(ko),Wa=Xe(pr,1),qa=V(Wa);function Ro(T,I){for(var O=-1,F=T==null?0:T.length;++O<F&&I(T[O],O,T)!==!1;);return T}function Xa(T){return function(I,O,F){for(var z=-1,j=Object(I),J=F(I),rt=J.length;rt--;){var mt=J[T?rt:++z];if(O(j[mt],mt,j)===!1)break}return I}}var wo=Xa();function So(T,I){return T&&wo(T,I,Fl)}function qu(T,I,O,F){for(var z=T.length,j=O+(F?1:-1);F?j--:++j<z;)if(I(T[j],j,T))return j;return-1}function Sh(T){return T!==T}function Xu(T,I,O){for(var F=O-1,z=T.length;++F<z;)if(T[F]===I)return F;return-1}function Ts(T,I,O){return I===I?Xu(T,I,O):qu(T,Sh,O)}var Kl=function(T,I,O){typeof I=="function"&&(O=I,I=null),O=ri(O||Gt);var F=Fl(T),z=F.length;if(!z)return O(null);I||(I=z);var j={},J=0,rt=!1,mt=Object.create(null),yt=[],gt=[],Lt={};So(T,function(_e,Te){if(!Oe(_e)){he(Te,[_e]),gt.push(Te);return}var Ke=_e.slice(0,_e.length-1),ui=Ke.length;if(ui===0){he(Te,_e),gt.push(Te);return}Lt[Te]=ui,Ro(Ke,function(R){if(!T[R])throw new Error("async.auto task `"+Te+"` has a non-existent dependency `"+R+"` in "+Ke.join(", "));Fn(R,function(){ui--,ui===0&&he(Te,_e)})})}),Mx(),nn();function he(_e,Te){yt.push(function(){ci(_e,Te)})}function nn(){if(yt.length===0&&J===0)return O(null,j);for(;yt.length&&J<I;){var _e=yt.shift();_e()}}function Fn(_e,Te){var Ke=mt[_e];Ke||(Ke=mt[_e]=[]),Ke.push(Te)}function Cr(_e){var Te=mt[_e]||[];Ro(Te,function(Ke){Ke()}),nn()}function ci(_e,Te){if(!rt){var Ke=gr(function(R,Mo){if(J--,arguments.length>2&&(Mo=r(arguments,1)),R){var Gl={};So(j,function(Er,Yt){Gl[Yt]=Er}),Gl[_e]=Mo,rt=!0,mt=Object.create(null),O(R,Gl)}else j[_e]=Mo,Cr(_e)});J++;var ui=M(Te[Te.length-1]);Te.length>1?ui(j,Ke):ui(Ke)}}function Mx(){for(var _e,Te=0;gt.length;)_e=gt.pop(),Te++,Ro(Ux(_e),function(Ke){--Lt[Ke]===0&&gt.push(Ke)});if(Te!==z)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function Ux(_e){var Te=[];return So(T,function(Ke,ui){Oe(Ke)&&Ts(Ke,_e,0)>=0&&Te.push(ui)}),Te}};function oi(T,I){for(var O=-1,F=T==null?0:T.length,z=Array(F);++O<F;)z[O]=I(T[O],O,T);return z}var Lh="[object Symbol]";function Yu(T){return typeof T=="symbol"||kn(T)&&tr(T)==Lh}var Ih=1/0,Ya=ft?ft.prototype:void 0,ks=Ya?Ya.toString:void 0;function Qa(T){if(typeof T=="string")return T;if(Oe(T))return oi(T,Qa)+"";if(Yu(T))return ks?ks.call(T):"";var I=T+"";return I=="0"&&1/T==-Ih?"-0":I}function Lo(T,I,O){var F=-1,z=T.length;I<0&&(I=-I>z?0:z+I),O=O>z?z:O,O<0&&(O+=z),z=I>O?0:O-I>>>0,I>>>=0;for(var j=Array(z);++F<z;)j[F]=T[F+I];return j}function si(T,I,O){var F=T.length;return O=O===void 0?F:O,!I&&O>=F?T:Lo(T,I,O)}function Ja(T,I){for(var O=T.length;O--&&Ts(I,T[O],0)>-1;);return O}function Qu(T,I){for(var O=-1,F=T.length;++O<F&&Ts(I,T[O],0)>-1;);return O}function Vl(T){return T.split("")}var Dh="\\ud800-\\udfff",_h="\\u0300-\\u036f",Mh="\\ufe20-\\ufe2f",pe="\\u20d0-\\u20ff",de=_h+Mh+pe,Uh="\\ufe0e\\ufe0f",$l="\\u200d",Pi=RegExp("["+$l+Dh+de+Uh+"]");function Oh(T){return Pi.test(T)}var Hl="\\ud800-\\udfff",Ju="\\u0300-\\u036f",Za="\\ufe20-\\ufe2f",Fi="\\u20d0-\\u20ff",Ye=Ju+Za+Fi,tc="\\ufe0e\\ufe0f",li="["+Hl+"]",Io="["+Ye+"]",ai="\\ud83c[\\udffb-\\udfff]",xn="(?:"+Io+"|"+ai+")",Rs="[^"+Hl+"]",ec="(?:\\ud83c[\\udde6-\\uddff]){2}",nc="[\\ud800-\\udbff][\\udc00-\\udfff]",Zu="\\u200d",rc=xn+"?",ws="["+tc+"]?",Pn="(?:"+Zu+"(?:"+[Rs,ec,nc].join("|")+")"+ws+rc+")*",Nh=ws+rc+Pn,Gn="(?:"+[Rs+Io+"?",Io,ec,nc,li].join("|")+")",k=RegExp(ai+"(?="+ai+")|"+Gn+Nh,"g");function N(T){return T.match(k)||[]}function W(T){return Oh(T)?N(T):Vl(T)}function lt(T){return T==null?"":Qa(T)}var St=/^\s+|\s+$/g;function dt(T,I,O){if(T=lt(T),T&&(O||I===void 0))return T.replace(St,"");if(!T||!(I=Qa(I)))return T;var F=W(T),z=W(I),j=Qu(F,z),J=Ja(F,z)+1;return si(F,j,J).join("")}var $t=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,Zt=/,/,ce=/(=.+)?(\s*)$/,we=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function Se(T){return T=T.toString().replace(we,""),T=T.match($t)[2].replace(" ",""),T=T?T.split(Zt):[],T=T.map(function(I){return dt(I.replace(ce,""))}),T}function De(T,I){var O={};So(T,function(F,z){var j,J=U(F),rt=!J&&F.length===1||J&&F.length===0;if(Oe(F))j=F.slice(0,-1),F=F[F.length-1],O[z]=j.concat(j.length>0?mt:F);else if(rt)O[z]=F;else{if(j=Se(F),F.length===0&&!J&&j.length===0)throw new Error("autoInject task functions require explicit parameters.");J||j.pop(),O[z]=j.concat(mt)}function mt(yt,gt){var Lt=oi(j,function(he){return yt[he]});Lt.push(gt),M(F).apply(null,Lt)}}),Kl(O,I)}function ee(){this.head=this.tail=null,this.length=0}function Rn(T,I){T.length=1,T.head=T.tail=I}ee.prototype.removeLink=function(T){return T.prev?T.prev.next=T.next:this.head=T.next,T.next?T.next.prev=T.prev:this.tail=T.prev,T.prev=T.next=null,this.length-=1,T},ee.prototype.empty=function(){for(;this.head;)this.shift();return this},ee.prototype.insertAfter=function(T,I){I.prev=T,I.next=T.next,T.next?T.next.prev=I:this.tail=I,T.next=I,this.length+=1},ee.prototype.insertBefore=function(T,I){I.prev=T.prev,I.next=T,T.prev?T.prev.next=I:this.head=I,T.prev=I,this.length+=1},ee.prototype.unshift=function(T){this.head?this.insertBefore(this.head,T):Rn(this,T)},ee.prototype.push=function(T){this.tail?this.insertAfter(this.tail,T):Rn(this,T)},ee.prototype.shift=function(){return this.head&&this.removeLink(this.head)},ee.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},ee.prototype.toArray=function(){for(var T=Array(this.length),I=this.head,O=0;O<this.length;O++)T[O]=I.data,I=I.next;return T},ee.prototype.remove=function(T){for(var I=this.head;I;){var O=I.next;T(I)&&this.removeLink(I),I=O}return this};function hn(T,I,O){if(I==null)I=1;else if(I===0)throw new Error("Concurrency must not be zero");var F=M(T),z=0,j=[],J=!1;function rt(Lt,he,nn){if(nn!=null&&typeof nn!="function")throw new Error("task callback must be a function");if(gt.started=!0,Oe(Lt)||(Lt=[Lt]),Lt.length===0&&gt.idle())return E(function(){gt.drain()});for(var Fn=0,Cr=Lt.length;Fn<Cr;Fn++){var ci={data:Lt[Fn],callback:nn||Gt};he?gt._tasks.unshift(ci):gt._tasks.push(ci)}J||(J=!0,E(function(){J=!1,gt.process()}))}function mt(Lt){return function(he){z-=1;for(var nn=0,Fn=Lt.length;nn<Fn;nn++){var Cr=Lt[nn],ci=Ts(j,Cr,0);ci===0?j.shift():ci>0&&j.splice(ci,1),Cr.callback.apply(Cr,arguments),he!=null&&gt.error(he,Cr.data)}z<=gt.concurrency-gt.buffer&&gt.unsaturated(),gt.idle()&&gt.drain(),gt.process()}}var yt=!1,gt={_tasks:new ee,concurrency:I,payload:O,saturated:Gt,unsaturated:Gt,buffer:I/4,empty:Gt,drain:Gt,error:Gt,started:!1,paused:!1,push:function(Lt,he){rt(Lt,!1,he)},kill:function(){gt.drain=Gt,gt._tasks.empty()},unshift:function(Lt,he){rt(Lt,!0,he)},remove:function(Lt){gt._tasks.remove(Lt)},process:function(){if(!yt){for(yt=!0;!gt.paused&&z<gt.concurrency&&gt._tasks.length;){var Lt=[],he=[],nn=gt._tasks.length;gt.payload&&(nn=Math.min(nn,gt.payload));for(var Fn=0;Fn<nn;Fn++){var Cr=gt._tasks.shift();Lt.push(Cr),j.push(Cr),he.push(Cr.data)}z+=1,gt._tasks.length===0&&gt.empty(),z===gt.concurrency&&gt.saturated();var ci=gr(mt(Lt));F(he,ci)}yt=!1}},length:function(){return gt._tasks.length},running:function(){return z},workersList:function(){return j},idle:function(){return gt._tasks.length+z===0},pause:function(){gt.paused=!0},resume:function(){gt.paused!==!1&&(gt.paused=!1,E(gt.process))}};return gt}function wn(T,I){return hn(T,1,I)}var Sn=Xe(ii,1);function bn(T,I,O,F){F=ri(F||Gt);var z=M(O);Sn(T,function(j,J,rt){z(I,j,function(mt,yt){I=yt,rt(mt)})},function(j){F(j,I)})}function Ss(){var T=oi(arguments,M);return function(){var I=r(arguments),O=this,F=I[I.length-1];typeof F=="function"?I.pop():F=Gt,bn(T,I,function(z,j,J){j.apply(O,z.concat(function(rt){var mt=r(arguments,1);J(rt,mt)}))},function(z,j){F.apply(O,[z].concat(j))})}}var Ki=function(){return Ss.apply(null,r(arguments).reverse())},Do=Array.prototype.concat,ic=function(T,I,O,F){F=F||Gt;var z=M(O);pr(T,I,function(j,J){z(j,function(rt){return rt?J(rt):J(null,r(arguments,1))})},function(j,J){for(var rt=[],mt=0;mt<J.length;mt++)J[mt]&&(rt=Do.apply(rt,J[mt]));return F(j,rt)})},$g=Xe(ic,1/0),tf=Xe(ic,1),ef=function(){var T=r(arguments),I=[null].concat(T);return function(){var O=arguments[arguments.length-1];return O.apply(this,I)}};function oc(T){return T}function Ls(T,I){return function(O,F,z,j){j=j||Gt;var J=!1,rt;O(F,function(mt,yt,gt){z(mt,function(Lt,he){Lt?gt(Lt):T(he)&&!rt?(J=!0,rt=I(!0,mt),gt(null,te)):gt()})},function(mt){mt?j(mt):j(null,J?rt:I(!1))})}}function Wn(T,I){return I}var jl=Nr(Ls(oc,Wn)),Vi=Ni(Ls(oc,Wn)),sc=Xe(Vi,1);function Ph(T){return function(I){var O=r(arguments,1);O.push(function(F){var z=r(arguments,1);typeof console=="object"&&(F?console.error&&console.error(F):console[T]&&Ro(z,function(j){console[T](j)}))}),M(I).apply(null,O)}}var Hg=Ph("dir");function jg(T,I,O){O=gr(O||Gt);var F=M(T),z=M(I);function j(rt){if(rt)return O(rt);var mt=r(arguments,1);mt.push(J),z.apply(this,mt)}function J(rt,mt){if(rt)return O(rt);if(!mt)return O(null);F(j)}J(null,!0)}function Fh(T,I,O){O=gr(O||Gt);var F=M(T),z=function(j){if(j)return O(j);var J=r(arguments,1);if(I.apply(this,J))return F(z);O.apply(null,[null].concat(J))};F(z)}function zg(T,I,O){Fh(T,function(){return!I.apply(this,arguments)},O)}function Gg(T,I,O){O=gr(O||Gt);var F=M(I),z=M(T);function j(rt){if(rt)return O(rt);z(J)}function J(rt,mt){if(rt)return O(rt);if(!mt)return O(null);F(j)}z(J)}function Is(T){return function(I,O,F){return T(I,F)}}function nf(T,I,O){Or(T,Is(M(I)),O)}function lc(T,I,O,F){Nn(I)(T,Is(M(O)),F)}var Ds=Xe(lc,1);function rf(T){return U(T)?T:o(function(I,O){var F=!0;I.push(function(){var z=arguments;F?E(function(){O.apply(null,z)}):O.apply(null,z)}),T.apply(this,I),F=!1})}function Pr(T){return!T}var _s=Nr(Ls(Pr,Pr)),ac=Ni(Ls(Pr,Pr)),of=Xe(ac,1);function Wg(T){return function(I){return I==null?void 0:I[T]}}function zl(T,I,O,F){var z=new Array(I.length);T(I,function(j,J,rt){O(j,function(mt,yt){z[J]=!!yt,rt(mt)})},function(j){if(j)return F(j);for(var J=[],rt=0;rt<I.length;rt++)z[rt]&&J.push(I[rt]);F(null,J)})}function Fr(T,I,O,F){var z=[];T(I,function(j,J,rt){O(j,function(mt,yt){mt?rt(mt):(yt&&z.push({index:J,value:j}),rt())})},function(j){j?F(j):F(null,oi(z.sort(function(J,rt){return J.index-rt.index}),Wg("value")))})}function sf(T,I,O,F){var z=us(I)?zl:Fr;z(T,I,M(O),F||Gt)}var lf=Nr(sf),cc=Ni(sf),af=Xe(cc,1);function qg(T,I){var O=gr(I||Gt),F=M(rf(T));function z(j){if(j)return O(j);F(z)}z()}var cf=function(T,I,O,F){F=F||Gt;var z=M(O);pr(T,I,function(j,J){z(j,function(rt,mt){return rt?J(rt):J(null,{key:mt,val:j})})},function(j,J){for(var rt={},mt=Object.prototype.hasOwnProperty,yt=0;yt<J.length;yt++)if(J[yt]){var gt=J[yt].key,Lt=J[yt].val;mt.call(rt,gt)?rt[gt].push(Lt):rt[gt]=[Lt]}return F(j,rt)})},Ms=Xe(cf,1/0),$=Xe(cf,1),Q=Ph("log");function G(T,I,O,F){F=ri(F||Gt);var z={},j=M(O);ii(T,I,function(J,rt,mt){j(J,rt,function(yt,gt){if(yt)return mt(yt);z[rt]=gt,mt()})},function(J){F(J,z)})}var vt=Xe(G,1/0),Nt=Xe(G,1);function oe(T,I){return I in T}function Qe(T,I){var O=Object.create(null),F=Object.create(null);I=I||oc;var z=M(T),j=o(function(rt,mt){var yt=I.apply(null,rt);oe(O,yt)?E(function(){mt.apply(null,O[yt])}):oe(F,yt)?F[yt].push(mt):(F[yt]=[mt],z.apply(null,rt.concat(function(){var gt=r(arguments);O[yt]=gt;var Lt=F[yt];delete F[yt];for(var he=0,nn=Lt.length;he<nn;he++)Lt[he].apply(null,gt)})))});return j.memo=O,j.unmemoized=T,j}var ue;c?ue=process.nextTick:l?ue=setImmediate:ue=d;var uf=h(ue);function Kh(T,I,O){O=O||Gt;var F=us(I)?[]:{};T(I,function(z,j,J){M(z)(function(rt,mt){arguments.length>2&&(mt=r(arguments,1)),F[j]=mt,J(rt)})},function(z){O(z,F)})}function nr(T,I){Kh(Or,T,I)}function uc(T,I,O){Kh(Nn(I),T,O)}var Vh=function(T,I){var O=M(T);return hn(function(F,z){O(F[0],z)},I,1)},Us=function(T,I){var O=Vh(T,I);return O.push=function(F,z,j){if(j==null&&(j=Gt),typeof j!="function")throw new Error("task callback must be a function");if(O.started=!0,Oe(F)||(F=[F]),F.length===0)return E(function(){O.drain()});z=z||0;for(var J=O._tasks.head;J&&z>=J.priority;)J=J.next;for(var rt=0,mt=F.length;rt<mt;rt++){var yt={data:F[rt],priority:z,callback:j};J?O._tasks.insertBefore(J,yt):O._tasks.push(yt)}E(O.process)},delete O.unshift,O};function fc(T,I){if(I=ri(I||Gt),!Oe(T))return I(new TypeError("First argument to race must be an array of functions"));if(!T.length)return I();for(var O=0,F=T.length;O<F;O++)M(T[O])(I)}function Os(T,I,O,F){var z=r(T).reverse();bn(z,I,O,F)}function se(T){var I=M(T);return o(function(F,z){return F.push(function(J,rt){if(J)z(null,{error:J});else{var mt;arguments.length<=2?mt=rt:mt=r(arguments,1),z(null,{value:mt})}}),I.apply(this,F)})}function Xg(T){var I;return Oe(T)?I=oi(T,se):(I={},So(T,function(O,F){I[F]=se.call(this,O)})),I}function $h(T,I,O,F){sf(T,I,function(z,j){O(z,function(J,rt){j(J,!rt)})},F)}var dc=Nr($h),Hh=Ni($h),Yg=Xe(Hh,1);function Qg(T){return function(){return T}}function Ns(T,I,O){var F=5,z=0,j={times:F,intervalFunc:Qg(z)};function J(gt,Lt){if(typeof Lt=="object")gt.times=+Lt.times||F,gt.intervalFunc=typeof Lt.interval=="function"?Lt.interval:Qg(+Lt.interval||z),gt.errorFilter=Lt.errorFilter;else if(typeof Lt=="number"||typeof Lt=="string")gt.times=+Lt||F;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof T=="function"?(O=I||Gt,I=T):(J(j,T),O=O||Gt),typeof I!="function")throw new Error("Invalid arguments for async.retry");var rt=M(I),mt=1;function yt(){rt(function(gt){gt&&mt++<j.times&&(typeof j.errorFilter!="function"||j.errorFilter(gt))?setTimeout(yt,j.intervalFunc(mt)):O.apply(null,arguments)})}yt()}var $i=function(T,I){I||(I=T,T=null);var O=M(I);return o(function(F,z){function j(J){O.apply(null,F.concat(J))}T?Ns(T,j,z):Ns(j,z)})};function hc(T,I){Kh(Sn,T,I)}var mc=Nr(Ls(Boolean,oc)),_o=Ni(Ls(Boolean,oc)),gc=Xe(_o,1);function jh(T,I,O){var F=M(I);ys(T,function(j,J){F(j,function(rt,mt){if(rt)return J(rt);J(null,{value:j,criteria:mt})})},function(j,J){if(j)return O(j);O(null,oi(J.sort(z),Wg("value")))});function z(j,J){var rt=j.criteria,mt=J.criteria;return rt<mt?-1:rt>mt?1:0}}function pc(T,I,O){var F=M(T);return o(function(z,j){var J=!1,rt;function mt(){var yt=T.name||"anonymous",gt=new Error('Callback function "'+yt+'" timed out.');gt.code="ETIMEDOUT",O&&(gt.info=O),J=!0,j(gt)}z.push(function(){J||(j.apply(null,arguments),clearTimeout(rt))}),rt=setTimeout(mt,I),F.apply(null,z)})}var Jg=Math.ceil,Cc=Math.max;function Ps(T,I,O,F){for(var z=-1,j=Cc(Jg((I-T)/(O||1)),0),J=Array(j);j--;)J[F?j:++z]=T,T+=O;return J}function Fs(T,I,O,F){var z=M(O);pr(Ps(0,T,1),I,z,F)}var Zg=Xe(Fs,1/0),tp=Xe(Fs,1);function ep(T,I,O,F){arguments.length<=3&&(F=O,O=I,I=Oe(T)?[]:{}),F=ri(F||Gt);var z=M(O);Or(T,function(j,J,rt){z(I,j,J,rt)},function(j){F(j,I)})}function Ec(T,I){var O=null,F;I=I||Gt,Ds(T,function(z,j){M(z)(function(J,rt){arguments.length>2?F=r(arguments,1):F=rt,O=J,j(!J)})},function(){I(O,F)})}function Ac(T){return function(){return(T.unmemoized||T).apply(null,arguments)}}function xc(T,I,O){O=gr(O||Gt);var F=M(I);if(!T())return O(null);var z=function(j){if(j)return O(j);if(T())return F(z);var J=r(arguments,1);O.apply(null,[null].concat(J))};F(z)}function np(T,I,O){xc(function(){return!T.apply(this,arguments)},I,O)}var zh=function(T,I){if(I=ri(I||Gt),!Oe(T))return I(new Error("First argument to waterfall must be an array of functions"));if(!T.length)return I();var O=0;function F(j){var J=M(T[O++]);j.push(gr(z)),J.apply(null,j)}function z(j){if(j||O===T.length)return I.apply(null,arguments);F(r(arguments,1))}F([])},_x={apply:i,applyEach:Ga,applyEachSeries:qa,asyncify:A,auto:Kl,autoInject:De,cargo:wn,compose:Ki,concat:$g,concatLimit:ic,concatSeries:tf,constant:ef,detect:jl,detectLimit:Vi,detectSeries:sc,dir:Hg,doDuring:jg,doUntil:zg,doWhilst:Fh,during:Gg,each:nf,eachLimit:lc,eachOf:Or,eachOfLimit:ii,eachOfSeries:Sn,eachSeries:Ds,ensureAsync:rf,every:_s,everyLimit:ac,everySeries:of,filter:lf,filterLimit:cc,filterSeries:af,forever:qg,groupBy:Ms,groupByLimit:cf,groupBySeries:$,log:Q,map:ys,mapLimit:pr,mapSeries:Wa,mapValues:vt,mapValuesLimit:G,mapValuesSeries:Nt,memoize:Qe,nextTick:uf,parallel:nr,parallelLimit:uc,priorityQueue:Us,queue:Vh,race:fc,reduce:bn,reduceRight:Os,reflect:se,reflectAll:Xg,reject:dc,rejectLimit:Hh,rejectSeries:Yg,retry:Ns,retryable:$i,seq:Ss,series:hc,setImmediate:E,some:mc,someLimit:_o,someSeries:gc,sortBy:jh,timeout:pc,times:Zg,timesLimit:Fs,timesSeries:tp,transform:ep,tryEach:Ec,unmemoize:Ac,until:np,waterfall:zh,whilst:xc,all:_s,allLimit:ac,allSeries:of,any:mc,anyLimit:_o,anySeries:gc,find:jl,findLimit:Vi,findSeries:sc,forEach:nf,forEachSeries:Ds,forEachLimit:lc,forEachOf:Or,forEachOfSeries:Sn,forEachOfLimit:ii,inject:bn,foldl:bn,foldr:Os,select:lf,selectLimit:cc,selectSeries:af,wrapSync:A};e.default=_x,e.apply=i,e.applyEach=Ga,e.applyEachSeries=qa,e.asyncify=A,e.auto=Kl,e.autoInject=De,e.cargo=wn,e.compose=Ki,e.concat=$g,e.concatLimit=ic,e.concatSeries=tf,e.constant=ef,e.detect=jl,e.detectLimit=Vi,e.detectSeries=sc,e.dir=Hg,e.doDuring=jg,e.doUntil=zg,e.doWhilst=Fh,e.during=Gg,e.each=nf,e.eachLimit=lc,e.eachOf=Or,e.eachOfLimit=ii,e.eachOfSeries=Sn,e.eachSeries=Ds,e.ensureAsync=rf,e.every=_s,e.everyLimit=ac,e.everySeries=of,e.filter=lf,e.filterLimit=cc,e.filterSeries=af,e.forever=qg,e.groupBy=Ms,e.groupByLimit=cf,e.groupBySeries=$,e.log=Q,e.map=ys,e.mapLimit=pr,e.mapSeries=Wa,e.mapValues=vt,e.mapValuesLimit=G,e.mapValuesSeries=Nt,e.memoize=Qe,e.nextTick=uf,e.parallel=nr,e.parallelLimit=uc,e.priorityQueue=Us,e.queue=Vh,e.race=fc,e.reduce=bn,e.reduceRight=Os,e.reflect=se,e.reflectAll=Xg,e.reject=dc,e.rejectLimit=Hh,e.rejectSeries=Yg,e.retry=Ns,e.retryable=$i,e.seq=Ss,e.series=hc,e.setImmediate=E,e.some=mc,e.someLimit=_o,e.someSeries=gc,e.sortBy=jh,e.timeout=pc,e.times=Zg,e.timesLimit=Fs,e.timesSeries=tp,e.transform=ep,e.tryEach=Ec,e.unmemoize=Ac,e.until=np,e.waterfall=zh,e.whilst=xc,e.all=_s,e.allLimit=ac,e.allSeries=of,e.any=mc,e.anyLimit=_o,e.anySeries=gc,e.find=jl,e.findLimit=Vi,e.findSeries=sc,e.forEach=nf,e.forEachSeries=Ds,e.forEachLimit=lc,e.forEachOf=Or,e.forEachOfSeries=Sn,e.forEachOfLimit=ii,e.inject=bn,e.foldl=bn,e.foldr=Os,e.select=lf,e.selectLimit=cc,e.selectSeries=af,e.wrapSync=A,Object.defineProperty(e,"__esModule",{value:!0})})})(_C,_C.exports);var Hy={exports:{}},MC=Hy.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),r=2;e===1/0;r*=2)e=Math.log(Math.pow(2,n/r))/Math.log(t)*r;for(var i=e-Math.floor(e),o="",r=0;r<Math.floor(e);r++){var s=Math.floor(Math.random()*t).toString(t);o=s+o}if(i){var l=Math.pow(t,i),s=Math.floor(Math.random()*l).toString(t);o=s+o}var c=parseInt(o,t);return c!==1/0&&c>=Math.pow(2,n)?MC(n,t):o};MC.rack=function(n,t,e){var r=function(o){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=MC(n,t)}while(Object.hasOwnProperty.call(i,l));return i[l]=o,l},i=r.hats={};return r.get=function(o){return r.hats[o]},r.set=function(o,s){return r.hats[o]=s,r},r.bits=n||128,r.base=t||16,r};var jy=ul,kU=Vy,RU=$y,gm=Qr,UC=_C.exports,wU=Hy.exports,zy=dl.ACTIONS,Gy=an;function an(n,t){if(jy.EventEmitter.call(this),!t||typeof t!="string")throw new Error("Presence channel must be provided");this.connection=n,this.channel=t,this.wantSubscribe=!1,this.subscribed=!1,this.remotePresences={},this.localPresences={},this._remotePresenceInstances={},this._subscriptionCallbacksBySeq={},this._wantsDestroy=!1}jy.mixin(an),an.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},an.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},an.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||wU();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},an.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(r){if(r)return t._callbackOrEmit(r,n);var i=Object.keys(t._remotePresenceInstances);UC.parallel([function(o){UC.each(e,function(s,l){t.localPresences[s].destroy(l)},o)},function(o){if(!t._wantsDestroy)return o();UC.each(i,function(s,l){t._remotePresenceInstances[s].destroy(l)},o)}],function(o){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(o,n)})})},an.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?zy.presenceSubscribe:zy.presenceUnsubscribe,r=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[r]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,r,this)},an.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},an.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},an.prototype._receiveUpdate=function(n,t){var e=gm.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var r=this,i=gm.digOrCreate(this._remotePresenceInstances,t.id,function(){return r._createRemotePresence(t.id)});i.receiveUpdate(t)},an.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},an.prototype._broadcastAllLocalPresence=function(n){if(n)return this.emit("error",n);for(var t in this.localPresences){var e=this.localPresences[t];e.value!==null&&e.send()}},an.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},an.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},an.prototype._resubscribe=function(){var n=[];for(var t in this._subscriptionCallbacksBySeq){var e=this._subscriptionCallback(t);n.push(e)}if(!this.wantSubscribe)return this._callEachOrEmit(n);var r=this;this.subscribe(function(i){r._callEachOrEmit(n,i)})},an.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},an.prototype._callbackOrEmit=function(n,t){if(t)return gm.nextTick(t,n);n&&this.emit("error",n)},an.prototype._createLocalPresence=function(n){return new kU(this,n)},an.prototype._createRemotePresence=function(n){return new RU(this,n)},an.prototype._callEachOrEmit=function(n,t){var e=gm.callEach(n,t);!e&&t&&this.emit("error",t)};var od=Vy,Wy=fm,SU=Qr,qy=Wy.CODES,LU=ki;function ki(n,t){od.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._isSending=!1,this._docDataVersionByPresenceVersion={},this._opHandler=this._transformAgainstOp.bind(this),this._createOrDelHandler=this._handleCreateOrDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._destroyHandler=this.destroy.bind(this),this._registerWithDoc()}ki.prototype=Object.create(od.prototype),ki.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:qy.ERR_DOC_DOES_NOT_EXIST,message:"Cannot submit presence. Document has not been created"};return this._callbackOrEmit(e,t)}this._docDataVersionByPresenceVersion[this.presenceVersion]=this._doc._dataStateVersion,od.prototype.submit.call(this,n,t)},ki.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),this._emitter.removeEventListener(this._doc,"destroy",this._destroyHandler),od.prototype.destroy.call(this,n)},ki.prototype._sendPending=function(){if(!this._isSending){this._isSending=!0;var n=this;this._doc.whenNothingPending(function(){n._isSending=!1,n.connection.canSend&&(n._pendingMessages.forEach(function(t){t.t=n._doc.type.uri,t.v=n._doc.version,n.connection.send(t)}),n._pendingMessages=[],n._docDataVersionByPresenceVersion={})})}},ki.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler),this._emitter.addEventListener(this._doc,"destroy",this._destroyHandler)},ki.prototype._transformAgainstOp=function(n,t){var e=this,r=this._doc._dataStateVersion;this._pendingMessages.forEach(function(i){var o=e._docDataVersionByPresenceVersion[i.pv];if(!(o>=r))try{i.p=e._transformPresence(i.p,n,t),e._docDataVersionByPresenceVersion[i.pv]=r}catch(l){var s=e._getCallback(i.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(i){this.emit("error",i)}},ki.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},ki.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},ki.prototype._message=function(){var n=od.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},ki.prototype._transformPresence=function(n,t,e){var r=this._doc.type;if(!SU.supportsPresence(r))throw new Wy(qy.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+r.name);return r.transformPresence(n,t,e)};var Xy={};(function(n){var t=ed,e=fm,r=Qr,i=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var c=l.create.type;if(typeof c!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[c];if(d==null||typeof d!="object")return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(i.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(i.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(i.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,c){if(typeof l!="object")return new e(i.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&c.v!=null&&l.v!==c.v)return new e(i.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(c.create){if(l.type)return new e(i.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=c.create,h=t.map[d.type];if(!h)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(E){return E}}else if(c.del)l.data=void 0,l.type=null,l.v++;else if("op"in c){var C=o(l,c.op);if(C)return C;l.v++}else l.v++};function o(l,c){if(!l.type)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(c===void 0)return new e(i.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,c)}catch(h){return new e(i.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,c,d){if(c.v!=null&&c.v!==d.v)return new e(i.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(c.create||"op"in c)return new e(i.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in c||c.create||c.del)||"op"in d&&c.create)return new e(i.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in c){if(!l)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{c.op=l.transform(c.op,d.op,"left")}catch(h){return h}}}c.v!=null&&c.v++},n.applyOps=function(l,c,d){d=d||{};for(var h=0;h<c.length;h++){var C=c[h];if(d._normalizeLegacyJson0Ops)try{s(l,C)}catch{return new e(i.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=C.v;var E=n.apply(l,C);if(E)return E}},n.transformPresence=function(l,c,d){var h=this.checkOp(c);if(h)return h;var C=l.t;if(typeof C=="string"&&(C=t.map[C]),!C)return{code:i.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!r.supportsPresence(C))return{code:i.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(c.create||c.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:C.transformPresence(l.p,c.op,d)}catch(E){return{code:i.ERR_PRESENCE_TRANSFORM_FAILED,message:E.message||E}}l.v++};function s(l,c){if(l.type===t.defaultType.uri){var d=c.op;if(!!d){var h=l.data;d.length>1&&(h=r.clone(h));for(var C=0;C<d.length;C++){var E=d[C];typeof E.lm=="string"&&(E.lm=+E.lm);for(var A=E.p,v=h,w=0;w<A.length;w++){var S=A[w];Object.prototype.toString.call(v)=="[object Array]"?A[w]=+S:v.constructor===Object&&(A[w]=S.toString()),v=v[S]}C<d.length-1&&(h=t.defaultType.apply(h,[E]))}}}}})(Xy);var sd=$y,IU=Xy,DU=Jr;function Jr(n,t){sd.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this.src=null,this.presenceVersion=null,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._pending=null,this._opCache=null,this._pendingSetPending=!1,this._opHandler=this._handleOp.bind(this),this._createDelHandler=this._handleCreateDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._registerWithDoc()}Jr.prototype=Object.create(sd.prototype),Jr.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},Jr.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),sd.prototype.destroy.call(this,n)},Jr.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createDelHandler),this._emitter.addEventListener(this._doc,"del",this._createDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler)},Jr.prototype._setPendingPresence=function(){if(!this._pendingSetPending){this._pendingSetPending=!0;var n=this;this._doc.whenNothingPending(function(){if(n._pendingSetPending=!1,!!n._pending){if(n._pending.pv<n.presenceVersion)return n._pending=null;if(n._pending.v>n._doc.version)return n._doc.fetch();!n._catchUpStalePresence()||(n.value=n._pending.p,n.presenceVersion=n._pending.pv,n._pending=null,n.presence._updateRemotePresence(n))}})}},Jr.prototype._handleOp=function(n,t,e){var r=e===this.src;this._transformAgainstOp(n,r),this._cacheOp(n,r),this._setPendingPresence()},sd.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},sd.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},Jr.prototype._transformAgainstOp=function(n,t){if(!!this.value){try{this.value=this._doc.type.transformPresence(this.value,n,t)}catch(e){return this.presence.emit("error",e)}this.presence._updateRemotePresence(this)}},Jr.prototype._catchUpStalePresence=function(){if(this._pending.v>=this._doc.version)return!0;if(!this._opCache)return this._startCachingOps(),this._doc.fetch(),this.presence.subscribe(),!1;for(;this._opCache[this._pending.v];){var n=this._opCache[this._pending.v],t=n.op,e=n.isOwnOp;t===null?(this._pending.p=null,this._pending.v++):IU.transformPresence(this._pending,t,e)}var r=this._pending.v>=this._doc.version;return r&&this._stopCachingOps(),r},Jr.prototype._startCachingOps=function(){this._opCache=[]},Jr.prototype._stopCachingOps=function(){this._opCache=null},Jr.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var Yy=Gy,_U=LU,MU=DU;function tu(n,t,e){var r=tu.channel(t,e);Yy.call(this,n,r),this.collection=t,this.id=e}var UU=tu;tu.prototype=Object.create(Yy.prototype),tu.channel=function(n,t){return n+"."+t},tu.prototype._createLocalPresence=function(n){return new _U(this,n)},tu.prototype._createRemotePresence=function(n){return new MU(this,n)};var OU=NU;function NU(n,t,e,r,i){this.id=n,this.v=t,this.type=e,this.data=r,this.m=i}var PU=OU,Qy=ul,Jy=ld;function ld(n,t,e,r,i){if(Qy.EventEmitter.call(this),typeof i!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=r,this.collection=e,this.callback=i,this.sent=!1}Qy.mixin(ld),ld.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},ld.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},ld.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,r=new PU(this.id,t.v,t.type,t.data,e);this.callback(null,r)};var Zy=Jy,FU=Qr,KU=dl.ACTIONS,VU=OC;function OC(n,t,e,r,i,o){if(Zy.call(this,n,t,e,r,o),!FU.isValidVersion(i))throw new Error("Snapshot version must be a positive integer or null");this.version=i}OC.prototype=Object.create(Zy.prototype),OC.prototype._message=function(){return{a:KU.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var tT=Jy,$U=Qr,HU=dl.ACTIONS,jU=NC;function NC(n,t,e,r,i,o){if(tT.call(this,n,t,e,r,o),!$U.isValidTimestamp(i))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=i}NC.prototype=Object.create(tT.prototype),NC.prototype._message=function(){return{a:HU.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var oo=Qr,zU=Sp.default.EventEmitter,GU=["create","del","destroy","load","op"],WU=ad;function ad(){this._docs={},this._forwarders={},this._emitters={}}ad.prototype.addEventListener=function(n,t,e){this._registerDoc(n);var r=oo.dig(this._emitters,n.collection,n.id);r.on(t,e)},ad.prototype.removeEventListener=function(n,t,e){var r=oo.dig(this._emitters,n.collection,n.id);!r||(r.off(t,e),r._eventsCount===1&&this._unregisterDoc(n))},ad.prototype._registerDoc=function(n){var t=!0;if(oo.digOrCreate(this._docs,n.collection,n.id,function(){return t=!1,n}),!t){var e=oo.digOrCreate(this._emitters,n.collection,n.id,function(){var i=new zU;return i.setMaxListeners(1e3),i}),r=this;GU.forEach(function(i){var o=oo.digOrCreate(r._forwarders,n.collection,n.id,i,function(){return e.emit.bind(e,i)});n.on(i,o)}),this.addEventListener(n,"destroy",this._unregisterDoc.bind(this,n))}},ad.prototype._unregisterDoc=function(n){var t=oo.dig(this._forwarders,n.collection,n.id);for(var e in t)n.off(e,t[e]);var r=oo.dig(this._emitters,n.collection,n.id);r.removeAllListeners(),oo.digAndRemove(this._forwarders,n.collection,n.id),oo.digAndRemove(this._emitters,n.collection,n.id),oo.digAndRemove(this._docs,n.collection,n.id)};var qU=CU,XU=vU,YU=Gy,eT=UU,QU=VU,JU=jU,nT=ul,eu=fm,ye=dl.ACTIONS,rT=ed,Ri=Qr,cd=Dy,ZU=WU,ud=eu.CODES;function iT(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var tO=Ut;function Ut(n){nT.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._docPresenceEmitter=new ZU,this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=iT(n),this.bindToSocket(n)}nT.mixin(Ut),Ut.prototype.bindToSocket=function(n){this.socket&&(this.socket.close(),this.socket.onmessage=null,this.socket.onopen=null,this.socket.onerror=null,this.socket.onclose=null),this.socket=n;var t=iT(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(r){try{var i=typeof r.data=="string"?JSON.parse(r.data):r.data}catch{cd.warn("Failed to parse message",r);return}e.debug&&cd.info("RECV",JSON.stringify(i));var o={data:i};if(e.emit("receive",o),!!o.data)try{e.handleMessage(o.data)}catch(s){Ri.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(r){e.emit("connection error",r)},n.onclose=function(r){r==="closed"||r==="Closed"?e._setState("closed",r):r==="stopped"||r==="Stopped by server"?e._setState("stopped",r):e._setState("disconnected",r)}},Ut.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=oT(n.error,n),delete n.error),n.a){case ye.initLegacy:return this._handleLegacyInit(n);case ye.handshake:return this._handleHandshake(t,n);case ye.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case ye.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case ye.queryUnsubscribe:return;case ye.queryUpdate:var e=this.queries[n.id];if(!e)return;if(t)return e._handleError(t);n.diff&&e._handleDiff(n.diff),n.hasOwnProperty("extra")&&e._handleExtra(n.extra);return;case ye.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case ye.bulkSubscribe:case ye.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case ye.snapshotFetch:case ye.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case ye.fetch:var r=this.getExisting(n.c,n.d);r&&r._handleFetch(t,n.data);return;case ye.subscribe:case ye.unsubscribe:var r=this.getExisting(n.c,n.d);r&&r._handleSubscribe(t,n.data);return;case ye.op:var r=this.getExisting(n.c,n.d);r&&r._handleOp(t,n);return;case ye.presence:return this._handlePresence(t,n);case ye.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case ye.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case ye.presenceRequest:return this._handlePresenceRequest(t,n);case ye.pingPong:return this._handlePingPong(t);default:cd.warn("Ignoring unrecognized message",n)}};function oT(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}Ut.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var r in t.data){var i=t.data[r],o=this.getExisting(t.c,r);o&&(n?o[e](n):i.error?o[e](oT(i.error)):o[e](null,i))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var r=t.b[s],o=this.getExisting(t.c,r);o&&o[e](n)}else if(t.b)for(var r in t.b){var o=this.getExisting(t.c,r);o&&o[e](n)}else cd.error("Invalid bulk message",t)},Ut.prototype._reset=function(){this.agent=null},Ut.prototype._setState=function(n,t){if(this.state!==n){if(n==="connecting"&&this.state!=="disconnected"&&this.state!=="stopped"&&this.state!=="closed"||n==="connected"&&this.state!=="connecting"){var e=new eu(ud.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var r in this.queries){var i=this.queries[r];i._onConnectionStateChanged()}for(var o in this.collections){var s=this.collections[o];for(var r in s)s[r]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var r in this._snapshotRequests){var c=this._snapshotRequests[r];c._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},Ut.prototype.startBulk=function(){this.bulk||(this.bulk={})},Ut.prototype.endBulk=function(){if(this.bulk)for(var n in this.bulk){var t=this.bulk[n];this._sendBulk("f",n,t.f),this._sendBulk("s",n,t.s),this._sendBulk("u",n,t.u)}this.bulk=null},Ut.prototype._sendBulk=function(n,t,e){if(!!e){var r=[],i={},o=0,s;for(var l in e){var c=e[l];c==null?r.push(l):(i[l]=c,s=l,o++)}if(r.length===1){var l=r[0];this.send({a:n,c:t,d:l})}else r.length&&this.send({a:"b"+n,c:t,b:r});if(o===1){var d=i[s];this.send({a:n,c:t,d:s,v:d})}else o&&this.send({a:"b"+n,c:t,b:i})}},Ut.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var r=this.bulk[t.collection]||(this.bulk[t.collection]={}),i=r[n]||(r[n]={}),o=i.hasOwnProperty(t.id);return i[t.id]=e,o}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},Ut.prototype.sendFetch=function(n){return this._sendActions(ye.fetch,n,n.version)},Ut.prototype.sendSubscribe=function(n){return this._sendActions(ye.subscribe,n,n.version)},Ut.prototype.sendUnsubscribe=function(n){return this._sendActions(ye.unsubscribe,n)},Ut.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:ye.op,c:n.collection,d:n.id,v:n.version,src:t.src,seq:t.seq,x:{}};"op"in t&&(e.op=t.op),t.create&&(e.create=t.create),t.del&&(e.del=t.del),n.submitSource&&(e.x.source=t.source),this.send(e)},Ut.prototype.send=function(n){this.debug&&cd.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},Ut.prototype.ping=function(){if(!this.canSend)throw new eu(ud.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:ye.pingPong};this.send(n)},Ut.prototype.close=function(){this.socket.close()},Ut.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},Ut.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),r=e[t];return r||(r=e[t]=new qU(this,n,t),this.emit("doc",r)),r._wantsDestroy=!1,r},Ut.prototype._destroyDoc=function(n){!n._wantsDestroy||(Ri.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},Ut.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},Ut.prototype._createQuery=function(n,t,e,r,i){var o=this.nextQueryId++,s=new XU(n,this,o,t,e,r,i);return this.queries[o]=s,s.send(),s},Ut.prototype._destroyQuery=function(n){delete this.queries[n.id]},Ut.prototype.createFetchQuery=function(n,t,e,r){return this._createQuery(ye.queryFetch,n,t,e,r)},Ut.prototype.createSubscribeQuery=function(n,t,e,r){return this._createQuery(ye.querySubscribe,n,t,e,r)},Ut.prototype.hasPending=function(){return!!(this._firstDoc(pm)||this._firstQuery(pm)||this._firstSnapshotRequest())};function pm(n){return n.hasPending()}Ut.prototype.hasWritePending=function(){return!!this._firstDoc(eO)};function eO(n){return n.hasWritePending()}Ut.prototype.whenNothingPending=function(n){var t=this._firstDoc(pm);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(pm);if(e){e.once("ready",this._nothingPendingRetry(n));return}var r=this._firstSnapshotRequest();if(r){r.once("ready",this._nothingPendingRetry(n));return}Ri.nextTick(n)},Ut.prototype._nothingPendingRetry=function(n){var t=this;return function(){Ri.nextTick(function(){t.whenNothingPending(n)})}},Ut.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var r in e){var i=e[r];if(n(i))return i}}},Ut.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},Ut.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},Ut.prototype.fetchSnapshot=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new QU(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},Ut.prototype.fetchSnapshotByTimestamp=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new JU(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},Ut.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},Ut.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},Ut.prototype._initializeHandshake=function(){this.send({a:ye.handshake,id:this.id})},Ut.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},Ut.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},Ut.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new eu(ud.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(rT.map[n.type]!==rT.defaultType)return this.emit("error",new eu(ud.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new eu(ud.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},Ut.prototype.getPresence=function(n){var t=this,e=Ri.digOrCreate(this._presences,n,function(){return new YU(t,n)});return e._wantsDestroy=!1,e},Ut.prototype.getDocPresence=function(n,t){var e=eT.channel(n,t),r=this,i=Ri.digOrCreate(this._presences,e,function(){return new eT(r,n,t)});return i._wantsDestroy=!1,i},Ut.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var r={a:n,ch:e.channel,seq:t};return this.send(r),r.seq},Ut.prototype._addPresence=function(n){Ri.digOrCreate(this._presences,n.channel,function(){return n})},Ut.prototype._handlePresenceSubscribe=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},Ut.prototype._handlePresenceUnsubscribe=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},Ut.prototype._handlePresence=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},Ut.prototype._handlePresenceRequest=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var sT=tO,nO=ed;const fd={err:1001,msg:"user auth error",name:"AuthError"},Cm={err:1002,msg:"you don't have required permission",name:"PermissionError"},PC={err:1003,msg:"Too many user connected",name:"MaxUserError"},dd={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},rO={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},iO={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},ba="x-live-editor-token",nu="x-live-editor-base-url",En=D("auth-connection");function oO(n){try{n()}catch(t){En.error(t)}}class sO{constructor(t,e){m(this,"enabled",!0);m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new kb.EventEmitter);m(this,"token",null);m(this,"resourceToken",null);m(this,"pingOptions",{interval:5e4,timeout:15e4});m(this,"reAuth",async()=>{if(!this.enabled||!this.connection||!this.reauthFunc)return;if(window.isReauthError&&yr.level===Gi.DEBUG)throw new Error("reauth error");const t=await this.reauthFunc();await this.auth(t);const e=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:e}})}});this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return qi(this.getBaseURL())}async auth(t){p(En,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,r=await window.fetch(e,{method:"GET",headers:{[ba]:t.token,[nu]:this.getBase64BaseURL()},credentials:"include"});return r.status,this.enabled?(this.token=t.token,await r.json()):{read:"",user:""}}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[nu]:qi(this.getBaseURL())}})}async init(t){const e=await this.auth(t);if(!this.enabled)return;this.resourceToken=e.read,this.ws=new c9.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(sT.prototype),p(En,this.connection,"no this.connection");const r=this.ws,i=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:i}}),this._ping==null&&(this._ping=window.setInterval(()=>{var d;const c=Date.now();c-((d=this.lastReceiveTime)!=null?d:0)>i.interval&&this.send({a:"ping",id:this.id,ts:c}),this.lastReceiveTime&&c-this.lastReceiveTime>i.timeout&&r&&r.readyState===r.OPEN&&(r.reconnect(),this.lastReceiveTime=Date.now())},1e3))};const o=this.connection.handleMessage.bind(this.connection);let s=!1;this.connection.handleMessage=l=>{var d;const c=l;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in c||c.a==="pong")s=!1,this.handleMessage(c);else{Object.prototype.hasOwnProperty.call(c,"a")&&c.a==="hs"&&this.retryCount>0&&(s?(En.info("retrying re-auth success"),s=!1,this.emitAuthRecover()):s=!0),Object.prototype.hasOwnProperty.call(c,"a")&&c.a!=="init"&&c.a!=="hs"&&(this.retryCount=0);try{o(c)}catch(h){if((h==null?void 0:h.type)==="writeConflict"){this.emitWriteConflictError(h,c);return}if((d=h==null?void 0:h.message)!=null&&d.startsWith("Cannot invert subtype")){this.emitWriteConflictError(h,c);return}throw h}}},sT.apply(this.connection,[this.ws])}async reConnect(t){var r,i;(r=this.ws)==null||r.close();const e=this.pingOptions;if(this.connection&&this.reauthFunc){const o=await this.reauthFunc();await this.auth(o),(i=this.ws)==null||i.reconnect(),this.connection._initializeHandshake=function(){t&&(o.token=t),this.send({a:"hs",id:this.id,auth:o,options:{ping:e}})}}}async _autoReAuth(){this.retryCount+=1,En.info(`retrying re-auth attempt no. ${this.retryCount}`);try{await this.reAuth()}catch(t){En.error(t),this.retryCount>=5&&(En.warn("retry auth times exceed 5, broadcast auth error"),this.emitAuthError());const e=30*1e3;await new Promise((r,i)=>{setTimeout(()=>{this._autoReAuth().then(r).catch(i)},Math.min(2*this.retryCount*1e3,e))})}}async autoReAuth(){var t,e;if(!this.enabled||this.retryCount>0){En.debug("autoReAuth: not enabled or retryCount > 0");return}En.log("autoReAuth begin!"),(t=this.ws)==null||t.close(),await this._autoReAuth(),En.log("autoReAuth end!"),(e=this.ws)==null||e.reconnect()}async handleAuthError(){this.autoReAuth()}emitPermissionError(){const t=new Error(Cm.msg);t.code=Cm.err,this.events.emit("error",t)}emitAuthRecover(){this.events.emit("authRecover")}emitAuthError(){const t=new Error(fd.msg);t.code=fd.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(dd.msg);t.code=dd.err,this.events.emit("requestReloadError",t)}emitWriteConflictError(t,e){t.orgMsg=e,this.events.emit("writeConflictError",t)}emitMaxUsersError(){this.events.emit("maxUsersError"),this.end(!1)}handleMessage(t){const e=t;if(e.a==="pong")return;const r=e.err;if(r===fd.err)En.warn("auth error"),this.handleAuthError();else if(r===PC.err)En.warn(PC.msg),this.emitMaxUsersError();else if(r===dd.err){En.warn(dd.msg);try{this.emitRequestReloadError()}catch(i){En.error(`error occurred while process reload error: ${JSON.stringify(i)}`)}finally{this.end(!1)}}else r===Cm.err?this.emitPermissionError():(En.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError())}get(t,e){return p(En,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(p(En,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onAuthError(t){this.events.addListener("error",t)}onAuthRecover(t){this.events.addListener("authRecover",t)}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){p(En,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){p(En,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e,r;this.enabled=!1,this.reauthFunc=void 0,this.events.removeAllListeners(),oO(()=>{var i;return(i=this.connection)==null?void 0:i.close()}),(e=this.connection)!=null&&e._ping&&window.clearInterval(this.connection._ping),this.connection=void 0,(r=this.ws)==null||r.close(),this.ws=void 0,t&&this.logout()}}D("utils/file");function lO(){function n(){return new Promise(t=>{const e=new FileReader;e.onload=()=>{t(e.result)},e.readAsArrayBuffer(this)})}File.prototype.arrayBuffer=File.prototype.arrayBuffer||n,Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||n}lO();async function aO(n){const e=n.size,r=Math.floor((e+102400-1)/102400),i=new u9.Hash;for(let s=0;s<r;s++){const l=s*102400;let c=l+102400;c>e&&(c=e);const h=await n.slice(l,c,n.type).arrayBuffer();i.update(new Uint8Array(h))}const o=i.digest();return qi(o)}const so=D("sharedb-doc/client"),cO=Rb.default.create();class uO{constructor(t,e,r){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",it());m(this,"getDoc",async()=>{const t=r=>new Promise((i,o)=>{r.fetch(s=>{s?o(s):i()})});p(so,!this.doc,"This websocket has opened a doc."),await this.connection.init(this.auth);const e=this.connection.get(this.auth.appId,this.auth.docId);return this.doc=e,await t(e),so.debug(e),e});this.auth=t;const i=`${e}/${this.auth.appId}/${this.auth.docId}`;nO.register(n0.type),this.connection=new sO(i,r),this.reauthFunc=r}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(so,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,r=>{(t==="error"||this.doc)&&e(r)})}onAuthError(t){this.connection.onAuthError(t)}onAuthRecover(t){this.connection.onAuthRecover(t)}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,r,i,o){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...o},data:{name:r,size:i}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const r=`${this.apiServer()}/resources`;try{const i=`${r}/hash`,o=await this.request(i,{method:"post",headers:{[ba]:this.connection.token},data:{resources:t}});return o.data&&Array.isArray(o.data)?o.data:[]}catch{return[]}}async uploadFile(t,e,r,i,o){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=A=>{so.info(`on progress: ${A.loaded}`);let v=A.loaded*100/s;v>100&&(v=100),i(v)},c=await aO(e),d=await this.getFileUrlByHash(t,c,e.name,e.size,r);if(d)return i(-1),d;let h=t;o!=null&&o.thumbnail&&(h+="/thumbnail");const C=new FormData;C.append("file-size",`${e.size}`),C.append("file-hash",c),C.append("file",e,e.name);const E=await this.request(h,{method:"post",data:C,withCredentials:!0,headers:{...r},onUploadProgress:l});return so.info(E),i(100),Array.isArray(E.data)?E.data[0]:E.data}async uploadResource(t,e=()=>{},r){const o=`${this.apiServer()}/resources`;p(so,this.connection.token,"no connection token");const s=await this.uploadFile(o,t,{[ba]:this.connection.token},e,r);return p(so,s,"no result"),s}async request(t,e){var o,s;let r=this.connection.token,i;for(let l=0;l<2;l++){const c=e||{};c.url=t,c.headers||(c.headers={}),p(so,r,"no token"),c.headers={...c.headers,[ba]:r,[nu]:this.connection.getBase64BaseURL()};try{if(window.isReauthError&&yr.level===Gi.DEBUG)throw new Error("reauth error");return await cO(t,c)}catch(d){if(i=d,((o=d==null?void 0:d.response)==null?void 0:o.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;r=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw p(so,i,"no error"),i}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=wb.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(so,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const r=`${this.apiServer()}/resources/external/${qi(t)}`;return(await this.request(r)).data}getResourceId(t){const e=/\/resources\/([^?]+)/,r=t.match(e);return r&&r.length>=2?r[1]:""}buildResourceUrl(t,e){var s,l;if(!t)return"";if(t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;const r=this.apiServer();if(t.startsWith("http:")||t.startsWith("https:")){const c=r.replace(/\/[^/]*$/,"");if(c&&t.includes(c)){const d=this.auth.docId,h=`${c}/`,C="/resources",E=t.indexOf(h),A=t.indexOf(C,E+h.length);if(E!==-1&&A!==-1){const v=t.substring(E+h.length,A);if(v!==d){let w=t.replace(v,d);const S=new URL(w),U="token";(s=S.searchParams)==null||s.delete(U),w=S.toString();const M=this.getResourceId(w);return e!=null&&e.syncNewResources&&((l=e==null?void 0:e.syncNewResources)==null||l.call(e,M,w)),w}return t}return t}return t}let i=`${r}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken&&o.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const c=o.join("&");i+=`?${c}`}return i}reAuth(t=!1){t?this.connection.autoReAuth():this.connection.reAuth()}}function fO(){return{blocks:[{id:it(),type:"text",text:[]}],comments:{},meta:{}}}const FC=D("block-ids");class dO{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((i,o)=>o-i);for(let i=0;i<e.length;i++){const o=e[i];if(o>=t){const s=this.ids.get(o);p(FC,s!==void 0,"old id is not exists"),this.ids.delete(o),this.ids.set(o+1,s)}}const r=it();this.ids.set(t,r)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((r,i)=>r-i);for(let r=0;r<e.length;r++){const i=e[r];if(i>t){const o=this.ids.get(i);p(FC,o!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i-1,o)}}}getId(t){let e=this.ids.get(t);return e||(e=it(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class hO{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new dO,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let r=0;r<e.length;r++){const i=e[r],o=i[1].getById(t);if(o)return{containerId:i[0],blockIndex:o[0]}}return p(FC,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class lT{constructor(t=new Set,e=new Map){this.deletedKeys=t,this.insertedValues=e}insert(t,e){this.insertedValues.set(t,e)}delete(t){this.deletedKeys.add(t)}toDocBlockDelta(){const t={};return this.insertedValues.forEach((e,r)=>{t[r]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const KC=D("op-parse-handler");class mO{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const r={...t,containerId:(i=>i==="blocks"?"root":i)(t.containerId)};this.actions.push(r)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,r){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:r})}onDeleteBlockData(t,e,r){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:r})}onInsertBlockData(t,e,r,i){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:r,value:i})}onUpdateBlockText(t,e,r){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:r})}onDeleteContainer(t){this.pushActions({type:"deleteContainer",containerId:t})}onCreateContainer(t,e){this.pushActions({type:"createContainer",containerId:t,data:e})}onDeleteComment(t){this.pushActions({type:"deleteComment",commentId:t})}onCreateComment(t){this.pushActions({type:"createComment",commentId:t})}onUpdateComment(t){this.pushActions({type:"updateComment",commentId:t})}end(){const t=this.actions,e=new Set,r=new Map,i=new hO,o=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of o)if(s.type==="deleteBlock"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);i.onDeleteBlock(l.containerId,l.blockIndex);const d=r.get(c);d&&(KC.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),r.delete(c));const h=`${l.containerId}-${l.blockIndex}`;e.add(h),this.outerHandler.onDeleteBlock(l.containerId,l.blockIndex,this.local)}else if(s.type==="deleteBlockData"){const l=s,c=`${l.containerId}-${l.blockIndex}`;if(e.has(c)){KC.warn("delete block data after delete block, ignore it");continue}const d=i.getBlockId(l.containerId,l.blockIndex);let h=r.get(d);h||(h=new lT,r.set(d,h)),h.delete(l.key)}else p(KC,!1,`invalid action type, ${s.type}`);this.actions.forEach(s=>{if(s.type==="deleteContainer"){const l=s;this.outerHandler.onDeleteContainer(l.containerId,this.local)}else if(s.type==="deleteComment"){const l=s;this.outerHandler.onDeleteComment(l.commentId,this.local)}}),this.actions.forEach(s=>{if(s.type==="createContainer"){const l=s;this.outerHandler.onCreateContainer(l.containerId,l.data,this.local)}}),this.actions.forEach(s=>{if(s.type==="insertBlock"){const l=s;this.outerHandler.onInsertBlock(l.containerId,l.blockIndex,l.data,this.local)}else if(s.type==="insertBlockData"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);let d=r.get(c);d||(d=new lT,r.set(c,d)),d.insert(l.key,l.value)}else if(s.type==="updateBlockText"){const l=s;this.outerHandler.onUpdateBlockText(l.containerId,l.blockIndex,l.richTextData,this.local)}else if(s.type==="createComment"){const l=s;this.outerHandler.onCreateComment(l.commentId,this.local)}else if(s.type==="updateComment"){const l=s;this.outerHandler.onUpdateComment(l.commentId,this.local)}}),Array.from(r.entries()).forEach(([s,l])=>{const{containerId:c,blockIndex:d}=i.getBlockIndexById(s);this.outerHandler.onUpdateBlockData(c,d,l.toDocBlockDelta(),this.local)})}}const cn=D("op-parser");class aT{}class VC{constructor(t){m(this,"key");this.key=t}}function gO(n,t,e){const r=t.concat(),i=r[0];if(typeof i!="number"||(r.shift(),r.length===1))return!1;const o=r[0];if(typeof o!="object"||!o.i||Object.keys(o).length!==1)return!1;for(let l=1;l<r.length;l++){const c=r[l];if(!Array.isArray(c)||c.length!==2||typeof c[0]!="string")return!1;const h=c[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=o.i;p(cn,s.id,"block id is required"),p(cn,s.type,"block type is required");for(let l=1;l<r.length;l++){const c=r[l],d=c[0],h=c[1];s[d]=h.i}return e.onInsertBlock(n,i,s),!0}function $C(n,t,e,r){if(e==="upsert"&&gO(n,t,r))return;p(cn,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const i=t.concat(),o=i[0];i.shift();const s=[];for(;i.length>0;){const l=i[0];if(l==="text"){const c=i[1];if(p(cn,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),p(cn,c.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),i.splice(0,2),e==="upsert"){const h=c.e;r.onUpdateBlockText(n,o,h)}p(cn,i.length===0,`invalid block ops.length !== 0, ${JSON.stringify(i)}`)}else if(Array.isArray(l)){p(cn,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];p(cn,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const d=l[1];if(c==="text"){if(p(cn,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&r.onInsertBlockData(n,o,c,d.i),d.r&&e==="remove"&&r.onDeleteBlockData(n,o,c),d.et==="rich-text"&&e==="upsert"){const C=d.e;r.onUpdateBlockText(n,o,C)}}else e==="remove"&&d.r&&s.push(new VC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i);i.shift()}else if(typeof l=="object"){const c=l;e==="remove"&&c.r&&s.push(new aT),e==="upsert"&&c.i&&r.onInsertBlock(n,o,c.i),i.shift()}else{p(cn,typeof l=="string","data is not string"),p(cn,l!=="text","data !== 'text'"),p(cn,i.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(i)}`);const c=l,d=i[1];e==="remove"&&d.r&&s.push(new VC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i),i.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof aT?r.onDeleteBlock(n,o):l instanceof VC?r.onDeleteBlockData(n,o,l.key):p(cn,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function pO(n,t,e){cn.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function CO(n,t,e){const r=n[1],i=n[2];p(cn,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),p(cn,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?cn.error(`unknown comment op, ${JSON.stringify(n)}`):i.i&&i.r?t==="upsert"&&e.onUpdateComment(r):i.i?t==="upsert"&&e.onCreateComment(r):i.r?t==="remove"&&e.onDeleteComment(r):cn.error(`unknown comment op, ${JSON.stringify(n)}`)}function HC(n,t,e){const r=n[0];if(Array.isArray(r)){r.forEach(s=>{HC(s,t,e)});return}const i=r;if(p(cn,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){pO(n);return}if(i==="comments"){CO(n,t,e);return}const o=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{$C(o,s,t,e)}):n.slice(1).forEach(s=>{$C(o,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(o),s.i&&t==="upsert"&&e.onCreateContainer(o,s.i)}else p(cn,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),$C(o,n.slice(1),t,e)}function jC(n,t,e){const r=new mO(t,e);for(let i=0;i<2;i++){const o=i===0?"remove":"upsert",s=Et.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{HC(c,o,r)}):HC(s,o,r)}r.end()}const EO=D("sharedb-comments");function zC(n){const t=n.blocks;p(EO,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([r,i])=>{Array.isArray(i)&&(e.blocks[r]=i)}),Et.default(e)}function cT(n){const{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}=n;return{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}}function GC(n,t){const e=JM(t),{comments:r,meta:i,blocks:o,...s}=e,l={...n,blocks:o,...s},c=Et.default(l);return delete c.children,c}const Ae=D("sharedb-doc/doc-container"),uT="ot-json1";n0.type.registerSubtype(ZM.type),n0.type.name=uT,n0.type.invert=null;class hd extends Lc{constructor(e,r,i=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new YM);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)})});m(this,"handleReset",async e=>{const r=new Error(`reset doc: ${e}`);r.code="ResetDoc",this.callbacks.forEach(i=>{var o;return(o=i.onError)==null?void 0:o.call(i,r)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,r,i)=>{const o=[e,r,{i}];return this.submitOp(o)});m(this,"deleteObject",async(e,r)=>{const i=[e,r,{r:!0}];return this.submitOp(i)});m(this,"replaceObject",async(e,r,i)=>{const o=[e,r,{r:!0,i}];return this.submitOp(o)});m(this,"updateObject",async(e,r,i)=>{const o=this.data()[e][r],s=[e,r];return Object.entries(i).forEach(([l,c])=>{if(!Cf.default(o[l],c))if(o[l]===void 0){if(c!=null){const d={i:c};s.push([l,d])}}else if(c==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:c};s.push([l,d])}}),Object.entries(o).forEach(([l,c])=>{if((i[l]===void 0||i[l]===null)&&c!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const r={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(r)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((r,i)=>{if(this.destroyed){Ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},o=>{o?(Ae.error(`invalid op, ${o.message}, ${JSON.stringify(e)}`),i(o),Ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):r()}),this.doc.data||(Ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((r,i)=>{this.doc.create(e,uT,o=>{o?i(o):r()})}));m(this,"submitInsertChildContainers",async e=>{if(e.length===0)return Promise.resolve();const r=e.map(({containerId:i,blocks:o})=>[ts(i),{i:o}]);return this.submitOp([r])});m(this,"submitDeleteChildContainer",async e=>{const r=[ts(e),{r:!0}];return this.submitOp(r)});m(this,"submitInsertBlock",async(e,r,i)=>{const o=[ts(e),r,{i}];return this.submitOp(o)});m(this,"submitDeleteBlock",async(e,r)=>{const i=[ts(e),r,{r:!0}];return this.submitOp(i)});m(this,"submitUpdateBlockData",async(e,r,i)=>{if(i.delete.length===0&&Object.keys(i.insert).length===0)return Promise.resolve();const o=[ts(e),r],s=new Set(i.delete);Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c)){const h={r:!0,i:d};o.push([c,h])}});const l=new Set(Object.keys(i.insert));return i.delete.forEach(c=>{if(l.has(c))return;const d={r:!0};o.push([c,d])}),Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c))return;const h={i:d};o.push([c,h])}),this.submitOp(o)});m(this,"submitUpdateRichText",async(e,r,i)=>{const o=[ts(e),r,"text",{e:i,et:"rich-text"}];return this.submitOp(o)});m(this,"handleOp",(e,r,i)=>{if(!e){Ae.warn("handleOp: no ops");return}if(this.destroyed){Ae.warn("handleOp: destroyed");return}try{jC(e,this,!!r)}catch(o){throw Ae.error(o),o}});this.client=e,this.doc=r,this.doc.preventCompose=!0,this.disableLogout=i,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,p(Ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const r=new uO(e.auth,e.serverUrl,e.reauthFunc);r.onMaxUsersError(()=>{var s;return(s=e.onMaxUsersError)==null?void 0:s.call(e)});const i=await r.getDoc(),o=new hd(r,i,e.disableLogout);if(i.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await o.createDoc(e.templateData||fO())}return await o.initPresence(),await o.subscribe(),o.initEvents(),o}catch(r){throw Ae.error(r),Ae.error(`failed to load doc: ${JSON.stringify(r)}`),r}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onAuthError(e=>{this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}),this.client.onAuthRecover(()=>{this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,r)=>{if(this.localPresence)e();else{const i=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);i.on("receive",(o,s)=>{this.onCustomMessage(s)}),i.subscribe(o=>{o?r(o):(this.localPresence=i.create(it()),e())})}})}subscribe(){return new Promise((e,r)=>{this.doc.subscribe(i=>{i?r(i):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return Zo(this.data())}getContainerBlocks(e){const r=this.data();p(Ae,r,"no doc data");const i=r[ts(e)];return p(Ae,i,`no container data: ${e}`),Et.default(i)}findContainerBlocks(e){const r=this.data();p(Ae,r,"no doc data");const i=r[ts(e)];return i!=null?i:null}getBlockData(e,r){const i=this.data();p(Ae,i,"no doc data");const o=i[ts(e)];p(Ae,o,`no container data: ${e}`);const s=o[r];return p(Ae,s,`no block data: ${r}`),Et.default(s)}localInsertBlock(e,r,i){return this.submitInsertBlock(e,r,i),this.getBlockData(e,r)}localDeleteBlock(e,r){const i=this.getBlockData(e,r);return this.submitDeleteBlock(e,r),i}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(Ae,o.text,"no block text");const s=Et.default(o.text);this.submitUpdateRichText(e,r,i);const l=Hn.apply(s,i);return p(Ae,l,"no block text"),l}localUpdateBlockData(e,r,i){const o=Et.default(this.getBlockData(e,r));return this.submitUpdateBlockData(e,r,i),o}localInsertChildContainers(e){this.submitInsertChildContainers(e)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(r=>{this.submitDeleteChildContainer(r)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(r=>cT(r))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const r=this.data().comments[e];return zC(r)}localCreateComment(e,r){const i=GC(e,r),s=["comments",i.id,{i}];return this.submitOp(s)}localDeleteComment(e){const r=["comments",e,{r:!0}];return this.submitOp(r)}localUpdateComment(e,r){const i=GC(e,r),o=["comments",e.id,{r:!0,i}];return this.submitOp(o)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,r,i){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onDeleteBlock)==null?void 0:s.call(o,Zc(e),r,i)})}onInsertBlock(e,r,i,o){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Zc(e),r,i,o)})}onUpdateBlockData(e,r,i,o){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Zc(e),r,i,o)})}onUpdateBlockText(e,r,i,o){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Zc(e),r,i,o)})}onDeleteContainer(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),p(Ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,Zc(e),r)})}onCreateContainer(e,r,i){p(Ae,this.callbacks.length>0,"no callbacks"),p(Ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,Zc(e),r,i)})}onDeleteComment(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteComment)==null?void 0:o.call(i,e,r)})}onCreateComment(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onCreateComment)==null?void 0:o.call(i,e,r)})}onUpdateComment(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onUpdateComment)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){const r=e;(r==null?void 0:r.type)==="custom"&&(r==null?void 0:r.clientId)!==this.client.clientId?this.callbacks.forEach(i=>{var o;return(o=i.onCustomMessage)==null?void 0:o.call(i,r.data)}):(r==null?void 0:r.type)==="onlineUsers"&&setTimeout(()=>{const i={type:"custom",data:e,clientId:"-"};this.onCustomMessage(i)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}async addResources(e){let r=[];return e.forEach(o=>{const s=o.split("|");r.push(...s)}),r=Array.from(new Set(r)),await this.client.getFileUrlsByHashes(r)}async uploadResource(e,r){var o;return{resourceId:await this.client.uploadResource(e,(o=r==null?void 0:r.onProgress)!=null?o:()=>{})}}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}request(e,r){return this.client.request(e,r)}getUser(){const e=this.client.clientId,{permission:r,userId:i,displayName:o,avatarUrl:s}=this.client.auth;return{permission:r,clientId:e,userId:i,displayName:o,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return Zo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return Zo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:Zo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:Zo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,r){jC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}triggerReAuth(e=!1){this.client.reAuth(e)}}D("remote-cursor");class fT{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",Ne.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const r=this.editor.findBlockById(e);r&&this.editor.reloadBlock(r)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const dT=D("remote-cursor-decorator");class WC{decorateText(t,e,r){const i=t.doc.getRemoteUsers();if(!i)return{};const o=new Map,{containerId:s,blockIndex:l}=e[e.length-1];p(dT,typeof s=="string","invalid path containerId"),p(dT,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),d=$n(r);return i.getSimpleCursors(c.id).forEach((C,E)=>{E>d&&(E=d);const A=C.map(w=>({id:it(),type:"remote-cursor",name:w.user.displayName,time:w.time,rainbowIndex:w.user.rainbowIndex})),v=o.get(E);v?v.push(...A):o.set(E,A)}),{insertions:o}}}const qC=D("sharedb-doc/share-db-server"),AO=Rb.default.create();class xO{constructor(t,e){m(this,"auth");m(this,"clientId",it());this.serverUrl=e,this.auth=t}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(qC,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}apiServer(){const t=`${this.serverUrl}/${this.auth.appId}/${this.auth.docId}`;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}getBaseURL(){const t=new URL(this.apiServer());return`${t.protocol}//${t.host}${t.pathname}`}getBase64BaseURL(){return qi(this.getBaseURL())}async request(t,e){var o;const r=this.auth.token,i=e||{};i.url=t,i.headers||(i.headers={}),p(qC,r,"no token"),i.headers={...i.headers,[ba]:r,[nu]:this.getBase64BaseURL()};try{return await AO(t,i)}catch(s){throw(o=s.response)!=null&&o.data&&(s.responseData=s.response.data),s}}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=wb.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(qC,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}buildResourceUrl(t,e){if(!t)return"";if(t.startsWith("https:")||t.startsWith("http:")||t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;let i=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken,e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const s=o.join("&");i+=`?${s}`}return i}}const bO=D("sharedb-doc/share-db-server");function hT(n){const t=new URL(n);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}function vO(n){return qi(hT(n))}class Em extends Lc{constructor(e){super();m(this,"remoteUsers",new td);m(this,"client");this.options=e,this.client=new xO(e.auth,e.serverUrl)}destroy(){}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}getRemoteUsers(){return this.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return Zo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return Zo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:Zo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:Zo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}parseHistoryData(e,r){jC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}static async auth(e,r){p(bO,e.token,"no auth token");const i=`${hT(r)}/auth`,o=await window.fetch(i,{method:"GET",headers:{[ba]:e.token,[nu]:vO(r)},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return await o.json()}static async load(e){const r=`${e.serverUrl}/${e.auth.appId}/${e.auth.docId}`;return await this.auth(e.auth,r),new Em(e)}}class mT extends Ve.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,r){if(re(Ci(this.editor,t)))return;const i=this.editor.getBlockByIndex(t,e),o=et(this.editor.getContainerById(t));o&&this.emit("change",this.editor,{containerId:t,blockIndex:e},o,i,r)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}onInsertBlock(t,e){re(Ci(this.editor,t))||this.emit("insert",this.editor,{containerId:t,blockIndex:e})}onDeleteBlock(t,e){this.handleChild(t,e,"remove")}destroy(){this.editor.doc.unregisterCallback(this)}}function gT(n,t){const e=n.addCustom("child-block-tracker",()=>new mT(n));e.addListener("change",t),e.addListener("insert",t)}function pT(n,t){const e=n.addCustom("child-block-tracker",()=>new mT(n));e.removeListener("change",t),e.removeListener("insert",t)}const Wlt="",BO={colorPalette:{colorDesc:"\u5B57\u4F53\u989C\u8272",name:"\u6587\u672C\u989C\u8272",backgroundDesc:"\u80CC\u666F\u989C\u8272",reset:"\u6062\u590D\u9ED8\u8BA4"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}},yO={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},TO={colorPalette:{colorDesc:"\u30D5\u30A9\u30F3\u30C8\u306E\u8272",name:"\u30C6\u30AD\u30B9\u30C8\u306E\u8272",backgroundDesc:"\u80CC\u666F\u8272",reset:"\u30C7\u30D5\u30A9\u30EB\u30C8\u306B\u623B\u3059"},search:{emptyTips:"\u691C\u7D22\u7D50\u679C\u304C\u3042\u308A\u307E\u305B\u3093"}};_.mergeLang({"zh-CN":BO,"en-US":yO,"ja-JP":TO});const qlt="";D("button");function Zr(n,t,e,r,i){const o=B("button",["editor-button"],null);return o.setAttribute("data-button-id",n),i&&o.setAttribute(`data-editor-tooltip-${i}`,t),e?typeof e=="string"?e.startsWith("<")?o.innerHTML=e:o.innerText=e:o.appendChild(e):o.innerText=t,r&&(r.indexOf("checked")!==-1&&q(o,"checked"),r.indexOf("disabled")!==-1&&(o.disabled=!0),r.indexOf("primary")!==-1&&q(o,"primary")),o}const Xlt="",Am=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
31
+ `)}return yf([{type:"text/plain",data:new Blob([r],{type:"text/plain"})}]),!0}const hM=Object.freeze(Object.defineProperty({__proto__:null,editorHandleEnter:ty,editorHandleDelete:ey,editorHandleBackspace:ny,editorHandleInsertBr:ry,editorHandlePastePlainText:iy,isSelectedCodeTextBlock:oy,getSelectedCodeBlockMarkdown:sy,editorHandleCopyMarkdown:BC},Symbol.toStringTag,{value:"Module"})),sm={ArrowDown:p5,ArrowUp:g5,ArrowLeft:h5,ArrowRight:m5,"Shift+ArrowDown":C5,"Shift+ArrowUp":x5,"Shift+ArrowLeft":E5,"Shift+ArrowRight":A5,"CtrlOrCmd+ArrowLeft":v5,"CtrlOrCmd+ArrowRight":B5,"CtrlOrCmd+Shift+ArrowLeft":y5,"CtrlOrCmd+Shift+ArrowRight":T5,"CtrlOrCmd+ArrowUp":k5,"CtrlOrCmd+ArrowDown":mC,"CtrlOrCmd+Shift+ArrowUp":R5,"CtrlOrCmd+Shift+ArrowDown":gC,"CtrlOrCmd+A":pC,Home:_5,End:M5,"Shift+Home":I5,"Shift+End":D5,PageUp:F5,PageDown:K5,"Shift+PageUp":$5,"Shift+PageDown":H5,"CtrlOrCmd+Z":eM,"CtrlOrCmd+Shift+Z":nM,Enter:ty,Delete:ey,Backspace:ny,"Shift+Enter":ry,"CtrlOrCmd+Shift+V":iy,"CtrlOrCmd+Shift+C":BC};function ly(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function ay(n,t,e){if(t.type==="embed"){const o=t.embedData,s=o.src;if(s&&typeof s=="string"){const l=e.get(s);if(l)o.src=l;else{let c="";s.split("|").forEach(h=>{const C=e.get(h);C&&(c+=c?`|${C}`:`${C}`)}),c&&(o.src=c)}}return}const r=t.text;r&&r.forEach(o=>{if(o.attributes&&o.attributes.src&&typeof o.attributes.src=="string"){const s=e.get(o.attributes.src);s&&(o.attributes.src=s)}});const i=t.children;i&&i.forEach(o=>{n.blocks[o].forEach(l=>{ay(n,l,e)})})}function cy(n,t,e){if(e.size===0)return;t.blocks.root.forEach(i=>{const o=n.editorBlocks.getBlockClass(i.type);o.replaceResources?o.replaceResources(i,e):ay(t,i,e)})}async function mM(n,t){let e=t.filter(s=>s.indexOf(":")===-1);const r=[];e.forEach(s=>{const l=s.split("|");r.push(...l)}),e=Array.from(new Set(r)),e=r;const i=await n.doc.addResources(e),o=new Map;if(e.length!==i.length)return o;for(let s=0;s<e.length;s++)o.set(e[s],i[s]);return o}function gM(n,t){var l,c,d,h;const r=t.meta.serverId;if(!r||typeof r!="string")return!1;const i=(c=(l=n.doc).getServerMeta)==null?void 0:c.call(l);if(!i)return!1;const o=/.*(?=\/)/;return((d=(i.serverId||"").match(o))==null?void 0:d[0])===((h=r.match(o))==null?void 0:h[0])}async function yC(n,t){const r=t.meta.resources;if(!r||Object.keys(r).length===0)return;let i=new Map;if(gM(n,t)){const s=Array.from(Object.keys(r));i=await mM(n,s),cy(n,t,i)}const o=new Map;Object.entries(r).forEach(([s,l])=>{i.get(s)===void 0&&s!==l&&o.set(s,l)}),o.size!==0&&cy(n,t,o)}async function pM(n,t,e){await yC(n,t),n.undoManager.runInGroup(()=>{const{start:r,end:i}=n.selection.range,o=n.getBlockById(r.blockId);if(r.blockId===i.blockId&&Le(o)){const s=at(o),l=n.getBlockIndex(o),[c]=n.insertDocAt(s,l+1,t,e);c&&n.selection.selectBlock(c,Ct(n,c))}else{n.clearSelectedContents();const{block:s,offset:l}=Gc(n);n.insertDoc(s,l,t,e)}})}const CM=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function EM(n){let t;for(const e of CM)if(t=n[e],t)break;return t||null}class AM{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"hookExecutionAttempt",(t,e,r)=>{for(let i=0;i<this.handlers.length;i++){const o=this.handlers[i];if(o.handleBeforeCopy){const s=o.handleBeforeCopy(this.editor,e,r);if(s===!0)return!0;if(typeof s=="object"&&s!=null)return s}}});m(this,"onPasteText",async(t,e)=>{const r=new DataTransfer;r.setData("text/plain",t);const i=await this.editor.dataConverter.fromData(this.editor,r,e);if(i){const o=[];this.pasteDocs(i,null,o)}});m(this,"onBlur",Ne.default(()=>{const t=this.editor.selection.range;if(!t.isCollapsed()){let e=null;if(ha(t.anchor)){const r=t.anchor.childContainerId,i=Ci(this.editor,r);e=h3(this.editor,i)}else e=this.editor.getBlockById(t.anchor.blockId);if(e){let r=t.start;t.isSimple()||(r=ht(e,0,"normal")),this.editor.selection.setSelection(r,void 0,{noScroll:!0})}}this.removeActiveForBlur()},200));m(this,"removeActiveForBlur",Ne.default(()=>{ct(this.editor.rootElement,"active")},200));this.editor=t}onInsertText(t,e){if(!st(this.editor,this.editor.getFocusedBlock()))return;const{containerId:r,blockIndex:i,offset:o}=Gc(this.editor);this.handleBeforeInsertText(r,i,o,e)||(this.defaultInsertText(this.editor,r,i,o,e),this.handleAfterInsertText(r,i,o,e),this.editor.selection.updateLastCaretRect())}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleChanged&&r.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleRemoteChanged&&r.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){if(!st(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:r,offset:i}=Gc(this.editor);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,r,i)}}onUpdateCompositionText(t,e,r){if(!st(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText(e,r),this.editor.selection.caret.update();const{containerId:i,blockIndex:o,offset:s}=Gc(this.editor);for(let l=0;l<this.handlers.length;l++){const c=this.handlers[l];c.handleUpdateCompositionText&&c.handleUpdateCompositionText(this.editor,i,o,s,r)}this.editor.selection.updateLastCaretRect()}onCopy(t){uM(this.editor,t,this.hookExecutionAttempt)}onCopyWithoutEvent(){fM(this.editor,this.hookExecutionAttempt)}onCut(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeCut&&i.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const r=this.editor.selection.focusedBlock;Le(r)&&this.editor.deleteBlock(r)}else J0(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;const e=this.editor.dataConverter.fromData(this.editor,t.clipboardData),r=Array.from(t.clipboardData.files);e.then(async i=>{i&&this.pasteDocs(i,t,r)})}onFocus(){q(this.editor.rootElement,"active"),this.onBlur.cancel(),this.removeActiveForBlur.cancel()}addHandler(t){this.handlers.push(t),this.handlers=this.handlers.sort((e,r)=>{var s,l;const i=(s=e.order)!=null?s:1;return((l=r.order)!=null?l:1)-i})}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,r,i))return!0}return!1}handleAfterInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,r,i))return!0}return!1}handleBeforeKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,r,i,o){J1(this.editor,o)}defaultHandleKeydown(t,e){return ly(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePasteDoc&&await i.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map,boxIdMap:new Map};await pM(this.editor,t,e);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPasteDoc&&await i.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e,r){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforePaste&&await s.handleBeforePaste(this.editor,e,t,r))return}const i=EM(t);if(!!i){await this.pasteDoc(i);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterPaste&&await s.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}forEach(t){this.handlers.forEach(t)}}function xM(n,t,e){const r=Js(t,e);return r.remove(),r}D("copy-dom-attributes");const uy=["onabort","onanimationcancel","onanimationend","onanimationiteration","onanimationstart","onauxclick","onblur","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","ongotpointercapture","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onlostpointercapture","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onpause","onplay","onplaying","onpointercancel","onpointerdown","onpointerenter","onpointerleave","onpointermove","onpointerout","onpointerover","onpointerup","onprogress","onratechange","onreset","onresize","onscroll","onsecuritypolicyviolation","onseeked","onseeking","onselect","onselectionchange","onselectstart","onslotchange","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","ontransitioncancel","ontransitionend","ontransitionrun","ontransitionstart","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel"];function bM(n,t){for(let l=0;l<uy.length;l++){const c=uy[l];t[c]=n[c]}const e=n.attributes,r=t.attributes,i=[],o=[];for(let l=0;l<e.length;l++){const c=e[l],d=r.getNamedItem(c.name);d?d.value!==c.value&&(d.value=c.value,o.push(c)):i.push(c)}const s=[];for(let l=0;l<r.length;l++){const c=r[l];e.getNamedItem(c.name)||s.push(c)}i.forEach(l=>{t.setAttribute(l.name,l.value)}),o.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function fy(n){const t=Array.from(n.childNodes).filter(e=>!_v(e));return t.forEach(e=>{e.remove()}),t}function dy(n,t,e){var d;const r=n.getContainerById(t),i=Js(r,e),o=el(i),s=n.doc.getBlockData(t,e),l=le(n,i);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,i,s))n.editorBlockRenders.updateBlock(n,o,i,s);else{const h=n.editorBlocks.createBlock(o,r,s),C=fy(h);fy(i),C.forEach(A=>{i.appendChild(A)});const E=y0(h);if(E){const A=y0(i);A&&A.remove(),i.appendChild(E)}bM(h,i)}zv(n,i,s),n.blockHooks.forEach(h=>{var C;(C=h.update)==null||C.call(h,n,o,r,i,s)}),setTimeout(()=>{n.selection.updateSelection(null,{focusBlockChanged:!0})})}const vM=D("transform-selection");function hy(n,t,e,r){const{range:i}=n.selection,{anchor:o,focus:s}=i;if(o.blockId!==t&&s.blockId!==t)return i;p(vM,o.isSimple()&&s.isSimple(),"invalid text pos type");let l=o;if(o.blockId===t){const d=Hn.transformCursor(o.offset,e,r);l=ht(t,d,"normal")}let c=s;if(s.blockId===t){const d=Hn.transformCursor(s.offset,e,r);c=ht(t,d,"normal")}return Cn(n,{anchor:l,focus:c})}const BM=D("handle-block-text-changed");function yM(n,t,e,r,i){const o=n.getContainerById(t),s=Js(o,e),l=n.doc.getBlockData(t,e);if(p(BM,l.text,"no block text"),Sv(n,s).setBlockText(n,s,l.text),!i){const c=hy(n,l.id,r,i);n.selection.setRange(c,{noScroll:!0})}}function TM(n,t){const e=Et.default(n);return t.delete.forEach(i=>{delete e[i]}),{...e,...t.insert}}function my(n,t,e,r){const i=le(n,t);i.handleDeleteBlock&&i.handleDeleteBlock(n,t,e,r),n.emit("blockDeleted",n,t,e,r)}function kM(n,t,e,r){const i=n.getBlockByIndex(t,e);i.querySelectorAll('[data-type="editor-block"]').forEach(o=>{my(n,o,r,{child:!0})}),my(n,i,r,{child:!1})}const Bi=D("editor-doc");class RM extends Lc{constructor(e,r,i){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=r,this.externalDoc.registerCallback(this),this.registerLocalEvents(i)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var r,i;return(i=(r=this.externalDoc).getVersionHelper)==null?void 0:i.call(r)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}findContainerBlocks(e){return this.externalDoc.findContainerBlocks(e)}getBlockData(e,r){return this.externalDoc.getBlockData(e,r)}verifyBlockWritable(e,r){const i=this.editor.getBlockByIndex(e,r);p(Bi,this.editor.isBlockWritable(i),`block is not writable, ${e}, ${r}`)}localUpdateBlockText(e,r,i,o){p(Bi,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const s=this.getBlockData(e,r),l=s.text;p(Bi,l,`no text, ${e}, ${r}`);const c=hy(this.editor,s.id,i,!0),d=Hn.apply(l,i);this.localEvents.forEach(C=>C.onBeforeUpdateBlockText(e,s.id,l,d,c.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,r,i);return this.editor.selection.setRange(c,o),h}localUpdateBlockData(e,r,i,o,s){p(Bi,!this.editor.readonly,"editor is readonly");const l=this.editor.getBlockByIndex(e,r);if(!this.editor.isBlockWritable(l)){const C=Array.from(i.delete).filter(A=>A!=="comments"),E=Object.keys(i.insert).filter(A=>A!=="comments");(C.length>0||E.length>0)&&p(Bi,!1,`block is not writable, comment supported only, ${JSON.stringify(i)}}`)}const c=Et.default(this.getBlockData(e,r)),d=Et.default(TM(c,i));this.localEvents.forEach(C=>C.onBeforeUpdateBlockData(e,c.id,c,d,o));const h=this.externalDoc.localUpdateBlockData(e,r,i,o);return this.editor.selection.setRange(nl(this.editor,o),s),h}localInsertBlock(e,r,i,o,s){p(Bi,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(c=>c.onBeforeInsertBlock(e,r,i,o));const l=this.externalDoc.localInsertBlock(e,r,i,o);return s!=null&&s.noFocus||this.editor.selection.setRange(nl(this.editor,o),s),l}localDeleteBlock(e,r,i){p(Bi,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const o=Et.default(this.getBlockData(e,r));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,r,o,i));const s=this.externalDoc.localDeleteBlock(e,r,i);return this.editor.selection.setRange(nl(this.editor,i)),s}localDeleteChildContainers(e){return p(Bi,!this.editor.readonly,"editor is readonly"),e.forEach(r=>{const i=Et.default(this.getContainerBlocks(r));this.localEvents.forEach(o=>o.onBeforeDeleteChildContainer(r,i))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainers(e){p(Bi,!this.editor.readonly,"editor is readonly");const r=Et.default(e);r.forEach(i=>{this.localEvents.forEach(o=>o.onBeforeInsertChildContainer(i.containerId,i.blocks))}),this.externalDoc.localInsertChildContainers(r)}onRequestReload(e){Bi.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(i=>{var o;return(o=i.onRequestReload)==null?void 0:o.call(i,e)});const r=!1;this.editor.emit("docChanged",this.editor,r)}onUpdateBlockText(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,r,i,o)}),yM(this.editor,e,r,i,o),this.editor.emit("docChanged",this.editor,o)}onUpdateBlockData(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,o)}),dy(this.editor,e,r),this.editor.emit("docChanged",this.editor,o)}onInsertBlock(e,r,i,o){this.callbacks.forEach(l=>{var c;return(c=l.onInsertBlock)==null?void 0:c.call(l,e,r,i,o)});const s=this.editor.getContainerById(e);HI(this.editor,s,r,i),this.editor.emit("docChanged",this.editor,o)}onDeleteBlock(e,r,i){kM(this.editor,e,r,i),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,i)});const o=this.editor.getContainerById(e);xM(this.editor,o,r),this.editor.emit("docChanged",this.editor,i)}onInsertChildContainer(e,r,i){this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,e,r,i)})}onDeleteChildContainer(e,r){this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,e)})}onStatusChanged(e){this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)})}onError(e){this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}uploadResource(e,r){return this.externalDoc.uploadResource(e,r)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,r){return this.externalDoc.buildResourceUrl(e,r)}request(e,r){return this.externalDoc.request(e,r)}broadcastMessage(e){return this.externalDoc.broadcastMessage(e)}getUser(){return this.externalDoc.getUser()}getRemoteUsers(){return this.externalDoc.getRemoteUsers()}triggerReAuth(e=!1){var r,i;(i=(r=this.externalDoc).triggerReAuth)==null||i.call(r,e)}destroy(){this.externalDoc.destroy(),this.clearCallbacks()}getServerMeta(){var e,r,i;return(i=(r=(e=this.externalDoc).getServerMeta)==null?void 0:r.call(e))!=null?i:{}}reset(e){Bi.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function gy(n,t){if(n.length===0){n.push(t);return}const e=n[n.length-1];if(!e.combinable(t)){n.push(t);return}e.combine(t)}const lm=D("undo-action");class Jc{constructor(t,e,r){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=r}undo(t){return!1}redo(t){return!1}combinable(t){return p(lm,t,"no other action"),!1}combine(t){p(lm,!1,"no other")}setAfterRange(t){this.afterRange&&lm.warn("after range has already set"),this.afterRange=t}hasDocContainerId(t,e){return!!t.doc.findContainerBlocks(e)}findDocBlockById(t,e){const r=t.doc.findContainerBlocks(this.containerId);if(!!r)return r.find(i=>i.id===e)}checkBlockData(t,e){if(Array.isArray(e.children)){const r=t.doc.toJSON();for(let i=0;i<e.children.length;i++){const o=e.children[i];if(!r.blocks[o])return lm.warn(`container (${o}) not found, deleted by others?`),!1}}return!0}}const am=D("block-action");class py extends Jc{constructor(e,r,i,o,s){super(e,r,s);m(this,"blockData");m(this,"blockIndex");this.blockData=Et.default(o),this.blockIndex=i}deleteBlock(e,r){if(!this.hasDocContainerId(e,this.containerId))return am.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const o=e.findBlockById(this.blockData.id);return o?(Y0(e,o,nl(e,r)),!0):!1}insertBlock(e,r){return this.hasDocContainerId(e,this.containerId)?this.checkBlockData(e,this.blockData)?e.findBlockByIndex(this.containerId,Math.max(0,this.blockIndex-1))?e.findBlockById(this.blockData.id)?(am.warn(`block (${this.blockData.id}) already exists, inserted by others?`),!1):(qc(e,this.containerId,this.blockIndex,Et.default(this.blockData),r),!0):(am.warn(`block (${Math.max(0,this.blockIndex-1)}) not found, deleted by others?`),!1):!1:(am.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}}D("insert-block-action");class wM extends py{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class SM extends py{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class LM extends Jc{constructor(e){super(e,pt(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){gy(this.actions,e),this.afterRange=e.afterRange}undo(e){let r=!1;for(const i of this.actions.concat().reverse())if(i.undo(e))r=!0;else break;return r}redo(e){let r=!1;for(const i of this.actions)if(i.redo(e))r=!0;else break;return r}setAfterRange(e){this.afterRange=e;const r=this.actions[this.actions.length-1];!r||r instanceof Jc&&(r.afterRange||r.setAfterRange(e))}}const cl=D("update-block-data-action");class cm extends Jc{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=i,p(cl,this.blockId===o.id,"invalid block id"),p(cl,this.blockId===s.id,"invalid block id"),this.beforeBlockData=Et.default(o),this.afterBlockData=Et.default(s),p(cl,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){if(!e.findBlockById(this.blockId))return cl.warn(`block (${this.blockId}) not found, deleted by others?`),!1;const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(cl,i,"no container"),tm(e,r,cm.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){if(!e.findBlockById(this.blockId))return cl.warn(`block (${this.blockId}) not found, deleted by others?`),!1;p(cl,e,"no editor");const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(cl,i,"no container"),tm(e,r,cm.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const r=Et.default(e);return delete r.id,delete r.type,r}}const Aa=D("update-block-text-action");class Jf extends Jc{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=i,this.beforeRichTextData=Et.default(o),this.afterRichTextData=Et.default(s),this.type=Jf.calType(o,s)}static calType(e,r){p(Aa,e,"no old data"),p(Aa,r,"no new data");const o=Hn.diff(e,r),s=new Set;let l=!1;const c=h=>ev(h)?`cjk_${h}`:Zb(h)?"number":g0(h)?"space":tv(h)?"letter":"unknown";let d=!1;return o.forEach(h=>{h.insert?h.insert===" "?s.add("insert_letter"):typeof h.insert=="string"&&h.insert.startsWith(" ")&&h.insert.length>1?(l=!0,d=!0,s.add(`insert_${c(h.insert.substr(1))}`)):s.add(`insert_${c(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!this.hasDocContainerId(e,this.containerId))return Aa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findDocBlockById(e,this.blockId))return Aa.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Z0(e,i,this.beforeRichTextData),!0):!1}redo(e){if(!this.hasDocContainerId(e,this.containerId))return Aa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findDocBlockById(e,this.blockId))return Aa.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Z0(e,i,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof Jf)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const r=e.beforeRange,i=r.anchor;if(!i.isSimple())return!1;const o=this.afterRange;if(!o)return!1;const s=o.anchor;return!(!s.isSimple()||s.blockId!==r.anchor.blockId||s.offset!==i.offset)}combine(e){p(Aa,e instanceof Jf,"invalid action type");const r=e;this.afterRichTextData=r.afterRichTextData,this.afterRange=e.afterRange}}const Cy=D("child-container-action");class Ey extends Jc{constructor(t,e,r){super(t,e,t.selection.range.toDocRange()),this.blocks=r}deleteChildContainer(t){return this.hasDocContainerId(t,this.containerId)?(t.doc.localDeleteChildContainers([this.containerId]),!0):(Cy.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}insertChildContainer(t){return this.hasDocContainerId(t,this.containerId)?(Cy.warn(`container (${this.containerId}) already exists`),!1):(t.doc.localInsertChildContainers([{containerId:this.containerId,blocks:Et.default(this.blocks)}]),!0)}}class IM extends Ey{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class DM extends Ey{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Qn=D("undo");class _M{constructor(t){m(this,"editor");m(this,"actions",[]);m(this,"undoCursor");m(this,"currentGroup",null);m(this,"groupCounter",0);m(this,"undoRedoing",!1);m(this,"handleSelectionChange",t=>{if(this.currentGroup){this.currentGroup.setAfterRange(t.selection.range.toDocRange());return}const e=this.actions[this.actions.length-1];!e||e.afterRange||e.setAfterRange(t.selection.range.toDocRange())});this.editor=t,this.undoCursor=-1,this.editor.addListener("selectionChanged",this.handleSelectionChange)}reset(){this.actions=[],this.undoCursor=-1}prepareSaveUndoState(){this.undoCursor!==-1&&(this.actions.splice(this.undoCursor),this.undoCursor=-1)}addAction(t){this.currentGroup?this.currentGroup.addAction(t):(gy(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(p(Qn,!this.currentGroup,"current group already exists"),this.currentGroup=new LM(this.editor),this.groupCounter=1):(p(Qn,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){p(Qn,this.currentGroup,"current group not exists"),p(Qn,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Qn.warn("empty undo group, skip it"):(this.actions.push(this.currentGroup),this.editor.input.handleChanged(this.currentGroup)),this.currentGroup=null)}hasGroup(){return this.groupCounter>0}runInGroup(t){this.beginGroup();try{const e=t();return setTimeout(()=>this.editor.selection.caret.update()),e}catch(e){throw Qn.error(`failed to run action: ${e.message}`),e}finally{this.endGroup()}}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=Ct(this.editor,e)||p(Qn,!1,"invalid block position, out of range");else{const r=t.childContainerId;!!this.editor.getContainerById(r)||p(Qn,!1,"invalid complex block position, no container found")}}checkRange(){const{start:t,end:e}=this.editor.selection.range;try{this.verifyPos(t),this.verifyPos(e)}catch(r){Qn.error(`undo: failed to restore caret pos: ${r.message}`);const i=this.editor.getFirstBlock();this.editor.selection.setRange(Ie(this.editor,i,0),{noScroll:!0})}}undo(){this.undoCursor===-1&&(this.undoCursor=this.actions.length);try{for(this.undoRedoing=!0;this.undoCursor>0;){this.undoCursor-=1;const t=this.actions[this.undoCursor];if(t.undo(this.editor)){try{this.editor.selection.setRange(nl(this.editor,t.beforeRange))}catch(e){Qn.error(`undo: failed to restore caret pos: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}catch(t){return Qn.error(`failed to undo: ${t.message}`),!1}finally{this.undoRedoing=!1,this.checkRange()}}redo(){this.undoCursor===-1&&(this.undoCursor=this.actions.length);try{for(this.undoRedoing=!0;this.undoCursor<this.actions.length;){const t=this.actions[this.undoCursor];if(this.undoCursor+=1,t.redo(this.editor)){try{const e=t.afterRange;e?this.editor.selection.setRange(nl(this.editor,e)):Qn.warn("no after range")}catch(e){Qn.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1,this.checkRange()}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,r,i,o){this.undoRedoing||(this.prepareSaveUndoState(),Hn.diff(r,i).length!==0&&this.addAction(new Jf(this.editor,t,e,r,i,o)))}onBeforeUpdateBlockData(t,e,r,i,o){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new cm(this.editor,t,e,r,i,o);this.addAction(s)}onBeforeInsertBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),p(Qn,e>=0,"invalid block index"),p(Qn,r,"no block data"),this.addAction(new wM(this.editor,t,e,r,i)))}onBeforeDeleteBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new SM(this.editor,t,e,r,i)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new IM(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new DM(this.editor,t,e)))}}class MM{async fromData(t,e){const r=e.getData("text/x-ones-editor-doc");if(r)return{"text/x-ones-editor-doc":JSON.parse(r)}}}class UM{constructor(){m(this,"converters",[]);m(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new MM)}prepareData(t){const e=new DataTransfer;for(let r=0;r<this.converterTypes.length;r++)e.setData(this.converterTypes[r],t.getData(this.converterTypes[r]));return e}async fromData(t,e,r){let i={};const o=this.prepareData(e);for(const s of this.converters){const l=await s.fromData(t,o,r);l&&(i={...i,...l})}return i}addConverter(t){this.converters.push(t)}}function OM(n){n.editorBlocks.registerBlockClass(ar),n.editorBlocks.registerBlockClass(d3),n.editorBoxes.registerBoxClass(yB),n.editorBoxes.registerBoxClass(TB),n.editorBoxes.registerBoxClass(wB),n.editorBoxes.registerBoxClass(SB),n.editorInsertions.registerInsertionClass(LB),n.editorBlockRenders.registerRender(new Dv)}function NM(n,t){OM(n),t!=null&&t.blocks&&t.blocks.forEach(e=>n.editorBlocks.registerBlockClass(e)),t!=null&&t.boxes&&t.boxes.forEach(e=>n.editorBoxes.registerBoxClass(e)),t!=null&&t.embeds&&t.embeds.forEach(e=>n.editorEmbeds.registerEmbedClass(e)),t!=null&&t.insertions&&t.insertions.forEach(e=>n.editorInsertions.registerInsertionClass(e)),t!=null&&t.decorators&&t.decorators.forEach(e=>n.editorDecorators.registerDecorator(e)),t!=null&&t.dataConverters&&t.dataConverters.forEach(e=>n.dataConverter.addConverter(e)),t!=null&&t.commandProviders&&t.commandProviders.forEach(e=>n.editorCommandProviders.registerCommandProvider(e)),t!=null&&t.textRenders&&t.textRenders.forEach(e=>n.editorBlockRenders.registerRender(e))}const um=D("range-commands");function Ay(n,t){n.forEach(e=>{e.source=t,e.children&&Ay(e.children,t)})}function xy(n,t){n.forEach(e=>{e.group=t,e.children&&xy(e.children,t)})}function by(n,t,e,r){const i=ut(t);p(um,i===e.start.blockId,"invalid start range"),p(um,i===e.end.blockId,"invalid end range");const o=n.editorCommandProviders.getCommandProviders();let s=[];if(o.forEach(l=>{const c=l.getAvailableCommands(n,t,e);Ay(c,r),xy(c,l.id),s.push(...c)}),o.forEach(l=>{if(l.filterCommands){const c=l.filterCommands(n,t,e,s);c&&(s=c)}}),Pt(n,t)){if(!ha(e.start))return s;p(um,!e.start.isSimple(),"invalid start pos"),p(um,!e.end.isSimple(),"invalid end pos");const l=e.start.childContainerId,c=Ci(n,l),h=ke(c)[0];if(h){const C=Ct(n,h),E=Cn(n,{anchor:ht(h,0,"home"),focus:ht(h,C,"end")}),A=by(n,h,E,r);s.push(...A)}}return s}function vy(n,t){const e=n.getEditor(),r=n.getSelectedBlocks(),i=[],o=n.isReverse()?r[0]:r[r.length-1],s=Cn(e,{anchor:o.start,focus:o.end});return by(e,o.block,s,t).forEach(c=>{i.push(c)}),i}function By(n,t,e,r,i,o){var h;const s=n.editorCommandProviders.getCommandProviders();for(let C=0;C<s.length;C++){const E=s[C];if(E.beforeExecuteCommand&&E.beforeExecuteCommand(n,t,e,r,i))return!1}const l=n.editorCommandProviders.getCommandProvider(r.group),c={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,r,i,{}))return o[ut(t)]=c,!0;let d=!1;return Pt(n,t)&&Pc(n,t,e.start,e.end).forEach(E=>{ke(E).forEach(v=>{const w=Ct(n,v),S=Cn(n,{anchor:ht(v,0,"home"),focus:ht(v,w,"end")});By(n,v,S,r,i,o)&&(d=!0)})}),s.forEach(C=>{C.afterExecuteCommand&&C.afterExecuteCommand(n,t,e,r,i,o)}),d}function yy(n,t,e){const r=n.getEditor(),i={},o=r.editorCommandProviders.getCommandProvider(t.group);return o.executeRangeCommand&&o.executeRangeCommand(r,n,t,e,i)||(n.getSelectedBlocks().forEach(l=>{const c=Cn(r,{anchor:l.start,focus:l.end});By(r,l.block,c,t,e,i)}),r.focus()),i}const PM=D("command-providers");class Ty{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(r=>r.id===t);return p(PM,e,`no command provider, id=${t}`),e}getCommands(t,e){return vy(t,e)}executeCommand(t,e,r){return this.editor.emit("beforeExecCommand",this.editor,e,{source:e.source}),this.editor.undoManager.runInGroup(()=>yy(t,e,r))}getEmptyBlockTextAttributes(t,e){let r={};if(this.providers.forEach(i=>{var s;const o=(s=i.getEmptyBlockTextAttributes)==null?void 0:s.call(i,t,e);o&&(r={...r,...o})}),Object.keys(r).length!==0)return r}}function FM(n,t){const e=at(t),r=pt(e),i=Rt(t);dy(n,r,i)}const ky=D("update-block-text");function KM(n,t,e){const r=n.getBoxById(t.id),i=et(r);p(ky,i,"no parent block"),p(ky,st(n,i),"not a text block");const o=n.getBlockText(i),s=pB(o,"id",t.id,t);JB(n,i,s,e)}function VM(n,t){for(const e of n.blockHooks)if(e.writable){const r=e.writable(n,t);if(typeof r=="boolean")return r}return!0}function $M(n){if(n.readonly)return!1;const t=Zi(n);return!!n.isBlockWritable(t.map(e=>e.block))}class HM{constructor(t){this.editor=t}getKey(t){return`${this.editor.id}-${t}`}getItem(t){return window.localStorage.getItem(this.getKey(t))}setItem(t,e){if(!e){this.removeItem(t);return}window.localStorage.setItem(this.getKey(t),e)}removeItem(t){window.localStorage.removeItem(this.getKey(t))}}class jM{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const r=this.shortcuts;for(const i of r){const o=Object.entries(i);for(const[s,l]of o)if(Wi(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const Jo=D("editor");class zM extends Ve.TypedEmitter{constructor(e,r,i){var o,s,l,c,d,h,C,E,A;super();m(this,"parent");m(this,"rootElement");m(this,"contentElement");m(this,"rootContainerObject");m(this,"rootContainer");m(this,"input");m(this,"selection");m(this,"selectionHandler");m(this,"doc");m(this,"id");m(this,"clientId");m(this,"compositingText","");m(this,"undoManager");m(this,"shortcuts",new jM);m(this,"dataConverter",new UM);m(this,"editorBlocks",new a3(this));m(this,"editorBoxes",new RB(this));m(this,"editorInsertions",new DB(this));m(this,"editorEmbeds",new u3(this));m(this,"editorDecorators",new _B(this));m(this,"editorCommandProviders",new Ty(this));m(this,"editorBlockRenders",new _I(this));m(this,"blockHooks",[]);m(this,"domEvents",new j_(this));m(this,"customs",new Map);m(this,"options");m(this,"version","");m(this,"inputHandlers",new AM(this));m(this,"settingsProvider");m(this,"_readonly",!1);m(this,"getColor",e=>{const r=this.options.colors;return r.length===0?"#FF1A75":r[e%r.length]});Jo.debug("create editor"),this.setMaxListeners(100),this.options={colors:(o=i==null?void 0:i.colors)!=null?o:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"],componentsOptions:(l=(s=i==null?void 0:i.components)==null?void 0:s.options)!=null?l:{},scrollContainer:i==null?void 0:i.scrollContainer,enableComments:(c=i==null?void 0:i.enableComments)!=null?c:!0,enableContextMenu:(d=i==null?void 0:i.enableContextMenu)!=null?d:!0},this.settingsProvider=(h=i==null?void 0:i.settingsProvider)!=null?h:new HM(this),NM(this,i==null?void 0:i.components),this.blockHooks.push(...(E=(C=i==null?void 0:i.components)==null?void 0:C.blockHooks)!=null?E:[]),this.id=(A=i==null?void 0:i.id)!=null?A:it(),this.clientId=it(),this.undoManager=new _M(this),this.doc=new RM(this,r,this.undoManager),this.parent=e,this.rootElement=B("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=B("div",["editor-content"],this.rootElement),this.rootContainerObject=o3(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new c_(this,this.inputHandlers),this.selection=new Q_(this),this.selectionHandler=new tM(this),i!=null&&i.shortcuts&&this.shortcuts.shortcuts.push(...i.shortcuts),me.isMobile&&q(this.rootElement,"mobile"),me.isSafari&&q(this.rootElement,"safari"),this._readonly&&q(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?q(this.rootElement,"readonly"):ct(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:gn(this.rootContainer)}addCustom(e,r){const i=this.customs.get(e);if(i)return i;const o=r(this);return this.customs.set(e,o),o}getCustom(e){const r=this.customs.get(e);return p(Jo,r,`${e} does not exists`),r}replaceCustom(e,r){const i=this.customs.get(e);return i&&i.destroy(),this.customs.set(e,r),r}findCustom(e){return this.customs.get(e)}findCustomByType(e){const r=this.customs.values();for(const i of r)if(i instanceof e)return i;return null}destroyCustom(e){const r=this.customs.get(e);r&&(this.customs.delete(e),r.destroy())}getComponentOptions(e){return this.options.componentsOptions[e]}registerLocalEvents(e){this.doc.registerLocalEvents(e)}reload(){this.rootContainerObject.reload(),this.emit("load",this,!0)}createBlock(e,r,i){return this.editorBlocks.createBlock(e,r,i)}createBox(e,r){return this.editorBoxes.createBox(e,r)}createInsertion(e,r){return this.editorInsertions.createInsertion(e,r)}destroy(){Jo.debug("destroy editor"),this.emit("destroy",this),this.input.destroy(),this.rootContainerObject.destroy(),this.rootElement.remove(),this.doc.destroy(),this.customs.forEach(e=>e.destroy()),this.customs.clear(),this.selection.destroy(),this.domEvents.destroy(),this.removeAllListeners(),this.inputHandlers.destroy()}focus(e){this.input.focus(e)}focusToBlock(e,r){iC(this,e,r)}isWritable(){return $M(this)}isBlockWritable(e){return VM(this,e)}getChildContainerData(e){const r=this.doc.getContainerBlocks(e);return(!r||!Array.isArray(r))&&(p(Jo,r,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),p(Jo,Array.isArray(r),`container data is not an array: ${JSON.stringify(r)}`)),r}createChildContainer(e,r,i){return s3(this,e,r,i)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(Jo,ca(r),"not an valid block element"),r!=null?r:null}findBoxById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(Jo,T0(r),"not an valid box element"),r!=null?r:null}getBlockById(e){const r=this.findBlockById(e);return p(Jo,r,`no block, id=${e}`),r}getBoxById(e){const r=this.findBoxById(e);return p(Jo,r,`no box, id=${e}`),r}getBlockByIndex(e,r){const i=this.getContainerById(e);return Js(i,r)}findBlockByIndex(e,r){const i=this.getContainerById(e);return Rv(i,r)}getBlockIndex(e){if(typeof e=="string"){const r=this.getBlockById(e);return Rt(r)}return Rt(e)}getContainerById(e){return Ci(this,e)}getParentContainer(e){return at(e)}reloadBlock(e){FM(this,e)}contains(e){const r=e instanceof Element?e:e.parentElement;return r?r.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,r,i,o,s){const l={blockId:i.id,offset:0},c={anchor:l,focus:l};return qc(this,e,r,i,o!=null?o:c,s)}insertEmbed(e,r,i,o,s,l){const c={id:it(),type:"embed",embedType:i,embedData:o,...l};return this.insertBlock(e,r,c,s)}deleteBlock(e,r){nC(this,e,r)}mergeTextBlock(e,r){return XB(this,e,r)}breakTextBlock(e,r,i){return Xc(this,e,r,i).newBlock}getTextPosition(){return Gc(this)}getBlockString(e,r){const i=this.getBlockText(e);return Re(i,r)}getBlockData(e){return Qo(this,e)}getBoxData(e){return vB(this,e)}getBlockText(e){return Yn(this,e)}setBlockText(e,r){JB(this,e,r)}deleteTextFromBlock(e,r,i,o){return tC(this,e,r,i,o)}insertTextToBlock(e,r,i,o){return HB(this,e,r,i,o)}insertBoxToBlock(e,r,i){return jB(this,e,r,i)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,r,i,o){e5(this,e,r,i,o)}insertDocAt(e,r,i,o){return lC(this,e,r,i,o)}deleteChildContainers(e){qB(this,e)}replaceBlockText(e,r){return Z0(this,e,r)}updateBlockData(e,r,i,o){const s={...this.getBlockData(e),...r},{id:l,type:c,...d}=s;return tm(this,e,d,(i!=null?i:this.selection.range).toDocRange(),o)}updateEmbedData(e,r,i){return ZB(this,e,r,i)}updateBoxData(e,r){KM(this,e,r)}getSelectedText(){const e=Qc(this);return ol(this,e)}clearSelectedContents(){J0(this)}insertTextBlock(e,r,i,o,s){const l=no(e!=null?e:"",s);return WB(this,l,r,i,o==null?void 0:o.newRange,o==null?void 0:o.insertBlockOptions)}updateCompositionText(e,r){if(e&&!r&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!r){Z1(this);return}r?(this.compositingText="",Ef()?e||Z1(this):J1(this,e)):(this.compositingText=e,zB(this))}}function Zf(n,t,e){return new zM(n,t,e)}function GM(n){const t=(r,i)=>{const o=r.findIndex(l=>l.id===i.id);if(o===-1){r.push(i);return}const s=r[o];if(s.value!==i.value){r.splice(o,1);return}if(!!s.states){if(!i.states){s.states=[];return}s.states=Lp.default(s.states,i.states)}},e=[];return n.forEach(r=>{r.forEach(i=>{t(e,i)})}),e}const WM=["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"];class td extends Ve.TypedEmitter{constructor(e){super();m(this,"users",new Map);m(this,"cursors",new Map);m(this,"addingUser",!1);m(this,"colors");this.colors=e&&e.length>0?e:WM}setCursor(e){this.addUser(e.user);const r=this.cursors.get(e.user.userId);if(r&&Cf.default(r,e))return;this.cursors.set(e.user.userId,e);const i=new Set([e.range.anchor.blockId,e.range.focus.blockId]),o=new Set(i);r&&new Set([r.range.anchor.blockId,r.range.focus.blockId]).forEach(l=>{i.has(l)||o.add(l)}),this.emit("remote-carets-change",[...o])}addUsers(e){this.addingUser=!0,e.forEach(r=>this.addUser(r)),this.addingUser=!1,this.emit("change",Array.from(this.users.values()))}addUser(e){this.users.set(e.userId,e),this.addingUser||this.emit("change",Array.from(this.users.values()))}findUser(e){var r;return(r=this.users.get(e))!=null?r:null}removeUser(e){this.users.delete(e),this.emit("change",Array.from(this.users.values()));const r=this.cursors.get(e);if(r){const i=new Set(new Set([r==null?void 0:r.range.anchor.blockId,r==null?void 0:r.range.focus.blockId]));this.cursors.delete(e),this.emit("remote-carets-change",[...i])}}updateUsers(e){this.users.forEach(r=>{e.find(i=>i.userId===r.userId)||this.removeUser(r.userId)}),this.users.clear(),this.addingUser=!0;try{e.forEach(r=>{this.addUser(r)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const r=new Map;return Array.from(this.cursors.values()).filter(i=>i.range.anchor.blockId===e&&K0(i.range)).forEach(i=>{const o=i.range.focus.offset;let s=r.get(o);s||(s=[],r.set(o,s)),s.push(i)}),r}getCursors(e){return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e||r.range.focus.blockId===e)}onUpdateBlockText(e,r,i){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(K0(l.range)){const{anchor:c,focus:d}=l.range;c.blockId===e.id&&(c.offset=Hn.transformCursor(c.offset,r,i)),d.blockId===e.id&&(d.offset=Hn.transformCursor(d.offset,r,i))}})}getFixedUserColor(e,r){let i=0;Array.from(e).forEach(s=>{i+=s.charCodeAt(0)});const o=i%this.colors.length;return this.colors[o]}destroy(){this.removeAllListeners()}}const _n=D("local-doc");class TC extends Lc{constructor(e,r){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[no("")]}},this.serviceUrl=(r==null?void 0:r.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return Et.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}findContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,r){const i=this.getContainerBlocks(e);p(_n,i,`no container data: ${e}`);const o=i[r];return p(_n,o,`no block data: ${r}`),o}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(_n,o.text,"no text for data");const s=Hn.apply(o.text,i);return o.text=s,p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var c;return(c=l.onUpdateBlockText)==null?void 0:c.call(l,e,r,i,!0)}),s}localUpdateBlockData(e,r,i){const o=this.getBlockData(e,r);return i.delete.forEach(s=>delete o[s]),Object.entries(i.insert).forEach(([s,l])=>{o[s]=l}),p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,!0)}),o}localInsertBlock(e,r,i){const o=this.getContainerBlocks(e);return p(_n,o,`no container data: ${e}`),p(_n,r>=0&&r<=o.length,`invalid block index: ${r}, ${o.length}`),o.splice(r,0,i),p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,r,i,!0)}),i}localDeleteBlock(e,r){const i=this.getContainerBlocks(e);p(_n,i,`no container data: ${e}`),p(_n,r>=0&&r<=i.length,`invalid block index: ${r}, ${i.length}`);const o=i[r];return i.splice(r,1),p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,!0)}),o}localInsertChildContainers(e){e.forEach(({containerId:r,blocks:i})=>{this.doc.blocks[r]=i,p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,r,i,!0)})})}localDeleteChildContainers(e){_n.debug(`delete child containers: ${e}`),e.forEach(r=>{p(_n,this.doc.blocks[r],`no child container: ${r}`),delete this.doc.blocks[r]}),e.forEach(r=>{p(_n,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,r,!0)})})}uploadResource(e,r){p(_n,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,r){p(_n,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new td}setDoc(e){this.doc=Et.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,"change doc")})}destroy(){this.clearCallbacks()}}class qM{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function kC(n,t,e){n.addCustom(t,()=>{var o;const r=(o=e())!=null?o:void 0;return new qM(r)})}const Ry=D("find-block");function wy(n,t){const e=Gr(t);if(!e){if(qr(t))return null;const r=ua(t);return p(Ry,r,"no parent block"),wy(n,r)}return Pt(n,e)?Fc(n,e,{visibleOnly:!0}):e}function Sy(n,t){const e=Wr(t);if(!e){if(qr(t))return null;const r=ua(t);return p(Ry,r,"no parent block"),Sy(n,r)}return Pt(n,e)?E1(n,e,{visibleOnly:!0}):e}const XM=D("remote-cursor");class YM{constructor(){m(this,"remoteUsers",new td)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const r=e;this.handleUpdateUsers(r.users)}else e.type==="caret"?this.handleUpdateCaret(e):XM.debug(`unknown remote message received: ${t}`)}handleUpdateUsers(t){this.remoteUsers.updateUsers(t)}handleUpdateCaret(t){const e=this.remoteUsers.findUser(t.userId);!e||this.remoteUsers.setCursor({oneseditor:"cursor",user:e,range:t.range,time:Date.now()})}destroy(){this.remoteUsers.destroy()}}function QM(n){const{blocks:t,meta:e,comments:r,...i}=n;return{rootBlocks:t,meta:e,comments:r,childBlocks:i}}function JM(n){const{blocks:t,meta:e,comments:r}=n,{root:i,...o}=t;return{blocks:i,meta:e,comments:r,...o}}function Zo(n){const{childBlocks:t,meta:e,comments:r,rootBlocks:i}=QM(Et.default(n));return{blocks:{root:i,...t},meta:e,comments:r}}function ts(n){return n==="root"?"blocks":n}function Zc(n){return n==="blocks"?"root":n}const ZM={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new Vn.default(n)},apply(n,t){const e=new Vn.default(n),r=new Vn.default(t);return e.compose(r).ops},compose(n,t){const e=new Vn.default(n),r=new Vn.default(t);return e.compose(r).ops},diff(n,t){const e=new Vn.default(n),r=new Vn.default(t);return e.diff(r).ops},transform(n,t,e){const r=new Vn.default(n);return new Vn.default(t).transform(r,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const r=new Vn.default(t),i=this.transformCursor(n.index,r,e),o=this.transformCursor(n.index+n.length,r,e);return{...n,index:i,length:o-i}}}};var ul={},RC=Sp.default.EventEmitter;ul.EventEmitter=RC,ul.mixin=tU;function tU(n){for(var t in RC.prototype)n.prototype[t]=RC.prototype[t]}var Ly=["info","warn","error"];function Iy(){var n={};Ly.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var eU=Iy;Iy.prototype.setMethods=function(n){n=n||{};var t=this;Ly.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var nU=eU,rU=new nU,Dy=rU;function xa(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,xa):this.stack=new Error().stack}xa.prototype=Object.create(Error.prototype),xa.prototype.constructor=xa,xa.prototype.name="ShareDBError",xa.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_FIXUP_IS_ONLY_VALID_ON_APPLY:"ERR_FIXUP_IS_ONLY_VALID_ON_APPLY",ERR_CANNOT_FIXUP_DELETION:"ERR_CANNOT_FIXUP_DELETION",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_CHANNEL_MISSING:"ERR_QUERY_CHANNEL_MISSING",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE:"ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var fm=xa,ed={},_y=iU;function iU(n,t,e,r){var i=function(s,l,c,d){t(c,s,l,"left"),t(d,l,s,"right")},o=n.transformX=function(s,l){e(s),e(l);for(var c=[],d=0;d<l.length;d++){for(var h=l[d],C=[],E=0;E<s.length;){var A=[];if(i(s[E],h,C,A),E++,A.length===1)h=A[0];else if(A.length===0){for(var v=E;v<s.length;v++)r(C,s[v]);h=null;break}else{for(var w=o(s.slice(E),A),S=0;S<w[0].length;S++)r(C,w[0][S]);for(var U=0;U<w[1].length;U++)r(c,w[1][U]);h=null;break}}h!=null&&r(c,h),s=C}return[s,c]};n.transform=function(s,l,c){if(!(c==="left"||c==="right"))throw new Error("type must be 'left' or 'right'");return l.length===0?s:s.length===1&&l.length===1?t([],s[0],l[0],c):c==="left"?o(s,l)[0]:o(l,s)[1]}}var My={exports:{}},fl=My.exports={name:"text0",uri:"http://sharejs.org/types/textv0",create:function(n){if(n!=null&&typeof n!="string")throw new Error("Initial data must be a string");return n||""}},wC=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},SC=function(n){if(typeof n.p!="number")throw new Error("component missing position field");if(typeof n.i=="string"==(typeof n.d=="string"))throw new Error("component needs an i or d field");if(n.p<0)throw new Error("position cannot be negative")},dm=function(n){for(var t=0;t<n.length;t++)SC(n[t])};fl.apply=function(n,t){var e;dm(t);for(var r=0;r<t.length;r++){var i=t[r];if(i.i!=null)n=wC(n,i.p,i.i);else{if(e=n.slice(i.p,i.p+i.d.length),i.d!==e)throw new Error("Delete component '"+i.d+"' does not match deleted text '"+e+"'");n=n.slice(0,i.p)+n.slice(i.p+i.d.length)}}return n};var es=fl._append=function(n,t){if(!(t.i===""||t.d===""))if(n.length===0)n.push(t);else{var e=n[n.length-1];e.i!=null&&t.i!=null&&e.p<=t.p&&t.p<=e.p+e.i.length?n[n.length-1]={i:wC(e.i,t.p-e.p,t.i),p:e.p}:e.d!=null&&t.d!=null&&t.p<=e.p&&e.p<=t.p+t.d.length?n[n.length-1]={d:wC(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};fl.compose=function(n,t){dm(n),dm(t);for(var e=n.slice(),r=0;r<t.length;r++)es(e,t[r]);return e},fl.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=0),es(t,r)}return t};var LC=function(n,t,e){return t.i!=null?t.p<n||t.p===n&&e?n+t.i.length:n:n<=t.p?n:n<=t.p+t.d.length?t.p:n-t.d.length};fl.transformCursor=function(n,t,e){for(var r=e==="right",i=0;i<t.length;i++)n=LC(n,t[i],r);return n};var oU=fl._tc=function(n,t,e,r){if(SC(t),SC(e),t.i!=null)es(n,{i:t.i,p:LC(t.p,e,r==="right")});else if(e.i!=null){var i=t.d;t.p<e.p&&(es(n,{d:i.slice(0,e.p-t.p),p:t.p}),i=i.slice(e.p-t.p)),i!==""&&es(n,{d:i,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)es(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)es(n,t);else{var o={d:"",p:t.p};t.p<e.p&&(o.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(o.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),c=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(c!==d)throw new Error("Delete ops delete different text in the same region of the document");o.d!==""&&(o.p=LC(o.p,e),es(n,o))}return n},sU=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};fl.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=sU(n[t]);return n},_y(fl,oU,dm,es);var hm=function(n){return Object.prototype.toString.call(n)=="[object Array]"},lU=function(n){return!!n&&n.constructor===Object},yi=function(n){return JSON.parse(JSON.stringify(n))},Ft={name:"json0",uri:"http://sharejs.org/types/JSONv0"},ns={};Ft.registerSubtype=function(n){ns[n.name]=n},Ft.create=function(n){return n===void 0?null:yi(n)},Ft.invertComponent=function(n){var t={p:n.p};return n.t&&ns[n.t]&&(t.t=n.t,t.o=ns[n.t].invert(n.o)),n.si!==void 0&&(t.sd=n.si),n.sd!==void 0&&(t.si=n.sd),n.oi!==void 0&&(t.od=n.oi),n.od!==void 0&&(t.oi=n.od),n.li!==void 0&&(t.ld=n.li),n.ld!==void 0&&(t.li=n.ld),n.na!==void 0&&(t.na=-n.na),n.lm!==void 0&&(t.lm=n.p[n.p.length-1],t.p=n.p.slice(0,n.p.length-1).concat([n.lm])),t},Ft.invert=function(n){for(var t=n.slice().reverse(),e=[],r=0;r<t.length;r++)e.push(Ft.invertComponent(t[r]));return e},Ft.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!hm(n[t].p))throw new Error("Missing path")},Ft.checkList=function(n){if(!hm(n))throw new Error("Referenced element not a list")},Ft.checkObj=function(n){if(!lU(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function nd(n){n.t="text0";var t={p:n.p.pop()};n.si!=null&&(t.i=n.si),n.sd!=null&&(t.d=n.sd),n.o=[t]}function rd(n){n.p.push(n.o[0].p),n.o[0].i!=null&&(n.si=n.o[0].i),n.o[0].d!=null&&(n.sd=n.o[0].d),delete n.t,delete n.o}Ft.apply=function(n,t){Ft.checkValidOp(t),t=yi(t);for(var e={data:n},r=0;r<t.length;r++){var i=t[r];(i.si!=null||i.sd!=null)&&nd(i);for(var o=null,s=e,l="data",c=0;c<i.p.length;c++){var d=i.p[c];if(o=s,s=s[l],l=d,o==null)throw new Error("Path invalid")}if(i.t&&i.o!==void 0&&ns[i.t])s[l]=ns[i.t].apply(s[l],i.o);else if(i.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=i.na}else if(i.li!==void 0&&i.ld!==void 0)Ft.checkList(s),s[l]=i.li;else if(i.li!==void 0)Ft.checkList(s),s.splice(l,0,i.li);else if(i.ld!==void 0)Ft.checkList(s),s.splice(l,1);else if(i.lm!==void 0){if(Ft.checkList(s),i.lm!=l){var h=s[l];s.splice(l,1),s.splice(i.lm,0,h)}}else if(i.oi!==void 0)Ft.checkObj(s),s[l]=i.oi;else if(i.od!==void 0)Ft.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},Ft.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},Ft.incrementalApply=function(n,t,e){for(var r=0;r<t.length;r++){var i=[t[r]];n=Ft.apply(n,i),e(i,n)}return n};var aU=Ft.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var r=0;r<n.length;r++)if(n[r]!==t[r]&&(!e||r!==n.length-1))return!1;return!0};Ft.append=function(n,t){if(t=yi(t),n.length===0){n.push(t);return}var e=n[n.length-1];if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(nd(t),nd(e)),aU(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&ns[t.t]){if(e.o=ns[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var r=t.p,i=0;i<e.o.length-1;i++)t.o=[e.o.pop()],t.p=r.slice(),rd(t),n.push(t);rd(e)}}else e.na!=null&&t.na!=null?n[n.length-1]={p:e.p,na:e.na+t.na}:e.li!==void 0&&t.li===void 0&&t.ld===e.li?e.ld!==void 0?delete e.li:n.pop():e.od!==void 0&&e.oi===void 0&&t.oi!==void 0&&t.od===void 0?e.oi=t.oi:e.oi!==void 0&&t.od!==void 0?t.oi!==void 0?e.oi=t.oi:e.od!==void 0?delete e.oi:n.pop():t.lm!==void 0&&t.p[t.p.length-1]===t.lm||n.push(t);else(t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(rd(t),rd(e)),n.push(t)},Ft.compose=function(n,t){Ft.checkValidOp(n),Ft.checkValidOp(t);for(var e=yi(n),r=0;r<t.length;r++)Ft.append(e,t[r]);return e},Ft.normalize=function(n){var t=[];n=hm(n)?n:[n];for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=[]),Ft.append(t,r)}return t},Ft.commonLengthForOps=function(n,t){var e=n.p.length,r=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&r++,e===0)return-1;if(r===0)return null;e--,r--;for(var i=0;i<e;i++){var o=n.p[i];if(i>=r||o!==t.p[i])return null}return e},Ft.canOpAffectPath=function(n,t){return Ft.commonLengthForOps({p:t},n)!=null},Ft.transformComponent=function(n,t,e,r){t=yi(t);var i=Ft.commonLengthForOps(e,t),o=Ft.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,o!=null&&l>s&&t.p[o]==e.p[o]){if(t.ld!==void 0){var c=yi(e);c.p=c.p.slice(s),t.ld=Ft.apply(yi(t.ld),[c])}else if(t.od!==void 0){var c=yi(e);c.p=c.p.slice(s),t.od=Ft.apply(yi(t.od),[c])}}if(i!=null){var d=s==l,c=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(nd(t),c=yi(e),nd(c)),c.t&&ns[c.t]){if(t.t&&t.t===c.t){var h=ns[t.t].transform(t.o,c.o,r);if(t.si!=null||t.sd!=null)for(var C=t.p,E=0;E<h.length;E++)t.o=[h[E]],t.p=C.slice(),rd(t),Ft.append(n,t);else(!hm(h)||h.length>0)&&(t.o=h,Ft.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[i]===t.p[i])if(d){if(t.ld!==void 0)if(t.li!==void 0&&r==="left")t.ld=yi(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&d&&t.p[i]===e.p[i]?r==="right"&&t.p[i]++:e.p[i]<=t.p[i]&&t.p[i]++,t.lm!==void 0&&d&&e.p[i]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[i]===t.p[i])return n;var C=e.p[i],A=t.p[i],v=t.lm;(C<v||C===v&&A<v)&&t.lm--}if(e.p[i]<t.p[i])t.p[i]--;else if(e.p[i]===t.p[i]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var A=t.p[i],v=t.lm,w=e.p[i],S=e.lm;if(w!==S)if(A===w)if(r==="left")t.p[i]=S,A===v&&(t.lm=S);else return n;else A>w&&t.p[i]--,A>S?t.p[i]++:A===S&&w>S&&(t.p[i]++,A===v&&t.lm++),(v>w||v===w&&v>A)&&t.lm--,v>S?t.lm++:v===S&&(S>w&&v>A||S<w&&v<A?r==="right"&&t.lm++:v>A?t.lm++:v===w&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var A=e.p[i],v=e.lm;C=t.p[i],C>A&&t.p[i]--,C>v&&t.p[i]++}else{var A=e.p[i],v=e.lm;C=t.p[i],C===A?t.p[i]=v:(C>A&&t.p[i]--,(C>v||C===v&&A>v)&&t.p[i]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[i]===e.p[i])if(t.oi!==void 0&&d){if(r==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[i]===e.p[i])if(r==="left")Ft.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[i]==e.p[i]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return Ft.append(n,t),n},_y(Ft,Ft.transformComponent,Ft.checkValidOp,Ft.append);var cU=My.exports;Ft.registerSubtype(cU);var uU=Ft,fU={type:uU};(function(n){n.defaultType=fU.type,n.map={},n.register=function(t){t.name&&(n.map[t.name]=t),t.uri&&(n.map[t.uri]=t)},n.register(n.defaultType)})(ed);var Qr={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var r in e)return!0;return!1},n.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e},n.isValidVersion=function(e){return e===null?!0:n.isInteger(e)&&e>=0},n.isValidTimestamp=function(e){return n.isValidVersion(e)},n.MAX_SAFE_INTEGER=9007199254740991,n.dig=function(){for(var e=arguments[0],r=1;r<arguments.length;r++){var i=arguments[r];e=e[i]||(r===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],r=arguments[arguments.length-1],i=1;i<arguments.length-1;i++){var o=arguments[i];e=e[o]||(e[o]=i===arguments.length-2?r():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],r=[e],i=1;i<arguments.length-1;i++){var o=arguments[i];if(!e.hasOwnProperty(o))break;e=e[o],r.push(e)}for(var i=r.length-1;i>=0;i--){var s=r[i],o=arguments[i+1],l=s[o];(i===r.length-1||!n.hasKeys(l))&&delete s[o]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,r){var i=!1;return e.forEach(function(o){o&&(o(r),i=!0)}),i},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];setTimeout(function(){e.apply(null,r)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(Qr);var Uy=Array.isArray,Oy=Object.keys,dU=Object.prototype.hasOwnProperty,hU=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=Uy(t),i=Uy(e),o,s,l;if(r&&i){if(s=t.length,s!=e.length)return!1;for(o=s;o--!==0;)if(!n(t[o],e[o]))return!1;return!0}if(r!=i)return!1;var c=t instanceof Date,d=e instanceof Date;if(c!=d)return!1;if(c&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,C=e instanceof RegExp;if(h!=C)return!1;if(h&&C)return t.toString()==e.toString();var E=Oy(t);if(s=E.length,s!==Oy(e).length)return!1;for(o=s;o--!==0;)if(!dU.call(e,E[o]))return!1;for(o=s;o--!==0;)if(l=E[o],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},dl={};dl.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",fixup:"fixup",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var Ny=ul,mU=Dy,wr=fm,mm=ed,Ti=Qr,gU=Ti.clone,pU=hU,IC=dl.ACTIONS,cr=wr.CODES,CU=Xt;function Xt(n,t,e){Ny.EventEmitter.call(this),this.connection=n,this.collection=t,this.id=e,this.version=null,this.type=null,this.data=void 0,this.inflightFetch=[],this.inflightSubscribe=null,this.pendingFetch=[],this.pendingSubscribe=[],this.subscribed=!1,this.wantSubscribe=!1,this._wantsDestroy=!1,this.inflightOp=null,this.pendingOps=[],this.type=null,this.applyStack=null,this.preventCompose=!1,this.submitSource=!1,this.paused=!1,this._dataStateVersion=0}Ny.mixin(Xt),Xt.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this;t.whenNothingPending(function(){t.wantSubscribe?t.unsubscribe(function(e){if(e)return n?n(e):t.emit("error",e);t.connection._destroyDoc(t),n&&n()}):(t.connection._destroyDoc(t),n&&n())})},Xt.prototype._setType=function(n){if(typeof n=="string"&&(n=mm.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new wr(cr.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Xt.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Xt.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new wr(cr.ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION,"Missing version in ingested snapshot. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}if(this.type||this.hasWritePending()){if(this.version==null){if(this.hasWritePending())return t&&this.once("no write pending",t);var e=new wr(cr.ERR_DOC_MISSING_VERSION,"Cannot ingest snapshot in doc with null version. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}return n.v>this.version?this.fetch(t):t&&t()}if(this.version>n.v)return t&&t();this.version=n.v;var r=n.type===void 0?mm.defaultType:n.type;this._setType(r),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},Xt.prototype.whenNothingPending=function(n){var t=this;Ti.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Xt.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Xt.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Xt.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Xt.prototype._emitResponseError=function(n,t){if(n&&n.code===cr.ERR_SNAPSHOT_READ_SILENT_REJECTION){this.wantSubscribe=!1,t&&t(),this._emitNothingPending();return}if(t){t(n),this._emitNothingPending();return}this._emitNothingPending(),this.emit("error",n)},Xt.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var r=this.inflightFetch.shift();if(r&&e.push(r),e.length&&(r=function(i){Ti.callEach(e,i)}),n)return this._emitResponseError(n,r);this.ingestSnapshot(t,r),this._emitNothingPending()},Xt.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var r=this.pendingFetch;this.pendingFetch=[],e.callback&&r.push(e.callback);var i;if(r.length&&(i=function(o){Ti.callEach(r,o)}),n)return this._emitResponseError(n,i);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,i):i&&i(),this._emitNothingPending(),this._flushSubscribe()},Xt.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===cr.ERR_OP_SUBMIT_REJECTED&&(n=null),this._rollback(n)):this.emit("error",n);if(this.inflightOp&&t.src===this.inflightOp.src&&t.seq===this.inflightOp.seq){this._opAcknowledged(t);return}if(this.version==null||t.v>this.version){this.fetch();return}if(!(t.v<this.version)){if(this.inflightOp){var e=id(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var r=0;r<this.pendingOps.length;r++){var e=id(this.pendingOps[r],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}}},Xt.prototype._onConnectionStateChanged=function(){this.connection.canSend?(this.flush(),this._resubscribe()):(this.inflightOp&&(this.pendingOps.unshift(this.inflightOp),this.inflightOp=null),this.subscribed=!1,this.inflightSubscribe&&(this.inflightSubscribe.wantSubscribe?(this.pendingSubscribe.unshift(this.inflightSubscribe),this.inflightSubscribe=null):this._handleSubscribe()),this.inflightFetch.length&&(this.pendingFetch=this.pendingFetch.concat(this.inflightFetch),this.inflightFetch.length=0))},Xt.prototype._resubscribe=function(){if(!this.pendingSubscribe.length&&this.wantSubscribe)return this.subscribe();var n=this.pendingSubscribe.some(function(t){return t.wantSubscribe});!n&&this.pendingFetch.length&&this.fetch(),this._flushSubscribe()},Xt.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);EU(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Xt.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Xt.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Xt.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,r=e&&e.wantSubscribe===n;if(r){e.callback=AU([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Xt.prototype._flushSubscribe=function(){if(!(this.inflightSubscribe||!this.pendingSubscribe.length)){if(this.connection.canSend){this.inflightSubscribe=this.pendingSubscribe.shift(),this.wantSubscribe=this.inflightSubscribe.wantSubscribe,this.wantSubscribe?this.connection.sendSubscribe(this):(this.subscribed=!1,this.connection.sendUnsubscribe(this));return}if(!this.pendingSubscribe[0].wantSubscribe){this.inflightSubscribe=this.pendingSubscribe.shift();var n=this;Ti.nextTick(function(){n._handleSubscribe()})}}};function EU(n,t,e){if(t){var r=n.pop();n.push(function(i){r&&r(i),e&&e(i)})}else n.push(e)}function AU(n){return n=n.filter(Ti.truthy),n.length?function(t){Ti.callEach(n,t)}:null}Xt.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function xU(n){delete n.op,delete n.create,delete n.del}function id(n,t){if(n.del)return xU(t);if(t.del)return new wr(cr.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new wr(cr.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new wr(cr.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var r=n.type.transform(n.op,t.op,"left"),i=n.type.transform(t.op,n.op,"right");n.op=r,t.op=i}}}Xt.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new wr(cr.ERR_DOC_DOES_NOT_EXIST,"Cannot apply op to uncreated document. "+this.collection+"."+this.id);if(this.emit("before op batch",n.op,t),!t&&this.type===mm.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,r=0;r<n.op.length;r++){var i=n.op[r],o={op:[i]};this.emit("before op",o.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=id(this.applyStack[s],o);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,o.op)),this.emit("op",o.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var c=this.data;this._setType(null),this.emit("del",c,t);return}},Xt.prototype._sendOp=function(){if(!!this.connection.canSend){var n=this.connection.id;this.inflightOp||(this.inflightOp=this.pendingOps.shift());var t=this.inflightOp;if(!t){var e=new wr(cr.ERR_INFLIGHT_OP_MISSING,"No op to send on call to _sendOp");return this.emit("error",e)}if(t.sentAt=Date.now(),t.retries=t.retries==null?0:t.retries+1,t.seq==null){if(this.connection.seq>=Ti.MAX_SAFE_INTEGER)return this.emit("error",new wr(cr.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW,"Connection seq has exceeded the max safe integer, maybe from being open for too long"));t.seq=this.connection.seq++}this.connection.sendOp(this,t),t.src==null&&(t.src=n)}},Xt.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var r=new wr(cr.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(r):this.emit("error",r)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(o){return this._hardRollback(o)}var i=this;Ti.nextTick(function(){i.flush()})},Xt.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var r=this._tryCompose(n);if(r){r.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},Xt.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var r=this.pendingOps.splice(e),e=0;e<r.length;e++){var t=r[e],i=this._tryCompose(t);i?i.callbacks=i.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},Xt.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!pU(n.source,t.source))){if(t.create&&"op"in n)return t.create.data=this.type.apply(t.create.data,n.op),t;if("op"in t&&"op"in n&&this.type.compose)return t.op=this.type.compose(t.op,n.op),t}}},Xt.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var r={op:n},i=t&&t.source;this._submit(r,i,e)},Xt.prototype.create=function(n,t,e,r){if(typeof t=="function"?(r=t,e=null,t=null):typeof e=="function"&&(r=e,e=null),t||(t=mm.defaultType.uri),this.type){var i=new wr(cr.ERR_DOC_ALREADY_CREATED,"Document already exists");return r?r(i):this.emit("error",i)}var o={create:{type:t,data:n}},s=e&&e.source;this._submit(o,s,r)},Xt.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new wr(cr.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var r={del:!0},i=n&&n.source;this._submit(r,i,t)},Xt.prototype.pause=function(){this.paused=!0},Xt.prototype.resume=function(){this.paused=!1,this.flush()},Xt.prototype.toSnapshot=function(){return{v:this.version,data:gU(this.data),type:this.type.uri}},Xt.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return mU.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();if(n[IC.fixup])for(var t=0;t<n[IC.fixup].length;t++){for(var e=n[IC.fixup][t],r=0;r<this.pendingOps.length;r++){var i=id(this.pendingOps[t],e);if(i)return this._hardRollback(i)}try{this._otApply(e,!1)}catch(o){return this._hardRollback(o)}}this.version++,this._clearInflightOp()},Xt.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var r=id(this.pendingOps[e],t);if(r)return this._hardRollback(r)}try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}this._clearInflightOp(n);return}this._hardRollback(n)},Xt.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var r=!!t.length,i=0;i<t.length;i++)r=Ti.callEach(t[i].callbacks,n)&&r;if(n&&!r)return e.emit("error",n)})},Xt.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=Ti.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var Py=ul,Fy=dl.ACTIONS,bU=Qr,vU=ur;function ur(n,t,e,r,i,o,s){Py.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=r,this.query=i,this.results=null,o&&o.results&&(this.results=o.results,delete o.results),this.extra=void 0,this.options=o,this.callback=s,this.ready=!1,this.sent=!1}Py.mixin(ur),ur.prototype.hasPending=function(){return!this.ready},ur.prototype.send=function(){if(!!this.connection.canSend){var n={a:this.action,id:this.id,c:this.collection,q:this.query};if(this.options&&(n.o=this.options),this.results){for(var t=[],e=0;e<this.results.length;e++){var r=this.results[e];t.push([r.id,r.version])}n.r=t}this.connection.send(n),this.sent=!0}},ur.prototype.destroy=function(n){this.connection.canSend&&this.action===Fy.querySubscribe&&this.connection.send({a:Fy.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&bU.nextTick(n)},ur.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},ur.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},ur.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},ur.prototype._handleResponse=function(n,t,e){var r=this.callback;if(this.callback=null,n)return this._finishResponse(n,r);if(!t)return this._finishResponse(null,r);var i=this,o=1,s=function(h){if(h)return i._finishResponse(h,r);--o||i._finishResponse(null,r)};if(Array.isArray(t))o+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){o++;var c=t[l],d=this.connection.get(c.c||this.collection,l);d.ingestSnapshot(c,s)}s()},ur.prototype._ingestSnapshots=function(n,t){for(var e=[],r=0;r<n.length;r++){var i=n[r],o=this.connection.get(i.c||this.collection,i.d);o.ingestSnapshot(i,t),e.push(o)}return e},ur.prototype._finishResponse=function(n,t){if(this.emit("ready"),this.ready=!0,n)return this.connection._destroyQuery(this),t?t(n):this.emit("error",n);t&&t(null,this.results,this.extra)},ur.prototype._handleError=function(n){this.emit("error",n)},ur.prototype._handleDiff=function(n){for(var t=0;t<n.length;t++){var e=n[t];e.type==="insert"&&(e.values=this._ingestSnapshots(e.values))}for(var t=0;t<n.length;t++){var e=n[t];switch(e.type){case"insert":var r=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(r)),this.emit("insert",r,e.index);break;case"remove":var o=e.howMany||1,i=this.results.splice(e.index,o);this.emit("remove",i,e.index);break;case"move":var o=e.howMany||1,s=this.results.splice(e.from,o);Array.prototype.splice.apply(this.results,[e.to,0].concat(s)),this.emit("move",s,e.from,e.to);break}}this.emit("changed",this.results)},ur.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var Ky=ul,BU=dl.ACTIONS,yU=Qr,Vy=io;function io(n,t){if(Ky.EventEmitter.call(this),!t||typeof t!="string")throw new Error("LocalPresence presenceId must be a string");this.presence=n,this.presenceId=t,this.connection=n.connection,this.presenceVersion=0,this.value=null,this._pendingMessages=[],this._callbacksByPresenceVersion={}}Ky.mixin(io),io.prototype.submit=function(n,t){this.value=n,this.send(t)},io.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},io.prototype.destroy=function(n){var t=this;this.submit(null,function(e){if(e)return t._callbackOrEmit(e,n);delete t.presence.localPresences[t.presenceId],n&&n()})},io.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},io.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},io.prototype._message=function(){return{a:BU.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},io.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},io.prototype._callbackOrEmit=function(n,t){if(t)return yU.nextTick(t,n);n&&this.emit("error",n)};var TU=Qr,$y=DC;function DC(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}DC.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},DC.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&TU.nextTick(n)};var _C={exports:{}};(function(n,t){(function(e,r){r(t)})(yn,function(e){function r(T,I){I=I|0;for(var O=Math.max(T.length-I,0),F=Array(O),z=0;z<O;z++)F[z]=T[I+z];return F}var i=function(T){var I=r(arguments,1);return function(){var O=r(arguments);return T.apply(null,I.concat(O))}},o=function(T){return function(){var I=r(arguments),O=I.pop();T.call(this,I,O)}};function s(T){var I=typeof T;return T!=null&&(I=="object"||I=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function d(T){setTimeout(T,0)}function h(T){return function(I){var O=r(arguments,1);T(function(){I.apply(null,O)})}}var C;l?C=setImmediate:c?C=process.nextTick:C=d;var E=h(C);function A(T){return o(function(I,O){var F;try{F=T.apply(this,I)}catch(z){return O(z)}s(F)&&typeof F.then=="function"?F.then(function(z){v(O,null,z)},function(z){v(O,z.message?z:new Error(z))}):O(null,F)})}function v(T,I,O){try{T(I,O)}catch(F){E(w,F)}}function w(T){throw T}var S=typeof Symbol=="function";function U(T){return S&&T[Symbol.toStringTag]==="AsyncFunction"}function M(T){return U(T)?A(T):T}function V(T){return function(I){var O=r(arguments,1),F=o(function(z,j){var J=this;return T(I,function(rt,mt){M(rt).apply(J,z.concat(mt))},j)});return O.length?F.apply(this,O):F}}var nt=typeof yn=="object"&&yn&&yn.Object===Object&&yn,Y=typeof self=="object"&&self&&self.Object===Object&&self,X=nt||Y||Function("return this")(),ft=X.Symbol,xt=Object.prototype,bt=xt.hasOwnProperty,wt=xt.toString,Tt=ft?ft.toStringTag:void 0;function ie(T){var I=bt.call(T,Tt),O=T[Tt];try{T[Tt]=void 0;var F=!0}catch{}var z=wt.call(T);return F&&(I?T[Tt]=O:delete T[Tt]),z}var xe=Object.prototype,fe=xe.toString;function Dr(T){return fe.call(T)}var dr="[object Null]",je="[object Undefined]",Tn=ft?ft.toStringTag:void 0;function tr(T){return T==null?T===void 0?je:dr:Tn&&Tn in Object(T)?ie(T):Dr(T)}var hr="[object AsyncFunction]",mr="[object Function]",uh="[object GeneratorFunction]",fh="[object Proxy]";function dh(T){if(!s(T))return!1;var I=tr(T);return I==mr||I==uh||I==hr||I==fh}var Ao=9007199254740991;function cs(T){return typeof T=="number"&&T>-1&&T%1==0&&T<=Ao}function us(T){return T!=null&&cs(T.length)&&!dh(T)}var te={};function Gt(){}function ri(T){return function(){if(T!==null){var I=T;T=null,I.apply(this,arguments)}}}var On=typeof Symbol=="function"&&Symbol.iterator,fs=function(T){return On&&T[On]&&T[On]()};function Oa(T,I){for(var O=-1,F=Array(T);++O<T;)F[O]=I(O);return F}function kn(T){return T!=null&&typeof T=="object"}var xo="[object Arguments]";function Na(T){return kn(T)&&tr(T)==xo}var er=Object.prototype,Pu=er.hasOwnProperty,hh=er.propertyIsEnumerable,ds=Na(function(){return arguments}())?Na:function(T){return kn(T)&&Pu.call(T,"callee")&&!hh.call(T,"callee")},Oe=Array.isArray;function hs(){return!1}var ms=typeof e=="object"&&e&&!e.nodeType&&e,Fu=ms&&!0&&n&&!n.nodeType&&n,gs=Fu&&Fu.exports===ms,Ku=gs?X.Buffer:void 0,ps=Ku?Ku.isBuffer:void 0,bo=ps||hs,Cs=9007199254740991,Pa=/^(?:0|[1-9]\d*)$/;function Fa(T,I){var O=typeof T;return I=I==null?Cs:I,!!I&&(O=="number"||O!="symbol"&&Pa.test(T))&&T>-1&&T%1==0&&T<I}var Es="[object Arguments]",Ka="[object Array]",Va="[object Boolean]",vo="[object Date]",As="[object Error]",Dl="[object Function]",Vu="[object Map]",_r="[object Number]",Bo="[object Object]",$u="[object RegExp]",$a="[object Set]",Hu="[object String]",mh="[object WeakMap]",gh="[object ArrayBuffer]",ph="[object DataView]",_l="[object Float32Array]",xs="[object Float64Array]",Ha="[object Int8Array]",yo="[object Int16Array]",bs="[object Int32Array]",vs="[object Uint8Array]",ja="[object Uint8ClampedArray]",Ch="[object Uint16Array]",Eh="[object Uint32Array]",be={};be[_l]=be[xs]=be[Ha]=be[yo]=be[bs]=be[vs]=be[ja]=be[Ch]=be[Eh]=!0,be[Es]=be[Ka]=be[gh]=be[Va]=be[ph]=be[vo]=be[As]=be[Dl]=be[Vu]=be[_r]=be[Bo]=be[$u]=be[$a]=be[Hu]=be[mh]=!1;function Ah(T){return kn(T)&&cs(T.length)&&!!be[tr(T)]}function Ml(T){return function(I){return T(I)}}var Ul=typeof e=="object"&&e&&!e.nodeType&&e,To=Ul&&!0&&n&&!n.nodeType&&n,Oi=To&&To.exports===Ul,Ol=Oi&&nt.process,ju=function(){try{var T=To&&To.require&&To.require("util").types;return T||Ol&&Ol.binding&&Ol.binding("util")}catch{}}(),zu=ju&&ju.isTypedArray,xh=zu?Ml(zu):Ah,bh=Object.prototype,Mr=bh.hasOwnProperty;function vh(T,I){var O=Oe(T),F=!O&&ds(T),z=!O&&!F&&bo(T),j=!O&&!F&&!z&&xh(T),J=O||F||z||j,rt=J?Oa(T.length,String):[],mt=rt.length;for(var yt in T)(I||Mr.call(T,yt))&&!(J&&(yt=="length"||z&&(yt=="offset"||yt=="parent")||j&&(yt=="buffer"||yt=="byteLength"||yt=="byteOffset")||Fa(yt,mt)))&&rt.push(yt);return rt}var Nl=Object.prototype;function Bh(T){var I=T&&T.constructor,O=typeof I=="function"&&I.prototype||Nl;return T===O}function Pl(T,I){return function(O){return T(I(O))}}var yh=Pl(Object.keys,Object),Ur=Object.prototype,Th=Ur.hasOwnProperty;function Gu(T){if(!Bh(T))return yh(T);var I=[];for(var O in Object(T))Th.call(T,O)&&O!="constructor"&&I.push(O);return I}function Fl(T){return us(T)?vh(T):Gu(T)}function Wu(T){var I=-1,O=T.length;return function(){return++I<O?{value:T[I],key:I}:null}}function kh(T){var I=-1;return function(){var F=T.next();return F.done?null:(I++,{value:F.value,key:I})}}function Bs(T){var I=Fl(T),O=-1,F=I.length;return function z(){var j=I[++O];return j==="__proto__"?z():O<F?{value:T[j],key:j}:null}}function Rh(T){if(us(T))return Wu(T);var I=fs(T);return I?kh(I):Bs(T)}function gr(T){return function(){if(T===null)throw new Error("Callback was already called.");var I=T;T=null,I.apply(this,arguments)}}function Nn(T){return function(I,O,F){if(F=ri(F||Gt),T<=0||!I)return F(null);var z=Rh(I),j=!1,J=0,rt=!1;function mt(gt,Lt){if(J-=1,gt)j=!0,F(gt);else{if(Lt===te||j&&J<=0)return j=!0,F(null);rt||yt()}}function yt(){for(rt=!0;J<T&&!j;){var gt=z();if(gt===null){j=!0,J<=0&&F(null);return}J+=1,O(gt.value,gt.key,gr(mt))}rt=!1}yt()}}function ii(T,I,O,F){Nn(I)(T,M(O),F)}function Xe(T,I){return function(O,F,z){return T(O,I,F,z)}}function za(T,I,O){O=ri(O||Gt);var F=0,z=0,j=T.length;j===0&&O(null);function J(rt,mt){rt?O(rt):(++z===j||mt===te)&&O(null)}for(;F<j;F++)I(T[F],F,gr(J))}var wh=Xe(ii,1/0),Or=function(T,I,O){var F=us(T)?za:wh;F(T,M(I),O)};function Nr(T){return function(I,O,F){return T(Or,I,M(O),F)}}function ko(T,I,O,F){F=F||Gt,I=I||[];var z=[],j=0,J=M(O);T(I,function(rt,mt,yt){var gt=j++;J(rt,function(Lt,he){z[gt]=he,yt(Lt)})},function(rt){F(rt,z)})}var ys=Nr(ko),Ga=V(ys);function Ni(T){return function(I,O,F,z){return T(Nn(O),I,M(F),z)}}var pr=Ni(ko),Wa=Xe(pr,1),qa=V(Wa);function Ro(T,I){for(var O=-1,F=T==null?0:T.length;++O<F&&I(T[O],O,T)!==!1;);return T}function Xa(T){return function(I,O,F){for(var z=-1,j=Object(I),J=F(I),rt=J.length;rt--;){var mt=J[T?rt:++z];if(O(j[mt],mt,j)===!1)break}return I}}var wo=Xa();function So(T,I){return T&&wo(T,I,Fl)}function qu(T,I,O,F){for(var z=T.length,j=O+(F?1:-1);F?j--:++j<z;)if(I(T[j],j,T))return j;return-1}function Sh(T){return T!==T}function Xu(T,I,O){for(var F=O-1,z=T.length;++F<z;)if(T[F]===I)return F;return-1}function Ts(T,I,O){return I===I?Xu(T,I,O):qu(T,Sh,O)}var Kl=function(T,I,O){typeof I=="function"&&(O=I,I=null),O=ri(O||Gt);var F=Fl(T),z=F.length;if(!z)return O(null);I||(I=z);var j={},J=0,rt=!1,mt=Object.create(null),yt=[],gt=[],Lt={};So(T,function(_e,Te){if(!Oe(_e)){he(Te,[_e]),gt.push(Te);return}var Ke=_e.slice(0,_e.length-1),ui=Ke.length;if(ui===0){he(Te,_e),gt.push(Te);return}Lt[Te]=ui,Ro(Ke,function(R){if(!T[R])throw new Error("async.auto task `"+Te+"` has a non-existent dependency `"+R+"` in "+Ke.join(", "));Fn(R,function(){ui--,ui===0&&he(Te,_e)})})}),Mx(),nn();function he(_e,Te){yt.push(function(){ci(_e,Te)})}function nn(){if(yt.length===0&&J===0)return O(null,j);for(;yt.length&&J<I;){var _e=yt.shift();_e()}}function Fn(_e,Te){var Ke=mt[_e];Ke||(Ke=mt[_e]=[]),Ke.push(Te)}function Cr(_e){var Te=mt[_e]||[];Ro(Te,function(Ke){Ke()}),nn()}function ci(_e,Te){if(!rt){var Ke=gr(function(R,Mo){if(J--,arguments.length>2&&(Mo=r(arguments,1)),R){var Gl={};So(j,function(Er,Yt){Gl[Yt]=Er}),Gl[_e]=Mo,rt=!0,mt=Object.create(null),O(R,Gl)}else j[_e]=Mo,Cr(_e)});J++;var ui=M(Te[Te.length-1]);Te.length>1?ui(j,Ke):ui(Ke)}}function Mx(){for(var _e,Te=0;gt.length;)_e=gt.pop(),Te++,Ro(Ux(_e),function(Ke){--Lt[Ke]===0&&gt.push(Ke)});if(Te!==z)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function Ux(_e){var Te=[];return So(T,function(Ke,ui){Oe(Ke)&&Ts(Ke,_e,0)>=0&&Te.push(ui)}),Te}};function oi(T,I){for(var O=-1,F=T==null?0:T.length,z=Array(F);++O<F;)z[O]=I(T[O],O,T);return z}var Lh="[object Symbol]";function Yu(T){return typeof T=="symbol"||kn(T)&&tr(T)==Lh}var Ih=1/0,Ya=ft?ft.prototype:void 0,ks=Ya?Ya.toString:void 0;function Qa(T){if(typeof T=="string")return T;if(Oe(T))return oi(T,Qa)+"";if(Yu(T))return ks?ks.call(T):"";var I=T+"";return I=="0"&&1/T==-Ih?"-0":I}function Lo(T,I,O){var F=-1,z=T.length;I<0&&(I=-I>z?0:z+I),O=O>z?z:O,O<0&&(O+=z),z=I>O?0:O-I>>>0,I>>>=0;for(var j=Array(z);++F<z;)j[F]=T[F+I];return j}function si(T,I,O){var F=T.length;return O=O===void 0?F:O,!I&&O>=F?T:Lo(T,I,O)}function Ja(T,I){for(var O=T.length;O--&&Ts(I,T[O],0)>-1;);return O}function Qu(T,I){for(var O=-1,F=T.length;++O<F&&Ts(I,T[O],0)>-1;);return O}function Vl(T){return T.split("")}var Dh="\\ud800-\\udfff",_h="\\u0300-\\u036f",Mh="\\ufe20-\\ufe2f",pe="\\u20d0-\\u20ff",de=_h+Mh+pe,Uh="\\ufe0e\\ufe0f",$l="\\u200d",Pi=RegExp("["+$l+Dh+de+Uh+"]");function Oh(T){return Pi.test(T)}var Hl="\\ud800-\\udfff",Ju="\\u0300-\\u036f",Za="\\ufe20-\\ufe2f",Fi="\\u20d0-\\u20ff",Ye=Ju+Za+Fi,tc="\\ufe0e\\ufe0f",li="["+Hl+"]",Io="["+Ye+"]",ai="\\ud83c[\\udffb-\\udfff]",xn="(?:"+Io+"|"+ai+")",Rs="[^"+Hl+"]",ec="(?:\\ud83c[\\udde6-\\uddff]){2}",nc="[\\ud800-\\udbff][\\udc00-\\udfff]",Zu="\\u200d",rc=xn+"?",ws="["+tc+"]?",Pn="(?:"+Zu+"(?:"+[Rs,ec,nc].join("|")+")"+ws+rc+")*",Nh=ws+rc+Pn,Gn="(?:"+[Rs+Io+"?",Io,ec,nc,li].join("|")+")",k=RegExp(ai+"(?="+ai+")|"+Gn+Nh,"g");function N(T){return T.match(k)||[]}function W(T){return Oh(T)?N(T):Vl(T)}function lt(T){return T==null?"":Qa(T)}var St=/^\s+|\s+$/g;function dt(T,I,O){if(T=lt(T),T&&(O||I===void 0))return T.replace(St,"");if(!T||!(I=Qa(I)))return T;var F=W(T),z=W(I),j=Qu(F,z),J=Ja(F,z)+1;return si(F,j,J).join("")}var $t=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,Zt=/,/,ce=/(=.+)?(\s*)$/,we=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function Se(T){return T=T.toString().replace(we,""),T=T.match($t)[2].replace(" ",""),T=T?T.split(Zt):[],T=T.map(function(I){return dt(I.replace(ce,""))}),T}function De(T,I){var O={};So(T,function(F,z){var j,J=U(F),rt=!J&&F.length===1||J&&F.length===0;if(Oe(F))j=F.slice(0,-1),F=F[F.length-1],O[z]=j.concat(j.length>0?mt:F);else if(rt)O[z]=F;else{if(j=Se(F),F.length===0&&!J&&j.length===0)throw new Error("autoInject task functions require explicit parameters.");J||j.pop(),O[z]=j.concat(mt)}function mt(yt,gt){var Lt=oi(j,function(he){return yt[he]});Lt.push(gt),M(F).apply(null,Lt)}}),Kl(O,I)}function ee(){this.head=this.tail=null,this.length=0}function Rn(T,I){T.length=1,T.head=T.tail=I}ee.prototype.removeLink=function(T){return T.prev?T.prev.next=T.next:this.head=T.next,T.next?T.next.prev=T.prev:this.tail=T.prev,T.prev=T.next=null,this.length-=1,T},ee.prototype.empty=function(){for(;this.head;)this.shift();return this},ee.prototype.insertAfter=function(T,I){I.prev=T,I.next=T.next,T.next?T.next.prev=I:this.tail=I,T.next=I,this.length+=1},ee.prototype.insertBefore=function(T,I){I.prev=T.prev,I.next=T,T.prev?T.prev.next=I:this.head=I,T.prev=I,this.length+=1},ee.prototype.unshift=function(T){this.head?this.insertBefore(this.head,T):Rn(this,T)},ee.prototype.push=function(T){this.tail?this.insertAfter(this.tail,T):Rn(this,T)},ee.prototype.shift=function(){return this.head&&this.removeLink(this.head)},ee.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},ee.prototype.toArray=function(){for(var T=Array(this.length),I=this.head,O=0;O<this.length;O++)T[O]=I.data,I=I.next;return T},ee.prototype.remove=function(T){for(var I=this.head;I;){var O=I.next;T(I)&&this.removeLink(I),I=O}return this};function hn(T,I,O){if(I==null)I=1;else if(I===0)throw new Error("Concurrency must not be zero");var F=M(T),z=0,j=[],J=!1;function rt(Lt,he,nn){if(nn!=null&&typeof nn!="function")throw new Error("task callback must be a function");if(gt.started=!0,Oe(Lt)||(Lt=[Lt]),Lt.length===0&&gt.idle())return E(function(){gt.drain()});for(var Fn=0,Cr=Lt.length;Fn<Cr;Fn++){var ci={data:Lt[Fn],callback:nn||Gt};he?gt._tasks.unshift(ci):gt._tasks.push(ci)}J||(J=!0,E(function(){J=!1,gt.process()}))}function mt(Lt){return function(he){z-=1;for(var nn=0,Fn=Lt.length;nn<Fn;nn++){var Cr=Lt[nn],ci=Ts(j,Cr,0);ci===0?j.shift():ci>0&&j.splice(ci,1),Cr.callback.apply(Cr,arguments),he!=null&&gt.error(he,Cr.data)}z<=gt.concurrency-gt.buffer&&gt.unsaturated(),gt.idle()&&gt.drain(),gt.process()}}var yt=!1,gt={_tasks:new ee,concurrency:I,payload:O,saturated:Gt,unsaturated:Gt,buffer:I/4,empty:Gt,drain:Gt,error:Gt,started:!1,paused:!1,push:function(Lt,he){rt(Lt,!1,he)},kill:function(){gt.drain=Gt,gt._tasks.empty()},unshift:function(Lt,he){rt(Lt,!0,he)},remove:function(Lt){gt._tasks.remove(Lt)},process:function(){if(!yt){for(yt=!0;!gt.paused&&z<gt.concurrency&&gt._tasks.length;){var Lt=[],he=[],nn=gt._tasks.length;gt.payload&&(nn=Math.min(nn,gt.payload));for(var Fn=0;Fn<nn;Fn++){var Cr=gt._tasks.shift();Lt.push(Cr),j.push(Cr),he.push(Cr.data)}z+=1,gt._tasks.length===0&&gt.empty(),z===gt.concurrency&&gt.saturated();var ci=gr(mt(Lt));F(he,ci)}yt=!1}},length:function(){return gt._tasks.length},running:function(){return z},workersList:function(){return j},idle:function(){return gt._tasks.length+z===0},pause:function(){gt.paused=!0},resume:function(){gt.paused!==!1&&(gt.paused=!1,E(gt.process))}};return gt}function wn(T,I){return hn(T,1,I)}var Sn=Xe(ii,1);function bn(T,I,O,F){F=ri(F||Gt);var z=M(O);Sn(T,function(j,J,rt){z(I,j,function(mt,yt){I=yt,rt(mt)})},function(j){F(j,I)})}function Ss(){var T=oi(arguments,M);return function(){var I=r(arguments),O=this,F=I[I.length-1];typeof F=="function"?I.pop():F=Gt,bn(T,I,function(z,j,J){j.apply(O,z.concat(function(rt){var mt=r(arguments,1);J(rt,mt)}))},function(z,j){F.apply(O,[z].concat(j))})}}var Ki=function(){return Ss.apply(null,r(arguments).reverse())},Do=Array.prototype.concat,ic=function(T,I,O,F){F=F||Gt;var z=M(O);pr(T,I,function(j,J){z(j,function(rt){return rt?J(rt):J(null,r(arguments,1))})},function(j,J){for(var rt=[],mt=0;mt<J.length;mt++)J[mt]&&(rt=Do.apply(rt,J[mt]));return F(j,rt)})},$g=Xe(ic,1/0),tf=Xe(ic,1),ef=function(){var T=r(arguments),I=[null].concat(T);return function(){var O=arguments[arguments.length-1];return O.apply(this,I)}};function oc(T){return T}function Ls(T,I){return function(O,F,z,j){j=j||Gt;var J=!1,rt;O(F,function(mt,yt,gt){z(mt,function(Lt,he){Lt?gt(Lt):T(he)&&!rt?(J=!0,rt=I(!0,mt),gt(null,te)):gt()})},function(mt){mt?j(mt):j(null,J?rt:I(!1))})}}function Wn(T,I){return I}var jl=Nr(Ls(oc,Wn)),Vi=Ni(Ls(oc,Wn)),sc=Xe(Vi,1);function Ph(T){return function(I){var O=r(arguments,1);O.push(function(F){var z=r(arguments,1);typeof console=="object"&&(F?console.error&&console.error(F):console[T]&&Ro(z,function(j){console[T](j)}))}),M(I).apply(null,O)}}var Hg=Ph("dir");function jg(T,I,O){O=gr(O||Gt);var F=M(T),z=M(I);function j(rt){if(rt)return O(rt);var mt=r(arguments,1);mt.push(J),z.apply(this,mt)}function J(rt,mt){if(rt)return O(rt);if(!mt)return O(null);F(j)}J(null,!0)}function Fh(T,I,O){O=gr(O||Gt);var F=M(T),z=function(j){if(j)return O(j);var J=r(arguments,1);if(I.apply(this,J))return F(z);O.apply(null,[null].concat(J))};F(z)}function zg(T,I,O){Fh(T,function(){return!I.apply(this,arguments)},O)}function Gg(T,I,O){O=gr(O||Gt);var F=M(I),z=M(T);function j(rt){if(rt)return O(rt);z(J)}function J(rt,mt){if(rt)return O(rt);if(!mt)return O(null);F(j)}z(J)}function Is(T){return function(I,O,F){return T(I,F)}}function nf(T,I,O){Or(T,Is(M(I)),O)}function lc(T,I,O,F){Nn(I)(T,Is(M(O)),F)}var Ds=Xe(lc,1);function rf(T){return U(T)?T:o(function(I,O){var F=!0;I.push(function(){var z=arguments;F?E(function(){O.apply(null,z)}):O.apply(null,z)}),T.apply(this,I),F=!1})}function Pr(T){return!T}var _s=Nr(Ls(Pr,Pr)),ac=Ni(Ls(Pr,Pr)),of=Xe(ac,1);function Wg(T){return function(I){return I==null?void 0:I[T]}}function zl(T,I,O,F){var z=new Array(I.length);T(I,function(j,J,rt){O(j,function(mt,yt){z[J]=!!yt,rt(mt)})},function(j){if(j)return F(j);for(var J=[],rt=0;rt<I.length;rt++)z[rt]&&J.push(I[rt]);F(null,J)})}function Fr(T,I,O,F){var z=[];T(I,function(j,J,rt){O(j,function(mt,yt){mt?rt(mt):(yt&&z.push({index:J,value:j}),rt())})},function(j){j?F(j):F(null,oi(z.sort(function(J,rt){return J.index-rt.index}),Wg("value")))})}function sf(T,I,O,F){var z=us(I)?zl:Fr;z(T,I,M(O),F||Gt)}var lf=Nr(sf),cc=Ni(sf),af=Xe(cc,1);function qg(T,I){var O=gr(I||Gt),F=M(rf(T));function z(j){if(j)return O(j);F(z)}z()}var cf=function(T,I,O,F){F=F||Gt;var z=M(O);pr(T,I,function(j,J){z(j,function(rt,mt){return rt?J(rt):J(null,{key:mt,val:j})})},function(j,J){for(var rt={},mt=Object.prototype.hasOwnProperty,yt=0;yt<J.length;yt++)if(J[yt]){var gt=J[yt].key,Lt=J[yt].val;mt.call(rt,gt)?rt[gt].push(Lt):rt[gt]=[Lt]}return F(j,rt)})},Ms=Xe(cf,1/0),$=Xe(cf,1),Q=Ph("log");function G(T,I,O,F){F=ri(F||Gt);var z={},j=M(O);ii(T,I,function(J,rt,mt){j(J,rt,function(yt,gt){if(yt)return mt(yt);z[rt]=gt,mt()})},function(J){F(J,z)})}var vt=Xe(G,1/0),Nt=Xe(G,1);function oe(T,I){return I in T}function Qe(T,I){var O=Object.create(null),F=Object.create(null);I=I||oc;var z=M(T),j=o(function(rt,mt){var yt=I.apply(null,rt);oe(O,yt)?E(function(){mt.apply(null,O[yt])}):oe(F,yt)?F[yt].push(mt):(F[yt]=[mt],z.apply(null,rt.concat(function(){var gt=r(arguments);O[yt]=gt;var Lt=F[yt];delete F[yt];for(var he=0,nn=Lt.length;he<nn;he++)Lt[he].apply(null,gt)})))});return j.memo=O,j.unmemoized=T,j}var ue;c?ue=process.nextTick:l?ue=setImmediate:ue=d;var uf=h(ue);function Kh(T,I,O){O=O||Gt;var F=us(I)?[]:{};T(I,function(z,j,J){M(z)(function(rt,mt){arguments.length>2&&(mt=r(arguments,1)),F[j]=mt,J(rt)})},function(z){O(z,F)})}function nr(T,I){Kh(Or,T,I)}function uc(T,I,O){Kh(Nn(I),T,O)}var Vh=function(T,I){var O=M(T);return hn(function(F,z){O(F[0],z)},I,1)},Us=function(T,I){var O=Vh(T,I);return O.push=function(F,z,j){if(j==null&&(j=Gt),typeof j!="function")throw new Error("task callback must be a function");if(O.started=!0,Oe(F)||(F=[F]),F.length===0)return E(function(){O.drain()});z=z||0;for(var J=O._tasks.head;J&&z>=J.priority;)J=J.next;for(var rt=0,mt=F.length;rt<mt;rt++){var yt={data:F[rt],priority:z,callback:j};J?O._tasks.insertBefore(J,yt):O._tasks.push(yt)}E(O.process)},delete O.unshift,O};function fc(T,I){if(I=ri(I||Gt),!Oe(T))return I(new TypeError("First argument to race must be an array of functions"));if(!T.length)return I();for(var O=0,F=T.length;O<F;O++)M(T[O])(I)}function Os(T,I,O,F){var z=r(T).reverse();bn(z,I,O,F)}function se(T){var I=M(T);return o(function(F,z){return F.push(function(J,rt){if(J)z(null,{error:J});else{var mt;arguments.length<=2?mt=rt:mt=r(arguments,1),z(null,{value:mt})}}),I.apply(this,F)})}function Xg(T){var I;return Oe(T)?I=oi(T,se):(I={},So(T,function(O,F){I[F]=se.call(this,O)})),I}function $h(T,I,O,F){sf(T,I,function(z,j){O(z,function(J,rt){j(J,!rt)})},F)}var dc=Nr($h),Hh=Ni($h),Yg=Xe(Hh,1);function Qg(T){return function(){return T}}function Ns(T,I,O){var F=5,z=0,j={times:F,intervalFunc:Qg(z)};function J(gt,Lt){if(typeof Lt=="object")gt.times=+Lt.times||F,gt.intervalFunc=typeof Lt.interval=="function"?Lt.interval:Qg(+Lt.interval||z),gt.errorFilter=Lt.errorFilter;else if(typeof Lt=="number"||typeof Lt=="string")gt.times=+Lt||F;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof T=="function"?(O=I||Gt,I=T):(J(j,T),O=O||Gt),typeof I!="function")throw new Error("Invalid arguments for async.retry");var rt=M(I),mt=1;function yt(){rt(function(gt){gt&&mt++<j.times&&(typeof j.errorFilter!="function"||j.errorFilter(gt))?setTimeout(yt,j.intervalFunc(mt)):O.apply(null,arguments)})}yt()}var $i=function(T,I){I||(I=T,T=null);var O=M(I);return o(function(F,z){function j(J){O.apply(null,F.concat(J))}T?Ns(T,j,z):Ns(j,z)})};function hc(T,I){Kh(Sn,T,I)}var mc=Nr(Ls(Boolean,oc)),_o=Ni(Ls(Boolean,oc)),gc=Xe(_o,1);function jh(T,I,O){var F=M(I);ys(T,function(j,J){F(j,function(rt,mt){if(rt)return J(rt);J(null,{value:j,criteria:mt})})},function(j,J){if(j)return O(j);O(null,oi(J.sort(z),Wg("value")))});function z(j,J){var rt=j.criteria,mt=J.criteria;return rt<mt?-1:rt>mt?1:0}}function pc(T,I,O){var F=M(T);return o(function(z,j){var J=!1,rt;function mt(){var yt=T.name||"anonymous",gt=new Error('Callback function "'+yt+'" timed out.');gt.code="ETIMEDOUT",O&&(gt.info=O),J=!0,j(gt)}z.push(function(){J||(j.apply(null,arguments),clearTimeout(rt))}),rt=setTimeout(mt,I),F.apply(null,z)})}var Jg=Math.ceil,Cc=Math.max;function Ps(T,I,O,F){for(var z=-1,j=Cc(Jg((I-T)/(O||1)),0),J=Array(j);j--;)J[F?j:++z]=T,T+=O;return J}function Fs(T,I,O,F){var z=M(O);pr(Ps(0,T,1),I,z,F)}var Zg=Xe(Fs,1/0),tp=Xe(Fs,1);function ep(T,I,O,F){arguments.length<=3&&(F=O,O=I,I=Oe(T)?[]:{}),F=ri(F||Gt);var z=M(O);Or(T,function(j,J,rt){z(I,j,J,rt)},function(j){F(j,I)})}function Ec(T,I){var O=null,F;I=I||Gt,Ds(T,function(z,j){M(z)(function(J,rt){arguments.length>2?F=r(arguments,1):F=rt,O=J,j(!J)})},function(){I(O,F)})}function Ac(T){return function(){return(T.unmemoized||T).apply(null,arguments)}}function xc(T,I,O){O=gr(O||Gt);var F=M(I);if(!T())return O(null);var z=function(j){if(j)return O(j);if(T())return F(z);var J=r(arguments,1);O.apply(null,[null].concat(J))};F(z)}function np(T,I,O){xc(function(){return!T.apply(this,arguments)},I,O)}var zh=function(T,I){if(I=ri(I||Gt),!Oe(T))return I(new Error("First argument to waterfall must be an array of functions"));if(!T.length)return I();var O=0;function F(j){var J=M(T[O++]);j.push(gr(z)),J.apply(null,j)}function z(j){if(j||O===T.length)return I.apply(null,arguments);F(r(arguments,1))}F([])},_x={apply:i,applyEach:Ga,applyEachSeries:qa,asyncify:A,auto:Kl,autoInject:De,cargo:wn,compose:Ki,concat:$g,concatLimit:ic,concatSeries:tf,constant:ef,detect:jl,detectLimit:Vi,detectSeries:sc,dir:Hg,doDuring:jg,doUntil:zg,doWhilst:Fh,during:Gg,each:nf,eachLimit:lc,eachOf:Or,eachOfLimit:ii,eachOfSeries:Sn,eachSeries:Ds,ensureAsync:rf,every:_s,everyLimit:ac,everySeries:of,filter:lf,filterLimit:cc,filterSeries:af,forever:qg,groupBy:Ms,groupByLimit:cf,groupBySeries:$,log:Q,map:ys,mapLimit:pr,mapSeries:Wa,mapValues:vt,mapValuesLimit:G,mapValuesSeries:Nt,memoize:Qe,nextTick:uf,parallel:nr,parallelLimit:uc,priorityQueue:Us,queue:Vh,race:fc,reduce:bn,reduceRight:Os,reflect:se,reflectAll:Xg,reject:dc,rejectLimit:Hh,rejectSeries:Yg,retry:Ns,retryable:$i,seq:Ss,series:hc,setImmediate:E,some:mc,someLimit:_o,someSeries:gc,sortBy:jh,timeout:pc,times:Zg,timesLimit:Fs,timesSeries:tp,transform:ep,tryEach:Ec,unmemoize:Ac,until:np,waterfall:zh,whilst:xc,all:_s,allLimit:ac,allSeries:of,any:mc,anyLimit:_o,anySeries:gc,find:jl,findLimit:Vi,findSeries:sc,forEach:nf,forEachSeries:Ds,forEachLimit:lc,forEachOf:Or,forEachOfSeries:Sn,forEachOfLimit:ii,inject:bn,foldl:bn,foldr:Os,select:lf,selectLimit:cc,selectSeries:af,wrapSync:A};e.default=_x,e.apply=i,e.applyEach=Ga,e.applyEachSeries=qa,e.asyncify=A,e.auto=Kl,e.autoInject=De,e.cargo=wn,e.compose=Ki,e.concat=$g,e.concatLimit=ic,e.concatSeries=tf,e.constant=ef,e.detect=jl,e.detectLimit=Vi,e.detectSeries=sc,e.dir=Hg,e.doDuring=jg,e.doUntil=zg,e.doWhilst=Fh,e.during=Gg,e.each=nf,e.eachLimit=lc,e.eachOf=Or,e.eachOfLimit=ii,e.eachOfSeries=Sn,e.eachSeries=Ds,e.ensureAsync=rf,e.every=_s,e.everyLimit=ac,e.everySeries=of,e.filter=lf,e.filterLimit=cc,e.filterSeries=af,e.forever=qg,e.groupBy=Ms,e.groupByLimit=cf,e.groupBySeries=$,e.log=Q,e.map=ys,e.mapLimit=pr,e.mapSeries=Wa,e.mapValues=vt,e.mapValuesLimit=G,e.mapValuesSeries=Nt,e.memoize=Qe,e.nextTick=uf,e.parallel=nr,e.parallelLimit=uc,e.priorityQueue=Us,e.queue=Vh,e.race=fc,e.reduce=bn,e.reduceRight=Os,e.reflect=se,e.reflectAll=Xg,e.reject=dc,e.rejectLimit=Hh,e.rejectSeries=Yg,e.retry=Ns,e.retryable=$i,e.seq=Ss,e.series=hc,e.setImmediate=E,e.some=mc,e.someLimit=_o,e.someSeries=gc,e.sortBy=jh,e.timeout=pc,e.times=Zg,e.timesLimit=Fs,e.timesSeries=tp,e.transform=ep,e.tryEach=Ec,e.unmemoize=Ac,e.until=np,e.waterfall=zh,e.whilst=xc,e.all=_s,e.allLimit=ac,e.allSeries=of,e.any=mc,e.anyLimit=_o,e.anySeries=gc,e.find=jl,e.findLimit=Vi,e.findSeries=sc,e.forEach=nf,e.forEachSeries=Ds,e.forEachLimit=lc,e.forEachOf=Or,e.forEachOfSeries=Sn,e.forEachOfLimit=ii,e.inject=bn,e.foldl=bn,e.foldr=Os,e.select=lf,e.selectLimit=cc,e.selectSeries=af,e.wrapSync=A,Object.defineProperty(e,"__esModule",{value:!0})})})(_C,_C.exports);var Hy={exports:{}},MC=Hy.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),r=2;e===1/0;r*=2)e=Math.log(Math.pow(2,n/r))/Math.log(t)*r;for(var i=e-Math.floor(e),o="",r=0;r<Math.floor(e);r++){var s=Math.floor(Math.random()*t).toString(t);o=s+o}if(i){var l=Math.pow(t,i),s=Math.floor(Math.random()*l).toString(t);o=s+o}var c=parseInt(o,t);return c!==1/0&&c>=Math.pow(2,n)?MC(n,t):o};MC.rack=function(n,t,e){var r=function(o){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=MC(n,t)}while(Object.hasOwnProperty.call(i,l));return i[l]=o,l},i=r.hats={};return r.get=function(o){return r.hats[o]},r.set=function(o,s){return r.hats[o]=s,r},r.bits=n||128,r.base=t||16,r};var jy=ul,kU=Vy,RU=$y,gm=Qr,UC=_C.exports,wU=Hy.exports,zy=dl.ACTIONS,Gy=an;function an(n,t){if(jy.EventEmitter.call(this),!t||typeof t!="string")throw new Error("Presence channel must be provided");this.connection=n,this.channel=t,this.wantSubscribe=!1,this.subscribed=!1,this.remotePresences={},this.localPresences={},this._remotePresenceInstances={},this._subscriptionCallbacksBySeq={},this._wantsDestroy=!1}jy.mixin(an),an.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},an.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},an.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||wU();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},an.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(r){if(r)return t._callbackOrEmit(r,n);var i=Object.keys(t._remotePresenceInstances);UC.parallel([function(o){UC.each(e,function(s,l){t.localPresences[s].destroy(l)},o)},function(o){if(!t._wantsDestroy)return o();UC.each(i,function(s,l){t._remotePresenceInstances[s].destroy(l)},o)}],function(o){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(o,n)})})},an.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?zy.presenceSubscribe:zy.presenceUnsubscribe,r=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[r]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,r,this)},an.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},an.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},an.prototype._receiveUpdate=function(n,t){var e=gm.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var r=this,i=gm.digOrCreate(this._remotePresenceInstances,t.id,function(){return r._createRemotePresence(t.id)});i.receiveUpdate(t)},an.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},an.prototype._broadcastAllLocalPresence=function(n){if(n)return this.emit("error",n);for(var t in this.localPresences){var e=this.localPresences[t];e.value!==null&&e.send()}},an.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},an.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},an.prototype._resubscribe=function(){var n=[];for(var t in this._subscriptionCallbacksBySeq){var e=this._subscriptionCallback(t);n.push(e)}if(!this.wantSubscribe)return this._callEachOrEmit(n);var r=this;this.subscribe(function(i){r._callEachOrEmit(n,i)})},an.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},an.prototype._callbackOrEmit=function(n,t){if(t)return gm.nextTick(t,n);n&&this.emit("error",n)},an.prototype._createLocalPresence=function(n){return new kU(this,n)},an.prototype._createRemotePresence=function(n){return new RU(this,n)},an.prototype._callEachOrEmit=function(n,t){var e=gm.callEach(n,t);!e&&t&&this.emit("error",t)};var od=Vy,Wy=fm,SU=Qr,qy=Wy.CODES,LU=ki;function ki(n,t){od.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._isSending=!1,this._docDataVersionByPresenceVersion={},this._opHandler=this._transformAgainstOp.bind(this),this._createOrDelHandler=this._handleCreateOrDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._destroyHandler=this.destroy.bind(this),this._registerWithDoc()}ki.prototype=Object.create(od.prototype),ki.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:qy.ERR_DOC_DOES_NOT_EXIST,message:"Cannot submit presence. Document has not been created"};return this._callbackOrEmit(e,t)}this._docDataVersionByPresenceVersion[this.presenceVersion]=this._doc._dataStateVersion,od.prototype.submit.call(this,n,t)},ki.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),this._emitter.removeEventListener(this._doc,"destroy",this._destroyHandler),od.prototype.destroy.call(this,n)},ki.prototype._sendPending=function(){if(!this._isSending){this._isSending=!0;var n=this;this._doc.whenNothingPending(function(){n._isSending=!1,n.connection.canSend&&(n._pendingMessages.forEach(function(t){t.t=n._doc.type.uri,t.v=n._doc.version,n.connection.send(t)}),n._pendingMessages=[],n._docDataVersionByPresenceVersion={})})}},ki.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler),this._emitter.addEventListener(this._doc,"destroy",this._destroyHandler)},ki.prototype._transformAgainstOp=function(n,t){var e=this,r=this._doc._dataStateVersion;this._pendingMessages.forEach(function(i){var o=e._docDataVersionByPresenceVersion[i.pv];if(!(o>=r))try{i.p=e._transformPresence(i.p,n,t),e._docDataVersionByPresenceVersion[i.pv]=r}catch(l){var s=e._getCallback(i.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(i){this.emit("error",i)}},ki.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},ki.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},ki.prototype._message=function(){var n=od.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},ki.prototype._transformPresence=function(n,t,e){var r=this._doc.type;if(!SU.supportsPresence(r))throw new Wy(qy.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+r.name);return r.transformPresence(n,t,e)};var Xy={};(function(n){var t=ed,e=fm,r=Qr,i=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var c=l.create.type;if(typeof c!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[c];if(d==null||typeof d!="object")return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(i.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(i.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(i.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,c){if(typeof l!="object")return new e(i.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&c.v!=null&&l.v!==c.v)return new e(i.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(c.create){if(l.type)return new e(i.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=c.create,h=t.map[d.type];if(!h)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(E){return E}}else if(c.del)l.data=void 0,l.type=null,l.v++;else if("op"in c){var C=o(l,c.op);if(C)return C;l.v++}else l.v++};function o(l,c){if(!l.type)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(c===void 0)return new e(i.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,c)}catch(h){return new e(i.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,c,d){if(c.v!=null&&c.v!==d.v)return new e(i.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(c.create||"op"in c)return new e(i.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in c||c.create||c.del)||"op"in d&&c.create)return new e(i.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in c){if(!l)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{c.op=l.transform(c.op,d.op,"left")}catch(h){return h}}}c.v!=null&&c.v++},n.applyOps=function(l,c,d){d=d||{};for(var h=0;h<c.length;h++){var C=c[h];if(d._normalizeLegacyJson0Ops)try{s(l,C)}catch{return new e(i.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=C.v;var E=n.apply(l,C);if(E)return E}},n.transformPresence=function(l,c,d){var h=this.checkOp(c);if(h)return h;var C=l.t;if(typeof C=="string"&&(C=t.map[C]),!C)return{code:i.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!r.supportsPresence(C))return{code:i.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(c.create||c.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:C.transformPresence(l.p,c.op,d)}catch(E){return{code:i.ERR_PRESENCE_TRANSFORM_FAILED,message:E.message||E}}l.v++};function s(l,c){if(l.type===t.defaultType.uri){var d=c.op;if(!!d){var h=l.data;d.length>1&&(h=r.clone(h));for(var C=0;C<d.length;C++){var E=d[C];typeof E.lm=="string"&&(E.lm=+E.lm);for(var A=E.p,v=h,w=0;w<A.length;w++){var S=A[w];Object.prototype.toString.call(v)=="[object Array]"?A[w]=+S:v.constructor===Object&&(A[w]=S.toString()),v=v[S]}C<d.length-1&&(h=t.defaultType.apply(h,[E]))}}}}})(Xy);var sd=$y,IU=Xy,DU=Jr;function Jr(n,t){sd.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this.src=null,this.presenceVersion=null,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._pending=null,this._opCache=null,this._pendingSetPending=!1,this._opHandler=this._handleOp.bind(this),this._createDelHandler=this._handleCreateDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._registerWithDoc()}Jr.prototype=Object.create(sd.prototype),Jr.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},Jr.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),sd.prototype.destroy.call(this,n)},Jr.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createDelHandler),this._emitter.addEventListener(this._doc,"del",this._createDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler)},Jr.prototype._setPendingPresence=function(){if(!this._pendingSetPending){this._pendingSetPending=!0;var n=this;this._doc.whenNothingPending(function(){if(n._pendingSetPending=!1,!!n._pending){if(n._pending.pv<n.presenceVersion)return n._pending=null;if(n._pending.v>n._doc.version)return n._doc.fetch();!n._catchUpStalePresence()||(n.value=n._pending.p,n.presenceVersion=n._pending.pv,n._pending=null,n.presence._updateRemotePresence(n))}})}},Jr.prototype._handleOp=function(n,t,e){var r=e===this.src;this._transformAgainstOp(n,r),this._cacheOp(n,r),this._setPendingPresence()},sd.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},sd.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},Jr.prototype._transformAgainstOp=function(n,t){if(!!this.value){try{this.value=this._doc.type.transformPresence(this.value,n,t)}catch(e){return this.presence.emit("error",e)}this.presence._updateRemotePresence(this)}},Jr.prototype._catchUpStalePresence=function(){if(this._pending.v>=this._doc.version)return!0;if(!this._opCache)return this._startCachingOps(),this._doc.fetch(),this.presence.subscribe(),!1;for(;this._opCache[this._pending.v];){var n=this._opCache[this._pending.v],t=n.op,e=n.isOwnOp;t===null?(this._pending.p=null,this._pending.v++):IU.transformPresence(this._pending,t,e)}var r=this._pending.v>=this._doc.version;return r&&this._stopCachingOps(),r},Jr.prototype._startCachingOps=function(){this._opCache=[]},Jr.prototype._stopCachingOps=function(){this._opCache=null},Jr.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var Yy=Gy,_U=LU,MU=DU;function tu(n,t,e){var r=tu.channel(t,e);Yy.call(this,n,r),this.collection=t,this.id=e}var UU=tu;tu.prototype=Object.create(Yy.prototype),tu.channel=function(n,t){return n+"."+t},tu.prototype._createLocalPresence=function(n){return new _U(this,n)},tu.prototype._createRemotePresence=function(n){return new MU(this,n)};var OU=NU;function NU(n,t,e,r,i){this.id=n,this.v=t,this.type=e,this.data=r,this.m=i}var PU=OU,Qy=ul,Jy=ld;function ld(n,t,e,r,i){if(Qy.EventEmitter.call(this),typeof i!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=r,this.collection=e,this.callback=i,this.sent=!1}Qy.mixin(ld),ld.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},ld.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},ld.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,r=new PU(this.id,t.v,t.type,t.data,e);this.callback(null,r)};var Zy=Jy,FU=Qr,KU=dl.ACTIONS,VU=OC;function OC(n,t,e,r,i,o){if(Zy.call(this,n,t,e,r,o),!FU.isValidVersion(i))throw new Error("Snapshot version must be a positive integer or null");this.version=i}OC.prototype=Object.create(Zy.prototype),OC.prototype._message=function(){return{a:KU.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var tT=Jy,$U=Qr,HU=dl.ACTIONS,jU=NC;function NC(n,t,e,r,i,o){if(tT.call(this,n,t,e,r,o),!$U.isValidTimestamp(i))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=i}NC.prototype=Object.create(tT.prototype),NC.prototype._message=function(){return{a:HU.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var oo=Qr,zU=Sp.default.EventEmitter,GU=["create","del","destroy","load","op"],WU=ad;function ad(){this._docs={},this._forwarders={},this._emitters={}}ad.prototype.addEventListener=function(n,t,e){this._registerDoc(n);var r=oo.dig(this._emitters,n.collection,n.id);r.on(t,e)},ad.prototype.removeEventListener=function(n,t,e){var r=oo.dig(this._emitters,n.collection,n.id);!r||(r.off(t,e),r._eventsCount===1&&this._unregisterDoc(n))},ad.prototype._registerDoc=function(n){var t=!0;if(oo.digOrCreate(this._docs,n.collection,n.id,function(){return t=!1,n}),!t){var e=oo.digOrCreate(this._emitters,n.collection,n.id,function(){var i=new zU;return i.setMaxListeners(1e3),i}),r=this;GU.forEach(function(i){var o=oo.digOrCreate(r._forwarders,n.collection,n.id,i,function(){return e.emit.bind(e,i)});n.on(i,o)}),this.addEventListener(n,"destroy",this._unregisterDoc.bind(this,n))}},ad.prototype._unregisterDoc=function(n){var t=oo.dig(this._forwarders,n.collection,n.id);for(var e in t)n.off(e,t[e]);var r=oo.dig(this._emitters,n.collection,n.id);r.removeAllListeners(),oo.digAndRemove(this._forwarders,n.collection,n.id),oo.digAndRemove(this._emitters,n.collection,n.id),oo.digAndRemove(this._docs,n.collection,n.id)};var qU=CU,XU=vU,YU=Gy,eT=UU,QU=VU,JU=jU,nT=ul,eu=fm,ye=dl.ACTIONS,rT=ed,Ri=Qr,cd=Dy,ZU=WU,ud=eu.CODES;function iT(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var tO=Ut;function Ut(n){nT.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._docPresenceEmitter=new ZU,this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=iT(n),this.bindToSocket(n)}nT.mixin(Ut),Ut.prototype.bindToSocket=function(n){this.socket&&(this.socket.close(),this.socket.onmessage=null,this.socket.onopen=null,this.socket.onerror=null,this.socket.onclose=null),this.socket=n;var t=iT(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(r){try{var i=typeof r.data=="string"?JSON.parse(r.data):r.data}catch{cd.warn("Failed to parse message",r);return}e.debug&&cd.info("RECV",JSON.stringify(i));var o={data:i};if(e.emit("receive",o),!!o.data)try{e.handleMessage(o.data)}catch(s){Ri.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(r){e.emit("connection error",r)},n.onclose=function(r){r==="closed"||r==="Closed"?e._setState("closed",r):r==="stopped"||r==="Stopped by server"?e._setState("stopped",r):e._setState("disconnected",r)}},Ut.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=oT(n.error,n),delete n.error),n.a){case ye.initLegacy:return this._handleLegacyInit(n);case ye.handshake:return this._handleHandshake(t,n);case ye.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case ye.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case ye.queryUnsubscribe:return;case ye.queryUpdate:var e=this.queries[n.id];if(!e)return;if(t)return e._handleError(t);n.diff&&e._handleDiff(n.diff),n.hasOwnProperty("extra")&&e._handleExtra(n.extra);return;case ye.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case ye.bulkSubscribe:case ye.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case ye.snapshotFetch:case ye.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case ye.fetch:var r=this.getExisting(n.c,n.d);r&&r._handleFetch(t,n.data);return;case ye.subscribe:case ye.unsubscribe:var r=this.getExisting(n.c,n.d);r&&r._handleSubscribe(t,n.data);return;case ye.op:var r=this.getExisting(n.c,n.d);r&&r._handleOp(t,n);return;case ye.presence:return this._handlePresence(t,n);case ye.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case ye.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case ye.presenceRequest:return this._handlePresenceRequest(t,n);case ye.pingPong:return this._handlePingPong(t);default:cd.warn("Ignoring unrecognized message",n)}};function oT(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}Ut.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var r in t.data){var i=t.data[r],o=this.getExisting(t.c,r);o&&(n?o[e](n):i.error?o[e](oT(i.error)):o[e](null,i))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var r=t.b[s],o=this.getExisting(t.c,r);o&&o[e](n)}else if(t.b)for(var r in t.b){var o=this.getExisting(t.c,r);o&&o[e](n)}else cd.error("Invalid bulk message",t)},Ut.prototype._reset=function(){this.agent=null},Ut.prototype._setState=function(n,t){if(this.state!==n){if(n==="connecting"&&this.state!=="disconnected"&&this.state!=="stopped"&&this.state!=="closed"||n==="connected"&&this.state!=="connecting"){var e=new eu(ud.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var r in this.queries){var i=this.queries[r];i._onConnectionStateChanged()}for(var o in this.collections){var s=this.collections[o];for(var r in s)s[r]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var r in this._snapshotRequests){var c=this._snapshotRequests[r];c._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},Ut.prototype.startBulk=function(){this.bulk||(this.bulk={})},Ut.prototype.endBulk=function(){if(this.bulk)for(var n in this.bulk){var t=this.bulk[n];this._sendBulk("f",n,t.f),this._sendBulk("s",n,t.s),this._sendBulk("u",n,t.u)}this.bulk=null},Ut.prototype._sendBulk=function(n,t,e){if(!!e){var r=[],i={},o=0,s;for(var l in e){var c=e[l];c==null?r.push(l):(i[l]=c,s=l,o++)}if(r.length===1){var l=r[0];this.send({a:n,c:t,d:l})}else r.length&&this.send({a:"b"+n,c:t,b:r});if(o===1){var d=i[s];this.send({a:n,c:t,d:s,v:d})}else o&&this.send({a:"b"+n,c:t,b:i})}},Ut.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var r=this.bulk[t.collection]||(this.bulk[t.collection]={}),i=r[n]||(r[n]={}),o=i.hasOwnProperty(t.id);return i[t.id]=e,o}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},Ut.prototype.sendFetch=function(n){return this._sendActions(ye.fetch,n,n.version)},Ut.prototype.sendSubscribe=function(n){return this._sendActions(ye.subscribe,n,n.version)},Ut.prototype.sendUnsubscribe=function(n){return this._sendActions(ye.unsubscribe,n)},Ut.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:ye.op,c:n.collection,d:n.id,v:n.version,src:t.src,seq:t.seq,x:{}};"op"in t&&(e.op=t.op),t.create&&(e.create=t.create),t.del&&(e.del=t.del),n.submitSource&&(e.x.source=t.source),this.send(e)},Ut.prototype.send=function(n){this.debug&&cd.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},Ut.prototype.ping=function(){if(!this.canSend)throw new eu(ud.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:ye.pingPong};this.send(n)},Ut.prototype.close=function(){this.socket.close()},Ut.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},Ut.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),r=e[t];return r||(r=e[t]=new qU(this,n,t),this.emit("doc",r)),r._wantsDestroy=!1,r},Ut.prototype._destroyDoc=function(n){!n._wantsDestroy||(Ri.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},Ut.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},Ut.prototype._createQuery=function(n,t,e,r,i){var o=this.nextQueryId++,s=new XU(n,this,o,t,e,r,i);return this.queries[o]=s,s.send(),s},Ut.prototype._destroyQuery=function(n){delete this.queries[n.id]},Ut.prototype.createFetchQuery=function(n,t,e,r){return this._createQuery(ye.queryFetch,n,t,e,r)},Ut.prototype.createSubscribeQuery=function(n,t,e,r){return this._createQuery(ye.querySubscribe,n,t,e,r)},Ut.prototype.hasPending=function(){return!!(this._firstDoc(pm)||this._firstQuery(pm)||this._firstSnapshotRequest())};function pm(n){return n.hasPending()}Ut.prototype.hasWritePending=function(){return!!this._firstDoc(eO)};function eO(n){return n.hasWritePending()}Ut.prototype.whenNothingPending=function(n){var t=this._firstDoc(pm);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(pm);if(e){e.once("ready",this._nothingPendingRetry(n));return}var r=this._firstSnapshotRequest();if(r){r.once("ready",this._nothingPendingRetry(n));return}Ri.nextTick(n)},Ut.prototype._nothingPendingRetry=function(n){var t=this;return function(){Ri.nextTick(function(){t.whenNothingPending(n)})}},Ut.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var r in e){var i=e[r];if(n(i))return i}}},Ut.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},Ut.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},Ut.prototype.fetchSnapshot=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new QU(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},Ut.prototype.fetchSnapshotByTimestamp=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new JU(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},Ut.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},Ut.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},Ut.prototype._initializeHandshake=function(){this.send({a:ye.handshake,id:this.id})},Ut.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},Ut.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},Ut.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new eu(ud.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(rT.map[n.type]!==rT.defaultType)return this.emit("error",new eu(ud.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new eu(ud.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},Ut.prototype.getPresence=function(n){var t=this,e=Ri.digOrCreate(this._presences,n,function(){return new YU(t,n)});return e._wantsDestroy=!1,e},Ut.prototype.getDocPresence=function(n,t){var e=eT.channel(n,t),r=this,i=Ri.digOrCreate(this._presences,e,function(){return new eT(r,n,t)});return i._wantsDestroy=!1,i},Ut.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var r={a:n,ch:e.channel,seq:t};return this.send(r),r.seq},Ut.prototype._addPresence=function(n){Ri.digOrCreate(this._presences,n.channel,function(){return n})},Ut.prototype._handlePresenceSubscribe=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},Ut.prototype._handlePresenceUnsubscribe=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},Ut.prototype._handlePresence=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},Ut.prototype._handlePresenceRequest=function(n,t){var e=Ri.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var sT=tO,nO=ed;const fd={err:1001,msg:"user auth error",name:"AuthError"},Cm={err:1002,msg:"you don't have required permission",name:"PermissionError"},PC={err:1003,msg:"Too many user connected",name:"MaxUserError"},dd={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},rO={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},iO={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},ba="x-live-editor-token",nu="x-live-editor-base-url",En=D("auth-connection");function oO(n){try{n()}catch(t){En.error(t)}}class sO{constructor(t,e){m(this,"enabled",!0);m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new kb.EventEmitter);m(this,"token",null);m(this,"resourceToken",null);m(this,"pingOptions",{interval:5e4,timeout:15e4});m(this,"reAuth",async()=>{if(!this.enabled||!this.connection||!this.reauthFunc)return;if(window.isReauthError&&yr.level===Gi.DEBUG)throw new Error("reauth error");const t=await this.reauthFunc();await this.auth(t);const e=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:e}})}});this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return qi(this.getBaseURL())}async auth(t){p(En,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,r=await window.fetch(e,{method:"GET",headers:{[ba]:t.token,[nu]:this.getBase64BaseURL()},credentials:"include"});return r.status,this.enabled?(this.token=t.token,await r.json()):{read:"",user:""}}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[nu]:qi(this.getBaseURL())}})}async init(t){const e=await this.auth(t);if(!this.enabled)return;this.resourceToken=e.read,this.ws=new c9.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(sT.prototype),p(En,this.connection,"no this.connection");const r=this.ws,i=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:i}}),this._ping==null&&(this._ping=window.setInterval(()=>{var d;const c=Date.now();c-((d=this.lastReceiveTime)!=null?d:0)>i.interval&&this.send({a:"ping",id:this.id,ts:c}),this.lastReceiveTime&&c-this.lastReceiveTime>i.timeout&&r&&r.readyState===r.OPEN&&(r.reconnect(),this.lastReceiveTime=Date.now())},1e3))};const o=this.connection.handleMessage.bind(this.connection);let s=!1;this.connection.handleMessage=l=>{var d;const c=l;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in c||c.a==="pong")s=!1,this.handleMessage(c);else{Object.prototype.hasOwnProperty.call(c,"a")&&c.a==="hs"&&this.retryCount>0&&(s?(En.info("retrying re-auth success"),s=!1,this.emitAuthRecover()):s=!0),Object.prototype.hasOwnProperty.call(c,"a")&&c.a!=="init"&&c.a!=="hs"&&(this.retryCount=0);try{o(c)}catch(h){if((h==null?void 0:h.type)==="writeConflict"){this.emitWriteConflictError(h,c);return}if((d=h==null?void 0:h.message)!=null&&d.startsWith("Cannot invert subtype")){this.emitWriteConflictError(h,c);return}throw h}}},sT.apply(this.connection,[this.ws])}async reConnect(t){var r,i;(r=this.ws)==null||r.close();const e=this.pingOptions;if(this.connection&&this.reauthFunc){const o=await this.reauthFunc();await this.auth(o),(i=this.ws)==null||i.reconnect(),this.connection._initializeHandshake=function(){t&&(o.token=t),this.send({a:"hs",id:this.id,auth:o,options:{ping:e}})}}}async _autoReAuth(){this.retryCount+=1,En.info(`retrying re-auth attempt no. ${this.retryCount}`);try{await this.reAuth()}catch(t){En.error(t),this.retryCount>=5&&(En.warn("retry auth times exceed 5, broadcast auth error"),this.emitAuthError());const e=30*1e3;await new Promise((r,i)=>{setTimeout(()=>{this._autoReAuth().then(r).catch(i)},Math.min(2*this.retryCount*1e3,e))})}}async autoReAuth(){var t,e;if(!this.enabled||this.retryCount>0){En.debug("autoReAuth: not enabled or retryCount > 0");return}En.log("autoReAuth begin!"),(t=this.ws)==null||t.close(),await this._autoReAuth(),En.log("autoReAuth end!"),(e=this.ws)==null||e.reconnect()}async handleAuthError(){this.autoReAuth()}emitPermissionError(){const t=new Error(Cm.msg);t.code=Cm.err,this.events.emit("error",t)}emitAuthRecover(){this.events.emit("authRecover")}emitAuthError(){const t=new Error(fd.msg);t.code=fd.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(dd.msg);t.code=dd.err,this.events.emit("requestReloadError",t)}emitWriteConflictError(t,e){t.orgMsg=e,this.events.emit("writeConflictError",t)}emitMaxUsersError(){this.events.emit("maxUsersError"),this.end(!1)}handleMessage(t){const e=t;if(e.a==="pong")return;const r=e.err;if(r===fd.err)En.warn("auth error"),this.handleAuthError();else if(r===PC.err)En.warn(PC.msg),this.emitMaxUsersError();else if(r===dd.err){En.warn(dd.msg);try{this.emitRequestReloadError()}catch(i){En.error(`error occurred while process reload error: ${JSON.stringify(i)}`)}finally{this.end(!1)}}else r===Cm.err?this.emitPermissionError():(En.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError())}get(t,e){return p(En,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(p(En,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onAuthError(t){this.events.addListener("error",t)}onAuthRecover(t){this.events.addListener("authRecover",t)}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){p(En,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){p(En,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e,r;this.enabled=!1,this.reauthFunc=void 0,this.events.removeAllListeners(),oO(()=>{var i;return(i=this.connection)==null?void 0:i.close()}),(e=this.connection)!=null&&e._ping&&window.clearInterval(this.connection._ping),this.connection=void 0,(r=this.ws)==null||r.close(),this.ws=void 0,t&&this.logout()}}D("utils/file");function lO(){function n(){return new Promise(t=>{const e=new FileReader;e.onload=()=>{t(e.result)},e.readAsArrayBuffer(this)})}File.prototype.arrayBuffer=File.prototype.arrayBuffer||n,Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||n}lO();async function aO(n){const e=n.size,r=Math.floor((e+102400-1)/102400),i=new u9.Hash;for(let s=0;s<r;s++){const l=s*102400;let c=l+102400;c>e&&(c=e);const h=await n.slice(l,c,n.type).arrayBuffer();i.update(new Uint8Array(h))}const o=i.digest();return qi(o)}const so=D("sharedb-doc/client"),cO=Rb.default.create();class uO{constructor(t,e,r){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",it());m(this,"getDoc",async()=>{const t=r=>new Promise((i,o)=>{r.fetch(s=>{s?o(s):i()})});p(so,!this.doc,"This websocket has opened a doc."),await this.connection.init(this.auth);const e=this.connection.get(this.auth.appId,this.auth.docId);return this.doc=e,await t(e),so.debug(e),e});this.auth=t;const i=`${e}/${this.auth.appId}/${this.auth.docId}`;nO.register(n0.type),this.connection=new sO(i,r),this.reauthFunc=r}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(so,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,r=>{(t==="error"||this.doc)&&e(r)})}onAuthError(t){this.connection.onAuthError(t)}onAuthRecover(t){this.connection.onAuthRecover(t)}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,r,i,o){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...o},data:{name:r,size:i}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const r=`${this.apiServer()}/resources`;try{const i=`${r}/hash`,o=await this.request(i,{method:"post",headers:{[ba]:this.connection.token},data:{resources:t}});return o.data&&Array.isArray(o.data)?o.data:[]}catch{return[]}}async uploadFile(t,e,r,i,o){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=A=>{so.info(`on progress: ${A.loaded}`);let v=A.loaded*100/s;v>100&&(v=100),i(v)},c=await aO(e),d=await this.getFileUrlByHash(t,c,e.name,e.size,r);if(d)return i(-1),d;let h=t;o!=null&&o.thumbnail&&(h+="/thumbnail");const C=new FormData;C.append("file-size",`${e.size}`),C.append("file-hash",c),C.append("file",e,e.name);const E=await this.request(h,{method:"post",data:C,withCredentials:!0,headers:{...r},onUploadProgress:l});return so.info(E),i(100),Array.isArray(E.data)?E.data[0]:E.data}async uploadResource(t,e=()=>{},r){const o=`${this.apiServer()}/resources`;p(so,this.connection.token,"no connection token");const s=await this.uploadFile(o,t,{[ba]:this.connection.token},e,r);return p(so,s,"no result"),s}async request(t,e){var o,s;let r=this.connection.token,i;for(let l=0;l<2;l++){const c=e||{};c.url=t,c.headers||(c.headers={}),p(so,r,"no token"),c.headers={...c.headers,[ba]:r,[nu]:this.connection.getBase64BaseURL()};try{if(window.isReauthError&&yr.level===Gi.DEBUG)throw new Error("reauth error");return await cO(t,c)}catch(d){if(i=d,((o=d==null?void 0:d.response)==null?void 0:o.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;r=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw p(so,i,"no error"),i}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=wb.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(so,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const r=`${this.apiServer()}/resources/external/${qi(t)}`;return(await this.request(r)).data}getResourceId(t){const e=/\/resources\/([^?]+)/,r=t.match(e);return r&&r.length>=2?r[1]:""}buildResourceUrl(t,e){var s,l;if(!t)return"";if(t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;const r=this.apiServer();if(t.startsWith("http:")||t.startsWith("https:")){const c=r.replace(/\/[^/]*$/,"");if(c&&t.includes(c)){const d=this.auth.docId,h=`${c}/`,C="/resources",E=t.indexOf(h),A=t.indexOf(C,E+h.length);if(E!==-1&&A!==-1){const v=t.substring(E+h.length,A);if(v!==d){let w=t.replace(v,d);const S=new URL(w),U="token";(s=S.searchParams)==null||s.delete(U),w=S.toString();const M=this.getResourceId(w);return e!=null&&e.syncNewResources&&((l=e==null?void 0:e.syncNewResources)==null||l.call(e,M,w)),w}return t}return t}return t}let i=`${r}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken&&o.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const c=o.join("&");i+=`?${c}`}return i}reAuth(t=!1){t?this.connection.autoReAuth():this.connection.reAuth()}}function fO(){return{blocks:[{id:it(),type:"text",text:[]}],comments:{},meta:{}}}const FC=D("block-ids");class dO{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((i,o)=>o-i);for(let i=0;i<e.length;i++){const o=e[i];if(o>=t){const s=this.ids.get(o);p(FC,s!==void 0,"old id is not exists"),this.ids.delete(o),this.ids.set(o+1,s)}}const r=it();this.ids.set(t,r)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((r,i)=>r-i);for(let r=0;r<e.length;r++){const i=e[r];if(i>t){const o=this.ids.get(i);p(FC,o!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i-1,o)}}}getId(t){let e=this.ids.get(t);return e||(e=it(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class hO{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new dO,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let r=0;r<e.length;r++){const i=e[r],o=i[1].getById(t);if(o)return{containerId:i[0],blockIndex:o[0]}}return p(FC,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class lT{constructor(t=new Set,e=new Map){this.deletedKeys=t,this.insertedValues=e}insert(t,e){this.insertedValues.set(t,e)}delete(t){this.deletedKeys.add(t)}toDocBlockDelta(){const t={};return this.insertedValues.forEach((e,r)=>{t[r]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const KC=D("op-parse-handler");class mO{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const r={...t,containerId:(i=>i==="blocks"?"root":i)(t.containerId)};this.actions.push(r)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,r){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:r})}onDeleteBlockData(t,e,r){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:r})}onInsertBlockData(t,e,r,i){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:r,value:i})}onUpdateBlockText(t,e,r){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:r})}onDeleteContainer(t){this.pushActions({type:"deleteContainer",containerId:t})}onCreateContainer(t,e){this.pushActions({type:"createContainer",containerId:t,data:e})}onDeleteComment(t){this.pushActions({type:"deleteComment",commentId:t})}onCreateComment(t){this.pushActions({type:"createComment",commentId:t})}onUpdateComment(t){this.pushActions({type:"updateComment",commentId:t})}end(){const t=this.actions,e=new Set,r=new Map,i=new hO,o=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of o)if(s.type==="deleteBlock"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);i.onDeleteBlock(l.containerId,l.blockIndex);const d=r.get(c);d&&(KC.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),r.delete(c));const h=`${l.containerId}-${l.blockIndex}`;e.add(h),this.outerHandler.onDeleteBlock(l.containerId,l.blockIndex,this.local)}else if(s.type==="deleteBlockData"){const l=s,c=`${l.containerId}-${l.blockIndex}`;if(e.has(c)){KC.warn("delete block data after delete block, ignore it");continue}const d=i.getBlockId(l.containerId,l.blockIndex);let h=r.get(d);h||(h=new lT,r.set(d,h)),h.delete(l.key)}else p(KC,!1,`invalid action type, ${s.type}`);this.actions.forEach(s=>{if(s.type==="deleteContainer"){const l=s;this.outerHandler.onDeleteContainer(l.containerId,this.local)}else if(s.type==="deleteComment"){const l=s;this.outerHandler.onDeleteComment(l.commentId,this.local)}}),this.actions.forEach(s=>{if(s.type==="createContainer"){const l=s;this.outerHandler.onCreateContainer(l.containerId,l.data,this.local)}}),this.actions.forEach(s=>{if(s.type==="insertBlock"){const l=s;this.outerHandler.onInsertBlock(l.containerId,l.blockIndex,l.data,this.local)}else if(s.type==="insertBlockData"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);let d=r.get(c);d||(d=new lT,r.set(c,d)),d.insert(l.key,l.value)}else if(s.type==="updateBlockText"){const l=s;this.outerHandler.onUpdateBlockText(l.containerId,l.blockIndex,l.richTextData,this.local)}else if(s.type==="createComment"){const l=s;this.outerHandler.onCreateComment(l.commentId,this.local)}else if(s.type==="updateComment"){const l=s;this.outerHandler.onUpdateComment(l.commentId,this.local)}}),Array.from(r.entries()).forEach(([s,l])=>{const{containerId:c,blockIndex:d}=i.getBlockIndexById(s);this.outerHandler.onUpdateBlockData(c,d,l.toDocBlockDelta(),this.local)})}}const cn=D("op-parser");class aT{}class VC{constructor(t){m(this,"key");this.key=t}}function gO(n,t,e){const r=t.concat(),i=r[0];if(typeof i!="number"||(r.shift(),r.length===1))return!1;const o=r[0];if(typeof o!="object"||!o.i||Object.keys(o).length!==1)return!1;for(let l=1;l<r.length;l++){const c=r[l];if(!Array.isArray(c)||c.length!==2||typeof c[0]!="string")return!1;const h=c[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=o.i;p(cn,s.id,"block id is required"),p(cn,s.type,"block type is required");for(let l=1;l<r.length;l++){const c=r[l],d=c[0],h=c[1];s[d]=h.i}return e.onInsertBlock(n,i,s),!0}function $C(n,t,e,r){if(e==="upsert"&&gO(n,t,r))return;p(cn,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const i=t.concat(),o=i[0];i.shift();const s=[];for(;i.length>0;){const l=i[0];if(l==="text"){const c=i[1];if(p(cn,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),p(cn,c.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),i.splice(0,2),e==="upsert"){const h=c.e;r.onUpdateBlockText(n,o,h)}p(cn,i.length===0,`invalid block ops.length !== 0, ${JSON.stringify(i)}`)}else if(Array.isArray(l)){p(cn,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];p(cn,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const d=l[1];if(c==="text"){if(p(cn,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&r.onInsertBlockData(n,o,c,d.i),d.r&&e==="remove"&&r.onDeleteBlockData(n,o,c),d.et==="rich-text"&&e==="upsert"){const C=d.e;r.onUpdateBlockText(n,o,C)}}else e==="remove"&&d.r&&s.push(new VC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i);i.shift()}else if(typeof l=="object"){const c=l;e==="remove"&&c.r&&s.push(new aT),e==="upsert"&&c.i&&r.onInsertBlock(n,o,c.i),i.shift()}else{p(cn,typeof l=="string","data is not string"),p(cn,l!=="text","data !== 'text'"),p(cn,i.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(i)}`);const c=l,d=i[1];e==="remove"&&d.r&&s.push(new VC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i),i.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof aT?r.onDeleteBlock(n,o):l instanceof VC?r.onDeleteBlockData(n,o,l.key):p(cn,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function pO(n,t,e){cn.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function CO(n,t,e){const r=n[1],i=n[2];p(cn,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),p(cn,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?cn.error(`unknown comment op, ${JSON.stringify(n)}`):i.i&&i.r?t==="upsert"&&e.onUpdateComment(r):i.i?t==="upsert"&&e.onCreateComment(r):i.r?t==="remove"&&e.onDeleteComment(r):cn.error(`unknown comment op, ${JSON.stringify(n)}`)}function HC(n,t,e){const r=n[0];if(Array.isArray(r)){r.forEach(s=>{HC(s,t,e)});return}const i=r;if(p(cn,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){pO(n);return}if(i==="comments"){CO(n,t,e);return}const o=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{$C(o,s,t,e)}):n.slice(1).forEach(s=>{$C(o,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(o),s.i&&t==="upsert"&&e.onCreateContainer(o,s.i)}else p(cn,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),$C(o,n.slice(1),t,e)}function jC(n,t,e){const r=new mO(t,e);for(let i=0;i<2;i++){const o=i===0?"remove":"upsert",s=Et.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{HC(c,o,r)}):HC(s,o,r)}r.end()}const EO=D("sharedb-comments");function zC(n){const t=n.blocks;p(EO,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([r,i])=>{Array.isArray(i)&&(e.blocks[r]=i)}),Et.default(e)}function cT(n){const{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}=n;return{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}}function GC(n,t){const e=JM(t),{comments:r,meta:i,blocks:o,...s}=e,l={...n,blocks:o,...s},c=Et.default(l);return delete c.children,c}const Ae=D("sharedb-doc/doc-container"),uT="ot-json1";n0.type.registerSubtype(ZM.type),n0.type.name=uT,n0.type.invert=null;class hd extends Lc{constructor(e,r,i=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new YM);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)})});m(this,"handleReset",async e=>{const r=new Error(`reset doc: ${e}`);r.code="ResetDoc",this.callbacks.forEach(i=>{var o;return(o=i.onError)==null?void 0:o.call(i,r)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,r,i)=>{const o=[e,r,{i}];return this.submitOp(o)});m(this,"deleteObject",async(e,r)=>{const i=[e,r,{r:!0}];return this.submitOp(i)});m(this,"replaceObject",async(e,r,i)=>{const o=[e,r,{r:!0,i}];return this.submitOp(o)});m(this,"updateObject",async(e,r,i)=>{const o=this.data()[e][r],s=[e,r];return Object.entries(i).forEach(([l,c])=>{if(!Cf.default(o[l],c))if(o[l]===void 0){if(c!=null){const d={i:c};s.push([l,d])}}else if(c==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:c};s.push([l,d])}}),Object.entries(o).forEach(([l,c])=>{if((i[l]===void 0||i[l]===null)&&c!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const r={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(r)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((r,i)=>{if(this.destroyed){Ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},o=>{o?(Ae.error(`invalid op, ${o.message}, ${JSON.stringify(e)}`),i(o),Ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):r()}),this.doc.data||(Ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((r,i)=>{this.doc.create(e,uT,o=>{o?i(o):r()})}));m(this,"submitInsertChildContainers",async e=>{if(e.length===0)return Promise.resolve();const r=e.map(({containerId:i,blocks:o})=>[ts(i),{i:o}]);return this.submitOp([r])});m(this,"submitDeleteChildContainer",async e=>{const r=[ts(e),{r:!0}];return this.submitOp(r)});m(this,"submitInsertBlock",async(e,r,i)=>{const o=[ts(e),r,{i}];return this.submitOp(o)});m(this,"submitDeleteBlock",async(e,r)=>{const i=[ts(e),r,{r:!0}];return this.submitOp(i)});m(this,"submitUpdateBlockData",async(e,r,i)=>{if(i.delete.length===0&&Object.keys(i.insert).length===0)return Promise.resolve();const o=[ts(e),r],s=new Set(i.delete);Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c)){const h={r:!0,i:d};o.push([c,h])}});const l=new Set(Object.keys(i.insert));return i.delete.forEach(c=>{if(l.has(c))return;const d={r:!0};o.push([c,d])}),Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c))return;const h={i:d};o.push([c,h])}),this.submitOp(o)});m(this,"submitUpdateRichText",async(e,r,i)=>{const o=[ts(e),r,"text",{e:i,et:"rich-text"}];return this.submitOp(o)});m(this,"handleOp",(e,r,i)=>{if(!e){Ae.warn("handleOp: no ops");return}if(this.destroyed){Ae.warn("handleOp: destroyed");return}try{jC(e,this,!!r)}catch(o){throw Ae.error(o),o}});this.client=e,this.doc=r,this.doc.preventCompose=!0,this.disableLogout=i,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,p(Ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const r=new uO(e.auth,e.serverUrl,e.reauthFunc);r.onMaxUsersError(()=>{var s;return(s=e.onMaxUsersError)==null?void 0:s.call(e)});const i=await r.getDoc(),o=new hd(r,i,e.disableLogout);if(i.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await o.createDoc(e.templateData||fO())}return await o.initPresence(),await o.subscribe(),o.initEvents(),o}catch(r){throw Ae.error(r),Ae.error(`failed to load doc: ${JSON.stringify(r)}`),r}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onAuthError(e=>{this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}),this.client.onAuthRecover(()=>{this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,r)=>{if(this.localPresence)e();else{const i=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);i.on("receive",(o,s)=>{this.onCustomMessage(s)}),i.subscribe(o=>{o?r(o):(this.localPresence=i.create(it()),e())})}})}subscribe(){return new Promise((e,r)=>{this.doc.subscribe(i=>{i?r(i):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return Zo(this.data())}getContainerBlocks(e){const r=this.data();p(Ae,r,"no doc data");const i=r[ts(e)];return p(Ae,i,`no container data: ${e}`),Et.default(i)}findContainerBlocks(e){const r=this.data();p(Ae,r,"no doc data");const i=r[ts(e)];return i!=null?i:null}getBlockData(e,r){const i=this.data();p(Ae,i,"no doc data");const o=i[ts(e)];p(Ae,o,`no container data: ${e}`);const s=o[r];return p(Ae,s,`no block data: ${r}`),Et.default(s)}localInsertBlock(e,r,i){return this.submitInsertBlock(e,r,i),this.getBlockData(e,r)}localDeleteBlock(e,r){const i=this.getBlockData(e,r);return this.submitDeleteBlock(e,r),i}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(Ae,o.text,"no block text");const s=Et.default(o.text);this.submitUpdateRichText(e,r,i);const l=Hn.apply(s,i);return p(Ae,l,"no block text"),l}localUpdateBlockData(e,r,i){const o=Et.default(this.getBlockData(e,r));return this.submitUpdateBlockData(e,r,i),o}localInsertChildContainers(e){this.submitInsertChildContainers(e)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(r=>{this.submitDeleteChildContainer(r)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(r=>cT(r))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const r=this.data().comments[e];return zC(r)}localCreateComment(e,r){const i=GC(e,r),s=["comments",i.id,{i}];return this.submitOp(s)}localDeleteComment(e){const r=["comments",e,{r:!0}];return this.submitOp(r)}localUpdateComment(e,r){const i=GC(e,r),o=["comments",e.id,{r:!0,i}];return this.submitOp(o)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,r,i){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onDeleteBlock)==null?void 0:s.call(o,Zc(e),r,i)})}onInsertBlock(e,r,i,o){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Zc(e),r,i,o)})}onUpdateBlockData(e,r,i,o){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Zc(e),r,i,o)})}onUpdateBlockText(e,r,i,o){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Zc(e),r,i,o)})}onDeleteContainer(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),p(Ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,Zc(e),r)})}onCreateContainer(e,r,i){p(Ae,this.callbacks.length>0,"no callbacks"),p(Ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,Zc(e),r,i)})}onDeleteComment(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteComment)==null?void 0:o.call(i,e,r)})}onCreateComment(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onCreateComment)==null?void 0:o.call(i,e,r)})}onUpdateComment(e,r){p(Ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onUpdateComment)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){const r=e;(r==null?void 0:r.type)==="custom"&&(r==null?void 0:r.clientId)!==this.client.clientId?this.callbacks.forEach(i=>{var o;return(o=i.onCustomMessage)==null?void 0:o.call(i,r.data)}):(r==null?void 0:r.type)==="onlineUsers"&&setTimeout(()=>{const i={type:"custom",data:e,clientId:"-"};this.onCustomMessage(i)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}async addResources(e){let r=[];return e.forEach(o=>{const s=o.split("|");r.push(...s)}),r=Array.from(new Set(r)),await this.client.getFileUrlsByHashes(r)}async uploadResource(e,r){var o;return{resourceId:await this.client.uploadResource(e,(o=r==null?void 0:r.onProgress)!=null?o:()=>{})}}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}request(e,r){return this.client.request(e,r)}getUser(){const e=this.client.clientId,{permission:r,userId:i,displayName:o,avatarUrl:s}=this.client.auth;return{permission:r,clientId:e,userId:i,displayName:o,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return Zo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return Zo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:Zo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:Zo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,r){jC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}triggerReAuth(e=!1){this.client.reAuth(e)}}D("remote-cursor");class fT{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",Ne.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const r=this.editor.findBlockById(e);r&&this.editor.reloadBlock(r)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const dT=D("remote-cursor-decorator");class WC{decorateText(t,e,r){const i=t.doc.getRemoteUsers();if(!i)return{};const o=new Map,{containerId:s,blockIndex:l}=e[e.length-1];p(dT,typeof s=="string","invalid path containerId"),p(dT,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),d=$n(r);return i.getSimpleCursors(c.id).forEach((C,E)=>{E>d&&(E=d);const A=C.map(w=>({id:it(),type:"remote-cursor",name:w.user.displayName,time:w.time,rainbowIndex:w.user.rainbowIndex})),v=o.get(E);v?v.push(...A):o.set(E,A)}),{insertions:o}}}const qC=D("sharedb-doc/share-db-server"),AO=Rb.default.create();class xO{constructor(t,e){m(this,"auth");m(this,"clientId",it());this.serverUrl=e,this.auth=t}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(qC,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}apiServer(){const t=`${this.serverUrl}/${this.auth.appId}/${this.auth.docId}`;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}getBaseURL(){const t=new URL(this.apiServer());return`${t.protocol}//${t.host}${t.pathname}`}getBase64BaseURL(){return qi(this.getBaseURL())}async request(t,e){var o;const r=this.auth.token,i=e||{};i.url=t,i.headers||(i.headers={}),p(qC,r,"no token"),i.headers={...i.headers,[ba]:r,[nu]:this.getBase64BaseURL()};try{return await AO(t,i)}catch(s){throw(o=s.response)!=null&&o.data&&(s.responseData=s.response.data),s}}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=wb.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(qC,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}buildResourceUrl(t,e){if(!t)return"";if(t.startsWith("https:")||t.startsWith("http:")||t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;let i=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken,e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const s=o.join("&");i+=`?${s}`}return i}}const bO=D("sharedb-doc/share-db-server");function hT(n){const t=new URL(n);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}function vO(n){return qi(hT(n))}class Em extends Lc{constructor(e){super();m(this,"remoteUsers",new td);m(this,"client");this.options=e,this.client=new xO(e.auth,e.serverUrl)}destroy(){}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}getRemoteUsers(){return this.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return Zo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return Zo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:Zo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:Zo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}parseHistoryData(e,r){jC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}static async auth(e,r){p(bO,e.token,"no auth token");const i=`${hT(r)}/auth`,o=await window.fetch(i,{method:"GET",headers:{[ba]:e.token,[nu]:vO(r)},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return await o.json()}static async load(e){const r=`${e.serverUrl}/${e.auth.appId}/${e.auth.docId}`;return await this.auth(e.auth,r),new Em(e)}}class mT extends Ve.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,r){if(re(Ci(this.editor,t)))return;const i=this.editor.getBlockByIndex(t,e),o=et(this.editor.getContainerById(t));o&&this.emit("change",this.editor,{containerId:t,blockIndex:e},o,i,r)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}onInsertBlock(t,e){re(Ci(this.editor,t))||this.emit("insert",this.editor,{containerId:t,blockIndex:e})}onDeleteBlock(t,e){this.handleChild(t,e,"remove")}destroy(){this.editor.doc.unregisterCallback(this)}}function gT(n,t){const e=n.addCustom("child-block-tracker",()=>new mT(n));e.addListener("change",t),e.addListener("insert",t)}function pT(n,t){const e=n.addCustom("child-block-tracker",()=>new mT(n));e.removeListener("change",t),e.removeListener("insert",t)}const Wlt="",BO={colorPalette:{colorDesc:"\u5B57\u4F53\u989C\u8272",name:"\u6587\u672C\u989C\u8272",backgroundDesc:"\u80CC\u666F\u989C\u8272",reset:"\u6062\u590D\u9ED8\u8BA4"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}},yO={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},TO={colorPalette:{colorDesc:"\u30D5\u30A9\u30F3\u30C8\u306E\u8272",name:"\u30C6\u30AD\u30B9\u30C8\u306E\u8272",backgroundDesc:"\u80CC\u666F\u8272",reset:"\u30C7\u30D5\u30A9\u30EB\u30C8\u306B\u623B\u3059"},search:{emptyTips:"\u691C\u7D22\u7D50\u679C\u304C\u3042\u308A\u307E\u305B\u3093"}};_.mergeLang({"zh-CN":BO,"en-US":yO,"ja-JP":TO});const qlt="";D("button");function Zr(n,t,e,r,i){const o=B("button",["editor-button"],null);return o.setAttribute("data-button-id",n),i&&o.setAttribute(`data-editor-tooltip-${i}`,t),e?typeof e=="string"?e.startsWith("<")?o.innerHTML=e:o.innerText=e:o.appendChild(e):o.innerText=t,r&&(r.indexOf("checked")!==-1&&q(o,"checked"),r.indexOf("disabled")!==-1&&(o.disabled=!0),r.indexOf("primary")!==-1&&q(o,"primary")),o}const Xlt="",Am=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
32
32
  <path d="M8.00874 7.89952L12.9497 2.94975M8.00874 7.89952L12.9497 12.8492M8.00874 7.89952L3.05025 12.8492M8.00874 7.89952L3.05025 2.94975" stroke="currentColor" stroke-linejoin="round"/>
33
33
  </svg>
34
34
  `,CT=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -611,7 +611,7 @@ ${t}
611
611
  </defs>
612
612
  </svg>
613
613
  `,HO=Object.freeze(Object.defineProperty({__proto__:null,ClearIcon:e2,CloseIcon:Am,PrevIcon:CT,NextIcon:ET,MoreIcon:XC,TextColorIcon:YC,ArrowDownIcon:xm,ArrowUpIcon:kO,ArrowLeftIcon:RO,ArrowRightIcon:QC,DeleteRowIcon:AT,DeleteColIcon:xT,MergeCellIcon:bT,SplitCellIcon:vT,DeleteTableIcon:BT,Heading1Icon:bm,Heading2Icon:vm,Heading3Icon:Bm,Heading4Icon:ym,Heading5Icon:Tm,Heading6Icon:km,Heading7Icon:Rm,Heading8Icon:wm,HeadingNIcon:wO,OrderedListIcon:yT,UnorderedListIcon:TT,CheckListIcon:kT,BlockquoteIcon:RT,AlignCenterIcon:Lm,AlignLeftIcon:ru,AlignRightIcon:Sm,ImageIcon:wT,ImageMenuIcon:ST,ImageErrorIcon:ZC,ImageEmptyIcon:IT,LinkIcon:rE,LinkOffIcon:DT,WarningIcon:JC,PasteSpecialIcon:LT,LaunchIcon:tE,CodeIcon:GT,AudioIcon:$T,GraphIcon:SO,VideoIcon:HT,FileIcon:LO,MathIcon:DO,MathMenuIcon:_T,TableIcon:_O,TableMenuIcon:MT,BilibiliIcon:OT,YoukuIcon:NT,ModaoIcon:FT,FigmaIcon:PT,EditIcon:Im,CommentIcon:va,RefreshIcon:UT,HelpIcon:eE,CheckMarkIcon:nE,TextIcon:iu,RightArrowIcon:IO,TencentVideoIcon:KT,WebPageIcon:VT,UmlIcon:jT,DividingLineIcon:zT,HeadingH1Icon:MO,HeadingH2Icon:UO,HeadingH3Icon:OO,HeadingH4Icon:NO,HeadingH5Icon:PO,HeadingH6Icon:FO,HeadingH7Icon:KO,HeadingH8Icon:VO,CheckboxIcon:iE,QuoteIcon:oE,LinkHrefIcon:$O,OrderedIcon:lE,UnorderedIcon:sE,CopyIcon:WT,CutIcon:qT,DeleteIcon:XT,LockBlockIcon:YT,UnLockBlockIcon:QT,InsertBeforeIcon:JT,InsertAfterIcon:ZT,MentionIcon:t2,CircleAddIcon:n2,LoadingIcon:r2,DragIcon:aE,UmlBrandIcon:Dm,OnesLoadingIcon:i2,BoldIcon:o2,ItalicIcon:s2,UnderlineIcon:l2,LineThroughIcon:a2,SubscriptIcon:u2,SuperscriptIcon:f2,InlineCodeIcon:c2,ToMindMapIcon:d2,FitIcon:h2,FullScreenIcon:cE,ExitFullScreenIcon:m2,CaretDownIcon:g2,StatusIcon:p2},Symbol.toStringTag,{value:"Module"}));function C2(){const n=B("span",["editor-loading-icon"],null);return n.innerHTML=i2,n}const Ylt="";function jO(n,t){const e=B("button",["editor-checkbox-wrapper"],null);e.setAttribute("data-button-id",n),t!=null&&t.includes("checked")&&q(e,"checked"),t!=null&&t.includes("disabled")&&(e.disabled=!0);const r=B("span",["editor-checkbox"],e);return B("span",["editor-checkbox-inner"],r),e}const Qlt="",ou=D("ui-command-bar-base"),zO={itemElementTag:"div",tippyArrow:!1},Ix=class extends Ve.TypedEmitter{constructor(e,r,i){var o,s;super();m(this,"content");m(this,"items");m(this,"subBar",null);m(this,"parentItem",null);m(this,"closeable",null);m(this,"closeReason",null);m(this,"options");m(this,"id");m(this,"header",null);m(this,"footer",null);m(this,"handleDocumentKeydown",e=>{var r,i;if(!!this.isVisible&&!e.isComposing&&!Oc(e.target)){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){if((i=(r=this.options).beforeClose)!=null&&i.call(r))return;this.close("cancelBar");return}if(e.key==="ArrowUp"){const o=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const o=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const o=this.getSelectedItem();o&&o.children&&this.showSubCommandBar(o.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const o=this.getSelectedItemIndex();if(o===-1)return;const s=this.items[o],l=this.getItemElementById(s.id);l&&this.emit("click",this,s,l)}}}});m(this,"handleDocumentMouseDown",e=>{var r,i;if(e.target instanceof Element){if((i=(r=this.options).beforeClose)!=null&&i.call(r,e))return;if(!this.isInCommandBar(e.target)){const o=this.listeners("closing");for(let s=0;s<o.length;s++)if(o[s](this,e)===!1)return;this.close("clickBackground")}}});m(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),zp(this.id)});m(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&q(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&jp(this.id)});m(this,"lastEnterPauseTime",0);m(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});m(this,"handleItemMouseEnter",e=>{if(Date.now()-this.lastEnterPauseTime<100)return;const r=this.getParentCommandItemElement(e.target);if(!r)return;const i=this.getItemElementId(r),o=this.getItemById(i);if(this.selectItem(i),o.manualShowChildren)return;const s=o.childrenMenuId||"";this.showSubCommandBar(s)});m(this,"handleItemMouseLeave",e=>{var i,o;const r=this.getParentCommandItemElement(e.target);!r||((o=(i=this.subBar)==null?void 0:i.parentItem)==null?void 0:o.id)!==this.getItemElementId(r)&&(ct(r,"selected"),this.emit("selectionChange",this,""))});m(this,"handleItemClick",e=>{var s,l;const r=this.getParentCommandItemElement(e.target);if(!r)return;const i=this.getItemElementId(r),o=this.items.find(c=>c.id===i);if(!!o&&!(o.states&&o.states.indexOf("disabled")!==-1)){if(o.children&&o.children.length>0&&o.manualShowChildren){this.showSubCommandBar(o.childrenMenuId);return}if(!o.element&&(this.emit("click",this,o,r),this.options.autoClose)){if((l=(s=this.options).beforeClose)!=null&&l.call(s,e))return;this.close("clickItem")}}});m(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const r=e.target;if(!r||!(r instanceof Node))return;const i=r instanceof HTMLElement?r:r.parentElement;if(!i)return;const o=gn(i);if(!Ee(this.content,o)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?o.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&o.scrollTop+o.clientHeight>=o.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(o=i==null?void 0:i.id)!=null?o:it(),this.options={...zO,...i},this.items=e,this.parentItem=(s=i==null?void 0:i.parentItem)!=null?s:null,this.closeable=r!=null?r:null,this.content=this.createCommandBarContent(e)}close(e){this.closeReason=e,this.subBar&&this.subBar.close(e),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}click(e,r){this.emit("click",this,e,r)}createPopperOptions(){var i,o;const e={modifiers:[]},r=this.options.overflowBoundary;return r&&((i=e==null?void 0:e.modifiers)==null||i.push({name:"flip",options:{boundary:r,fallbackPlacements:["top","bottom"]}})),this.options.padding&&((o=e==null?void 0:e.modifiers)==null||o.push({name:"preventOverflow",options:{padding:this.options.padding}})),e}destroy(){var e;this.close(null),this.removeAllListeners(),(e=this.subBar)==null||e.destroy(),this.subBar=null,this.closeable=null,this.content.removeEventListener("wheel",this.handleWheel)}get isSubCommandBar(){return!!this.parentItem}updateItems(e){var i;this.subBar&&e.findIndex(s=>{var l,c;return s.id===((c=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:c.id)})===-1&&((i=this.subBar)==null||i.destroy(),this.subBar=null),this.items=e;const r=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(r.children).forEach(o=>{this.content.appendChild(o)})}get popper(){return this.content.closest("[data-tippy-root]")}getSelectedItemIndex(){const e=this.getSelectedItem();return e?this.items.indexOf(e):-1}getPrevItemIndex(e){if(e<=0)return this.items.length-1;let r=e-1;for(;;){const i=this.items[r],o=i.type,l=!(i.states&&i.states.indexOf("disabled")!==-1);if(o!=="separator"&&o!=="section"&&l)return r;if(r-=1,r<0)return this.items.length-1}}getNextItemIndex(e){let r=e+1;for(;;){if(!this.items[r])return this.getNextItemIndex(-1);const i=this.items[r],o=i.type,l=!(i.states&&i.states.indexOf("disabled")!==-1);if(o!=="separator"&&o!=="section"&&l)return r;if(r+=1,r>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const r=this.getItemElementById(e.id);r&&ct(r,"selected")}selectItem(e,r="event"){const i=this.getSelectedItem();if(i){if(i.id===e)return;const s=i.id,l=this.getItemElementById(s);l&&ct(l,"selected")}const o=this.getItemElementById(e);o?(q(o,"selected"),this.emit("selectionChange",this,o.getAttribute("data-id")||""),!this.options.disableSelectedScroll&&r==="event"&&o.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l,c,d;const r=this.getSelectedItem();if(!r||!r.children&&((l=(s=this.subBar)==null?void 0:s.parentItem)==null?void 0:l.manualShowChildren))return;if(this.subBar){if(((c=this.subBar.parentItem)==null?void 0:c.id)===r.id){r.manualShowChildren&&this.subBar.close("switchItem");return}this.subBar.destroy(),this.subBar=null}if(!r.children)return;const i=this.getItemElementById(r.id);if(!i)return;const o=Ix.createSubCommandBar(r,(d=this.closeable)!=null?d:this,e?{id:e}:{});this.subBar=o,this.subBar.on("click",(h,C,E)=>{this.emit("click",h,C,E)}),this.subBar.on("close",()=>{var h;(h=this.subBar)==null||h.destroy(),this.subBar=null,ct(i,"active")}),r.beforePopup&&r.beforePopup(o),this.subBar.manualShow(i,this.getSubBarOptions(r)),q(i,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const r=this.getCommandBarRoot();return r&&Ee(r,e)||Ee(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var o,s,l,c;let r=(o=this.options.itemElementTag)!=null?o:"div";e.element&&(r="div");const i=B(r,["command-item"],null);return i.setAttribute("data-id",e.id),e.type==="separator"?i.classList.add("separator"):e.type==="section"?(i.classList.add("section","text"),e.element&&(typeof e.element=="function"?i.appendChild(e.element(e)):i.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&i.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&i.classList.add("checked"),(c=e.states)!=null&&c.includes("disabled")&&i.classList.add("disabled"),i.onclick=this.handleItemClick,i.onmouseenter=this.handleItemMouseEnter,i.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?i.appendChild(e.element(e)):i.appendChild(e.element):i.classList.add("standard")),this.initItemElement(e,i),i}getItemById(e){const r=this.items.find(i=>i.id===e);return p(ou,r,`can not find command item for id: ${e}`),r}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const r=this.getItemElementId(e),i=this.items.find(o=>o.id===r);return p(ou,i,`can not find command item for id: ${r}`),i}return null}getItemElementId(e){const r=e.getAttribute("data-id");return p(ou,r,"no data-id attribute"),r}getItemElementById(e){const r=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return p(ou,r,`no exists command item, id=${e}`),r}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(Mt(e,"command-item"))return e;const r=e.closest(".command-item");return r||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const r=B("div",["editor-command-bar-root"],null);if(this.options.header){const o=B("div",["editor-command-bar-header"],null);if(this.options.header instanceof Function){const s=this.options.header();s&&o.appendChild(s)}else o.appendChild(this.options.header);this.header=o,this.header&&r.appendChild(this.header)}const i=B("div",["editor-command-bar"],r);if(e.forEach(o=>{var l;const s=this.createCommandItem(o);i.appendChild(s),o.element&&o.setCloseable&&o.setCloseable((l=this.closeable)!=null?l:this)}),this.options.footer){const o=B("div",["menu-item","editor-command-bar","footer"],null);if(this.options.footer instanceof Function){const s=this.options.footer();s&&o.appendChild(s)}else o.appendChild(this.options.footer);this.footer=o,this.footer&&r.appendChild(this.footer)}return(this.options.header||this.options.footer)&&q(r,"scrollable-bar"),this.initCommandBarElement(i),r.addEventListener("wheel",this.handleWheel,{passive:!1}),r}getSubBarOptions(e){var r;return{placement:(r=e.childrenPlacement)!=null?r:"right-start",offset:e.childrenOffset,arrow:e.childArrow}}static registerManualCommandBar(e,r){this.commandBarCreators.set(e,r)}static createSubCommandBar(e,r,i){var l;p(ou,e.children&&e.children.length>0,"no item children");const o=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(o);return p(ou,s,`no creator for command type: ${o}`),s(e,r,i)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let Ba=Ix;m(Ba,"commandBarCreators",new Map),D("ui-command-bar");class _m extends Ba{constructor(){super(...arguments);m(this,"tippyInstance",null)}manualShow(e,r){var i,o,s;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=f9.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(i=r==null?void 0:r.placement)!=null?i:"bottom-start",maxWidth:650,arrow:(o=r==null?void 0:r.arrow)!=null?o:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:r==null?void 0:r.theme,getReferenceClientRect:r==null?void 0:r.getReferenceClientRect,offset:(s=r==null?void 0:r.offset)!=null?s:[0,0],popperOptions:this.createPopperOptions()}),r!=null&&r.point){const{x:l,y:c}=r.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(l,c,0,0)})}this.clearSelectedItem(),this.tippyInstance.show(),this.parentItem||(document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)),this.popper&&this.options.id&&this.popper.setAttribute("data-command-bar-id",this.options.id)}}close(e){var r;super.close(e),this.isVisible&&((r=this.tippyInstance)==null||r.hide())}destroy(){var e;(e=this.tippyInstance)==null||e.destroy(),this.tippyInstance=null,super.destroy()}getCommandBarRoot(){return this.content.closest("[data-tippy-root]")}get isVisible(){var e,r;return(r=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?r:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const E2=D("ui-base");class su extends _m{constructor(t,e){var o;const r=(o=e==null?void 0:e.id)!=null?o:`popup-${it()}`,i=[{id:r,name:"",element:t}];super(i,void 0,{disablePageScroll:!0,id:r,beforeClose:e==null?void 0:e.beforeClose})}initCommandBarElement(t){q(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];p(E2,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return p(E2,e,"no item element"),e}}const rs=D("filterable-list");function A2(n){var e,r;const t=B("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(B("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&(q(t,"selected"),ea(nE,["list-item-selected-icon"],t)),(r=n.states)!=null&&r.includes("disabled")&&q(t,"disabled"),t}function x2(n){const t=B("div",["list-root"],null);return n.forEach(e=>{t.appendChild(A2(e))}),n.length||t.appendChild(A2({id:"placeholder",states:["disabled"],name:_.t("search.emptyTips")})),t}function b2(n,t){return n.map(e=>({...e,states:t===e.id?["selected"]:[]}))}function GO(n,t){const e=B("div",["filterable-list"],null),r=B("div",["filter"],e),i=B("div",["filter-container"],r),o=B("input",["filter-input"],i);t&&t.placeholder&&(o.placeholder=t.placeholder);const s=B("div",["list"],e),l=x2(b2(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function v2(n,t,e){const r=n.querySelector(".list");p(rs,r,"no list root");const i=x2(b2(t,e)),o=r.querySelector(".list-root");if(p(rs,o,"no exists menu"),Bf(o,i),e){const s=r.querySelector(".list-item.selected");s&&(p(rs,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class WO{constructor(t,e){m(this,"root");m(this,"visibleItems");m(this,"selectedId");m(this,"filter","");m(this,"onSelected",null);m(this,"handleKeydown",t=>{this.processKeyDown(t)});m(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");p(rs,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});m(this,"handleClick",t=>{this.processClick(t)});var r;this.items=t,this.options=e,this.root=GO(t,e),this.bindEvents(),this.selectedId=(r=e==null?void 0:e.initialSelectedId)!=null?r:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");p(rs,t,"no input"),t.addEventListener("keyup",this.handleInputChanged),t.addEventListener("keydown",this.handleKeydown),this.root.addEventListener("click",this.handleClick)}unbindEvents(){const t=this.root.querySelector(".filter-input");p(rs,t,"no input"),t.removeEventListener("keyup",this.handleInputChanged),t.removeEventListener("keydown",this.handleKeydown),this.root.removeEventListener("click",this.handleClick)}destroy(){this.unbindEvents(),this.onSelected=null}getSelectedIndex(){return this.selectedId?this.visibleItems.findIndex(t=>t.id===this.selectedId):-1}setSelectedId(t){this.selectedId=t,v2(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");p(rs,t,"no input"),t.focus()}moveSelectedItemIntoView(){const t=this.root.querySelector(".list-item.selected");t&&(p(rs,t,"no selected menu item"),t.scrollIntoView({block:"nearest"}))}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");p(rs,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),v2(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const r=e.closest(".list-item");if(!r)return;const i=(s=r.getAttribute("data-id"))!=null?s:"",o=(l=this.visibleItems.find(c=>c.id===i))!=null?l:null;this.onSelected&&this.onSelected(this,o)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let r=this.getSelectedIndex();r===-1?r=this.visibleItems.length-1:r>0&&(r-=1);let i="";r!==-1&&(i=this.visibleItems[r].id),this.setSelectedId(i);return}if(t.key==="ArrowDown"){let r=this.getSelectedIndex();r===-1?r=0:r<this.visibleItems.length-1&&(r+=1);let i="";r!==-1&&(i=this.visibleItems[r].id),this.setSelectedId(i);return}if(t.key==="Enter"){const r=(e=this.visibleItems.find(i=>i.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,r)}}}class qO extends WO{constructor(e,r,i){super(e,i);m(this,"popup");m(this,"onShow",null);m(this,"onHide",null);m(this,"custom",null);m(this,"handleShow",()=>{this.onShow&&this.onShow(this)});m(this,"handleHide",()=>{this.onHide&&this.onHide(this)});m(this,"handleShown",()=>{this.focus()});this.popup=new su(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus(),this.moveSelectedItemIntoView()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close("cancelBar")}processClick(e){super.processClick(e);const r=e.target;!(r instanceof HTMLElement)||!r.closest(".list-item")||this.popup.close("clickItem")}}const Jlt="",Zlt="";function XO(n,t){const e=document.createElement("div");e.classList.add("toast","show"),t!=null&&t.theme&&e.setAttribute("data-theme",t.theme),t!=null&&t.id&&e.setAttribute("data-id",t.id),t!=null&&t.html?e.innerHTML=n:e.textContent=n,t!=null&&t.position&&(e.style.left=`${t.position.x}px`,e.style.top=`${t.position.y}px`,e.classList.add("positioned")),document.body.appendChild(e),setTimeout(()=>{e.classList.remove("show"),setTimeout(()=>{e.remove()},500)},(t==null?void 0:t.duration)||3e3)}function YO(n,t){var e,r;if(q(t,"menu-item"),!n.element){if(n.type==="section"){const i=B("div",["section-name"],null,n.name);t.appendChild(i)}else if(n.type!=="separator"){if(n.icon){const o=B("div",["menu-item-icon"],null);n.icon&&(o.innerHTML=n.icon),t.appendChild(o)}const i=B("div",["menu-item-name","text"],null);if(B("span",[],i,n.name),n.ellipsisTooltip&&(t.setAttribute("data-editor-tooltip-allow-markdown","true"),t.setAttribute("data-editor-tooltip-offset-y","25"),t.setAttribute("data-editor-tooltip-placement","right"),t.setAttribute("data-editor-tooltip-common",`<div style="word-break: break-word;">${n.ellipsisTooltip}</div>`)),((e=n.states)==null?void 0:e.includes("disabled"))&&n.disableReason&&(t.setAttribute("data-editor-tooltip-placement","right"),t.setAttribute("data-editor-tooltip-common",n.disableReason)),t.appendChild(i),n.subText&&B("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const o=B("div",["menu-item-sub-indicator"],null);o.innerHTML=QC,t.appendChild(o)}if((r=n.states)!=null&&r.includes("checked")){const o=B("div",["menu-item-checked-icon"],null);o.innerHTML=nE,t.appendChild(o)}}}}class hl extends _m{constructor(t,e,r){super(t,e,{autoClose:!0,disablePageScroll:!0,beforeClose:r==null?void 0:r.beforeClose,...r})}manualShow(t,e){const r={theme:"menu",...e};super.manualShow(t,r)}initCommandBarElement(t){q(t,"menu")}initItemElement(t,e){YO(t,e)}}function QO(n,t,e){var r;return new hl((r=n.children)!=null?r:[],t,{...e,parentItem:n})}function B2(n,t,e){t.setAttribute("data-button-id",n.id),e.tooltipId&&n.name&&!n.disableTooltip&&(t.setAttribute(`data-editor-tooltip-${e.tooltipId}`,n.name),n.desc&&t.setAttribute(`data-editor-tooltip-desc-${e.tooltipId}`,n.desc));const r=t;if(!n.element)if(n.icon){const i=B("span",["toolbar-item-icon-container"],r);n.icon.trim().startsWith("<")?i.innerHTML=n.icon:i.innerText=n.icon}else{const i=B("span",["toolbar-item-name-container"],r);i.innerText=n.name}if(n.dropdown){t.setAttribute("data-dropdown","true");const i=B("span",["toolbar-item-dropdown-container"],r);i.innerHTML=xm}n.states&&(n.states.indexOf("checked")!==-1&&q(r,"checked"),n.states.indexOf("disabled")!==-1&&(r.disabled=!0))}class md extends _m{constructor(t,e,r){super(t,e,{itemElementTag:"button",tippyArrow:!1,...r})}getSubBarOptions(t){var i,o;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),d=s.getBoundingClientRect();return new DOMRect(d.left,c.top,d.width,c.height)};return{placement:(i=t.childrenPlacement)!=null?i:"top",getReferenceClientRect:e,offset:(o=t.childrenOffset)!=null?o:[0,4]}}manualShow(t,e){const r={theme:"toolbar",...e};super.manualShow(t,r)}initCommandBarElement(t){q(t,"toolbar")}initItemElement(t,e){B2(t,e,this.options)}}function JO(n,t,e){var r;return new md((r=n.children)!=null?r:[],t,{...e,parentItem:n})}class ZO extends Ba{constructor(t,e,r){super(e,void 0,r),t.appendChild(this.content),document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)}initCommandBarElement(t){q(t,"toolbar","fixed")}initItemElement(t,e){B2(t,e,this.options)}close(){this.clearSelectedItem(),this.subBar&&(this.subBar.close("cancelBar"),this.subBar=null)}destroy(){this.content.remove(),super.destroy(),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}getCommandBarRoot(){return this.content.parentElement}get isVisible(){return!0}}const tat="";Ba.registerManualCommandBar("menu",QO),Ba.registerManualCommandBar("toolbar",JO);const eat="",y2=D("ui-base");class gd extends _m{constructor(e,r){super(gd.getCommandItems(e,r),void 0,{disablePageScroll:!0,...r});m(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){q(e,"dialog","manual")}initItemElement(e,r){}show(e,r){this.manualShow(e,{...r,theme:"light"})}get dialogContent(){const e=this.items[0];p(y2,e,"no dialog item");const r=e.element;return p(y2,r,"no item element"),r}static getCommandItems(e,r){var s;return[{id:(s=r==null?void 0:r.id)!=null?s:`manual-dialog-${it()}`,name:"",element:e}]}}const nat="",tN=D("ui-base");class T2{constructor(t){m(this,"menu");m(this,"currentText","");m(this,"handleSearchText");m(this,"handleClick",Ne.default((t,e)=>{this.options.onClickItem(this,e)},300,{leading:!0,trailing:!1}));m(this,"handleShow",t=>{});m(this,"handleClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.options=t,this.menu=new hl([],void 0,{id:t.id,header:t.header,footer:t.footer,disableSelectedScroll:t.disableSelectedScroll}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose),this.menu.addListener("show",this.handleShow),this.options.wait?this.handleSearchText=Ne.default(async e=>{this.handleSearchTextPure(e)},this.options.wait):this.handleSearchText=this.handleSearchTextPure}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(r=>r.type!=="section"&&r.type!=="separator");e&&this.menu.selectItem(e.id,"manual")}}async popup(t,e){var i,o;if(!(e!=null&&e.noEvent)&&((o=(i=this.options).onShow)==null?void 0:o.call(i,this))===!1)return;this.menu.manualShow(t),this.options.placeholder&&this.showPlaceholder();const r=await this.options.queryItems(this,"");this.highlightText("",r),this.setItems(r)}showLoading(){!this.options.showLoading||(this.options.loadingElement?this.setItems([{id:"loading",name:"",element:this.options.loadingElement,states:["disabled"]}]):this.setItems([{id:"loading",name:"loading",states:["disabled"]}]))}showPlaceholder(){this.setItems([{id:"placeholder",name:"enter text to search",states:["disabled"]}])}showNoResultMessage(t){if(this.options.noResultMessage){const e={name:"",id:"placeholder",states:["disabled"]};typeof this.options.noResultMessage=="string"?e.name=this.options.noResultMessage:(this.options.noResultMessage instanceof HTMLElement||typeof this.options.noResultMessage=="function")&&(e.element=this.options.noResultMessage),this.setItems([e])}else this.setItems([{id:"placeholder",name:this.options.emptyPlaceholder||_.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close("cancelBar")}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close("cancelBar"),this.menu.removeAllListeners(),this.menu.destroy()}isInCommandBar(t){return this.menu.isInCommandBar(t)}async handleSearchTextPure(t){this.currentText=t;const e="auto-suggest";try{await gi.lock(e),this.showLoading();const r=this.currentText,i=await this.options.queryItems(this,t);if(this.currentText===r&&(this.currentText=""),i.length===0){this.showNoResultMessage(t);return}this.setItems(i),this.options.highlight&&this.highlightText(r.replace(/^\s+|\s+$/g,""),i)}finally{gi.release(e)}}highlightText(t,e){tN.debug(`highlight menu text: ${t}`);const r=this.menu.content,i=(s,l)=>{if(!l)return s;let c="";const d=l.length,h=l.toLocaleLowerCase();let C=0;for(C=0;C<=s.length-d;C){let E=s.substring(C,C+d);if(E.toLocaleLowerCase()===h){C+=d;const A=s.charAt(C);let v=!1;E.endsWith(" ")&&(v=!0,E=E.trimEnd()),c+=`<span class="highlight">${E}${A===" "||v?"&nbsp":""}</span>`}else c+=s.charAt(C),C++}return C<s.length&&(c+=s.substring(C)),c},o=s=>{if(Mt(s,"text")){const l=e==null?void 0:e.find(h=>h.id===s.getAttribute("data-id"));if(l&&l.element)return;const c=s.textContent;if(!c)return;const d=i(c,t);s.innerHTML=d;return}Array.from(s.children).forEach(o)};o(r)}}class uE{constructor(t,e){m(this,"root");m(this,"input");m(this,"text");m(this,"dropdownIcon");m(this,"clearIcon");m(this,"autoSuggest");m(this,"labels");m(this,"items",[]);m(this,"handleClick",()=>{this.autoSuggest.popup(this.root),this.input.focus()});m(this,"handleClickItem",(t,e)=>{var r,i;(i=(r=this.options)==null?void 0:r.onClickItem)==null||i.call(r,e)});m(this,"handleInput",()=>{this.autoSuggest.handleSearchText(this.input.value),this.updatePlaceholder()});m(this,"handleClear",t=>{var e,r;this.clear(),this.autoSuggest.handleSearchText(""),t.preventDefault(),t.stopPropagation(),(r=(e=this.options)==null?void 0:e.onClear)==null||r.call(e)});m(this,"handleQueryItems",async(t,e)=>this.items.filter(i=>{var o;return(o=this.options)!=null&&o.filter?this.options.filter(i,e):!0}));m(this,"handleShow",()=>{q(this.root,"active"),this.input.focus()});m(this,"handleClose",()=>{var t,e;(e=(t=this.options)==null?void 0:t.onClose)==null||e.call(t),ct(this.root,"active")});var c,d,h,C,E;this.options=e,this.labels=(d=(c=this.options)==null?void 0:c.labels)!=null?d:[];const{root:r,input:i,text:o,clearIcon:s,dropdownIcon:l}=uE.createDropdown(t,this.labels);this.root=r,this.input=i,this.text=o,this.clearIcon=s,this.dropdownIcon=l,this.autoSuggest=new T2({id:(e==null?void 0:e.popupId)||"dropdown-auto-suggest",header:(h=this.options)==null?void 0:h.header,onClickItem:this.handleClickItem,queryItems:this.handleQueryItems,onClose:this.handleClose,onShow:this.handleShow,highlight:e==null?void 0:e.highlight,emptyPlaceholder:e==null?void 0:e.emptyPlaceholder,disableSelectedScroll:e==null?void 0:e.disableSelectedScroll}),this.items=(E=(C=this.options)==null?void 0:C.items)!=null?E:[],this.root.addEventListener("click",this.handleClick),this.input.addEventListener("input",this.handleInput),this.clearIcon.addEventListener("click",this.handleClear)}close(){this.autoSuggest.close()}destroy(){this.input.removeEventListener("input",this.handleInput),this.root.removeEventListener("click",this.handleClick),this.clearIcon.removeEventListener("click",this.handleClear),this.autoSuggest.destroy()}updateItems(t){this.items=t,this.autoSuggest.handleSearchText("")}setText(t){this.text.innerText=t,this.input.value=t,this.updatePlaceholder()}clear(){this.setText(""),this.setLabels([])}setLabels(t){this.labels=t,this.updateLabels()}static createDropdown(t,e){const r=B("div",["editor-dropdown","empty"],t),i=B("input",["dropdown-input"],r),o=B("div",["dropdown-text"],r),s=B("div",["dropdown-labels"],r);for(let d=0;d<e.length;d+=1){const h=e[d];B("span",["dropdown-label"],s,h)}const l=B("div",["dropdown-clear-icon"],r);l.innerHTML=e2;const c=B("div",["dropdown-icon"],r);return c.innerHTML=xm,{root:r,input:i,text:o,clearIcon:l,dropdownIcon:c}}updateLabels(){const t=this.root.querySelector(".dropdown-labels");if(t){t.innerHTML="";for(let e=0;e<this.labels.length;e+=1){const r=this.labels[e];B("span",["dropdown-label"],t,r)}}}updatePlaceholder(){var t;if(this.input.value===""){const e=(t=this.options)==null?void 0:t.placeholder;e&&(this.input.placeholder=e,this.text.textContent=e),q(this.root,"empty")}else ct(this.root,"empty")}}const eN=[-1,6,0,1,2,3,4,5],nN=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],k2=D("color-palette");function R2(n,t,e,r){p(k2,n>0,"no color in palette");const i=t||1;p(k2,i>0,`invalid palette rows: ${i}`);const o=n/i,s=B("div",["palette-container",r],null);for(let l=0;l<i;l++){const c=B("div",["palette-container-row"],s);for(let d=0;d<o;d++){const h=e(l*o+d);c.appendChild(h)}}return s}function rN(n){const t=B("button",["color-button"],null),e=eN[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=YC,t}function iN(n){const t=B("button",["background-color-button"],null),e=nN[n];return t.setAttribute("data-color-index",`${e}`),t}function oN(){const n=B("div",["clear-button-container"],null),t=B("button",["clear-button"],n);return t.innerText=_.t("colorPalette.reset"),n}function sN(n){const t=B("div",["color-palette"],null);return n.color!==!1&&(B("div",["bar-desc"],t,_.t("colorPalette.colorDesc")),t.appendChild(R2(8,1,rN,"color"))),n.backgroundColor!==!1&&(B("div",["bar-desc"],t,_.t("colorPalette.backgroundDesc")),t.appendChild(R2(16,2,iN,"background-color"))),n.clearColorButton!==!1&&t.appendChild(oN()),t}function lN(n,t,e){const r=t==="color"?"color":"background-color",i=n.querySelector(`.${r} button.selected`);i&&ct(i,"selected"),e===null&&(e=-1);const o=n.querySelector(`.${r} button[data-color-index="${e}"]`);o&&q(o,"selected")}const rat="",aN={};class cN extends Ve.TypedEmitter{constructor(e=aN){super();m(this,"root");m(this,"handleClick",e=>{const r=e.target;if(!r||!(r instanceof Element))return;const i=r.closest("button");if(!i)return;if(Mt(i,"clear-button")){this.setColor("backgroundColor",null),this.setColor("color",null),this.emit("onClick","clearColor",0);return}const o=i.getAttribute("data-color-index");if(!o)return;const s=Number.parseInt(o,10);Number.isNaN(s)||(Mt(i,"color-button")?s===-1?(this.setColor("color",null),this.emit("onClick","clearColor",1)):(this.setColor("color",s),this.emit("onClick","color",s)):s===-1?(this.setColor("backgroundColor",null),this.emit("onClick","clearColor",2)):(this.setColor("backgroundColor",s),this.emit("onClick","backgroundColor",s)))});this.options=e,this.root=sN(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,r){lN(this.root,e,r)}}class w2{constructor(t,e){m(this,"name","Color Palette");m(this,"element");m(this,"palette");m(this,"closeable",null);this.id=t,this.palette=new cN(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function uN(){const n=B("button",["color-button"],null);return n.innerHTML=YC,n}function fE(n,t){const[e,r]=t;e===null?n.removeAttribute("data-color"):n.setAttribute("data-color",`${e}`),r===null?n.removeAttribute("data-background-color"):n.setAttribute("data-background-color",`${r}`)}class S2 extends Ve.TypedEmitter{constructor(e){super();m(this,"id","text-color-item");m(this,"name",_.t("colorPalette.name"));m(this,"dropdown",!0);m(this,"manualShowChildren",!0);m(this,"children",[]);m(this,"element");m(this,"colorPaletteItem");m(this,"latestColors",[null,null]);m(this,"handlePaletteClick",(e,r)=>{this.emit("onClick",e,r)});m(this,"setLatestColors",(e,r)=>{e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=r:this.latestColors[1]=r:this.latestColors=[null,null],fE(this.element,this.latestColors)});m(this,"beforePopup",()=>{this.updatePaletteColor(this.latestColors),this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new w2("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=uN()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,fE(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,fE(this.element,this.latestColors)}}const iat="";function Mm(n,t){const e=B("div",["editor-input-wrap"],n);if(t!=null&&t.className&&q(e,t==null?void 0:t.className),t.label){const s=B("div",["editor-input-label"],e);B("span",[],s,t.label),t.required&&q(s,"required")}const r=B("div",["editor-input-container"],e),i=B("input",["editor-input"],null);if(t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue),t.maxLength&&(i.maxLength=t.maxLength),t.maxLength){const s=B("div",["editor-input-suffix"],r);B("span",[],s,`${i.value.length} / ${t.maxLength}`),i.addEventListener("input",l=>{const c=l.target;s.innerText=`${c.value.length} / ${t.maxLength}`})}r.appendChild(i);const o=B("div",["editor-input-error"],e);return i.addEventListener("input",s=>{var l;(l=t.onChange)==null||l.call(t,s),ct(e,"error")}),h0(i,(s,l)=>{var c;(c=t.onKeyDown)==null||c.call(t,s,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:s=>{q(e,"error"),o.innerText=s},focus:()=>{setTimeout(()=>{i.focus()})}}}function dE(n){const t=document.getSelection();if(!t)return!0;const e=t.focusNode;if(!e)return!0;const r=t.focusOffset,i=e.childNodes[r];if(!i)return!0;if(i instanceof HTMLElement){const o=i.tagName.toLowerCase();if(i===n.input.inputElement)return!0;if(o==="input"||o==="textarea")return!1}return!0}class fN extends T2{constructor(e,r){super(r);m(this,"handleClose",()=>{var e,r;dE(this.editor)&&this.editor.focus(),(r=(e=this.options).onClose)==null||r.call(e)});this.editor=e,this.editorOptions=r}async popupInEditor(e,r,i){var d,h;if(((h=(d=this.editorOptions).onShow)==null?void 0:h.call(d,this,e,r,i))===!1)return;this.options.showLoading&&this.showLoading();const o=this.editor.getBlockByIndex(e,r);if(!Ee(this.editor.rootContainer,o)||Ct(this.editor,o)<i)return;const s=Vo(this.editor,o,Ie(this.editor,o,i));if(s.length===0)return;const l=s[0],c=jo(this.editor,o,"editor-auto-suggest-menu",l);super.popup(c,{noEvent:!0})}}const hE=D("auto-suggest-menu");class mE{constructor(t,e){m(this,"order",100);m(this,"menu");m(this,"anchor",null);m(this,"close",()=>{this.menu.close()});m(this,"oldCompositingText","");m(this,"handleSelectionChanged",t=>{var r,i;if(!((r=this.menu)!=null&&r.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((i=this.anchor)==null?void 0:i.blockId)&&e.offset>=this.anchor.offset){const o=t.getBlockById(e.blockId);if(Re(sr(Yn(t,o),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});m(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:r,offset:i}=e,o=t.getBlockById(r),s=Re(H0(t,o,i));if(p(hE,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,c=i-l;return t.selection.selectBlock(o,l),c&&(t.deleteTextFromBlock(o,l,c),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});m(this,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"onShow",(t,e,r,i)=>{var o;if((o=this.options)!=null&&o.onShow)return this.options.onShow(this,e,r,i)});m(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});m(this,"queryItems",(t,e)=>this.options.queryItems(this,e));m(this,"renderMenuItem",(t,e)=>{var i,o;return(o=(i=this.options).renderMenuItem)==null?void 0:o.call(i,this,e)});m(this,"hasExistsMenuThemeCommandBar",()=>!!document.querySelector('div.tippy-box[data-theme="menu"]'));this.editor=t,this.options=e,this.menu=new fN(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,header:e.header,footer:e.footer,wait:e.wait,noResultMessage:e.noResultMessage,highlight:e.highlight,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,renderMenuItem:this.renderMenuItem}),t.input.addHandler(this),t.addListener("selectionChanged",this.handleSelectionChanged)}handleBeforeKeyDown(t,e){var r;return!((r=this.menu)!=null&&r.isVisible)||Kp(e.key)?!1:ov(e)&&!sa(e)?(setTimeout(()=>{this.resetItems()}),!1):p0(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,r,i){this.anchor={blockId:ut(t),offset:e,leftText:r,trigger:i};const o=pt(at(t)),s=Rt(t);this.menu.popupInEditor(o,s,e)}triggerPopup(t,e,r,i,o){var l;const s=t.selection.range.start;if(!s.isSimple())return!1;if(this.options.trigger.indexOf(o)!==-1){const c=t.getBlockByIndex(e,r);if(i>0&&this.options.needSpaceBeforeTrigger&&(((l=t.getBlockData(c).text)==null?void 0:l.reduce((A,v)=>A+v.insert,""))||"")[i-1].trim().length!==0||this.hasExistsMenuThemeCommandBar())return!1;const{offset:d}=s,h=Re(H0(t,c,d));this.popup(c,d,h,o)}return!1}handleAfterInsertText(t,e,r,i,o){var h;const s=t.selection.range.start;if(!s.isSimple())return!1;const l=t.getBlockByIndex(e,r);if(Ko(l))return!1;const{blockId:c,offset:d}=s;return ut(l)!==c?!1:(h=this.menu)!=null&&h.isVisible?(this.resetItems(),!1):this.triggerPopup(t,e,r,i,o)}handleUpdateCompositionText(t,e,r,i,o){var h;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,r);if(ut(c)!==l)return!1;if((h=this.menu)!=null&&h.isVisible&&this.resetItems(),!o)return this.oldCompositingText=t.compositingText,!1;const d=this.triggerPopup(t,e,r,i,this.oldCompositingText);return this.oldCompositingText="",d}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:r,offset:i}=e,o=t.getBlockById(r),s=Re(H0(t,o,i));if(p(hE,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);hE.debug(`search text: ${c}`),this.menu.handleSearchText(c)}}destroy(){var t;this.editor.input.removeHandler(this),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.menu)==null||t.destroy()}}function dN(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const hN={"insert-hr":{shortcut:"/hr"},"insert-uml":{shortcut:"/uml"},"insert-table":{shortcut:"/table"},"insert-image":{shortcut:"/image"},"insert-code":{shortcut:"/code"},"insert-link":{shortcut:"/link"},"insert-drawio":{shortcut:"/uml"},"insert-video":{shortcut:"/video"},"insert-audio":{shortcut:"/audio"},"insert-math":{shortcut:"/math"},"insert-webPage":{shortcut:"/web"},"insert-bilibili":{shortcut:"/bilibili"},"insert-youku":{shortcut:"/youku"},"insert-figma":{shortcut:"/figma"},"insert-modao":{shortcut:"/modao"},"insert-tencent":{shortcut:"/tencent"},"insert-unordered":{shortcut:"/bl"},"insert-ordered":{shortcut:"/nu"},"insert-checkbox":{shortcut:"/todo"},"insert-quote":{shortcut:"/quote"},...dN()};function Jn(n){var t;return(t=hN[n])==null?void 0:t.shortcut}function mN(n){var t;return(t=n.subText)!=null?t:""}const lo=D("table-dom");function ao(n){return`${ut(n)}_scroll`}function un(n){const t=n.querySelector("div[data-type=table-content] >table");return p(lo,t instanceof HTMLTableElement,"invalid table"),t}function co(n,t){const r=n.getCustom(ao(t)).contentElement.firstElementChild;p(lo,r instanceof HTMLElement,"invalid table content");let i=r.querySelector(":scope >div[data-type=table-tools]");return i||(i=B("div",[],r),i.setAttribute("data-type","table-tools"),n.domEvents.addEventListener(i,"dblclick",(o,s)=>s.stopPropagation()),n.domEvents.addEventListener(i,"click",(o,s)=>{s.detail===3&&s.stopPropagation()})),p(lo,i,"no table tools"),i}function gN(n,t){return n.findCustom(ao(t))?co(n,t):null}function L2(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function pd(n){const t=n.querySelector(":scope div[data-type=editor-container]");return p(lo,t,"no child container in cell"),t}function pN(n){const r=L2(n).map(i=>{const o=pd(i),s=pt(o),l=i.colSpan,c=i.rowSpan;return`${s}/${l}/${c}`}).join();return r0.default(r)}function fn(n){return Ot(n)==="table"}function gE(n){const t=at(n);if(re(t))return null;const e=et(t);return p(lo,e,"no parent block"),fn(e)?t:gE(e)}function is(n){if(fn(n))return n;const t=at(n);if(re(t))return null;const e=et(t);return p(lo,e,"no parent block"),fn(e)?e:is(e)}function CN(n,t){const e=n.querySelector("colgroup");p(lo,e,"no colgroup");const r=e.children[t];return p(lo,r,"no col"),p(lo,r instanceof HTMLTableColElement,`invalid col: ${r.tagName}`),r}function I2(n){try{return un(n),!0}catch{return!1}}function EN(n){return ve(n).querySelector(":scope > .block-helper")}function D2(n){const t=et(n.contentElement);p(lo,t,"no block");const e=EN(t);if(e){const o=Math.min(n.contentElement.offsetLeft+29,n.rootElement.scrollLeft),s=t.getBoundingClientRect().width;e.style.right=`${o+s+5}px`}}function AN(n){const t=n.getComponentOptions("table"),e=t==null?void 0:t.bigTableBoundary;if(!e)return!1;const r=n.rootContainer.querySelectorAll("div[data-type=table-content] >table");let i=!1;return r.forEach(o=>{o.getBoundingClientRect().width>e&&(i=!0)}),i}var pE={exports:{}};(function(n,t){var e=200,r="Expected a function",i="__lodash_hash_undefined__",o=1,s=2,l=1/0,c=9007199254740991,d="[object Arguments]",h="[object Array]",C="[object Boolean]",E="[object Date]",A="[object Error]",v="[object Function]",w="[object GeneratorFunction]",S="[object Map]",U="[object Number]",M="[object Object]",V="[object Promise]",nt="[object RegExp]",Y="[object Set]",X="[object String]",ft="[object Symbol]",xt="[object WeakMap]",bt="[object ArrayBuffer]",wt="[object DataView]",Tt="[object Float32Array]",ie="[object Float64Array]",xe="[object Int8Array]",fe="[object Int16Array]",Dr="[object Int32Array]",dr="[object Uint8Array]",je="[object Uint8ClampedArray]",Tn="[object Uint16Array]",tr="[object Uint32Array]",hr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,mr=/^\w*$/,uh=/^\./,fh=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,dh=/[\\^$.*+?()[\]{}|]/g,Ao=/\\(\\)?/g,cs=/^\[object .+?Constructor\]$/,us=/^(?:0|[1-9]\d*)$/,te={};te[Tt]=te[ie]=te[xe]=te[fe]=te[Dr]=te[dr]=te[je]=te[Tn]=te[tr]=!0,te[d]=te[h]=te[bt]=te[C]=te[wt]=te[E]=te[A]=te[v]=te[S]=te[U]=te[M]=te[nt]=te[Y]=te[X]=te[xt]=!1;var Gt=typeof yn=="object"&&yn&&yn.Object===Object&&yn,ri=typeof self=="object"&&self&&self.Object===Object&&self,On=Gt||ri||Function("return this")(),fs=t&&!t.nodeType&&t,Oa=fs&&!0&&n&&!n.nodeType&&n,kn=Oa&&Oa.exports===fs,xo=kn&&Gt.process,Na=function(){try{return xo&&xo.binding("util")}catch{}}(),er=Na&&Na.isTypedArray;function Pu(k,N){var W=k?k.length:0;return!!W&&hs(k,N,0)>-1}function hh(k,N,W){for(var lt=-1,St=k?k.length:0;++lt<St;)if(W(N,k[lt]))return!0;return!1}function ds(k,N){for(var W=-1,lt=k?k.length:0;++W<lt;)if(N(k[W],W,k))return!0;return!1}function Oe(k,N,W,lt){for(var St=k.length,dt=W+(lt?1:-1);lt?dt--:++dt<St;)if(N(k[dt],dt,k))return dt;return-1}function hs(k,N,W){if(N!==N)return Oe(k,ms,W);for(var lt=W-1,St=k.length;++lt<St;)if(k[lt]===N)return lt;return-1}function ms(k){return k!==k}function Fu(k){return function(N){return N==null?void 0:N[k]}}function gs(k,N){for(var W=-1,lt=Array(k);++W<k;)lt[W]=N(W);return lt}function Ku(k){return function(N){return k(N)}}function ps(k,N){return k.has(N)}function bo(k,N){return k==null?void 0:k[N]}function Cs(k){var N=!1;if(k!=null&&typeof k.toString!="function")try{N=!!(k+"")}catch{}return N}function Pa(k){var N=-1,W=Array(k.size);return k.forEach(function(lt,St){W[++N]=[St,lt]}),W}function Fa(k,N){return function(W){return k(N(W))}}function Es(k){var N=-1,W=Array(k.size);return k.forEach(function(lt){W[++N]=lt}),W}var Ka=Array.prototype,Va=Function.prototype,vo=Object.prototype,As=On["__core-js_shared__"],Dl=function(){var k=/[^.]+$/.exec(As&&As.keys&&As.keys.IE_PROTO||"");return k?"Symbol(src)_1."+k:""}(),Vu=Va.toString,_r=vo.hasOwnProperty,Bo=vo.toString,$u=RegExp("^"+Vu.call(_r).replace(dh,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),$a=On.Symbol,Hu=On.Uint8Array,mh=vo.propertyIsEnumerable,gh=Ka.splice,ph=Fa(Object.keys,Object),_l=Lo(On,"DataView"),xs=Lo(On,"Map"),Ha=Lo(On,"Promise"),yo=Lo(On,"Set"),bs=Lo(On,"WeakMap"),vs=Lo(Object,"create"),ja=Pi(_l),Ch=Pi(xs),Eh=Pi(Ha),be=Pi(yo),Ah=Pi(bs),Ml=$a?$a.prototype:void 0,Ul=Ml?Ml.valueOf:void 0,To=Ml?Ml.toString:void 0;function Oi(k){var N=-1,W=k?k.length:0;for(this.clear();++N<W;){var lt=k[N];this.set(lt[0],lt[1])}}function Ol(){this.__data__=vs?vs(null):{}}function ju(k){return this.has(k)&&delete this.__data__[k]}function zu(k){var N=this.__data__;if(vs){var W=N[k];return W===i?void 0:W}return _r.call(N,k)?N[k]:void 0}function xh(k){var N=this.__data__;return vs?N[k]!==void 0:_r.call(N,k)}function bh(k,N){var W=this.__data__;return W[k]=vs&&N===void 0?i:N,this}Oi.prototype.clear=Ol,Oi.prototype.delete=ju,Oi.prototype.get=zu,Oi.prototype.has=xh,Oi.prototype.set=bh;function Mr(k){var N=-1,W=k?k.length:0;for(this.clear();++N<W;){var lt=k[N];this.set(lt[0],lt[1])}}function vh(){this.__data__=[]}function Nl(k){var N=this.__data__,W=ko(N,k);if(W<0)return!1;var lt=N.length-1;return W==lt?N.pop():gh.call(N,W,1),!0}function Bh(k){var N=this.__data__,W=ko(N,k);return W<0?void 0:N[W][1]}function Pl(k){return ko(this.__data__,k)>-1}function yh(k,N){var W=this.__data__,lt=ko(W,k);return lt<0?W.push([k,N]):W[lt][1]=N,this}Mr.prototype.clear=vh,Mr.prototype.delete=Nl,Mr.prototype.get=Bh,Mr.prototype.has=Pl,Mr.prototype.set=yh;function Ur(k){var N=-1,W=k?k.length:0;for(this.clear();++N<W;){var lt=k[N];this.set(lt[0],lt[1])}}function Th(){this.__data__={hash:new Oi,map:new(xs||Mr),string:new Oi}}function Gu(k){return ks(this,k).delete(k)}function Fl(k){return ks(this,k).get(k)}function Wu(k){return ks(this,k).has(k)}function kh(k,N){return ks(this,k).set(k,N),this}Ur.prototype.clear=Th,Ur.prototype.delete=Gu,Ur.prototype.get=Fl,Ur.prototype.has=Wu,Ur.prototype.set=kh;function Bs(k){var N=-1,W=k?k.length:0;for(this.__data__=new Ur;++N<W;)this.add(k[N])}function Rh(k){return this.__data__.set(k,i),this}function gr(k){return this.__data__.has(k)}Bs.prototype.add=Bs.prototype.push=Rh,Bs.prototype.has=gr;function Nn(k){this.__data__=new Mr(k)}function ii(){this.__data__=new Mr}function Xe(k){return this.__data__.delete(k)}function za(k){return this.__data__.get(k)}function wh(k){return this.__data__.has(k)}function Or(k,N){var W=this.__data__;if(W instanceof Mr){var lt=W.__data__;if(!xs||lt.length<e-1)return lt.push([k,N]),this;W=this.__data__=new Ur(lt)}return W.set(k,N),this}Nn.prototype.clear=ii,Nn.prototype.delete=Xe,Nn.prototype.get=za,Nn.prototype.has=wh,Nn.prototype.set=Or;function Nr(k,N){var W=Fi(k)||Za(k)?gs(k.length,String):[],lt=W.length,St=!!lt;for(var dt in k)(N||_r.call(k,dt))&&!(St&&(dt=="length"||Qu(dt,lt)))&&W.push(dt);return W}function ko(k,N){for(var W=k.length;W--;)if(Ju(k[W][0],N))return W;return-1}function ys(k,N){N=Vl(N,k)?[N]:oi(N);for(var W=0,lt=N.length;k!=null&&W<lt;)k=k[$l(N[W++])];return W&&W==lt?k:void 0}function Ga(k){return Bo.call(k)}function Ni(k,N){return k!=null&&N in Object(k)}function pr(k,N,W,lt,St){return k===N?!0:k==null||N==null||!ai(k)&&!xn(N)?k!==k&&N!==N:Wa(k,N,pr,W,lt,St)}function Wa(k,N,W,lt,St,dt){var $t=Fi(k),Zt=Fi(N),ce=h,we=h;$t||(ce=si(k),ce=ce==d?M:ce),Zt||(we=si(N),we=we==d?M:we);var Se=ce==M&&!Cs(k),De=we==M&&!Cs(N),ee=ce==we;if(ee&&!Se)return dt||(dt=new Nn),$t||ec(k)?Yu(k,N,W,lt,St,dt):Ih(k,N,ce,W,lt,St,dt);if(!(St&s)){var Rn=Se&&_r.call(k,"__wrapped__"),hn=De&&_r.call(N,"__wrapped__");if(Rn||hn){var wn=Rn?k.value():k,Sn=hn?N.value():N;return dt||(dt=new Nn),W(wn,Sn,lt,St,dt)}}return ee?(dt||(dt=new Nn),Ya(k,N,W,lt,St,dt)):!1}function qa(k,N,W,lt){var St=W.length,dt=St,$t=!lt;if(k==null)return!dt;for(k=Object(k);St--;){var Zt=W[St];if($t&&Zt[2]?Zt[1]!==k[Zt[0]]:!(Zt[0]in k))return!1}for(;++St<dt;){Zt=W[St];var ce=Zt[0],we=k[ce],Se=Zt[1];if($t&&Zt[2]){if(we===void 0&&!(ce in k))return!1}else{var De=new Nn;if(lt)var ee=lt(we,Se,ce,k,N,De);if(!(ee===void 0?pr(Se,we,lt,o|s,De):ee))return!1}}return!0}function Ro(k){if(!ai(k)||_h(k))return!1;var N=li(k)||Cs(k)?$u:cs;return N.test(Pi(k))}function Xa(k){return xn(k)&&Io(k.length)&&!!te[Bo.call(k)]}function wo(k){return typeof k=="function"?k:k==null?Pn:typeof k=="object"?Fi(k)?Sh(k[0],k[1]):qu(k):Gn(k)}function So(k){if(!Mh(k))return ph(k);var N=[];for(var W in Object(k))_r.call(k,W)&&W!="constructor"&&N.push(W);return N}function qu(k){var N=Qa(k);return N.length==1&&N[0][2]?de(N[0][0],N[0][1]):function(W){return W===k||qa(W,k,N)}}function Sh(k,N){return Vl(k)&&pe(N)?de($l(k),N):function(W){var lt=Zu(W,k);return lt===void 0&&lt===N?rc(W,k):pr(N,lt,void 0,o|s)}}function Xu(k){return function(N){return ys(N,k)}}function Ts(k){if(typeof k=="string")return k;if(Rs(k))return To?To.call(k):"";var N=k+"";return N=="0"&&1/k==-l?"-0":N}function Kl(k,N,W){var lt=-1,St=Pu,dt=k.length,$t=!0,Zt=[],ce=Zt;if(W)$t=!1,St=hh;else if(dt>=e){var we=N?null:Lh(k);if(we)return Es(we);$t=!1,St=ps,ce=new Bs}else ce=N?[]:Zt;t:for(;++lt<dt;){var Se=k[lt],De=N?N(Se):Se;if(Se=W||Se!==0?Se:0,$t&&De===De){for(var ee=ce.length;ee--;)if(ce[ee]===De)continue t;N&&ce.push(De),Zt.push(Se)}else St(ce,De,W)||(ce!==Zt&&ce.push(De),Zt.push(Se))}return Zt}function oi(k){return Fi(k)?k:Uh(k)}var Lh=yo&&1/Es(new yo([,-0]))[1]==l?function(k){return new yo(k)}:Nh;function Yu(k,N,W,lt,St,dt){var $t=St&s,Zt=k.length,ce=N.length;if(Zt!=ce&&!($t&&ce>Zt))return!1;var we=dt.get(k);if(we&&dt.get(N))return we==N;var Se=-1,De=!0,ee=St&o?new Bs:void 0;for(dt.set(k,N),dt.set(N,k);++Se<Zt;){var Rn=k[Se],hn=N[Se];if(lt)var wn=$t?lt(hn,Rn,Se,N,k,dt):lt(Rn,hn,Se,k,N,dt);if(wn!==void 0){if(wn)continue;De=!1;break}if(ee){if(!ds(N,function(Sn,bn){if(!ee.has(bn)&&(Rn===Sn||W(Rn,Sn,lt,St,dt)))return ee.add(bn)})){De=!1;break}}else if(!(Rn===hn||W(Rn,hn,lt,St,dt))){De=!1;break}}return dt.delete(k),dt.delete(N),De}function Ih(k,N,W,lt,St,dt,$t){switch(W){case wt:if(k.byteLength!=N.byteLength||k.byteOffset!=N.byteOffset)return!1;k=k.buffer,N=N.buffer;case bt:return!(k.byteLength!=N.byteLength||!lt(new Hu(k),new Hu(N)));case C:case E:case U:return Ju(+k,+N);case A:return k.name==N.name&&k.message==N.message;case nt:case X:return k==N+"";case S:var Zt=Pa;case Y:var ce=dt&s;if(Zt||(Zt=Es),k.size!=N.size&&!ce)return!1;var we=$t.get(k);if(we)return we==N;dt|=o,$t.set(k,N);var Se=Yu(Zt(k),Zt(N),lt,St,dt,$t);return $t.delete(k),Se;case ft:if(Ul)return Ul.call(k)==Ul.call(N)}return!1}function Ya(k,N,W,lt,St,dt){var $t=St&s,Zt=ws(k),ce=Zt.length,we=ws(N),Se=we.length;if(ce!=Se&&!$t)return!1;for(var De=ce;De--;){var ee=Zt[De];if(!($t?ee in N:_r.call(N,ee)))return!1}var Rn=dt.get(k);if(Rn&&dt.get(N))return Rn==N;var hn=!0;dt.set(k,N),dt.set(N,k);for(var wn=$t;++De<ce;){ee=Zt[De];var Sn=k[ee],bn=N[ee];if(lt)var Ss=$t?lt(bn,Sn,ee,N,k,dt):lt(Sn,bn,ee,k,N,dt);if(!(Ss===void 0?Sn===bn||W(Sn,bn,lt,St,dt):Ss)){hn=!1;break}wn||(wn=ee=="constructor")}if(hn&&!wn){var Ki=k.constructor,Do=N.constructor;Ki!=Do&&"constructor"in k&&"constructor"in N&&!(typeof Ki=="function"&&Ki instanceof Ki&&typeof Do=="function"&&Do instanceof Do)&&(hn=!1)}return dt.delete(k),dt.delete(N),hn}function ks(k,N){var W=k.__data__;return Dh(N)?W[typeof N=="string"?"string":"hash"]:W.map}function Qa(k){for(var N=ws(k),W=N.length;W--;){var lt=N[W],St=k[lt];N[W]=[lt,St,pe(St)]}return N}function Lo(k,N){var W=bo(k,N);return Ro(W)?W:void 0}var si=Ga;(_l&&si(new _l(new ArrayBuffer(1)))!=wt||xs&&si(new xs)!=S||Ha&&si(Ha.resolve())!=V||yo&&si(new yo)!=Y||bs&&si(new bs)!=xt)&&(si=function(k){var N=Bo.call(k),W=N==M?k.constructor:void 0,lt=W?Pi(W):void 0;if(lt)switch(lt){case ja:return wt;case Ch:return S;case Eh:return V;case be:return Y;case Ah:return xt}return N});function Ja(k,N,W){N=Vl(N,k)?[N]:oi(N);for(var lt,St=-1,$t=N.length;++St<$t;){var dt=$l(N[St]);if(!(lt=k!=null&&W(k,dt)))break;k=k[dt]}if(lt)return lt;var $t=k?k.length:0;return!!$t&&Io($t)&&Qu(dt,$t)&&(Fi(k)||Za(k))}function Qu(k,N){return N=N==null?c:N,!!N&&(typeof k=="number"||us.test(k))&&k>-1&&k%1==0&&k<N}function Vl(k,N){if(Fi(k))return!1;var W=typeof k;return W=="number"||W=="symbol"||W=="boolean"||k==null||Rs(k)?!0:mr.test(k)||!hr.test(k)||N!=null&&k in Object(N)}function Dh(k){var N=typeof k;return N=="string"||N=="number"||N=="symbol"||N=="boolean"?k!=="__proto__":k===null}function _h(k){return!!Dl&&Dl in k}function Mh(k){var N=k&&k.constructor,W=typeof N=="function"&&N.prototype||vo;return k===W}function pe(k){return k===k&&!ai(k)}function de(k,N){return function(W){return W==null?!1:W[k]===N&&(N!==void 0||k in Object(W))}}var Uh=Hl(function(k){k=nc(k);var N=[];return uh.test(k)&&N.push(""),k.replace(fh,function(W,lt,St,dt){N.push(St?dt.replace(Ao,"$1"):lt||W)}),N});function $l(k){if(typeof k=="string"||Rs(k))return k;var N=k+"";return N=="0"&&1/k==-l?"-0":N}function Pi(k){if(k!=null){try{return Vu.call(k)}catch{}try{return k+""}catch{}}return""}function Oh(k,N){return k&&k.length?Kl(k,wo(N)):[]}function Hl(k,N){if(typeof k!="function"||N&&typeof N!="function")throw new TypeError(r);var W=function(){var lt=arguments,St=N?N.apply(this,lt):lt[0],dt=W.cache;if(dt.has(St))return dt.get(St);var $t=k.apply(this,lt);return W.cache=dt.set(St,$t),$t};return W.cache=new(Hl.Cache||Ur),W}Hl.Cache=Ur;function Ju(k,N){return k===N||k!==k&&N!==N}function Za(k){return tc(k)&&_r.call(k,"callee")&&(!mh.call(k,"callee")||Bo.call(k)==d)}var Fi=Array.isArray;function Ye(k){return k!=null&&Io(k.length)&&!li(k)}function tc(k){return xn(k)&&Ye(k)}function li(k){var N=ai(k)?Bo.call(k):"";return N==v||N==w}function Io(k){return typeof k=="number"&&k>-1&&k%1==0&&k<=c}function ai(k){var N=typeof k;return!!k&&(N=="object"||N=="function")}function xn(k){return!!k&&typeof k=="object"}function Rs(k){return typeof k=="symbol"||xn(k)&&Bo.call(k)==ft}var ec=er?Ku(er):Xa;function nc(k){return k==null?"":Ts(k)}function Zu(k,N,W){var lt=k==null?void 0:ys(k,N);return lt===void 0?W:lt}function rc(k,N){return k!=null&&Ja(k,N,Ni)}function ws(k){return Ye(k)?Nr(k):So(k)}function Pn(k){return k}function Nh(){}function Gn(k){return Vl(k)?Fu($l(k)):Xu(k)}n.exports=Oh})(pE,pE.exports);const xN=pE.exports,wi=D("doc-table-grid");class bN{constructor(t){m(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){p(wi,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){p(wi,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return p(wi,e,"get cell, no cell"),e}getCellAllowEmpty(t){return p(wi,t>=0&&t<this.cols(),`get cell, invalid col, ${t}`),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}forEach(t){this._cells.forEach(t)}}class Um{constructor(t){m(this,"_data");m(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new bN(this.colCount));this.fillGrid()}get rowCount(){return this._data.rows}get colCount(){return this._data.cols}getNextEmptyCell(t,e){let r=t,i=e;for(;;){if(r+=1,r===this.colCount&&(r=0,i+=1),i>=this.rowCount)return null;if(this._rows[i].getCellAllowEmpty(r)===void 0)return{col:r,row:i}}}fillGrid(){const t=this._data.children;p(wi,t,"no children");let e=0,r=0;t.forEach((i,o)=>{const s=this._data[`${i}_colSpan`]||1,l=this._data[`${i}_rowSpan`]||1;for(let d=0;d<l;d++)for(let h=0;h<s;h++)this._rows[r+d].setCell(e+h,{col:e,row:r,containerId:i,virtual:h!==0||d!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,r);c?(e=c.col,r=c.row):p(wi,o===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(i=>{i.forEach(o=>{p(wi,o,"no cell"),p(wi,o.containerId,"no containerId")})})}getCell(t){const{col:e,row:r}=t,i=this._rows[r];p(wi,i,`get cell, no row: ${r}`);const o=i.getCell(e);return p(wi,o,`get cell, no cell: ${e}`),o}getRow(t){const e=this._rows[t];return p(wi,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Om=D("table-data");function vN(n){const t=n.firstElementChild;return p(Om,t,"no child element for cell"),p(Om,Qs(t),"cell first child is not a container"),p(Om,pi(t),"cell first child is not a container"),t}function BN(n){const t=et(n);p(Om,t,"no parent block for table");const e=[],r={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const d=vN(c),h=pt(d);e.push(h),(c.colSpan>1||c.rowSpan>1)&&(r[`${h}_colSpan`]=c.colSpan,r[`${h}_rowSpan`]=c.rowSpan)})});const i=n.rows.length,o=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,c)=>l+c,0);return{id:ut(t),type:Ot(t),rows:i,cols:o,children:e,colsWidth:Array(o).fill(100),...r}}function ya(n){return new Um(n)}function yN(n){return ya(BN(n))}const tn=D("table-grid"),TN=60;class kN{constructor(t,e){m(this,"containerId");m(this,"row");m(this,"col");m(this,"colSpan");m(this,"rowSpan");m(this,"virtual");m(this,"table");this.table=t,this.containerId=e.containerId,this.row=e.row,this.col=e.col,this.colSpan=e.colSpan,this.rowSpan=e.rowSpan,this.virtual=e.virtual}get cell(){const e=this.container.closest("td");return p(tn,e,"no parent cell for child container"),e}get container(){const t=Zp(this.containerId),e=this.table.querySelectorAll(`#${t}`);p(tn,e.length===1,"containers !== 1"),p(tn,Qs(e[0]),"not a container");const r=e[0];return p(tn,pi(r),"not a child container"),r}}class RN{constructor(t,e){m(this,"_cells",[]);e.forEach(r=>{this._cells.push(new kN(t,r))})}get cells(){return this._cells}getCell(t){return p(tn,t<this._cells.length,"get cell, invalid col"),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}getSpannedCell(){return this._cells.find(t=>t.virtual||t.colSpan>1||t.rowSpan>1)}}const Dx=class{constructor(t){m(this,"_rows",[]);this.table=t,yN(t).forEach(i=>{this._rows.push(new RN(t,i))});const r=this.colCount;this._rows.forEach(i=>{p(tn,i.cells.length===r,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(p(tn,this.rowCount>0,"rowCount <= 0"),this.getRow(0).cells.length)}getRow(t){return this._rows[t]}getCell(t){const e=this.getRow(t.row);return p(tn,e,"no row"),e.getCell(t.col)}getCellContainer(t){return this.getCell(t).container}getFirstCellContainer(){return this.getCellContainer({row:0,col:0})}getLastCellContainer(){const t=this.rowCount-1,e=this.colCount-1;return this.getCellContainer({row:t,col:e})}getColumnCells(t){p(tn,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,r=[];for(let i=0;i<e;i++){const o=this.getCell({row:i,col:t});r.push(o)}return r}toRealCells(t){const e=[];return t.forEach(r=>{const i=this.getRealCell(r);e.findIndex(o=>o.containerId===i.containerId)===-1&&e.push(i)}),e}getColumnRealCells(t){const e=this.getColumnCells(t);return this.toRealCells(e)}getRowRealCells(t){const e=this.getRow(t).cells;return this.toRealCells(e)}getFirstSpannedCell(t){p(tn,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});if(i.virtual||i.colSpan>1||i.rowSpan>1)return i}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const r=this.getCellById(e.containerId);return p(tn,!r.virtual,"found a virtual cell"),r}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let r=1e5,i=-1;return e.forEach(o=>{r=Math.min(o.col,r),i=Math.max(o.col+o.colSpan-1,i)}),p(tn,r<=i,"min > max"),p(tn,r>=0,"min < 0"),p(tn,i<this.colCount,"max >= colCount"),[r,i]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let r=1e5,i=-1;return e.forEach(o=>{r=Math.min(o.row,r),i=Math.max(o.row+o.rowSpan-1,i)}),p(tn,r<=i,"min > max"),p(tn,r>=0,"min < 0"),p(tn,i<this.rowCount,"max >= rowCount"),[r,i]}getSpannedRange(t,e){const r=Math.min(t.row,e.row),i=Math.max(t.row,e.row),o=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let A=r;A<=i;A++)for(let v=o;v<=s;v++)l.push(this.getCell({row:A,col:v}));const c=this.toRealCells(l);let d=1e4,h=1e4,C=-1,E=-1;return c.forEach(A=>{h=Math.min(A.col,h),d=Math.min(A.row,d),E=Math.max(A.col+A.colSpan-1,E),C=Math.max(A.row+A.rowSpan-1,C)}),[{row:d,col:h},{row:C,col:E}]}getAllCells(){return this.getCells({col:0,row:0},{col:this.colCount-1,row:this.rowCount-1})}sub(t,e){const r=[];for(let i=t.row;i<=e.row;i++){const o=[];for(let s=t.col;s<=e.col;s++){const l=this.getCell({row:i,col:s});o.push(l)}r.push(o)}return r}getAllContainers(){return this.getAllCells().map(e=>e.container)}getCells(t,e){const r=[],i=this.getSpannedRange(t,e),o=i[0],s=i[1],l=Math.min(o.row,s.row),c=Math.max(o.row,s.row),d=Math.min(o.col,s.col),h=Math.max(o.col,s.col);for(let C=l;C<=c;C++)for(let E=d;E<=h;E++){const A=this.getCell({row:C,col:E});A.virtual||r.push(A)}return r}map(t){const e=[];for(let r=0;r<this.rowCount;r++){const i=[];for(let o=0;o<this.colCount;o++){const s=this.getCell({row:r,col:o});i.push(t(s))}e.push(i)}return e}getBottomCell(t){const e=this.rowCount;let r=t,i=t.row;for(;r.containerId===t.containerId;){if(i+=1,i>=e)return null;r=this.getCell({row:i,col:t.col})}return this.getRealCell(r)}getTopCell(t){let e=t,r=t.row;for(;e.containerId===t.containerId;){if(r-=1,r<0)return null;e=this.getCell({row:r,col:t.col})}return this.getRealCell(e)}getLeftCell(t){const e=this.uniqueCells,r=e.findIndex(i=>i.containerId===t.containerId);return p(tn,r>=0,"not a valid child container"),r===0?null:e[r-1]}getRightCell(t){const e=this.uniqueCells,r=e.findIndex(i=>i.containerId===t.containerId);return p(tn,r>=0,"not a valid child container"),r===e.length-1?null:e[r+1]}get uniqueCells(){return xN(this.cells,"containerId")}get cells(){let t=[];return this._rows.forEach(e=>{t=t.concat(e.cells)}),t}getVirtualCellContainersGrid(){return this.map(t=>t.containerId)}static virtualCellContainersGridToChildren(t){const e=t,r=[];return e.forEach(i=>{i.forEach(o=>{r.indexOf(o)===-1&&r.push(o)})}),r}getCellById(t){const r=this.cells.find(i=>i.containerId===t);return p(tn,r,"cell not found"),r}getCellByCellElement(t){const e=pd(t);return this.getCellByContainerId(pt(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=pN(t),r=this.caches.getSync(e,()=>(tn.debug("create table grid"),new Dx(t)));return r.table!==t?(this.caches.delete(e),this.fromTable(t)):r}static fromBlock(t){return this.fromTable(un(t))}};let Kt=Dx;m(Kt,"caches",new Vb(TN));function Nm(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const wN=D("table-selection-range");function Si(n,t,e){var M,V,nt,Y;const r=Kt.fromBlock(n),i=t,o=e,s=r.getCellByContainerId(i.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=i.custom,d=o.custom,h=(M=c==null?void 0:c.rowIndex)!=null?M:s.row,C=(V=c==null?void 0:c.colIndex)!=null?V:s.col,E=(nt=d==null?void 0:d.rowIndex)!=null?nt:l.row+l.rowSpan-1,A=(Y=d==null?void 0:d.colIndex)!=null?Y:l.col+l.colSpan-1,v=Math.min(h,E),w=Math.max(h,E),S=Math.min(C,A),U=Math.max(C,A);return{fromRow:v,toRow:w,fromCol:S,toCol:U}}function CE(n,t){const e=new Set,r=new Set,i=n.selection.range;if(!i.isSimple()&&i.start.blockId===ut(t)){const o=Kt.fromBlock(t),{start:s,end:l}=i;p(wN,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:d,fromRow:h,toRow:C}=Si(t,s,l);if(h===0&&C===o.rowCount-1)for(let E=c;E<=d;E++)r.add(E);if(c===0&&d===o.colCount-1)for(let E=h;E<=C;E++)e.add(E)}return{selectedRows:e,selectedColumns:r}}function Cd(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const r=n.getBlockById(t.start.blockId);if(fn(r)){const i=at(r),o=et(i);o&&(e=is(o))}else e=is(r)}else{const r=n.getBlockById(t.start.blockId),i=is(r),o=n.getBlockById(t.end.blockId),s=is(o);i===s&&(e=i)}return e}const lu=D("delete-columns");function _2(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||Ot(t)!=="table")return!1;const{fromRow:s,toRow:l}=Si(t,e.start,e.end),c=Kt.fromBlock(t);return s===0&&l===c.rowCount-1}function EE(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var V,nt;const e=t.getBlockById(n.start.blockId);if(!_2(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:r,toCol:i}=Si(e,n.start,n.end),o=Kt.fromBlock(e);if(r===0&&i===o.colCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(Y=>Y.containerId);for(let Y=0;Y<l.length;Y++){const X=l[Y];for(let ft=r;ft<=i;ft++){const xt=X[ft];s.add(xt)}X.splice(r,i-r+1)}const c=new Set(l.flat()),d=new Set(Array.from(s).filter(Y=>!c.has(Y))),h=i-r+1,C=new Map,E=new Map;s.forEach(Y=>{if(d.has(Y))return;const X=o.getCellByContainerId(Y);if(p(lu,X.colSpan>1,"invalid effected cell, colSpan === 1"),X.col<r){p(lu,c.has(Y),"invalid effected cell, not exists");let ie=X.col+X.colSpan-1;ie>i&&(ie=i);const xe=ie-r+1,fe=X.colSpan-xe;C.set(Y,fe);return}p(lu,X.col<=i,"invalid effected cell, col > endCol");const ft=X.col,xt=X.col+X.colSpan-1,bt=X.col-r,wt=xt-ft+1-h+bt;p(lu,wt>0,"invalid effected cell, newSpanned <= 0");const Tt=Yo(t.doc);E.set(Y,{newContainerId:Tt,colSpan:wt})});for(let Y=0;Y<l.length;Y++){const X=l[Y];for(let ft=r;ft<X.length;ft++){const xt=X[ft],bt=E.get(xt);bt&&(X[ft]=bt.newContainerId)}}const A=Et.default(t.getBlockData(e));((V=A.colsWidth)!=null?V:new Array(A.cols).fill(0)).splice(r,i-r+1),d.forEach(Y=>{Nm(A,Y)}),C.forEach((Y,X)=>{p(lu,Y>=1,"invalid modified colSpan, colSpan < 1"),Y===1?A[`${X}_colSpan`]=void 0:A[`${X}_colSpan`]=Y}),E.forEach((Y,X)=>{Nm(A,X);const{newContainerId:ft,colSpan:xt}=Y;p(lu,xt>=1,"invalid newContainerData, colSpan < 1"),xt>1&&(A[`${ft}_colSpan`]=xt);const bt=o.getCellByContainerId(X).rowSpan;bt>1&&(A[`${ft}_rowSpan`]=bt)});const w=(nt=l[0][r])!=null?nt:l[0][r-1],S=t.getChildContainerData(w)[0],U=Kt.virtualCellContainersGridToChildren(l),M={...A,cols:A.cols-h,children:U};ya(M),t.updateBlockData(e,M,Ie(t,S.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const au=D("delete-rows");function M2(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||Ot(t)!=="table")return!1;const{fromCol:s,toCol:l}=Si(t,e.start,e.end),c=Kt.fromBlock(t);return s===0&&l===c.colCount-1}function AE(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!M2(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:r,toRow:i}=Si(e,n.start,n.end),o=Kt.fromBlock(e);if(r===0&&i===o.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(M=>M.containerId);for(let M=i;M>=r;M--)l[M].forEach(nt=>s.add(nt)),l.splice(M,1);const c=new Set(l.flat()),d=new Set(Array.from(s).filter(M=>!c.has(M))),h=i-r+1,C=new Map,E=new Map;s.forEach(M=>{if(d.has(M))return;const V=o.getCellByContainerId(M);if(p(au,V.rowSpan>1,"invalid effected cell, rowSpan === 1"),V.row<r){p(au,c.has(M),"invalid effected cell, not exists");let bt=V.row+V.rowSpan-1;bt>i&&(bt=i);const wt=bt-r+1,Tt=V.rowSpan-wt;C.set(M,Tt);return}p(au,V.row<=i,"invalid effected cell, col > endCol");const nt=V.row,Y=V.row+V.rowSpan-1,X=V.row-r,ft=Y-nt+1-h+X;p(au,ft>0,"invalid effected cell, newSpanned <= 0");const xt=Yo(t.doc);E.set(M,{newContainerId:xt,rowSpan:ft})});for(let M=r;M<l.length;M++){const V=l[M];for(let nt=0;nt<V.length;nt++){const Y=V[nt],X=E.get(Y);X&&(V[nt]=X.newContainerId)}}const A=Et.default(t.getBlockData(e));d.forEach(M=>{Nm(A,M)}),C.forEach((M,V)=>{p(au,M>=1,"invalid modified rowSpan, rowSpan < 1"),M===1?A[`${V}_rowSpan`]=void 0:A[`${V}_rowSpan`]=M}),E.forEach((M,V)=>{Nm(A,V);const{newContainerId:nt,rowSpan:Y}=M;p(au,Y>=1,"invalid newContainerData, rowSpan < 1"),Y>1&&(A[`${nt}_rowSpan`]=Y);const X=o.getCellByContainerId(V).colSpan;X>1&&(A[`${nt}_colSpan`]=X)});const v=l[r]?l[r][0]:l[r-1][0],w=t.getChildContainerData(v)[0],S=Kt.virtualCellContainersGridToChildren(l),U={...A,rows:A.rows-h,children:S};ya(U),t.updateBlockData(e,U,Ie(t,w.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const Ed=D("table-range");function Pm(n){p(Ed,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;p(Ed,!t.isSimple(),"invalid start pos type"),p(Ed,!e.isSimple(),"invalid end pos type");const r=n.getEditor();p(Ed,t.blockId===e.blockId,"invalid range, not same block");const i=r.getBlockById(t.blockId);p(Ed,Ot(i)==="table","invalid block type, not a table block");const o=un(i),s=Kt.fromTable(o),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),d=Math.min(l.row,c.row),h=Math.max(l.row,c.row),C=Math.min(l.col,c.col),E=Math.max(l.col,c.col),A=s.getCell({row:d,col:C}),v=s.getCell({row:h,col:E});return{editor:r,block:i,table:o,startCell:A,endCell:v,startRow:d,startCol:C,endRow:h,endCol:E}}const xE=D("split-cell");function bE(n,t,e){n.undoManager.runInGroup(()=>{const r=Kt.fromBlock(t),i=r.getRealCell(e);p(xE,!i.virtual,"should not split virtual cell"),p(xE,i.colSpan>1||i.rowSpan>1,"cell does not has span data");const o=r.getVirtualCellContainersGrid();for(let C=0;C<i.rowSpan;C++)for(let E=0;E<i.colSpan;E++){if(C===0&&E===0)continue;const A=C+i.row,v=E+i.col,w=Yo(n.doc);o[A][v]=w}const s=n.getBlockData(t),l=Et.default(s);l[`${i.containerId}_colSpan`]=null,l[`${i.containerId}_rowSpan`]=null,l.children=Kt.virtualCellContainersGridToChildren(o);const d=n.getChildContainerData(i.containerId)[0];p(xE,d,"no child block");const h=Ie(n,d.id,0);ya(l),n.updateBlockData(t,l,h)})}function SN(n,t,e){e.forEach(r=>{const i=Kt.fromBlock(t).getCell(r);(i.virtual||i.colSpan>1||i.rowSpan>1)&&bE(n,t,r)})}function U2(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||Ot(t)!=="table")return!1;const{startCell:s,endCell:l}=Pm(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function vE(n){const{editor:t,block:e,startRow:r,startCol:i,endRow:o,endCol:s}=Pm(n),l=[];for(let c=r;c<=o;c++)for(let d=i;d<=s;d++)l.push({row:c,col:d});return SN(t,e,l),!0}const cu=D("merge-cells");function O2(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||Ot(t)!=="table")return!1;const{startCell:s,endCell:l}=Pm(e);return s.cell!==l.cell}function N2(n){const t=Pm(n),e=t.editor;e.undoManager.runInGroup(()=>{const r=t.endCell,i=r.row+r.rowSpan-1,o=r.col+r.colSpan-1,s=ut(t.block);vE(n);const l=e.getBlockById(s),c=un(l),{startRow:d,startCol:h}=t,C=Et.default(e.getBlockData(l));p(cu,C.children,"no table children");const E=Kt.fromTable(c),A=[];for(let bt=d;bt<=i;bt++)for(let wt=h;wt<=o;wt++){const Tt=E.getCell({row:bt,col:wt});p(cu,!Tt.virtual,"cell is virtual"),A.push(Tt)}p(cu,A.length>0,"no selected cells");const v=A[0],w=A.slice(1),S=E.getCellByContainerId(v.containerId).container,U=[];w.forEach(bt=>{const wt=E.getCellByContainerId(bt.containerId).container,Tt=pt(wt);if(!Uf(e,wt)){const ie=X5(e,Tt);if(Uf(e,S)){const xe=ke(S)[0];e.insertDocAt(S,0,ie),e.deleteBlock(xe)}else e.insertDocAt(S,Xi(S),ie)}U.push(Tt)});const M=pt(S),V=o-h+1,nt=i-d+1;C[`${M}_colSpan`]=V,C[`${M}_rowSpan`]=nt,U.forEach(bt=>{p(cu,C.children,"no table children");const wt=C.children.indexOf(bt);p(cu,wt>0,"no deleted container"),C.children.splice(wt,1)});const Y=C,ft=e.getChildContainerData(M)[0];p(cu,ft,"no child block");const xt=Ie(e,ft.id,0);ya(Y),e.updateBlockData(l,Y,xt),e.deleteChildContainers(U)})}const BE=10,LN=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Fm{constructor(){m(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,r){if(Ot(e)!=="table")return[];const i={blockId:ut(e),blockKind:Ei(t,e),blockType:Ot(e)},o=[];O2(t,e,r)&&o.push({id:"table/merge-cells",name:_.t("table.mergeCell"),icon:bT,groupIndex:BE,...i}),U2(t,e,r)&&o.push({id:"table/split-cell",name:_.t("table.splitCell"),icon:vT,groupIndex:BE,...i});const s=_2(t,e,r),l=M2(t,e,r);return s&&l&&o.push({id:"table/delete",name:_.t("table.deleteTable"),icon:BT,groupIndex:BE,...i}),o}executeCommand(t,e,r,i,o,s){return Ot(e)!=="table"||!new Set(LN).has(i.id)?!1:i.id==="table/merge-cells"?(N2(r),!0):i.id==="table/split-cell"?(vE(r),!0):i.id==="table/delete-columns"?(EE(r),!0):i.id==="table/delete-rows"?(AE(r),!0):i.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var P2=(n=>(n.COL_TITLE_TABLE="col-title-table",n.COL_TITLE_ITEM="col-title-item",n.STRIPE_STYLE_TABLE="stripe-style-table",n.NO_BORDER="table-no-border",n))(P2||{});const uu=6,Ad=20,yE="table-cell-menu-btn";function IN(n,t){if(!n.isBlockWritable(t))return;const r={...Et.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,r)}function DN(n,t){if(!n.isBlockWritable(t))return;const r={...Et.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,r)}function _N(n,t){if(!n.isBlockWritable(t))return;const r={...Et.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,r)}function MN(n,t){if(!n.isBlockWritable(t))return;const r={...Et.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,r)}function UN(n,t){if(!n.isBlockWritable(t))return;const r={...Et.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,r)}function ON(n,t){if(!n.isBlockWritable(t))return;const r={...Et.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,r)}function NN(n,t,e){if(!n.isBlockWritable(t))return;const i={...Et.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,i)}const os=D("table-cell-dom");function PN(n,t,e){let r=n.getBlockById(e);for(;r;){const i=r.closest("td");p(os,i,"no parent cell");const o=et(i);if(p(os,o,"no parent block"),o===t)return i;r=o}return p(os,!1,"filed to get cell by child block id"),null}function ml(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return p(os,e.childContainerId,"block position must have childContainerId attribute"),e;const i=PN(n,t,e.blockId),o=pt(pd(i));return Ue(t,o)}function TE(n,t){const e=n.selection.range,r=ml(n,t,e.start),i=ml(n,t,e.end);return Si(t,r,i)}function F2(n,t,e,r){p(os,fn(t),"invalid table block");const i=co(n,t),o=ve(t),s=()=>{const c=i.querySelector(".table-border-bar-container.top");p(os,c,"no top border bar container"),c.querySelectorAll(".table-border-bar-cell.top").forEach(h=>{const C=parseInt(h.getAttribute("data-top-index")||"0",10);r.includes(C)?q(h,"danger"):ct(h,"danger")})},l=()=>{const c=o.querySelector(".table-border-bar-container.left");p(os,c,"no left border bar container"),c.querySelectorAll(".table-border-bar-cell.left").forEach(h=>{const C=parseInt(h.getAttribute("data-left-index")||"0",10);e.includes(C)?q(h,"danger"):ct(h,"danger")})};s(),l()}function gl(n,t,e=!0,r){try{const o=Kt.fromBlock(t).map(h=>h),{fromCol:s,toCol:l,fromRow:c,toRow:d}=TE(n,t);for(let h=0;h<o.length;h++){const C=o[h];for(let E=0;E<C.length;E++){const A=C[E],v=r?E>=s&&E+A.colSpan-1<=l:h>=c&&h+A.rowSpan-1<=d;e&&v?A.virtual||q(A.cell,"danger"):A.virtual||ct(A.cell,"danger")}}}catch(i){os.error("update cells danger status failed: ",i.message)}}function pl(n,t,e=!0,r){try{const i=new Set,o=new Set;if(!e){F2(n,t,Array.from(i),Array.from(o));return}const{fromCol:s,toCol:l,fromRow:c,toRow:d}=TE(n,t);if(r)for(let h=s;h<=l;h++)o.add(h);else for(let h=c;h<=d;h++)i.add(h);F2(n,t,Array.from(i),Array.from(o))}catch(i){os.error("update cell bars danger status failed: ",i.message)}}function K2(n,t,e){const{fromCol:r,toCol:i,fromRow:o,toRow:s}=TE(n,t),l=Kt.fromBlock(t);let c=null,d=null;return e?(c=l.getCell({col:r,row:0}),d=l.getCell({col:i,row:l.rowCount-1}),Cn(n,{anchor:Ue(t,c.containerId,{colIndex:r,rowIndex:0}),focus:Ue(t,d.containerId,{colIndex:i,rowIndex:l.rowCount-1})})):(c=l.getCell({col:0,row:o}),d=l.getCell({col:l.colCount-1,row:s}),Cn(n,{anchor:Ue(t,c.containerId,{colIndex:0,rowIndex:o}),focus:Ue(t,d.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}const V2=["style-bg-color-0","style-bg-color-1","style-bg-color-2","style-bg-color-3","style-bg-color-4","style-bg-color-5","style-bg-color-6","style-bg-color-7","style-bg-color-8","style-bg-color-9","style-bg-color-10","style-bg-color-11","style-bg-color-12","style-bg-color-13"];function $2(n){return`style-bg-color-${n}`}function xd(n){return`${n}_background`}function FN(n,t,e){const r=un(n),s=(e!=null?e:Kt.fromTable(r)).getCell(t).cell;for(let l=0;l<V2.length;l++){const c=V2[l];if(Mt(s,c))return c}}function H2(n,t,e){if(!n.isBlockWritable(t))return;const r=n.selection.range,o={...Et.default(n.getBlockData(t))},s=ml(n,t,r.start),l=ml(n,t,r.end);if(r.isSimple()){const c=s.childContainerId;e===-1?o[xd(c)]=void 0:o[xd(c)]=$2(e)}else{const c=Kt.fromBlock(t),d=Si(t,s,l),h=new Set;for(let C=d.fromRow;C<=d.toRow;C++)for(let E=d.fromCol;E<=d.toCol;E++){const A=c.getCell({row:C,col:E});!h.has(A.containerId)&&A.col>=d.fromCol&&A.row>=d.fromRow&&A.col+A.colSpan-1<=d.toCol&&A.row+A.rowSpan-1<=d.toRow&&(h.add(A.containerId),e===-1?o[xd(A.containerId)]=void 0:o[xd(A.containerId)]=$2(e))}}n.updateBlockData(t,o)}function KN(n,t,e){if(!n.isBlockWritable(t))return;const i={...Et.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,i)}const j2=D("table-chart");function VN(n,t){const e=gN(n,t);if(e){const r=e.querySelector(".editor-table-chart");if(r){const i=r.chartObject;i&&i.destroy(),r.remove()}}}function Km(n){var t;return(t=n.textContent)!=null?t:""}async function $N(n,t){if(!n.contains(t)||!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){VN(n,t);return}const i=[],o=Kt.fromBlock(t),s=["line","bar","pie","radar"],l=o.getCell({row:0,col:0}).container;let c=Km(l).trim().toLowerCase();new Set(s).has(c)||(c=s[0]);const d=[];for(let S=1;S<o.colCount;S++)d.push(Km(o.getCell({row:0,col:S}).container));for(let S=1;S<o.rowCount;S++){const U=o.getCell({row:S,col:0}),M=U.container,V=Km(M),nt=[];for(let xe=1;xe<o.colCount;xe++){const fe=Km(o.getCell({row:S,col:xe}).container),Dr=Number.parseFloat(fe)||0;nt.push(Dr)}let Y;const X=FN(t,U,o);X?Y=window.getComputedStyle(n.rootElement).getPropertyValue(`--${X}`).trim():Y=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[ft,xt,bt,wt]=Y?kp.fromString(Y).toRgbaArray():[];if(!ft&&!xt&&!bt&&!wt){const xe=(S-1)%n.options.colors.length;Y=n.options.colors[xe],[ft,xt,bt,wt]=kp.fromString(Y).toRgbaArray()}const Tt=Y,ie=kp.fromRgba([ft,xt,bt,wt/3]).toHexString();i.push({label:V,data:nt,borderColor:Tt,backgroundColor:ie,borderWidth:2})}const h=co(n,t);let C=null,E=h.querySelector(".editor-table-chart");E?C=E.chartObject:E=B("div",["editor-table-chart"],h);const A=E;p(j2,A,"no chart container");const v=n.getComponentOptions("table"),w=(v==null?void 0:v.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await ra(w,"editor-chartjs");let S=!1;(C&&C.config.data.datasets.length>i.length||C&&C.config.data.datasets[0].data.length>i[0].data.length)&&(S=!0),C&&(c!==C.config.type||S)&&(C.destroy(),C=null,Array.from(E.querySelectorAll(".editor-chartjs-canvas")).forEach(V=>{V.remove()}));const U=wp.default({},{type:c,data:{datasets:i,labels:d},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(C)wp.default(C.config,U),C.update();else{const V=B("canvas",["editor-chartjs-canvas"],A).getContext("2d");C=new window.Chart(V,U),E.chartObject=C}}catch(S){j2.error(`failed to resolve chart cdn: ${JSON.stringify(S)}`)}}async function z2(n,t){await gi.lock("updateTableChart");try{await $N(n,t)}finally{gi.release("updateTableChart")}}const G2=Ne.default(z2,1e3);let W2=null;function kE(n,t,e){if(W2!==t&&(G2.flush(),W2=t),e.updateNow){z2(n,t);return}G2(n,t)}function RE(n,t,e){e&&fn(e)&&kE(n,e,{updateNow:!1})}function HN(n,t){fn(t)&&kE(n,t,{updateNow:!0})}const ti={SCROLL:"container-scroll-tool",COMMON:"container-border-shadow",RIGHT:"container-right-border-shadow",LEFT:"container-left-border-shadow",LAYOUT_SIGN:"container-layout-border-shadow",ACTIVE:"active"},Vm={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},Cl={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function bd(n,t){return n.containers.get(t)}function q2(n){return n.closest(`.${Cl.SCROLL_CONTAINER}`)}function Li(n){return n.firstElementChild}function Zn(n){return n.closest(`.${Cl.CONTAINER}`)}function vd(n){const t=Zn(n);let e=t.querySelector(`:scope >.${Cl.TOOL}`);return e||(e=B("div",[Cl.TOOL],t)),e}function jN(n){return Zn(n).firstElementChild}function zN(n,t){const e=bd(n,Zn(t));return e!=null&&e.barFloatWindowBottom?typeof e.barFloatWindowBottom=="function"?e.barFloatWindowBottom():e.barFloatWindowBottom:0}function ei(n,t){const e=jr(n);return t/e}function Bd(n){const t=window.getComputedStyle(n),e=jr(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function fu(n){const t=jr(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function GN(n,t){const e=jr(n);return n[t]*e}function wE(n,t){const e=Zn(t),r=bd(n,e),i=(r==null?void 0:r.safeRightSpace)||0,o=(r==null?void 0:r.safeLeftSpace)||0,l=(r==null?void 0:r.locatingContainer).getBoundingClientRect(),c=e.getBoundingClientRect(),d=c.width;let h=Math.floor(c.left-l.left-o);h<0&&(h=0);let C=l.right;C-=i;let E=C-c.right;return E<0&&(E=0),h=Math.round(h),E=Math.round(E),{originWidth:d,maxLeft:h,maxRight:E}}function WN(n,t){const e=wE(n,t),{maxLeft:r}=e;t.style.marginLeft=`${ei(t,0-r)}px`,t.style.paddingLeft=`${ei(t,r)}px`}function qN(n,t){const e=wE(n,t);t.style.marginRight=`${ei(t,0-e.maxRight)}px`}function XN(n){if(n!==document.documentElement&&n!==document.body)return n.getBoundingClientRect();const t=0,e=0,r=document.documentElement.clientWidth,i=document.documentElement.clientHeight;return new DOMRect(t,e,r,i)}const X2=D("scroll-bar-handle"),YN=2;function du(n){const t=vd(n);let e=t.querySelector(`.${Vm.SCROLL_BAR}`);return e||(e=B("div",[Vm.SCROLL_BAR],t),me.isWindows&&me.isFirefox&&(e.style.minHeight="10px")),p(X2,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||B("div",[],e),e}function $m(n,t){const e=q2(t),r=du(e),{scrollWidth:i,clientWidth:o}=fu(e),{paddingLeft:s,paddingRight:l}=Bd(t),c=wE(n,e),{originWidth:d,maxRight:h}=c;qN(n,e),WN(n,e);const C=i-o;p(X2,r.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),r.style.width=`${ei(e,d+h-s-l)}px`,r.firstElementChild.style.width=`${ei(e,d+h+C-s-l)}px`}function QN(n,t){const e=Li(n),{paddingLeft:r}=Bd(e);if(Mt(t,"fixed")){const o=Zn(n).getBoundingClientRect();t.style.left=`${ei(n,o.left+r)}px`}else t.style.left=`${ei(n,r)}px`}function hu(n,t){var M;const e=n.getParentScrollContainer(),r=XN(e),i=t.getBoundingClientRect(),o=du(t),s=o.getBoundingClientRect(),l=bd(n,Zn(t)),c=zN(n,t),d=Li(t),{paddingTop:h,paddingBottom:C}=Bd(d),{scrollWidth:E,clientWidth:A}=fu(t),v=document.documentElement.clientHeight-c,w=r.top+fu(e).clientHeight-v,S=v+Math.min(0,w);if(E>A&&i.top+h<S-s.height&&i.bottom>S-s.height+C&&!((M=l==null?void 0:l.isSetScale)!=null&&M.call(l))){l!=null&&l.allowScrollBarFixed&&q(o,Vm.FIXED);const V=w>0?c:0;o.style.bottom=`${Math.max(document.documentElement.clientHeight-r.bottom,0)+YN+V}px`}else ct(o,Vm.FIXED),o.style.bottom=`${ei(t,C-s.height)}px`;QN(t,o)}class JN{constructor(t,e){m(this,"intersectionObserver");m(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Zn(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});m(this,"handleIntersectionEntry",t=>{const e=t.target;hu(this.scrollCore,e);const r=Li(e);$m(this.scrollCore,r)});this.scrollCore=t,this.callback=e;const i={root:this.scrollCore.getParentScrollContainer(),rootMargin:"20px",threshold:0};this.intersectionObserver=new IntersectionObserver(this.handleIntersection,i)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.intersectionObserver.observe(t)}unbind(t){this.intersectionObserver.unobserve(t)}destroy(){this.intersectionObserver.disconnect()}}const Ta=D("container-scroll-shadow");function Y2(n,t,e){const r=n,i=t.getBoundingClientRect(),o=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=Bd(e);r.style.top=`${ei(t,o.top-i.top+s)}px`,r.style.bottom=`${ei(t,i.bottom-o.bottom+l)}px`}function Q2(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function ZN(n){const t=vd(n);p(Ta,t,"no container tools");let e=t.querySelector(`.${ti.LEFT}`);if(!e){const l=Li(n),c=[ti.COMMON,ti.LEFT];e=B("div",c,t),p(Ta,e instanceof HTMLDivElement,"invalid child for container tools"),Y2(e,n,l)}p(Ta,e instanceof HTMLElement,"invalid child for container tools");const i=Zn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.left=`${ei(n,o.left-i.left)}px`;const s=fu(n).scrollLeft;p(Ta,e instanceof HTMLDivElement,"invalid child for container tools"),Q2(e,s),q(e,ti.ACTIVE)}function tP(n){const t=vd(n);let e=t.querySelector(`.${ti.RIGHT}`);if(!e){const h=Li(n),C=[ti.COMMON,ti.RIGHT];e=B("div",C,t),p(Ta,e instanceof HTMLDivElement,"no div, create shadow failed"),Y2(e,n,h)}p(Ta,e instanceof HTMLElement,"");const i=Zn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.right=`${ei(n,i.right-o.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=fu(n),d=s-l-c;p(Ta,e instanceof HTMLDivElement,"no shadow element"),Q2(e,d),q(e,ti.ACTIVE)}function eP(n){const e=vd(n).querySelector(`.${ti.LEFT}`);e&&ct(e,ti.ACTIVE)}function nP(n){const e=vd(n).querySelector(`.${ti.RIGHT}`);e&&ct(e,ti.ACTIVE)}function yd(n){const{scrollLeft:t,scrollWidth:e,clientWidth:r}=fu(n),i=Li(n),{paddingLeft:o,paddingRight:s}=Bd(i),l=GN(i,"offsetLeft");e-o<=r-s||e-o<=t+r-s?nP(n):tP(n),i&&t>=l+o?ZN(n):eP(n)}class rP{constructor(t,e){m(this,"resizeObserver");m(this,"handleResizeEntry",t=>{const e=t.target,r=Li(e);yd(e),$m(this.scrollCore,r),hu(this.scrollCore,e),this.callback(e)});m(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Zn(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new Zl(this.handleContentResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}const J2=D("container-scroll-observer");class iP{constructor(t,e){m(this,"handleContentScroll",t=>{const e=t.target;p(J2,e instanceof Element,"invalid target for scroll event");const r=du(e);r.removeEventListener("scroll",this.handleScroll);const i=!0;this.fixScrollXPos(e,e.scrollLeft,i),this.bind(r),yd(e),this.callback(e)});m(this,"handleScroll",t=>{const e=t.target;p(J2,e instanceof HTMLElement,"");const r=e.scrollLeft,i=!1,o=jN(e);this.unbindContentScroll(o),this.fixScrollXPos(o,r,i),this.bindContentScroll(o),yd(o),this.callback(o)});m(this,"handlePrevent",t=>{t.stopPropagation()});m(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});m(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});m(this,"bindContentScroll",Ne.default(this.bindContentScrollCore,300));m(this,"bind",Ne.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,r){const i=du(t);r||(t.scrollLeft=e),r&&i.scrollLeft!==e&&(i.scrollLeft=e)}bindCore(t){this.unbind(t),t.addEventListener("scroll",this.handleScroll),t.addEventListener("mousedown",this.handlePrevent)}unbind(t){t.removeEventListener("scroll",this.handleScroll),t.removeEventListener("mousedown",this.handlePrevent)}}class oP{constructor(t){m(this,"scrollContainers",new Set);m(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{hu(this.scrollCore,t)})});m(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});m(this,"unbindScrollContainer",t=>{let e=!1;this.scrollContainers.has(t)&&(this.scrollContainers.delete(t),e=this.scrollContainers.size===0),e&&this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll)});this.scrollCore=t}get eventTarget(){const t=this.scrollCore.getParentScrollContainer();return t===document.documentElement?document:t}destroy(){this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll),this.scrollContainers.clear()}}const sP=D("scroll-wrap-resize-observer");class lP{constructor(t){m(this,"resizeObserver");m(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Zn(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});m(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;p(sP,e instanceof HTMLElement,"invalid target for observer entry");const r=q2(e);$m(this.scrollCore,e),yd(r),hu(this.scrollCore,r)});this.scrollCore=t,this.resizeObserver=new Zl(this.handleScrollWrapResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}class aP{constructor(t,e){m(this,"resizeObserver");m(this,"scrollContainersMap",new Map);m(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const r=Li(e);yd(e),$m(this.scrollCore,r),hu(this.scrollCore,e),this.callback(e)})});m(this,"handleResize",t=>{t.forEach(e=>{const r=this.scrollContainersMap.get(e.target);r!=null&&r.length&&this.handleResizeEntry(r)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new Zl(this.handleResize)}bind(t){var i,o;const e=Zn(t),r=(i=bd(this.scrollCore,e))==null?void 0:i.locatingContainer;this.scrollContainersMap.has(r)?(o=this.scrollContainersMap.get(r))==null||o.push(t):(this.scrollContainersMap.set(r,[t]),this.resizeObserver.observe(r))}unbind(t){var o,s;const e=Zn(t),r=(o=bd(this.scrollCore,e))==null?void 0:o.locatingContainer;if(!r)return;const i=this.scrollContainersMap.get(r);this.scrollContainersMap.set(r,(i==null?void 0:i.filter(l=>l!==t))||[]),(s=this.scrollContainersMap.get(r))!=null&&s.length||(this.resizeObserver.unobserve(r),this.scrollContainersMap.delete(r))}destroy(){this.scrollContainersMap.clear(),this.resizeObserver.disconnect()}}const oat="";class cP extends Ve.TypedEmitter{constructor(e){super();m(this,"containerIntersectionObserver",null);m(this,"containerResizeObserver",null);m(this,"containerScrollObserver",null);m(this,"parentContainerScrollObserver",null);m(this,"scrollWrapResizeObserve",null);m(this,"locatingContainerResizeObserver",null);m(this,"isWindowEventBind",!1);m(this,"containers",new Map);m(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});m(this,"handleResize",e=>{this.emit("resize",this,e)});m(this,"handleIntersection",e=>{const r=e.target,i=Li(r);e.isIntersecting?(this.load(),this.bindCore(r,i)):this.unbindCore(r,i)});m(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(r=>{hu(this,r)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new rP(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new iP(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new oP(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new lP(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new aP(this,this.handleResize)),this.isWindowEventBind||(window.addEventListener("resize",this.handleWindowEffect),this.getParentScrollContainer()!==document.documentElement&&window.addEventListener("scroll",this.handleWindowEffect))}getParentScrollContainer(){return this.parentContainer}getScrollContainerInViewable(){var e;return(e=this.parentContainerScrollObserver)==null?void 0:e.scrollContainers}unbindCore(e,r){var o,s,l,c,d,h;const i=du(e);(o=this.containerScrollObserver)==null||o.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(i),(l=this.scrollWrapResizeObserve)==null||l.unbind(r),(c=this.containerResizeObserver)==null||c.unbind(e),(d=this.parentContainerScrollObserver)==null||d.unbindScrollContainer(e),(h=this.locatingContainerResizeObserver)==null||h.unbind(e)}bindCore(e,r){var s,l,c,d,h,C;if(this.unbindCore(e,r),!e.closest("body"))return;const i=du(e);(s=this.containerScrollObserver)==null||s.bindContentScrollCore(e),(l=this.containerScrollObserver)==null||l.bindCore(i),(c=this.scrollWrapResizeObserve)==null||c.bind(r),(d=this.containerResizeObserver)==null||d.bind(e);const o=this.containers.get(Zn(e));o!=null&&o.allowScrollBarFixed&&((h=this.parentContainerScrollObserver)==null||h.bindScrollContainer(e)),(C=this.locatingContainerResizeObserver)==null||C.bind(e)}bind(e,r){this.containers.set(e,r);const i=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new JN(this,this.handleIntersection)),this.containerIntersectionObserver.bind(i)}unbind(e){var o;const r=e.firstElementChild,i=Li(r);this.unbindCore(r,i),this.containers.delete(e),(o=this.containerIntersectionObserver)==null||o.unbind(r),this.containers.size||this.destroy()}destroy(){var e,r,i,o,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(r=this.containerIntersectionObserver)==null||r.destroy(),(i=this.containerResizeObserver)==null||i.destroy(),(o=this.scrollWrapResizeObserve)==null||o.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const Z2=D("scroll-container"),Hm=new Map;class uP extends Ve.TypedEmitter{constructor(){super(...arguments);m(this,"scrollListener");m(this,"options");m(this,"scrollContainerElement");m(this,"init",e=>{this.options=e;const r=B("div",[Cl.CONTAINER],e.parentElement);me.isMac&&q(r,Cl.MAC);const i=B("div",[Cl.SCROLL_CONTAINER],r),o=B("div",[Cl.SCROLL_AREA],i);o.style.paddingLeft=e.paddingLeft?`${e.paddingLeft}px`:"",o.style.paddingTop=e.paddingTop?`${e.paddingTop}px`:"",o.style.paddingBottom=e.paddingBottom?`${e.paddingBottom}px`:"",o.style.paddingRight=e.paddingRight?`${e.paddingRight}px`:"",o.appendChild(e.childElement);const s=e.parentContainer;this.scrollListener=Hm.get(s),this.scrollListener||(this.scrollListener=new cP(s),Hm.set(s,this.scrollListener)),this.scrollListener.unbind(r),this.scrollListener.bind(r,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollListener.on("resize",this.handleResize),this.scrollContainerElement=i});m(this,"handleContainerScroll",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)});m(this,"handleResize",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return p(Z2,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),Li(this.scrollContainerElement)}get scrollOptions(){return p(Z2,this.options,"options cannot be undefined"),{...this.options}}handleBaseListenerDestroy(e){e.destroy()}destroy(){var r;(r=this.scrollListener)==null||r.off("scroll",this.handleContainerScroll);const e=Zn(this.contentElement);e&&Hm.forEach((i,o)=>{i.unbind(e),i.containers.size===0&&(this.handleBaseListenerDestroy(i),Hm.delete(o))})}}function fP(){return new uP}const SE=D("column-width");function dP(n,t,e){const r=CN(n,t);r.style.width=`${e}px`,r.style.minWidth=`${e}px`}function hP(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const r=Kt.fromTable(n),i=Array(r.colCount).fill(-1),o=n.getBoundingClientRect().left;r.toRealCells(r.cells).forEach(c=>{const d=c.col+c.colSpan-1;i[d]===-1&&(i[d]=c.cell.getBoundingClientRect().right-o)}),SE.debug(`cellRightOffsets1: ${i.join()}`);for(let c=0;c<i.length;c++){const d=i[c];if(d===-1||c===0)continue;let h=c-1;for(;i[h]===-1&&(h--,h!==-1););const C=h===-1?0:i[h],A=(d-C)/(c-h);for(let v=h+1;v<c;v++)i[v]=C+A*(v-h)}SE.debug(`cellRightOffsets2: ${i.join()}`);const s=[];let l=0;for(let c=0;c<i.length;c++){const d=i[c];s.push(d-l),l=d}return SE.debug(`widths: ${s.join()}`),s}function Td(n){return Array.from(n.querySelector("colgroup").children).map(r=>r.getBoundingClientRect().width||Number.parseInt(r.style.width,10))}const LE=200,mP=40,gP=D("table-resize-gripper"),tk=7,IE=(tk-1)/2,pP=3;function CP(n,t,e){const{rows:r}=n;for(let i=0;i<r.length;i++){const o=r[i],s=Array.from(o.cells);for(let l=0;l<s.length;l++){const c=s[l],d=c.getBoundingClientRect(),h=Math.round(d.right);if(Math.abs(t-h)<=IE&&d.top<=e&&e<=d.bottom)return c}}return null}function EP(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function DE(n,t){return co(n,t).querySelector(".table-resize-gripper")}function ek(n,t){const e=DE(n,t);p(gP,!e,"resize gripper has already exists");const r=co(n,t),i=B("div",["table-resize-gripper","table-indicator"],r);return B("div",["table-resize-gripper-indicator"],i),i}function nk(n,t,e){let r=DE(n,t);r||(r=ek(n,t));const o=un(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=o.height,d=n.getCustom(ao(t)).contentElement.getBoundingClientRect(),h=s.right-d.left;r.style.left=`${h-IE-uu-Ad}px`,r.style.top=`${l}px`,r.style.height=`${c}px`,r.style.width=`${tk}px`}function _E(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function AP(n,t,e){const i={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,i,void 0,{noScroll:!0})}function xP(n,t,e,r){const i=t,o=Kt.fromTable(e),s=o.getCellByCellElement(i),l=s.col+s.colSpan-1,c=Td(e);let d=r;const h=(E,A)=>{const v=A+1,w=E.col+E.colSpan;return c.slice(v,w).reduce((U,M)=>U+M,0)},C=new Set;for(let E=0;E<o.rowCount;E++){const A=o.getCell({row:E,col:l});if(C.has(A.cell))continue;C.add(A.cell);const v=A.cell,w=v.getBoundingClientRect();let S=r-w.left+IE-pP;const U=pd(v),M=m1(n,U)||mP*A.colSpan,V=h(A,l),nt=M-V;S<nt&&(S=nt);const Y=w.left+S;d=Math.max(d,Y)}return d}const bP=D("table-resize-drag-drop");class vP{constructor(t,e,r,i){m(this,"cursor","col-resize");this.editor=t,this.elem=e,this.data=r,this.onEnd=i}onDragStart(t,e,r){}onDragging(t,e,r,i,o){const{table:s,block:l,draggingRefCell:c}=t.data,h=xP(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;p(bP,c,"no dragging cell");const E=Kt.fromTable(s).getCellByCellElement(c),A=E.col+E.colSpan-1,v=Td(s),w=v.slice(0,A).reduce((U,M)=>U+M,0),S=h-w;if(dP(s,A,S),S){const U=parseFloat(s.style.minWidth);s.style.minWidth=`${U+(S-v[A])}px`}nk(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,r,i,o){const s=Td(t.data.table);AP(this.editor,t.data.block,s),_E(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function BP(n,t){const e=Pe(t.x,t.y);if(!e)return null;const r=et(e);return!r||!n.contains(r)||!fn(r)?null:r}D("table-resize");class yP{constructor(t){m(this,"draggingRefCell",null);m(this,"handleMouseMove",(t,e)=>{if(t.readonly||window.isDragging||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const r=e.target;if(!(r instanceof Element))return;const i=et(r);if(!i||Ot(i)!=="table"||r.closest(".table-indicator"))return;const s=e,l=BP(t,s);if(!l||!I2(l)||!t.isBlockWritable(l)){_E(t);return}this.updateGripper(l,s.x,s.y)});this.editor=t,t.domEvents.addEventListener(document,"mousemove",this.handleMouseMove)}destroy(){this.editor.domEvents.removeEventListener(document,"mousemove",this.handleMouseMove)}updateGripper(t,e,r){const i=un(t),o=CP(i,e,r);if(o){if(!DE(this.editor,t)){if(EP(this.editor))return;const l=ek(this.editor,t),c={block:t,table:i,draggingRefCell:o};Pp(new vP(this.editor,l,c,d=>{this.updateGripper(t,d.x,d.y)}))}nk(this.editor,t,o)}else _E(this.editor)}}function rk(n){n.addCustom("table-mouse-event-handler",t=>new yP(t))}const ik=D("table-insert-column");function ok(n,t,e){n.undoManager.runInGroup(()=>{var E;const r=un(t),i=Kt.fromTable(r),o=i.colCount;p(ik,e>=0&&e<=o,`insert index ${e} is out of range [0, ${o}]`);const s=i.map(A=>A.containerId),l=new Set;n.doc.beginBatchUpdate();for(let A=0;A<s.length;A++){const v=s[A],w=v[e-1],S=v[e];if(e===0||e===v.length||w!==S){const U=Yo(n.doc);v.splice(e,0,U)}else v.splice(e,0,w),l.add(w)}n.doc.endBatchUpdate();const c=Et.default(n.getBlockData(t));l.forEach(A=>{const v=`${A}_colSpan`,w=c[v];p(ik,typeof w=="number"&&w>1,`no colSpan for containerId ${A}, ${w}`),c[v]=w+1});const d=((E=c.colsWidth)==null?void 0:E.concat())||new Array(c.cols).fill(0);d.splice(e,0,LE);const h=Kt.virtualCellContainersGridToChildren(s),C={...c,cols:c.cols+1,children:h,colsWidth:d};ya(C),n.updateBlockData(t,C)})}const jm=D("table-insert-row");function ME(n,t,e){n.undoManager.runInGroup(()=>{const r=un(t),i=Kt.fromTable(r),o=i.rowCount;p(jm,e>=0&&e<=o,`insert index ${e} is out of range [0, ${o}]`);const s=i.map(E=>E.containerId),l=new Set;n.doc.beginBatchUpdate();const c=[];for(let E=0;E<i.colCount;E++){const A=e>0&&s[e-1][E],v=e<i.rowCount&&s[e][E];if(p(jm,A||v,"no top and bottom cell"),e===0||e===i.rowCount||A!==v){const w=Yo(n.doc);c.push(w)}else p(jm,A,"no top cell"),c.push(A),l.add(A)}n.doc.endBatchUpdate(),s.splice(e,0,c);const d=Et.default(n.getBlockData(t));l.forEach(E=>{const A=`${E}_rowSpan`,v=d[A];p(jm,typeof v=="number"&&v>1,`no rowSpan for containerId ${E}, ${v}`),d[A]=v+1});const h=Kt.virtualCellContainersGridToChildren(s),C={...d,rows:d.rows+1,children:h};ya(C),n.updateBlockData(t,C)})}const UE=D("paste-table-in-table-block");function TP(n,t,e,r,i){let o=Kt.fromBlock(e);const s=t.blocks.root[0];p(UE,s,"no table data"),p(UE,s.type==="table",`table data type is not table, but ${s.type}`);const l=s,c=o.getCellByCellElement(r),d=l.cols,h=l.rows,C=c.col,E=c.row,A=C+d,v=E+h,w=[];for(let S=C;S<A&&S<o.colCount;S++)for(let U=E;U<v&&U<o.rowCount;U++){const M=o.getCell({col:S,row:U});M.virtual?M.virtual&&w.push({col:S,row:U}):(M.colSpan>1||M.rowSpan>1)&&w.push({col:S,row:U})}n.undoManager.runInGroup(()=>{if(n.doc.beginBatchUpdate(),w.forEach(V=>{const nt=Kt.fromBlock(e).getCell(V);(nt.colSpan>1||nt.rowSpan>1)&&bE(n,e,V)}),A>o.colCount)for(let V=o.colCount;V<A;V++)ok(n,e,V);if(v>o.rowCount)for(let V=o.rowCount;V<v;V++)ME(n,e,V);o=Kt.fromBlock(e);const S=new Um(l);let U;for(let V=0;V<S.colCount;V++)for(let nt=0;nt<S.rowCount;nt++){const Y=S.getCell({col:V,row:nt});if(!Y.virtual){const X=oC(n.editorBlocks,t,Y.containerId,i),ft=C+V,xt=E+nt,bt={col:ft,row:xt},wt=o.getCellContainer(bt);n5(n,wt,X,i),U=wt}}n.doc.endBatchUpdate(),p(UE,U,"no last container");const M=Ge(U);n.selection.selectBlock(M,Ct(n,M))})}const OE=D("paste-in-table-block");class kP{constructor(t){m(this,"pasteData");this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){this.pasteData=void 0}async handleBeforePaste(t,e,r,i){return this.pasteData={doc:r,files:i,event:e},!1}async handleBeforePasteDoc(t,e){var E,A,v,w;if(!t.selection.range.isSimple())return this.pasteData=void 0,!1;if(t.selection.range.start.offset!==0)return this.pasteData=void 0,!1;const i=t.selection.startBlock,o=at(i);if(re(o))return this.pasteData=void 0,!1;if(!Uf(t,o))return this.pasteData=void 0,!1;const s=et(o);if(p(OE,s,"no parent block"),!fn(s))return this.pasteData=void 0,!1;if(e.blocks.root.length!==1)return this.pasteData=void 0,!1;if(e.blocks.root[0].type!=="table")return this.pasteData=void 0,!1;OE.debug("paste child table in table");const d=Kt.fromBlock(s).getCellByContainerId(pt(o)).cell;yC(t,e);const h={blockIdMap:new Map,containerIdMap:new Map,boxIdMap:new Map};TP(t,e,s,d,h),p(OE,this.pasteData,"invalid paste data");const C=[];t.input.forEach(S=>{C.push(S)});for(let S=0;S<C.length&&!await((A=(E=C[S]).handleAfterPasteDoc)==null?void 0:A.call(E,t,e,h));S++);for(let S=0;S<C.length&&!await((w=(v=C[S]).handleAfterPaste)==null?void 0:w.call(v,t,this.pasteData.event,this.pasteData.doc));S++);return this.pasteData=void 0,!0}}function sk(n){n.addCustom("table-block-paste-event",t=>new kP(t))}const NE=D("table-select-columns");function RP(n,t,e,r,i){p(NE,fn(t),"is not a table block");const o=Kt.fromBlock(t);p(NE,e>=0&&e<o.colCount,"invalid from"),p(NE,r>0&&e+r<=o.colCount,"invalid count");const s=o.getCell({row:0,col:e}),l=o.getCell({row:o.rowCount-1,col:e+r-1}),c=Ue(t,s.containerId,{colIndex:e,rowIndex:0}),d=Ue(t,l.containerId,{colIndex:e+r-1,rowIndex:o.rowCount-1});i!=null&&i.reverse?n.selection.setSelection(d,c):n.selection.setSelection(c,d)}const PE=D("table-select-columns");function wP(n,t,e,r,i){p(PE,fn(t),"is not a table block");const o=Kt.fromBlock(t);p(PE,e>=0&&e<o.rowCount,"invalid from"),p(PE,r>0&&e+r<=o.rowCount,"invalid count");const s=o.getCell({row:e,col:0}),l=o.getCell({row:e+r-1,col:o.colCount-1}),c=Ue(t,s.containerId,{rowIndex:e,colIndex:0}),d=Ue(t,l.containerId,{rowIndex:e+r-1,colIndex:o.colCount-1});i!=null&&i.reverse?n.selection.setSelection(d,c):n.selection.setSelection(c,d)}const sat="",lk=D("get-toolbar-reference-client");function ak(n,t){const e=n.selection.range;if(!e.isSimple()){p(lk,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);p(lk,Pt(n,s),"not a complex block");const l=le(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const r=e.isReverse()?t.start:t.end,i=Cn(n,{anchor:r,focus:r}),o=Vo(n,t.block,i);if(o.length!==0)return o[0]}function SP(n){var t,e;if(n.children){let r=!1;const i=[];for(const o of n.children){if((t=o.states)!=null&&t.includes("checked")){r=!0;break}(e=n.defaultCheckedChildren)!=null&&e.includes(o.id)&&i.push(o)}if(!r&&(i==null?void 0:i.length))for(const o of i)Array.isArray(o.states)?o.states.push("checked"):o.states=["checked"]}}function zm(n){const t=(i,o)=>{const s=i.findIndex(c=>c.id===o.id);if(s===-1){i.push(o);return}const l=i[s];if(l.value!==o.value&&delete l.value,!!l.states){if(!o.states){l.states=[];return}l.states=Lp.default(l.states,o.states)}},e=[],r=new Map;return n.forEach(i=>{var o,s;(o=i.children)!=null&&o.length&&(r.has(i.id)?(s=r.get(i.id))==null||s.push(...i.children):r.set(i.id,[...i.children])),t(e,i)}),r.forEach((i,o)=>{const s=e.find(l=>l.id===o);s&&(s.children=zm(i),SP(s))}),e}function Gm(n){return n.findCustom("toolbar-handler")}const lat="";class LP{constructor(){m(this,"linkPopup",null);m(this,"form",{});m(this,"onFinished",null);m(this,"onClose",null);m(this,"onBeforeFormatUrl",null);m(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:r}=this.form,i=r.getInputValue();let o="";this.onBeforeFormatUrl&&this.onBeforeFormatUrl(i)!==!1?o=this.onBeforeFormatUrl(i):o=this.formatUrl(i),(t=this.onFinished)==null||t.call(this,e.getInputValue()||o,o),this._destroy()}catch{}});m(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});m(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});m(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector('[data-button-id="submit-button"]');t.disabled=!1});m(this,"handleTextKeyboard",(t,e)=>{var r;if(!e){if(t.key==="Enter"){(r=this.form.linkUrl)==null||r.getField().focus(),t.stopPropagation();return}t.key==="Escape"&&this.handleClose()}});m(this,"handleUrlKeyboard",(t,e)=>{if(!e){if(t.key==="Enter"){this.handleOk(),t.preventDefault();return}t.key==="Escape"&&this.handleClose()}})}async checkValue(){const{linkUrl:t}=this.form;if(!t.getInputValue())throw t.setFieldError(_.t("link.urlPlaceholder")),new Error(_.t("link.urlPlaceholder"))}formatUrl(t){if(!t)return"";try{new URL(t)}catch{return`${window.location.protocol}//${t}`}return t}editLink(t){var C,E;const{target:e,linkText:r,linkUrl:i,onFinished:o,onClose:s,onBeforeFormatUrl:l,placement:c="bottom-start"}=t;this.linkPopup=new su(this.createPopupContent(r,i)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:c}),this.onFinished=o,s&&(this.onClose=s),l&&(this.onBeforeFormatUrl=l);const d=(C=this.linkPopup)==null?void 0:C.content.querySelector('[data-button-id="submit-button"]'),h=(E=this.linkPopup)==null?void 0:E.content.querySelector('[data-button-id="cancel-button"]');d==null||d.addEventListener("click",this.handleOk),h==null||h.addEventListener("click",this.handleClose)}createPopupContent(t,e){const r=B("div",["link-popup-content"],null);this.form.linkText=Mm(r,{label:_.t("link.textLabel"),required:!1,placeholder:_.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Mm(r,{className:"link-popup-gap",label:_.t("link.urlLabel"),required:!0,placeholder:_.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const i=B("div",["link-popup-footer"],r),o=Zr("cancel-button",_.t("link.cancelText"));i.appendChild(o);const s=Zr("submit-button",_.t("link.submitText"),void 0,["disabled","primary"]);return i.appendChild(s),r}_destroy(){var r,i,o,s;const t=(r=this.linkPopup)==null?void 0:r.content.querySelector('[data-button-id="submit-button"]'),e=(i=this.linkPopup)==null?void 0:i.content.querySelector('[data-button-id="cancel-button"]');t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(o=this.linkPopup)==null||o.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function kd(n,t){const e=n.addCustom("link-editor",()=>new LP),r=n.getComponentOptions("link"),i={...t,...r};e.editLink(i)}const IP=D("link-popup");function DP(n){return Mt(n,"link")}function Rd(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function _P(n,t,e){var i,o,s,l;if(n.isBlockWritable(t)&&e&&Tr(e)){const c=e,d=(o=(i=n.editorBoxes.getBoxClass(Lf(c))).getBoxProperties)==null?void 0:o.call(i,n,c);if(d!=null&&d.boxCommands){const h=(l=(s=d.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[];return{element:e,commands:h}}return{element:null,commands:[]}}if(n.isWritable()&&e&&st(n,t)&&DP(e)){const c=B("a",["link-href-button"],null,Rd(e));c.href=Rd(e),c.target="_blank",c.rel="noopener noreferrer";const d=[{id:"link-text",name:Rd(e),disableTooltip:!0,element:c},{id:"edit-link",name:_.t("link.edit"),icon:Im},{id:"remove-link",name:_.t("link.remove"),icon:DT}];return{element:e,commands:d}}return qv(n,t,"hovering-toolbar")}function ck(n,t,e){var l;const r=rl(t,e),i=n.getBlockText(t),o={start:0,end:0};let s=(l=e.textContent)!=null?l:"";for(let c=0;c<i.length;c++){const d=i[c];if(o.end+d.insert.length>=r.end){o.end+=d.insert.length,s=d.insert;break}o.start<r.start&&(o.start+=d.insert.length,o.end=o.start)}return[o,s]}function MP(n,t,e){const[r,i]=ck(n,t,e);n.selection.selectBlock(t,r.start,r.end);const o=Rd(e),s=(h,C)=>{try{const E=n.getBlockText(t),A=F1(E,r.start,r.end-r.start),v=qo(A,r.start,h,{link:C});n.setBlockText(t,v),n.selection.selectBlock(t,r.start+h.length),n.focus()}catch(E){IP.error(E)}},l=()=>{n.selection.selectBlock(t,r.end),n.focus()},c=Vo(n,t,n.selection.range)[0];if(!c)return;const d=jo(n,t,"link-button-anchor",c);kd(n,{target:d,linkText:i,linkUrl:o,onFinished:s,onClose:l})}function UP(n,t,e){const[r]=ck(n,t,e),i=n.getBlockText(t),o=Rd(e),s=$c(r.start,r.end-r.start,i,"link",o);n.setBlockText(t,s),n.selection.selectBlock(t,r.end)}function OP(n,t,e,r){var s,l,c;if(e){if(n.isBlockWritable(t)&&Tr(e)){const h=e,C=(l=(s=n.editorBoxes.getBoxClass(Lf(h))).getBoxProperties)==null?void 0:l.call(s,n,h);if(C!=null&&C.boxCommands){C.boxCommands["hovering-toolbar"].executeCommand(n,t,h,r);return}return}const d=Gm(n);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},400),r.id==="edit-link"?MP(n,t,e):r.id==="remove-link"&&UP(n,t,e);return}const i=Wv(n,t);if(!i)return;const o=(c=i.blockCommands)==null?void 0:c["hovering-toolbar"];!o||o.executeCommand(n,t,r)}function Wm(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}function ni(n){const e=n.selection.range;if(e.isCollapsed()||e.start.blockId!==e.end.blockId||!e.start.isSimple()||!e.end.isSimple()||e.end.offset-e.start.offset!==1)return!1;const r=n.getBlockById(e.start.blockId);return!(!st(n,r)||Vf(n,r,e.start.offset).charType!=="box")}const NP=[bm,vm,Bm,ym,Tm,km,Rm,wm];class PP{constructor(t){m(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=Wm();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,r){if(!st(t,e))return[];if(ni(t))return[];const i=ut(e),o=Ot(e),s=Ei(t,e),c=t.getBlockData(e).heading,d=[];for(let C=0;C<this.getHeadingIndex();C++)d.push({id:`heading-${C+1}`,name:_.t("commands.heading",{name:`${C+1}`}),icon:NP[C],states:c===C+1?["checked"]:[],value:`${C+1}`});const h=C=>{var A;const E=B("span",["toolbar-item-name-container"],null);for(const v of C.children)if((A=v.states)!=null&&A.includes("checked"))return E.innerHTML=v.icon||iu,E;return E.innerHTML=iu,E};return[{id:"turn-into",name:_.t("commands.headingGroup"),blockId:i,blockType:o,blockKind:s,element:h,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:_.t("commands.text"),icon:iu,states:c?[]:["checked"]},...d],childrenType:"menu"}]}applyHeadingStyle(t,e,r){t.updateBlockData(e,{heading:r})}executeCommand(t,e,r,i){if(ni(t))return!1;if(st(t,e)&&(i.id.startsWith("heading-")||i.id==="text")){const o=i.value?Number(i.value):null;return this.applyHeadingStyle(t,e,o),!0}return!1}}const FP=8,We=D("list-block"),qm=D("list-block");function Ht(n){return Ot(n)==="list"}function en(n){p(qm,Ht(n),"not a list block")}function Sr(n){en(n);const t=n.getAttribute("data-list-type");return p(qm,t,"no list type"),t}function Xm(n){return Ht(n)&&Sr(n)==="text-only"}function Lr(n){var t,e;return en(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function Mn(n){var t,e;return en(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function mu(n){en(n);const t=n.getAttribute("data-list-group-id");return p(qm,t,"no group id"),t}function uo(n){var o,s,l,c,d;en(n);const t=(o=n.getAttribute("data-list-type"))!=null?o:"ordered",e=(l=Number.parseInt((s=n.getAttribute("data-list-start"))!=null?s:"1",10))!=null?l:1,r=(d=Number.parseInt((c=n.getAttribute("data-list-level"))!=null?c:"1",10))!=null?d:1,i=n.getAttribute("data-list-group-id");return p(qm,i,"no group id"),{type:t,start:e,level:r,groupId:i}}function Ym(n){switch(n){case"ordered":return{ordered:!0,checkbox:null,textOnly:null};case"unordered":return{ordered:!1,checkbox:null,textOnly:null};case"checked":return{checkbox:"checked",ordered:!1,textOnly:null};case"unchecked":return{checkbox:"unchecked",ordered:!1,textOnly:null};case"text-only":return{checkbox:null,ordered:!1,textOnly:!0};default:return{checkbox:null,ordered:!0,textOnly:!1}}}function KP(n){const t={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};let e="",r=n;return Object.entries(t).forEach(([i,o])=>{for(;r>=o;)e+=i,r-=o}),e.toLowerCase()}const VP="abcdefghijklmnopqrstuvwxyz";function uk(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),r=VP[t];return e?uk(e)+r:r}function $P(n){return`${n}`}const fk=[$P,uk,KP];function HP(n,t){const e=fk[(n-1)%fk.length];return e(t)}function jP(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}function El(n,t){en(n);const{level:e,groupId:r,type:i}=uo(n);let o=He(n);for(;o;){if(!Ht(o)){o=He(o);continue}const{level:s,groupId:l,type:c}=uo(o);if(s<e)return null;if(e===s&&((t==null?void 0:t.ignoreGroupId)||r===l)&&(c==="text-only"||i==="text-only"||i===c))return o;o=He(o)}return null}function dk(n){return El(n,{ignoreGroupId:!0})}function ka(n){en(n);const{level:t,groupId:e,type:r}=uo(n);let i=ae(n);for(;i;){if(Ht(i)){const{level:o,groupId:s,type:l}=uo(i);if(t===o&&e===s&&(l==="text-only"||r==="text-only"||r===l))return i;if(o<t)return null}i=ae(i)}return null}function hk(n){en(n);const t=[];let e=El(n);for(;e;)t.unshift(e),e=El(e);return t}function gu(n){en(n);const t=[];let e=ka(n);for(;e;)t.push(e),e=ka(e);return t}function wd(n){en(n);let t=El(n);for(;t;){const e=El(t);if(!e)return t;t=e}return n}function zP(n){en(n);let t=ka(n);for(;t;){const e=ka(t);if(!e)return t;t=e}return null}function mk(n,t){const e=hk(n),r=gu(n);return t.withSelf?[...e,n,...r]:[...e,...r]}function Qm(n){en(n);let t=n;const e=hk(n);e.length>0&&(t=e[0]);const r=He(t);return!r||!Ht(r)?null:Mn(r)<Mn(t)?r:null}function GP(n,t){en(n);let e=n;for(;e;){const r=Mn(e);if(r===t)return e;if(r>t)e=Qm(e);else if(r<t)return null}return null}function WP(n){let t=wd(n);for(;;){const e=Qm(t);if(!e)return t;t=wd(e)}}class qP{constructor(){m(this,"nodeMap",new Map);m(this,"rootNodes",[])}addNode(t,e){const r={block:e,children:[]};if(this.nodeMap.set(e,r),t){const i=this.nodeMap.get(t);p(We,i,"no parent node"),i.children.push(r)}else this.rootNodes.push(r)}}function gk(n,t){const e=WP(t),r=new qP;r.addNode(null,e);let i=ae(e);for(;i&&Ht(i);){if(Xm(i)){r.addNode(null,i),i=ae(i);continue}if(Mn(i)===0&&Sr(i)!==Sr(e))break;const s=Qm(i);r.addNode(s,i),i=ae(i)}return r.rootNodes}function XP(n){const t=document.fullscreenEnabled||document.mozFullScreenEnabled||document.documentElement.webkitRequestFullScreen,e=r=>{if(r.requestFullscreen)return r.requestFullscreen();if(r.mozRequestFullScreen)return r.mozRequestFullScreen();if(r.webkitRequestFullScreen){try{document.fullscreenElement=n}catch{}return r.webkitRequestFullScreen()}return Promise.resolve(0)};return t?e(n):Promise.resolve(0)}function pk(){const e=(document.exitFullscreen||document.webkitExitFullscreen).bind(document)();try{document.fullscreenElement=null}catch{}return e}function FE(n){return Mt(n,"editor-in-mindmap-first")}function KE(n){if(p(We,Ht(n),"not a list block"),Mt(n,"editor-in-mindmap-first")||!Zs(n))return!0;const t=n.classList,e="editor-mindmap-root-";return!!Array.from(t).find(i=>{if(i.startsWith(e))return i})}function YP(n,t,e){const r=at(n);if(t){const s=at(t);p(We,r===s,"invalid block container")}const i=Rt(n);if(t){const s=Rt(t);p(We,i<=s,"invalid block index")}if(q(n,...e),!t||t===n)return;let o=ae(n);for(;o!==t;)p(We,o,"no next button"),q(o,...e),o=ae(o);o&&q(o,...e)}function QP(n){const t=`editor-mindmap-root-${n.id}`,r=at(n).querySelectorAll(`.${t}`);return r[r.length-1]}async function JP(n,t,e){const r=ve(t),i=r.querySelector('[data-button-id="mindmap-fullscreen"]');p(We,i,"no full screen button");const o=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{ct(r,"fullscreen"),i.innerHTML=cE,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,_.t("mindmap.fullScreen")),KE(t)&&setTimeout(()=>{o()},300)};if(document.fullscreenElement===r){try{await pk()}catch(l){We.error(l)}s()}else{try{q(r,"fullscreen"),await XP(r),o()}catch(l){We.error(l)}i.innerHTML=m2,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,_.t("mindmap.exitFullscreen"))}r.onfullscreenchange=()=>{document.fullscreenElement||s()}}function VE(n,t,e,r,i){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=Zr(e,r,i,[]);return s.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,r),q(s,"mindmap-button"),t.appendChild(s),s}function $E(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function ZP(n){return $E(n,"mindmap-fullscreen")}function tF(n){return $E(n,"mindmap-fit")}function eF(n){return $E(n,"mindmap-close")}function nF(n,t,e,r){const i=VE(n,t,"mindmap-close",_.t("mindmap.close"),Am);!i||n.domEvents.addEventListener(i,"click",()=>{r.closeMindmap(n,e)})}function rF(n,t,e,r){const i=VE(n,t,"mindmap-fit",_.t("mindmap.autoFit"),h2);!i||n.domEvents.addEventListener(i,"click",()=>{r.fitMindmap(n,e)})}function iF(n,t,e,r){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const o=VE(n,t,"mindmap-fullscreen",_.t("mindmap.fullScreen"),cE);!o||n.domEvents.addEventListener(o,"click",()=>{JP(n,e,r)})}function oF(n,t){const e=y0(t);if(!e)return;const r=tF(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=eF(e);i&&(i.remove(),n.domEvents.removeAllListeners(i));const o=ZP(e);o&&(o.remove(),n.domEvents.removeAllListeners(o))}const pu=new Map;function HE(n,t,e){const r=(s,l)=>{s.forEach(c=>{l?q(c.block,"to-mindmap-highlight"):ct(c.block,"to-mindmap-highlight"),r(c.children,l)})},i=gk(n,t);if(i.length===0)return;const o=i[0].block;if(e){const s=pu.get(o);s&&(s.forEach(l=>l.cancel()),pu.delete(o)),r(i,!0)}else{const s=setTimeout(()=>{r(i,!1),pu.delete(o)},300),l=()=>{clearTimeout(s),pu.delete(o)},c=pu.get(o);c?c.push({cancel:l}):pu.set(o,[{cancel:l}])}}const{Markmap:sF}=h9;function lF(n,t){en(t);const e=gk(n,t),r=e[0].block,i=d=>({type:"text",content:zt(d.block).textContent,depth:1,children:d.children.length>0?d.children.map(C=>i(C)):void 0});let o=null;e.length>1?o={type:"root",content:"root",depth:0,children:e.length>0?e.map(d=>i(d)):void 0}:o=i(e[0]);const l=d=>{if(d.length===0)return null;const h=d[d.length-1];return h.children&&h.children.length>0?l(h.children):h},c=l(e);return{root:o,block:r,nodes:e,last:c}}function Jm(n,t,e,r){const{root:i,block:o,last:s}=lF(n,t);r.selectBlock&&n.selection.selectBlock(o,0,0),HE(n,o,!1),r.saveData&&n.updateBlockData(o,{viewAsMindmap:!0});const l=ve(o);let c=l.querySelector(".editor-mindmap-svg");if(r.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const U="http://www.w3.org/2000/svg",M=l.getBoundingClientRect(),V=document.fullscreenElement===l,nt=V?`${M.width}`:`${t.getBoundingClientRect().width}`,Y=V?`${M.height}`:"600",X=document.createElementNS(U,"svg");X.setAttributeNS(null,"viewBox",`0 0 ${nt} ${Y}`),X.setAttributeNS(null,"width","100%"),X.setAttributeNS(null,"height",Y),X.style.display="block",X.style.width="100%",X.style.height=`${Y}px`,X.classList.add("editor-mindmap-svg"),l.appendChild(X),c=X}const d=o,C=`editor-mindmap-root-${ut(o)}`;q(d,"editor-in-mindmap-first",C,"readonly"),d.contentEditable="false";const E=ae(o);E&&Rt(E)<=Rt(s.block)&&YP(E,s.block,["block-hidden",C]);const A=(U,M)=>{if(M.length>0){const V=M[0].parentElement;V&&(V.style.width="100vw",V.style.maxWidth="200px")}M.forEach(V=>{q(V,"editor-mindmap-node")})},v=new sF(c,{...e,autoFit:!0});v.viewHooks.transformHtml.tap(A),v.setData(i),v.fit();const w=ve(o);let S=w.querySelector(".mindmap-toolbar");S||(S=B("div",["mindmap-toolbar"],w)),rF(n,S,d,r.mindmapTools),iF(n,S,d,r.mindmapTools),nF(n,S,d,r.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(o,0),n.input.focus()}),d.mindMap=v}function aF(n){const t=B("div",["list-to-mindmap-wrap"],null),e=Zr("list-to-mindmap",_.t("mindmap.viewAsMindMap"),d2,[],n.clientId);return t.appendChild(e),t}async function Ck(n,t){const e=`editor-mindmap-root-${t.id}`,r=at(t);ke(r).forEach(l=>{Mt(l,e)&&ct(l,e,"editor-in-mindmap-first","block-hidden")});const o=ve(t);document.fullscreenElement===o&&await pk();const s=o.querySelector(".editor-mindmap-svg");!s||(p(We,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),oF(n,t))}function cF(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(i=>{if(i.startsWith(e))return i})}async function Ek(n,t){!cF(t)||(n.updateBlockData(t,{viewAsMindmap:null}),Ck(n,t),n.selection.selectBlock(t,0))}function uF(n,t){const e=t.mindMap;e&&e.fit()}const Zm={toMindmap:Jm,closeMindmap:Ek,fitMindmap:uF},aat="";class tg{constructor(t){m(this,"toMindmapButton");m(this,"currentBlock",null);m(this,"handleHoveringBlock",t=>{t&&Ht(t)&&Sr(t)!=="unchecked"&&Sr(t)!=="checked"&&this.editor.isWritable()?ve(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove()});m(this,"handleMouseEnter",()=>{const t=et(this.toMindmapButton);p(We,t&&Ht(t),"no parent list"),HE(this.editor,t,!0),this.currentBlock=t});m(this,"handleMouseLeave",()=>{this.currentBlock&&(HE(this.editor,this.currentBlock,!1),this.currentBlock=null)});m(this,"handleClick",()=>{const t=et(this.toMindmapButton);p(We,t&&Ht(t),"no parent list"),Jm(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:Zm})});this.editor=t,$e.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=aF(t),t.domEvents.addEventListener(this.toMindmapButton,"mouseenter",this.handleMouseEnter),t.domEvents.addEventListener(this.toMindmapButton,"mouseleave",this.handleMouseLeave),t.domEvents.addEventListener(this.toMindmapButton,"click",this.handleClick)}static get(t){return t.findCustomByType(tg)}destroy(){$e.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}function fF(n,t,e){var r;t==="beginDrag"&&((r=tg.get(n))==null||r.hide())}function Cu(n,t,e,r){var o;const i=(o=r==null?void 0:r.groupId)!=null?o:it();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(r==null?void 0:r.resetGroupId)){const c={...l,start:e};r!=null&&r.resetGroupId&&(c.groupId=i),n.updateBlockData(s,c)}l.textOnly||(e+=1)})}function jE(n,t,e,r){const i=mk(t,{withSelf:!0});i.length!==0&&Cu(n,i,e,r)}class Eu{constructor(t,e){m(this,"listStart",0);m(this,"listBrother",null);if(this.editor=t,Xm(e))return;const r=wd(e),i=Lr(r);this.listStart=i,r===e?this.listBrother=ka(r):this.listBrother=r}fix(){if(!!this.listBrother){if(Af(this.listBrother)){this.listBrother=null;return}jE(this.editor,this.listBrother,this.listStart)}}}class Ra{constructor(t,e,r){m(this,"listStart");m(this,"listBrother",null);this.editor=t,this.options=r;const i=wd(e),o=Lr(i);this.listStart=o,this.listBrother=i,r!=null&&r.resetStart&&(this.listStart=1)}fix(){!this.listBrother||jE(this.editor,this.listBrother,this.listStart,this.options)}}class Ak{constructor(t,e,r){m(this,"listStart");m(this,"listNextBrothers",[]);this.editor=t,this.listNextBrothers=gu(e);const{start:i,resetStart:o}=r||{};this.listStart=o?1:i!=null?i:1}fix(){!this.listNextBrothers.length||Cu(this.editor,this.listNextBrothers,this.listStart)}}function dF(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function zE(n,t,e,r){if(We.debug("drag a block on a list block"),!st(n,t))return!1;p(We,Ht(e),"target is not a list block");const{type:i,start:o,level:s,groupId:l}=uo(e),c=r==="after"?o+1:o,d=n.getBlockData(t),h={id:it(),type:"list",groupId:l,level:s,start:c,text:d.text,...Ym(i)};dF(n,e,h);let C=Rt(e);const E=at(e);r==="after"&&(C+=1);let A=null;Ht(t)&&(A=new Eu(n,t));const v=n.insertBlock(pt(E),C,h,V0(h.id,0));return n.deleteBlock(t),l!==d.groupId&&new Ra(n,v).fix(),A==null||A.fix(),!0}function hF(n,t,e,r){if(We.debug("drag a list between text blocks"),r==="after"){const d=ae(e);if(d&&Ht(d))return zE(n,t,d,"before")}if(r==="before"){const d=He(e);if(d&&Ht(d))return zE(n,t,d,"after")}const o={...n.getBlockData(t),groupId:it(),start:1,level:1};let s=Rt(e);const l=at(e);r==="after"&&(s+=1),n.insertBlock(pt(l),s,o,V0(o.id,0));const c=new Eu(n,t);return n.deleteBlock(t),c.fix(),!0}function mF(n,t,e,r,i){if(A0(e))return!1;const{blockId:o}=e,s=n.getBlockById(o);p(We,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=i;return!l&&c?(p(We,t===c,"block !== target block"),p(We,Ht(c),"target is not a list block"),zE(n,s,c,r)):hF(n,s,c,r)}function xk(n,t){if(!n.isWritable())return!1;const e=n.selection.range,i=n.editorCommandProviders.getCommands(e,"shortcut").find(o=>o.id===t);return i?(n.editorCommandProviders.executeCommand(e,i,{}),!0):!1}const gF={"Shift+CtrlOrCmd+L":n=>xk(n,"ordered-list"),"Shift+CtrlOrCmd+U":n=>xk(n,"unordered-list")};function eg(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function pF(n,t){let e;const r=eg(t);if(!r)e=1;else{if(r>=12)return e=12,!1;e=r+1}return n.updateBlockData(t,{...n.getBlockData(t),padding:e}),!0}function bk(n,t){const e=eg(t);if(!e)return!1;const r=n.getBlockData(t);return e>1?(n.updateBlockData(t,{...r,padding:e-1}),!0):(n.updateBlockData(t,{...r,padding:null}),!0)}function GE(n){return n.readonly||!n.isWritable()}function CF(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;st(n,r)&&pF(n,r)}),!0}function EF(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;st(n,r)&&bk(n,r)}),!0}function AF(n){return GE(n)?!1:n.undoManager.runInGroup(()=>(CF(n),!0))}function xF(n){return GE(n)?!1:n.undoManager.runInGroup(()=>(EF(n),!0))}function bF(n){if(GE(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!st(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!eg(t)))return bk(n,t),!0}class WE{renderBlock(t,e,r){const{padding:i}=r;return i?{attributes:{"block-padding-level":i}}:{}}}const cat="",vF={Tab:AF,"Shift+Tab":xF,Backspace:bF};function BF(n,t,e=1){if(!t)return null;let r=He(n);for(;r;){const i=r.getAttribute("data-style-heading"),o=Number(r.getAttribute("data-list-level"));if(i){if(i<t)return null;if(i===t&&o===e)return Ht(r)?r:null}r=He(r)}return null}function yF(n,t){const e=n.getAttribute("data-style-heading"),r=BF(n,e);if(r)return r;const i=He(n);if(i&&Ht(i)&&Sr(i)===t)return i;const o=ae(n);return o&&Ht(o)&&Sr(o)===t?o:null}function TF(n,t,e){var w,S,U;const r=(w=e.data)!=null?w:{};let i=1;if(Ht(t))i=Mn(t);else{const M=eg(t);M&&(i=M+1),i>8&&(i=8)}const o=(S=r.listType)!=null?S:"ordered";if(o==="text-only")return null;const s=n.getBlockData(t);let l=(U=s.text)!=null?U:[],d=Re(l);const h=e.offset||0;h<=$n(l)&&(l=sr(l,h).right,d=d.substring(0,h));let C=1;o==="ordered"&&(C=Number.parseInt(d,10)||1);let E=it();const A=yF(t,o);if(A)if(Mn(A)===i){if(Rt(t)>Rt(A))C=Lr(A)+1;else{const M=Lr(A);M>1&&(C=M-1),new Ak(n,A,{start:C+1}).fix()}E=mu(A)}else{const M=GP(A,i);M&&(C=Lr(M)+1)}else Ht(t)&&new Ak(n,t,{start:1}).fix();const v={id:it(),type:"list",level:i,start:C,groupId:E,ordered:!1,text:l};return s.quoted&&(v.quoted=!0),s.heading&&(v.heading=s.heading),o==="ordered"?v.ordered=!0:(o==="checked"||o==="unchecked")&&(v.checkbox=o),{blockData:v,onConverted:(M,V)=>{new Ra(M,V).fix()}}}function Al(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function kF(n){var e,r;if(n.checkbox)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${HP(t,(r=n.start)!=null?r:1)}.`:jP(t)}function ng(n){return n==="checked"||n==="unchecked"}function vk(n,t,e,r){const i=t,{containerId:o,blockIndex:s}=r[r.length-1];if(s===0)return!0;const l=e.blocks[o][s-1];if(l.type!=="list")return!0;const c=Al(i),d=Al(l);return c!==d&&(!ng(c)||!ng(d))||(i.level||1)>(l.level||1)}function Bk(n,t,e,r){const i=t,{containerId:o,blockIndex:s}=r[r.length-1];if(s===e.blocks[o].length-1)return!0;const l=e.blocks[o][s+1];if(l.type!=="list")return!0;const c=Al(i),d=Al(l);return c!==d&&(!ng(c)||!ng(d))||(i.level||1)>(l.level||1)}function RF(n,t,e,r,i){var s,l,c;const o=t;if(r==="text")return((s=ar.convertTo)==null?void 0:s.call(ar,n,t,e,"text",i))||"";if(r==="markdown"){let d=((l=ar.convertTo)==null?void 0:l.call(ar,n,t,e,"markdown",i))||"";o.checkbox==="checked"?d=`[x] ${d}`:o.checkbox==="unchecked"&&(d=`[ ] ${d}`),o.ordered?d=`${o.start}. ${d}`:d=`- ${d}`;const h=o.level||0;return d=(h>0?" ".repeat(h-1):"")+d,vk(n,t,e,i)&&(d=`${d}`),Bk(n,t,e,i)&&(d=`${d}`,h<=1&&(d+=`
614
- `)),d}if(r==="html"){let d=((c=ar.convertTo)==null?void 0:c.call(ar,n,t,e,"html",i))||"";d=d.replace("<p>","").replace("</p>",""),o.checkbox==="checked"?d=`<input type="checkbox" checked="checked" disabled="disabled" /> ${d}`:o.checkbox==="unchecked"&&(d=`<input type="checkbox" disabled="disabled" /> ${d}`);let h="ul",C="";if(o.ordered)switch(d=`<li value="${o.start}">${d}</li>`,h="ol",o.level){case 2:case 5:case 8:C="list-style-type: lower-alpha;";break;case 3:case 6:C="list-style-type: lower-roman;";break}else d=`<li>${d}</li>`;return vk(n,t,e,i)&&(d=`<${h}${C?` style="${C}"`:""}>${d}`),Bk(n,t,e,i)&&(d=`${d}</${h}>`),d}return""}function yk(n){const t=B("label",["editor-check-list-wrapper"],null);n&&q(t,"editor-check-list-wrapper-checked");const e=B("span",["editor-check-box"],t);return B("span",["editor-check-box-inner"],e),t}function wF(n,t){const e=Al(t);if(e!=="text-only"){if(e==="checked"){n.append(yk(!0));return}if(e==="unchecked"){n.append(yk(!1));return}n.innerText=kF(t)}}function SF(n){const t=B("div",["list-container"],null),e=B("button",["list-marker"],t);return wF(e,n),t}function Au(n,t){en(t);const e=n.getBlockData(t),r={id:it(),type:"text",text:e.text};e.heading&&(r.heading=e.heading),e.heading&&(r.heading=e.heading);const i=at(t),o=Rt(t);n.deleteBlock(t);const s=V0(r.id,0);if(Uf(n,i)&&!re(i)){const l=Me(i);n.insertBlock(pt(i),o,r,s),n.deleteBlock(l)}else n.insertBlock(pt(i),o,r,s)}function LF(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:(Au(n,t),!0)}function Tk(n){let t=ae(n);if(!t)return null;const e=ka(n);for(;t!==e;){if(p(We,t,"no next block"),Ht(t))return Mn(t)>Mn(n)?t:null;if(t=ae(t),!t)return null}return null}function qE(n){const t=[];let e=Tk(n);if(!e)return t;for(;e;){const r=ka(e);t.push({block:e,children:qE(e)}),e=r}return t}function IF(n){const t=(r,i)=>{i.push(r.block),r.children.forEach(o=>t(o,i))},e=[];return n.forEach(r=>t(r,e)),e}function kk(n,t){return Mn(t)!==1}function Rk(n,t,e){t.forEach(r=>{const i=n.getBlockData(r.block);n.updateBlockData(r.block,{...i,groupId:e,level:(i.level||1)-1}),r.children.length&&Rk(n,r.children,i.groupId)})}function XE(n,t){if(!kk(n,t))return!1;const e=Mn(t);if(e===1)return!1;let r=it(),i=1,o=Sr(t);const s=e-1,l=Qm(t);l&&(r=mu(l),i=Lr(l)+1,o!=="text-only"&&(o=Sr(l)));const c=qE(t),d=n.getBlockData(t),h={...d,groupId:r,level:s,start:i,...Ym(o)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),Rk(n,c,d.groupId),n.doc.endBatchUpdate(),new Ra(n,t).fix();const E=Tk(t);return E&&new Ra(n,E,{resetStart:!0,resetGroupId:!0}).fix(),!0}const DF=D("list-block");function _F(n,t,e){p(DF,Ht(t),"not a list block");const r={...n.getBlockData(t),id:it()};return e!=null&&e.level&&(r.level=e.level),e!=null&&e.start&&(r.start=e.start),e!=null&&e.keepText||delete r.text,(r==null?void 0:r.checkbox)==="checked"&&(r.checkbox="unchecked"),r}function MF(n){if(en(n),!Xm(n))return n;let t=El(n);for(;t;){if(!Xm(t))return t;t=El(t)}return null}function UF(n,t,e,r){const i=new Ra(n,r),o=Lr(r)+1;Xc(n,t,e,{forceInsertAfter:!0,newBlockData:_F(n,r,{start:o})}),i.fix()}function OF(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Ht(l)&&Ct(n,l)===0)return Mn(l)===1?Au(n,l):XE(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const r=e.offset,o=(s=r===Ct(n,t)?MF(t):t)!=null?s:t;return UF(n,t,r,o),!0}function wk(n){p(We,Ht(n),"not a list block");const{level:t}=uo(n);let e=He(n);for(;e;){if(Ht(e)){const{level:r}=uo(e);if(t===r)return e;if(r<t)return null}e=He(e)}return null}function Sk(n,t){return en(t),wk(t)?Mn(t)<FP:!1}function NF(n,t,e){let r=He(t);p(We,r,"no prev brother");const i=Mn(e);for(;r;){if(r===e)return null;if(Ht(r)&&Mn(r)===i+1)return r;r=He(r)}return null}function Lk(n,t){if(!Sk(n,t))return!1;en(t);const e=wk(t);p(We,e,"no list prev brother");const r=e,i=NF(n,t,r),o=Mn(r)+1;let s=it(),l=1,c=Sr(t);i&&(s=mu(i),l=Lr(i)+1,c=Sr(i));const d=qE(t),C={...n.getBlockData(t),groupId:s,level:o,start:l,...Ym(c)};return n.updateBlockData(t,C),n.doc.beginBatchUpdate(),IF(d).forEach(A=>{const v=n.getBlockData(A);n.updateBlockData(A,{...v,level:(v.level||1)+1})}),n.doc.endBatchUpdate(),!0}function PF(n,t,e){return t.length===0||!t.every(r=>Ht(r.block))?!1:e==="increase"?Sk(n,t[0].block):kk(n,t[0].block)}function Ik(n,t,e){if(!PF(n,t,e))return!1;const r=t[0].block,i=Mn(r),o=t.filter(d=>Mn(d.block)<=i),s=mk(r,{withSelf:!1}),l=new Set(o.map(d=>d.block)),c=s.filter(d=>!l.has(d));return n.undoManager.runInGroup(()=>{let d=null;c.length>0&&(d=new Ra(n,c[0])),o.forEach(h=>{e==="increase"?Lk(n,h.block):XE(n,h.block)}),d==null||d.fix()}),!0}function FF(n,t){return Lk(n,t)}function KF(n,t){return XE(n,t)}function VF(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return Ik(n,t,"increase"),!0;const e=t[0].block;if(!Ht(e))return!1;const r=new Eu(n,e);return FF(n,e)&&(r.fix(),new Ra(n,e).fix()),!0}function $F(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return Ik(n,t,"decrease"),!0;const e=t[0].block;return Ht(e)?(KF(n,e),!0):!1}class HF{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const r=t.selection.range.getSelectedBlocks();if(r.length===0||!r.some(o=>Ht(o.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!Ht(e.block)||Wi(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>OF(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>LF(this.editor))}handleTab(t){return Wi(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>$F(this.editor)):this.editor.undoManager.runInGroup(()=>VF(this.editor))}}class jF{constructor(t){m(this,"effectedBlockIds",new Map);m(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(i=>{const o=i.block;Ht(o)&&e.add(o)});const r=new Map;Array.from(e.values()).forEach(i=>{var c;const o=wd(i),{start:s}=uo(o);r.set(ut(o),s);const l=(c=zP(i))!=null?c:i;r.set(ut(l),s)}),this.effectedBlockIds=r});m(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const r=this.editor.findBlockById(t);!r||jE(this.editor,r,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const zF=D("customize-list-start-menu");class GF{constructor(t){m(this,"popup");m(this,"block",null);m(this,"show",(t,e)=>{const r=e.querySelector("div.list-container");p(zF,r,"list-block mark does not exist"),this.block=e,this.popup.manualShow(r,{theme:"light"})});m(this,"createDialogContent",()=>{const t=B("div",["customize-start-panel"],null);B("span",["customize-start-panel-title"],t,_.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const r=B("button",["customize-start-panel-button"],t,_.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(r,"click",this.handleOk),t});m(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,r=e.querySelector("button.customize-start-panel-button"),i=e.querySelector("input.customize-start-panel-input"),o=Lr(t);!r||!i||requestAnimationFrame(()=>{i.focus(),i.value=String(o)})});m(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),r=this.block;if(!r)return;const i=Number(e.value);!i||(this.editor.undoManager.runInGroup(()=>{Cu(this.editor,[r,...gu(r)],i,{resetGroupId:!0})}),this.popup.close("clickItem"))});m(this,"handleKeydown",(t,e)=>{const r=e;r.isComposing||(r.key==="Escape"?this.popup.close("cancelBar"):r.key==="Enter"&&this.handleOk())});this.editor=t,this.popup=new su(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}createNumericInput(){const t=B("input",["customize-start-panel-input"],null);t.type="number",t.min="1";const e=()=>{const i=t.value.replace(/[^\d]/g,"").replace(/^0+/,""),o=parseInt(i,10);o<=0||Number.isNaN(o)?t.value="":t.value=i};return this.editor.domEvents.addEventListener(t,"input",e),t}}function WF(n,t){return mu(n)===mu(t)}function qF(n,t){const e=dk(t);return e?WF(e,t)?Lr(e)!==Lr(t)-1:!0:!1}function XF(n,t){return El(t)?!0:Lr(t)!==1}function YF(n,t){return en(t),[{id:"continue-numbering",name:_.t("list.continueList"),states:qF(n,t)?[]:["disabled"]},{id:"start-new-list",name:_.t("list.restartList"),states:XF(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:_.t("list.changeNumber")}]}function QF(n,t,e){var r,i;if(en(t),e.id==="continue-numbering"){const o=dk(t);o&&Cu(n,[t,...gu(t)],Lr(o)+1,{resetGroupId:!0,groupId:mu(o)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{Cu(n,[t,...gu(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const o=(r=n.options.componentsOptions)==null?void 0:r.list;if((i=o==null?void 0:o.onChangeStart)!=null&&i.call(o,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new GF(n)).show(n,t)}}class JF{constructor(t){m(this,"menu");m(this,"handleClick",(t,e)=>{const r=Dc(e,"div.list-container");if(r&&this.editor.isWritable()){const i=et(r);p(We,i,"no parent block"),en(i);const o=t.getBlockData(i);if(o&&o.checkbox){t.updateBlockData(i,{...o,checkbox:o.checkbox==="checked"?"unchecked":"checked"});return}if(Sr(i)==="unordered")return;this.menu.updateItems(this.getCommandItems(i)),this.menu.manualShow(r),this.activeList(r,!0)}});m(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});m(this,"handleMenuClick",(t,e)=>{var i;const r=(i=this.menu.tippyInstance)==null?void 0:i.reference;if(r){const o=et(r);o&&QF(this.editor,o,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new hl([]),this.menu.addListener("close",this.handleMenuClose),this.menu.addListener("click",this.handleMenuClick)}destroy(){this.editor.removeListener("click",this.handleClick),this.menu.removeListener("close",this.handleMenuClose)}getCommandItems(t){return YF(this.editor,t)}activeList(t,e){const r=et(t);!r||(e?(q(t,"active"),q(r,"active")):(ct(t,"active"),ct(r,"active")))}}class ZF{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const r=t.selection.range.getSelectedBlocks();if(r.length===0)return!1;const i=r[0].block;if(!Ht(i)||!KE(i))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const o=Gr(i);return o&&t.selection.selectBlock(o,Ct(t,o)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const o=Wr(i);return o&&t.selection.selectBlock(o,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&Ek(t,i),!0}}function tK(n,t,e,r,i){kC(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new ZF(n)),n.input.addHandler(new HF(n)),n.addCustom("list-clear-selection-handler",()=>new jF(n)),n.addCustom("list-marker-menu",()=>new JF(n))})});const o=ar.createBlockContent(n,t,e,r,i),s=i,{level:l,start:c,groupId:d}=s,h=Al(s);r.setAttribute("data-list-level",`${l||1}`),r.setAttribute("data-list-start",`${c||1}`),r.setAttribute("data-list-group-id",`${d}`),r.setAttribute("data-list-type",h);const C=SF(s);return r.insertBefore(C,o),s.viewAsMindmap?setTimeout(()=>{const E=n.findBlockById(i.id);E&&Jm(n,E,{},{mindmapTools:Zm,saveData:!1})}):setTimeout(()=>{const E=n.findBlockById(i.id);E&&Ck(n,E)}),o}const eK={list:{confirm:"\u786E\u5B9A",setStart:"\u8BBE\u7F6E\u7F16\u53F7",continueList:"\u7EE7\u7EED\u7F16\u53F7",restartList:"\u5F00\u59CB\u65B0\u5217\u8868",changeNumber:"\u4FEE\u6539\u7F16\u53F7\u503C",numberLabel:"\u7F16\u53F7\u987A\u5E8F",mention:{tooltip:"\u63D0\u53CA\u4EBA\u5458\u5E76\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u663E\u793A\u4E3A\u8111\u56FE",autoFit:"\u81EA\u52A8\u7F29\u653E",fullScreen:"\u5168\u5C4F\u67E5\u770B",close:"\u5173\u95ED",exitFullscreen:"\u9000\u51FA\u5168\u5C4F"}},nK={list:{confirm:"Confirm",setStart:"Set number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"Mention and notify users"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto zoom",fullScreen:"Full screen",close:"Close",exitFullscreen:"Exit full screen"}},rK={list:{confirm:"OK",setStart:"\u756A\u53F7\u3092\u8A2D\u5B9A",continueList:"\u9023\u756A\u3092\u8A2D\u5B9A",restartList:"\u65B0\u3057\u3044\u30EA\u30B9\u30C8\u3092\u4F5C\u6210",changeNumber:"\u756A\u53F7\u3092\u7DE8\u96C6",numberLabel:"\u756A\u53F7",mention:{tooltip:"\u30E1\u30F3\u30B7\u30E7\u30F3\u304A\u3088\u3073\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7\u3067\u8868\u793A",autoFit:"\u81EA\u52D5\u30D5\u30A3\u30C3\u30C8",fullScreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30F3",close:"\u9589\u3058\u308B",exitFullscreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30D5"}};_.mergeLang({"zh-CN":eK,"en-US":nK,"ja-JP":rK});const uat="",iK=D("list-block:paste-handler");class Dk{constructor(){m(this,"fixStartByList",null)}async handleBeforePasteDoc(t,e){const r=new Map,i=new Map;return Object.values(e.blocks).forEach(o=>{o.forEach((s,l)=>{if(s.type==="list"){if(l===0){const d=t.selection.startBlock;if(Ht(d)){const{start:C,groupId:E,level:A,type:v}=uo(d),w=Al(s),S=s.groupId;s.groupId=E,s.start=C,s.level=A;const U=Ym(v);Object.assign(s,U),A===s.level&&v===w&&(r.set(S,E),i.set(E,C)),this.fixStartByList=new Eu(t,d);return}const h=He(d);if(h&&Ht(h)){const{start:C,groupId:E,level:A,type:v}=uo(h),w=Al(s);if(A===s.level&&v===w){const S=s.groupId;s.groupId=E,s.start=C+1,s.level=A,r.set(S,E),i.set(E,C+1),this.fixStartByList=new Eu(t,h);return}}}const c=r.get(s.groupId);if(c){const d=i.get(c);p(iK,d,"start is null"),s.start=d+1,s.groupId=c,i.set(c,d+1)}else{const d=it();r.set(s.groupId,d),s.groupId=d,s.start=1,i.set(d,1)}}})}),!1}async handleAfterPaste(t){return t.undoManager.runInGroup(()=>{this.fixStartByList&&(this.fixStartByList.fix(),this.fixStartByList=null)}),!1}}const oK=D("list selection to doc");function sK(n){const t={type:"text"};return Object.entries(n).forEach(([e,r])=>{["ordered","unordered","checked","unchecked","text-only","start","level","groupId","type"].includes(e)||(t[e]=r)}),t}function lK(n,t){const e=Et.default(Qo(n,t.block)),r=t.start,i=t.end;p(oK,e.text,"no block text");const o=Ct(n,t.block);if(i.offset-r.offset===o)return{blocks:{root:[{...e}]},meta:{},comments:{}};const s=sK(e);if(r.offset===i.offset)return{blocks:{root:[{...s,text:[]}]},meta:{},comments:{}};const{middle:l}=ln(e.text,r.offset,i.offset-r.offset);return{blocks:{root:[{...s,text:l}]},meta:{},comments:{}}}const _k={...ar,blockType:"list",createBlockContent:tK,convertFrom:TF,convertTo:RF,handleDrop:mF,notify:fF,handleDeleteBlock:(n,t)=>{if(Ht(t)){const e=new Eu(n,t);setTimeout(()=>{e.fix()})}},selectionToDoc:lK},YE=D("paragraph");class aK{constructor(t){m(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){if(!st(t,e))return[];if(ni(t))return[];const r=[],i={"unordered-list":[_.t("commands.unordered"),mn("CtrlOrCmd+Shift+U"),TT],"ordered-list":[_.t("commands.ordered"),mn("CtrlOrCmd+Shift+L"),yT],"check-list":[_.t("commands.check"),void 0,kT],link:[_.t("commands.link"),mn("CtrlOrCmd+K"),rE],quoted:[_.t("commands.quote"),void 0,RT]},o=ut(e),s=Ot(e),l=Ei(t,e),c=t.getBlockData(e);return Object.entries(i).forEach(([d,[h,C,E]])=>{const A=[];if(this.isChecked(c,d)&&A.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&A.push("disabled")}r.push({blockId:o,blockType:s,blockKind:l,id:d,name:h,desc:C,states:A,icon:E,groupIndex:600})}),r}convertLink(t,e,r){p(YE,bi(e.start),""),p(YE,bi(e.start),"");const i="bottom-start",o=e.start.offset,s=e.end.offset,l=(A,v)=>{t.undoManager.runInGroup(()=>{try{const w=t.selection.range.isCollapsed();let S;if(w){S=qo(t.getBlockText(r),s,A,{link:v}),t.setBlockText(r,S);return}S=P0(t.getBlockText(r),o,s,A),S=Pf(o,A.length,S,"link",v),t.setBlockText(r,S),t.selection.selectBlock(r,o+A.length),t.focus()}catch(w){YE.error(w)}})},c=()=>{t.selection.selectBlock(r,s),t.focus()},d=Vo(t,r,e)[0];if(!d)return;const h=jo(t,r,"link-button-anchor",d),C=t.getBlockText(r),E=Hc(C,o);kd(t,{target:h,linkText:t.getSelectedText(),linkUrl:(E==null?void 0:E.link)||"",onFinished:l,onClose:c,placement:i})}convertToList(t,e,r){const i=k0(t,e,"list",{offset:0,data:{listType:r}});i&&t.undoManager.runInGroup(()=>{const o=Rt(e),s=at(e);t.insertBlock(pt(s),o,i.blockData),t.deleteBlock(e)})}executeCommand(t,e,r,i){var c;if(!st(t,e)||ni(t))return!1;const o=i.id,s=(c=i.states)==null?void 0:c.includes("checked");let l=!1;if(o==="unordered-list"&&(s?Au(t,e):this.convertToList(t,e,"unordered"),l=!0),o==="ordered-list"&&(s?Au(t,e):this.convertToList(t,e,"ordered"),l=!0),o==="check-list"&&(s?Au(t,e):this.convertToList(t,e,"unchecked"),l=!0),o==="quoted"){const h=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:h?void 0:!0}),l=!0}if(o==="link"){const d=Gm(t);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},1e3),this.convertLink(t,r,e),l=!0}return l}}const cK={left:ru,right:Sm,center:Lm};class uK{constructor(t){m(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,r){Object.keys(cK).includes(r)?t.updateBlockData(e,{align:r}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,r){if(!st(t,e))return[];if(ni(t))return[];const i=ut(e),o=Ot(e),s=Ei(t,e),l=t.getBlockData(e),c=d=>{var C;const h=B("span",["toolbar-item-name-container"],null);for(const E of d.children)if((C=E.states)!=null&&C.includes("checked"))return h.innerHTML=E.icon||ru,h;return h.innerHTML=ru,h};return[{id:"align",name:_.t("commands.alignGroup"),blockId:i,blockType:o,blockKind:s,groupIndex:700,dropdown:!0,element:c,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:_.t("commands.alignLeft"),icon:ru,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:_.t("commands.alignCenter"),icon:Lm,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:_.t("commands.alignRight"),icon:Sm,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}executeCommand(t,e,r,i){if(!st(t,e)||ni(t))return!1;if(i.id.startsWith("align")){const o=i.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,o),!0}return!1}}const fK=D("toolbar-handler"),dK={id:"",name:"",type:"separator"};class xu{constructor(t){m(this,"id","editor-toolbar");m(this,"toolbar");m(this,"toolbarType","object");m(this,"mouseDown",!1);m(this,"oldRange",null);m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"_disableTextToolbar",!1);m(this,"_lastClickTime",0);m(this,"isInToolbar",t=>this.toolbar.isInCommandBar(t.target));m(this,"handleButtonClick",(t,e)=>{const r=this.editor.getCustom("editor-tooltip");r.lastClickButtonId=e.id,this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.editor.isWritable()&&this.showTextToolbar("click")):Date.now()-this._lastClickTime>200&&(this.toolbar.close("clickItem"),this.hoveringBlock&&OP(this.editor,this.hoveringBlock,this.hoveringTextChild,e)),this._lastClickTime=Date.now()});m(this,"handleClose",()=>{dE(this.editor)&&this.editor.focus()});m(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const r=zb(e);if(this.hoveringBlock===r)return!1}return!0});m(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});m(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});m(this,"handleHoveringBlockChildChange",(t,e,r,i)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close("fromHover");return}this.showObjectToolbar(i)}});m(this,"handleSelectionChange",Ne.default(t=>{var r;if(p(fK,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"){const i=(r=this.toolbar.tippyInstance)==null?void 0:r.reference,o=this.editor.selection.focusedBlock;if(i&&Ee(i,o))return}this.toolbar.close("selectionChange"),this.oldRange=null;return}if(!this.editor.isWritable()){this.toolbar.close("selectionChange"),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close("selectionChange"),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new md([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0,padding:20}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.toolbar.on("closing",this.handleClosing),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),$e.get(t).addListener("childChange",this.handleHoveringBlockChildChange),$e.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new PP(t)),t.editorCommandProviders.registerCommandProvider(new aK(t)),t.editorCommandProviders.registerCommandProvider(new uK(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close("selectionChange")}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),$e.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&Ee(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){!this.editor.isWritable()||this.showTextToolbar(t)}showTextToolbar(t){var w,S;if(this._disableTextToolbar)return;const e=this.editor.selection.range,r=e.getSelectedBlocks();if(r.length===0)return;const i=r[0];if(!i)return;if(r.length===1){if(Le(i.block)){t==="click"&&this.showObjectToolbar(null);return}if(Pt(this.editor,i.block)&&e.isSimple())return}if(Ko(i.block)){this.toolbar.close("selectionChange");return}const o=this.editor.editorCommandProviders.getCommands(this.editor.selection.range,this.id),s=new Map;o.forEach(U=>{const M=U.groupIndex,V=s.get(M);V?V.push(U):s.set(M,[U])});const l=[[]],c=Array.from(s.entries()).sort((U,M)=>U[0]-M[0]);for(let U=0;U<c.length;U++){const[,M]=c[U];if(M.length===0)continue;let V=l[l.length-1];V.length>0&&V[V.length-1].groupIndex!==M[M.length-1].groupIndex&&(V=[],l.push(V)),V.push(...zm(M))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((U,M)=>{const V=U.sort((nt,Y)=>{var X,ft;return((X=nt.order)!=null?X:0)-((ft=Y.order)!=null?ft:0)});d.push(...V),M!==l.length-1&&d.push(dK)}),d.length===0){this.toolbar.close("selectionChange");return}this.toolbar.updateItems(d);const h=r[r.length-1],C=!this.editor.selection.range.isReverse()&&h!==i,E=C?h:i,A=ak(this.editor,E),v=jo(this.editor,E.block,"editor-quick-menu",A);this.toolbar.manualShow(v,{placement:C?"bottom":"top",offset:[0,C?5:10]}),(S=(w=this.toolbar.tippyInstance)==null?void 0:w.popperInstance)==null||S.update()}showObjectToolbar(t){var l,c,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,r=this.hoveringTextChild,{commands:i,element:o}=_P(this.editor,e,r);if(!i.length||!o){this.toolbar.close("fromHover");return}this.toolbarType="object",this.toolbar.isVisible&&((c=(l=this.toolbar)==null?void 0:l.tippyInstance)==null?void 0:c.reference)!==o&&this.toolbar.close("fromHover");const s=()=>{let h;const C=o.getClientRects(),E=[];if(Array.from(C).forEach(A=>{const{y:v}=A;E.includes(v)||E.push(v)}),E.length>1){if(h=r?C[C.length-1]:C[0],t)for(let A=0;A<C.length;A++){const v=C[A],w=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(w.x<t.clientX&&t.clientX<w.right&&w.y<t.clientY&&t.clientY<w.bottom){h=v;break}}}else{if(h=o.getBoundingClientRect(),r){const A=r.getBoundingClientRect();return new DOMRect(A.x,A.y,A.width,A.height)}return new DOMRect(C[0].x,C[0].y,C[0].width,C[0].height)}if(t){const A=h.y,v=t.clientX;return new DOMRect(v,A,10,h.height)}return h};this.toolbar.updateItems(i),this.toolbar.isVisible||(this.toolbar.manualShow(o,{placement:r?"bottom":"top",getReferenceClientRect:s}),(d=this.toolbar.tippyInstance)!=null&&d.popper&&(this.toolbar.tippyInstance.popper.style.paddingTop="10px",this.toolbar.tippyInstance.popper.style.paddingBottom="5px"))}static register(t){return t.addCustom("toolbar-handler",e=>new xu(e))}static get(t){return t.getCustom("toolbar-handler")}}function rg(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function Mk(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function QE(n,t){const r=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:r?void 0:!0})}function JE(n,t){return!!(n[t]||n.level&&(n.ordered===!0&&!n.checkbox&&t==="ordered-list"||n.ordered===!1&&!n.checkbox&&t==="unordered-list")||t==="check-list"&&n.checkbox)}function ZE(n,t,e){if(!n.selection.range.focus.isSimple())return;const i=n.getBlockData(t);let o;switch(e){case"unordered-list":o=JE(i,"unordered-list")?void 0:"unordered";break;case"ordered-list":o=JE(i,"ordered-list")?void 0:"ordered";break;case"check-list":o=JE(i,"check-list")?void 0:"unchecked";break}if(o){const s=k0(n,t,"list",{offset:0,data:{listType:o}});s&&n.undoManager.runInGroup(()=>{const l=Rt(t),c=at(t);n.deleteBlock(t);const d=n.insertBlock(pt(c),l,s.blockData);s.onConverted&&s.onConverted(n,d)})}else Au(n,t)}const hK=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:rg,applyAlignStyle:Mk,applyQuoteStyle:QE,applyList:ZE},Symbol.toStringTag,{value:"Module"})),mK=[bm,vm,Bm,ym,Tm,km,Rm,wm],gK={Unordered:sE,Ordered:lE,Checkbox:iE,Quote:oE};function Uk(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(r=>Uk(r,t))}function pK(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:iu,name:_.t("commands.text"),order:0,group:"basics",value:"text"}]}}function tA(n=1){var i;const t={name:"basic",insertBlockCommandItems:[]};let e=Wm();e<=4?e=5:e<8&&(e+=1);let r=n;for(;r<=e;){const o=`heading-${r}`;(i=t.insertBlockCommandItems)==null||i.push({id:o,icon:mK[r-1],name:_.t("quickMenu.basic.heading.title",{heading:String(r)}),order:r,group:"basics",value:String(r),subText:Jn(o)}),r++}return t}function CK(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,r)=>{var o;const i=`insert-${e.toLocaleLowerCase()}`;(o=n.insertBlockCommandItems)==null||o.push({id:i,name:_.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:gK[e],value:e.toLocaleLowerCase(),group:"basics",order:10+r,subText:Jn(i)})}),n}class Ok{constructor(t){this.withPlainText=t}getCommands(){const t=pK(),e=tA(),r=CK();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...r.insertBlockCommandItems||[]]}updateBlock(t,e,r,i){const{value:o,id:s}=i;return s.startsWith("heading-")?rg(t,r,Number.parseInt(o!=null?o:"1",10)||1):o==="ordered"||o==="unordered"||o==="checkbox"?ZE(t,r,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[o]):o==="quote"&&QE(t,r),null}async handleUpdateBlockCore(t,e){const r=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,r,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:r,blockIndex:i}=e,o=t.insertTextBlock(void 0,r,i);return this.updateBlock(t,e.containerId,o,e.item)}async executeCommand(t,e,r){if(r.from==="quick-menu"||r.from==="add-block-menu"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=pt(o),l=t.getBlockIndex(i);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l})),t.focus()}else r.from==="block-menu"&&(t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:r.containerId,blockIndex:r.blockIndex})),t.focus());return null}}const Nk={basics:100,system:200,common:300,thirdParty:400};class eA{constructor(){m(this,"dataUrl","");m(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const EK=D("mathjax-converter"),AK="MathJax-script",xK=30,Pk=8;async function bK(n){var r;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((r=t==null?void 0:t.cdn)==null?void 0:r.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await ra(e,AK)}function vK(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function nA(n,t){const e="mathjax2Svg";try{await gi.lock(e),vK(),await bK(n);const r=await window.MathJax.tex2svgPromise(t),i=r.querySelector("merror");if(i)throw new Error(i.textContent);return r.querySelector("svg").outerHTML}catch(r){throw EK.error(r),r}finally{gi.release(e)}}function BK(n){const t=new DOMParser().parseFromString(n,"image/svg+xml"),e={width:0,height:0};if(t&&t.firstChild){const r=t.firstChild,i=r.getAttribute("height"),o=r.style.minWidth;i&&(e.width=parseInt(o,10)*Pk+xK,e.height=parseInt(i,10)*Pk)}return e}async function Fk(n,t){const e=await nA(n,t);return e?await Hp(e,"image/svg+xml"):""}async function Kk(n,t){const r=await nA(n,t),i=new File([r],"math.svg");return(await n.doc.uploadResource(i)).resourceId}async function yK(n,t){const e=await nA(n,t),r=BK(e),i=e,o=new File([i],"math.svg");return{resourceId:(await n.doc.uploadResource(o)).resourceId,...r}}const Vk=D("edit-mathjax");class TK{constructor(){m(this,"editMathjaxPopup",null);m(this,"onChange",null);m(this,"tex","");m(this,"observer",null);m(this,"handleClose",t=>{var r;const e=t.content.querySelector("textarea");if(e){const i=e.value;i!==this.tex&&((r=this.onChange)==null||r.call(this,i,!0))}});m(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close("cancelBar")),this.handleChange(t.target.value))});m(this,"handleChange",Ne.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,r,i){if(!this.editMathjaxPopup)this.editMathjaxPopup=new su(this.createPopupContent(e),{id:"mathjax-popover"});else{const o=this.getTextarea();o.value=e}this.tex=e,this.editMathjaxPopup.manualShow(t,{theme:"light",placement:i==null?void 0:i.placement}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=r}createPopupContent(t){const e=B("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),this.textareaWatcher(e),e}textareaWatcher(t){const e=t;e.onblur=()=>{var i;(i=this.editMathjaxPopup)!=null&&i.isVisible&&t.focus()};const r=()=>{setTimeout(()=>{t.focus()})};this.observer=new IntersectionObserver(r,{}),this.observer.observe(t)}getTextarea(){p(Vk,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return p(Vk,t,"no textarea"),t}destroy(){var t,e;this.onChange=null,(t=this.observer)==null||t.disconnect(),(e=this.editMathjaxPopup)==null||e.removeAllListeners()}}function $k(n,t,e,r,i){n.addCustom("mathjax-editor",()=>new TK).editMathjax(t,e.trim(),r,i)}function Hk(){return{insert:" ",attributes:{id:it(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function ig(n,t){const e=n.getBoxData(t),r=et(t);if(!r)return;const i=rl(r,t);n.selection.selectBlock(r,i.start,i.end);const o=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await gi.lock("convertAndUploadMathjax");const c=await Kk(n,s);n.updateBoxData({...e,tex:s,src:c})}catch(c){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new eA).setError(c),n.updateBoxData({...e,tex:s,src:""})}finally{gi.release("convertAndUploadMathjax"),l&&n.focus()}};$k(n,t,e.tex,o)}const jk=D("mathjax-box");function rA(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,rA)}async function kK(n,t,e){try{if(!t.tex.trim())return;const r=await Fk(n,t.tex),i=n.findBoxById(t.id);if(!i)return;const o=o1(i);o.innerHTML="";const s=B("img",["mathjax"],o);s.src=r,e.setDataUrl(r),n.domEvents.addEventListener(s,"load",rA)}catch(r){e.setError(r);const i=n.findBoxById(t.id);if(!i)return;const o=i.querySelector(".mathjax-tex-text");q(o,"mathjax-error"),o.innerText=r.message,n.selection.updateSelection(null)}}function RK(n,t,e,r){const i=r,o=n.addCustom(`mathjax-box-${i.id}`,()=>new eA);if(i.src||o.dataUrl){const c=B("img",["mathjax"],e);c.src=n.doc.buildResourceUrl(i.src||o.dataUrl,{syncNewResources:async(d,h)=>{var E,A;await n.doc.addResources([d]);const C=(A=(E=n.doc).getServerMeta)==null?void 0:A.call(E).appId;if(i.src&&i.src!==h&&C&&i.src.includes(C)){const v=et(e),w=Et.default(i);v&&n.isBlockWritable(v)&&!n.readonly&&(w.src=d,n.updateBoxData(w))}}}),n.domEvents.addEventListener(c,"load",rA);return}const s=["mathjax-tex-text"];let l=i.tex;l.trim()?o.error&&(l=o.error.message,s.push("mathjax-error")):l=_.t("mathjax.emptyText"),B("span",s,e,l),kK(n,i,o)}function wK(n,t){const e={id:it(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return Kk(n,t).then(r=>{if(!n.findBoxById(e.id))return;const o={...e,src:r};n.updateBoxData(o)}).catch(r=>{jk.error(`failed to convert and upload mathjax: ${JSON.stringify(r)}`)}),e}function SK(n,t,e,r){const i=t;return r==="text"?i.tex:r==="markdown"?` $${i.tex}$ `:i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:`<code>$${i.tex}$</code>`}function LK(n,t,e){const r=et(t);p(jk,r,"failed to get block"),!(n.readonly||!n.isBlockWritable(r))&&ig(n,t)}function IK(){return{abstract:`[${_.t("mathjax.abstract")}]`}}const zk={boxType:"math",updateBoxContent:RK,convertFrom:wK,convertTo:SK,handleClickBox:LK,getBoxProperties:IK};async function DK(n,t,e){try{const r=t.embedData,i=await Fk(n,r.mathjaxText),o=n.findBlockById(t.id);if(!o)return;const s=zt(o);s.innerHTML="";const l=B("img",["mathjax"],s);l.src=i,e.setDataUrl(i)}catch(r){e.setError(r)}}function _K(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=et(t.target);if(!e||!Le(e)||sn(e)!=="math")return;const r=zt(e),i=r.querySelector("img")||r.querySelector("span.mathjax-tex-text");if(!i||!Ee(i,t.target))return;const s=n.getBlockData(e).embedData;$k(n,i,s.mathjaxText,async l=>{const{resourceId:c,width:d,height:h}=await yK(n,l),C={mathjaxText:l,src:c,width:d,height:h};n.updateEmbedData(e,C)},{placement:"bottom"})}function MK(n,t,e){const r=e.embedData,{src:i,width:o}=r,s=n.addCustom(`mathjax-block-${e.id}`,()=>new eA);if(n.domEvents.addEventListener(t,"click",_K),!r.mathjaxText.trim()){B("span",["mathjax-tex-text"],t,_.t("mathjax.emptyText"));return}if(i||s.dataUrl){const l=B("img",["mathjax"],t);l.src=n.doc.buildResourceUrl(i||s.dataUrl,{syncNewResources:async(c,d)=>{var h,C;if(i){await n.doc.addResources([c]);const E=(C=(h=n.doc).getServerMeta)==null?void 0:C.call(h).appId;if(i&&d!==i&&E&&i.includes(E)){const A=et(t);setTimeout(()=>{if(A&&!n.readonly&&n.isBlockWritable(A)){const v=Et.default(e);v.embedData.src=c,n.updateBlockData(A,v)}})}}}}),o&&(l.style.minWidth=`${o}px`,setTimeout(()=>{const c=t.getBoundingClientRect().width;o>c?(q(t,"mathjax-overflow"),t.style.overflow="auto",t.style.setProperty("--mathjax-width",`${o}px`)):(ct(t,"mathjax-overflow"),t.removeAttribute("data-mathjax-width"),t.style.removeProperty("--mathjax-width"))}));return}s.error,B("span",["mathjax-tex-text"],t,r.mathjaxText),DK(n,e,s)}function UK(n,t,e){if(!st(n,t))return null;const r=n.getBlockString(t).trim();if(!r||!r.startsWith("$$")||!r.endsWith("$$"))return null;const i=Fp(r,"$");if(!i)return null;const o={mathjaxText:i,src:""};return{blockData:{id:it(),type:"embed",embedType:"math",embedData:o}}}function OK(n){return{name:"Mathjax"}}function NK(n,t){var r;const e=zt(t);n.domEvents.removeAllListeners(e),n.findCustom("mathjax-editor")&&((r=n.getCustom("mathjax-editor").editMathjaxPopup)==null||r.close("cancelBar"))}function PK(n,t,e,r){const i=t.embedData;return r==="html"?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:r==="markdown"?`
614
+ `)),d}if(r==="html"){let d=((c=ar.convertTo)==null?void 0:c.call(ar,n,t,e,"html",i))||"";d=d.replace("<p>","").replace("</p>",""),o.checkbox==="checked"?d=`<input type="checkbox" checked="checked" disabled="disabled" /> ${d}`:o.checkbox==="unchecked"&&(d=`<input type="checkbox" disabled="disabled" /> ${d}`);let h="ul",C="";if(o.ordered)switch(d=`<li value="${o.start}">${d}</li>`,h="ol",o.level){case 2:case 5:case 8:C="list-style-type: lower-alpha;";break;case 3:case 6:C="list-style-type: lower-roman;";break}else d=`<li>${d}</li>`;return vk(n,t,e,i)&&(d=`<${h}${C?` style="${C}"`:""}>${d}`),Bk(n,t,e,i)&&(d=`${d}</${h}>`),d}return""}function yk(n){const t=B("label",["editor-check-list-wrapper"],null);n&&q(t,"editor-check-list-wrapper-checked");const e=B("span",["editor-check-box"],t);return B("span",["editor-check-box-inner"],e),t}function wF(n,t){const e=Al(t);if(e!=="text-only"){if(e==="checked"){n.append(yk(!0));return}if(e==="unchecked"){n.append(yk(!1));return}n.innerText=kF(t)}}function SF(n){const t=B("div",["list-container"],null),e=B("button",["list-marker"],t);return wF(e,n),t}function Au(n,t){en(t);const e=n.getBlockData(t),r={id:it(),type:"text",text:e.text};e.heading&&(r.heading=e.heading),e.heading&&(r.heading=e.heading);const i=at(t),o=Rt(t);n.deleteBlock(t);const s=V0(r.id,0);if(Uf(n,i)&&!re(i)){const l=Me(i);n.insertBlock(pt(i),o,r,s),n.deleteBlock(l)}else n.insertBlock(pt(i),o,r,s)}function LF(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:(Au(n,t),!0)}function Tk(n){let t=ae(n);if(!t)return null;const e=ka(n);for(;t!==e;){if(p(We,t,"no next block"),Ht(t))return Mn(t)>Mn(n)?t:null;if(t=ae(t),!t)return null}return null}function qE(n){const t=[];let e=Tk(n);if(!e)return t;for(;e;){const r=ka(e);t.push({block:e,children:qE(e)}),e=r}return t}function IF(n){const t=(r,i)=>{i.push(r.block),r.children.forEach(o=>t(o,i))},e=[];return n.forEach(r=>t(r,e)),e}function kk(n,t){return Mn(t)!==1}function Rk(n,t,e){t.forEach(r=>{const i=n.getBlockData(r.block);n.updateBlockData(r.block,{...i,groupId:e,level:(i.level||1)-1}),r.children.length&&Rk(n,r.children,i.groupId)})}function XE(n,t){if(!kk(n,t))return!1;const e=Mn(t);if(e===1)return!1;let r=it(),i=1,o=Sr(t);const s=e-1,l=Qm(t);l&&(r=mu(l),i=Lr(l)+1,o!=="text-only"&&(o=Sr(l)));const c=qE(t),d=n.getBlockData(t),h={...d,groupId:r,level:s,start:i,...Ym(o)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),Rk(n,c,d.groupId),n.doc.endBatchUpdate(),new Ra(n,t).fix();const E=Tk(t);return E&&new Ra(n,E,{resetStart:!0,resetGroupId:!0}).fix(),!0}const DF=D("list-block");function _F(n,t,e){p(DF,Ht(t),"not a list block");const r={...n.getBlockData(t),id:it()};return e!=null&&e.level&&(r.level=e.level),e!=null&&e.start&&(r.start=e.start),e!=null&&e.keepText||delete r.text,(r==null?void 0:r.checkbox)==="checked"&&(r.checkbox="unchecked"),r}function MF(n){if(en(n),!Xm(n))return n;let t=El(n);for(;t;){if(!Xm(t))return t;t=El(t)}return null}function UF(n,t,e,r){const i=new Ra(n,r),o=Lr(r)+1;Xc(n,t,e,{forceInsertAfter:!0,newBlockData:_F(n,r,{start:o})}),i.fix()}function OF(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Ht(l)&&Ct(n,l)===0)return Mn(l)===1?Au(n,l):XE(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const r=e.offset,o=(s=r===Ct(n,t)?MF(t):t)!=null?s:t;return UF(n,t,r,o),!0}function wk(n){p(We,Ht(n),"not a list block");const{level:t}=uo(n);let e=He(n);for(;e;){if(Ht(e)){const{level:r}=uo(e);if(t===r)return e;if(r<t)return null}e=He(e)}return null}function Sk(n,t){return en(t),wk(t)?Mn(t)<FP:!1}function NF(n,t,e){let r=He(t);p(We,r,"no prev brother");const i=Mn(e);for(;r;){if(r===e)return null;if(Ht(r)&&Mn(r)===i+1)return r;r=He(r)}return null}function Lk(n,t){if(!Sk(n,t))return!1;en(t);const e=wk(t);p(We,e,"no list prev brother");const r=e,i=NF(n,t,r),o=Mn(r)+1;let s=it(),l=1,c=Sr(t);i&&(s=mu(i),l=Lr(i)+1,c=Sr(i));const d=qE(t),C={...n.getBlockData(t),groupId:s,level:o,start:l,...Ym(c)};return n.updateBlockData(t,C),n.doc.beginBatchUpdate(),IF(d).forEach(A=>{const v=n.getBlockData(A);n.updateBlockData(A,{...v,level:(v.level||1)+1})}),n.doc.endBatchUpdate(),!0}function PF(n,t,e){return t.length===0||!t.every(r=>Ht(r.block))?!1:e==="increase"?Sk(n,t[0].block):kk(n,t[0].block)}function Ik(n,t,e){if(!PF(n,t,e))return!1;const r=t[0].block,i=Mn(r),o=t.filter(d=>Mn(d.block)<=i),s=mk(r,{withSelf:!1}),l=new Set(o.map(d=>d.block)),c=s.filter(d=>!l.has(d));return n.undoManager.runInGroup(()=>{let d=null;c.length>0&&(d=new Ra(n,c[0])),o.forEach(h=>{e==="increase"?Lk(n,h.block):XE(n,h.block)}),d==null||d.fix()}),!0}function FF(n,t){return Lk(n,t)}function KF(n,t){return XE(n,t)}function VF(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return Ik(n,t,"increase"),!0;const e=t[0].block;if(!Ht(e))return!1;const r=new Eu(n,e);return FF(n,e)&&(r.fix(),new Ra(n,e).fix()),!0}function $F(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return Ik(n,t,"decrease"),!0;const e=t[0].block;return Ht(e)?(KF(n,e),!0):!1}class HF{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const r=t.selection.range.getSelectedBlocks();if(r.length===0||!r.some(o=>Ht(o.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!Ht(e.block)||Wi(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>OF(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>LF(this.editor))}handleTab(t){return Wi(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>$F(this.editor)):this.editor.undoManager.runInGroup(()=>VF(this.editor))}}class jF{constructor(t){m(this,"effectedBlockIds",new Map);m(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(i=>{const o=i.block;Ht(o)&&e.add(o)});const r=new Map;Array.from(e.values()).forEach(i=>{var c;const o=wd(i),{start:s}=uo(o);r.set(ut(o),s);const l=(c=zP(i))!=null?c:i;r.set(ut(l),s)}),this.effectedBlockIds=r});m(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const r=this.editor.findBlockById(t);!r||jE(this.editor,r,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const zF=D("customize-list-start-menu");class GF{constructor(t){m(this,"popup");m(this,"block",null);m(this,"show",(t,e)=>{const r=e.querySelector("div.list-container");p(zF,r,"list-block mark does not exist"),this.block=e,this.popup.manualShow(r,{theme:"light"})});m(this,"createDialogContent",()=>{const t=B("div",["customize-start-panel"],null);B("span",["customize-start-panel-title"],t,_.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const r=B("button",["customize-start-panel-button"],t,_.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(r,"click",this.handleOk),t});m(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,r=e.querySelector("button.customize-start-panel-button"),i=e.querySelector("input.customize-start-panel-input"),o=Lr(t);!r||!i||requestAnimationFrame(()=>{i.focus(),i.value=String(o)})});m(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),r=this.block;if(!r)return;const i=Number(e.value);!i||(this.editor.undoManager.runInGroup(()=>{Cu(this.editor,[r,...gu(r)],i,{resetGroupId:!0})}),this.popup.close("clickItem"))});m(this,"handleKeydown",(t,e)=>{const r=e;r.isComposing||(r.key==="Escape"?this.popup.close("cancelBar"):r.key==="Enter"&&this.handleOk())});this.editor=t,this.popup=new su(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}createNumericInput(){const t=B("input",["customize-start-panel-input"],null);t.type="number",t.min="1";const e=()=>{const i=t.value.replace(/[^\d]/g,"").replace(/^0+/,""),o=parseInt(i,10);o<=0||Number.isNaN(o)?t.value="":t.value=i};return this.editor.domEvents.addEventListener(t,"input",e),t}}function WF(n,t){return mu(n)===mu(t)}function qF(n,t){const e=dk(t);return e?WF(e,t)?Lr(e)!==Lr(t)-1:!0:!1}function XF(n,t){return El(t)?!0:Lr(t)!==1}function YF(n,t){return en(t),[{id:"continue-numbering",name:_.t("list.continueList"),states:qF(n,t)?[]:["disabled"]},{id:"start-new-list",name:_.t("list.restartList"),states:XF(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:_.t("list.changeNumber")}]}function QF(n,t,e){var r,i;if(en(t),e.id==="continue-numbering"){const o=dk(t);o&&Cu(n,[t,...gu(t)],Lr(o)+1,{resetGroupId:!0,groupId:mu(o)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{Cu(n,[t,...gu(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const o=(r=n.options.componentsOptions)==null?void 0:r.list;if((i=o==null?void 0:o.onChangeStart)!=null&&i.call(o,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new GF(n)).show(n,t)}}class JF{constructor(t){m(this,"menu");m(this,"handleClick",(t,e)=>{const r=Dc(e,"div.list-container");if(r&&this.editor.isWritable()){const i=et(r);p(We,i,"no parent block"),en(i);const o=t.getBlockData(i);if(o&&o.checkbox){t.updateBlockData(i,{...o,checkbox:o.checkbox==="checked"?"unchecked":"checked"});return}if(Sr(i)==="unordered")return;this.menu.updateItems(this.getCommandItems(i)),this.menu.manualShow(r),this.activeList(r,!0)}});m(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});m(this,"handleMenuClick",(t,e)=>{var i;const r=(i=this.menu.tippyInstance)==null?void 0:i.reference;if(r){const o=et(r);o&&QF(this.editor,o,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new hl([]),this.menu.addListener("close",this.handleMenuClose),this.menu.addListener("click",this.handleMenuClick)}destroy(){this.editor.removeListener("click",this.handleClick),this.menu.removeListener("close",this.handleMenuClose)}getCommandItems(t){return YF(this.editor,t)}activeList(t,e){const r=et(t);!r||(e?(q(t,"active"),q(r,"active")):(ct(t,"active"),ct(r,"active")))}}class ZF{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const r=t.selection.range.getSelectedBlocks();if(r.length===0)return!1;const i=r[0].block;if(!Ht(i)||!KE(i))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const o=Gr(i);return o&&t.selection.selectBlock(o,Ct(t,o)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const o=Wr(i);return o&&t.selection.selectBlock(o,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&Ek(t,i),!0}}function tK(n,t,e,r,i){kC(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new ZF(n)),n.input.addHandler(new HF(n)),n.addCustom("list-clear-selection-handler",()=>new jF(n)),n.addCustom("list-marker-menu",()=>new JF(n))})});const o=ar.createBlockContent(n,t,e,r,i),s=i,{level:l,start:c,groupId:d}=s,h=Al(s);r.setAttribute("data-list-level",`${l||1}`),r.setAttribute("data-list-start",`${c||1}`),r.setAttribute("data-list-group-id",`${d}`),r.setAttribute("data-list-type",h);const C=SF(s);return r.insertBefore(C,o),s.viewAsMindmap?setTimeout(()=>{const E=n.findBlockById(i.id);E&&Jm(n,E,{},{mindmapTools:Zm,saveData:!1})}):setTimeout(()=>{const E=n.findBlockById(i.id);E&&Ck(n,E)}),o}const eK={list:{confirm:"\u786E\u5B9A",setStart:"\u8BBE\u7F6E\u7F16\u53F7",continueList:"\u7EE7\u7EED\u7F16\u53F7",restartList:"\u5F00\u59CB\u65B0\u5217\u8868",changeNumber:"\u4FEE\u6539\u7F16\u53F7\u503C",numberLabel:"\u7F16\u53F7\u987A\u5E8F",mention:{tooltip:"\u63D0\u53CA\u4EBA\u5458\u5E76\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u663E\u793A\u4E3A\u8111\u56FE",autoFit:"\u81EA\u52A8\u7F29\u653E",fullScreen:"\u5168\u5C4F\u67E5\u770B",close:"\u5173\u95ED",exitFullscreen:"\u9000\u51FA\u5168\u5C4F"}},nK={list:{confirm:"Confirm",setStart:"Set number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"Mention and notify users"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto zoom",fullScreen:"Full screen",close:"Close",exitFullscreen:"Exit full screen"}},rK={list:{confirm:"OK",setStart:"\u756A\u53F7\u3092\u8A2D\u5B9A",continueList:"\u9023\u756A\u3092\u8A2D\u5B9A",restartList:"\u65B0\u3057\u3044\u30EA\u30B9\u30C8\u3092\u4F5C\u6210",changeNumber:"\u756A\u53F7\u3092\u7DE8\u96C6",numberLabel:"\u756A\u53F7",mention:{tooltip:"\u30E1\u30F3\u30B7\u30E7\u30F3\u304A\u3088\u3073\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7\u3067\u8868\u793A",autoFit:"\u81EA\u52D5\u30D5\u30A3\u30C3\u30C8",fullScreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30F3",close:"\u9589\u3058\u308B",exitFullscreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30D5"}};_.mergeLang({"zh-CN":eK,"en-US":nK,"ja-JP":rK});const uat="",iK=D("list-block:paste-handler");class Dk{constructor(){m(this,"fixStartByList",null)}async handleBeforePasteDoc(t,e){const r=new Map,i=new Map;return Object.values(e.blocks).forEach(o=>{o.forEach((s,l)=>{if(s.type==="list"){if(l===0){const d=t.selection.startBlock;if(Ht(d)){const{start:C,groupId:E,level:A,type:v}=uo(d),w=Al(s),S=s.groupId;s.groupId=E,s.start=C,s.level=A;const U=Ym(v);Object.assign(s,U),A===s.level&&v===w&&(r.set(S,E),i.set(E,C)),this.fixStartByList=new Eu(t,d);return}const h=He(d);if(h&&Ht(h)){const{start:C,groupId:E,level:A,type:v}=uo(h),w=Al(s);if(A===s.level&&v===w){const S=s.groupId;s.groupId=E,s.start=C+1,s.level=A,r.set(S,E),i.set(E,C+1),this.fixStartByList=new Eu(t,h);return}}}const c=r.get(s.groupId);if(c){const d=i.get(c);p(iK,d,"start is null"),s.start=d+1,s.groupId=c,i.set(c,d+1)}else{const d=it();r.set(s.groupId,d),s.groupId=d,s.start=1,i.set(d,1)}}})}),!1}async handleAfterPaste(t){return t.undoManager.runInGroup(()=>{this.fixStartByList&&(this.fixStartByList.fix(),this.fixStartByList=null)}),!1}}const oK=D("list selection to doc");function sK(n){const t={type:"text"};return Object.entries(n).forEach(([e,r])=>{["ordered","unordered","checked","unchecked","text-only","start","level","groupId","type"].includes(e)||(t[e]=r)}),t}function lK(n,t){const e=Et.default(Qo(n,t.block)),r=t.start,i=t.end;p(oK,e.text,"no block text");const o=Ct(n,t.block);if(i.offset-r.offset===o)return{blocks:{root:[{...e}]},meta:{},comments:{}};const s=sK(e);if(r.offset===i.offset)return{blocks:{root:[{...s,text:[]}]},meta:{},comments:{}};const{middle:l}=ln(e.text,r.offset,i.offset-r.offset);return{blocks:{root:[{...s,text:l}]},meta:{},comments:{}}}const _k={...ar,blockType:"list",createBlockContent:tK,convertFrom:TF,convertTo:RF,handleDrop:mF,notify:fF,handleDeleteBlock:(n,t)=>{if(Ht(t)){const e=new Eu(n,t);setTimeout(()=>{e.fix()})}},selectionToDoc:lK},YE=D("paragraph");class aK{constructor(t){m(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){if(!st(t,e))return[];if(ni(t))return[];const r=[],i={"unordered-list":[_.t("commands.unordered"),mn("CtrlOrCmd+Shift+U"),TT],"ordered-list":[_.t("commands.ordered"),mn("CtrlOrCmd+Shift+L"),yT],"check-list":[_.t("commands.check"),void 0,kT],link:[_.t("commands.link"),mn("CtrlOrCmd+K"),rE],quoted:[_.t("commands.quote"),void 0,RT]},o=ut(e),s=Ot(e),l=Ei(t,e),c=t.getBlockData(e);return Object.entries(i).forEach(([d,[h,C,E]])=>{const A=[];if(this.isChecked(c,d)&&A.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&A.push("disabled")}r.push({blockId:o,blockType:s,blockKind:l,id:d,name:h,desc:C,states:A,icon:E,groupIndex:600})}),r}convertLink(t,e,r){p(YE,bi(e.start),""),p(YE,bi(e.start),"");const i="bottom-start",o=e.start.offset,s=e.end.offset,l=(A,v)=>{t.undoManager.runInGroup(()=>{try{const w=t.selection.range.isCollapsed();let S;if(w){S=qo(t.getBlockText(r),s,A,{link:v}),t.setBlockText(r,S);return}S=P0(t.getBlockText(r),o,s,A),S=Pf(o,A.length,S,"link",v),t.setBlockText(r,S),t.selection.selectBlock(r,o+A.length),t.focus()}catch(w){YE.error(w)}})},c=()=>{t.selection.selectBlock(r,s),t.focus()},d=Vo(t,r,e)[0];if(!d)return;const h=jo(t,r,"link-button-anchor",d),C=t.getBlockText(r),E=Hc(C,o);kd(t,{target:h,linkText:t.getSelectedText(),linkUrl:(E==null?void 0:E.link)||"",onFinished:l,onClose:c,placement:i})}convertToList(t,e,r){const i=k0(t,e,"list",{offset:0,data:{listType:r}});i&&t.undoManager.runInGroup(()=>{const o=Rt(e),s=at(e);t.insertBlock(pt(s),o,i.blockData),t.deleteBlock(e)})}executeCommand(t,e,r,i){var c;if(!st(t,e)||ni(t))return!1;const o=i.id,s=(c=i.states)==null?void 0:c.includes("checked");let l=!1;if(o==="unordered-list"&&(s?Au(t,e):this.convertToList(t,e,"unordered"),l=!0),o==="ordered-list"&&(s?Au(t,e):this.convertToList(t,e,"ordered"),l=!0),o==="check-list"&&(s?Au(t,e):this.convertToList(t,e,"unchecked"),l=!0),o==="quoted"){const h=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:h?void 0:!0}),l=!0}if(o==="link"){const d=Gm(t);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},1e3),this.convertLink(t,r,e),l=!0}return l}}const cK={left:ru,right:Sm,center:Lm};class uK{constructor(t){m(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,r){Object.keys(cK).includes(r)?t.updateBlockData(e,{align:r}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,r){if(!st(t,e))return[];if(ni(t))return[];const i=ut(e),o=Ot(e),s=Ei(t,e),l=t.getBlockData(e),c=d=>{var C;const h=B("span",["toolbar-item-name-container"],null);for(const E of d.children)if((C=E.states)!=null&&C.includes("checked"))return h.innerHTML=E.icon||ru,h;return h.innerHTML=ru,h};return[{id:"align",name:_.t("commands.alignGroup"),blockId:i,blockType:o,blockKind:s,groupIndex:700,dropdown:!0,element:c,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:_.t("commands.alignLeft"),icon:ru,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:_.t("commands.alignCenter"),icon:Lm,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:_.t("commands.alignRight"),icon:Sm,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}executeCommand(t,e,r,i){if(!st(t,e)||ni(t))return!1;if(i.id.startsWith("align")){const o=i.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,o),!0}return!1}}const fK=D("toolbar-handler"),dK={id:"",name:"",type:"separator"};class xu{constructor(t){m(this,"id","editor-toolbar");m(this,"toolbar");m(this,"toolbarType","object");m(this,"mouseDown",!1);m(this,"oldRange",null);m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"_disableTextToolbar",!1);m(this,"_lastClickTime",0);m(this,"isInToolbar",t=>this.toolbar.isInCommandBar(t.target));m(this,"handleButtonClick",(t,e)=>{const r=this.editor.getCustom("editor-tooltip");r.lastClickButtonId=e.id,this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.editor.isWritable()&&this.showTextToolbar("click")):Date.now()-this._lastClickTime>200&&(this.toolbar.close("clickItem"),this.hoveringBlock&&OP(this.editor,this.hoveringBlock,this.hoveringTextChild,e)),this._lastClickTime=Date.now()});m(this,"handleClose",()=>{dE(this.editor)&&this.editor.focus({preventScroll:!0})});m(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const r=zb(e);if(this.hoveringBlock===r)return!1}return!0});m(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});m(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});m(this,"handleHoveringBlockChildChange",(t,e,r,i)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close("fromHover");return}this.showObjectToolbar(i)}});m(this,"handleSelectionChange",Ne.default(t=>{var r;if(p(fK,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"){const i=(r=this.toolbar.tippyInstance)==null?void 0:r.reference,o=this.editor.selection.focusedBlock;if(i&&Ee(i,o))return}this.toolbar.close("selectionChange"),this.oldRange=null;return}if(!this.editor.isWritable()){this.toolbar.close("selectionChange"),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close("selectionChange"),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new md([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0,padding:20}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.toolbar.on("closing",this.handleClosing),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),$e.get(t).addListener("childChange",this.handleHoveringBlockChildChange),$e.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new PP(t)),t.editorCommandProviders.registerCommandProvider(new aK(t)),t.editorCommandProviders.registerCommandProvider(new uK(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close("selectionChange")}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),$e.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&Ee(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){!this.editor.isWritable()||this.showTextToolbar(t)}showTextToolbar(t){var w,S;if(this._disableTextToolbar)return;const e=this.editor.selection.range,r=e.getSelectedBlocks();if(r.length===0)return;const i=r[0];if(!i)return;if(r.length===1){if(Le(i.block)){t==="click"&&this.showObjectToolbar(null);return}if(Pt(this.editor,i.block)&&e.isSimple())return}if(Ko(i.block)){this.toolbar.close("selectionChange");return}const o=this.editor.editorCommandProviders.getCommands(this.editor.selection.range,this.id),s=new Map;o.forEach(U=>{const M=U.groupIndex,V=s.get(M);V?V.push(U):s.set(M,[U])});const l=[[]],c=Array.from(s.entries()).sort((U,M)=>U[0]-M[0]);for(let U=0;U<c.length;U++){const[,M]=c[U];if(M.length===0)continue;let V=l[l.length-1];V.length>0&&V[V.length-1].groupIndex!==M[M.length-1].groupIndex&&(V=[],l.push(V)),V.push(...zm(M))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((U,M)=>{const V=U.sort((nt,Y)=>{var X,ft;return((X=nt.order)!=null?X:0)-((ft=Y.order)!=null?ft:0)});d.push(...V),M!==l.length-1&&d.push(dK)}),d.length===0){this.toolbar.close("selectionChange");return}this.toolbar.updateItems(d);const h=r[r.length-1],C=!this.editor.selection.range.isReverse()&&h!==i,E=C?h:i,A=ak(this.editor,E),v=jo(this.editor,E.block,"editor-quick-menu",A);this.toolbar.manualShow(v,{placement:C?"bottom":"top",offset:[0,C?5:10]}),(S=(w=this.toolbar.tippyInstance)==null?void 0:w.popperInstance)==null||S.update()}showObjectToolbar(t){var l,c,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,r=this.hoveringTextChild,{commands:i,element:o}=_P(this.editor,e,r);if(!i.length||!o){this.toolbar.close("fromHover");return}this.toolbarType="object",this.toolbar.isVisible&&((c=(l=this.toolbar)==null?void 0:l.tippyInstance)==null?void 0:c.reference)!==o&&this.toolbar.close("fromHover");const s=()=>{let h;const C=o.getClientRects(),E=[];if(Array.from(C).forEach(A=>{const{y:v}=A;E.includes(v)||E.push(v)}),E.length>1){if(h=r?C[C.length-1]:C[0],t)for(let A=0;A<C.length;A++){const v=C[A],w=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(w.x<t.clientX&&t.clientX<w.right&&w.y<t.clientY&&t.clientY<w.bottom){h=v;break}}}else{if(h=o.getBoundingClientRect(),r){const A=r.getBoundingClientRect();return new DOMRect(A.x,A.y,A.width,A.height)}return new DOMRect(C[0].x,C[0].y,C[0].width,C[0].height)}if(t){const A=h.y,v=t.clientX;return new DOMRect(v,A,10,h.height)}return h};this.toolbar.updateItems(i),this.toolbar.isVisible||(this.toolbar.manualShow(o,{placement:r?"bottom":"top",getReferenceClientRect:s}),(d=this.toolbar.tippyInstance)!=null&&d.popper&&(this.toolbar.tippyInstance.popper.style.paddingTop="10px",this.toolbar.tippyInstance.popper.style.paddingBottom="5px"))}static register(t){return t.addCustom("toolbar-handler",e=>new xu(e))}static get(t){return t.getCustom("toolbar-handler")}}function rg(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function Mk(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function QE(n,t){const r=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:r?void 0:!0})}function JE(n,t){return!!(n[t]||n.level&&(n.ordered===!0&&!n.checkbox&&t==="ordered-list"||n.ordered===!1&&!n.checkbox&&t==="unordered-list")||t==="check-list"&&n.checkbox)}function ZE(n,t,e){if(!n.selection.range.focus.isSimple())return;const i=n.getBlockData(t);let o;switch(e){case"unordered-list":o=JE(i,"unordered-list")?void 0:"unordered";break;case"ordered-list":o=JE(i,"ordered-list")?void 0:"ordered";break;case"check-list":o=JE(i,"check-list")?void 0:"unchecked";break}if(o){const s=k0(n,t,"list",{offset:0,data:{listType:o}});s&&n.undoManager.runInGroup(()=>{const l=Rt(t),c=at(t);n.deleteBlock(t);const d=n.insertBlock(pt(c),l,s.blockData);s.onConverted&&s.onConverted(n,d)})}else Au(n,t)}const hK=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:rg,applyAlignStyle:Mk,applyQuoteStyle:QE,applyList:ZE},Symbol.toStringTag,{value:"Module"})),mK=[bm,vm,Bm,ym,Tm,km,Rm,wm],gK={Unordered:sE,Ordered:lE,Checkbox:iE,Quote:oE};function Uk(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(r=>Uk(r,t))}function pK(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:iu,name:_.t("commands.text"),order:0,group:"basics",value:"text"}]}}function tA(n=1){var i;const t={name:"basic",insertBlockCommandItems:[]};let e=Wm();e<=4?e=5:e<8&&(e+=1);let r=n;for(;r<=e;){const o=`heading-${r}`;(i=t.insertBlockCommandItems)==null||i.push({id:o,icon:mK[r-1],name:_.t("quickMenu.basic.heading.title",{heading:String(r)}),order:r,group:"basics",value:String(r),subText:Jn(o)}),r++}return t}function CK(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,r)=>{var o;const i=`insert-${e.toLocaleLowerCase()}`;(o=n.insertBlockCommandItems)==null||o.push({id:i,name:_.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:gK[e],value:e.toLocaleLowerCase(),group:"basics",order:10+r,subText:Jn(i)})}),n}class Ok{constructor(t){this.withPlainText=t}getCommands(){const t=pK(),e=tA(),r=CK();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...r.insertBlockCommandItems||[]]}updateBlock(t,e,r,i){const{value:o,id:s}=i;return s.startsWith("heading-")?rg(t,r,Number.parseInt(o!=null?o:"1",10)||1):o==="ordered"||o==="unordered"||o==="checkbox"?ZE(t,r,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[o]):o==="quote"&&QE(t,r),null}async handleUpdateBlockCore(t,e){const r=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,r,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:r,blockIndex:i}=e,o=t.insertTextBlock(void 0,r,i);return this.updateBlock(t,e.containerId,o,e.item)}async executeCommand(t,e,r){if(r.from==="quick-menu"||r.from==="add-block-menu"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=pt(o),l=t.getBlockIndex(i);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l})),t.focus()}else r.from==="block-menu"&&(t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:r.containerId,blockIndex:r.blockIndex})),t.focus());return null}}const Nk={basics:100,system:200,common:300,thirdParty:400};class eA{constructor(){m(this,"dataUrl","");m(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const EK=D("mathjax-converter"),AK="MathJax-script",xK=30,Pk=8;async function bK(n){var r;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((r=t==null?void 0:t.cdn)==null?void 0:r.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await ra(e,AK)}function vK(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function nA(n,t){const e="mathjax2Svg";try{await gi.lock(e),vK(),await bK(n);const r=await window.MathJax.tex2svgPromise(t),i=r.querySelector("merror");if(i)throw new Error(i.textContent);return r.querySelector("svg").outerHTML}catch(r){throw EK.error(r),r}finally{gi.release(e)}}function BK(n){const t=new DOMParser().parseFromString(n,"image/svg+xml"),e={width:0,height:0};if(t&&t.firstChild){const r=t.firstChild,i=r.getAttribute("height"),o=r.style.minWidth;i&&(e.width=parseInt(o,10)*Pk+xK,e.height=parseInt(i,10)*Pk)}return e}async function Fk(n,t){const e=await nA(n,t);return e?await Hp(e,"image/svg+xml"):""}async function Kk(n,t){const r=await nA(n,t),i=new File([r],"math.svg");return(await n.doc.uploadResource(i)).resourceId}async function yK(n,t){const e=await nA(n,t),r=BK(e),i=e,o=new File([i],"math.svg");return{resourceId:(await n.doc.uploadResource(o)).resourceId,...r}}const Vk=D("edit-mathjax");class TK{constructor(){m(this,"editMathjaxPopup",null);m(this,"onChange",null);m(this,"tex","");m(this,"observer",null);m(this,"handleClose",t=>{var r;const e=t.content.querySelector("textarea");if(e){const i=e.value;i!==this.tex&&((r=this.onChange)==null||r.call(this,i,!0))}});m(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close("cancelBar")),this.handleChange(t.target.value))});m(this,"handleChange",Ne.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,r,i){if(!this.editMathjaxPopup)this.editMathjaxPopup=new su(this.createPopupContent(e),{id:"mathjax-popover"});else{const o=this.getTextarea();o.value=e}this.tex=e,this.editMathjaxPopup.manualShow(t,{theme:"light",placement:i==null?void 0:i.placement}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=r}createPopupContent(t){const e=B("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),this.textareaWatcher(e),e}textareaWatcher(t){const e=t;e.onblur=()=>{var i;(i=this.editMathjaxPopup)!=null&&i.isVisible&&t.focus()};const r=()=>{setTimeout(()=>{t.focus()})};this.observer=new IntersectionObserver(r,{}),this.observer.observe(t)}getTextarea(){p(Vk,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return p(Vk,t,"no textarea"),t}destroy(){var t,e;this.onChange=null,(t=this.observer)==null||t.disconnect(),(e=this.editMathjaxPopup)==null||e.removeAllListeners()}}function $k(n,t,e,r,i){n.addCustom("mathjax-editor",()=>new TK).editMathjax(t,e.trim(),r,i)}function Hk(){return{insert:" ",attributes:{id:it(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function ig(n,t){const e=n.getBoxData(t),r=et(t);if(!r)return;const i=rl(r,t);n.selection.selectBlock(r,i.start,i.end);const o=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await gi.lock("convertAndUploadMathjax");const c=await Kk(n,s);n.updateBoxData({...e,tex:s,src:c})}catch(c){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new eA).setError(c),n.updateBoxData({...e,tex:s,src:""})}finally{gi.release("convertAndUploadMathjax"),l&&n.focus()}};$k(n,t,e.tex,o)}const jk=D("mathjax-box");function rA(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,rA)}async function kK(n,t,e){try{if(!t.tex.trim())return;const r=await Fk(n,t.tex),i=n.findBoxById(t.id);if(!i)return;const o=o1(i);o.innerHTML="";const s=B("img",["mathjax"],o);s.src=r,e.setDataUrl(r),n.domEvents.addEventListener(s,"load",rA)}catch(r){e.setError(r);const i=n.findBoxById(t.id);if(!i)return;const o=i.querySelector(".mathjax-tex-text");q(o,"mathjax-error"),o.innerText=r.message,n.selection.updateSelection(null)}}function RK(n,t,e,r){const i=r,o=n.addCustom(`mathjax-box-${i.id}`,()=>new eA);if(i.src||o.dataUrl){const c=B("img",["mathjax"],e);c.src=n.doc.buildResourceUrl(i.src||o.dataUrl,{syncNewResources:async(d,h)=>{var E,A;await n.doc.addResources([d]);const C=(A=(E=n.doc).getServerMeta)==null?void 0:A.call(E).appId;if(i.src&&i.src!==h&&C&&i.src.includes(C)){const v=et(e),w=Et.default(i);v&&n.isBlockWritable(v)&&!n.readonly&&(w.src=d,n.updateBoxData(w))}}}),n.domEvents.addEventListener(c,"load",rA);return}const s=["mathjax-tex-text"];let l=i.tex;l.trim()?o.error&&(l=o.error.message,s.push("mathjax-error")):l=_.t("mathjax.emptyText"),B("span",s,e,l),kK(n,i,o)}function wK(n,t){const e={id:it(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return Kk(n,t).then(r=>{if(!n.findBoxById(e.id))return;const o={...e,src:r};n.updateBoxData(o)}).catch(r=>{jk.error(`failed to convert and upload mathjax: ${JSON.stringify(r)}`)}),e}function SK(n,t,e,r){const i=t;return r==="text"?i.tex:r==="markdown"?` $${i.tex}$ `:i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:`<code>$${i.tex}$</code>`}function LK(n,t,e){const r=et(t);p(jk,r,"failed to get block"),!(n.readonly||!n.isBlockWritable(r))&&ig(n,t)}function IK(){return{abstract:`[${_.t("mathjax.abstract")}]`}}const zk={boxType:"math",updateBoxContent:RK,convertFrom:wK,convertTo:SK,handleClickBox:LK,getBoxProperties:IK};async function DK(n,t,e){try{const r=t.embedData,i=await Fk(n,r.mathjaxText),o=n.findBlockById(t.id);if(!o)return;const s=zt(o);s.innerHTML="";const l=B("img",["mathjax"],s);l.src=i,e.setDataUrl(i)}catch(r){e.setError(r)}}function _K(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=et(t.target);if(!e||!Le(e)||sn(e)!=="math")return;const r=zt(e),i=r.querySelector("img")||r.querySelector("span.mathjax-tex-text");if(!i||!Ee(i,t.target))return;const s=n.getBlockData(e).embedData;$k(n,i,s.mathjaxText,async l=>{const{resourceId:c,width:d,height:h}=await yK(n,l),C={mathjaxText:l,src:c,width:d,height:h};n.updateEmbedData(e,C)},{placement:"bottom"})}function MK(n,t,e){const r=e.embedData,{src:i,width:o}=r,s=n.addCustom(`mathjax-block-${e.id}`,()=>new eA);if(n.domEvents.addEventListener(t,"click",_K),!r.mathjaxText.trim()){B("span",["mathjax-tex-text"],t,_.t("mathjax.emptyText"));return}if(i||s.dataUrl){const l=B("img",["mathjax"],t);l.src=n.doc.buildResourceUrl(i||s.dataUrl,{syncNewResources:async(c,d)=>{var h,C;if(i){await n.doc.addResources([c]);const E=(C=(h=n.doc).getServerMeta)==null?void 0:C.call(h).appId;if(i&&d!==i&&E&&i.includes(E)){const A=et(t);setTimeout(()=>{if(A&&!n.readonly&&n.isBlockWritable(A)){const v=Et.default(e);v.embedData.src=c,n.updateBlockData(A,v)}})}}}}),o&&(l.style.minWidth=`${o}px`,setTimeout(()=>{const c=t.getBoundingClientRect().width;o>c?(q(t,"mathjax-overflow"),t.style.overflow="auto",t.style.setProperty("--mathjax-width",`${o}px`)):(ct(t,"mathjax-overflow"),t.removeAttribute("data-mathjax-width"),t.style.removeProperty("--mathjax-width"))}));return}s.error,B("span",["mathjax-tex-text"],t,r.mathjaxText),DK(n,e,s)}function UK(n,t,e){if(!st(n,t))return null;const r=n.getBlockString(t).trim();if(!r||!r.startsWith("$$")||!r.endsWith("$$"))return null;const i=Fp(r,"$");if(!i)return null;const o={mathjaxText:i,src:""};return{blockData:{id:it(),type:"embed",embedType:"math",embedData:o}}}function OK(n){return{name:"Mathjax"}}function NK(n,t){var r;const e=zt(t);n.domEvents.removeAllListeners(e),n.findCustom("mathjax-editor")&&((r=n.getCustom("mathjax-editor").editMathjaxPopup)==null||r.close("cancelBar"))}function PK(n,t,e,r){const i=t.embedData;return r==="html"?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:r==="markdown"?`
615
615
  $$${i.mathjaxText}$$
616
616
  `:i.mathjaxText}function FK(){return{abstract:_.t("mathjax.abstract")}}const KK={embedType:"math",createEmbedContent:MK,getOptions:OK,convertFrom:UK,handleDeleteBlock:NK,convertTo:PK,getBlockProperties:FK},fat="",VK={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},$K={mathjax:{emptyText:"Empty formula",abstract:"Formula"}},HK={mathjax:{emptyText:"\u6570\u5F0F\u306A\u3057",abstract:"\u6570\u5F0F"}};_.mergeLang({"zh-CN":VK,"en-US":$K,"ja-JP":HK});function jK(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=sr(o,r);if(!Re(s).endsWith("$$$$"))return!1;const c=r-4,d=r,h={id:it(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,c,d-c),n.insertBoxToBlock(i,c,h),setTimeout(()=>{const C=n.getBoxById(h.id);ig(n,C)})}),!0}class zK{handleAfterInsertText(t,e,r,i,o){return!!(o===" "&&jK(t,e,r,i))}}var Ii={exports:{}};/**
617
617
  * @license
@@ -960,4 +960,4 @@ ${o.mermaidText}
960
960
  ${o.flowchartText}
961
961
  \`\`\`\`\`\``}return""}const zJ={embedType:"flowchart",convertFrom:$J,handleUpdateBlock:VJ,createEmbedContent:KJ,getBlockProperties:HJ,convertTo:jJ},GJ=D("plantuml-helper");function NS(n,t){var l;let r=((l=(n.getComponentOptions("plantuml")||{}).cdn)==null?void 0:l.plantuml)||BJ;r.endsWith("/")||(r+="/");const i=p9.default.encode(t);p(GJ,i,i),r+=i;const s=new URLSearchParams(document.location.search).get("doc");return Vp(r,{id:`${s}-${it()}`})}async function WJ(n,t){try{const e=await vx(n,t);return(await n.doc.uploadResource(e)).resourceId}catch{return Promise.resolve(t)}}class Ou extends kx{constructor(t){super(t,"plantuml","plantumlText")}static get(t,e){return t.addCustom(`plantuml-${e.id}`,()=>new Ou(t))}code2ObjectUrl(t){return Promise.resolve(NS(this.editor,t))}code2ResourceId(t){const e=NS(this.editor,t);return WJ(this.editor,e)}destroy(){}}function qJ(n,t,e){Ou.get(n,e).createEmbedContent(t,e)}function XJ(n,t,e){const r=Ou.get(n,e),i=zt(t);return r.updateEmbedContent(i,e),!0}function YJ(n,t,e){const{data:r}=e,i=n.getBlockString(t).trim();if(!r||r.embedType!=="plantuml"||i!=="```plantuml"||!st(n,t))return null;const o={src:"",plantumlText:""};return{blockData:{id:it(),type:"embed",embedType:"plantuml",embedData:o},onConverted:(c,d)=>{Ou.get(c,c.getBlockData(d)).editGraph(zt(d))}}}function QJ(n,t){return Ou.get(n,n.getBlockData(t)).getBlockProperties(t)}function JJ(n,t,e,r){const{embedData:i}=t,o=i;if(r==="html")return o.src?`<img src="${n.doc.buildResourceUrl(o.src,{withToken:!0})}" />`:o.flowchartText?`<div>${o.flowchartText}</div>`:"<p>[plantuml]</p>";if(r==="markdown"){if(o.src)return`![plantuml](${n.doc.buildResourceUrl(o.src,{withToken:!0})})`;if(o.flowchartText)return`\`\`\`plantuml\`\`\`
962
962
  ${o.flowchartText}
963
- \`\`\`\`\`\``}return""}const ZJ={embedType:"plantuml",convertFrom:YJ,handleUpdateBlock:XJ,createEmbedContent:qJ,getBlockProperties:QJ,convertTo:JJ},oct="",tZ="hr",eZ={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},nZ={dividingLine:{type:"Dividing-Line",abstract:"Dividing-Line"}},rZ={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};_.mergeLang({"zh-CN":eZ,"en-US":nZ,"ja-JP":rZ});function iZ(n,t){const e=B("div",["editor-embed-container"],t);B("hr",["editor-embed-hr"],e)}function oZ(n,t,e,r){return r==="html"?"<hr />":r==="markdown"?"---":"------------"}function sZ(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:_.t("dividingLine.type"),icon:zT,order:500,group:"common",subText:Jn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:r}=t;return n.insertEmbed(e,r,tZ,{})}}}function lZ(n,t,e){const{data:r}=e;if(!r||r.embedType!=="dividing-line"||!st(n,t))return null;const i={};return{blockData:{id:it(),type:"embed",embedType:"hr",embedData:i}}}function aZ(){return{abstract:_.t("dividingLine.abstract")}}const cZ={embedType:"hr",createEmbedContent:iZ,convertTo:oZ,getOptions:sZ,convertFrom:lZ,getBlockProperties:aZ},sct="",lct="",uZ={media:{upload:{failed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>',maxSizeFailed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u6587\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6</div>'},load:{failed:'<div class="line-1">{name}\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},fZ={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>',maxSizeFailed:'<div class="line-1">{name} upload failed</div><div class="line-2">The file size exceeds limit. Please choose another file.</div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}},dZ={media:{upload:{failed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>',maxSizeFailed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u30D5\u30A1\u30A4\u30EB\u306E\u30B5\u30A4\u30BA\u304C\u4E0A\u9650\u3092\u8D85\u3048\u3066\u3044\u308B\u305F\u3081\u3001\u4ED6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044</div>'},load:{failed:'<div class="line-1">{name}\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},audio:{menuItem:"\u97F3\u58F0",abstract:"\u97F3\u58F0"},video:{menuItem:"\u52D5\u753B",abstract:"\u52D5\u753B"}}};_.mergeLang({"zh-CN":uZ,"en-US":fZ,"ja-JP":dZ});var Ui=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(Ui||{}),ah=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(ah||{});const PS=10*1024*1024,hZ=["wav","mp3","aac","ogg","webm","flac"],mZ=["ogg","mp4","webm"],gZ=()=>{};function FS(n){var h,C,E,A,v,w;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:r,callbacks:i}=t,o=(C=e==null?void 0:e.audio)!=null?C:hZ,s=(E=e==null?void 0:e.video)!=null?E:mZ,l=(A=r==null?void 0:r.audio)!=null?A:PS,c=(v=r==null?void 0:r.video)!=null?v:PS,d=(w=i==null?void 0:i.onError)!=null?w:gZ;return{allowedMedias:{audio:o,video:s},maxSize:{audio:l,video:c},callbacks:{onError:d}}}function pZ(n,t){const e=o=>o.map(s=>`.${s}`).join(","),{allowedMedias:r}=FS(n),i=r[t];return i?e(i):"*"}function CZ(n,t,e){const{maxSize:r,callbacks:i,allowedMedias:o}=FS(t),{[e]:s}=r,{[e]:l}=o;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,i!=null&&i.onError&&(i==null||i.onError(t,d)),d}const c=Tf(n.name);if(l&&!l.includes(c.toLowerCase())){const d=new Error(`media file is not allowed: ${c}`);throw d.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(t,d)),d}}function EZ(n){return n===ah.Empty||n===ah.Error}const An=D("media");class AZ extends Ve.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,r)=>{if(!r.target||!(r.target instanceof Node)||!(r.target instanceof Element?r.target:r.target.parentElement))return;const o=et(r.target);if(!o||!o.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",ut(o))});m(this,"handleUploadFile",async e=>{p(An,this.abstract,"no abstract"),p(An,this.mediaContainer,"The media element not exist");const{editor:r}=this.options,i=et(this.mediaContainer);p(An,i,"The block element not exist");const o=r.getBlockData(i);try{const{resourceId:s}=await r.doc.uploadResource(e,{onProgress:C=>{this.renderProgress(C,e)}}),{name:l,type:c,size:d}=e,h={...o,embedData:{...o.embedData,src:s,fileName:l,fileSize:d,fileType:c}};r.updateBlockData(i,h)}catch(s){An.error(s),this.emit("mediaError",r,"upload_error",o.id),this.renderRetry(e,s)}ct(i,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){p(An,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){p(An,this.abstract,"no abstract");const{editor:e,createMediaElement:r}=this.options,{mediaIcon:i,mediaName:o}=this.abstract;p(An,this.mediaContainer,"The media element not exist");const s=et(this.mediaContainer);p(An,s,"The block element not exist");const l=e.getBlockData(s),c=B("div",["media-error","embed-selected-content","embed-hover-content"],null),d=B("span",["media-error-icon"],c);d.innerHTML=i;const h=B("div",[],c);h.innerHTML=_.t("media.load.failed",{name:o}),c.appendChild(h);const C=h.querySelector(".retry-upload");return p(An,C,"The element not exist"),e.domEvents.addEventListener(C,"click",(E,A)=>{const v=B("div",["media-element"],null),w=this.getResourceUrl(l),S=r(E,v,l,w);this.unbindMediaEvent(),this.media=S,this.bindMediaEvent(),this.updateMediaContent(v)}),this.setFullScreen(),c}renderRetry(e,r){var E,A;p(An,this.abstract,"no abstract");const{editor:i}=this.options,{mediaIcon:o,mediaName:s}=this.abstract,l=B("div",["media-error","embed-selected-content","embed-hover-content"],null),c=B("span",["media-error-icon"],l);c.innerHTML=o;const d=B("div",[],l);let h=_.t("media.upload.failed",{name:s});(((E=r.response)==null?void 0:E.status)===420||((A=r.response)==null?void 0:A.status)===413)&&(h=_.t("media.upload.maxSizeFailed",{name:s})),d.innerHTML=h,l.appendChild(d);const C=d.querySelector(".retry-upload");C&&i.domEvents.addEventListener(C,"click",()=>{i.readonly||(p(An,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(l),this.setFullScreen()}renderProgress(e,r){p(An,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope .media-progress"),o=e===-1||e===100?100:e;if(i){const{updateProgressElement:s}=this.options;s(i,o)}else{const{createProgressElement:s}=this.options,l=et(this.mediaContainer);p(An,l,"The element not exist"),q(l,"media-block-uploading");const c=B("div",["media-progress"],null);s(c,o,r),this.updateMediaContent(c)}this.setFullScreen()}renderMediaElement(e,r){p(An,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:o,updateMediaElement:s,editor:l}=this.options,c=this.getResourceUrl(e,r);if(i){const d=s(l,i,e,c);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent()}else{const d=B("div",["media-element"],null),h=o(l,d,e,c);this.unbindMediaEvent(),this.media=h,this.bindMediaEvent(),this.updateMediaContent(d)}}renderEmpty(e){p(An,this.abstract,"no abstract"),p(An,this.mediaContainer,"The media element not exist");const r=B("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);r.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(r);const{editor:i}=this.options;i.findBlockById(e.id)&&this.emit("mediaError",i,"empty",e.id),this.setFullScreen()}getResourceUrl(e,r){const{src:i}=e.embedData,{editor:o}=this.options;return o.doc.buildResourceUrl(i,{syncNewResources:async(s,l)=>{var d,h;if(!r)return;await o.doc.addResources([s]);const c=(h=(d=o.doc).getServerMeta)==null?void 0:h.call(d).appId;if(l!==e.embedData.src&&c&&e.embedData.src.includes(c)){const C=et(r);if(C&&!o.readonly&&o.isBlockWritable(C)){const E=Et.default(e);E.embedData.src=s,o.updateBlockData(C,E)}}}})}setFullScreen(){p(An,this.mediaContainer,"The media element not exist"),q(this.mediaContainer,"full-screen")}removeFullScreen(){p(An,this.mediaContainer,"The media element not exist"),ct(this.mediaContainer,"full-screen")}updateBlockAlign(e,r){const i=et(r);p(An,i,"The block element not exist");const{align:o}=e;e.embedType==="video"&&(i.hasAttribute("data-style-align")&&i.removeAttribute("data-style-align"),i.setAttribute("data-style-align",o))}render(e,r){const{src:i}=e.embedData;(!this.mediaContainer||!r.contains(this.mediaContainer))&&(this.mediaContainer=B("div",["media"],r)),this.updateBlockAlign(e,r),EZ(i)?i===ah.Empty&&this.renderEmpty(e):this.renderMediaElement(e,r)}setAbstract(e){this.abstract=e}}D("media-embed");const xZ="left";class KS{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var C;const{containerId:r,blockIndex:i}=e;let o;(C=e.data)!=null&&C.file&&(o=e.data.file);const s=pZ(t,this.embedType);if(o=o!=null?o:await Uc(s,{}),!o)return null;const{mediaType:l}=this.getAbstract();try{CZ(o,t,l)}catch{return null}const c={id:it(),type:"embed",embedType:this.embedType,embedData:{src:ah.Empty}};l==="video"&&(c.align=xZ);const d=t.insertBlock(r,i,c);return await this.getMedia(t,c.id).handleUploadFile(o),d})}getMedia(t,e){const r=t.addCustom(`media-${e}`,()=>new AZ({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return r.setAbstract({...this.getAbstract()}),r}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:r,order:i,group:o}=this.getAbstract();return{name:r,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:i,group:o,subText:Jn(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,r){const{id:i}=r;this.getMedia(t,i).render(r,e)}handleUpdateBlock(t,e,r){const{id:i}=r,o=this.getMedia(t,i),s=zt(e);return o.render(r,s),!0}handleDeleteBlock(t,e){const r=e.id,i=this.getMedia(t,r);i.removeAllListeners(),i.destroy()}convertTo(t,e,r,i){const o=e.embedData,s=t.doc.buildResourceUrl(o.src,{withToken:!0});return i==="html"?`<${o.type} src="${s}" />`:i==="markdown"?`![${o.src}](${s})`:s}}function VS(n,t){const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e),i=B("div",["uploading-progress-bar-value"],r);i.style.width=`${t}%`}function $S(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const bZ=D("media-audio");class vZ extends KS{constructor(){super(...arguments);m(this,"embedType",Ui.AUDIO);m(this,"updateProgressElement",$S);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["audio-container","embed-hover-content","embed-selected-content"],r),l=B("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=o,setTimeout(()=>{this.getMedia(e,i.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:$T,mediaName:_.t(`media.${Ui.AUDIO}.menuItem`),menuItem:_.t(`media.${Ui.AUDIO}.menuItem`),order:800,mediaType:Ui.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${_.t(`media.${Ui.AUDIO}.abstract`)}`}}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .audio-container > audio");return p(bZ,s,"The media element not exist"),s.src!==o&&(s.src=o),s}createProgressElement(e,r){const i=B("audio",[],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,i.src="about:blank",VS(e,r)}}const BZ=new vZ;D("video-resizer");function HS(n){return n&&Le(n)&&sn(n)==="video"}const yZ=50;class Rx{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&HS(e)&&this.disableBlockResize(e),t&&HS(t)&&this.editor.isBlockWritable(t))){const r=this.getVideoElement(t);if(!r)return;this.enableBlockResize(t,r)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const r=t.getBlock();if(!r)return;const i=r.getBoundingClientRect().width,o=Math.min(Math.max(e.width,yZ),i);this.currentResizableElement.style.width=`${o}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const r=this.editor.getBlockData(e),{width:i}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...r,width:i})});this.editor=t,$e.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,$e.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return zt(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${ut(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${ut(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const r=this.editor.addCustom(`${ut(t)}-resizer`,()=>new Pd(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));r.enableResize(t,e),r.removeListener("resizing",this.handleResizing),r.removeListener("resized",this.handleResized),r.addListener("resizing",this.handleResizing),r.addListener("resized",this.handleResized),this.currentResizableElement=e}}const TZ=D("video");class kZ extends KS{constructor(){super(...arguments);m(this,"embedType",Ui.VIDEO);m(this,"updateProgressElement",$S);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["video-container","embed-selected-content","drag-preview-element"],r),l=B("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=o,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new Rx(e)),this.getMedia(e,i.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).removeFullScreen()}),i.width&&(l.style.width=`${i.width}px`),l});m(this,"createProgressElement",(e,r,i)=>{const o=B("video",["progress-video"],e);o.innerHTML="Your browser does not support the <code>audio</code> element.",o.controls=!0,VS(e,r),Mc(i).then(s=>{const l=e.querySelector(".progress-video");l&&l1(e)&&(l.src=s)})})}getAbstract(){return{mediaName:_.t(`media.${Ui.VIDEO}.menuItem`),mediaIcon:HT,menuItem:_.t(`media.${Ui.VIDEO}.menuItem`),order:700,mediaType:Ui.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`${_.t(`media.${Ui.VIDEO}.abstract`)}`}}handleMediaError(e,r,i){const o=e.addCustom("video-resizer",()=>new Rx(e)),s=e.getBlockById(i);o.disableBlockResize(s)}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .video-container > video");p(TZ,s,"The media element not exist"),s.src!==o&&(s.src=o),i.width?s.style.width=`${i.width}px`:s.style.width="";const l=e.getBlockById(i.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new Rx(e)).updateResizer(l)}),s}}const RZ=new kZ,jS=[uA,EA,AA,_k],wx=[_S,RQ,OJ,zJ,ZJ,KK,cZ,RZ,BZ,Oz,cS,AX],zS=[zk,dS,U4];function wZ(n,t,e){var i,o,s,l;yr.level=(i=e.logLevel)!=null?i:Gi.DEBUG;const r=Zf(n,t,{components:{blocks:[...jS,...((o=e==null?void 0:e.components)==null?void 0:o.blocks)||[]],embeds:[...wx,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[...zS,...((l=e.components)==null?void 0:l.boxes)||[]],textRenders:[new WE],options:{...e.componentsOptions}}});return r.readonly=!0,r.addCustom("heading-collapse",()=>new dx(r)),r.addCustom("editor-tooltip",()=>new Ld(r)),r.addListener("clickLink",(c,d,h)=>{var E;if((E=e==null?void 0:e.events)!=null&&E.onClickLink){e.events.onClickLink(c,d,h);return}const C=h.getAttribute("link");C&&(c.readonly||d.ctrlKey||d.metaKey)&&window.open(C,"_blank")}),r}class GS{constructor(t){this.createOptions=t,t.lang&&_.setLang(t.lang)}createHistoryEditor(t,e){return wZ(t,e,this.createOptions)}}function WS(n,{root:t,childDoc:e,doc:r}){var h,C;e.uploadResource=r.uploadResource.bind(r),e.buildResourceUrl=r.buildResourceUrl.bind(r);const i=n.getComponentOptions("comment"),o={image:{defaultAlign:"left"},table:{locatingContainer:t,hideCellMenu:!0,hideToolbar:!0},...i==null?void 0:i.componentsOptions},s=[];n.editorBlocks.forEach(E=>{E.blockType==="text"||E.blockType==="embed"||s.push(E)});const l=[];n.editorEmbeds.forEach(E=>{l.push(E)});const c=[];n.editorBoxes.forEach(E=>{E.boxType==="text"||E.boxType==="br"||E.boxType==="image"||E.boxType==="anchor"||c.push(E)});const d=Zf(t,e,{shortcuts:[sm],components:{blocks:s,commandProviders:[new Fm],decorators:[new dg],embeds:l,boxes:c,options:o}});if(d.input.addHandler(new mg),d.input.addHandler(new PA(d)),d.input.addHandler(new zA(d)),d.input.addHandler(new Sq(d)),d.input.addHandler(new Eg),d.addCustom("image-paste-handler",()=>new NA(d)),me.isMobile||d.addCustom("editor-tooltip",()=>new Ld(d)),n.options.enableContextMenu!==!1&&d.addCustom("editor-context-menu",E=>new qA(E)),(h=n.options.componentsOptions)!=null&&h.mention){const E=n.options.componentsOptions.mention;d.addCustom("mention",()=>new fS(d,{...E}))}if((C=n.options.componentsOptions)!=null&&C.comment){const E=n.options.componentsOptions.comment;E.onCommentEditorClick&&d.addListener("click",E.onCommentEditorClick)}return d}function SZ(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),r=new Set;e.forEach(i=>{const o=et(i);o&&r.add(o)}),r.forEach(i=>{Lq(n,i,t)})}class LZ{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const r=e.groupId;this.getComments().filter(o=>o.groupId===r).length===0&&SZ(this.editor,r)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){return WS(this.editor,{root:t,childDoc:e,doc:this.doc})}allowEdit(t){return t.userId===this.doc.getUser().userId}}class IZ{constructor(t,e){m(this,"listeners",new Set);this.editor=t,this.localDoc=e}get doc(){return this.localDoc.toJSON()}getComments(){return Object.values(this.doc.comments)}getComment(t){return this.doc.comments[t]}getCommentDoc(t){const e=this.doc.comments[t];return zC(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){return WS(this.editor,{root:t,childDoc:e,doc:this.localDoc})}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const DZ={placeholder:{common:{title:"\u8BF7\u8F93\u5165\u6807\u9898",readonlyTitle:"\u8BF7\u8F93\u5165\u6807\u9898",content:"\u70B9\u51FB + \uFF0C\u6216\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6",contentInTable:"\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6"},local:{readonlyTitle:"\u672A\u547D\u540D"}},copyCutProperty:{copy:"\u590D\u5236",cut:"\u526A\u5207",unsafeEnvTips:"\u7531\u4E8E\u5F53\u524D http \u8BBF\u95EE\u73AF\u5883\u4E0B\u7684\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528\u5FEB\u6377\u952E({shortCut}) {operation}",limitedEnvTips:"\u7531\u4E8E\u6D4F\u89C8\u5668\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528 {shortCut} \u7C98\u8D34"}},_Z={placeholder:{common:{title:"Enter a title",readonlyTitle:"Enter a title",content:'Click "+", or enter "/" to insert components quickly',contentInTable:'Enter "/" to insert components quickly'},local:{readonlyTitle:"Untitled"}},copyCutProperty:{copy:"Copy",cut:"Cut",unsafeEnvTips:"Due to the limitations of the current http access environment, please use the shortcut ({shortCut}) {operation}",limitedEnvTips:"Press {shortCut} to paste due to browser restrictions"}},MZ={placeholder:{common:{title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",readonlyTitle:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",content:"\u300C+\u300D\u3092\u30AF\u30EA\u30C3\u30AF\u3059\u308B\u304B\u3001\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059",contentInTable:"\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059"},local:{readonlyTitle:"\u7121\u984C"}},copyCutProperty:{copy:"\u8907\u88FD",cut:"\u5207\u308B",unsafeEnvTips:"HTTP\u74B0\u5883\u306E\u5236\u7D04\u306B\u3088\u308A\u3001{operation}\u3059\u308B\u306B\u306F\u3001\u30B7\u30E7\u30FC\u30C8\u30AB\u30C3\u30C8({shortCut}) \u3092\u3054\u4F7F\u7528\u304F\u3060\u3055\u3044",limitedEnvTips:"\u30D6\u30E9\u30A6\u30B6\u30FC\u306E\u5236\u9650\u306B\u3088\u308A\u3001\u300C{shortCut}\u300D\u3092\u4F7F\u7528\u3057\u3066\u8CBC\u308A\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044"}};_.mergeLang({"zh-CN":DZ,"en-US":_Z,"ja-JP":MZ});const UZ="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",OZ=()=>$p(UZ),NZ=D("image-to-docx");async function PZ(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function qS(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};try{const e=await Mc(new File([t],"",{})),r=await PZ(e);return r.width===void 0||r.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||r.width*n.height/r.height,height:n.height||r.height*n.width/r.width,buffer:t}:{width:r.width,height:r.height,buffer:t}}catch(e){NZ.error(e);return}}function FZ(n,t){let e=n.filter(s=>s!=null);const r=t-(e.length-1)*20,i=.87,o=e.reduce((s,l)=>s+l.width,0);return o>r&&(e=e.map(s=>({width:s.width*r/o,height:s.height*r/o,buffer:s.buffer}))),e.map(s=>({width:s.width*i,height:s.height*i,buffer:s.buffer}))}function KZ(n,t,e){if(!e||typeof e!="object")return;const r=e,i=n.filter(s=>s!=null),o=t-(i.length-1)*20;i.forEach((s,l)=>{if(i.length===1&&r.widthPercent){const d=r.widthPercent,h=s.width;s.width=o*(d/100),s.height*=s.width/h;return}const c=`${l}_flex`;if(r[c]){const d=r[c],h=s.width;s.width=o*d,s.height*=s.width/h}})}function XS(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let r;switch(e%3){case 0:r=Bt.LevelFormat.DECIMAL;break;case 1:r=Bt.LevelFormat.LOWER_LETTER;break;default:r=Bt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:r,text:`%${e+1}. `,alignment:Bt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(e+1)),hanging:Bt.convertInchesToTwip(.2)}}}}})}function VZ(){return[0,1,2,3,4,5,6,7].map(n=>{let t;switch(n%3){case 0:t="\u2022";break;case 1:t="\u25E6";break;default:t="\u25AA";break}return{level:n,format:Bt.LevelFormat.BULLET,text:t,alignment:Bt.AlignmentType.START,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(n+1)),hanging:Bt.convertInchesToTwip(.2)}}}}})}function $Z(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Bt.LevelFormat.BULLET,text:"\u2611",alignment:Bt.AlignmentType.START,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(n+1)),hanging:Bt.convertInchesToTwip(.2)}}}}))}function HZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Bt.LevelFormat.BULLET,text:"\u2610",alignment:Bt.AlignmentType.START,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(n+1)),hanging:Bt.convertInchesToTwip(.2)}}}}))}var ch=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))(ch||{});const jZ=[{levels:XS(),reference:"number-numbering-reference"},{levels:VZ(),reference:"number-bullet-reference"},{levels:$Z(),reference:"checked-bullet-reference"},{levels:HZ(),reference:"unchecked-bullet-reference"}];function zZ(n){switch(n){case"style-color-0":return"d83931";case"style-color-1":return"de7802";case"style-color-2":return"dc9b04";case"style-color-3":return"2ea121";case"style-color-4":return"245bdb";case"style-color-5":return"6425d0";case"style-color-6":return"8f959e";default:return}}function GZ(n){switch(n){case"style-bg-color-1":case"style-bg-color-2":case"style-bg-color-8":case"style-bg-color-9":return"yellow";case"style-bg-color-0":case"style-bg-color-5":return"magenta";case"style-bg-color-3":return"green";case"style-bg-color-4":case"style-bg-color-11":return"blue";case"style-bg-color-6":return"lightGray";case"style-bg-color-7":return"red";case"style-bg-color-10":return"darkGreen";case"style-bg-color-12":return"darkMagenta";case"style-bg-color-13":return"darkGray";default:return}}function WZ(n){switch(n){case"style-bg-color-0":return"fbbab6";case"style-bg-color-1":return"ffdcb0";case"style-bg-color-2":return"fff7a0";case"style-bg-color-3":return"ceefc5";case"style-bg-color-4":return"d1ddfb";case"style-bg-color-5":return"d9cbf8";case"style-bg-color-6":return"eaeaea";case"style-bg-color-7":return"fe837c";case"style-bg-color-8":return"ffbd6a";case"style-bg-color-9":return"ffe662";case"style-bg-color-10":return"a8f393";case"style-bg-color-11":return"98b5ff";case"style-bg-color-12":return"b394f8";case"style-bg-color-13":return"b1b1b1";default:return}}const qZ=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function YS(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(qZ);if(t){const e=s=>{let l=Number(s).toString(16);return l.length<2&&(l=`0${l}`),l},r=e(t[1]),i=e(t[2]),o=e(t[3]);return`${r}${i}${o}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function Un(n,t){if(n&&n.attributes&&n.attributes[t])return n.attributes[t];if(n&&n.attributes&&n.attributes.box&&n.attributes.inputType&&t==="style-underline")return!0}function QS(n,t,e){for(let r=0;r<=e;++r){const i=`${t}${r}`;if(Un(n,i))return i}}function Kg(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function Sx(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function JS(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function XZ(n){const t=Un(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const r of e){const i=r.split(":");if(i.length!==2)continue;const o=i[0].trim().toLowerCase(),s=i[1].trim().toLowerCase();o==="font-size"&&Kg(n,"inline-style-font-size",s),o==="color"&&Kg(n,"inline-style-color",s),o==="background-color"&&Kg(n,"inline-style-background-color",s),o==="font-family"&&Kg(n,"inline-style-font-family",s)}}function YZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function QZ(n){const t=`${Un(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function JZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` ${n.attributes.text} `;if(n.attributes&&n.attributes.box&&n.attributes.inputType)return n.attributes.value?`${n.attributes.value}`:" "}function ZZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function ttt(n){return Un(n,"inline-style-font-family")}function ett(n){const t=Un(n,"inline-style-background-color");return YS(t)}function ntt(n){const t=Un(n,"inline-style-color");return YS(t)}function rtt(n){XZ(n);const t=Un(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!Un(n,"style-code"),link:JS(Un(n,"link")),size:QZ(n),text:t?ZZ(n):JZ(n)||n.insert,bold:!!Un(n,"style-bold"),underline:!!Un(n,"style-underline"),italics:!!Un(n,"style-italic"),strike:!!Un(n,"style-strikethrough"),superScript:!!Un(n,"style-super"),subScript:!!Un(n,"style-sub"),math:Un(n,"type")==="math"?Un(n,"src"):void 0,mention:t,fontFamily:ttt(n),background:ett(n),color:t?"338fe5":zZ(QS(n,"style-color-",6))||ntt(n),highlight:QS(n,"style-bg-color-",13)}}function itt(){return[new Bt.Paragraph({border:{top:{color:"auto",style:Bt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new Bt.Paragraph({spacing:{line:0}})]}function ott(){return new Bt.Paragraph({children:[new Bt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function stt(){return new Bt.Paragraph({children:[new Bt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function ltt(n,t){return new Bt.Paragraph({children:[new Bt.ExternalHyperlink({children:[new Bt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function ZS(n){if(n.heading!=null)return`Heading${n.heading}`}function tL(n){if(n.alignment!=null){if(n.alignment==="center")return Bt.AlignmentType.CENTER;if(n.alignment==="right")return Bt.AlignmentType.RIGHT;if(n.alignment==="left")return Bt.AlignmentType.LEFT}}function att(n){if(n.indent)return{left:Bt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:Bt.convertInchesToTwip(.3*n.padding)}}function ctt(n){return{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function utt(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function eL(n,t){var o;let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const r=n.size||t,i=r!=null?Math.floor(r*1.5+.5):void 0;return n.text=(o=n.text)==null?void 0:o.replace(/\x00/g," "),new Bt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:Bt.UnderlineType.SINGLE}:void 0,italics:n.italics||void 0,strike:n.strike||void 0,superScript:n.superScript||void 0,subScript:n.subScript||void 0,size:i,style:e,font:n.fontFamily?utt(n.fontFamily):void 0,shading:n.background?ctt(n.background):void 0,color:n.color,highlight:GZ(n.highlight)})}function ftt(n,t){if(n.link)return n.link=n.link.replace(/\x00/g," "),new Bt.ExternalHyperlink({children:[eL(n,t)],link:n.link})}async function nL(n,t,e,r,i){const[o]=await i(n,t,e);if(o==null)return;const s=await qS({width:r||0,height:0,src:e},o);return new Bt.ImageRun({data:o,transformation:{width:(s==null?void 0:s.width)||100,height:(s==null?void 0:s.height)||20}})}function dtt(n){if(n.heading||n.heading)return n.heading}function htt(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function mtt(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function gtt(n,t){var r;const e=[];if(n.text&&Array.isArray(n.text)){for(let i=0;i<n.text.length;i++){const o=n.text[i];if(((r=o.attributes)==null?void 0:r.box)===!0&&t){const s=await t(o);if(s){n.text.splice(i+1,0,...s);continue}}e.push(rtt(o))}return e}}function ptt(n){if(n.type==="list"&&n.textOnly!==!0)return{checkbox:n.checkbox,groupId:n.groupId,ordered:!!n.ordered,level:n.level||1,start:n.start||0}}function Ctt(n,t){if(n.type==="embed"&&n.embedType&&Sx(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(r=>{const i=t(r),o=n.embedData[`${i}_width`],s=n.embedData[`${i}_height`];return{src:r,width:o,height:s}})}function Ett(n){if(n.padding)return n.padding}function Att(n){return!!(n.type==="embed"&&n.embedType&&Sx(n.embedType)&&n.embedData&&n.embedData.src)}async function Vg(n,t,e){return{quoted:!!n.quoted,heading:dtt(n),alignment:htt(n),indent:mtt(n),padding:Ett(n),texts:await gtt(n,e),list:ptt(n),images:Ctt(n,t),border:Att(n)}}async function xtt(n,t,e,r){const i=[];if(!n.children)return[];for(const o of n.children){const s=[];for(const l of t.blocks[o])s.push(await Vg(l,e,r));i.push(s)}return i}const btt=D("to-docx");function vtt(n,t){return Array(n).fill(0).map(()=>Array(t).fill(0).map(()=>({cellId:void 0,color:void 0,from:void 0,rowSpan:1,colSpan:1,width:0,originalWidth:void 0,align:void 0})))}function Btt(n,t,e,r){const i=!!n.hasColTitle,o=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let c=0;c<t;c++)for(let d=0;d<e;d++)(i&&d===0||o&&c===0||s&&c%2===1)&&(r[c][d].color=l)}function ytt(n){p(btt,n.children,"no table children");const t=n.rows,e=n.cols,r=n.colsWidth;if(r)for(let s=0;s<r.length;s++)r[s]===0&&(r[s]=100);const i=vtt(t,e);let o=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(i[s][l].originalWidth=r?r[l]:void 0,i[s][l].from!==void 0)continue;const c=n.children[o];o+=1,i[s][l].cellId=c,i[s][l].color=WZ(n[`${c}_background`]),i[s][l].width=r?r[l]:100,i[s][l].align=n[`${c}_align`];const d=n[`${c}_rowSpan`]||1,h=n[`${c}_colSpan`]||1;if(i[s][l].rowSpan=d,i[s][l].colSpan=h,d>1||h>1){let C=0;for(let E=0;E<d;E++)for(let A=0;A<h;A++)E===0&&(C+=r?r[l+A]:80),!(E===0&&A===0)&&(i[s+E][l+A].from=[s,l]);i[s][l].width=C}}return Btt(n,t,e,i),i}async function Ttt(n,t,e,r,i,o,s,l,c,d){async function h(E){if(l&&E.type!=="_exportVirtualBlock"){const A=await l(i,o,E);if(A){await r.addDoc(n,A,d);return}}if(E.type==="text"||E.textOnly===!0){const A=await Vg(E,s,c);await r.addTextBlock(A);return}if(E.type==="code"){const A=await xtt(E,e,s,c);await r.addCodeBlockObject(A);return}if(E.type==="list"&&E.textOnly!==!0){const A=await Vg(E,s,c);await r.addListBlockObject(n,A);return}if(E.type==="embed"&&E.embedType){const A=E,v=A.embedData,w=A.embedType;if(Sx(w)){const S=await Vg(E,s,c);await r.addImagesBlockObject(E,S,d)}else E.embedType==="hr"?r.addSeparatorBlock():E.embedType==="video"?r.addVideoPlaceholder():E.embedType==="audio"?r.addAudioPlaceholder():E.embedType==="webpage"?r.addHyperlinkParagraph(JS(v.src),v.title):r.addOtherEmbedBlock(w,E.embedData);return}if(E.type==="table"){let A=[];if(E.colsWidth)A=E.colsWidth;else{const w=E.cols;A=new Array(w);for(let S=0;S<A.length;S++)A[S]=100;E.colsWidth=A}const v=ytt(E);await r.addTableMatrix(A,v,e),r.addEmptyParagraph()}E.type==="_exportVirtualBlock"&&await r.addVirtualBlock(E.id,e,d)}function C(E){var w;const A=((w=E==null?void 0:E.embedData)==null?void 0:w.exportSpec)||(E==null?void 0:E.exportSpec);if(!A)return[E];const v=[];for(const{type:S,data:U}of A){if(S==="text"){const M={id:it(),text:[{insert:U}],type:"text"};v.push(M);continue}if(S==="image"){const M={id:it(),type:"embed",embedType:"image",align:"left",embedData:{src:U}};v.push(M);continue}if(S==="link"){const M={id:it(),type:"embed",embedType:"webpage",embedData:{src:U.url,title:U.title}};v.push(M);continue}if(S==="block")for(const M of U){if(!e.blocks[M])continue;const nt={id:M,type:"_exportVirtualBlock"};v.push(nt)}}return v}for(const E of t)for(const A of C(E))!A||await h(A)}function ktt(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const Rtt=D("to-docx");class wtt{constructor(t,e,r,i,o,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=r,this.readImageFunc=i,this.convertBlocksFunc=o,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new Bt.Paragraph({heading:ZS(t),alignment:tL(t),children:await this.paragraphsFromBlockTexts(t),indent:att(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new Bt.Paragraph({text:`[${_.t("docx.imageExportFailed")}]`,shading:{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=YZ(this.defaultFontSize,t.heading),r=[];for(const i of t.texts){if(i.link){const o=ftt(i,e);o&&r.push(o);continue}if(i.box&&i.box.type&&i.box.type==="br"){r.push(new Bt.TextRun({text:"",break:1}));continue}if(i.box&&i.box.type&&i.box.type==="image"){const o=await nL(this.appId,this.docId,i.box.src,i.box.width,this.readImageFunc);o&&r.push(o);continue}if(i.math){const o=await nL(this.appId,this.docId,i.math,0,this.readImageFunc);o&&r.push(o);continue}r.push(eL(i,e))}return r}async addCodeBlockObject(t){for(const e of t)for(const r of e){const i={style:Bt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new Bt.Paragraph({style:"Code",border:{left:{...i},right:{...i},top:{...i},bottom:{...i}},children:await this.paragraphsFromBlockTexts(r)}))}}async addListBlockObject(t,e){if(e.list==null)return;let r;const i=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[i])r=this.state.listInstMap[i];else if(r=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[i]=r,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${r}`,l=XS([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:r}),this.state.listRefMap[i]=s}else e.list.ordered?this.state.listRefMap[i]=ch.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[i]=ch.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[i]=ch.UNCHECKED:this.state.listRefMap[i]=ch.BULLET;const o=ZS(e);e.texts&&this.paragraphs.push(new Bt.Paragraph({heading:o,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[i],level:e.list.level-1,instance:r}}))}imageDimWithBufferToImageRun(t){return new Bt.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,r){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:c}=t.embedData;c||this.addEmptyImagePlaceHolder()}return}const i=[],o=await Promise.all(e.images.map(async c=>{const[d,h]=await this.readImageFunc(this.appId,this.docId,c.src);if(d){const C=await qS(c,d);if(C)return C}i.push(h)}));KZ(o,r,t.embedData);const s=FZ(o,r),l={style:Bt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new Bt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:tL(e)||Bt.AlignmentType.CENTER,children:s.map(c=>this.imageDimWithBufferToImageRun(c)).flatMap((c,d,h)=>c==null?[]:h.length-1!==d?[c,new Bt.TextRun({text:" "})]:c)})),i.forEach(c=>{this.addHyperlinkParagraph(c)})}addSeparatorBlock(){itt().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new Bt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(ott())}addAudioPlaceholder(){this.paragraphs.push(stt())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(ltt(t,e))}async addTableMatrix(t,e,r){const i=t.map(o=>o!==0?o*15:1500);this.paragraphs.push(new Bt.Table({rows:await this.generateTableRows(e,r),columnWidths:i}))}async generateRowCells(t,e){const r=[];for(const i of t){const o=i.cellId;if(o===void 0)continue;const s=i.width*.9;r.push(new Bt.TableCell({children:await this.convertBlocksFunc(o,e.blocks[o],e,this.appId,this.docId,this.state,s),columnSpan:i.colSpan,rowSpan:i.rowSpan,width:{type:Bt.WidthType.DXA,size:i.width*15},shading:i.color?{fill:i.color,type:Bt.ShadingType.CLEAR,color:"auto"}:void 0}))}return r}async generateTableRows(t,e){const r=[];for(const i of t)r.push(new Bt.TableRow({children:await this.generateRowCells(i,e)}));return r}async addDoc(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,r);i&&(this.paragraphs=this.paragraphs.concat(i))}async addVirtualBlock(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks[t],e,this.appId,this.docId,this.state,r);this.paragraphs.push(...i)}async addOtherEmbedBlock(){}}class Stt{constructor(t,e,r,i,o,s,l,c){m(this,"convertBlocks",async(t,e,r,i,o,s,l=720)=>{const c=new wtt(i,o,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await Ttt(t,e,r,c,i,o,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),c.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=r,this.readImage=i,this.defaultFontSize=o,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=c}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,r){const i=new Bt.ImportDotx,o=this.templateData?await i.extract(this.templateData):void 0,s=t.blocks.root;p(Rtt,s,"data must have blocks");const l=ktt(),c=await this.convertBlocks("blocks",s,t,e,r,l),d=this.backgroundImageOptions?{default:new Bt.Header({children:[new Bt.Paragraph({children:[new Bt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new Bt.Document({numbering:{config:[...jZ,...l.levelConfigs]},sections:[{headers:d,children:c,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:o});return Bt.Packer.toBlob(h)}}const Ltt=D("editor-to-docx");async function Itt(n,t,e,r){const i=n.doc.buildResourceUrl(r,{withToken:!0});let o=await AS(i);if(!o)return[void 0,i];if(o.type.indexOf("/svg")!==-1){const l=await pS(o);l&&(o=new File([l],o.name))}return[await o.arrayBuffer(),i]}async function Dtt(n,t,e){const r=n.editorBlocks.getBlockClass(e.type);if(r.toStandardDoc)try{return await r.toStandardDoc(n,e,t)}catch(i){Ltt.error(`toStandardDoc error: ${JSON.stringify(i)}`);return}}async function _tt(n,t){const e=t.attributes,r=n.editorBoxes.getBoxClass(e.type);if(r.toStandardText)return r.toStandardText(n,e)}async function Mtt(n,t){let{template:e,download:r,backgroundImageOptions:i}=t!=null?t:{};e||(e=OZ());const o=n.doc.toJSON(),s=(C,E,A)=>Itt(n,C,E,A),l=async(C,E,A)=>Dtt(n,o,A),c=async C=>_tt(n,C),h=await new Stt(e,o,r0.default,s,void 0,l,c,i).convert("_appId","_docId");if(r){const C=URL.createObjectURL(h),E=document.createElement("a");E.setAttribute("download",`${ES(n)}.docx`),E.setAttribute("href",`${C}`),E.click(),E.remove()}return h}const Lx=D("create-editor");async function Utt(n,t){var s,l,c,d,h,C,E,A,v,w,S,U,M,V,nt,Y;p(Lx,n,"app does not exists"),t.lang&&_.setLang(t.lang),yr.level=(s=t.logLevel)!=null?s:Gi.DEBUG;const e=t.onReauth?async()=>{var bt;const X=t.user.userId,ft=t.docId,xt=await((bt=t.onReauth)==null?void 0:bt.call(t,X,ft,t.permission));return{userId:X,docId:ft,permission:t.permission,appId:t.appId,token:xt,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,r={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout,onMaxUsersError:t.onMaxUsersError},i=await hd.load(r),o=Zf(n,i,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,enableContextMenu:t==null?void 0:t.enableContextMenu,components:{blocks:[...jS,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...wx,...((c=t.components)==null?void 0:c.embeds)||[]],boxes:[...zS,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Fm,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new dg,new WC],insertions:[G1],blockHooks:[new DA,new aw,...((C=t.components)==null?void 0:C.blockHooks)||[]],textRenders:[new R4,new WE,...((E=t.components)==null?void 0:E.textRenders)||[]],options:{...t.componentsOptions}},shortcuts:[Vq,mH,kz,fA,Zw,vF,oA,TX,sm,gF,...t.shortcuts||[]],colors:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"]});if(o.editorCommandProviders.registerCommandProvider(new po(o)),o.input.addHandler(new mY),o.input.addHandler(new mg),o.input.addHandler(new zK),o.input.addHandler(new Ez),o.input.addHandler(new xA(o,{hideTitle:t.hideTitle,headingLevel:1,titlePlaceholder:_.t("placeholder.common.title"),contentPlaceholder:_.t("placeholder.common.content"),readonlyTitlePlaceholder:_.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0,applyContentPlaceholder:(A=t.placeholder)==null?void 0:A.applyContentPlaceholder})),o.input.addHandler(new sg(o,(v=t.componentsOptions)==null?void 0:v.quickMenu)),o.input.addHandler(new PA(o)),o.input.addHandler(new zA(o)),o.input.addHandler(new Eg),o.input.addHandler(new Dk),o.doc.registerCallback(new gY(o)),o.addCustom("remote-cursor",()=>new fT(o)),o.addCustom("block-menu",X=>new fw(X)),me.isMobile||o.addCustom("editor-tooltip",()=>new Ld(o)),t!=null&&t.enableComments&&o.addCustom("editor-comments",X=>new k4(X,new LZ(X))),t.enableContextMenu!==!1&&o.addCustom("editor-context-menu",X=>new qA(X)),o.addCustom("create-options",()=>new _b(o,t)),o.addCustom("drop-target",()=>new qd(o)),o.addCustom("list-to-mindmap",()=>new tg(o)),o.addCustom("list-to-mention",()=>new OY(o)),o.addCustom("mobile-helper",()=>new oQ(o)),o.addCustom("code-caret",()=>new uH(o)),o.addCustom("image-paste-handler",()=>new NA(o)),(w=t.componentsOptions)!=null&&w.mention){const X=t.componentsOptions.mention;o.addCustom("mention",()=>new fS(o,X))}if(o.addCustom("heading-collapse",()=>new dx(o)),o.addCustom(lh,X=>new Ax(X)),xu.register(o),qd.register(o),Il.register(o),Tl.register(o),o.addListener("clickLink",(X,ft,xt)=>{var wt;if((wt=t==null?void 0:t.events)!=null&&wt.onClickLink){t.events.onClickLink(X,ft,xt);return}const bt=xt.getAttribute("link");bt&&(X.readonly||ft.ctrlKey||ft.metaKey)&&window.open(bt,"_blank")}),(U=(S=t.componentsOptions)==null?void 0:S.remoteCarets)!=null&&U.onUserChanged){const X=(V=(M=t.componentsOptions)==null?void 0:M.remoteCarets)==null?void 0:V.onUserChanged;o.doc.getRemoteUsers().on("change",ft=>{X(o,ft)})}return(Y=(nt=t.componentsOptions)==null?void 0:nt.templates)!=null&&Y.templates.length&&(o.addListener("docChanged",()=>{Pg(o)}),o.addListener("resize",()=>{Pg(o,{reset:!0})}),setTimeout(()=>{Pg(o)},100)),o.doc.registerCallback({onError:async X=>{if(X.code==="ResetDoc"){Lx.error(`reset doc: ${X.message}`);const ft=await hd.load(r);o.doc.reset(ft)}}}),o.version="1.1.32-beta.2",yr.level===Gi.DEBUG&&(window.setReauthFail=X=>{window.isReauthError=X},window.reConnect=X=>o.doc.externalDoc.client.connection.reConnect(X)),o}function Ott(n){return n.toJSON!==void 0}async function Ntt(n,t,e){var o,s,l,c,d,h,C,E;p(Lx,n,"app does not exists");const r=Ott(t)?t:new TC(t,{serverUrl:e.serverUrl||""});e.lang&&_.setLang(e.lang),yr.level=(o=e.logLevel)!=null?o:Gi.DEBUG;const i=Zf(n,r,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[uA,EA,AA,_k,...(l=(s=e.components)==null?void 0:s.blocks)!=null?l:[]],commandProviders:[new Fm],decorators:[new dg,new WC],embeds:[...wx,...((c=e.components)==null?void 0:c.embeds)||[]],boxes:[zk,dS,U4,...((d=e.components)==null?void 0:d.boxes)||[]],insertions:[G1],blockHooks:[new DA,...((h=e.components)==null?void 0:h.blockHooks)||[]],textRenders:[new R4,new WE,...((C=e.components)==null?void 0:C.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[fA,Zw,oA,sm]});return i.editorCommandProviders.registerCommandProvider(new po(i)),i.input.addHandler(new mg),i.input.addHandler(new xA(i,{hideTitle:e.hideTitle,headingLevel:1,titlePlaceholder:_.t("placeholder.common.title"),contentPlaceholder:_.t("placeholder.common.content"),readonlyTitlePlaceholder:_.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new sg(i,(E=e.componentsOptions)==null?void 0:E.quickMenu)),i.input.addHandler(new PA(i)),i.input.addHandler(new zA(i)),i.input.addHandler(new Eg),i.input.addHandler(new Dk),i.addCustom("block-menu",A=>new fw(A)),me.isMobile||i.addCustom("editor-tooltip",()=>new Ld(i)),i.addCustom("image-paste-handler",()=>new NA(i)),e!=null&&e.enableComments&&i.addCustom("editor-comments",A=>new k4(A,new IZ(A,r))),e.enableContextMenu!==!1&&i.addCustom("editor-context-menu",A=>new qA(A)),i.addCustom("heading-collapse",()=>new dx(i)),i.addListener("clickLink",(A,v,w)=>{var U;if((U=e==null?void 0:e.events)!=null&&U.onClickLink){e.events.onClickLink(A,v,w);return}const S=w.getAttribute("link");S&&(A.readonly||v.ctrlKey||v.metaKey)&&window.open(S,"_blank")}),i.addCustom(lh,A=>new Ax(A)),xu.register(i),i.version="1.1.32-beta.2",i}async function Ptt(n,t,e){var h;const r=n.doc.externalDoc.client.auth,i=await Em.load({auth:r,serverUrl:e});if(!((h=i.getVersionHelper)==null?void 0:h.call(i)))throw new Error("the editor does not support to show versions");const s=n.getCustom("create-options");if(!s)throw new Error("the editor does not support to show versions");const l=s.getData(),c=new GS(l),d=n.addCustom("version-dialog",()=>new Q4(i,c));return d.show(t),d}b.tippy=d9,b.AnchorBox=SB,b.AuthError=fd,b.AuthHeader=ba,b.AutoScroll=b0,b.BaseURLHeader=nu,b.BasicCommands=hK,b.BlockExclusiveHook=aw,b.BlockLockerHook=DA,b.BlockLockerPasteHandler=Eg,b.BlockResizer=Pd,b.BrBox=TB,b.CodeBlock=EA,b.CodeLineBlock=AA,b.CodeTextDecorator=dg,b.DOC_RE_AUTH_KEYS=lh,b.DefaultShortcuts=sm,b.DocIdError=rO,b.DocReAuthCallbacks=Ax,b.DragDrop=Qb,b.DrawioEmbed=_S,b.EditorBlocks=a3,b.EditorBoxes=RB,b.EditorCommandProviders=Ty,b.EditorComplexBlockPosition=xi,b.EditorComplexSelectionRange=Ji,b.EditorDecorators=_B,b.EditorEmbeds=u3,b.EditorInsertions=DB,b.EditorSimpleBlockPosition=pn,b.EditorSimpleSelectionRange=vn,b.EmbedBlock=d3,b.EmbedBlockResizer=nh,b.EnforceWithDocumentTitleHandler=xA,b.EventCallbacks=Lc,b.FILL_CHAR=w8,b.FileExtError=iO,b.GroupOrder=Nk,b.HeadingBlockScrollListener=SY,b.ImageBox=wB,b.InlineBoxCommandProvider=Qk,b.InputtingInsertion=LB,b.LocalDoc=TC,b.LogLevel=Gi,b.Logger=yr,b.MIN_DISTANCE_THRESHOLD=Xb,b.ManualCloseDialog=gd,b.ManualMenu=hl,b.ManualToolbar=md,b.MarkdownInputHandler=mg,b.MaxUserError=PC,b.Mindmap=Zm,b.OnesEditorAutoSuggest=mE,b.OnesEditorCustomDataWrapper=_b,b.OnesEditorExclusiveBlock=Tl,b.OnesEditorHoveringBlock=$e,b.OnesEditorIcons=HO,b.OnesEditorQuickMenu=sg,b.OnesEditorToc=sh,b.OnesEditorTocProvider=Il,b.OnesEditorToolbar=xu,b.OnesEditorTooltip=Ld,b.OnesEditorVersionsDialog=Q4,b.PermissionError=Cm,b.Popup=su,b.ReAuthToolbar=xS,b.RemoteCarets=fT,b.RemoteCaretsDecorator=WC,b.RemoteCaretsInsertion=G1,b.RemoteUsers=td,b.RequestReloadError=dd,b.RichText=Hn,b.ShareDBDoc=hd,b.ShareDBDocVersionsProvider=GS,b.ShareDBServer=Em,b.SimpleCache=Vb,b.StandardEmbedBlockCommands=ix,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=T1,b.TEXT_STYLE_COLOR_PREFIX=y1,b.TableBlock=uA,b.TableBlockCommandProvider=Fm,b.TableShortcuts=fA,b.TextBlock=ar,b.TextBox=yB,b.TextColorItem=S2,b.TextStyleShortcuts=oA,b.TocEmbed=cS,b.ZERO_WIDTH_SPACE_CHAR=_c,b.abbreviation=v0,b.addAttribute=I0,b.addClass=q,b.addCommentToBlock=eh,b.addDays=vI,b.addMetaToDoc=Qf,b.addMonths=bI,b.animateScrollTo=ia,b.applyPlaceholderToBlock=Od,b.assert=p,b.autoShowHideTemplates=Pg,b.bindKeyDownEvent=h0,b.blockToDoc=AC,b.blockToHtml=X1,b.blockToMarkdown=W0,b.blockToText=G0,b.blocksToDoc=q5,b.clearAllSelection=$v,b.clientType=me,b.cloneBlock=sl,b.cloneChildContainer=oC,b.cloneDoc=sC,b.cloneText=gB,b.commentToShareDbComment=GC,b.compareElement=u0,b.comparePosition=p1,b.complexBlockAdjustSelectionPos=w0,b.complexBlockFindNearestChildBlock=x7,b.complexBlockGetAllChildContainers=Dn,b.complexBlockGetBottomChildContainers=p3,b.complexBlockGetDeepFirstChild=h3,b.complexBlockGetFirstSimpleChild=E1,b.complexBlockGetLastSimpleChild=Fc,b.complexBlockGetSelectedContainers=Pc,b.complexBlockGetTopChildContainers=g3,b.containerToDoc=X5,b.continuousScroll=mv,b.convertBlockFrom=k0,b.convertImageFileToPng=pS,b.convertImageSrcToPng=JY,b.converterIntercept=hg,b.copyBlockAttributes=GB,b.copyResourcesFromDoc=yC,b.createBlockAnchor=jo,b.createBlockCaretAnchor=E3,b.createBlockContentElement=fa,b.createBlockElement=Uv,b.createBlockSimpleDocRange=V0,b.createBlockSimpleRange=Ie,b.createBoxContentElement=Pv,b.createBoxElement=Ov,b.createBoxOp=mB,b.createChildContainer=s3,b.createComplexBlockPosition=Ue,b.createComplexDocPos=xB,b.createComplexDocRange=I8,b.createContainer=CB,b.createContainerElement=t1,b.createDeleteOps=uB,b.createEditor=Zf,b.createEditorSelectionRange=Cn,b.createElement=B,b.createEmptyContainer=Yo,b.createEmptyDoc=Xo,b.createEmptyTextBlockData=F0,b.createExpandedRange=a0,b.createIconButton=ea,b.createImage=_p,b.createInsertOps=N0,b.createInsertionContentElement=Vv,b.createInsertionElement=Fv,b.createLocalEditor=Ntt,b.createOnesEditor=Utt,b.createRange=$b,b.createRichText=Ca,b.createRootContainer=o3,b.createSimpleBlockPosition=ht,b.createSimpleDocPos=AB,b.createTextBlockData=no,b.createTextButton=Sa,b.createTextOp=Yr,b.createTextWithReplaceSoftReturn=N1,b.daysAfter=qp,b.deleteText=F1,b.diffDays=BI,b.disablePageScroll=jp,b.docToHtml=VB,b.docToHtmlFragment=jf,b.docToMarkdown=$B,b.docToText=ol,b.downloadImageToFile=AS,b.downloadObjectToFile=vx,b.downloadSvgToString=yS,b.editLink=kd,b.editorAddComment=Dq,b.editorAddTextAttribute=r5,b.editorAutoInsertBlock=WB,b.editorBreakTextBlock=Xc,b.editorClearCompositionText=Z1,b.editorClearSelectedContents=J0,b.editorCopyBlock=vC,b.editorCopyDoc=om,b.editorDeleteBlock=nC,b.editorDeleteBlockText=tC,b.editorDeleteBlockWithoutChildren=Y0,b.editorDeleteChildContainer=w_,b.editorDeleteChildContainers=qB,b.editorFocusToBlock=iC,b.editorFocusToEnd=W_,b.editorGetBlockData=Qo,b.editorGetBlockText=Yn,b.editorGetBlockTextEx=H0,b.editorGetBoxData=vB,b.editorHandleKeyboardEvent=ly,b.editorInsertBlock=qc,b.editorInsertBoxToBlock=jB,b.editorInsertDoc=e5,b.editorInsertDocAt=lC,b.editorInsertText=J1,b.editorInsertTextToBlock=HB,b.editorInsertTextToBlockEx=Q1,b.editorMergeTextBlock=XB,b.editorMoveDown=p5,b.editorMoveEnd=mC,b.editorMoveHome=k5,b.editorMoveLeft=h5,b.editorMoveLineEnd=M5,b.editorMoveLineHome=_5,b.editorMovePageDown=K5,b.editorMovePageUp=F5,b.editorMoveRight=m5,b.editorMoveUp=g5,b.editorMoveWordEnd=B5,b.editorMoveWordLeft=v5,b.editorRangeClearColor=o5,b.editorRangeGetColor=s5,b.editorRangeSetColor=i5,b.editorRemoveTextAttribute=D_,b.editorReplaceBlockText=Z0,b.editorReplaceContainer=n5,b.editorRunOnce=kC,b.editorSelectAll=pC,b.editorSelectContainer=nm,b.editorSelectDown=C5,b.editorSelectEnd=gC,b.editorSelectHome=R5,b.editorSelectLeft=E5,b.editorSelectLineEnd=D5,b.editorSelectLineHome=I5,b.editorSelectPageDown=H5,b.editorSelectPageUp=$5,b.editorSelectRight=A5,b.editorSelectUp=x5,b.editorSelectWordEnd=T5,b.editorSelectWordLeft=y5,b.editorSetTextColor=Yc,b.editorShowFindDialog=BW,b.editorToDocx=Mtt,b.editorUpdateBlockData=tm,b.editorUpdateCompositionText=zB,b.editorUpdateEmbedData=ZB,b.enablePageScroll=zp,b.escapeHtmlText=m0,b.escapeRegExp=Jp,b.escapeSpace=rI,b.exclusiveBlock=SA,b.executeBlockCommand=Qv,b.executeEmbedBlockCommand=Yv,b.executeRangeCommand=yy,b.fileToDataUrl=Mc,b.findAfterOffsetNotType=H1,b.findAllText=CC,b.findBlockByIndex=Rv,b.findEventTargetBlock=zb,b.findInsertionById=Kv,b.findNextOffset=Q8,b.findNextVisibleSimpleBlock=Sy,b.findPrevOffset=Y8,b.findPrevOffsetNotType=$1,b.findPrevSimpleBlockBeforeChildContainer=m3,b.findPrevVisibleSimpleBlock=wy,b.findTarget=Dc,b.findWordEnd=z1,b.findWordLeft=j1,b.format=kf,b.formatBytes=gv,b.formatDate=Yp,b.fragmentToHtml=av,b.fromBase64=vf,b.fromBase64ToBlob=$p,b.fromBase64ToUint8Array=mI,b.fromDocRange=nl,b.fromNowString=Qp,b.genId=it,b.generateEditorContainerId=Zp,b.getAllChildBlocks=v1,b.getAllQuickMenuItems=iA,b.getAllSelectedBlocks=Zi,b.getAttributesAt=Hc,b.getBlockBackground=r1,b.getBlockByIndex=Js,b.getBlockCaretRect=tl,b.getBlockClass=le,b.getBlockClassByType=aa,b.getBlockClientRects=Vo,b.getBlockCommandsWithHook=u1,b.getBlockContent=zt,b.getBlockHeading=If,b.getBlockId=ut,b.getBlockIndex=Rt,b.getBlockInfo=Hd,b.getBlockKind=Ei,b.getBlockMinWidth=jv,b.getBlockNearestRangeFromPoint=x1,b.getBlockOptions=OI,b.getBlockPath=el,b.getBlockProperties=Wv,b.getBlockRangeFromPoint=S0,b.getBlockStyles=UI,b.getBlockTextLength=Ct,b.getBlockTools=ve,b.getBlockType=Ot,b.getBoxContent=o1,b.getBoxId=Nv,b.getBoxTypeFromElement=Lf,b.getChildBlockCount=Xi,b.getChildBlocks=ke,b.getChildOffset=rl,b.getColorFromAttributes=R1,b.getColorFromContent=B0,b.getComplexBlockClass=zr,b.getContainerBlockPath=n3,b.getContainerBlocks=Tv,b.getContainerBlocksElement=wf,b.getContainerById=Ci,b.getContainerId=pt,b.getContainerMinWidth=m1,b.getContainerToolsElement=DI,b.getContainerWidth=l3,b.getDistanceSquare=Ys,b.getElementFromPoint=Pe,b.getElementOffset=xf,b.getElementScale=jr,b.getEmbedType=sn,b.getExistsBlockTools=y0,b.getExistsContainerById=Rf,b.getFileExt=Tf,b.getFirstChildBlock=Me,b.getFirstClientRect=c0,b.getHeadingBlockChildren=Nc,b.getHeadingMenuOptions=tA,b.getHorizontalPadding=Up,b.getInsertionContent=s1,b.getLastChildBlock=Ge,b.getLastClientRect=na,b.getListAllNextBrothers=gu,b.getLogger=D,b.getNextBlock=ae,b.getNextHiddenBlocks=t3,b.getNextValidOffset=ga,b.getNextVisibleBlock=Wr,b.getOffsetFromPoint=Mp,b.getOffsetInfoAfter=Vf,b.getOffsetInfoBefore=j0,b.getOpAt=j3,b.getOpLength=L0,b.getParentBlock=et,b.getParentBlockExcludeSelf=ua,b.getParentBox=i1,b.getParentContainer=at,b.getPrevBlock=He,b.getPrevValidOffset=il,b.getPrevVisibleBlock=Gr,b.getRangeCommands=vy,b.getReferenceClientRect=ak,b.getRootBlock=c1,b.getScrollContainer=gn,b.getSpecialBlockCommands=qv,b.getStandardEmbedBlockProperties=ox,b.getTextAfterOffset=q8,b.getTextAttributes=Y1,b.getTextBeforeOffset=X8,b.getTextBlockChild=Mf,b.getTextBlockClass=Sv,b.getTextBlockContentChildTextLength=Xr,b.getTextBlockContentChildType=e3,b.getTextBlockContentChildren=Qi,b.getTextLength=$n,b.getTextOpLength=B1,b.getTextWidth=E0,b.getToolbar=Gm,b.handleBlockElementUpdated=zv,b.hasAltOnly=cI,b.hasClass=Mt,b.hasCtrlOrCmd=rv,b.hasCtrlOrCmdOnly=aI,b.hashCode=vv,b.hideBlock=Mv,b.hideTemplates=gS,b.htmlToFragment=C0,b.i18n=_,b.includeBigTable=AN,b.injectDocToHtmlFragment=Yf,b.injectStyle=qb,b.inputActions=hM,b.insertEmptyBlock=FI,b.insertEmptyEmbedBlock=f1,b.insertText=qo,b.intersectionCommands=GM,b.isBackspace=ov,b.isBlock=ca,b.isBlockLocked=Cg,b.isBlockLockedByOthers=IA,b.isBlockLockedBySelf=jd,b.isBlockTools=_v,b.isBox=T0,b.isBoxOp=zo,b.isCJK=ev,b.isChildContainer=pi,b.isChildNode=Ee,b.isCodeBlock=Di,b.isCollapsedHeadingBlock=Yi,b.isCollapsedRange=L8,b.isComplexBlockPosition=ha,b.isComplexKindBlock=Pt,b.isContainer=Qs,b.isContainerSelectedAllChildBlocks=j5,b.isControlEvent=sa,b.isDelete=fI,b.isDraggingFiles=A0,b.isElementVisible=d0,b.isEmbedBlock=Le,b.isEmptyContainer=Uf,b.isEmptyDoc=K1,b.isEmptyTextBlock=Be,b.isEmptyTextBlockWithoutCompositionText=Ud,b.isEnterOnly=iv,b.isEscape=p0,b.isExclusiveBlock=$d,b.isExpandedHeadingBlock=Zv,b.isFirefox=Ef,b.isFirstChildBlockInComplexBlock=A7,b.isHeadingBlock=In,b.isHighSurrogate=Z9,b.isInBlock=l1,b.isInBlockTools=Oc,b.isLetter=tv,b.isLowSurrogate=tI,b.isMatchShortcut=Wi,b.isMoveForward=sI,b.isNavigationEvent=oI,b.isNavigationKey=nv,b.isNodeRemoved=Af,b.isNumber=Zb,b.isPrintableKey=Kp,b.isRootBlock=qr,b.isRootContainer=re,b.isSafari=ta,b.isSameDay=Xp,b.isSelectBoxOnly=ni,b.isShiftEnter=uI,b.isShiftTab=hI,b.isShortcutEvent=lI,b.isSimpleBlock=MI,b.isSimpleBlockPosition=bi,b.isSimplePos=EB,b.isSimpleRange=K0,b.isSpace=g0,b.isTab=dI,b.isTextBlockContentBoxChild=Tr,b.isTextBlockContentChild=Df,b.isTextBlockContentInsertionChild=Ho,b.isTextBlockContentTextChild=_f,b.isTextKindBlock=st,b.isTextKindBlockType=Sf,b.isTitleBlock=Ko,b.isToday=pv,b.isValidOffset=lr,b.isVisibleBlock=Zs,b.isYesterday=Cv,b.loadJs=jb,b.loadJsPromise=ra,b.lockers=gi,b.mergeCommands=zm,b.mergeDocs=Ea,b.mergeOps=P1,b.mergeText=k8,b.multiSplitText=G3,b.overflowText=Ev,b.parseShortcut=sv,b.patchNode=Bf,b.pointInRect=oa,b.rangeAddAttribute=Pf,b.rangeGetTextColor=Z3,b.rangeRemoveAttribute=$c,b.rangeSetTextColor=Y3,b.rangeTransformText=q3,b.registerDragDrop=Pp,b.removeAttribute=k1,b.removeClass=ct,b.removeLastBr=v8,b.removePlaceholderFromBlock=_R,b.removeStyle=Wb,b.replaceAll=yI,b.replaceAllCaseInsensitive=TI,b.replaceAllText=G5,b.replaceText=P0,b.requestDownload=x0,b.resetListStart=Cu,b.scrollIntoView=Hf,b.scrollable=hv,b.selectFile=Uc,b.selectedBlockToDoc=rm,b.selectionToDoc=Qc,b.setAttributes=f0,b.setClipboardData=yf,b.setClipboardDataByEvent=CI,b.setColorToAttributes=Q3,b.setDataset=Op,b.setDefaultCursor=bf,b.setStyles=Np,b.shareDBCommentToDocObject=zC,b.shareDBDocCommentToComment=cT,b.shortcutToDisplayText=mn,b.showBlock=n1,b.showDocVersions=Ptt,b.showTemplates=Cx,b.splitText=sr,b.splitToThree=ln,b.stringToDataUrl=Hp,b.stringToObjectUrl=Gp,b.subText=W3,b.textNodeOffsetFromPoint=Hb,b.titleFromEditor=ES,b.toBase64URL=qi,b.toMindmap=Jm,b.toPlainText=Re,b.toPlainTextKeepLength=V1,b.trimChar=Fp,b.unexclusiveBlock=LA,b.unicodeLength=eI,b.unicodeSubstr=nI,b.updateBlockSelection=Hv,b.updateOpAttributes=pB,b.updateTextBlockContent=W8,b.updateUrl=Vp;for(const n in Ve)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>Ve[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
963
+ \`\`\`\`\`\``}return""}const ZJ={embedType:"plantuml",convertFrom:YJ,handleUpdateBlock:XJ,createEmbedContent:qJ,getBlockProperties:QJ,convertTo:JJ},oct="",tZ="hr",eZ={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},nZ={dividingLine:{type:"Dividing-Line",abstract:"Dividing-Line"}},rZ={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};_.mergeLang({"zh-CN":eZ,"en-US":nZ,"ja-JP":rZ});function iZ(n,t){const e=B("div",["editor-embed-container"],t);B("hr",["editor-embed-hr"],e)}function oZ(n,t,e,r){return r==="html"?"<hr />":r==="markdown"?"---":"------------"}function sZ(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:_.t("dividingLine.type"),icon:zT,order:500,group:"common",subText:Jn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:r}=t;return n.insertEmbed(e,r,tZ,{})}}}function lZ(n,t,e){const{data:r}=e;if(!r||r.embedType!=="dividing-line"||!st(n,t))return null;const i={};return{blockData:{id:it(),type:"embed",embedType:"hr",embedData:i}}}function aZ(){return{abstract:_.t("dividingLine.abstract")}}const cZ={embedType:"hr",createEmbedContent:iZ,convertTo:oZ,getOptions:sZ,convertFrom:lZ,getBlockProperties:aZ},sct="",lct="",uZ={media:{upload:{failed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>',maxSizeFailed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u6587\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6</div>'},load:{failed:'<div class="line-1">{name}\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},fZ={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>',maxSizeFailed:'<div class="line-1">{name} upload failed</div><div class="line-2">The file size exceeds limit. Please choose another file.</div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}},dZ={media:{upload:{failed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>',maxSizeFailed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u30D5\u30A1\u30A4\u30EB\u306E\u30B5\u30A4\u30BA\u304C\u4E0A\u9650\u3092\u8D85\u3048\u3066\u3044\u308B\u305F\u3081\u3001\u4ED6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044</div>'},load:{failed:'<div class="line-1">{name}\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},audio:{menuItem:"\u97F3\u58F0",abstract:"\u97F3\u58F0"},video:{menuItem:"\u52D5\u753B",abstract:"\u52D5\u753B"}}};_.mergeLang({"zh-CN":uZ,"en-US":fZ,"ja-JP":dZ});var Ui=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(Ui||{}),ah=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(ah||{});const PS=10*1024*1024,hZ=["wav","mp3","aac","ogg","webm","flac"],mZ=["ogg","mp4","webm"],gZ=()=>{};function FS(n){var h,C,E,A,v,w;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:r,callbacks:i}=t,o=(C=e==null?void 0:e.audio)!=null?C:hZ,s=(E=e==null?void 0:e.video)!=null?E:mZ,l=(A=r==null?void 0:r.audio)!=null?A:PS,c=(v=r==null?void 0:r.video)!=null?v:PS,d=(w=i==null?void 0:i.onError)!=null?w:gZ;return{allowedMedias:{audio:o,video:s},maxSize:{audio:l,video:c},callbacks:{onError:d}}}function pZ(n,t){const e=o=>o.map(s=>`.${s}`).join(","),{allowedMedias:r}=FS(n),i=r[t];return i?e(i):"*"}function CZ(n,t,e){const{maxSize:r,callbacks:i,allowedMedias:o}=FS(t),{[e]:s}=r,{[e]:l}=o;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,i!=null&&i.onError&&(i==null||i.onError(t,d)),d}const c=Tf(n.name);if(l&&!l.includes(c.toLowerCase())){const d=new Error(`media file is not allowed: ${c}`);throw d.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(t,d)),d}}function EZ(n){return n===ah.Empty||n===ah.Error}const An=D("media");class AZ extends Ve.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,r)=>{if(!r.target||!(r.target instanceof Node)||!(r.target instanceof Element?r.target:r.target.parentElement))return;const o=et(r.target);if(!o||!o.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",ut(o))});m(this,"handleUploadFile",async e=>{p(An,this.abstract,"no abstract"),p(An,this.mediaContainer,"The media element not exist");const{editor:r}=this.options,i=et(this.mediaContainer);p(An,i,"The block element not exist");const o=r.getBlockData(i);try{const{resourceId:s}=await r.doc.uploadResource(e,{onProgress:C=>{this.renderProgress(C,e)}}),{name:l,type:c,size:d}=e,h={...o,embedData:{...o.embedData,src:s,fileName:l,fileSize:d,fileType:c}};r.updateBlockData(i,h)}catch(s){An.error(s),this.emit("mediaError",r,"upload_error",o.id),this.renderRetry(e,s)}ct(i,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){p(An,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){p(An,this.abstract,"no abstract");const{editor:e,createMediaElement:r}=this.options,{mediaIcon:i,mediaName:o}=this.abstract;p(An,this.mediaContainer,"The media element not exist");const s=et(this.mediaContainer);p(An,s,"The block element not exist");const l=e.getBlockData(s),c=B("div",["media-error","embed-selected-content","embed-hover-content"],null),d=B("span",["media-error-icon"],c);d.innerHTML=i;const h=B("div",[],c);h.innerHTML=_.t("media.load.failed",{name:o}),c.appendChild(h);const C=h.querySelector(".retry-upload");return p(An,C,"The element not exist"),e.domEvents.addEventListener(C,"click",(E,A)=>{const v=B("div",["media-element"],null),w=this.getResourceUrl(l),S=r(E,v,l,w);this.unbindMediaEvent(),this.media=S,this.bindMediaEvent(),this.updateMediaContent(v)}),this.setFullScreen(),c}renderRetry(e,r){var E,A;p(An,this.abstract,"no abstract");const{editor:i}=this.options,{mediaIcon:o,mediaName:s}=this.abstract,l=B("div",["media-error","embed-selected-content","embed-hover-content"],null),c=B("span",["media-error-icon"],l);c.innerHTML=o;const d=B("div",[],l);let h=_.t("media.upload.failed",{name:s});(((E=r.response)==null?void 0:E.status)===420||((A=r.response)==null?void 0:A.status)===413)&&(h=_.t("media.upload.maxSizeFailed",{name:s})),d.innerHTML=h,l.appendChild(d);const C=d.querySelector(".retry-upload");C&&i.domEvents.addEventListener(C,"click",()=>{i.readonly||(p(An,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(l),this.setFullScreen()}renderProgress(e,r){p(An,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope .media-progress"),o=e===-1||e===100?100:e;if(i){const{updateProgressElement:s}=this.options;s(i,o)}else{const{createProgressElement:s}=this.options,l=et(this.mediaContainer);p(An,l,"The element not exist"),q(l,"media-block-uploading");const c=B("div",["media-progress"],null);s(c,o,r),this.updateMediaContent(c)}this.setFullScreen()}renderMediaElement(e,r){p(An,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:o,updateMediaElement:s,editor:l}=this.options,c=this.getResourceUrl(e,r);if(i){const d=s(l,i,e,c);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent()}else{const d=B("div",["media-element"],null),h=o(l,d,e,c);this.unbindMediaEvent(),this.media=h,this.bindMediaEvent(),this.updateMediaContent(d)}}renderEmpty(e){p(An,this.abstract,"no abstract"),p(An,this.mediaContainer,"The media element not exist");const r=B("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);r.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(r);const{editor:i}=this.options;i.findBlockById(e.id)&&this.emit("mediaError",i,"empty",e.id),this.setFullScreen()}getResourceUrl(e,r){const{src:i}=e.embedData,{editor:o}=this.options;return o.doc.buildResourceUrl(i,{syncNewResources:async(s,l)=>{var d,h;if(!r)return;await o.doc.addResources([s]);const c=(h=(d=o.doc).getServerMeta)==null?void 0:h.call(d).appId;if(l!==e.embedData.src&&c&&e.embedData.src.includes(c)){const C=et(r);if(C&&!o.readonly&&o.isBlockWritable(C)){const E=Et.default(e);E.embedData.src=s,o.updateBlockData(C,E)}}}})}setFullScreen(){p(An,this.mediaContainer,"The media element not exist"),q(this.mediaContainer,"full-screen")}removeFullScreen(){p(An,this.mediaContainer,"The media element not exist"),ct(this.mediaContainer,"full-screen")}updateBlockAlign(e,r){const i=et(r);p(An,i,"The block element not exist");const{align:o}=e;e.embedType==="video"&&(i.hasAttribute("data-style-align")&&i.removeAttribute("data-style-align"),i.setAttribute("data-style-align",o))}render(e,r){const{src:i}=e.embedData;(!this.mediaContainer||!r.contains(this.mediaContainer))&&(this.mediaContainer=B("div",["media"],r)),this.updateBlockAlign(e,r),EZ(i)?i===ah.Empty&&this.renderEmpty(e):this.renderMediaElement(e,r)}setAbstract(e){this.abstract=e}}D("media-embed");const xZ="left";class KS{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var C;const{containerId:r,blockIndex:i}=e;let o;(C=e.data)!=null&&C.file&&(o=e.data.file);const s=pZ(t,this.embedType);if(o=o!=null?o:await Uc(s,{}),!o)return null;const{mediaType:l}=this.getAbstract();try{CZ(o,t,l)}catch{return null}const c={id:it(),type:"embed",embedType:this.embedType,embedData:{src:ah.Empty}};l==="video"&&(c.align=xZ);const d=t.insertBlock(r,i,c);return await this.getMedia(t,c.id).handleUploadFile(o),d})}getMedia(t,e){const r=t.addCustom(`media-${e}`,()=>new AZ({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return r.setAbstract({...this.getAbstract()}),r}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:r,order:i,group:o}=this.getAbstract();return{name:r,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:i,group:o,subText:Jn(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,r){const{id:i}=r;this.getMedia(t,i).render(r,e)}handleUpdateBlock(t,e,r){const{id:i}=r,o=this.getMedia(t,i),s=zt(e);return o.render(r,s),!0}handleDeleteBlock(t,e){const r=e.id,i=this.getMedia(t,r);i.removeAllListeners(),i.destroy()}convertTo(t,e,r,i){const o=e.embedData,s=t.doc.buildResourceUrl(o.src,{withToken:!0});return i==="html"?`<${o.type} src="${s}" />`:i==="markdown"?`![${o.src}](${s})`:s}}function VS(n,t){const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e),i=B("div",["uploading-progress-bar-value"],r);i.style.width=`${t}%`}function $S(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const bZ=D("media-audio");class vZ extends KS{constructor(){super(...arguments);m(this,"embedType",Ui.AUDIO);m(this,"updateProgressElement",$S);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["audio-container","embed-hover-content","embed-selected-content"],r),l=B("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=o,setTimeout(()=>{this.getMedia(e,i.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:$T,mediaName:_.t(`media.${Ui.AUDIO}.menuItem`),menuItem:_.t(`media.${Ui.AUDIO}.menuItem`),order:800,mediaType:Ui.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${_.t(`media.${Ui.AUDIO}.abstract`)}`}}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .audio-container > audio");return p(bZ,s,"The media element not exist"),s.src!==o&&(s.src=o),s}createProgressElement(e,r){const i=B("audio",[],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,i.src="about:blank",VS(e,r)}}const BZ=new vZ;D("video-resizer");function HS(n){return n&&Le(n)&&sn(n)==="video"}const yZ=50;class Rx{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&HS(e)&&this.disableBlockResize(e),t&&HS(t)&&this.editor.isBlockWritable(t))){const r=this.getVideoElement(t);if(!r)return;this.enableBlockResize(t,r)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const r=t.getBlock();if(!r)return;const i=r.getBoundingClientRect().width,o=Math.min(Math.max(e.width,yZ),i);this.currentResizableElement.style.width=`${o}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const r=this.editor.getBlockData(e),{width:i}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...r,width:i})});this.editor=t,$e.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,$e.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return zt(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${ut(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${ut(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const r=this.editor.addCustom(`${ut(t)}-resizer`,()=>new Pd(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));r.enableResize(t,e),r.removeListener("resizing",this.handleResizing),r.removeListener("resized",this.handleResized),r.addListener("resizing",this.handleResizing),r.addListener("resized",this.handleResized),this.currentResizableElement=e}}const TZ=D("video");class kZ extends KS{constructor(){super(...arguments);m(this,"embedType",Ui.VIDEO);m(this,"updateProgressElement",$S);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["video-container","embed-selected-content","drag-preview-element"],r),l=B("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=o,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new Rx(e)),this.getMedia(e,i.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).removeFullScreen()}),i.width&&(l.style.width=`${i.width}px`),l});m(this,"createProgressElement",(e,r,i)=>{const o=B("video",["progress-video"],e);o.innerHTML="Your browser does not support the <code>audio</code> element.",o.controls=!0,VS(e,r),Mc(i).then(s=>{const l=e.querySelector(".progress-video");l&&l1(e)&&(l.src=s)})})}getAbstract(){return{mediaName:_.t(`media.${Ui.VIDEO}.menuItem`),mediaIcon:HT,menuItem:_.t(`media.${Ui.VIDEO}.menuItem`),order:700,mediaType:Ui.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`${_.t(`media.${Ui.VIDEO}.abstract`)}`}}handleMediaError(e,r,i){const o=e.addCustom("video-resizer",()=>new Rx(e)),s=e.getBlockById(i);o.disableBlockResize(s)}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .video-container > video");p(TZ,s,"The media element not exist"),s.src!==o&&(s.src=o),i.width?s.style.width=`${i.width}px`:s.style.width="";const l=e.getBlockById(i.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new Rx(e)).updateResizer(l)}),s}}const RZ=new kZ,jS=[uA,EA,AA,_k],wx=[_S,RQ,OJ,zJ,ZJ,KK,cZ,RZ,BZ,Oz,cS,AX],zS=[zk,dS,U4];function wZ(n,t,e){var i,o,s,l;yr.level=(i=e.logLevel)!=null?i:Gi.DEBUG;const r=Zf(n,t,{components:{blocks:[...jS,...((o=e==null?void 0:e.components)==null?void 0:o.blocks)||[]],embeds:[...wx,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[...zS,...((l=e.components)==null?void 0:l.boxes)||[]],textRenders:[new WE],options:{...e.componentsOptions}}});return r.readonly=!0,r.addCustom("heading-collapse",()=>new dx(r)),r.addCustom("editor-tooltip",()=>new Ld(r)),r.addListener("clickLink",(c,d,h)=>{var E;if((E=e==null?void 0:e.events)!=null&&E.onClickLink){e.events.onClickLink(c,d,h);return}const C=h.getAttribute("link");C&&(c.readonly||d.ctrlKey||d.metaKey)&&window.open(C,"_blank")}),r}class GS{constructor(t){this.createOptions=t,t.lang&&_.setLang(t.lang)}createHistoryEditor(t,e){return wZ(t,e,this.createOptions)}}function WS(n,{root:t,childDoc:e,doc:r}){var h,C;e.uploadResource=r.uploadResource.bind(r),e.buildResourceUrl=r.buildResourceUrl.bind(r);const i=n.getComponentOptions("comment"),o={image:{defaultAlign:"left"},table:{locatingContainer:t,hideCellMenu:!0,hideToolbar:!0},...i==null?void 0:i.componentsOptions},s=[];n.editorBlocks.forEach(E=>{E.blockType==="text"||E.blockType==="embed"||s.push(E)});const l=[];n.editorEmbeds.forEach(E=>{l.push(E)});const c=[];n.editorBoxes.forEach(E=>{E.boxType==="text"||E.boxType==="br"||E.boxType==="image"||E.boxType==="anchor"||c.push(E)});const d=Zf(t,e,{shortcuts:[sm],components:{blocks:s,commandProviders:[new Fm],decorators:[new dg],embeds:l,boxes:c,options:o}});if(d.input.addHandler(new mg),d.input.addHandler(new PA(d)),d.input.addHandler(new zA(d)),d.input.addHandler(new Sq(d)),d.input.addHandler(new Eg),d.addCustom("image-paste-handler",()=>new NA(d)),me.isMobile||d.addCustom("editor-tooltip",()=>new Ld(d)),n.options.enableContextMenu!==!1&&d.addCustom("editor-context-menu",E=>new qA(E)),(h=n.options.componentsOptions)!=null&&h.mention){const E=n.options.componentsOptions.mention;d.addCustom("mention",()=>new fS(d,{...E}))}if((C=n.options.componentsOptions)!=null&&C.comment){const E=n.options.componentsOptions.comment;E.onCommentEditorClick&&d.addListener("click",E.onCommentEditorClick)}return d}function SZ(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),r=new Set;e.forEach(i=>{const o=et(i);o&&r.add(o)}),r.forEach(i=>{Lq(n,i,t)})}class LZ{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const r=e.groupId;this.getComments().filter(o=>o.groupId===r).length===0&&SZ(this.editor,r)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){return WS(this.editor,{root:t,childDoc:e,doc:this.doc})}allowEdit(t){return t.userId===this.doc.getUser().userId}}class IZ{constructor(t,e){m(this,"listeners",new Set);this.editor=t,this.localDoc=e}get doc(){return this.localDoc.toJSON()}getComments(){return Object.values(this.doc.comments)}getComment(t){return this.doc.comments[t]}getCommentDoc(t){const e=this.doc.comments[t];return zC(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){return WS(this.editor,{root:t,childDoc:e,doc:this.localDoc})}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const DZ={placeholder:{common:{title:"\u8BF7\u8F93\u5165\u6807\u9898",readonlyTitle:"\u8BF7\u8F93\u5165\u6807\u9898",content:"\u70B9\u51FB + \uFF0C\u6216\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6",contentInTable:"\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6"},local:{readonlyTitle:"\u672A\u547D\u540D"}},copyCutProperty:{copy:"\u590D\u5236",cut:"\u526A\u5207",unsafeEnvTips:"\u7531\u4E8E\u5F53\u524D http \u8BBF\u95EE\u73AF\u5883\u4E0B\u7684\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528\u5FEB\u6377\u952E({shortCut}) {operation}",limitedEnvTips:"\u7531\u4E8E\u6D4F\u89C8\u5668\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528 {shortCut} \u7C98\u8D34"}},_Z={placeholder:{common:{title:"Enter a title",readonlyTitle:"Enter a title",content:'Click "+", or enter "/" to insert components quickly',contentInTable:'Enter "/" to insert components quickly'},local:{readonlyTitle:"Untitled"}},copyCutProperty:{copy:"Copy",cut:"Cut",unsafeEnvTips:"Due to the limitations of the current http access environment, please use the shortcut ({shortCut}) {operation}",limitedEnvTips:"Press {shortCut} to paste due to browser restrictions"}},MZ={placeholder:{common:{title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",readonlyTitle:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",content:"\u300C+\u300D\u3092\u30AF\u30EA\u30C3\u30AF\u3059\u308B\u304B\u3001\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059",contentInTable:"\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059"},local:{readonlyTitle:"\u7121\u984C"}},copyCutProperty:{copy:"\u8907\u88FD",cut:"\u5207\u308B",unsafeEnvTips:"HTTP\u74B0\u5883\u306E\u5236\u7D04\u306B\u3088\u308A\u3001{operation}\u3059\u308B\u306B\u306F\u3001\u30B7\u30E7\u30FC\u30C8\u30AB\u30C3\u30C8({shortCut}) \u3092\u3054\u4F7F\u7528\u304F\u3060\u3055\u3044",limitedEnvTips:"\u30D6\u30E9\u30A6\u30B6\u30FC\u306E\u5236\u9650\u306B\u3088\u308A\u3001\u300C{shortCut}\u300D\u3092\u4F7F\u7528\u3057\u3066\u8CBC\u308A\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044"}};_.mergeLang({"zh-CN":DZ,"en-US":_Z,"ja-JP":MZ});const UZ="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",OZ=()=>$p(UZ),NZ=D("image-to-docx");async function PZ(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function qS(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};try{const e=await Mc(new File([t],"",{})),r=await PZ(e);return r.width===void 0||r.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||r.width*n.height/r.height,height:n.height||r.height*n.width/r.width,buffer:t}:{width:r.width,height:r.height,buffer:t}}catch(e){NZ.error(e);return}}function FZ(n,t){let e=n.filter(s=>s!=null);const r=t-(e.length-1)*20,i=.87,o=e.reduce((s,l)=>s+l.width,0);return o>r&&(e=e.map(s=>({width:s.width*r/o,height:s.height*r/o,buffer:s.buffer}))),e.map(s=>({width:s.width*i,height:s.height*i,buffer:s.buffer}))}function KZ(n,t,e){if(!e||typeof e!="object")return;const r=e,i=n.filter(s=>s!=null),o=t-(i.length-1)*20;i.forEach((s,l)=>{if(i.length===1&&r.widthPercent){const d=r.widthPercent,h=s.width;s.width=o*(d/100),s.height*=s.width/h;return}const c=`${l}_flex`;if(r[c]){const d=r[c],h=s.width;s.width=o*d,s.height*=s.width/h}})}function XS(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let r;switch(e%3){case 0:r=Bt.LevelFormat.DECIMAL;break;case 1:r=Bt.LevelFormat.LOWER_LETTER;break;default:r=Bt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:r,text:`%${e+1}. `,alignment:Bt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(e+1)),hanging:Bt.convertInchesToTwip(.2)}}}}})}function VZ(){return[0,1,2,3,4,5,6,7].map(n=>{let t;switch(n%3){case 0:t="\u2022";break;case 1:t="\u25E6";break;default:t="\u25AA";break}return{level:n,format:Bt.LevelFormat.BULLET,text:t,alignment:Bt.AlignmentType.START,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(n+1)),hanging:Bt.convertInchesToTwip(.2)}}}}})}function $Z(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Bt.LevelFormat.BULLET,text:"\u2611",alignment:Bt.AlignmentType.START,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(n+1)),hanging:Bt.convertInchesToTwip(.2)}}}}))}function HZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Bt.LevelFormat.BULLET,text:"\u2610",alignment:Bt.AlignmentType.START,style:{paragraph:{indent:{left:Bt.convertInchesToTwip(.3*(n+1)),hanging:Bt.convertInchesToTwip(.2)}}}}))}var ch=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))(ch||{});const jZ=[{levels:XS(),reference:"number-numbering-reference"},{levels:VZ(),reference:"number-bullet-reference"},{levels:$Z(),reference:"checked-bullet-reference"},{levels:HZ(),reference:"unchecked-bullet-reference"}];function zZ(n){switch(n){case"style-color-0":return"d83931";case"style-color-1":return"de7802";case"style-color-2":return"dc9b04";case"style-color-3":return"2ea121";case"style-color-4":return"245bdb";case"style-color-5":return"6425d0";case"style-color-6":return"8f959e";default:return}}function GZ(n){switch(n){case"style-bg-color-1":case"style-bg-color-2":case"style-bg-color-8":case"style-bg-color-9":return"yellow";case"style-bg-color-0":case"style-bg-color-5":return"magenta";case"style-bg-color-3":return"green";case"style-bg-color-4":case"style-bg-color-11":return"blue";case"style-bg-color-6":return"lightGray";case"style-bg-color-7":return"red";case"style-bg-color-10":return"darkGreen";case"style-bg-color-12":return"darkMagenta";case"style-bg-color-13":return"darkGray";default:return}}function WZ(n){switch(n){case"style-bg-color-0":return"fbbab6";case"style-bg-color-1":return"ffdcb0";case"style-bg-color-2":return"fff7a0";case"style-bg-color-3":return"ceefc5";case"style-bg-color-4":return"d1ddfb";case"style-bg-color-5":return"d9cbf8";case"style-bg-color-6":return"eaeaea";case"style-bg-color-7":return"fe837c";case"style-bg-color-8":return"ffbd6a";case"style-bg-color-9":return"ffe662";case"style-bg-color-10":return"a8f393";case"style-bg-color-11":return"98b5ff";case"style-bg-color-12":return"b394f8";case"style-bg-color-13":return"b1b1b1";default:return}}const qZ=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function YS(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(qZ);if(t){const e=s=>{let l=Number(s).toString(16);return l.length<2&&(l=`0${l}`),l},r=e(t[1]),i=e(t[2]),o=e(t[3]);return`${r}${i}${o}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function Un(n,t){if(n&&n.attributes&&n.attributes[t])return n.attributes[t];if(n&&n.attributes&&n.attributes.box&&n.attributes.inputType&&t==="style-underline")return!0}function QS(n,t,e){for(let r=0;r<=e;++r){const i=`${t}${r}`;if(Un(n,i))return i}}function Kg(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function Sx(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function JS(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function XZ(n){const t=Un(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const r of e){const i=r.split(":");if(i.length!==2)continue;const o=i[0].trim().toLowerCase(),s=i[1].trim().toLowerCase();o==="font-size"&&Kg(n,"inline-style-font-size",s),o==="color"&&Kg(n,"inline-style-color",s),o==="background-color"&&Kg(n,"inline-style-background-color",s),o==="font-family"&&Kg(n,"inline-style-font-family",s)}}function YZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function QZ(n){const t=`${Un(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function JZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` ${n.attributes.text} `;if(n.attributes&&n.attributes.box&&n.attributes.inputType)return n.attributes.value?`${n.attributes.value}`:" "}function ZZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function ttt(n){return Un(n,"inline-style-font-family")}function ett(n){const t=Un(n,"inline-style-background-color");return YS(t)}function ntt(n){const t=Un(n,"inline-style-color");return YS(t)}function rtt(n){XZ(n);const t=Un(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!Un(n,"style-code"),link:JS(Un(n,"link")),size:QZ(n),text:t?ZZ(n):JZ(n)||n.insert,bold:!!Un(n,"style-bold"),underline:!!Un(n,"style-underline"),italics:!!Un(n,"style-italic"),strike:!!Un(n,"style-strikethrough"),superScript:!!Un(n,"style-super"),subScript:!!Un(n,"style-sub"),math:Un(n,"type")==="math"?Un(n,"src"):void 0,mention:t,fontFamily:ttt(n),background:ett(n),color:t?"338fe5":zZ(QS(n,"style-color-",6))||ntt(n),highlight:QS(n,"style-bg-color-",13)}}function itt(){return[new Bt.Paragraph({border:{top:{color:"auto",style:Bt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new Bt.Paragraph({spacing:{line:0}})]}function ott(){return new Bt.Paragraph({children:[new Bt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function stt(){return new Bt.Paragraph({children:[new Bt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function ltt(n,t){return new Bt.Paragraph({children:[new Bt.ExternalHyperlink({children:[new Bt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function ZS(n){if(n.heading!=null)return`Heading${n.heading}`}function tL(n){if(n.alignment!=null){if(n.alignment==="center")return Bt.AlignmentType.CENTER;if(n.alignment==="right")return Bt.AlignmentType.RIGHT;if(n.alignment==="left")return Bt.AlignmentType.LEFT}}function att(n){if(n.indent)return{left:Bt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:Bt.convertInchesToTwip(.3*n.padding)}}function ctt(n){return{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function utt(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function eL(n,t){var o;let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const r=n.size||t,i=r!=null?Math.floor(r*1.5+.5):void 0;return n.text=(o=n.text)==null?void 0:o.replace(/\x00/g," "),new Bt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:Bt.UnderlineType.SINGLE}:void 0,italics:n.italics||void 0,strike:n.strike||void 0,superScript:n.superScript||void 0,subScript:n.subScript||void 0,size:i,style:e,font:n.fontFamily?utt(n.fontFamily):void 0,shading:n.background?ctt(n.background):void 0,color:n.color,highlight:GZ(n.highlight)})}function ftt(n,t){if(n.link)return n.link=n.link.replace(/\x00/g," "),new Bt.ExternalHyperlink({children:[eL(n,t)],link:n.link})}async function nL(n,t,e,r,i){const[o]=await i(n,t,e);if(o==null)return;const s=await qS({width:r||0,height:0,src:e},o);return new Bt.ImageRun({data:o,transformation:{width:(s==null?void 0:s.width)||100,height:(s==null?void 0:s.height)||20}})}function dtt(n){if(n.heading||n.heading)return n.heading}function htt(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function mtt(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function gtt(n,t){var r;const e=[];if(n.text&&Array.isArray(n.text)){for(let i=0;i<n.text.length;i++){const o=n.text[i];if(((r=o.attributes)==null?void 0:r.box)===!0&&t){const s=await t(o);if(s){n.text.splice(i+1,0,...s);continue}}e.push(rtt(o))}return e}}function ptt(n){if(n.type==="list"&&n.textOnly!==!0)return{checkbox:n.checkbox,groupId:n.groupId,ordered:!!n.ordered,level:n.level||1,start:n.start||0}}function Ctt(n,t){if(n.type==="embed"&&n.embedType&&Sx(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(r=>{const i=t(r),o=n.embedData[`${i}_width`],s=n.embedData[`${i}_height`];return{src:r,width:o,height:s}})}function Ett(n){if(n.padding)return n.padding}function Att(n){return!!(n.type==="embed"&&n.embedType&&Sx(n.embedType)&&n.embedData&&n.embedData.src)}async function Vg(n,t,e){return{quoted:!!n.quoted,heading:dtt(n),alignment:htt(n),indent:mtt(n),padding:Ett(n),texts:await gtt(n,e),list:ptt(n),images:Ctt(n,t),border:Att(n)}}async function xtt(n,t,e,r){const i=[];if(!n.children)return[];for(const o of n.children){const s=[];for(const l of t.blocks[o])s.push(await Vg(l,e,r));i.push(s)}return i}const btt=D("to-docx");function vtt(n,t){return Array(n).fill(0).map(()=>Array(t).fill(0).map(()=>({cellId:void 0,color:void 0,from:void 0,rowSpan:1,colSpan:1,width:0,originalWidth:void 0,align:void 0})))}function Btt(n,t,e,r){const i=!!n.hasColTitle,o=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let c=0;c<t;c++)for(let d=0;d<e;d++)(i&&d===0||o&&c===0||s&&c%2===1)&&(r[c][d].color=l)}function ytt(n){p(btt,n.children,"no table children");const t=n.rows,e=n.cols,r=n.colsWidth;if(r)for(let s=0;s<r.length;s++)r[s]===0&&(r[s]=100);const i=vtt(t,e);let o=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(i[s][l].originalWidth=r?r[l]:void 0,i[s][l].from!==void 0)continue;const c=n.children[o];o+=1,i[s][l].cellId=c,i[s][l].color=WZ(n[`${c}_background`]),i[s][l].width=r?r[l]:100,i[s][l].align=n[`${c}_align`];const d=n[`${c}_rowSpan`]||1,h=n[`${c}_colSpan`]||1;if(i[s][l].rowSpan=d,i[s][l].colSpan=h,d>1||h>1){let C=0;for(let E=0;E<d;E++)for(let A=0;A<h;A++)E===0&&(C+=r?r[l+A]:80),!(E===0&&A===0)&&(i[s+E][l+A].from=[s,l]);i[s][l].width=C}}return Btt(n,t,e,i),i}async function Ttt(n,t,e,r,i,o,s,l,c,d){async function h(E){if(l&&E.type!=="_exportVirtualBlock"){const A=await l(i,o,E);if(A){await r.addDoc(n,A,d);return}}if(E.type==="text"||E.textOnly===!0){const A=await Vg(E,s,c);await r.addTextBlock(A);return}if(E.type==="code"){const A=await xtt(E,e,s,c);await r.addCodeBlockObject(A);return}if(E.type==="list"&&E.textOnly!==!0){const A=await Vg(E,s,c);await r.addListBlockObject(n,A);return}if(E.type==="embed"&&E.embedType){const A=E,v=A.embedData,w=A.embedType;if(Sx(w)){const S=await Vg(E,s,c);await r.addImagesBlockObject(E,S,d)}else E.embedType==="hr"?r.addSeparatorBlock():E.embedType==="video"?r.addVideoPlaceholder():E.embedType==="audio"?r.addAudioPlaceholder():E.embedType==="webpage"?r.addHyperlinkParagraph(JS(v.src),v.title):r.addOtherEmbedBlock(w,E.embedData);return}if(E.type==="table"){let A=[];if(E.colsWidth)A=E.colsWidth;else{const w=E.cols;A=new Array(w);for(let S=0;S<A.length;S++)A[S]=100;E.colsWidth=A}const v=ytt(E);await r.addTableMatrix(A,v,e),r.addEmptyParagraph()}E.type==="_exportVirtualBlock"&&await r.addVirtualBlock(E.id,e,d)}function C(E){var w;const A=((w=E==null?void 0:E.embedData)==null?void 0:w.exportSpec)||(E==null?void 0:E.exportSpec);if(!A)return[E];const v=[];for(const{type:S,data:U}of A){if(S==="text"){const M={id:it(),text:[{insert:U}],type:"text"};v.push(M);continue}if(S==="image"){const M={id:it(),type:"embed",embedType:"image",align:"left",embedData:{src:U}};v.push(M);continue}if(S==="link"){const M={id:it(),type:"embed",embedType:"webpage",embedData:{src:U.url,title:U.title}};v.push(M);continue}if(S==="block")for(const M of U){if(!e.blocks[M])continue;const nt={id:M,type:"_exportVirtualBlock"};v.push(nt)}}return v}for(const E of t)for(const A of C(E))!A||await h(A)}function ktt(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const Rtt=D("to-docx");class wtt{constructor(t,e,r,i,o,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=r,this.readImageFunc=i,this.convertBlocksFunc=o,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new Bt.Paragraph({heading:ZS(t),alignment:tL(t),children:await this.paragraphsFromBlockTexts(t),indent:att(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new Bt.Paragraph({text:`[${_.t("docx.imageExportFailed")}]`,shading:{type:Bt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=YZ(this.defaultFontSize,t.heading),r=[];for(const i of t.texts){if(i.link){const o=ftt(i,e);o&&r.push(o);continue}if(i.box&&i.box.type&&i.box.type==="br"){r.push(new Bt.TextRun({text:"",break:1}));continue}if(i.box&&i.box.type&&i.box.type==="image"){const o=await nL(this.appId,this.docId,i.box.src,i.box.width,this.readImageFunc);o&&r.push(o);continue}if(i.math){const o=await nL(this.appId,this.docId,i.math,0,this.readImageFunc);o&&r.push(o);continue}r.push(eL(i,e))}return r}async addCodeBlockObject(t){for(const e of t)for(const r of e){const i={style:Bt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new Bt.Paragraph({style:"Code",border:{left:{...i},right:{...i},top:{...i},bottom:{...i}},children:await this.paragraphsFromBlockTexts(r)}))}}async addListBlockObject(t,e){if(e.list==null)return;let r;const i=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[i])r=this.state.listInstMap[i];else if(r=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[i]=r,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${r}`,l=XS([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:r}),this.state.listRefMap[i]=s}else e.list.ordered?this.state.listRefMap[i]=ch.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[i]=ch.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[i]=ch.UNCHECKED:this.state.listRefMap[i]=ch.BULLET;const o=ZS(e);e.texts&&this.paragraphs.push(new Bt.Paragraph({heading:o,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[i],level:e.list.level-1,instance:r}}))}imageDimWithBufferToImageRun(t){return new Bt.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,r){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:c}=t.embedData;c||this.addEmptyImagePlaceHolder()}return}const i=[],o=await Promise.all(e.images.map(async c=>{const[d,h]=await this.readImageFunc(this.appId,this.docId,c.src);if(d){const C=await qS(c,d);if(C)return C}i.push(h)}));KZ(o,r,t.embedData);const s=FZ(o,r),l={style:Bt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new Bt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:tL(e)||Bt.AlignmentType.CENTER,children:s.map(c=>this.imageDimWithBufferToImageRun(c)).flatMap((c,d,h)=>c==null?[]:h.length-1!==d?[c,new Bt.TextRun({text:" "})]:c)})),i.forEach(c=>{this.addHyperlinkParagraph(c)})}addSeparatorBlock(){itt().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new Bt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(ott())}addAudioPlaceholder(){this.paragraphs.push(stt())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(ltt(t,e))}async addTableMatrix(t,e,r){const i=t.map(o=>o!==0?o*15:1500);this.paragraphs.push(new Bt.Table({rows:await this.generateTableRows(e,r),columnWidths:i}))}async generateRowCells(t,e){const r=[];for(const i of t){const o=i.cellId;if(o===void 0)continue;const s=i.width*.9;r.push(new Bt.TableCell({children:await this.convertBlocksFunc(o,e.blocks[o],e,this.appId,this.docId,this.state,s),columnSpan:i.colSpan,rowSpan:i.rowSpan,width:{type:Bt.WidthType.DXA,size:i.width*15},shading:i.color?{fill:i.color,type:Bt.ShadingType.CLEAR,color:"auto"}:void 0}))}return r}async generateTableRows(t,e){const r=[];for(const i of t)r.push(new Bt.TableRow({children:await this.generateRowCells(i,e)}));return r}async addDoc(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,r);i&&(this.paragraphs=this.paragraphs.concat(i))}async addVirtualBlock(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks[t],e,this.appId,this.docId,this.state,r);this.paragraphs.push(...i)}async addOtherEmbedBlock(){}}class Stt{constructor(t,e,r,i,o,s,l,c){m(this,"convertBlocks",async(t,e,r,i,o,s,l=720)=>{const c=new wtt(i,o,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await Ttt(t,e,r,c,i,o,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),c.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=r,this.readImage=i,this.defaultFontSize=o,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=c}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,r){const i=new Bt.ImportDotx,o=this.templateData?await i.extract(this.templateData):void 0,s=t.blocks.root;p(Rtt,s,"data must have blocks");const l=ktt(),c=await this.convertBlocks("blocks",s,t,e,r,l),d=this.backgroundImageOptions?{default:new Bt.Header({children:[new Bt.Paragraph({children:[new Bt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new Bt.Document({numbering:{config:[...jZ,...l.levelConfigs]},sections:[{headers:d,children:c,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:o});return Bt.Packer.toBlob(h)}}const Ltt=D("editor-to-docx");async function Itt(n,t,e,r){const i=n.doc.buildResourceUrl(r,{withToken:!0});let o=await AS(i);if(!o)return[void 0,i];if(o.type.indexOf("/svg")!==-1){const l=await pS(o);l&&(o=new File([l],o.name))}return[await o.arrayBuffer(),i]}async function Dtt(n,t,e){const r=n.editorBlocks.getBlockClass(e.type);if(r.toStandardDoc)try{return await r.toStandardDoc(n,e,t)}catch(i){Ltt.error(`toStandardDoc error: ${JSON.stringify(i)}`);return}}async function _tt(n,t){const e=t.attributes,r=n.editorBoxes.getBoxClass(e.type);if(r.toStandardText)return r.toStandardText(n,e)}async function Mtt(n,t){let{template:e,download:r,backgroundImageOptions:i}=t!=null?t:{};e||(e=OZ());const o=n.doc.toJSON(),s=(C,E,A)=>Itt(n,C,E,A),l=async(C,E,A)=>Dtt(n,o,A),c=async C=>_tt(n,C),h=await new Stt(e,o,r0.default,s,void 0,l,c,i).convert("_appId","_docId");if(r){const C=URL.createObjectURL(h),E=document.createElement("a");E.setAttribute("download",`${ES(n)}.docx`),E.setAttribute("href",`${C}`),E.click(),E.remove()}return h}const Lx=D("create-editor");async function Utt(n,t){var s,l,c,d,h,C,E,A,v,w,S,U,M,V,nt,Y;p(Lx,n,"app does not exists"),t.lang&&_.setLang(t.lang),yr.level=(s=t.logLevel)!=null?s:Gi.DEBUG;const e=t.onReauth?async()=>{var bt;const X=t.user.userId,ft=t.docId,xt=await((bt=t.onReauth)==null?void 0:bt.call(t,X,ft,t.permission));return{userId:X,docId:ft,permission:t.permission,appId:t.appId,token:xt,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,r={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout,onMaxUsersError:t.onMaxUsersError},i=await hd.load(r),o=Zf(n,i,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,enableContextMenu:t==null?void 0:t.enableContextMenu,components:{blocks:[...jS,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...wx,...((c=t.components)==null?void 0:c.embeds)||[]],boxes:[...zS,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Fm,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new dg,new WC],insertions:[G1],blockHooks:[new DA,new aw,...((C=t.components)==null?void 0:C.blockHooks)||[]],textRenders:[new R4,new WE,...((E=t.components)==null?void 0:E.textRenders)||[]],options:{...t.componentsOptions}},shortcuts:[Vq,mH,kz,fA,Zw,vF,oA,TX,sm,gF,...t.shortcuts||[]],colors:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"]});if(o.editorCommandProviders.registerCommandProvider(new po(o)),o.input.addHandler(new mY),o.input.addHandler(new mg),o.input.addHandler(new zK),o.input.addHandler(new Ez),o.input.addHandler(new xA(o,{hideTitle:t.hideTitle,headingLevel:1,titlePlaceholder:_.t("placeholder.common.title"),contentPlaceholder:_.t("placeholder.common.content"),readonlyTitlePlaceholder:_.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0,applyContentPlaceholder:(A=t.placeholder)==null?void 0:A.applyContentPlaceholder})),o.input.addHandler(new sg(o,(v=t.componentsOptions)==null?void 0:v.quickMenu)),o.input.addHandler(new PA(o)),o.input.addHandler(new zA(o)),o.input.addHandler(new Eg),o.input.addHandler(new Dk),o.doc.registerCallback(new gY(o)),o.addCustom("remote-cursor",()=>new fT(o)),o.addCustom("block-menu",X=>new fw(X)),me.isMobile||o.addCustom("editor-tooltip",()=>new Ld(o)),t!=null&&t.enableComments&&o.addCustom("editor-comments",X=>new k4(X,new LZ(X))),t.enableContextMenu!==!1&&o.addCustom("editor-context-menu",X=>new qA(X)),o.addCustom("create-options",()=>new _b(o,t)),o.addCustom("drop-target",()=>new qd(o)),o.addCustom("list-to-mindmap",()=>new tg(o)),o.addCustom("list-to-mention",()=>new OY(o)),o.addCustom("mobile-helper",()=>new oQ(o)),o.addCustom("code-caret",()=>new uH(o)),o.addCustom("image-paste-handler",()=>new NA(o)),(w=t.componentsOptions)!=null&&w.mention){const X=t.componentsOptions.mention;o.addCustom("mention",()=>new fS(o,X))}if(o.addCustom("heading-collapse",()=>new dx(o)),o.addCustom(lh,X=>new Ax(X)),xu.register(o),qd.register(o),Il.register(o),Tl.register(o),o.addListener("clickLink",(X,ft,xt)=>{var wt;if((wt=t==null?void 0:t.events)!=null&&wt.onClickLink){t.events.onClickLink(X,ft,xt);return}const bt=xt.getAttribute("link");bt&&(X.readonly||ft.ctrlKey||ft.metaKey)&&window.open(bt,"_blank")}),(U=(S=t.componentsOptions)==null?void 0:S.remoteCarets)!=null&&U.onUserChanged){const X=(V=(M=t.componentsOptions)==null?void 0:M.remoteCarets)==null?void 0:V.onUserChanged;o.doc.getRemoteUsers().on("change",ft=>{X(o,ft)})}return(Y=(nt=t.componentsOptions)==null?void 0:nt.templates)!=null&&Y.templates.length&&(o.addListener("docChanged",()=>{Pg(o)}),o.addListener("resize",()=>{Pg(o,{reset:!0})}),setTimeout(()=>{Pg(o)},100)),o.doc.registerCallback({onError:async X=>{if(X.code==="ResetDoc"){Lx.error(`reset doc: ${X.message}`);const ft=await hd.load(r);o.doc.reset(ft)}}}),o.version="1.1.32-beta.3",yr.level===Gi.DEBUG&&(window.setReauthFail=X=>{window.isReauthError=X},window.reConnect=X=>o.doc.externalDoc.client.connection.reConnect(X)),o}function Ott(n){return n.toJSON!==void 0}async function Ntt(n,t,e){var o,s,l,c,d,h,C,E;p(Lx,n,"app does not exists");const r=Ott(t)?t:new TC(t,{serverUrl:e.serverUrl||""});e.lang&&_.setLang(e.lang),yr.level=(o=e.logLevel)!=null?o:Gi.DEBUG;const i=Zf(n,r,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[uA,EA,AA,_k,...(l=(s=e.components)==null?void 0:s.blocks)!=null?l:[]],commandProviders:[new Fm],decorators:[new dg,new WC],embeds:[...wx,...((c=e.components)==null?void 0:c.embeds)||[]],boxes:[zk,dS,U4,...((d=e.components)==null?void 0:d.boxes)||[]],insertions:[G1],blockHooks:[new DA,...((h=e.components)==null?void 0:h.blockHooks)||[]],textRenders:[new R4,new WE,...((C=e.components)==null?void 0:C.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[fA,Zw,oA,sm]});return i.editorCommandProviders.registerCommandProvider(new po(i)),i.input.addHandler(new mg),i.input.addHandler(new xA(i,{hideTitle:e.hideTitle,headingLevel:1,titlePlaceholder:_.t("placeholder.common.title"),contentPlaceholder:_.t("placeholder.common.content"),readonlyTitlePlaceholder:_.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new sg(i,(E=e.componentsOptions)==null?void 0:E.quickMenu)),i.input.addHandler(new PA(i)),i.input.addHandler(new zA(i)),i.input.addHandler(new Eg),i.input.addHandler(new Dk),i.addCustom("block-menu",A=>new fw(A)),me.isMobile||i.addCustom("editor-tooltip",()=>new Ld(i)),i.addCustom("image-paste-handler",()=>new NA(i)),e!=null&&e.enableComments&&i.addCustom("editor-comments",A=>new k4(A,new IZ(A,r))),e.enableContextMenu!==!1&&i.addCustom("editor-context-menu",A=>new qA(A)),i.addCustom("heading-collapse",()=>new dx(i)),i.addListener("clickLink",(A,v,w)=>{var U;if((U=e==null?void 0:e.events)!=null&&U.onClickLink){e.events.onClickLink(A,v,w);return}const S=w.getAttribute("link");S&&(A.readonly||v.ctrlKey||v.metaKey)&&window.open(S,"_blank")}),i.addCustom(lh,A=>new Ax(A)),xu.register(i),i.version="1.1.32-beta.3",i}async function Ptt(n,t,e){var h;const r=n.doc.externalDoc.client.auth,i=await Em.load({auth:r,serverUrl:e});if(!((h=i.getVersionHelper)==null?void 0:h.call(i)))throw new Error("the editor does not support to show versions");const s=n.getCustom("create-options");if(!s)throw new Error("the editor does not support to show versions");const l=s.getData(),c=new GS(l),d=n.addCustom("version-dialog",()=>new Q4(i,c));return d.show(t),d}b.tippy=d9,b.AnchorBox=SB,b.AuthError=fd,b.AuthHeader=ba,b.AutoScroll=b0,b.BaseURLHeader=nu,b.BasicCommands=hK,b.BlockExclusiveHook=aw,b.BlockLockerHook=DA,b.BlockLockerPasteHandler=Eg,b.BlockResizer=Pd,b.BrBox=TB,b.CodeBlock=EA,b.CodeLineBlock=AA,b.CodeTextDecorator=dg,b.DOC_RE_AUTH_KEYS=lh,b.DefaultShortcuts=sm,b.DocIdError=rO,b.DocReAuthCallbacks=Ax,b.DragDrop=Qb,b.DrawioEmbed=_S,b.EditorBlocks=a3,b.EditorBoxes=RB,b.EditorCommandProviders=Ty,b.EditorComplexBlockPosition=xi,b.EditorComplexSelectionRange=Ji,b.EditorDecorators=_B,b.EditorEmbeds=u3,b.EditorInsertions=DB,b.EditorSimpleBlockPosition=pn,b.EditorSimpleSelectionRange=vn,b.EmbedBlock=d3,b.EmbedBlockResizer=nh,b.EnforceWithDocumentTitleHandler=xA,b.EventCallbacks=Lc,b.FILL_CHAR=w8,b.FileExtError=iO,b.GroupOrder=Nk,b.HeadingBlockScrollListener=SY,b.ImageBox=wB,b.InlineBoxCommandProvider=Qk,b.InputtingInsertion=LB,b.LocalDoc=TC,b.LogLevel=Gi,b.Logger=yr,b.MIN_DISTANCE_THRESHOLD=Xb,b.ManualCloseDialog=gd,b.ManualMenu=hl,b.ManualToolbar=md,b.MarkdownInputHandler=mg,b.MaxUserError=PC,b.Mindmap=Zm,b.OnesEditorAutoSuggest=mE,b.OnesEditorCustomDataWrapper=_b,b.OnesEditorExclusiveBlock=Tl,b.OnesEditorHoveringBlock=$e,b.OnesEditorIcons=HO,b.OnesEditorQuickMenu=sg,b.OnesEditorToc=sh,b.OnesEditorTocProvider=Il,b.OnesEditorToolbar=xu,b.OnesEditorTooltip=Ld,b.OnesEditorVersionsDialog=Q4,b.PermissionError=Cm,b.Popup=su,b.ReAuthToolbar=xS,b.RemoteCarets=fT,b.RemoteCaretsDecorator=WC,b.RemoteCaretsInsertion=G1,b.RemoteUsers=td,b.RequestReloadError=dd,b.RichText=Hn,b.ShareDBDoc=hd,b.ShareDBDocVersionsProvider=GS,b.ShareDBServer=Em,b.SimpleCache=Vb,b.StandardEmbedBlockCommands=ix,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=T1,b.TEXT_STYLE_COLOR_PREFIX=y1,b.TableBlock=uA,b.TableBlockCommandProvider=Fm,b.TableShortcuts=fA,b.TextBlock=ar,b.TextBox=yB,b.TextColorItem=S2,b.TextStyleShortcuts=oA,b.TocEmbed=cS,b.ZERO_WIDTH_SPACE_CHAR=_c,b.abbreviation=v0,b.addAttribute=I0,b.addClass=q,b.addCommentToBlock=eh,b.addDays=vI,b.addMetaToDoc=Qf,b.addMonths=bI,b.animateScrollTo=ia,b.applyPlaceholderToBlock=Od,b.assert=p,b.autoShowHideTemplates=Pg,b.bindKeyDownEvent=h0,b.blockToDoc=AC,b.blockToHtml=X1,b.blockToMarkdown=W0,b.blockToText=G0,b.blocksToDoc=q5,b.clearAllSelection=$v,b.clientType=me,b.cloneBlock=sl,b.cloneChildContainer=oC,b.cloneDoc=sC,b.cloneText=gB,b.commentToShareDbComment=GC,b.compareElement=u0,b.comparePosition=p1,b.complexBlockAdjustSelectionPos=w0,b.complexBlockFindNearestChildBlock=x7,b.complexBlockGetAllChildContainers=Dn,b.complexBlockGetBottomChildContainers=p3,b.complexBlockGetDeepFirstChild=h3,b.complexBlockGetFirstSimpleChild=E1,b.complexBlockGetLastSimpleChild=Fc,b.complexBlockGetSelectedContainers=Pc,b.complexBlockGetTopChildContainers=g3,b.containerToDoc=X5,b.continuousScroll=mv,b.convertBlockFrom=k0,b.convertImageFileToPng=pS,b.convertImageSrcToPng=JY,b.converterIntercept=hg,b.copyBlockAttributes=GB,b.copyResourcesFromDoc=yC,b.createBlockAnchor=jo,b.createBlockCaretAnchor=E3,b.createBlockContentElement=fa,b.createBlockElement=Uv,b.createBlockSimpleDocRange=V0,b.createBlockSimpleRange=Ie,b.createBoxContentElement=Pv,b.createBoxElement=Ov,b.createBoxOp=mB,b.createChildContainer=s3,b.createComplexBlockPosition=Ue,b.createComplexDocPos=xB,b.createComplexDocRange=I8,b.createContainer=CB,b.createContainerElement=t1,b.createDeleteOps=uB,b.createEditor=Zf,b.createEditorSelectionRange=Cn,b.createElement=B,b.createEmptyContainer=Yo,b.createEmptyDoc=Xo,b.createEmptyTextBlockData=F0,b.createExpandedRange=a0,b.createIconButton=ea,b.createImage=_p,b.createInsertOps=N0,b.createInsertionContentElement=Vv,b.createInsertionElement=Fv,b.createLocalEditor=Ntt,b.createOnesEditor=Utt,b.createRange=$b,b.createRichText=Ca,b.createRootContainer=o3,b.createSimpleBlockPosition=ht,b.createSimpleDocPos=AB,b.createTextBlockData=no,b.createTextButton=Sa,b.createTextOp=Yr,b.createTextWithReplaceSoftReturn=N1,b.daysAfter=qp,b.deleteText=F1,b.diffDays=BI,b.disablePageScroll=jp,b.docToHtml=VB,b.docToHtmlFragment=jf,b.docToMarkdown=$B,b.docToText=ol,b.downloadImageToFile=AS,b.downloadObjectToFile=vx,b.downloadSvgToString=yS,b.editLink=kd,b.editorAddComment=Dq,b.editorAddTextAttribute=r5,b.editorAutoInsertBlock=WB,b.editorBreakTextBlock=Xc,b.editorClearCompositionText=Z1,b.editorClearSelectedContents=J0,b.editorCopyBlock=vC,b.editorCopyDoc=om,b.editorDeleteBlock=nC,b.editorDeleteBlockText=tC,b.editorDeleteBlockWithoutChildren=Y0,b.editorDeleteChildContainer=w_,b.editorDeleteChildContainers=qB,b.editorFocusToBlock=iC,b.editorFocusToEnd=W_,b.editorGetBlockData=Qo,b.editorGetBlockText=Yn,b.editorGetBlockTextEx=H0,b.editorGetBoxData=vB,b.editorHandleKeyboardEvent=ly,b.editorInsertBlock=qc,b.editorInsertBoxToBlock=jB,b.editorInsertDoc=e5,b.editorInsertDocAt=lC,b.editorInsertText=J1,b.editorInsertTextToBlock=HB,b.editorInsertTextToBlockEx=Q1,b.editorMergeTextBlock=XB,b.editorMoveDown=p5,b.editorMoveEnd=mC,b.editorMoveHome=k5,b.editorMoveLeft=h5,b.editorMoveLineEnd=M5,b.editorMoveLineHome=_5,b.editorMovePageDown=K5,b.editorMovePageUp=F5,b.editorMoveRight=m5,b.editorMoveUp=g5,b.editorMoveWordEnd=B5,b.editorMoveWordLeft=v5,b.editorRangeClearColor=o5,b.editorRangeGetColor=s5,b.editorRangeSetColor=i5,b.editorRemoveTextAttribute=D_,b.editorReplaceBlockText=Z0,b.editorReplaceContainer=n5,b.editorRunOnce=kC,b.editorSelectAll=pC,b.editorSelectContainer=nm,b.editorSelectDown=C5,b.editorSelectEnd=gC,b.editorSelectHome=R5,b.editorSelectLeft=E5,b.editorSelectLineEnd=D5,b.editorSelectLineHome=I5,b.editorSelectPageDown=H5,b.editorSelectPageUp=$5,b.editorSelectRight=A5,b.editorSelectUp=x5,b.editorSelectWordEnd=T5,b.editorSelectWordLeft=y5,b.editorSetTextColor=Yc,b.editorShowFindDialog=BW,b.editorToDocx=Mtt,b.editorUpdateBlockData=tm,b.editorUpdateCompositionText=zB,b.editorUpdateEmbedData=ZB,b.enablePageScroll=zp,b.escapeHtmlText=m0,b.escapeRegExp=Jp,b.escapeSpace=rI,b.exclusiveBlock=SA,b.executeBlockCommand=Qv,b.executeEmbedBlockCommand=Yv,b.executeRangeCommand=yy,b.fileToDataUrl=Mc,b.findAfterOffsetNotType=H1,b.findAllText=CC,b.findBlockByIndex=Rv,b.findEventTargetBlock=zb,b.findInsertionById=Kv,b.findNextOffset=Q8,b.findNextVisibleSimpleBlock=Sy,b.findPrevOffset=Y8,b.findPrevOffsetNotType=$1,b.findPrevSimpleBlockBeforeChildContainer=m3,b.findPrevVisibleSimpleBlock=wy,b.findTarget=Dc,b.findWordEnd=z1,b.findWordLeft=j1,b.format=kf,b.formatBytes=gv,b.formatDate=Yp,b.fragmentToHtml=av,b.fromBase64=vf,b.fromBase64ToBlob=$p,b.fromBase64ToUint8Array=mI,b.fromDocRange=nl,b.fromNowString=Qp,b.genId=it,b.generateEditorContainerId=Zp,b.getAllChildBlocks=v1,b.getAllQuickMenuItems=iA,b.getAllSelectedBlocks=Zi,b.getAttributesAt=Hc,b.getBlockBackground=r1,b.getBlockByIndex=Js,b.getBlockCaretRect=tl,b.getBlockClass=le,b.getBlockClassByType=aa,b.getBlockClientRects=Vo,b.getBlockCommandsWithHook=u1,b.getBlockContent=zt,b.getBlockHeading=If,b.getBlockId=ut,b.getBlockIndex=Rt,b.getBlockInfo=Hd,b.getBlockKind=Ei,b.getBlockMinWidth=jv,b.getBlockNearestRangeFromPoint=x1,b.getBlockOptions=OI,b.getBlockPath=el,b.getBlockProperties=Wv,b.getBlockRangeFromPoint=S0,b.getBlockStyles=UI,b.getBlockTextLength=Ct,b.getBlockTools=ve,b.getBlockType=Ot,b.getBoxContent=o1,b.getBoxId=Nv,b.getBoxTypeFromElement=Lf,b.getChildBlockCount=Xi,b.getChildBlocks=ke,b.getChildOffset=rl,b.getColorFromAttributes=R1,b.getColorFromContent=B0,b.getComplexBlockClass=zr,b.getContainerBlockPath=n3,b.getContainerBlocks=Tv,b.getContainerBlocksElement=wf,b.getContainerById=Ci,b.getContainerId=pt,b.getContainerMinWidth=m1,b.getContainerToolsElement=DI,b.getContainerWidth=l3,b.getDistanceSquare=Ys,b.getElementFromPoint=Pe,b.getElementOffset=xf,b.getElementScale=jr,b.getEmbedType=sn,b.getExistsBlockTools=y0,b.getExistsContainerById=Rf,b.getFileExt=Tf,b.getFirstChildBlock=Me,b.getFirstClientRect=c0,b.getHeadingBlockChildren=Nc,b.getHeadingMenuOptions=tA,b.getHorizontalPadding=Up,b.getInsertionContent=s1,b.getLastChildBlock=Ge,b.getLastClientRect=na,b.getListAllNextBrothers=gu,b.getLogger=D,b.getNextBlock=ae,b.getNextHiddenBlocks=t3,b.getNextValidOffset=ga,b.getNextVisibleBlock=Wr,b.getOffsetFromPoint=Mp,b.getOffsetInfoAfter=Vf,b.getOffsetInfoBefore=j0,b.getOpAt=j3,b.getOpLength=L0,b.getParentBlock=et,b.getParentBlockExcludeSelf=ua,b.getParentBox=i1,b.getParentContainer=at,b.getPrevBlock=He,b.getPrevValidOffset=il,b.getPrevVisibleBlock=Gr,b.getRangeCommands=vy,b.getReferenceClientRect=ak,b.getRootBlock=c1,b.getScrollContainer=gn,b.getSpecialBlockCommands=qv,b.getStandardEmbedBlockProperties=ox,b.getTextAfterOffset=q8,b.getTextAttributes=Y1,b.getTextBeforeOffset=X8,b.getTextBlockChild=Mf,b.getTextBlockClass=Sv,b.getTextBlockContentChildTextLength=Xr,b.getTextBlockContentChildType=e3,b.getTextBlockContentChildren=Qi,b.getTextLength=$n,b.getTextOpLength=B1,b.getTextWidth=E0,b.getToolbar=Gm,b.handleBlockElementUpdated=zv,b.hasAltOnly=cI,b.hasClass=Mt,b.hasCtrlOrCmd=rv,b.hasCtrlOrCmdOnly=aI,b.hashCode=vv,b.hideBlock=Mv,b.hideTemplates=gS,b.htmlToFragment=C0,b.i18n=_,b.includeBigTable=AN,b.injectDocToHtmlFragment=Yf,b.injectStyle=qb,b.inputActions=hM,b.insertEmptyBlock=FI,b.insertEmptyEmbedBlock=f1,b.insertText=qo,b.intersectionCommands=GM,b.isBackspace=ov,b.isBlock=ca,b.isBlockLocked=Cg,b.isBlockLockedByOthers=IA,b.isBlockLockedBySelf=jd,b.isBlockTools=_v,b.isBox=T0,b.isBoxOp=zo,b.isCJK=ev,b.isChildContainer=pi,b.isChildNode=Ee,b.isCodeBlock=Di,b.isCollapsedHeadingBlock=Yi,b.isCollapsedRange=L8,b.isComplexBlockPosition=ha,b.isComplexKindBlock=Pt,b.isContainer=Qs,b.isContainerSelectedAllChildBlocks=j5,b.isControlEvent=sa,b.isDelete=fI,b.isDraggingFiles=A0,b.isElementVisible=d0,b.isEmbedBlock=Le,b.isEmptyContainer=Uf,b.isEmptyDoc=K1,b.isEmptyTextBlock=Be,b.isEmptyTextBlockWithoutCompositionText=Ud,b.isEnterOnly=iv,b.isEscape=p0,b.isExclusiveBlock=$d,b.isExpandedHeadingBlock=Zv,b.isFirefox=Ef,b.isFirstChildBlockInComplexBlock=A7,b.isHeadingBlock=In,b.isHighSurrogate=Z9,b.isInBlock=l1,b.isInBlockTools=Oc,b.isLetter=tv,b.isLowSurrogate=tI,b.isMatchShortcut=Wi,b.isMoveForward=sI,b.isNavigationEvent=oI,b.isNavigationKey=nv,b.isNodeRemoved=Af,b.isNumber=Zb,b.isPrintableKey=Kp,b.isRootBlock=qr,b.isRootContainer=re,b.isSafari=ta,b.isSameDay=Xp,b.isSelectBoxOnly=ni,b.isShiftEnter=uI,b.isShiftTab=hI,b.isShortcutEvent=lI,b.isSimpleBlock=MI,b.isSimpleBlockPosition=bi,b.isSimplePos=EB,b.isSimpleRange=K0,b.isSpace=g0,b.isTab=dI,b.isTextBlockContentBoxChild=Tr,b.isTextBlockContentChild=Df,b.isTextBlockContentInsertionChild=Ho,b.isTextBlockContentTextChild=_f,b.isTextKindBlock=st,b.isTextKindBlockType=Sf,b.isTitleBlock=Ko,b.isToday=pv,b.isValidOffset=lr,b.isVisibleBlock=Zs,b.isYesterday=Cv,b.loadJs=jb,b.loadJsPromise=ra,b.lockers=gi,b.mergeCommands=zm,b.mergeDocs=Ea,b.mergeOps=P1,b.mergeText=k8,b.multiSplitText=G3,b.overflowText=Ev,b.parseShortcut=sv,b.patchNode=Bf,b.pointInRect=oa,b.rangeAddAttribute=Pf,b.rangeGetTextColor=Z3,b.rangeRemoveAttribute=$c,b.rangeSetTextColor=Y3,b.rangeTransformText=q3,b.registerDragDrop=Pp,b.removeAttribute=k1,b.removeClass=ct,b.removeLastBr=v8,b.removePlaceholderFromBlock=_R,b.removeStyle=Wb,b.replaceAll=yI,b.replaceAllCaseInsensitive=TI,b.replaceAllText=G5,b.replaceText=P0,b.requestDownload=x0,b.resetListStart=Cu,b.scrollIntoView=Hf,b.scrollable=hv,b.selectFile=Uc,b.selectedBlockToDoc=rm,b.selectionToDoc=Qc,b.setAttributes=f0,b.setClipboardData=yf,b.setClipboardDataByEvent=CI,b.setColorToAttributes=Q3,b.setDataset=Op,b.setDefaultCursor=bf,b.setStyles=Np,b.shareDBCommentToDocObject=zC,b.shareDBDocCommentToComment=cT,b.shortcutToDisplayText=mn,b.showBlock=n1,b.showDocVersions=Ptt,b.showTemplates=Cx,b.splitText=sr,b.splitToThree=ln,b.stringToDataUrl=Hp,b.stringToObjectUrl=Gp,b.subText=W3,b.textNodeOffsetFromPoint=Hb,b.titleFromEditor=ES,b.toBase64URL=qi,b.toMindmap=Jm,b.toPlainText=Re,b.toPlainTextKeepLength=V1,b.trimChar=Fp,b.unexclusiveBlock=LA,b.unicodeLength=eI,b.unicodeSubstr=nI,b.updateBlockSelection=Hv,b.updateOpAttributes=pB,b.updateTextBlockContent=W8,b.updateUrl=Vp;for(const n in Ve)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>Ve[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});