@ones-editor/editor 1.1.0-beta.4 → 1.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -21,10 +21,10 @@ Available method signatures are:
|
|
|
21
21
|
`).map((i,o)=>{const l=o===0&&(t==null?void 0:t.firstLineAsTitle)?{heading:1}:void 0;return mi(i,l)})},meta:{},comments:{}}}function f1(n){const t=n.blocks.root;if(t.length!==1)return!1;const e=t[0];return!(!e.text||fn(e.text))}function P3(n,t){const e=J();return n.localInsertChildContainers([{containerId:e,blocks:t}]),e}function no(n,t){return P3(n,[Zd(t)])}function F3(n){return typeof n.offset=="number"}function Jd(n){return F3(n.anchor)}function T8(n){return Jd(n)&&n.anchor.offset===n.focus.offset&&n.anchor.blockId===n.focus.blockId}function K3(n,t){return{blockId:n,offset:t}}function th(n,t){const e=K3(n,t);return{anchor:e,focus:e}}function V3(n,t){return{blockId:n,childContainerId:t}}function y8(n,t){const e=V3(n,t);return{anchor:e,focus:e}}const k8=I("block-to-text");function R8(n,t,e){let r="";return t.forEach(i=>{if(p(k8,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 w8=I("block-to-text");function S8(n,t,e){let r="";return t.forEach(i=>{if(p(w8,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 L8(n,t,e){const r=t.text||[];let o=S8(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 I8(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 D8(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 _8=I("block-to-text");function M8(n,t,e){let r="";return t.forEach(i=>{if(p(_8,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(x=>x.startsWith("style-bg-color-"));d&&(c+=`background-color: ${D8(d)};`);const h=Object.keys(o).find(x=>x.startsWith("style-color-"));h&&(c+=`color: ${I8(h)};`),o.link&&(s=`<a href="${o.link}">${s}</a>`);let C=l.map(x=>`<${x}>`).join(""),E=l.reverse().map(x=>`</${x}>`).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 ma=I("text-block");function U8(n,t,e,r,i){const{text:o}=i;p(ma,o,"no text for text block");const s=Ks(r,"div");return zd(n,t,i.id,s,o),s}function O8(n,t,e){p(ma,e,"no text to update");const r=Ks(null,"div");zd(n,Ko(t),st(t),r,e);const i=Ot(t);jc(i,r)}function N8(n,t,e){return K7(n,t,e)}function $3(n,t){let e="";return t.forEach(r=>{var i,o;if(!!r.insert){if(r.attributes&&r.attributes.box===!0){const s=n.getBoxById(r.attributes.id),l=(o=(i=n.editorBoxes.getBoxClass(r.attributes.type)).getBoxProperties)==null?void 0:o.call(i,n,s);e+=l!=null&&l.abstract?` [${l.abstract}] `:" ";return}e+=r.insert}}),e.trim()}function P8(n,t){p(ma,et(n,t),"block in not textBlock");const e=n.selection.range;let r="";if(e.isCollapsed()){const i=n.getBlockText(t);r=$3(n,i)}else{const i=st(t),o=fi(n,{simpleBlockOnly:!0}).find(s=>st(s.block)===i);if(o&&!re(n,o.block)){p(ma,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}=qe(s,d,h);r=$3(n,C)}}}return{abstract:r.trim()}}function F8(n,t,e,r){return p(ma,t.text,"no text for text block"),r==="text"?R8(n,t.text,e):r==="markdown"?L8(n,t,e):M8(n,t.text,e)}function K8(n,t){const e=gt.default(t);e.id=J();const{text:r}=e;return p(ma,r,"no text for text block"),r.forEach(i=>{i.insert&&i.attributes&&i.attributes.box===!0&&(i.attributes.id=J())}),{blocks:{root:[e]},meta:{},comments:{}}}const Mn={blockType:"text",blockKind:"text",createBlockContent:U8,getBlockTextLength:tu,getRangeFromPoint:m8,moveCaret:f8,updateSelection:V7,clearSelection:$7,getCaretRect:Xn,getClientRects:N8,setBlockText:O8,getBlockProperties:P8,convertTo:F8,blockToDoc:K8},V8=zd,eh=I("action-helper");function jo(n,t){const e=it(t),r=ft(e),i=bt(t);return n.doc.getBlockData(r,i)}function bn(n,t){p(eh,et(n,t),"not a text kind block");const r=jo(n,t).text;return p(eh,r,"no text in block"),r}function nh(n,t,e){return In(bn(n,t),e).left}function H3(n,t){const e=nt(t);p(eh,e,"no parent block");const r=bn(n,e),i=rv(t),o=r.find(s=>{const l=s.attributes;return l?l.box&&l.id===i:!1});return p(eh,o,"failed to find box"),o.attributes}const Ae=I("block-text");function $8(n,t,e){p(Ae,et(n,t),"not a text kind block"),p(Ae,_n(t,e),"not a valid offset"),p(Ae,e>=0&&e<dt(n,t),`invalid offset: ${e}`);const i=Ws(t,e)-e;i===0&&p(Ae,!1,`no text after offset: ${e}`);const o=bn(n,t),{middle:s}=qe(o,e,i);p(Ae,s.length===1,"failed to split text to 3 parts");const l=s[0];return zs(l)?" ":(p(Ae,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function H8(n,t,e){p(Ae,et(n,t),"not a text kind block"),p(Ae,_n(t,e),"not a valid offset"),p(Ae,e>0&&e<=dt(n,t),`invalid offset: ${e}`);const r=Ho(t,e),i=e-r;i===0&&p(Ae,!1,`no text before offset: ${e}`);const o=bn(n,t),{middle:s}=qe(o,r,i);p(Ae,s.length===1,"failed to split text to 3 parts");const l=s[0];return zs(l)?" ":(p(Ae,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function rh(n,t,e){p(Ae,et(n,t),"not a text kind block"),p(Ae,_n(t,e),"not a valid offset"),p(Ae,e>0&&e<=dt(n,t),`invalid offset: ${e}`);const r=Ho(t,e),i=e-r;i===0&&p(Ae,!1,`no text before offset: ${e}`);const o=bn(n,t),{middle:s}=qe(o,r,i);p(Ae,s.length===1,"failed to split text to 3 parts");const l=s[0];return zs(l)?{op:l,charType:"box",offset:r,length:1}:{op:l,charType:Td(l.insert)?"space":"text",offset:r,length:l.insert.length}}function ou(n,t,e){p(Ae,et(n,t),"not a text kind block"),p(Ae,_n(t,e),"not a valid offset"),p(Ae,e>=0&&e<dt(n,t),`invalid offset: ${e}`);const i=Ws(t,e)-e;i===0&&p(Ae,!1,`no text after offset: ${e}`);const o=bn(n,t),{middle:s}=qe(o,e,i);p(Ae,s.length===1,"failed to split text to 3 parts");const l=s[0];return zs(l)?{op:l,charType:"box",offset:e,length:1}:{op:l,charType:Td(l.insert)?"space":"text",offset:e,length:l.insert.length}}function j8(n,t,e,r){let i=e;for(;i>0;){const o=rh(n,t,i);if(o.charType===r)return o;i-=o.length}return null}function z8(n,t,e,r){const i=dt(n,t);let o=e;for(;o<i;){const s=ou(n,t,o);if(s.charType===r)return s;o+=s.length}return null}function d1(n,t,e,r){let i=e;for(;i>0;){const o=rh(n,t,i);if(o.charType!==r)return o;i-=o.length}return null}function h1(n,t,e,r){const i=dt(n,t);let o=e;for(;o<i;){const s=ou(n,t,o);if(s.charType!==r)return s;o+=s.length}return null}function m1(n,t,e){if(p(Ae,et(n,t),"invalid blok type"),re(n,t))return 0;const r=rh(n,t,e);if(r.charType==="box")return e-1;let i=e;if(r.charType==="space"){const s=d1(n,t,i,"space");if(!s||s.offset===0)return 0;if(s.charType==="box")return s.offset;i=s.offset}const o=d1(n,t,i,"text");return o?o.offset+o.length:0}function g1(n,t,e){if(p(Ae,et(n,t),"invalid blok type"),re(n,t))return 0;const r=ou(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 dt(n,t);if(s.charType==="box")return s.offset;i=s.offset}const o=h1(n,t,i,"text");return o?o.offset:dt(n,t)}const j3=I("text-box");function G8(n,t,e,r){p(j3,r.text,`no text for text box data: ${JSON.stringify(r)}`),p(j3,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(r)}`),B("span",[],e,r.text)}function W8(n,t,e,r){var i;return(i=t.text)!=null?i:""}const z3={boxType:"text",updateBoxContent:G8,convertTo:W8},q8="data:image/svg+xml;base64,Cjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBkPSJNMTguMjQ0NSA2QzE3LjgyNzQgNiAxNy41MzYzIDYuMjkxMTcgMTcuNTM2MyA2LjcwODI2QzE3LjUzNjMgNi45ODM3IDE3LjU1OTkgNy4yMzU1MyAxNy41NTk5IDcuNjEzMjdDMTcuNTU5OSAxMC4yODExIDE2LjYyMzQgMTEuMzc0OSAxMy45NzkyIDExLjM3NDlIOC45NDI2Nkw3LjEyNDc5IDExLjQ4NTFMOS41NDA3NSA5LjI4MTYyTDExLjE5MzQgNy41OTc1M0MxMS4zMjcxIDcuNDcxNjEgMTEuMzk4IDcuMjgyNzQgMTEuMzk4IDcuMDkzODdDMTEuMzk4IDYuNjkyNTIgMTEuMDk4OSA2LjQwMTM1IDEwLjY5NzYgNi40MDEzNUMxMC41MDg3IDYuNDAxMzUgMTAuMzM1NiA2LjQ3MjE4IDEwLjE3ODIgNi42MjE3TDUuMjQzOTYgMTEuNTQ4MUM1LjA4NjU3IDExLjcwNTUgNSAxMS44OTQzIDUgMTIuMDkxMUM1IDEyLjI4NzggNS4wODY1NyAxMi40NzY3IDUuMjQzOTYgMTIuNjI2MkwxMC4xNjI1IDE3LjUzNjhDMTAuMzM1NiAxNy43MDk5IDEwLjUwODcgMTcuNzgwOCAxMC42OTc2IDE3Ljc4MDhDMTEuMDk4OSAxNy43ODA4IDExLjM5OCAxNy40ODk2IDExLjM5OCAxNy4wODgzQzExLjM5OCAxNi44OTE1IDExLjMyNzEgMTYuNzEwNSAxMS4xOTM0IDE2LjU4NDZMOS41NDA3NSAxNC45MDA1TDcuMTMyNjYgMTIuNjk3TDguOTQyNjYgMTIuODA3MkgxNC4wNTc5QzE3LjU1OTkgMTIuODA3MiAxOSAxMS4yNDExIDE5IDcuNjc2MjJDMTkgNy4yMzU1MyAxOC45OTIxIDYuODY1NjUgMTguOTM3IDYuNjEzODNDMTguODc0MSA2LjI5OTA0IDE4LjY3NzMgNiAxOC4yNDQ1IDZaIiBmaWxsPSIjQjJCQ0NEIi8+Cjwvc3ZnPgo=";function X8(n,t,e,r){fg(q8,[],e),B("br",[],e)}function Q8(n,t,e,r){return r==="text"?`
|
|
23
23
|
`:r==="html"?"<br>":r==="markdown"?`
|
|
24
|
-
`:""}const G3={boxType:"br",updateBoxContent:X8,convertTo:Q8},W3=I("editor-boxes");class q3{constructor(t){g(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,r=this.boxes.get(e);p(W3,!r,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return p(W3,e,`unknown box type: ${t}`),e}createBox(t,e){const r=nv(e),i=iv(r);return this.getBoxClass(e.type).updateBoxContent(this.editor,r,i,e),r}forEach(t){this.boxes.forEach(t)}}function Y8(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 X3={boxType:"image",updateBoxContent:Y8},Z8="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9InJnYigxNzgsIDE4OCwgMjA1KSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0ibTE3IDE1IDEuNTUgMS41NWMtLjk2IDEuNjktMy4zMyAzLjA0LTUuNTUgMy4zN1YxMWgzVjloLTNWNy44MkMxNC4xNiA3LjQgMTUgNi4zIDE1IDVjMC0xLjY1LTEuMzUtMy0zLTNTOSAzLjM1IDkgNWMwIDEuMy44NCAyLjQgMiAyLjgyVjlIOHYyaDN2OC45MmMtMi4yMi0uMzMtNC41OS0xLjY4LTUuNTUtMy4zN0w3IDE1bC00LTN2M2MwIDMuODggNC45MiA3IDkgN3M5LTMuMTIgOS03di0zbC00IDN6TTEyIDRjLjU1IDAgMSAuNDUgMSAxcy0uNDUgMS0xIDEtMS0uNDUtMS0xIC40NS0xIDEtMXoiPjwvcGF0aD4KPC9zdmc+Cg==";function J8(n,t,e){z(e,"editor-box-anchor"),fg(Z8,[],e)}const Q3={boxType:"anchor",updateBoxContent:J8};function tD(n,t,e,r){B("span",[],e,r.text)}const Y3={insertionType:"inputting",updateInsertionContent:tD},Z3=I("editor-insertion");class J3{constructor(t){g(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,r=this.insertions.get(e);p(Z3,!r,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return p(Z3,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const r=ov(e.type,e.id,e.attributes),i=lv(r);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,r,i,e),r}}class eD{constructor(t){g(this,"cursors",new Map);g(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=sv(this.editor,e);i&&ot(i,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function nD(n,t,e,r){var l;const i=r;Date.now()-i.time<5*1e3&&(n.addCustom("active-cursors",d=>new eD(d)).add(i.id,i.time),z(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 p1={insertionType:"remote-cursor",updateInsertionContent:nD};class t5{constructor(t){g(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=gt.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=gt.default(c))}}}),{insertions:i,text:r}}}const C1=I("editor-input");class rD{constructor(t,e){g(this,"editor");g(this,"composing",!1);g(this,"callbacks");g(this,"inputElement");g(this,"handleDocumentClick",t=>{const e=this.editor.rootContainer,r=t.target;if(r&&e.contains(r)&&!Hs(r)){this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus();return}this.editor.emit("blur",this.editor),this.callbacks.onBlur()});g(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&this.editor.contains(t)&&!Hs(t)||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});g(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});g(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});g(this,"handleCompositionstart",t=>{!this.editor.isWritable()||(this.composing=!0,this.callbacks.onCompositionStart(t))});g(this,"handleCompositionend",t=>{$c()?setTimeout(()=>{this.composing=!1},100):this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});g(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="")}});g(this,"handleKeyDown",t=>{if(console.log("handleKeyDown"),!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}!this.editor.isWritable()||setTimeout(()=>{this.composing||(this.inputElement.value="")})}});g(this,"handleCopy",t=>{this.callbacks.onCopy(t)});g(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onCut(t),C1.debug("on cut")});g(this,"handlePaste",t=>{if(t.target instanceof HTMLInputElement&&this.inputElement===t.target){if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)}});g(this,"handlePasteText",(t,e)=>{this.callbacks.onPasteText(t,e)});this.editor=t,this.callbacks=e;const r=B("input",["editor-input"],t.contentElement);r.type="text",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)}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),t.oncut=null}getInput(){return this.inputElement}focus(){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),he.isMobileSafari?(this.inputElement.focus(),z(this.editor.rootElement,"active")):setTimeout(()=>{this.inputElement.focus(),z(this.editor.rootElement,"active")})}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(C1,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,r,i,o)}defaultHandleKeydown(t,e){return p(C1,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}forEach(t){this.callbacks.forEach(t)}}function e5(n){const t=n.rootElement,e=t.getBoundingClientRect(),r=ur(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,x=0-e.top+C,v=n.input.inputElement;v.style.left=`${E/r}px`,v.style.top=`${x/r}px`}const E1=I("editor-caret");function iD(){const t=window.navigator.userAgent.match(/Firefox\/(\d+)\./);return t?Number.parseInt(t[1],10):null}class oD{constructor(t){g(this,"editor");g(this,"caretElem");g(this,"handleReadOnlyChanged",()=>{this.update()});if(this.editor=t,this.caretElem=B("div",["editor-cursor"],this.editor.contentElement),he.isFirefox){const e=iD();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 _e))return!1;const e=this.editor.getBlockById(t.blockId);return!!et(this.editor,e)}update(){if(ub(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",e5(this.editor);return}const{range:e}=this.editor.selection;p(E1,e.isCollapsed,"range is not collapsed");const r=e.start;p(E1,r instanceof _e,"only simple block position can has caret");const i=this.editor.getBlockById(r.blockId);p(E1,et(this.editor,i),"only text kind block can has caret");let o;const s=i.querySelector("span.inputting-insertion");s?(o=Is(s),o=new DOMRect(o.right,o.top,1,o.height)):o=Xn(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`,he.isMobileSafari&&(h.style.left=`${c-4}px`,h.style.height=`${o.height}px`);const E=cn(i,{horizontal:!0}).getBoundingClientRect(),x=E.left-l.left,v=x+E.width;c<x||c>v?(e5(this.editor),t.style.display="none"):t.style.display=""}}function sD(n){uv(n),n.selection.range.getSelectedBlocks().forEach(t=>fv(n,t.block,t.start,t.end))}const lD=I("editor-dom");function n5(n){return cn(n.rootContainer).clientHeight}function aD(n){return n.getFirstBlock().getBoundingClientRect().top}function cD(n){return n.getLastBlock().getBoundingClientRect().bottom}function ih(n){const e=cn(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 uD(n,t){const e=ih(n),r=n.getBlockById(t.blockId),o=_r(n,r,t);return Ms(e,o.x,o.y)&&Ms(e,o.right,o.bottom)}function r5(n,t){const e=ih(n),r=t.getBoundingClientRect();return r.top>=e.top&&r.top<=e.bottom||r.bottom<=e.bottom&&r.bottom>=e.top}function i5(n,t){const e=ih(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 fD(n,t){const e=ih(n),r=t.getBoundingClientRect();return Ms(e,r.x,r.y)||Ms(e,r.right,r.bottom)}function dD(n){if(!pg(n.rootContainer)){lD.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);fD(n,E)||E.scrollIntoView();return}if(e.range.start.blockId===e.range.end.blockId){const C=n.getBlockById(e.range.start.blockId);if(Re(C)&&r5(n,C)&&i5(n,C)>=95)return;const E=Ud(C);if(_t(n,E)&&r5(n,C)){if(i5(n,C)>=95)return;const x=Gt(E);if(x){_s(x,{elementToScroll:cn(n.rootContainer)});return}}}const i=r,o=n.getBlockById(i.blockId);if(uD(n,i))return;if(Re(o)){const C=Gt(o);if(C){["image"].includes(un(o))?setTimeout(()=>{_s(C,{elementToScroll:cn(n.rootContainer)})},500):_s(C,{elementToScroll:cn(n.rootContainer)});return}}const s=_r(n,o,i),l=o.getBoundingClientRect(),c=ne(o),d=B("div",["editor-block-anchor"],c),h=ur(o);d.style.top=`${(s.top-l.top)/h}px`,_s(d,{elementToScroll:cn(n.rootContainer)}),setTimeout(()=>{d.remove()},200)}function hD(n,t){if(t.isCollapsed())return!1;const e=ke(n.rootContainer),r=Ze(n.rootContainer),{start:i,end:o}=t;return i.blockId===st(e)&&i.offset===0&&o.blockId===st(r)&&o.offset===dt(n,r)}const o5=I("range-in-block");function s5(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 l5(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=me(t);if(o){for(;o&&!r.has(st(o));)o=me(o);p(o5,o,"no prev block while deleting a block"),i=ve(n,o,dt(n,o))}else{const s=Gt(t);p(o5,s,"no prev and next block while deleting a block"),i=ve(n,s,0)}return i}const mD=I("block-to-html");function A1(n,t,e,r){const i=Ns(n,t.type);if(i.convertTo)return i.convertTo(n,t,e,"html",r);if(i.blockKind!=="text")return`[${t.type}]`;p(mD,t.text,"no text");const o=ce(t.text);return`<div>${Bd(o)}</div>`}const a5=I("block-to-text");function gD(n,t,e){let r="";return t.forEach(i=>{if(p(a5,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 oh(n,t,e,r){const i=Ns(n,t.type);return i.convertTo?i.convertTo(n,t,e,"text",r):i.blockKind!=="text"?`[${t.type}]`:(p(a5,t.text,"no text"),gD(n,t.text,e))}function x1(n,t,e,r){const i=Ns(n,t.type);return i.convertTo?i.convertTo(n,t,e,"markdown",r):oh(n,t,e,r)}function sh(n,t){return t.blocks.root.map((i,o)=>A1(n,i,t,[{containerId:"root",blockIndex:o}])).join(`
|
|
25
|
-
`)}function
|
|
26
|
-
`)}function
|
|
27
|
-
`)}const pD=I("get-text-position");function ga(n,t){const e=t!=null?t:n.selection.range.start;e instanceof _e||p(pD,!1,`invalid insert pos type: ${typeof e}`);const{blockId:r}=e,i=n.getBlockById(r),o=bt(i),s=it(i),l=ft(s),{offset:c}=e;return{block:i,container:s,containerId:l,blockIndex:o,offset:c}}const pa=I("insert-text");function b1(n,t,e,r){var s;const i=n.doc.getBlockData(t,e);if(p(pa,i,"no block data"),p(pa,i.text,"no block text"),fn(i.text)===0)return p(pa,r===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,i.id);if(r===0)return;const o=qe(i.text,r-1,1).middle;if(!((s=o[0].attributes)!=null&&s.box))return o[0].attributes}function CD(n,t,e){const r=it(t),i=ft(r),o=bt(t);return b1(n,i,o,e)}function f5(n,t,e,r,i){const o=it(t),s=ft(o),l=bt(t),c=CD(n,t,e),d=Qd(e,r,c!=null?c:null);return n.doc.localUpdateBlockText(s,l,d,i),bn(n,t)}function d5(n,t,e,r){const i=it(t),o=ft(i),s=bt(t),l=Qd(e," ",r);return n.doc.localUpdateBlockText(o,s,l),bn(n,t)}function ED(n,t){let e=0;if(t===0)return!1;for(let r=0;r<n.length;r++){const i=n[r];p(pa,typeof i.insert=="string","invalid text op, no insert");const o=e+Hd(i);if(o===t)return!1;if(o>t)return!0;e=o}return!1}function v1(n,t,e,r,i){const o=n.doc.getBlockData(e,r);p(pa,o,"no block data"),p(pa,o.text,"no block text");const s=b1(n,e,r,i);s&&Object.keys(s).includes("link")&&(ED(o.text,i)||delete s.link);const l=Qd(i,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,r,l),bn(n,n.getBlockById(o.id))}function B1(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:r,offset:i}=ga(n);v1(n,t,e,r,i)}const lh=I("update-composition-text");function h5(n){const t=n.selection.range.start;t instanceof _e||p(lh,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,r=n.getBlockById(e);p(lh,et(n,r),"not a text kind block");const i=it(r),o=ft(i),s=bt(r),l=n.doc.getBlockData(o,s);p(lh,l,"no block data in doc"),p(lh,l.text,"no text data in text block");const c=Ot(r);zd(n,Ko(r),e,c,l.text)}function T1(n){O7(n)}function Ca(n,t,e,r,i,o){return n.doc.localInsertBlock(t,e,r,i,o),n.getBlockById(r.id)}const su=I("delete-block-text");function y1(n,t,e,r,i){if(!n.isBlockWritable(t))return su.error("block is not writable"),0;p(su,et(n,t),"block is not a text kind block");const o=it(t),s=ft(o),l=bt(t),c=n.doc.getBlockData(s,l);p(su,c,"no block data in doc"),p(su,c.text,"no text data in text block");let d=e;_n(t,e)||(d=Ho(t,d));let h=e+r;p(su,h<=dt(n,t),`invalid offset and count: ${e}, ${r}`),_n(t,h)||(h=Ws(t,h));const C=h-d,E=L3(d,C);return n.doc.localUpdateBlockText(s,l,E,i),console.log("delete"),C}const k1=I("break-text-block");function m5(n,t){const r=n.getBlockData(t).quoted;return r?{quoted:r}:{}}function Ea(n,t,e,r){p(k1,et(n,t),`block is not a text kind block: ${It(t)}`),p(k1,e>=0&&e<=dt(n,t),`invalid offset: ${e}`);const i=it(t),o=ft(i),s=bt(t),l=r!=null&&r.copyBlockAttributes?m5(n,t):{};if(!(r!=null&&r.forceInsertAfter)&&(e===0||e===dt(n,t))){const x=e===0?s:s+1,v={...mi(""),...l,...r==null?void 0:r.newBlockData},R=ve(n,t.id,0),L=Ca(n,o,x,v,R);return{block:t,newBlock:L}}p(k1,_n(t,e),"not a valid offset");const c=bn(n,t),{right:d}=In(c,e),h=fn(d);h>0&&y1(n,t,e,h);const C={...mi(d),...l,...r==null?void 0:r.newBlockData},E=Ca(n,o,s+1,C,ve(n,C.id,0));return{block:t,newBlock:E}}const AD=I("prepare-insert-new-block");function xD(n,t,e){if(t&&e!==void 0&&e!==null){const d=n.getContainerById(t),h=Ce(d);return p(AD,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=ft(it(i)),e=bt(i),!et(n,i))return{containerId:t,blockIndex:e+1};const s=r.offset;if(s===0||s===dt(n,i))return{containerId:t,blockIndex:s===0?e:e+1};const c=Ea(n,i,s).newBlock;return{containerId:t,blockIndex:bt(c)}}const bD=I("auto-insert-block");function g5(n,t,e,r,i,o){const s=xD(n,e,r);p(bD,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},c={anchor:l,focus:l};return Ca(n,s.containerId,s.blockIndex,t,i!=null?i:c,o)}const vD=I("delete-block");function ah(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(r=>{n.getChildContainerData(r).forEach(o=>{ah(n,o,e)})}))}function ch(n,t,e){const r=it(t),i=ft(r),o=bt(t),s=n.doc.getBlockData(i,o);return p(vD,s,"no block data in doc"),n.doc.localDeleteBlock(i,o,We(n,{anchor:e.start,focus:e.end})),s}function R1(n,t,e){return n.undoManager.runInGroup(()=>{const r=it(t);Lr(r)===1&&n.insertTextBlock("",ft(r),0);let i=e?Vo(n,e):null;if(!i){const l=n.selection.range;s5(t,l)?i=l5(n,t):i=l}const o=ch(n,t,i),s=[];return ah(n,o,s),s.length>0&&n.doc.localDeleteChildContainers(s),o})}function BD(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(i=>{ah(n,i,e)}),n.doc.localDeleteChildContainers(e)}function p5(n,t){const e=[...t];t.forEach(r=>{n.doc.getContainerBlocks(r).forEach(o=>{ah(n,o,e)})}),n.doc.localDeleteChildContainers(e)}const w1=I("merge-text-block");function C5(n,t,e){p(w1,et(n,t),"only text block can be merged"),p(w1,et(n,e),"only text block can be merged");const r=jo(n,t),i=jo(n,e),o=r.text,s=i.text;p(w1,o&&s,"block data has no text");const l=it(t),c=ft(l),d=bt(t),h=dt(n,t),C=v1(n,s,c,d,h),E=ve(n,t,fn(o));return R1(n,e,E),C}const gi=I("clear-selected-contents");function uh(n,t){p(gi,et(n,t.block),"not a text kind block");const{start:e,end:r}=t;p(gi,e.isSimple(),"not a simple block position"),p(gi,r.isSimple(),"not a simple block position");const i=e.offset,o=r.offset;p(gi,i<=o,`invalid delete text offset: ${i}, ${o}`),i!==o&&n.deleteTextFromBlock(t.block,i,o-i)}function E5(n,t,e){const r=ft(t),i=Ce(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 TD(n,t){const{block:e,start:r,end:i}=t;if(et(n,e)){uh(n,t);return}if(Re(e)||r.isSimple()){p(gi,i.isSimple(),"invalid range");const s=it(e),l=bt(e),c=n.insertTextBlock("",ft(s),l);n.selection.selectBlock(c,0),n.deleteBlock(e);return}p(gi,_t(n,e),"invalid block kind"),p(gi,!r.isSimple()&&!i.isSimple(),"invalid range"),la(n,e,r,i),n.selection.range.getSelectedContainers().forEach((s,l)=>{E5(n,s,{focus:l===0})})}function yD(n){if(!n.isWritable())return;const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(p(gi,e.length>0,"no selected block"),e.length===1){TD(n,e[0]);return}const r=e[0],i=r.block,o=it(i);p(gi,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(et(n,i)){uh(n,r);const h=ve(n,r.block,r.start.offset);if(e.slice(1,e.length-1).reverse().forEach(E=>n.deleteBlock(E.block)),et(n,l)){uh(n,s),n.mergeTextBlock(i,l,{focus:!0}),n.selection.setRange(h);return}n.deleteBlock(l),n.selection.setRange(h);return}if(et(n,l)){uh(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===Lr(o)){E5(n,o,{focus:!0});return}const c=me(i),d=Gt(l);p(gi,c||d,"no prev or next block"),e.forEach(h=>n.deleteBlock(h.block))}function S1(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),yD(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}const kD=I("core");function A5(n,t,e,r){const i=it(t),o=ft(i),s=bt(t);return n.doc.localUpdateBlockText(o,s,e,r),setTimeout(()=>{n.selection.updateSelection(null)}),bn(n,t)}function x5(n,t,e,r){if(!n.isBlockWritable(t)){kD.error("block is not writable");return}const i=n.getBlockText(t),o=dn.diff(i,e);A5(n,t,o,r)}function fh(n,t,e){const r=bn(n,t),i=typeof e=="string"?Xs(e):e,o=dn.diff(r,i);return A5(n,t,o)}const lu=I("update-block-data");function dh(n,t,e,r){const i=it(t),o=ft(i),s=bt(t),l=n.doc.getBlockData(o,s),c={insert:{},delete:[]},d=new Set(Object.keys(l)),h=new Set(Object.keys(e));return d.forEach(E=>{if(!h.has(E)){if(E==="id"||E==="type"||E==="text")return;lu.debug(`delete key: ${E}`),c.delete.push(E)}}),Object.entries(e).forEach(([E,x])=>{p(lu,E!=="id"&&E!=="type",`invalid block data delta, ${E}`);const v=l[E];if(x==null){v!=null&&(lu.debug(`delete key: ${E}`),c.delete.push(E));return}v!==x&&(Pc.default(v,x)||E==="text"&&dn.diff(v,x).length===0||(d.has(E)?(lu.debug(`replace key: ${E}`),c.delete.push(E)):lu.debug(`insert key: ${E}`),c.insert[E]=x))}),n.doc.localUpdateBlockData(o,s,c,r),jo(n,t)}function b5(n,t,e,r){const o={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,o,r)}function L1(n,t,e){if(!_t(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const i=qn(n,t).getChildContainers(n,t)[0],o=ke(i);L1(n,o,e)}function Ys(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 au=I("clone-block");function zo(n,t,e,r){const i=n.getBlockClass(e.type);if(i.blockToDoc)return i.blockToDoc(t,e,(h,C)=>(p(au,e!==C,"invalid child block"),zo(n,h,e,r)));let o={};const s=new Map,l=gt.default(e);l.children&&(l.children=l.children.map(h=>{const C=J(),E=t.blocks[h];p(au,Array.isArray(E),"invalid child blocks");const x=E.map(M=>zo(n,t,M,r)),v=Ys(x),{root:R,...L}=v.blocks;return o={...o,...L},o[C]=v.blocks.root,s.set(h,C),C}));const c=Array.from(s.entries()),d=h=>{for(const C of c){const[E,x]=C;{const v=`${E}/`;if(h.startsWith(v)){const R=h.substring(v.length),L=`${x}/${R}`;return au.debug(`replace key: ${h} -> ${L}`),L}}{const v=`${E}_`;if(h.startsWith(v)){const R=h.substring(v.length),L=`${x}_${R}`;return au.debug(`replace key: ${h} -> ${L}`),L}}}return h};return Array.from(Object.entries(l)).forEach(([h,C])=>{const E=d(h);E!==h&&delete l.key,l[E]=C}),l.id=J(),r&&(r.blockIdMap.set(e.id,l.id),s.forEach((h,C)=>r.containerIdMap.set(C,h))),{blocks:{root:[l],...o},meta:{},comments:{}}}function I1(n,t,e,r){const i=t.blocks[e];p(au,Array.isArray(i),"invalid child blocks");const o=i.map(l=>zo(n,t,l,r));return Ys(o)}function D1(n,t,e){const r=t.blocks.root.map(i=>zo(n.editorBlocks,t,i,e));return gt.default(Ys(r))}const v5=I("insert-doc");function B5(n,t,e,r,i){if(_t(n,t)){v5.warn("failed to insert doc into a complex block");return}const o=D1(n,r,i),s=it(t),l=bt(t),c=ft(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var F,G,q,rt;const d=[];Object.entries(o.blocks).forEach(([at,At])=>{at!=="root"&&d.push({containerId:at,blocks:At})}),d.length>0&&n.doc.localInsertChildContainers(d);const h=o.blocks.root;if(Re(t)){n.deleteBlock(t);let at;h.reverse().forEach(At=>{const Mt=n.insertBlock(c,l,At,void 0,{noFocus:!0});at||(at=Mt)}),at&&n.selection.selectBlock(at,dt(n,at));return}if(p(v5,et(n,t),"not a text block"),re(n,t)){const at=bt(t);let At,Mt=!1;for(let kt=0;kt<h.length;kt++){if(kt===0){const ue=n.getBlockByIndex(c,at);if(ue&&et(n,ue)&&re(n,ue)&&h[kt].type==="text"){n.insertTextToBlock(t,0,(F=h[kt].text)!=null?F:[]),Object.prototype.hasOwnProperty.call(h[kt],"heading")&&n.updateBlockData(ue,h[kt]);continue}Gi(ue)&&(Mt=!0)}const se=n.insertBlock(c,at+kt,h[kt],void 0,{noFocus:!0});kt===h.length-1&&(At=se)}At&&n.selection.selectBlock(At,dt(n,At)),Mt&&n.deleteBlock(t);return}if(h.length===1){const at=h[0];if(Wc(n,at.type)){n.insertTextToBlock(t,e,(G=at.text)!=null?G:[]);return}n.breakTextBlock(t,e),n.insertBlock(c,l+1,at);return}const C=e===dt(n,t),E=e===0,x=h[0],v=h[h.length-1];let R;!C&&!E?R=n.breakTextBlock(t,e,{forceInsertAfter:!0}):R=t;const L=E?l:l+1;C?(R=n.insertBlock(c,l+1,v),n.selection.selectBlock(R,dt(n,R))):(n.selection.selectBlock(R,0),Wc(n,v.type)?n.insertTextToBlock(R,0,(q=v.text)!=null?q:[]):n.insertBlock(c,L,v));const M=n.selection.range;let U=L;Wc(n,x.type)?E?(n.insertBlock(c,L,x),U+=1):n.insertTextToBlock(t,e,(rt=x.text)!=null?rt:[]):(n.insertBlock(c,L,x),U+=1),h.slice(1,h.length-1).reverse().forEach(at=>{n.insertBlock(c,U,at)}),n.selection.setRange(M)}),n.doc.endBatchUpdate()}function _1(n,t,e,r,i){const o=D1(n,r,i),s=ft(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 T5(n,t,e,r){const i=Lr(t);_1(n,t,i,e,r);for(let o=0;o<i;o++){const s=ke(t);n.deleteBlock(s)}}const cu=I("add-text-attribute");function RD(n,t,e,r){const{start:i,end:o}=e;p(cu,i.blockId===o.blockId&&i.blockId===st(t),"invalid range"),p(cu,r,"invalid attribute name");const s=n.getBlockText(t),l=fa(i.offset,o.offset-i.offset,s,r,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function y5(n,t,e,r,i){const{start:o,end:s}=e;p(cu,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(cu,r,"invalid attribute name");const l=n.getBlockText(t),c=nu(o.offset,s.offset-o.offset,l,r,i);return n.setBlockText(t,c),c}function Aa(n,t,e,r,i){const{start:o,end:s}=e;p(cu,o.blockId===s.blockId&&o.blockId===st(t),"invalid range");const l=n.getBlockText(t),c=E3(o.offset,s.offset-o.offset,l,r,i);return n.setBlockText(t,c),c}function k5(n,t,e,r){const i=fi(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{i.forEach(o=>{const{block:s,start:l,end:c}=o;if(!et(n,s))return;if(re(n,s)){r(n,st(s),t,e);return}const d=We(n,{anchor:l,focus:c});t==="color"||t==="backgroundColor"?Aa(n,s,d,t,e):(Aa(n,s,d,"color",null),Aa(n,s,d,"backgroundColor",null))})})}function R5(n,t,e){const r=fi(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:o,start:s,end:l}=i;if(!et(n,o))return;if(re(n,o)){(t==="clearColor"||t==="clearAll")&&e(n,st(o),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,st(o),"backgroundColor",null);return}const c=We(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Aa(n,o,c,"color",null),(t==="clearBackground"||t==="clearAll")&&Aa(n,o,c,"backgroundColor",null)})})}function w5(n,t,e){const r=t.getSelectedBlocks().filter(l=>et(n,l.block));if(r.length===0)return[null,null];const i=l=>{if(dt(n,l.block)===0)return e(n,st(l.block));const c=l.start,d=l.end,h=n.getBlockText(l.block);return b3(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 Qn=I("adjust-selection-pos");function S5(n){const t=[];for(;n;){const e=it(n);if(t.unshift(e),Qt(e))return t;const r=nt(e);p(Qn,r,"child container has not parent container"),n=r}p(Qn,!1,"should not come here: getParentContainers")}function L5(n,t){for(;t;){const e=it(t);if(e===n)return t;const r=nt(e);p(Qn,r,"could not find parent block for a child container"),t=r}p(Qn,!1,"no parent block in specified container")}function wD(n,t){const e=S5(n),r=S5(t);p(Qn,e.length>0&&r.length>0,"block has not parent container"),p(Qn,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=L5(i,n),s=L5(i,t);return{parentContainer:i,newBlock1:o,newBlock2:s}}function I5(n,t){let e=nt(t);for(p(Qn,e,"element is not in a block");e;){const r=it(e);p(Qn,Mr(r),"not a child container");const i=nt(r);if(p(Qn,i,"child container has not parent block"),i===n)return r;e=i}p(Qn,!1,"failed to find parent container in complex block")}function hh(n,t,e){const r=n.getBlockById(t.blockId),i=n.getBlockById(e.blockId);if(r===i)return t instanceof _e&&e instanceof _e?{anchor:t,focus:e}:t instanceof Ur&&e instanceof Ur?Vd(n,r,t,e):null;const o=it(r),s=it(i);if(o===s)return t instanceof Ur&&(t=lt(r,0,"home")),e instanceof Ur&&(e=lt(i,dt(n,i),"end")),p(Qn,t instanceof _e,"not valid position type"),p(Qn,e instanceof _e,"not valid position type"),{anchor:t,focus:e};if(r.contains(s))return null;if(i.contains(o)){if(t instanceof _e&&e instanceof Ur){const v=n.getContainerById(e.childContainerId);if(v===o)return{anchor:e,focus:e};const R=nt(o);if(R&&R===nt(v)){const L=Ee(R,ft(o)),M=Ee(R,ft(v));return Vd(n,R,L,M)}}return null}const l=bd(r,i)>0,{newBlock1:c,newBlock2:d}=wD(r,i);if(c===d){const v=c,R=I5(v,r),L=I5(v,i);return t=Ee(c,ft(R)),e=Ee(c,ft(L)),Qn.debug(`select in complex block: ${R.id}, ${L.id}`),Vd(n,v,t,e)}let h=l?dt(n,c):0;c===r&&t instanceof _e&&(h=t.offset);let E=l?0:dt(n,d);return d===i&&e instanceof _e&&(E=e.offset),t=lt(c,h,l?"end":"home"),e=lt(d,E,l?"home":"end"),{anchor:t,focus:e}}const SD=I("move-complex-block-position");function LD(n,t,e){const r=n.getBlockById(t.blockId);p(SD,_t(n,r),"is not a complex block");const i=qn(n,r),o=n.getContainerById(t.childContainerId),s=i.getNextContainer(n,r,o,e,{noWrap:!0});return s?Ee(r,ft(s)):null}const uu=I("move-simple-block-position");function D5(n,t){const e=xn(n,t,{visibleOnly:!0});p(uu,e.length>0,"complex block has not any child container");const r=e[0];return ke(r)}function _5(n,t){const e=xn(n,t,{visibleOnly:!0});p(uu,e.length>0,"complex block has not any child container");const r=e[e.length-1];return Ze(r)}function M5(n,t,e){const r=e?D5(n,t):_5(n,t);return _t(n,r)?M5(n,r,e):r}function ID(n,t){const e=n.getBlockById(t.blockId);return _t(n,e)&&t.offset===0?D5(n,e):$s(e)}function DD(n,t){const e=n.getBlockById(t.blockId);return _t(n,e)&&t.offset===1?_5(n,e):Vs(e)}function M1(n){return n==="ArrowLeft"||n==="ArrowUp"}function U1(n,t,e){const r=it(t);if(Qt(r))return null;const i=nt(r);p(uu,i,"child container has not parent block"),p(uu,_t(n,i),"is not a complex block");const o=qn(n,i).getNextContainer(n,i,r,e);return o?M1(e)?Ze(o):ke(o):U1(n,i,e)}function _D(n,t,e){const r=it(t);if(Qt(r))return null;const i=nt(r);if(p(uu,i,"child container has not parent block"),M1(e)){const l=me(i);if(l)return l}else{const l=Gt(i);if(l)return l}const o=U1(n,i,e);if(o)return o;let s=i;for(;!Qt(it(s));)s=nt(it(s));return M1(e)?me(s):Gt(s)}function MD(n,t,e){return!_t(n,t)||qn(n,t).enableKeyboardSelect?t:M5(n,t,e==="ArrowDown"||e==="ArrowRight")}function UD(n,t,e){const r=n.getBlockById(t.blockId),o=Zt(n,r).moveCaret(n,r,t,e);if(o)return o;let s=e==="ArrowDown"||e==="ArrowRight"?ID(n,t):DD(n,t);if(s||(s=U1(n,r,e),s||(s=_D(n,r,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!Qt(it(r)))return null;const l=n.insertTextBlock("",ft(n.rootContainer),Lr(n.rootContainer));return lt(l,0,"home")}return null}if(s=MD(n,s,e),et(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return o8(n,s,r,t,l);if(e==="ArrowUp")return i8(n,s,r,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?lt(s,dt(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?lt(s,0,"home"):null}function OD(n,t,e){if(t==="ArrowLeft")return e.start;const r=e.end,i=n.getBlockById(r.blockId);if(et(n,i))return r;const o=Gt(i);if(o)return lt(o,0,"home");if(!Qt(it(i))||n.readonly)return r;const s=n.insertTextBlock("",ft(n.rootContainer),Lr(n.rootContainer));return lt(s,0,"home")}function ND(n,t,e){const r=n.selection.range;let i;if(r instanceof Ge)e==="move"&&!r.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?i=OD(n,t,r):i=UD(n,r.getFocusedPos(),t);else if(i=LD(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=Ze(s);i=lt(l,0,"home")}else{const l=ke(s);i=lt(l,dt(n,l),"end")}}return i?e==="move"?{anchor:i,focus:i}:hh(n,r.anchor,i):null}function Go(n,t,e){const r=ND(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 U5(n){return Go(n,"ArrowLeft","move"),!0}function O5(n){return Go(n,"ArrowRight","move"),!0}function N5(n){return Go(n,"ArrowUp","move"),!0}function P5(n){if(Go(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=it(t);if(Qt(e)||Ze(e)!==t)return!0;const r=n.rootContainer;return n.insertTextBlock("",ft(r),Lr(r)),!0}function F5(n){return Go(n,"ArrowDown","select"),!0}function K5(n){return Go(n,"ArrowLeft","select"),!0}function V5(n){return Go(n,"ArrowRight","select"),!0}function $5(n){return Go(n,"ArrowUp","select"),!0}const H5=I("word-offset");function O1(n,t){const e=n.selection.range.focus;p(H5,e.isSimple(),"invalid range type");const r=n.getBlockById(e.blockId);if(re(n,r))return lt(r,0,"home");if(e.offset===0||!et(n,r)){const s=me(r);if(!s)return null;const l=lt(s,dt(n,s),"end");if(t==="select"&&et(n,s)){const c=m1(n,s,l.offset);return lt(s,c,"normal")}return l}const i=m1(n,r,e.offset);return lt(r,i,"normal")}function N1(n,t){const e=n.selection.range.focus;p(H5,e.isSimple(),"invalid range type");const r=n.getBlockById(e.blockId);if(re(n,r))return lt(r,0,"end");if(e.offset===dt(n,r)||!et(n,r)){const s=Gt(r);if(!s)return null;const l=lt(s,0,"home");if(t==="select"&&et(n,s)){const c=g1(n,s,l.offset);return lt(s,c,"end")}return l}const i=g1(n,r,e.offset);return lt(r,i,"normal")}function j5(n){if(!n.selection.range.focus.isSimple())return!1;const e=O1(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function z5(n){if(!n.selection.range.focus.isSimple())return!1;const e=N1(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function G5(n){if(!n.selection.range.focus.isSimple())return!1;const e=O1(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function W5(n){if(!n.selection.range.focus.isSimple())return!1;const e=N1(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}I("find-block");function P1(n,t){if(!_t(n,t))return t;const r=qn(n,t).getChildContainers(n,t)[0],o=Ce(r)[0];return P1(n,o)}function F1(n,t){if(!_t(n,t))return t;const e=qn(n,t).getChildContainers(n,t),r=e[e.length-1],i=Ce(r),o=i[i.length-1];return F1(n,o)}function K1(n){const t=F1(n,Ze(n.rootContainer)),e=lt(t,dt(n,t),"end");return n.selection.setSelection(e),!0}function q5(n){const t=P1(n,n.getFirstBlock()),e=lt(t,0,"home");return n.selection.setSelection(e),!0}function X5(n){const t=P1(n,n.getFirstBlock()),e=lt(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function V1(n){const t=F1(n,Ze(n.rootContainer)),e=lt(t,dt(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const Q5=I("line-offset");function Y5(n){const t=n.selection.range.focus;p(Q5,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!et(n,e))return lt(e,0,"home");let i=y3(e,t).start;const{next:o}=Nd(e,i);return o&&hr(o)&&Xc(o)==="br"&&(i+=1),lt(e,i,"home")}function Z5(n){const t=n.selection.range.focus;p(Q5,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===dt(n,e)||!et(n,e))return lt(e,dt(n,e),"end");const r=y3(e,t);return lt(e,r.end,"end")}function J5(n){if(!n.selection.range.focus.isSimple())return!1;const e=Y5(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function tB(n){if(!n.selection.range.focus.isSimple())return!1;const e=Z5(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function eB(n){if(!n.selection.range.focus.isSimple())return!1;const e=Y5(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function nB(n){if(!n.selection.range.focus.isSimple())return!1;const e=Z5(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const rB=I("find-block-position");function PD(n,t,e,r){p(rB,_t(n,t),"is not a complex block");const i=qn(n,t).getChildContainers(n,t);p(rB,i.length>0,"complex block has not any child container");const o=_r(n,e,r),s=o.left+o.width/2,l=o.top+o.height/2,c=Ov(n,t,s,l);return $1(n,c,e,r)}function $1(n,t,e,r){if(_t(n,t))return PD(n,t,e,r);const i=st(t);let o=Number.MAX_SAFE_INTEGER;const s=_r(n,e,r),l=s.left+s.width/2,c=s.top+s.height/2;let d=lt(i,0,"home");const h=dt(n,t);for(let C=0;C<=h;C++){const E=lt(i,C,"normal"),x=_r(n,t,E),v=Vi(x,l,c);v<o&&(o=v,d=E)}return d}const iB=I("page-offset");function FD(n,t){const e=n5(n)*.9,i=t.getBoundingClientRect().bottom-e;if(i<aD(n))return n.getFirstBlock();const o=me(t);if(!o)return n.getFirstBlock();let s=o;for(;s;){if(s.getBoundingClientRect().y<i)return s;s=me(s)}return n.getFirstBlock()}function KD(n,t){const e=n5(n)*.9,r=t.getBoundingClientRect(),i=cD(n),o=r.top+e;if(o>i)return n.getLastBlock();const s=Gt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>o)return l;l=Gt(l)}return n.getLastBlock()}function oB(n){const t=n.selection.range.focus;p(iB,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),r=FD(n,e);let i;return r===n.getFirstBlock()?i=lt(r,0,"home"):i=$1(n,r,e,t),i}function sB(n){const t=n.selection.range.focus;p(iB,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),r=KD(n,e);let i;return r===n.getLastBlock()?i=lt(r,dt(n,r),"end"):i=$1(n,r,e,t),i}function lB(n){if(!n.selection.range.focus.isSimple())return!1;const e=oB(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function aB(n){if(!n.selection.range.focus.isSimple())return!1;const e=sB(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function cB(n){if(!n.selection.range.focus.isSimple())return!1;const e=oB(n);if(!e)return!1;const r=hh(n,n.selection.getAnchorPos(),e);if(!r)return!1;const{anchor:i,focus:o}=r;return n.selection.setSelection(i,o),n.selection.updateLastCaretRect(),!0}function uB(n){if(!n.selection.range.focus.isSimple())return!1;const e=sB(n);if(!e)return!1;const r=hh(n,n.selection.getAnchorPos(),e);if(!r)return!1;const{anchor:i,focus:o}=r;return n.selection.setSelection(i,o),n.selection.updateLastCaretRect(),!0}const fu=I("select-all");function fB(n,t){const e=ke(n),r=Ze(n);return t.start.offset===0&&t.start.blockId===st(e)&&t.end.offset===dt(t.getEditor(),r)&&t.end.blockId===st(r)}function VD(n,t){const e=t.getEditor(),r=qn(e,n).getChildContainers(e,n),i=r[0],o=r[r.length-1],s=st(n);return t.start.blockId===s&&t.start.childContainerId===ft(i)&&t.end.blockId===s&&t.end.childContainerId===ft(o)}function $D(n,t){p(fu,t,"no parent block"),p(fu,_t(n,t),"not a complex block");const e=qn(n,t).getChildContainers(n,t),r=e[0],i=e[e.length-1];n.selection.setRange(We(n,{anchor:Ee(t,ft(r)),focus:Ee(t,ft(i))}))}function dB(n,t){const e=it(t);H1(n,e)}function hB(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&et(n,t)){const i=e.start,o=e.end,s=dt(n,t);if(i.offset>0||o.offset<s)return n.selection.selectBlock(t,0,s),!1}return z(n.rootContainer,"select-all"),dB(n,ke(n.rootContainer)),!1}return p(fu,!e.isSimple(),"invalid range type"),VD(t,e)?(dB(n,t),!1):(p(fu,t,"no parent block"),p(fu,_t(n,t),"not a complex block"),$D(n,t),!0)}function H1(n,t){const e=Ce(t),r=e[0],i=e[e.length-1],o=lt(r,0,"home"),s=lt(i,dt(n,i),"end");n.selection.setSelection(o,s,{noScroll:!0})}function HD(n){V1(n),n.focus()}const j1=I("selected-block-to-doc");function mB(n,t,e){!t.children||t.children.forEach(r=>{const i=n.getChildContainerData(r);i.forEach(o=>{mB(n,o,e)}),e.blocks[r]=gt.default(i)})}function mh(n,t){const e=Zt(n,t.block);if(e.selectionToDoc)return e.selectionToDoc(n,t);const r=gt.default(jo(n,t.block));if(et(n,t.block)){const o=t.start,s=t.end;if(p(j1,r.text,"no block text"),o.offset===s.offset)return{blocks:{root:[{...r,text:[]}]},meta:{},comments:{}};const{middle:l}=qe(r.text,o.offset,s.offset-o.offset);return{blocks:{root:[{...r,text:l}]},meta:{},comments:{}}}if(Re(t.block))return{blocks:{root:[r]},meta:{},comments:{}};p(j1,_t(n,t.block),"not complex block"),p(j1,r.children,"no children");const i={blocks:{root:[r]},meta:{},comments:{}};return mB(n,r,i),i}function z1(n,t){const e=lt(t,0,"normal"),r=lt(t,dt(n,t),"end");return mh(n,{block:t,start:e,end:r})}const jD=I("block-to-doc");function zD(n,t){p(jD,t.length>0,"invalid params, no blocks");const e=t.map(r=>z1(n,r));return Ys(e)}function gh(n){const e=n.selection.range.getSelectedBlocks().map(r=>mh(n,r));return Ys(e)}function gB(n,t){const e=n.getContainerById(t),o=Ce(e).map(s=>({start:lt(s,0,"home"),end:lt(s,dt(n,s),"end"),block:s})).map(s=>mh(n,s));return Ys(o)}const ph=I("editor-selection");class GD{constructor(t){g(this,"editor");g(this,"caret");g(this,"_range");g(this,"lastCaretRect");g(this,"handleBlockDelete",(t,e,r,i)=>{if(r||i.child)return;const o=this.range;if(s5(e,o)){ph.debug("adjust selection because remote deleted current block");const s=l5(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),r=st(e);this.caret=new oD(t);const i=lt(r,0,"normal");this._range=We(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){const i=lt(t,e,"normal");let o;r&&(o=lt(t,r,"normal")),this.setSelection(i,o)}setSelection(t,e,r){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const i=We(this.editor,{anchor:t,focus:e});if(this.range.isEqual(i))return this.range;const o=this._range;return this._range=i,this.selectionChanged(),this.updateFocusedBlock(o),Rt(this.editor.rootContainer,"select-all")&&(!i.isSimple()||!hD(this.editor,i))&&ot(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(){this.caret.update(),sD(this.editor)}getFocusedPos(){return this.range.focus}getAnchorPos(){return this.range.anchor}selectionChanging(t,e){return!0}selectionChanged(){this.updateSelection(),this.editor.emit("selectionChanged",this.editor)}updateLastCaretRect(){const t=this.range.focus;if(!Or(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=_r(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){dD(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=dt(this.editor,e)||p(ph,!1,"invalid block position, out of range");else{const r=t.childContainerId;!!this.editor.getContainerById(r)||p(ph,!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&&Rt(e,"focused")&&(ot(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=gh(this.editor);return t==="text"?Qs(this.editor,e):t==="markdown"?u5(this.editor,e):c5(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{ot(t,"focused"),ot(t,"child-focused")})}setBlockFocused(t){if(Rt(t,"focused"))return!1;z(t,"focused");let e=it(t);for(;Mr(e);){const r=nt(e);p(ph,r,"parent block not found"),z(r,"child-focused"),e=it(r)}return!0}}function WD(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,dt(n,e))}function qD(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!et(n,e))return;let r=O1(n,"select"),i=N1(n,"select");if(!r||!i)return;const o=t.blockId;r.blockId!==o&&(r=lt(e,0,"home")),i.blockId!==o&&(i=lt(e,dt(n,e),"end")),n.selection.setSelection(r,i)}class XD{constructor(t){g(this,"editor");g(this,"startPos",null);g(this,"lastCaretRect");g(this,"mouseDownEvent",null);g(this,"autoScroll",null);g(this,"handleMouseDown",(t,e)=>{var i;this.mouseDownEvent=t;const r=Fv(this.editor,t.x,t.y);if(r){if(r instanceof ui)return;if(!this.autoScroll&&e.autoScroll){const s=r.getSelectedBlocks(),l=cn(s[0].block);this.autoScroll=new Ld({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())}});g(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=$d(this.editor,t.x,t.y);if(!e)return;const r=hh(this.editor,this.startPos,e.end);if(!r)return;const{anchor:i,focus:o}=r;this.editor.selection.setSelection(i,o)});g(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){qD(this.editor)}handleTripleClick(t){WD(this.editor)}}function QD(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function YD(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const pB=I("delete-text");function CB(n,t,e,r){const i=r!=null?r:n.selection.range.start;i instanceof _e||p(pB,!1,`invalid insert pos type: ${typeof i}`);const{blockId:o}=i,s=n.getBlockById(o);p(pB,et(n,s),"block is not a text kind block");let{offset:l}=i;if(t==="backward"){if(l-e<0)return 0;if(!_n(s,l-e)){const c=Ho(s,l);e=l-c}}else if(t==="forward"&&l+e>dt(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function EB(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const ZD=I("handle-backspace");function G1(n,t){if(!re(n,t))return;const e=it(t);Lr(e)!==1&&n.deleteBlock(t)}function JD(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,r=n.getBlockById(e.blockId);if(et(n,r))if(e.offset===0){if(EB(n,r))return;const i=me(r);if(i){if(!n.isBlockWritable(i))return;if(et(n,i))n.mergeTextBlock(i,r,{focus:!0});else if(_t(n,i)){G1(n,r);const o=aa(n,i);o?n.selection.selectBlock(o,dt(n,o)):n.selection.selectBlock(i,0,dt(n,i))}else G1(n,r),p(ZD,Re(i),"prev block is not embed block"),n.selection.selectBlock(i,1)}else{const o=it(r);if(Mr(o)){const s=_v(n,o);if(s){if(!n.isBlockWritable(s))return;G1(n,r),n.selection.selectBlock(s,dt(n,s))}}}}else CB(n,"backward",1,null),n.selection.updateLastCaretRect();else{const i=bt(r),o=it(r);n.insertTextBlock("",ft(o),i),n.deleteBlock(r)}}function t_(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,r=n.getBlockById(e.blockId);if(et(n,r))if(e.offset===dt(n,r)){const i=Gt(r);if(i){if(!n.isBlockWritable(i))return;et(n,i)?n.mergeTextBlock(r,i,{focus:!0}):re(n,r)?n.deleteBlock(r,ve(n,i,0)):n.deleteBlock(i)}}else CB(n,"forward",1,null);else{const i=bt(r),o=it(r);n.insertTextBlock("",ft(o),i),n.deleteBlock(r)}}function e_(n){const{range:t}=n.selection,{start:e,end:r}=t,i=n.getBlockById(e.blockId),o=n.getBlockById(r.blockId);if(i!==o||!_t(n,i))return!1;if(Or(e))return!0;const s=la(n,i,e,r),l=xn(n,i);return s.length===l.length}function n_(n,t){if(e_(n)){const s=n.getFocusedBlock(),l=bt(s),c=ft(it(s));n.insertTextBlock("",c,l+1);return}const e=n.getFocusedBlock(),{start:r,end:i}=n.selection.range,o=r.blockId===i.blockId&&Re(e);if(!n.selection.range.isCollapsed()&&!o&&n.clearSelectedContents(),et(n,e)){if(re(n,e)&&EB(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 r_(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:r}=e;if(!et(n,r))return!1;const i=e.end;return n.insertBoxToBlock(r,i.offset,{type:"br",id:J(),box:!0,created:Date.now()}),!0}const i_=I("input-handler-actions");function o_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(n_(n),!0))}function s_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(t_(n),!0))}function l_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(JD(n),!0))}function a_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(r_(n),!0))}function c_(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t,{toPlainText:!0})}).catch(t=>{i_.error(t)}),!0)}const Ch={ArrowDown:P5,ArrowUp:N5,ArrowLeft:U5,ArrowRight:O5,"Shift+ArrowDown":F5,"Shift+ArrowUp":$5,"Shift+ArrowLeft":K5,"Shift+ArrowRight":V5,"CtrlOrCmd+ArrowLeft":j5,"CtrlOrCmd+ArrowRight":z5,"CtrlOrCmd+Shift+ArrowLeft":G5,"CtrlOrCmd+Shift+ArrowRight":W5,"CtrlOrCmd+ArrowUp":q5,"CtrlOrCmd+ArrowDown":K1,"CtrlOrCmd+Shift+ArrowUp":X5,"CtrlOrCmd+Shift+ArrowDown":V1,"CtrlOrCmd+A":hB,Home:eB,End:nB,"Shift+Home":J5,"Shift+End":tB,PageUp:lB,PageDown:aB,"Shift+PageUp":cB,"Shift+PageDown":uB,"CtrlOrCmd+Z":QD,"CtrlOrCmd+Shift+Z":YD,Enter:o_,Delete:s_,Backspace:l_,"Shift+Enter":a_,"CtrlOrCmd+Shift+V":c_};function AB(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function xB(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=>{xB(n,l,e)})})}function bB(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):xB(t,i,e)})}async function u_(n,t){const e=t.filter(o=>o.indexOf(":")===-1),r=await n.doc.addResources(e),i=new Map;if(e.length!==r.length)return i;for(let o=0;o<e.length;o++)i.set(e[o],r[o]);return i}function f_(n,t){var o,s;const r=t.meta.serverId;if(!r||typeof r!="string")return!1;const i=(s=(o=n.doc).getServerMeta)==null?void 0:s.call(o);return!(!i||i.serverId!==r)}async function W1(n,t){const r=t.meta.resources;if(!r||Object.keys(r).length===0)return;let i=new Map;if(f_(n,t)){const s=Array.from(Object.keys(r));i=await u_(n,s),bB(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&&bB(n,t,o)}async function d_(n,t,e){await W1(n,t),n.undoManager.runInGroup(()=>{const{start:r,end:i}=n.selection.range,o=n.getBlockById(r.blockId);if(r.blockId===i.blockId&&Re(o)){const s=it(o),l=n.getBlockIndex(o),[c]=n.insertDocAt(s,l+1,t,e);c&&n.selection.selectBlock(c,dt(n,c))}else{n.clearSelectedContents();const{block:s,offset:l}=ga(n);n.insertDoc(s,l,t,e)}})}const h_=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function m_(n){let t;for(const e of h_)if(t=n[e],t)break;return t||null}function vB(n,t,e){if(t.type==="embed"){const s=t.embedData.src;if(s&&typeof s=="string")for(const l of s.split("|"))e.add(l);return}const r=t.text;r&&r.forEach(o=>{o.attributes&&o.attributes.src&&typeof o.attributes.src=="string"&&e.add(o.attributes.src)});const i=t.children;i&&i.forEach(o=>{n.blocks[o].forEach(l=>{vB(n,l,e)})})}function g_(n,t){const e=new Set;return t.blocks.root.forEach(i=>{const o=n.editorBlocks.getBlockClass(i.type);o.getResources?o.getResources(i).forEach(s=>{e.add(s)}):vB(t,i,e)}),Array.from(e)}function Eh(n,t){return he.isFirefox?`<!doctype html><html><head><meta charset="utf8" /></head><body><canvas data-editor-doc="${ji(JSON.stringify(t))}" id="ones-editor-doc">${n}</body></html>`:`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${ji(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function Ah(n,t){var o,s,l;const e=(l=(s=(o=n.doc).getServerMeta)==null?void 0:s.call(o))!=null?l:{},r=g_(n,t),i={};r.forEach(c=>{const d=n.doc.buildResourceUrl(c,{withToken:!0});i[c]=d}),t.meta={...e,resources:i}}function p_(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let r=gh(n);const i=e==null?void 0:e(n,t,r);if(i===!0)return;typeof i=="object"&&i!==null&&(r=i),Ah(n,r);const o=sh(n,r),s=Qs(n,r),l=Eh(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))}async function xh(n,t){if(!window.isSecureContext)throw new Error("Can't copy block in insecure context.");const e=z1(n,t);Ah(n,e);const r=sh(n,e),i=Qs(n,e),o=Eh(r,e);return yg([{type:"text/plain",data:new Blob([i],{type:"text/plain"})},{type:"text/html",data:new Blob([o],{type:"text/html"})}])}class C_{constructor(t){g(this,"editor");g(this,"handlers",[]);g(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)}});this.editor=t}onInsertText(t,e){if(!et(this.editor,this.editor.getFocusedBlock()))return;const{containerId:r,blockIndex:i,offset:o}=ga(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(!et(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:r,offset:i}=ga(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(!et(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText(e,r),this.editor.selection.caret.update();const{containerId:i,blockIndex:o,offset:s}=ga(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){p_(this.editor,t,(e,r,i)=>{for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,r,i);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}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;Re(r)&&this.editor.deleteBlock(r)}else S1(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(){z(this.editor.rootElement,"active")}onBlur(){ot(this.editor.rootElement,"active")}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){B1(this.editor,o)}defaultHandleKeydown(t,e){return AB(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 d_(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=m_(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 E_(n,t,e){const r=zi(t,e);return r.remove(),r}I("copy-dom-attributes");const BB=["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 A_(n,t){for(let l=0;l<BB.length;l++){const c=BB[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 TB(n){const t=Array.from(n.childNodes).filter(e=>!Yb(e));return t.forEach(e=>{e.remove()}),t}function yB(n,t,e){var d;const r=n.getContainerById(t),i=zi(r,e),o=Ko(i),s=n.doc.getBlockData(t,e),l=Zt(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=TB(h);TB(i),C.forEach(x=>{i.appendChild(x)});const E=_d(h);if(E){const x=_d(i);x&&x.remove(),i.appendChild(E)}A_(h,i)}hv(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)})}const x_=I("transform-selection");function kB(n,t,e,r){const{range:i}=n.selection,{anchor:o,focus:s}=i;if(o.blockId!==t&&s.blockId!==t)return i;p(x_,o.isSimple()&&s.isSimple(),"invalid text pos type");let l=o;if(o.blockId===t){const d=dn.transformCursor(o.offset,e,r);l=lt(t,d,"normal")}let c=s;if(s.blockId===t){const d=dn.transformCursor(s.offset,e,r);c=lt(t,d,"normal")}return We(n,{anchor:l,focus:c})}const b_=I("handle-block-text-changed");function v_(n,t,e,r,i){const o=n.getContainerById(t),s=zi(o,e),l=n.doc.getBlockData(t,e);if(p(b_,l.text,"no block text"),Wb(n,s).setBlockText(n,s,l.text),!i){const c=kB(n,l.id,r,i);n.selection.setRange(c,{noScroll:!0})}}function B_(n,t){const e=gt.default(n);return t.delete.forEach(i=>{delete e[i]}),{...e,...t.insert}}function RB(n,t,e,r){const i=Zt(n,t);i.handleDeleteBlock&&i.handleDeleteBlock(n,t,e,r),n.emit("blockDeleted",n,t,e,r)}function T_(n,t,e,r){const i=n.getBlockByIndex(t,e);i.querySelectorAll('[data-type="editor-block"]').forEach(o=>{RB(n,o,r,{child:!0})}),RB(n,i,r,{child:!1})}const Pr=I("editor-doc");class y_ extends ea{constructor(e,r,i){super();g(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(Pr,this.editor.isBlockWritable(i),`block is not writable, ${e}, ${r}`)}localUpdateBlockText(e,r,i,o){p(Pr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const s=this.getBlockData(e,r),l=s.text;p(Pr,l,`no text, ${e}, ${r}`);const c=kB(this.editor,s.id,i,!0),d=dn.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){p(Pr,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,r);if(!this.editor.isBlockWritable(s)){const h=Array.from(i.delete).filter(E=>E!=="comments"),C=Object.keys(i.insert).filter(E=>E!=="comments");(h.length>0||C.length>0)&&p(Pr,!1,`block is not writable, comment supported only, ${JSON.stringify(i)}}`)}const l=gt.default(this.getBlockData(e,r)),c=gt.default(B_(l,i));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,c,o));const d=this.externalDoc.localUpdateBlockData(e,r,i,o);return this.editor.selection.setRange(Vo(this.editor,o)),d}localInsertBlock(e,r,i,o,s){p(Pr,!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(Vo(this.editor,o),s),l}localDeleteBlock(e,r,i){p(Pr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const o=gt.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(Vo(this.editor,i)),s}localDeleteChildContainers(e){return p(Pr,!this.editor.readonly,"editor is readonly"),e.forEach(r=>{const i=gt.default(this.getContainerBlocks(r));this.localEvents.forEach(o=>o.onBeforeDeleteChildContainer(r,i))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainers(e){p(Pr,!this.editor.readonly,"editor is readonly");const r=gt.default(e);r.forEach(i=>{this.localEvents.forEach(o=>o.onBeforeInsertChildContainer(i.containerId,i.blocks))}),this.externalDoc.localInsertChildContainers(r)}onRequestReload(e){Pr.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)}),v_(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)}),yB(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);P9(this.editor,s,r,i),this.editor.emit("docChanged",this.editor,o)}onDeleteBlock(e,r,i){T_(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);E_(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)})}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()}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){Pr.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function wB(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 bh=I("undo-action");class xa{constructor(t,e,r){g(this,"beforeRange");g(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(bh,t,"no other action"),!1}combine(t){p(bh,!1,"no other")}setAfterRange(t){this.afterRange&&bh.warn("after range has already set"),this.afterRange=t}findContainerById(t,e){return!!t.doc.findContainerBlocks(e)}findBlockById(t,e){const r=t.doc.findContainerBlocks(this.containerId);return r?r.some(i=>i.id===e):!1}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 bh.warn(`container (${o}) not found, deleted by others?`),!1}}return!0}}const ba=I("block-action");class SB extends xa{constructor(e,r,i,o,s){super(e,r,s);g(this,"blockData");g(this,"blockIndex");this.blockData=gt.default(o),this.blockIndex=i}deleteBlock(e,r){if(!this.findContainerById(e,this.containerId))return ba.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockData.id))return ba.warn(`block (${this.blockData.id}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const o=e.getBlockById(this.blockData.id);if(!o)return!1;try{p(ba,this.blockIndex===bt(o),"invalid block index"),ch(e,o,Vo(e,r))}catch(s){ba.warn(s.message),e.selection.selectBlock(o,0)}return!0}insertBlock(e,r){if(!this.findContainerById(e,this.containerId))return ba.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.checkBlockData(e,this.blockData))return!1;try{Ca(e,this.containerId,this.blockIndex,gt.default(this.blockData),r)}catch(i){ba.warn(i.message);const o=e.doc.getContainerBlocks(this.containerId),s=Math.min(o.length-1,this.blockIndex),l=e.getBlockByIndex(this.containerId,s);e.selection.selectBlock(l,0)}return!0}}I("insert-block-action");class k_ extends SB{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class R_ extends SB{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class w_ extends xa{constructor(e){super(e,ft(e.rootContainer),e.selection.range.toDocRange());g(this,"actions",[])}addAction(e){wB(this.actions,e),this.afterRange=e.afterRange}undo(e){let r=!1;return this.actions.concat().reverse().forEach(i=>{i.undo(e)&&(r=!0)}),r}redo(e){let r=!1;return this.actions.forEach(i=>{i.redo(e)&&(r=!0)}),r}setAfterRange(e){this.afterRange=e;const r=this.actions[this.actions.length-1];!r||r instanceof xa&&(r.afterRange||r.setAfterRange(e))}}const Wo=I("update-block-data-action");class vh extends xa{constructor(e,r,i,o,s,l){super(e,r,l);g(this,"beforeBlockData");g(this,"afterBlockData");g(this,"blockId");this.blockId=i,p(Wo,this.blockId===o.id,"invalid block id"),p(Wo,this.blockId===s.id,"invalid block id"),this.beforeBlockData=gt.default(o),this.afterBlockData=gt.default(s),p(Wo,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){if(!e.findBlockById(this.blockId))return Wo.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(Wo,i,"no container"),dh(e,r,vh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){if(!e.findBlockById(this.blockId))return Wo.warn(`block (${this.blockId}) not found, deleted by others?`),!1;p(Wo,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(Wo,i,"no container"),dh(e,r,vh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const r=gt.default(e);return delete r.id,delete r.type,r}}const Zs=I("update-block-text-action");class du extends xa{constructor(e,r,i,o,s,l){super(e,r,l);g(this,"beforeRichTextData");g(this,"afterRichTextData");g(this,"blockId");g(this,"type");this.blockId=i,this.beforeRichTextData=gt.default(o),this.afterRichTextData=gt.default(s),this.type=du.calType(o,s)}static calType(e,r){p(Zs,e,"no old data"),p(Zs,r,"no new data");const o=dn.diff(e,r),s=new Set;let l=!1;const c=h=>vb(h)?`cjk_${h}`:xb(h)?"number":Td(h)?"space":bb(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.findContainerById(e,this.containerId))return Zs.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return Zs.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?(fh(e,i,this.beforeRichTextData),!0):!1}redo(e){if(!this.findContainerById(e,this.containerId))return Zs.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return Zs.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?(fh(e,i,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof du)||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(Zs,e instanceof du,"invalid action type");const r=e;this.afterRichTextData=r.afterRichTextData,this.afterRange=e.afterRange}}const LB=I("child-container-action");class IB extends xa{constructor(t,e,r){super(t,e,t.selection.range.toDocRange()),this.blocks=r}deleteChildContainer(t){return this.findContainerById(t,this.containerId)?(t.doc.localDeleteChildContainers([this.containerId]),!0):(LB.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}insertChildContainer(t){return this.findContainerById(t,this.containerId)?(LB.warn(`container (${this.containerId}) already exists`),!1):(t.doc.localInsertChildContainers([{containerId:this.containerId,blocks:gt.default(this.blocks)}]),!0)}}class S_ extends IB{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class L_ extends IB{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Fr=I("undo");class I_{constructor(t){g(this,"editor");g(this,"actions",[]);g(this,"undoCursor");g(this,"currentGroup",null);g(this,"groupCounter",0);g(this,"undoRedoing",!1);g(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):(wB(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(p(Fr,!this.currentGroup,"current group already exists"),this.currentGroup=new w_(this.editor),this.groupCounter=1):(p(Fr,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){p(Fr,this.currentGroup,"current group not exists"),p(Fr,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Fr.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 Fr.error(`failed to run action: ${e.message}`),e}finally{this.endGroup()}}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(Vo(this.editor,t.beforeRange))}catch(e){Fr.error(`undo: failed to restore caret pos: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}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(Vo(this.editor,e)):Fr.warn("no after range")}catch(e){Fr.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}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(),dn.diff(r,i).length!==0&&this.addAction(new du(this.editor,t,e,r,i,o)))}onBeforeUpdateBlockData(t,e,r,i,o){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new vh(this.editor,t,e,r,i,o);this.addAction(s)}onBeforeInsertBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),p(Fr,e>=0,"invalid block index"),p(Fr,r,"no block data"),this.addAction(new k_(this.editor,t,e,r,i)))}onBeforeDeleteBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new R_(this.editor,t,e,r,i)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new S_(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new L_(this.editor,t,e)))}}class D_{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 __{constructor(){g(this,"converters",[]);g(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new D_)}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 M_(n){n.editorBlocks.registerBlockClass(Mn),n.editorBlocks.registerBlockClass(Dv),n.editorBoxes.registerBoxClass(z3),n.editorBoxes.registerBoxClass(G3),n.editorBoxes.registerBoxClass(X3),n.editorBoxes.registerBoxClass(Q3),n.editorInsertions.registerInsertionClass(Y3),n.editorBlockRenders.registerRender(new Qb)}function U_(n,t){M_(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 Bh=I("range-commands");function DB(n,t){n.forEach(e=>{e.source=t,e.children&&DB(e.children,t)})}function _B(n,t,e){const r=st(t);p(Bh,r===e.start.blockId,"invalid start range"),p(Bh,r===e.end.blockId,"invalid end range");const i=n.editorCommandProviders.getCommandProviders();let o=[];if(i.forEach(s=>{const l=s.getAvailableCommands(n,t,e);DB(l,s.id),o.push(...l)}),i.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,o);l&&(o=l)}}),_t(n,t)){if(!sa(e.start))return o;p(Bh,!e.start.isSimple(),"invalid start pos"),p(Bh,!e.end.isSimple(),"invalid end pos");const s=e.start.childContainerId,l=ci(n,s),d=Ce(l)[0];if(d){const h=dt(n,d),C=We(n,{anchor:lt(d,0,"home"),focus:lt(d,h,"end")}),E=_B(n,d,C);o.push(...E)}}return o}function MB(n){const t=n.getEditor(),e=n.getSelectedBlocks(),r=[],i=n.isReverse()?e[0]:e[e.length-1],o=We(t,{anchor:i.start,focus:i.end});return _B(t,i.block,o).forEach(l=>{r.push(l)}),r}function UB(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.source),c={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,r,i,{}))return o[st(t)]=c,!0;let d=!1;return _t(n,t)&&la(n,t,e.start,e.end).forEach(E=>{Ce(E).forEach(v=>{const R=dt(n,v),L=We(n,{anchor:lt(v,0,"home"),focus:lt(v,R,"end")});UB(n,v,L,r,i,o)&&(d=!0)})}),s.forEach(C=>{C.afterExecuteCommand&&C.afterExecuteCommand(n,t,e,r,i,o)}),d}function OB(n,t,e){const r=n.getEditor(),i={},o=r.editorCommandProviders.getCommandProvider(t.source);return o.executeRangeCommand&&o.executeRangeCommand(r,n,t,e,i)||(n.getSelectedBlocks().forEach(l=>{const c=We(r,{anchor:l.start,focus:l.end});UB(r,l.block,c,t,e,i)}),r.focus()),i}const O_=I("command-providers");class NB{constructor(t){g(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(O_,e,`no command provider, id=${t}`),e}getCommands(t){return MB(t)}executeCommand(t,e,r){return this.editor.undoManager.runInGroup(()=>OB(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 N_(n,t){const e=it(t),r=ft(e),i=bt(t);yB(n,r,i)}const P_=I("table-scroll");class PB{constructor(t,e,r,i,o){g(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 F_{constructor(t){g(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)){P_.warn(`event has already registered: ${e}`);return}o.push(new PB(this.editor,t,e,r,i))}else{const s=new PB(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)}}const FB=I("update-block-text");function K_(n,t,e){const r=n.getBoxById(t.id),i=nt(r);p(FB,i,"no parent block"),p(FB,et(n,i),"not a text block");const o=n.getBlockText(i),s=O3(o,"id",t.id,t);x5(n,i,s,e)}function V_(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 $_(n){if(n.readonly)return!1;const t=fi(n);return!!n.isBlockWritable(t.map(e=>e.block))}class H_{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 j_{constructor(){g(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(li(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const ro=I("editor");class z_ extends ye.TypedEmitter{constructor(e,r,i){var o,s,l,c,d,h,C,E;super();g(this,"parent");g(this,"rootElement");g(this,"contentElement");g(this,"rootContainerObject");g(this,"rootContainer");g(this,"input");g(this,"selection");g(this,"selectionHandler");g(this,"doc");g(this,"id");g(this,"clientId");g(this,"compositingText","");g(this,"undoManager");g(this,"shortcuts",new j_);g(this,"dataConverter",new __);g(this,"editorBlocks",new wv(this));g(this,"editorBoxes",new q3(this));g(this,"editorInsertions",new J3(this));g(this,"editorEmbeds",new Lv(this));g(this,"editorDecorators",new t5(this));g(this,"editorCommandProviders",new NB(this));g(this,"editorBlockRenders",new R9(this));g(this,"blockHooks",[]);g(this,"domEvents",new F_(this));g(this,"customs",new Map);g(this,"options");g(this,"inputHandlers",new C_(this));g(this,"settingsProvider");g(this,"_readonly",!1);g(this,"getColor",e=>{const r=this.options.colors;return r.length===0?"#FF1A75":r[e%r.length]});ro.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},this.settingsProvider=(d=i==null?void 0:i.settingsProvider)!=null?d:new H_(this),U_(this,i==null?void 0:i.components),this.blockHooks.push(...(C=(h=i==null?void 0:i.components)==null?void 0:h.blockHooks)!=null?C:[]),this.id=(E=i==null?void 0:i.id)!=null?E:J(),this.clientId=J(),this.undoManager=new I_(this),this.doc=new y_(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=yv(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new rD(this,this.inputHandlers),this.selection=new GD(this),this.selectionHandler=new XD(this),i!=null&&i.shortcuts&&this.shortcuts.shortcuts.push(...i.shortcuts),he.isMobile&&z(this.rootElement,"mobile"),he.isSafari&&z(this.rootElement,"safari"),this._readonly&&z(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?z(this.rootElement,"readonly"):ot(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:cn(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(ro,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(){ro.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){L1(this,e,r)}isWritable(){return $_(this)}isBlockWritable(e){return V_(this,e)}getChildContainerData(e){const r=this.doc.getContainerBlocks(e);return(!r||!Array.isArray(r))&&(p(ro,r,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),p(ro,Array.isArray(r),`container data is not an array: ${JSON.stringify(r)}`)),r}createChildContainer(e,r,i){return kv(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(ro,Ps(r),"not an valid block element"),r!=null?r:null}findBoxById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(ro,Md(r),"not an valid box element"),r!=null?r:null}getBlockById(e){const r=this.findBlockById(e);return p(ro,r,`no block, id=${e}`),r}getBoxById(e){const r=this.findBoxById(e);return p(ro,r,`no box, id=${e}`),r}getBlockByIndex(e,r){const i=this.getContainerById(e);return zi(i,r)}getBlockIndex(e){if(typeof e=="string"){const r=this.getBlockById(e);return bt(r)}return bt(e)}getContainerById(e){return ci(this,e)}getParentContainer(e){return it(e)}reloadBlock(e){N_(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 Ca(this,e,r,i,o!=null?o:c,s)}insertEmbed(e,r,i,o,s){const l={id:J(),type:"embed",embedType:i,embedData:o};return this.insertBlock(e,r,l,s)}deleteBlock(e,r){R1(this,e,r)}mergeTextBlock(e,r){return C5(this,e,r)}breakTextBlock(e,r,i){return Ea(this,e,r,i).newBlock}getTextPosition(){return ga(this)}getBlockString(e,r){const i=this.getBlockText(e);return ce(i,r)}getBlockData(e){return jo(this,e)}getBoxData(e){return H3(this,e)}getBlockText(e){return bn(this,e)}setBlockText(e,r){x5(this,e,r)}deleteTextFromBlock(e,r,i,o){return y1(this,e,r,i,o)}insertTextToBlock(e,r,i,o){return f5(this,e,r,i,o)}insertBoxToBlock(e,r,i){return d5(this,e,r,i)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,r,i,o){B5(this,e,r,i,o)}insertDocAt(e,r,i,o){return _1(this,e,r,i,o)}deleteChildContainers(e){p5(this,e)}replaceBlockText(e,r){return fh(this,e,r)}updateBlockData(e,r,i){const o={...this.getBlockData(e),...r},{id:s,type:l,...c}=o;return dh(this,e,c,(i!=null?i:this.selection.range).toDocRange())}updateEmbedData(e,r,i){return b5(this,e,r,i)}updateBoxData(e,r){K_(this,e,r)}getSelectedText(){const e=gh(this);return Qs(this,e)}clearSelectedContents(){S1(this)}insertTextBlock(e,r,i,o){const s=mi(e!=null?e:"");return g5(this,s,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){T1(this);return}r?(this.compositingText="",yd()?e||T1(this):B1(this,e)):(this.compositingText=e,h5(this))}}function hu(n,t,e){return new z_(n,t,e)}function G_(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=ag.default(s.states,i.states)}},e=[];return n.forEach(r=>{r.forEach(i=>{t(e,i)})}),e}const W_=["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"];class mu extends ye.TypedEmitter{constructor(e){super();g(this,"users",new Map);g(this,"cursors",new Map);g(this,"addingUser",!1);g(this,"colors");this.colors=e&&e.length>0?e:W_}setCursor(e){this.addUser(e.user);const r=this.cursors.get(e.user.userId);if(r&&Pc.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&&Jd(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(Jd(l.range)){const{anchor:c,focus:d}=l.range;c.blockId===e.id&&(c.offset=dn.transformCursor(c.offset,r,i)),d.blockId===e.id&&(d.offset=dn.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 en=I("local-doc");class q1 extends ea{constructor(e,r){super();g(this,"doc");g(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[mi("")]}},this.serviceUrl=(r==null?void 0:r.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return gt.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(en,i,`no container data: ${e}`);const o=i[r];return p(en,o,`no block data: ${r}`),o}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(en,o.text,"no text for data");const s=dn.apply(o.text,i);return o.text=s,p(en,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(en,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(en,o,`no container data: ${e}`),p(en,r>=0&&r<=o.length,`invalid block index: ${r}, ${o.length}`),o.splice(r,0,i),p(en,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(en,i,`no container data: ${e}`),p(en,r>=0&&r<=i.length,`invalid block index: ${r}, ${i.length}`);const o=i[r];return i.splice(r,1),p(en,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(en,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){en.debug(`delete child containers: ${e}`),e.forEach(r=>{p(en,this.doc.blocks[r],`no child container: ${r}`),delete this.doc.blocks[r]}),e.forEach(r=>{p(en,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(en,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,r){p(en,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new mu}setDoc(e){this.doc=gt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,"change doc")})}destroy(){this.clearCallbacks()}}class q_{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function X1(n,t,e){n.addCustom(t,()=>{var o;const r=(o=e())!=null?o:void 0;return new q_(r)})}const KB=I("find-block");function VB(n,t){const e=Vs(t);if(!e){if(dr(t))return null;const r=Fs(t);return p(KB,r,"no parent block"),VB(n,r)}return _t(n,e)?aa(n,e,{visibleOnly:!0}):e}function $B(n,t){const e=$s(t);if(!e){if(dr(t))return null;const r=Fs(t);return p(KB,r,"no parent block"),$B(n,r)}return _t(n,e)?Hg(n,e,{visibleOnly:!0}):e}const X_=I("remote-cursor");class Q_{constructor(){g(this,"remoteUsers",new mu)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const r=e;this.handleUpdateUsers(r.users)}else e.type==="caret"?this.handleUpdateCaret(e):X_.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 Y_(n){const{blocks:t,meta:e,comments:r,...i}=n;return{rootBlocks:t,meta:e,comments:r,childBlocks:i}}function Z_(n){const{blocks:t,meta:e,comments:r}=n,{root:i,...o}=t;return{blocks:i,meta:e,comments:r,...o}}function io(n){const{childBlocks:t,meta:e,comments:r,rootBlocks:i}=Y_(gt.default(n));return{blocks:{root:i,...t},meta:e,comments:r}}function oo(n){return n==="root"?"blocks":n}function va(n){return n==="blocks"?"root":n}const J_={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new an.default(n)},apply(n,t){const e=new an.default(n),r=new an.default(t);return e.compose(r).ops},compose(n,t){const e=new an.default(n),r=new an.default(t);return e.compose(r).ops},diff(n,t){const e=new an.default(n),r=new an.default(t);return e.diff(r).ops},transform(n,t,e){const r=new an.default(n);return new an.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 an.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 qo={},Q1=Gx.default.EventEmitter;qo.EventEmitter=Q1,qo.mixin=tM;function tM(n){for(var t in Q1.prototype)n.prototype[t]=Q1.prototype[t]}var HB=["info","warn","error"];function jB(){var n={};HB.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var eM=jB;jB.prototype.setMethods=function(n){n=n||{};var t=this;HB.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var nM=eM,rM=new nM,zB=rM;function Js(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,Js):this.stack=new Error().stack}Js.prototype=Object.create(Error.prototype),Js.prototype.constructor=Js,Js.prototype.name="ShareDBError",Js.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_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_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_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var Th=Js,gu={},GB=iM;function iM(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 x=[];if(i(s[E],h,C,x),E++,x.length===1)h=x[0];else if(x.length===0){for(var v=E;v<s.length;v++)r(C,s[v]);h=null;break}else{for(var R=o(s.slice(E),x),L=0;L<R[0].length;L++)r(C,R[0][L]);for(var M=0;M<R[1].length;M++)r(c,R[1][M]);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 WB={exports:{}},Xo=WB.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||""}},Y1=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},Z1=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")},yh=function(n){for(var t=0;t<n.length;t++)Z1(n[t])};Xo.apply=function(n,t){var e;yh(t);for(var r=0;r<t.length;r++){var i=t[r];if(i.i!=null)n=Y1(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 so=Xo._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:Y1(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:Y1(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};Xo.compose=function(n,t){yh(n),yh(t);for(var e=n.slice(),r=0;r<t.length;r++)so(e,t[r]);return e},Xo.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),so(t,r)}return t};var J1=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};Xo.transformCursor=function(n,t,e){for(var r=e==="right",i=0;i<t.length;i++)n=J1(n,t[i],r);return n};var oM=Xo._tc=function(n,t,e,r){if(Z1(t),Z1(e),t.i!=null)so(n,{i:t.i,p:J1(t.p,e,r==="right")});else if(e.i!=null){var i=t.d;t.p<e.p&&(so(n,{d:i.slice(0,e.p-t.p),p:t.p}),i=i.slice(e.p-t.p)),i!==""&&so(n,{d:i,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)so(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)so(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=J1(o.p,e),so(n,o))}return n},sM=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};Xo.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=sM(n[t]);return n},GB(Xo,oM,yh,so);var kh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},lM=function(n){return!!n&&n.constructor===Object},Kr=function(n){return JSON.parse(JSON.stringify(n))},St={name:"json0",uri:"http://sharejs.org/types/JSONv0"},lo={};St.registerSubtype=function(n){lo[n.name]=n},St.create=function(n){return n===void 0?null:Kr(n)},St.invertComponent=function(n){var t={p:n.p};return n.t&&lo[n.t]&&(t.t=n.t,t.o=lo[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},St.invert=function(n){for(var t=n.slice().reverse(),e=[],r=0;r<t.length;r++)e.push(St.invertComponent(t[r]));return e},St.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!kh(n[t].p))throw new Error("Missing path")},St.checkList=function(n){if(!kh(n))throw new Error("Referenced element not a list")},St.checkObj=function(n){if(!lM(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function pu(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 Cu(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}St.apply=function(n,t){St.checkValidOp(t),t=Kr(t);for(var e={data:n},r=0;r<t.length;r++){var i=t[r];(i.si!=null||i.sd!=null)&&pu(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&&lo[i.t])s[l]=lo[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)St.checkList(s),s[l]=i.li;else if(i.li!==void 0)St.checkList(s),s.splice(l,0,i.li);else if(i.ld!==void 0)St.checkList(s),s.splice(l,1);else if(i.lm!==void 0){if(St.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)St.checkObj(s),s[l]=i.oi;else if(i.od!==void 0)St.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},St.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},St.incrementalApply=function(n,t,e){for(var r=0;r<t.length;r++){var i=[t[r]];n=St.apply(n,i),e(i,n)}return n};var aM=St.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};St.append=function(n,t){if(t=Kr(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)&&(pu(t),pu(e)),aM(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&lo[t.t]){if(e.o=lo[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(),Cu(t),n.push(t);Cu(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)&&(Cu(t),Cu(e)),n.push(t)},St.compose=function(n,t){St.checkValidOp(n),St.checkValidOp(t);for(var e=Kr(n),r=0;r<t.length;r++)St.append(e,t[r]);return e},St.normalize=function(n){var t=[];n=kh(n)?n:[n];for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=[]),St.append(t,r)}return t},St.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},St.canOpAffectPath=function(n,t){return St.commonLengthForOps({p:t},n)!=null},St.transformComponent=function(n,t,e,r){t=Kr(t);var i=St.commonLengthForOps(e,t),o=St.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=Kr(e);c.p=c.p.slice(s),t.ld=St.apply(Kr(t.ld),[c])}else if(t.od!==void 0){var c=Kr(e);c.p=c.p.slice(s),t.od=St.apply(Kr(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)&&(pu(t),c=Kr(e),pu(c)),c.t&&lo[c.t]){if(t.t&&t.t===c.t){var h=lo[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(),Cu(t),St.append(n,t);else(!kh(h)||h.length>0)&&(t.o=h,St.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=Kr(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],x=t.p[i],v=t.lm;(C<v||C===v&&x<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 x=t.p[i],v=t.lm,R=e.p[i],L=e.lm;if(R!==L)if(x===R)if(r==="left")t.p[i]=L,x===v&&(t.lm=L);else return n;else x>R&&t.p[i]--,x>L?t.p[i]++:x===L&&R>L&&(t.p[i]++,x===v&&t.lm++),(v>R||v===R&&v>x)&&t.lm--,v>L?t.lm++:v===L&&(L>R&&v>x||L<R&&v<x?r==="right"&&t.lm++:v>x?t.lm++:v===R&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var x=e.p[i],v=e.lm;C=t.p[i],C>x&&t.p[i]--,C>v&&t.p[i]++}else{var x=e.p[i],v=e.lm;C=t.p[i],C===x?t.p[i]=v:(C>x&&t.p[i]--,(C>v||C===v&&x>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")St.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 St.append(n,t),n},GB(St,St.transformComponent,St.checkValidOp,St.append);var cM=WB.exports;St.registerSubtype(cM);var uM=St,fM={type:uM};(function(n){n.defaultType=fM.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)})(gu);var Vr={};(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))}})(Vr);var qB=Array.isArray,XB=Object.keys,dM=Object.prototype.hasOwnProperty,hM=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=qB(t),i=qB(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=XB(t);if(s=E.length,s!==XB(e).length)return!1;for(o=s;o--!==0;)if(!dM.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},QB=qo,mM=zB,Yn=Th,Rh=gu,$r=Vr,gM=$r.clone,pM=hM,Un=Yn.CODES,CM=Ft;function Ft(n,t,e){QB.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}QB.mixin(Ft),Ft.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())})},Ft.prototype._setType=function(n){if(typeof n=="string"&&(n=Rh.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new Yn(Un.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Ft.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Ft.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new Yn(Un.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 Yn(Un.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?Rh.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()},Ft.prototype.whenNothingPending=function(n){var t=this;$r.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Ft.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Ft.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Ft.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Ft.prototype._emitResponseError=function(n,t){if(n&&n.code===Un.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)},Ft.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){$r.callEach(e,i)}),n)return this._emitResponseError(n,r);this.ingestSnapshot(t,r),this._emitNothingPending()},Ft.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){$r.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()},Ft.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Un.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=wh(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var r=0;r<this.pendingOps.length;r++){var e=wh(this.pendingOps[r],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}}},Ft.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))},Ft.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()},Ft.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);EM(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Ft.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Ft.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Ft.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,r=e&&e.wantSubscribe===n;if(r){e.callback=AM([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Ft.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;$r.nextTick(function(){n._handleSubscribe()})}}};function EM(n,t,e){if(t){var r=n.pop();n.push(function(i){r&&r(i),e&&e(i)})}else n.push(e)}function AM(n){return n=n.filter($r.truthy),n.length?function(t){$r.callEach(n,t)}:null}Ft.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function xM(n){delete n.op,delete n.create,delete n.del}function wh(n,t){if(n.del)return xM(t);if(t.del)return new Yn(Un.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new Yn(Un.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new Yn(Un.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}}}Ft.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new Yn(Un.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===Rh.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=wh(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}},Ft.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 Yn(Un.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>=$r.MAX_SAFE_INTEGER)return this.emit("error",new Yn(Un.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)}},Ft.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var r=new Yn(Un.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;$r.nextTick(function(){i.flush()})},Ft.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)},Ft.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)}}},Ft.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!pM(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}}},Ft.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)},Ft.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=Rh.defaultType.uri),this.type){var i=new Yn(Un.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)},Ft.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new Yn(Un.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)},Ft.prototype.pause=function(){this.paused=!0},Ft.prototype.resume=function(){this.paused=!1,this.flush()},Ft.prototype.toSnapshot=function(){return{v:this.version,data:gM(this.data),type:this.type.uri}},Ft.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return mM.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();this.version++,this._clearInflightOp()},Ft.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=wh(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)},Ft.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=$r.callEach(t[i].callbacks,n)&&r;if(n&&!r)return e.emit("error",n)})},Ft.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=$r.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var tl={};tl.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var YB=qo,ZB=tl.ACTIONS,bM=Vr,vM=On;function On(n,t,e,r,i,o,s){YB.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}YB.mixin(On),On.prototype.hasPending=function(){return!this.ready},On.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}},On.prototype.destroy=function(n){this.connection.canSend&&this.action===ZB.querySubscribe&&this.connection.send({a:ZB.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&bM.nextTick(n)},On.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},On.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},On.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},On.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()},On.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},On.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)},On.prototype._handleError=function(n){this.emit("error",n)},On.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)},On.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var JB=qo,BM=tl.ACTIONS,TM=Vr,t2=pi;function pi(n,t){if(JB.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={}}JB.mixin(pi),pi.prototype.submit=function(n,t){this.value=n,this.send(t)},pi.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},pi.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()})},pi.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},pi.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},pi.prototype._message=function(){return{a:BM.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},pi.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},pi.prototype._callbackOrEmit=function(n,t){if(t)return TM.nextTick(t,n);n&&this.emit("error",n)};var yM=Vr,e2=tp;function tp(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}tp.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},tp.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&yM.nextTick(n)};var ep={exports:{}};(function(n,t){(function(e,r){r(t)})(Dn,function(e){function r(y,S){S=S|0;for(var _=Math.max(y.length-S,0),N=Array(_),H=0;H<_;H++)N[H]=y[S+H];return N}var i=function(y){var S=r(arguments,1);return function(){var _=r(arguments);return y.apply(null,S.concat(_))}},o=function(y){return function(){var S=r(arguments),_=S.pop();y.call(this,S,_)}};function s(y){var S=typeof y;return y!=null&&(S=="object"||S=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function d(y){setTimeout(y,0)}function h(y){return function(S){var _=r(arguments,1);y(function(){S.apply(null,_)})}}var C;l?C=setImmediate:c?C=process.nextTick:C=d;var E=h(C);function x(y){return o(function(S,_){var N;try{N=y.apply(this,S)}catch(H){return _(H)}s(N)&&typeof N.then=="function"?N.then(function(H){v(_,null,H)},function(H){v(_,H.message?H:new Error(H))}):_(null,N)})}function v(y,S,_){try{y(S,_)}catch(N){E(R,N)}}function R(y){throw y}var L=typeof Symbol=="function";function M(y){return L&&y[Symbol.toStringTag]==="AsyncFunction"}function U(y){return M(y)?x(y):y}function F(y){return function(S){var _=r(arguments,1),N=o(function(H,$){var X=this;return y(S,function(Z,ct){U(Z).apply(X,H.concat(ct))},$)});return _.length?N.apply(this,_):N}}var G=typeof Dn=="object"&&Dn&&Dn.Object===Object&&Dn,q=typeof self=="object"&&self&&self.Object===Object&&self,rt=G||q||Function("return this")(),at=rt.Symbol,At=Object.prototype,Mt=At.hasOwnProperty,kt=At.toString,se=at?at.toStringTag:void 0;function ue(y){var S=Mt.call(y,se),_=y[se];try{y[se]=void 0;var N=!0}catch{}var H=kt.call(y);return N&&(S?y[se]=_:delete y[se]),H}var nr=Object.prototype,Se=nr.toString;function Pn(y){return Se.call(y)}var Li="[object Null]",yn="[object Undefined]",gn=at?at.toStringTag:void 0;function Ii(y){return y==null?y===void 0?yn:Li:gn&&gn in Object(y)?ue(y):Pn(y)}var mo="[object AsyncFunction]",xr="[object Function]",JE="[object GeneratorFunction]",tA="[object Proxy]";function eA(y){if(!s(y))return!1;var S=Ii(y);return S==xr||S==JE||S==mo||S==tA}var ds=9007199254740991;function pl(y){return typeof y=="number"&&y>-1&&y%1==0&&y<=ds}function Cl(y){return y!=null&&pl(y.length)&&!eA(y)}var go={};function Ht(){}function Di(y){return function(){if(y!==null){var S=y;y=null,S.apply(this,arguments)}}}var hs=typeof Symbol=="function"&&Symbol.iterator,fc=function(y){return hs&&y[hs]&&y[hs]()};function tm(y,S){for(var _=-1,N=Array(y);++_<y;)N[_]=S(_);return N}function pn(y){return y!=null&&typeof y=="object"}var El="[object Arguments]";function em(y){return pn(y)&&Ii(y)==El}var br=Object.prototype,nm=br.hasOwnProperty,nA=br.propertyIsEnumerable,Al=em(function(){return arguments}())?em:function(y){return pn(y)&&nm.call(y,"callee")&&!nA.call(y,"callee")},Be=Array.isArray;function xl(){return!1}var bl=typeof e=="object"&&e&&!e.nodeType&&e,rm=bl&&!0&&n&&!n.nodeType&&n,vl=rm&&rm.exports===bl,im=vl?rt.Buffer:void 0,Bl=im?im.isBuffer:void 0,ms=Bl||xl,Ef=9007199254740991,Af=/^(?:0|[1-9]\d*)$/;function xf(y,S){var _=typeof y;return S=S==null?Ef:S,!!S&&(_=="number"||_!="symbol"&&Af.test(y))&&y>-1&&y%1==0&&y<S}var bf="[object Arguments]",vf="[object Array]",Bf="[object Boolean]",Tf="[object Date]",yf="[object Error]",kf="[object Function]",rA="[object Map]",iA="[object Number]",oA="[object Object]",om="[object RegExp]",sm="[object Set]",sA="[object String]",lA="[object WeakMap]",aA="[object ArrayBuffer]",cA="[object DataView]",lm="[object Float32Array]",uA="[object Float64Array]",fA="[object Int8Array]",dA="[object Int16Array]",Rf="[object Int32Array]",hA="[object Uint8Array]",wf="[object Uint8ClampedArray]",mA="[object Uint16Array]",gA="[object Uint32Array]",fe={};fe[lm]=fe[uA]=fe[fA]=fe[dA]=fe[Rf]=fe[hA]=fe[wf]=fe[mA]=fe[gA]=!0,fe[bf]=fe[vf]=fe[aA]=fe[Bf]=fe[cA]=fe[Tf]=fe[yf]=fe[kf]=fe[rA]=fe[iA]=fe[oA]=fe[om]=fe[sm]=fe[sA]=fe[lA]=!1;function pA(y){return pn(y)&&pl(y.length)&&!!fe[Ii(y)]}function CA(y){return function(S){return y(S)}}var am=typeof e=="object"&&e&&!e.nodeType&&e,Tl=am&&!0&&n&&!n.nodeType&&n,EA=Tl&&Tl.exports===am,dc=EA&&G.process,cm=function(){try{var y=Tl&&Tl.require&&Tl.require("util").types;return y||dc&&dc.binding&&dc.binding("util")}catch{}}(),um=cm&&cm.isTypedArray,AA=um?CA(um):pA,xA=Object.prototype,bA=xA.hasOwnProperty;function vA(y,S){var _=Be(y),N=!_&&Al(y),H=!_&&!N&&ms(y),$=!_&&!N&&!H&&AA(y),X=_||N||H||$,Z=X?tm(y.length,String):[],ct=Z.length;for(var Ct in y)(S||bA.call(y,Ct))&&!(X&&(Ct=="length"||H&&(Ct=="offset"||Ct=="parent")||$&&(Ct=="buffer"||Ct=="byteLength"||Ct=="byteOffset")||xf(Ct,ct)))&&Z.push(Ct);return Z}var hc=Object.prototype;function BA(y){var S=y&&y.constructor,_=typeof S=="function"&&S.prototype||hc;return y===_}function mc(y,S){return function(_){return y(S(_))}}var TA=mc(Object.keys,Object),yA=Object.prototype,kA=yA.hasOwnProperty;function fm(y){if(!BA(y))return TA(y);var S=[];for(var _ in Object(y))kA.call(y,_)&&_!="constructor"&&S.push(_);return S}function gc(y){return Cl(y)?vA(y):fm(y)}function dm(y){var S=-1,_=y.length;return function(){return++S<_?{value:y[S],key:S}:null}}function RA(y){var S=-1;return function(){var N=y.next();return N.done?null:(S++,{value:N.value,key:S})}}function wA(y){var S=gc(y),_=-1,N=S.length;return function H(){var $=S[++_];return $==="__proto__"?H():_<N?{value:y[$],key:$}:null}}function SA(y){if(Cl(y))return dm(y);var S=fc(y);return S?RA(S):wA(y)}function vr(y){return function(){if(y===null)throw new Error("Callback was already called.");var S=y;y=null,S.apply(this,arguments)}}function yl(y){return function(S,_,N){if(N=Di(N||Ht),y<=0||!S)return N(null);var H=SA(S),$=!1,X=0,Z=!1;function ct(ut,xt){if(X-=1,ut)$=!0,N(ut);else{if(xt===go||$&&X<=0)return $=!0,N(null);Z||Ct()}}function Ct(){for(Z=!0;X<y&&!$;){var ut=H();if(ut===null){$=!0,X<=0&&N(null);return}X+=1,_(ut.value,ut.key,vr(ct))}Z=!1}Ct()}}function _i(y,S,_,N){yl(S)(y,U(_),N)}function ze(y,S){return function(_,N,H){return y(_,S,N,H)}}function Sf(y,S,_){_=Di(_||Ht);var N=0,H=0,$=y.length;$===0&&_(null);function X(Z,ct){Z?_(Z):(++H===$||ct===go)&&_(null)}for(;N<$;N++)S(y[N],N,vr(X))}var LA=ze(_i,1/0),Yr=function(y,S,_){var N=Cl(y)?Sf:LA;N(y,U(S),_)};function Zr(y){return function(S,_,N){return y(Yr,S,U(_),N)}}function Lf(y,S,_,N){N=N||Ht,S=S||[];var H=[],$=0,X=U(_);y(S,function(Z,ct,Ct){var ut=$++;X(Z,function(xt,Yt){H[ut]=Yt,Ct(xt)})},function(Z){N(Z,H)})}var pc=Zr(Lf),If=F(pc);function po(y){return function(S,_,N,H){return y(yl(_),S,U(N),H)}}var Mi=po(Lf),Df=ze(Mi,1),_f=F(Df);function gs(y,S){for(var _=-1,N=y==null?0:y.length;++_<N&&S(y[_],_,y)!==!1;);return y}function Mf(y){return function(S,_,N){for(var H=-1,$=Object(S),X=N(S),Z=X.length;Z--;){var ct=X[y?Z:++H];if(_($[ct],ct,$)===!1)break}return S}}var ps=Mf();function Cs(y,S){return y&&ps(y,S,gc)}function hm(y,S,_,N){for(var H=y.length,$=_+(N?1:-1);N?$--:++$<H;)if(S(y[$],$,y))return $;return-1}function IA(y){return y!==y}function mm(y,S,_){for(var N=_-1,H=y.length;++N<H;)if(y[N]===S)return N;return-1}function kl(y,S,_){return S===S?mm(y,S,_):hm(y,IA,_)}var Cc=function(y,S,_){typeof S=="function"&&(_=S,S=null),_=Di(_||Ht);var N=gc(y),H=N.length;if(!H)return _(null);S||(S=H);var $={},X=0,Z=!1,ct=Object.create(null),Ct=[],ut=[],xt={};Cs(y,function(pe,ae){if(!Be(pe)){Yt(ae,[pe]),ut.push(ae);return}var xe=pe.slice(0,pe.length-1),Tr=xe.length;if(Tr===0){Yt(ae,pe),ut.push(ae);return}xt[ae]=Tr,gs(xe,function(k){if(!y[k])throw new Error("async.auto task `"+ae+"` has a non-existent dependency `"+k+"` in "+xe.join(", "));sn(k,function(){Tr--,Tr===0&&Yt(ae,pe)})})}),JA(),Ne();function Yt(pe,ae){Ct.push(function(){Br(pe,ae)})}function Ne(){if(Ct.length===0&&X===0)return _(null,$);for(;Ct.length&&X<S;){var pe=Ct.shift();pe()}}function sn(pe,ae){var xe=ct[pe];xe||(xe=ct[pe]=[]),xe.push(ae)}function Vn(pe){var ae=ct[pe]||[];gs(ae,function(xe){xe()}),Ne()}function Br(pe,ae){if(!Z){var xe=vr(function(k,Ni){if(X--,arguments.length>2&&(Ni=r(arguments,1)),k){var bs={};Cs($,function($n,Vt){bs[Vt]=$n}),bs[pe]=Ni,Z=!0,ct=Object.create(null),_(k,bs)}else $[pe]=Ni,Vn(pe)});X++;var Tr=U(ae[ae.length-1]);ae.length>1?Tr($,xe):Tr(xe)}}function JA(){for(var pe,ae=0;ut.length;)pe=ut.pop(),ae++,gs(tx(pe),function(xe){--xt[xe]===0&&ut.push(xe)});if(ae!==H)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function tx(pe){var ae=[];return Cs(y,function(xe,Tr){Be(xe)&&kl(xe,pe,0)>=0&&ae.push(Tr)}),ae}};function Co(y,S){for(var _=-1,N=y==null?0:y.length,H=Array(N);++_<N;)H[_]=S(y[_],_,y);return H}var DA="[object Symbol]";function _A(y){return typeof y=="symbol"||pn(y)&&Ii(y)==DA}var MA=1/0,Uf=at?at.prototype:void 0,gm=Uf?Uf.toString:void 0;function Of(y){if(typeof y=="string")return y;if(Be(y))return Co(y,Of)+"";if(_A(y))return gm?gm.call(y):"";var S=y+"";return S=="0"&&1/y==-MA?"-0":S}function UA(y,S,_){var N=-1,H=y.length;S<0&&(S=-S>H?0:H+S),_=_>H?H:_,_<0&&(_+=H),H=S>_?0:_-S>>>0,S>>>=0;for(var $=Array(H);++N<H;)$[N]=y[N+S];return $}function OA(y,S,_){var N=y.length;return _=_===void 0?N:_,!S&&_>=N?y:UA(y,S,_)}function Nf(y,S){for(var _=y.length;_--&&kl(S,y[_],0)>-1;);return _}function NA(y,S){for(var _=-1,N=y.length;++_<N&&kl(S,y[_],0)>-1;);return _}function PA(y){return y.split("")}var FA="\\ud800-\\udfff",KA="\\u0300-\\u036f",VA="\\ufe20-\\ufe2f",de="\\u20d0-\\u20ff",le=KA+VA+de,$A="\\ufe0e\\ufe0f",HA="\\u200d",jA=RegExp("["+HA+FA+le+$A+"]");function zA(y){return jA.test(y)}var pm="\\ud800-\\udfff",GA="\\u0300-\\u036f",Cm="\\ufe20-\\ufe2f",WA="\\u20d0-\\u20ff",Ye=GA+Cm+WA,Pf="\\ufe0e\\ufe0f",Eo="["+pm+"]",Ec="["+Ye+"]",Rl="\\ud83c[\\udffb-\\udfff]",Fn="(?:"+Ec+"|"+Rl+")",Ff="[^"+pm+"]",Kf="(?:\\ud83c[\\udde6-\\uddff]){2}",Vf="[\\ud800-\\udbff][\\udc00-\\udfff]",Em="\\u200d",$f=Fn+"?",Hf="["+Pf+"]?",kn="(?:"+Em+"(?:"+[Ff,Kf,Vf].join("|")+")"+Hf+$f+")*",qA=Hf+$f+kn,Kn="(?:"+[Ff+Ec+"?",Ec,Kf,Vf,Eo].join("|")+")",XA=RegExp(Rl+"(?="+Rl+")|"+Kn+qA,"g");function Am(y){return y.match(XA)||[]}function Jr(y){return zA(y)?Am(y):PA(y)}function Ac(y){return y==null?"":Of(y)}var jf=/^\s+|\s+$/g;function ge(y,S,_){if(y=Ac(y),y&&(_||S===void 0))return y.replace(jf,"");if(!y||!(S=Of(S)))return y;var N=Jr(y),H=Jr(S),$=NA(N,H),X=Nf(N,H)+1;return OA(N,$,X).join("")}var Ui=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,zf=/,/,QA=/(=.+)?(\s*)$/,Gf=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function YA(y){return y=y.toString().replace(Gf,""),y=y.match(Ui)[2].replace(" ",""),y=y?y.split(zf):[],y=y.map(function(S){return ge(S.replace(QA,""))}),y}function xm(y,S){var _={};Cs(y,function(N,H){var $,X=M(N),Z=!X&&N.length===1||X&&N.length===0;if(Be(N))$=N.slice(0,-1),N=N[N.length-1],_[H]=$.concat($.length>0?ct:N);else if(Z)_[H]=N;else{if($=YA(N),N.length===0&&!X&&$.length===0)throw new Error("autoInject task functions require explicit parameters.");X||$.pop(),_[H]=$.concat(ct)}function ct(Ct,ut){var xt=Co($,function(Yt){return Ct[Yt]});xt.push(ut),U(N).apply(null,xt)}}),Cc(_,S)}function rr(){this.head=this.tail=null,this.length=0}function Wf(y,S){y.length=1,y.head=y.tail=S}rr.prototype.removeLink=function(y){return y.prev?y.prev.next=y.next:this.head=y.next,y.next?y.next.prev=y.prev:this.tail=y.prev,y.prev=y.next=null,this.length-=1,y},rr.prototype.empty=function(){for(;this.head;)this.shift();return this},rr.prototype.insertAfter=function(y,S){S.prev=y,S.next=y.next,y.next?y.next.prev=S:this.tail=S,y.next=S,this.length+=1},rr.prototype.insertBefore=function(y,S){S.prev=y.prev,S.next=y,y.prev?y.prev.next=S:this.head=S,y.prev=S,this.length+=1},rr.prototype.unshift=function(y){this.head?this.insertBefore(this.head,y):Wf(this,y)},rr.prototype.push=function(y){this.tail?this.insertAfter(this.tail,y):Wf(this,y)},rr.prototype.shift=function(){return this.head&&this.removeLink(this.head)},rr.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},rr.prototype.toArray=function(){for(var y=Array(this.length),S=this.head,_=0;_<this.length;_++)y[_]=S.data,S=S.next;return y},rr.prototype.remove=function(y){for(var S=this.head;S;){var _=S.next;y(S)&&this.removeLink(S),S=_}return this};function wl(y,S,_){if(S==null)S=1;else if(S===0)throw new Error("Concurrency must not be zero");var N=U(y),H=0,$=[],X=!1;function Z(xt,Yt,Ne){if(Ne!=null&&typeof Ne!="function")throw new Error("task callback must be a function");if(ut.started=!0,Be(xt)||(xt=[xt]),xt.length===0&&ut.idle())return E(function(){ut.drain()});for(var sn=0,Vn=xt.length;sn<Vn;sn++){var Br={data:xt[sn],callback:Ne||Ht};Yt?ut._tasks.unshift(Br):ut._tasks.push(Br)}X||(X=!0,E(function(){X=!1,ut.process()}))}function ct(xt){return function(Yt){H-=1;for(var Ne=0,sn=xt.length;Ne<sn;Ne++){var Vn=xt[Ne],Br=kl($,Vn,0);Br===0?$.shift():Br>0&&$.splice(Br,1),Vn.callback.apply(Vn,arguments),Yt!=null&&ut.error(Yt,Vn.data)}H<=ut.concurrency-ut.buffer&&ut.unsaturated(),ut.idle()&&ut.drain(),ut.process()}}var Ct=!1,ut={_tasks:new rr,concurrency:S,payload:_,saturated:Ht,unsaturated:Ht,buffer:S/4,empty:Ht,drain:Ht,error:Ht,started:!1,paused:!1,push:function(xt,Yt){Z(xt,!1,Yt)},kill:function(){ut.drain=Ht,ut._tasks.empty()},unshift:function(xt,Yt){Z(xt,!0,Yt)},remove:function(xt){ut._tasks.remove(xt)},process:function(){if(!Ct){for(Ct=!0;!ut.paused&&H<ut.concurrency&&ut._tasks.length;){var xt=[],Yt=[],Ne=ut._tasks.length;ut.payload&&(Ne=Math.min(Ne,ut.payload));for(var sn=0;sn<Ne;sn++){var Vn=ut._tasks.shift();xt.push(Vn),$.push(Vn),Yt.push(Vn.data)}H+=1,ut._tasks.length===0&&ut.empty(),H===ut.concurrency&&ut.saturated();var Br=vr(ct(xt));N(Yt,Br)}Ct=!1}},length:function(){return ut._tasks.length},running:function(){return H},workersList:function(){return $},idle:function(){return ut._tasks.length+H===0},pause:function(){ut.paused=!0},resume:function(){ut.paused!==!1&&(ut.paused=!1,E(ut.process))}};return ut}function Ao(y,S){return wl(y,1,S)}var Es=ze(_i,1);function ti(y,S,_,N){N=Di(N||Ht);var H=U(_);Es(y,function($,X,Z){H(S,$,function(ct,Ct){S=Ct,Z(ct)})},function($){N($,S)})}function xc(){var y=Co(arguments,U);return function(){var S=r(arguments),_=this,N=S[S.length-1];typeof N=="function"?S.pop():N=Ht,ti(y,S,function(H,$,X){$.apply(_,H.concat(function(Z){var ct=r(arguments,1);X(Z,ct)}))},function(H,$){N.apply(_,[H].concat($))})}}var bc=function(){return xc.apply(null,r(arguments).reverse())},qf=Array.prototype.concat,Sl=function(y,S,_,N){N=N||Ht;var H=U(_);Mi(y,S,function($,X){H($,function(Z){return Z?X(Z):X(null,r(arguments,1))})},function($,X){for(var Z=[],ct=0;ct<X.length;ct++)X[ct]&&(Z=qf.apply(Z,X[ct]));return N($,Z)})},bm=ze(Sl,1/0),vc=ze(Sl,1),Bc=function(){var y=r(arguments),S=[null].concat(y);return function(){var _=arguments[arguments.length-1];return _.apply(this,S)}};function Ll(y){return y}function xo(y,S){return function(_,N,H,$){$=$||Ht;var X=!1,Z;_(N,function(ct,Ct,ut){H(ct,function(xt,Yt){xt?ut(xt):y(Yt)&&!Z?(X=!0,Z=S(!0,ct),ut(null,go)):ut()})},function(ct){ct?$(ct):$(null,X?Z:S(!1))})}}function Cn(y,S){return S}var As=Zr(xo(Ll,Cn)),ei=po(xo(Ll,Cn)),Il=ze(ei,1);function Xf(y){return function(S){var _=r(arguments,1);_.push(function(N){var H=r(arguments,1);typeof console=="object"&&(N?console.error&&console.error(N):console[y]&&gs(H,function($){console[y]($)}))}),U(S).apply(null,_)}}var vm=Xf("dir");function Bm(y,S,_){_=vr(_||Ht);var N=U(y),H=U(S);function $(Z){if(Z)return _(Z);var ct=r(arguments,1);ct.push(X),H.apply(this,ct)}function X(Z,ct){if(Z)return _(Z);if(!ct)return _(null);N($)}X(null,!0)}function Qf(y,S,_){_=vr(_||Ht);var N=U(y),H=function($){if($)return _($);var X=r(arguments,1);if(S.apply(this,X))return N(H);_.apply(null,[null].concat(X))};N(H)}function Tm(y,S,_){Qf(y,function(){return!S.apply(this,arguments)},_)}function ym(y,S,_){_=vr(_||Ht);var N=U(S),H=U(y);function $(Z){if(Z)return _(Z);H(X)}function X(Z,ct){if(Z)return _(Z);if(!ct)return _(null);N($)}H(X)}function bo(y){return function(S,_,N){return y(S,N)}}function Tc(y,S,_){Yr(y,bo(U(S)),_)}function Dl(y,S,_,N){yl(S)(y,bo(U(_)),N)}var vo=ze(Dl,1);function yc(y){return M(y)?y:o(function(S,_){var N=!0;S.push(function(){var H=arguments;N?E(function(){_.apply(null,H)}):_.apply(null,H)}),y.apply(this,S),N=!1})}function ir(y){return!y}var Bo=Zr(xo(ir,ir)),_l=po(xo(ir,ir)),kc=ze(_l,1);function km(y){return function(S){return S==null?void 0:S[y]}}function xs(y,S,_,N){var H=new Array(S.length);y(S,function($,X,Z){_($,function(ct,Ct){H[X]=!!Ct,Z(ct)})},function($){if($)return N($);for(var X=[],Z=0;Z<S.length;Z++)H[Z]&&X.push(S[Z]);N(null,X)})}function or(y,S,_,N){var H=[];y(S,function($,X,Z){_($,function(ct,Ct){ct?Z(ct):(Ct&&H.push({index:X,value:$}),Z())})},function($){$?N($):N(null,Co(H.sort(function(X,Z){return X.index-Z.index}),km("value")))})}function Rc(y,S,_,N){var H=Cl(S)?xs:or;H(y,S,U(_),N||Ht)}var wc=Zr(Rc),Ml=po(Rc),Sc=ze(Ml,1);function Rm(y,S){var _=vr(S||Ht),N=U(yc(y));function H($){if($)return _($);N(H)}H()}var Lc=function(y,S,_,N){N=N||Ht;var H=U(_);Mi(y,S,function($,X){H($,function(Z,ct){return Z?X(Z):X(null,{key:ct,val:$})})},function($,X){for(var Z={},ct=Object.prototype.hasOwnProperty,Ct=0;Ct<X.length;Ct++)if(X[Ct]){var ut=X[Ct].key,xt=X[Ct].val;ct.call(Z,ut)?Z[ut].push(xt):Z[ut]=[xt]}return N($,Z)})},To=ze(Lc,1/0),K=ze(Lc,1),W=Xf("log");function j(y,S,_,N){N=Di(N||Ht);var H={},$=U(_);_i(y,S,function(X,Z,ct){$(X,Z,function(Ct,ut){if(Ct)return ct(Ct);H[Z]=ut,ct()})},function(X){N(X,H)})}var mt=ze(j,1/0),wt=ze(j,1);function Wt(y,S){return S in y}function Le(y,S){var _=Object.create(null),N=Object.create(null);S=S||Ll;var H=U(y),$=o(function(Z,ct){var Ct=S.apply(null,Z);Wt(_,Ct)?E(function(){ct.apply(null,_[Ct])}):Wt(N,Ct)?N[Ct].push(ct):(N[Ct]=[ct],H.apply(null,Z.concat(function(){var ut=r(arguments);_[Ct]=ut;var xt=N[Ct];delete N[Ct];for(var Yt=0,Ne=xt.length;Yt<Ne;Yt++)xt[Yt].apply(null,ut)})))});return $.memo=_,$.unmemoized=y,$}var Xt;c?Xt=process.nextTick:l?Xt=setImmediate:Xt=d;var Ic=h(Xt);function Yf(y,S,_){_=_||Ht;var N=Cl(S)?[]:{};y(S,function(H,$,X){U(H)(function(Z,ct){arguments.length>2&&(ct=r(arguments,1)),N[$]=ct,X(Z)})},function(H){_(H,N)})}function Rn(y,S){Yf(Yr,y,S)}function Ul(y,S,_){Yf(yl(S),y,_)}var Zf=function(y,S){var _=U(y);return wl(function(N,H){_(N[0],H)},S,1)},yo=function(y,S){var _=Zf(y,S);return _.push=function(N,H,$){if($==null&&($=Ht),typeof $!="function")throw new Error("task callback must be a function");if(_.started=!0,Be(N)||(N=[N]),N.length===0)return E(function(){_.drain()});H=H||0;for(var X=_._tasks.head;X&&H>=X.priority;)X=X.next;for(var Z=0,ct=N.length;Z<ct;Z++){var Ct={data:N[Z],priority:H,callback:$};X?_._tasks.insertBefore(X,Ct):_._tasks.push(Ct)}E(_.process)},delete _.unshift,_};function Ol(y,S){if(S=Di(S||Ht),!Be(y))return S(new TypeError("First argument to race must be an array of functions"));if(!y.length)return S();for(var _=0,N=y.length;_<N;_++)U(y[_])(S)}function ko(y,S,_,N){var H=r(y).reverse();ti(H,S,_,N)}function qt(y){var S=U(y);return o(function(N,H){return N.push(function(X,Z){if(X)H(null,{error:X});else{var ct;arguments.length<=2?ct=Z:ct=r(arguments,1),H(null,{value:ct})}}),S.apply(this,N)})}function wm(y){var S;return Be(y)?S=Co(y,qt):(S={},Cs(y,function(_,N){S[N]=qt.call(this,_)})),S}function Jf(y,S,_,N){Rc(y,S,function(H,$){_(H,function(X,Z){$(X,!Z)})},N)}var Nl=Zr(Jf),td=po(Jf),Sm=ze(td,1);function Lm(y){return function(){return y}}function Ro(y,S,_){var N=5,H=0,$={times:N,intervalFunc:Lm(H)};function X(ut,xt){if(typeof xt=="object")ut.times=+xt.times||N,ut.intervalFunc=typeof xt.interval=="function"?xt.interval:Lm(+xt.interval||H),ut.errorFilter=xt.errorFilter;else if(typeof xt=="number"||typeof xt=="string")ut.times=+xt||N;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof y=="function"?(_=S||Ht,S=y):(X($,y),_=_||Ht),typeof S!="function")throw new Error("Invalid arguments for async.retry");var Z=U(S),ct=1;function Ct(){Z(function(ut){ut&&ct++<$.times&&(typeof $.errorFilter!="function"||$.errorFilter(ut))?setTimeout(Ct,$.intervalFunc(ct)):_.apply(null,arguments)})}Ct()}var ni=function(y,S){S||(S=y,y=null);var _=U(S);return o(function(N,H){function $(X){_.apply(null,N.concat(X))}y?Ro(y,$,H):Ro($,H)})};function Pl(y,S){Yf(Es,y,S)}var Fl=Zr(xo(Boolean,Ll)),Oi=po(xo(Boolean,Ll)),Kl=ze(Oi,1);function ed(y,S,_){var N=U(S);pc(y,function($,X){N($,function(Z,ct){if(Z)return X(Z);X(null,{value:$,criteria:ct})})},function($,X){if($)return _($);_(null,Co(X.sort(H),km("value")))});function H($,X){var Z=$.criteria,ct=X.criteria;return Z<ct?-1:Z>ct?1:0}}function Vl(y,S,_){var N=U(y);return o(function(H,$){var X=!1,Z;function ct(){var Ct=y.name||"anonymous",ut=new Error('Callback function "'+Ct+'" timed out.');ut.code="ETIMEDOUT",_&&(ut.info=_),X=!0,$(ut)}H.push(function(){X||($.apply(null,arguments),clearTimeout(Z))}),Z=setTimeout(ct,S),N.apply(null,H)})}var Im=Math.ceil,$l=Math.max;function wo(y,S,_,N){for(var H=-1,$=$l(Im((S-y)/(_||1)),0),X=Array($);$--;)X[N?$:++H]=y,y+=_;return X}function So(y,S,_,N){var H=U(_);Mi(wo(0,y,1),S,H,N)}var Dm=ze(So,1/0),_m=ze(So,1);function Mm(y,S,_,N){arguments.length<=3&&(N=_,_=S,S=Be(y)?[]:{}),N=Di(N||Ht);var H=U(_);Yr(y,function($,X,Z){H(S,$,X,Z)},function($){N($,S)})}function Hl(y,S){var _=null,N;S=S||Ht,vo(y,function(H,$){U(H)(function(X,Z){arguments.length>2?N=r(arguments,1):N=Z,_=X,$(!X)})},function(){S(_,N)})}function jl(y){return function(){return(y.unmemoized||y).apply(null,arguments)}}function zl(y,S,_){_=vr(_||Ht);var N=U(S);if(!y())return _(null);var H=function($){if($)return _($);if(y())return N(H);var X=r(arguments,1);_.apply(null,[null].concat(X))};N(H)}function Um(y,S,_){zl(function(){return!y.apply(this,arguments)},S,_)}var nd=function(y,S){if(S=Di(S||Ht),!Be(y))return S(new Error("First argument to waterfall must be an array of functions"));if(!y.length)return S();var _=0;function N($){var X=U(y[_++]);$.push(vr(H)),X.apply(null,$)}function H($){if($||_===y.length)return S.apply(null,arguments);N(r(arguments,1))}N([])},ZA={apply:i,applyEach:If,applyEachSeries:_f,asyncify:x,auto:Cc,autoInject:xm,cargo:Ao,compose:bc,concat:bm,concatLimit:Sl,concatSeries:vc,constant:Bc,detect:As,detectLimit:ei,detectSeries:Il,dir:vm,doDuring:Bm,doUntil:Tm,doWhilst:Qf,during:ym,each:Tc,eachLimit:Dl,eachOf:Yr,eachOfLimit:_i,eachOfSeries:Es,eachSeries:vo,ensureAsync:yc,every:Bo,everyLimit:_l,everySeries:kc,filter:wc,filterLimit:Ml,filterSeries:Sc,forever:Rm,groupBy:To,groupByLimit:Lc,groupBySeries:K,log:W,map:pc,mapLimit:Mi,mapSeries:Df,mapValues:mt,mapValuesLimit:j,mapValuesSeries:wt,memoize:Le,nextTick:Ic,parallel:Rn,parallelLimit:Ul,priorityQueue:yo,queue:Zf,race:Ol,reduce:ti,reduceRight:ko,reflect:qt,reflectAll:wm,reject:Nl,rejectLimit:td,rejectSeries:Sm,retry:Ro,retryable:ni,seq:xc,series:Pl,setImmediate:E,some:Fl,someLimit:Oi,someSeries:Kl,sortBy:ed,timeout:Vl,times:Dm,timesLimit:So,timesSeries:_m,transform:Mm,tryEach:Hl,unmemoize:jl,until:Um,waterfall:nd,whilst:zl,all:Bo,allLimit:_l,allSeries:kc,any:Fl,anyLimit:Oi,anySeries:Kl,find:As,findLimit:ei,findSeries:Il,forEach:Tc,forEachSeries:vo,forEachLimit:Dl,forEachOf:Yr,forEachOfSeries:Es,forEachOfLimit:_i,inject:ti,foldl:ti,foldr:ko,select:wc,selectLimit:Ml,selectSeries:Sc,wrapSync:x};e.default=ZA,e.apply=i,e.applyEach=If,e.applyEachSeries=_f,e.asyncify=x,e.auto=Cc,e.autoInject=xm,e.cargo=Ao,e.compose=bc,e.concat=bm,e.concatLimit=Sl,e.concatSeries=vc,e.constant=Bc,e.detect=As,e.detectLimit=ei,e.detectSeries=Il,e.dir=vm,e.doDuring=Bm,e.doUntil=Tm,e.doWhilst=Qf,e.during=ym,e.each=Tc,e.eachLimit=Dl,e.eachOf=Yr,e.eachOfLimit=_i,e.eachOfSeries=Es,e.eachSeries=vo,e.ensureAsync=yc,e.every=Bo,e.everyLimit=_l,e.everySeries=kc,e.filter=wc,e.filterLimit=Ml,e.filterSeries=Sc,e.forever=Rm,e.groupBy=To,e.groupByLimit=Lc,e.groupBySeries=K,e.log=W,e.map=pc,e.mapLimit=Mi,e.mapSeries=Df,e.mapValues=mt,e.mapValuesLimit=j,e.mapValuesSeries=wt,e.memoize=Le,e.nextTick=Ic,e.parallel=Rn,e.parallelLimit=Ul,e.priorityQueue=yo,e.queue=Zf,e.race=Ol,e.reduce=ti,e.reduceRight=ko,e.reflect=qt,e.reflectAll=wm,e.reject=Nl,e.rejectLimit=td,e.rejectSeries=Sm,e.retry=Ro,e.retryable=ni,e.seq=xc,e.series=Pl,e.setImmediate=E,e.some=Fl,e.someLimit=Oi,e.someSeries=Kl,e.sortBy=ed,e.timeout=Vl,e.times=Dm,e.timesLimit=So,e.timesSeries=_m,e.transform=Mm,e.tryEach=Hl,e.unmemoize=jl,e.until=Um,e.waterfall=nd,e.whilst=zl,e.all=Bo,e.allLimit=_l,e.allSeries=kc,e.any=Fl,e.anyLimit=Oi,e.anySeries=Kl,e.find=As,e.findLimit=ei,e.findSeries=Il,e.forEach=Tc,e.forEachSeries=vo,e.forEachLimit=Dl,e.forEachOf=Yr,e.forEachOfSeries=Es,e.forEachOfLimit=_i,e.inject=ti,e.foldl=ti,e.foldr=ko,e.select=wc,e.selectLimit=Ml,e.selectSeries=Sc,e.wrapSync=x,Object.defineProperty(e,"__esModule",{value:!0})})})(ep,ep.exports);var n2={exports:{}},np=n2.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)?np(n,t):o};np.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=np(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 r2=qo,kM=t2,RM=e2,Sh=Vr,rp=ep.exports,wM=n2.exports,i2=tl.ACTIONS,o2=Ve;function Ve(n,t){if(r2.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}r2.mixin(Ve),Ve.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Ve.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Ve.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||wM();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Ve.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);rp.parallel([function(o){rp.each(e,function(s,l){t.localPresences[s].destroy(l)},o)},function(o){if(!t._wantsDestroy)return o();rp.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)})})},Ve.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?i2.presenceSubscribe:i2.presenceUnsubscribe,r=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[r]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,r,this)},Ve.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Ve.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Ve.prototype._receiveUpdate=function(n,t){var e=Sh.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var r=this,i=Sh.digOrCreate(this._remotePresenceInstances,t.id,function(){return r._createRemotePresence(t.id)});i.receiveUpdate(t)},Ve.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Ve.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()}},Ve.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Ve.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Ve.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)})},Ve.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Ve.prototype._callbackOrEmit=function(n,t){if(t)return Sh.nextTick(t,n);n&&this.emit("error",n)},Ve.prototype._createLocalPresence=function(n){return new kM(this,n)},Ve.prototype._createRemotePresence=function(n){return new RM(this,n)},Ve.prototype._callEachOrEmit=function(n,t){var e=Sh.callEach(n,t);!e&&t&&this.emit("error",t)};var Eu=t2,s2=Th,SM=Vr,l2=s2.CODES,LM=Hr;function Hr(n,t){Eu.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),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()}Hr.prototype=Object.create(Eu.prototype),Hr.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:l2.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,Eu.prototype.submit.call(this,n,t)},Hr.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createOrDelHandler),this._doc.removeListener("del",this._createOrDelHandler),this._doc.removeListener("load",this._loadHandler),this._doc.removeListener("destroy",this._destroyHandler),Eu.prototype.destroy.call(this,n)},Hr.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={})})}},Hr.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createOrDelHandler),this._doc.on("del",this._createOrDelHandler),this._doc.on("load",this._loadHandler),this._doc.on("destroy",this._destroyHandler)},Hr.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)}},Hr.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},Hr.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},Hr.prototype._message=function(){var n=Eu.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},Hr.prototype._transformPresence=function(n,t,e){var r=this._doc.type;if(!SM.supportsPresence(r))throw new s2(l2.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+r.name);return r.transformPresence(n,t,e)};var a2={};(function(n){var t=gu,e=Th,r=Vr,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 x=E.p,v=h,R=0;R<x.length;R++){var L=x[R];Object.prototype.toString.call(v)=="[object Array]"?x[R]=+L:v.constructor===Object&&(x[R]=L.toString()),v=v[L]}C<d.length-1&&(h=t.defaultType.apply(h,[E]))}}}}})(a2);var Au=e2,IM=a2,DM=pr;function pr(n,t){Au.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._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()}pr.prototype=Object.create(Au.prototype),pr.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},pr.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createDelHandler),this._doc.removeListener("del",this._createDelHandler),this._doc.removeListener("load",this._loadHandler),Au.prototype.destroy.call(this,n)},pr.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createDelHandler),this._doc.on("del",this._createDelHandler),this._doc.on("load",this._loadHandler)},pr.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))}})}},pr.prototype._handleOp=function(n,t,e){var r=e===this.src;this._transformAgainstOp(n,r),this._cacheOp(n,r),this._setPendingPresence()},Au.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},Au.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},pr.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)}},pr.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++):IM.transformPresence(this._pending,t,e)}var r=this._pending.v>=this._doc.version;return r&&this._stopCachingOps(),r},pr.prototype._startCachingOps=function(){this._opCache=[]},pr.prototype._stopCachingOps=function(){this._opCache=null},pr.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var c2=o2,_M=LM,MM=DM;function Ba(n,t,e){var r=Ba.channel(t,e);c2.call(this,n,r),this.collection=t,this.id=e}var UM=Ba;Ba.prototype=Object.create(c2.prototype),Ba.channel=function(n,t){return n+"."+t},Ba.prototype._createLocalPresence=function(n){return new _M(this,n)},Ba.prototype._createRemotePresence=function(n){return new MM(this,n)};var OM=NM;function NM(n,t,e,r,i){this.id=n,this.v=t,this.type=e,this.data=r,this.m=i}var PM=OM,u2=qo,f2=xu;function xu(n,t,e,r,i){if(u2.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}u2.mixin(xu),xu.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},xu.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},xu.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,r=new PM(this.id,t.v,t.type,t.data,e);this.callback(null,r)};var d2=f2,FM=Vr,KM=tl.ACTIONS,VM=ip;function ip(n,t,e,r,i,o){if(d2.call(this,n,t,e,r,o),!FM.isValidVersion(i))throw new Error("Snapshot version must be a positive integer or null");this.version=i}ip.prototype=Object.create(d2.prototype),ip.prototype._message=function(){return{a:KM.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var h2=f2,$M=Vr,HM=tl.ACTIONS,jM=op;function op(n,t,e,r,i,o){if(h2.call(this,n,t,e,r,o),!$M.isValidTimestamp(i))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=i}op.prototype=Object.create(h2.prototype),op.prototype._message=function(){return{a:HM.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var zM=CM,GM=vM,WM=o2,m2=UM,qM=VM,XM=jM,g2=qo,Ta=Th,ie=tl.ACTIONS,p2=gu,jr=Vr,bu=zB,vu=Ta.CODES;function C2(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var QM=yt;function yt(n){g2.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=C2(n),this.bindToSocket(n)}g2.mixin(yt),yt.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=C2(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{bu.warn("Failed to parse message",r);return}e.debug&&bu.info("RECV",JSON.stringify(i));var o={data:i};if(e.emit("receive",o),!!o.data)try{e.handleMessage(o.data)}catch(s){jr.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)}},yt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=E2(n.error,n),delete n.error),n.a){case ie.initLegacy:return this._handleLegacyInit(n);case ie.handshake:return this._handleHandshake(t,n);case ie.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case ie.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case ie.queryUnsubscribe:return;case ie.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 ie.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case ie.bulkSubscribe:case ie.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case ie.snapshotFetch:case ie.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case ie.fetch:var r=this.getExisting(n.c,n.d);r&&r._handleFetch(t,n.data);return;case ie.subscribe:case ie.unsubscribe:var r=this.getExisting(n.c,n.d);r&&r._handleSubscribe(t,n.data);return;case ie.op:var r=this.getExisting(n.c,n.d);r&&r._handleOp(t,n);return;case ie.presence:return this._handlePresence(t,n);case ie.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case ie.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case ie.presenceRequest:return this._handlePresenceRequest(t,n);case ie.pingPong:return this._handlePingPong(t);default:bu.warn("Ignoring unrecognized message",n)}};function E2(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}yt.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](E2(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 bu.error("Invalid bulk message",t)},yt.prototype._reset=function(){this.agent=null},yt.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 Ta(vu.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)}},yt.prototype.startBulk=function(){this.bulk||(this.bulk={})},yt.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},yt.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})}},yt.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)}},yt.prototype.sendFetch=function(n){return this._sendActions(ie.fetch,n,n.version)},yt.prototype.sendSubscribe=function(n){return this._sendActions(ie.subscribe,n,n.version)},yt.prototype.sendUnsubscribe=function(n){return this._sendActions(ie.unsubscribe,n)},yt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:ie.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)},yt.prototype.send=function(n){this.debug&&bu.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},yt.prototype.ping=function(){if(!this.canSend)throw new Ta(vu.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:ie.pingPong};this.send(n)},yt.prototype.close=function(){this.socket.close()},yt.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},yt.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),r=e[t];return r||(r=e[t]=new zM(this,n,t),this.emit("doc",r)),r._wantsDestroy=!1,r},yt.prototype._destroyDoc=function(n){!n._wantsDestroy||(jr.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},yt.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},yt.prototype._createQuery=function(n,t,e,r,i){var o=this.nextQueryId++,s=new GM(n,this,o,t,e,r,i);return this.queries[o]=s,s.send(),s},yt.prototype._destroyQuery=function(n){delete this.queries[n.id]},yt.prototype.createFetchQuery=function(n,t,e,r){return this._createQuery(ie.queryFetch,n,t,e,r)},yt.prototype.createSubscribeQuery=function(n,t,e,r){return this._createQuery(ie.querySubscribe,n,t,e,r)},yt.prototype.hasPending=function(){return!!(this._firstDoc(Lh)||this._firstQuery(Lh)||this._firstSnapshotRequest())};function Lh(n){return n.hasPending()}yt.prototype.hasWritePending=function(){return!!this._firstDoc(YM)};function YM(n){return n.hasWritePending()}yt.prototype.whenNothingPending=function(n){var t=this._firstDoc(Lh);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(Lh);if(e){e.once("ready",this._nothingPendingRetry(n));return}var r=this._firstSnapshotRequest();if(r){r.once("ready",this._nothingPendingRetry(n));return}jr.nextTick(n)},yt.prototype._nothingPendingRetry=function(n){var t=this;return function(){jr.nextTick(function(){t.whenNothingPending(n)})}},yt.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}}},yt.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},yt.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},yt.prototype.fetchSnapshot=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new qM(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},yt.prototype.fetchSnapshotByTimestamp=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new XM(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},yt.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},yt.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},yt.prototype._initializeHandshake=function(){this.send({a:ie.handshake,id:this.id})},yt.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},yt.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},yt.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new Ta(vu.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(p2.map[n.type]!==p2.defaultType)return this.emit("error",new Ta(vu.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new Ta(vu.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},yt.prototype.getPresence=function(n){var t=this,e=jr.digOrCreate(this._presences,n,function(){return new WM(t,n)});return e._wantsDestroy=!1,e},yt.prototype.getDocPresence=function(n,t){var e=m2.channel(n,t),r=this,i=jr.digOrCreate(this._presences,e,function(){return new m2(r,n,t)});return i._wantsDestroy=!1,i},yt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var r={a:n,ch:e.channel,seq:t};return this.send(r),r.seq},yt.prototype._addPresence=function(n){jr.digOrCreate(this._presences,n.channel,function(){return n})},yt.prototype._handlePresenceSubscribe=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},yt.prototype._handlePresenceUnsubscribe=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},yt.prototype._handlePresence=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},yt.prototype._handlePresenceRequest=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var A2=QM,ZM=gu;const Ih={err:1001,msg:"user auth error",name:"AuthError"},JM={err:1002,msg:"you don't have required permission",name:"PermissionError"},sp={err:1003,msg:"Too many user connected",name:"MaxUserError"},Bu={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},tU={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},eU={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},ya="x-live-editor-token",Tu="x-live-editor-base-url",vn=I("auth-connection");function nU(n){try{n()}catch(t){vn.error(t)}}class rU{constructor(t,e){g(this,"enabled",!0);g(this,"connection");g(this,"ws");g(this,"retryCount");g(this,"events",new zx.EventEmitter);g(this,"token",null);g(this,"resourceToken",null);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 ji(this.getBaseURL())}async auth(t){p(vn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,r=await window.fetch(e,{method:"GET",headers:{[ya]:t.token,[Tu]:this.getBase64BaseURL()},credentials:"include"});if(r.status!==200)throw new Error("http auth error");return 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:{[Tu]:ji(this.getBaseURL())}})}async init(t){const e=await this.auth(t);if(!this.enabled)return;this.resourceToken=e.read,this.ws=new s6.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(A2.prototype),p(vn,this.connection,"no this.connection"),this.ws,this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})};const r=this.connection.handleMessage.bind(this.connection);this.connection.handleMessage=i=>{var s;const o=i;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in o||o.a==="pong")this.handleMessage(o);else{Object.prototype.hasOwnProperty.call(o,"a")&&o.a!=="init"&&o.a!=="hs"&&(this.retryCount=0);try{r(o)}catch(l){if((l==null?void 0:l.type)==="writeConflict"){this.emitWriteConflictError(l,o);return}if((s=l==null?void 0:l.message)!=null&&s.startsWith("Cannot invert subtype")){this.emitWriteConflictError(l,o);return}throw l}}},A2.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,vn.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const t=await this.reauthFunc();if(await this.auth(t),!this.enabled){this.retryCount=10,setTimeout(()=>this.handleAuthError(),0);return}this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})}}}catch(t){vn.error(t),setTimeout(()=>this.handleAuthError(),0)}}else vn.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(Ih.msg);t.code=Ih.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Bu.msg);t.code=Bu.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===Ih.err)vn.warn("auth error"),this.handleAuthError();else if(r===sp.err)vn.warn(sp.msg),this.emitMaxUsersError();else if(r===Bu.err){vn.warn(Bu.msg);try{this.emitRequestReloadError()}catch(i){vn.error(`error occurred while process reload error: ${JSON.stringify(i)}`)}finally{this.end(!1)}}else vn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return p(vn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(p(vn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onAuthError(t){this.events.addListener("error",t)}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){p(vn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){p(vn,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e;this.enabled=!1,this.reauthFunc=void 0,this.events.removeAllListeners(),nU(()=>{var r;return(r=this.connection)==null?void 0:r.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}I("utils/file");function iU(){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}iU();async function oU(n){const e=n.size,r=Math.floor((e+102400-1)/102400),i=new l6.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 ji(o)}const Ci=I("sharedb-doc/client"),sU=Wx.default.create();class lU{constructor(t,e,r){g(this,"connection");g(this,"auth");g(this,"doc",null);g(this,"reauthFunc");g(this,"clientId",J());g(this,"getDoc",async()=>{const t=r=>new Promise((i,o)=>{r.fetch(s=>{s?o(s):i()})});p(Ci,!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),Ci.debug(e),e});this.auth=t;const i=`${e}/${this.auth.appId}/${this.auth.docId}`;ZM.register(hd.type),this.connection=new rU(i,r),this.reauthFunc=r}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(Ci,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)}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`;let i=[];t.forEach(l=>{const c=l.split("|");i.push(...c)}),i=Array.from(new Set(i));const o=i.map(l=>this.getFileUrlByHash(r,l,"",0,{[ya]:this.connection.token}));return await Promise.all(o)}async uploadFile(t,e,r,i,o){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=x=>{Ci.info(`on progress: ${x.loaded}`);let v=x.loaded*100/s;v>100&&(v=100),i(v)},c=await oU(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 Ci.info(E),i(100),Array.isArray(E.data)?E.data[0]:E.data}async uploadResource(t,e=()=>{},r){const o=`${this.apiServer()}/resources`;p(Ci,this.connection.token,"no connection token");const s=await this.uploadFile(o,t,{[ya]:this.connection.token},e,r);return p(Ci,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(Ci,r,"no token"),c.headers={...c.headers,[ya]:r,[Tu]:this.connection.getBase64BaseURL()};try{return await sU(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(Ci,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=qx.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(Ci,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/${ji(t)}`;return(await this.request(r)).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&&o.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const s=o.join("&");i+=`?${s}`}return i}}function aU(){return{blocks:[{id:J(),type:"text",text:[]}],comments:{},meta:{}}}const lp=I("block-ids");class cU{constructor(){g(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(lp,s!==void 0,"old id is not exists"),this.ids.delete(o),this.ids.set(o+1,s)}}const r=J();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(lp,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=J(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class uU{constructor(){g(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new cU,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(lp,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class x2{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 ap=I("op-parse-handler");class fU{constructor(t,e){g(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 uU,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&&(ap.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)){ap.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 x2,r.set(d,h)),h.delete(l.key)}else p(ap,!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 x2,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 $e=I("op-parser");class b2{}class cp{constructor(t){g(this,"key");this.key=t}}function dU(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($e,s.id,"block id is required"),p($e,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 up(n,t,e,r){if(e==="upsert"&&dU(n,t,r))return;p($e,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($e,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),p($e,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($e,i.length===0,`invalid block ops.length !== 0, ${JSON.stringify(i)}`)}else if(Array.isArray(l)){p($e,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];p($e,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const d=l[1];if(c==="text"){if(p($e,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 cp(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 b2),e==="upsert"&&c.i&&r.onInsertBlock(n,o,c.i),i.shift()}else{p($e,typeof l=="string","data is not string"),p($e,l!=="text","data !== 'text'"),p($e,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 cp(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i),i.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof b2?r.onDeleteBlock(n,o):l instanceof cp?r.onDeleteBlockData(n,o,l.key):p($e,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function hU(n,t,e){$e.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function mU(n,t,e){const r=n[1],i=n[2];p($e,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),p($e,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?$e.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):$e.error(`unknown comment op, ${JSON.stringify(n)}`)}function fp(n,t,e){const r=n[0];if(Array.isArray(r)){r.forEach(s=>{fp(s,t,e)});return}const i=r;if(p($e,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){hU(n);return}if(i==="comments"){mU(n,t,e);return}const o=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{up(o,s,t,e)}):n.slice(1).forEach(s=>{up(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($e,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),up(o,n.slice(1),t,e)}function dp(n,t,e){const r=new fU(t,e);for(let i=0;i<2;i++){const o=i===0?"remove":"upsert",s=gt.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{fp(c,o,r)}):fp(s,o,r)}r.end()}const gU=I("sharedb-comments");function hp(n){const t=n.blocks;p(gU,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)}),gt.default(e)}function v2(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 mp(n,t){const e=Z_(t),{comments:r,meta:i,blocks:o,...s}=e,l={...n,blocks:o,...s},c=gt.default(l);return delete c.children,c}const oe=I("sharedb-doc/doc-container"),B2="ot-json1";hd.type.registerSubtype(J_.type),hd.type.name=B2,hd.type.invert=null;class yu extends ea{constructor(e,r,i=!0){super();g(this,"doc");g(this,"client");g(this,"localPresence");g(this,"remoteCaretHandler",new Q_);g(this,"batching",0);g(this,"status","clean");g(this,"disableLogout");g(this,"destroyed",!1);g(this,"handleNothingPending",()=>{this.setStatus("clean")});g(this,"handleCreate",()=>{this.handleReload("doc created")});g(this,"handleDel",()=>{});g(this,"handleReload",e=>{this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)})});g(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()});g(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});g(this,"insertObject",async(e,r,i)=>{const o=[e,r,{i}];return this.submitOp(o)});g(this,"deleteObject",async(e,r)=>{const i=[e,r,{r:!0}];return this.submitOp(i)});g(this,"replaceObject",async(e,r,i)=>{const o=[e,r,{r:!0,i}];return this.submitOp(o)});g(this,"updateObject",async(e,r,i)=>{const o=this.data()[e][r],s=[e,r];return Object.entries(i).forEach(([l,c])=>{if(!Pc.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)});g(this,"broadcastMessage",async e=>{const r={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(r)});g(this,"data",()=>this.doc.data);g(this,"submitOp",async e=>new Promise((r,i)=>{if(this.destroyed){oe.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},o=>{o?(oe.error(`invalid op, ${o.message}, ${JSON.stringify(e)}`),i(o),oe.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):r()}),this.doc.data||(oe.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));g(this,"createDoc",async e=>new Promise((r,i)=>{this.doc.create(e,B2,o=>{o?i(o):r()})}));g(this,"submitInsertChildContainers",async e=>{if(e.length===0)return Promise.resolve();const r=e.map(({containerId:i,blocks:o})=>[oo(i),{i:o}]);return this.submitOp([r])});g(this,"submitDeleteChildContainer",async e=>{const r=[oo(e),{r:!0}];return this.submitOp(r)});g(this,"submitInsertBlock",async(e,r,i)=>{const o=[oo(e),r,{i}];return this.submitOp(o)});g(this,"submitDeleteBlock",async(e,r)=>{const i=[oo(e),r,{r:!0}];return this.submitOp(i)});g(this,"submitUpdateBlockData",async(e,r,i)=>{if(i.delete.length===0&&Object.keys(i.insert).length===0)return Promise.resolve();const o=[oo(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)});g(this,"submitUpdateRichText",async(e,r,i)=>{const o=[oo(e),r,"text",{e:i,et:"rich-text"}];return this.submitOp(o)});g(this,"handleOp",(e,r,i)=>{if(this.destroyed){oe.warn("handleOp: destroyed");return}try{dp(e,this,!!r)}catch(o){throw oe.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(oe,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const r=new lU(e.auth,e.serverUrl,e.reauthFunc),i=await r.getDoc(),o=new yu(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||aU())}return await o.initPresence(),await o.subscribe(),o.initEvents(),o}catch(r){throw oe.error(r),oe.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.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(J()),e())})}})}subscribe(){return new Promise((e,r)=>{this.doc.subscribe(i=>{i?r(i):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return io(this.data())}getContainerBlocks(e){const r=this.data();p(oe,r,"no doc data");const i=r[oo(e)];return p(oe,i,`no container data: ${e}`),gt.default(i)}findContainerBlocks(e){const r=this.data();p(oe,r,"no doc data");const i=r[oo(e)];return i!=null?i:null}getBlockData(e,r){const i=this.data();p(oe,i,"no doc data");const o=i[oo(e)];p(oe,o,`no container data: ${e}`);const s=o[r];return p(oe,s,`no block data: ${r}`),gt.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(oe,o.text,"no block text");const s=gt.default(o.text);this.submitUpdateRichText(e,r,i);const l=dn.apply(s,i);return p(oe,l,"no block text"),l}localUpdateBlockData(e,r,i){const o=gt.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=>v2(r))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const r=this.data().comments[e];return hp(r)}localCreateComment(e,r){const i=mp(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=mp(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(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onDeleteBlock)==null?void 0:s.call(o,va(e),r,i)})}onInsertBlock(e,r,i,o){p(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,va(e),r,i,o)})}onUpdateBlockData(e,r,i,o){p(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,va(e),r,i,o)})}onUpdateBlockText(e,r,i,o){p(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,va(e),r,i,o)})}onDeleteContainer(e,r){p(oe,this.callbacks.length>0,"no callbacks"),p(oe,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,va(e),r)})}onCreateContainer(e,r,i){p(oe,this.callbacks.length>0,"no callbacks"),p(oe,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,va(e),r,i)})}onDeleteComment(e,r){p(oe,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(oe,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(oe,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)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}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 io(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return io(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:io(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:io(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){dp(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}I("remote-cursor");class T2{constructor(t){g(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});g(this,"broadcastCaretPos",Ke.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));g(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 y2=I("remote-cursor-decorator");class gp{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(y2,typeof s=="string","invalid path containerId"),p(y2,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),d=fn(r);return i.getSimpleCursors(c.id).forEach((C,E)=>{E>d&&(E=d);const x=C.map(R=>({id:J(),type:"remote-cursor",name:R.user.displayName,time:R.time,rainbowIndex:R.user.rainbowIndex})),v=o.get(E);v?v.push(...x):o.set(E,x)}),{insertions:o}}}const pp=I("sharedb-doc/share-db-server"),pU=Wx.default.create();class CU{constructor(t,e){g(this,"auth");g(this,"clientId",J());this.serverUrl=e,this.auth=t}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(pp,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 ji(this.getBaseURL())}async request(t,e){var o;const r=this.auth.token,i=e||{};i.url=t,i.headers||(i.headers={}),p(pp,r,"no token"),i.headers={...i.headers,[ya]:r,[Tu]:this.getBase64BaseURL()};try{return await pU(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=qx.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(pp,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}}I("sharedb-doc/share-db-server");class k2 extends ea{constructor(e){super();g(this,"remoteUsers",new mu);g(this,"client");this.options=e,this.client=new CU(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 io(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return io(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:io(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:io(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){dp(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}class R2 extends ye.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,r){if(Qt(ci(this.editor,t)))return;const i=this.editor.getBlockByIndex(t,e),o=nt(this.editor.getContainerById(t));o&&this.emit("change",this.editor,o,i,r)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}destroy(){this.editor.doc.unregisterCallback(this)}}function EU(n,t){n.addCustom("child-block-tracker",()=>new R2(n)).addListener("change",t)}function AU(n,t){n.addCustom("child-block-tracker",()=>new R2(n)).removeListener("change",t)}const Cst="",xU={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"}},bU={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},vU={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"}};D.mergeLang({"zh-CN":xU,"en-US":bU,"ja-JP":vU});const Est="";I("button");function Cr(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&&z(o,"checked"),r.indexOf("disabled")!==-1&&(o.disabled=!0),r.indexOf("primary")!==-1&&z(o,"primary")),o}const Ast="",Dh=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
24
|
+
`:""}const G3={boxType:"br",updateBoxContent:X8,convertTo:Q8},W3=I("editor-boxes");class q3{constructor(t){g(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,r=this.boxes.get(e);p(W3,!r,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return p(W3,e,`unknown box type: ${t}`),e}createBox(t,e){const r=nv(e),i=iv(r);return this.getBoxClass(e.type).updateBoxContent(this.editor,r,i,e),r}forEach(t){this.boxes.forEach(t)}}function Y8(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 X3={boxType:"image",updateBoxContent:Y8},Z8="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9InJnYigxNzgsIDE4OCwgMjA1KSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0ibTE3IDE1IDEuNTUgMS41NWMtLjk2IDEuNjktMy4zMyAzLjA0LTUuNTUgMy4zN1YxMWgzVjloLTNWNy44MkMxNC4xNiA3LjQgMTUgNi4zIDE1IDVjMC0xLjY1LTEuMzUtMy0zLTNTOSAzLjM1IDkgNWMwIDEuMy44NCAyLjQgMiAyLjgyVjlIOHYyaDN2OC45MmMtMi4yMi0uMzMtNC41OS0xLjY4LTUuNTUtMy4zN0w3IDE1bC00LTN2M2MwIDMuODggNC45MiA3IDkgN3M5LTMuMTIgOS03di0zbC00IDN6TTEyIDRjLjU1IDAgMSAuNDUgMSAxcy0uNDUgMS0xIDEtMS0uNDUtMS0xIC40NS0xIDEtMXoiPjwvcGF0aD4KPC9zdmc+Cg==";function J8(n,t,e){z(e,"editor-box-anchor"),fg(Z8,[],e)}const Q3={boxType:"anchor",updateBoxContent:J8};function tD(n,t,e,r){B("span",[],e,r.text)}const Y3={insertionType:"inputting",updateInsertionContent:tD},Z3=I("editor-insertion");class J3{constructor(t){g(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,r=this.insertions.get(e);p(Z3,!r,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return p(Z3,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const r=ov(e.type,e.id,e.attributes),i=lv(r);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,r,i,e),r}}class eD{constructor(t){g(this,"cursors",new Map);g(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=sv(this.editor,e);i&&ot(i,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function nD(n,t,e,r){var l;const i=r;Date.now()-i.time<5*1e3&&(n.addCustom("active-cursors",d=>new eD(d)).add(i.id,i.time),z(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 p1={insertionType:"remote-cursor",updateInsertionContent:nD};class tB{constructor(t){g(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=gt.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=gt.default(c))}}}),{insertions:i,text:r}}}const C1=I("editor-input");class rD{constructor(t,e){g(this,"editor");g(this,"composing",!1);g(this,"callbacks");g(this,"inputElement");g(this,"handleDocumentClick",t=>{const e=this.editor.rootContainer,r=t.target;if(r&&e.contains(r)&&!Hs(r)){this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus();return}this.editor.emit("blur",this.editor),this.callbacks.onBlur()});g(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&this.editor.contains(t)&&!Hs(t)||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});g(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});g(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});g(this,"handleCompositionstart",t=>{!this.editor.isWritable()||(this.composing=!0,this.callbacks.onCompositionStart(t))});g(this,"handleCompositionend",t=>{$c()?setTimeout(()=>{this.composing=!1},100):this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});g(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="")}});g(this,"handleKeyDown",t=>{if(console.log("handleKeyDown"),!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}!this.editor.isWritable()||setTimeout(()=>{this.composing||(this.inputElement.value="")})}});g(this,"handleCopy",t=>{this.callbacks.onCopy(t)});g(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onCut(t),C1.debug("on cut")});g(this,"handlePaste",t=>{if(t.target instanceof HTMLInputElement&&this.inputElement===t.target){if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)}});g(this,"handlePasteText",(t,e)=>{this.callbacks.onPasteText(t,e)});this.editor=t,this.callbacks=e;const r=B("input",["editor-input"],t.contentElement);r.type="text",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)}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),t.oncut=null}getInput(){return this.inputElement}focus(){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),he.isMobileSafari?(this.inputElement.focus(),z(this.editor.rootElement,"active")):setTimeout(()=>{this.inputElement.focus(),z(this.editor.rootElement,"active")})}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(C1,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,r,i,o)}defaultHandleKeydown(t,e){return p(C1,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}forEach(t){this.callbacks.forEach(t)}}function eB(n){const t=n.rootElement,e=t.getBoundingClientRect(),r=ur(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,x=0-e.top+C,v=n.input.inputElement;v.style.left=`${E/r}px`,v.style.top=`${x/r}px`}const E1=I("editor-caret");function iD(){const t=window.navigator.userAgent.match(/Firefox\/(\d+)\./);return t?Number.parseInt(t[1],10):null}class oD{constructor(t){g(this,"editor");g(this,"caretElem");g(this,"handleReadOnlyChanged",()=>{this.update()});if(this.editor=t,this.caretElem=B("div",["editor-cursor"],this.editor.contentElement),he.isFirefox){const e=iD();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 _e))return!1;const e=this.editor.getBlockById(t.blockId);return!!et(this.editor,e)}update(){if(ub(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",eB(this.editor);return}const{range:e}=this.editor.selection;p(E1,e.isCollapsed,"range is not collapsed");const r=e.start;p(E1,r instanceof _e,"only simple block position can has caret");const i=this.editor.getBlockById(r.blockId);p(E1,et(this.editor,i),"only text kind block can has caret");let o;const s=i.querySelector("span.inputting-insertion");s?(o=Is(s),o=new DOMRect(o.right,o.top,1,o.height)):o=Xn(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`,he.isMobileSafari&&(h.style.left=`${c-4}px`,h.style.height=`${o.height}px`);const E=cn(i,{horizontal:!0}).getBoundingClientRect(),x=E.left-l.left,v=x+E.width;c<x||c>v?(eB(this.editor),t.style.display="none"):t.style.display=""}}function sD(n){uv(n),n.selection.range.getSelectedBlocks().forEach(t=>fv(n,t.block,t.start,t.end))}const lD=I("editor-dom");function nB(n){return cn(n.rootContainer).clientHeight}function aD(n){return n.getFirstBlock().getBoundingClientRect().top}function cD(n){return n.getLastBlock().getBoundingClientRect().bottom}function ih(n){const e=cn(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 uD(n,t){const e=ih(n),r=n.getBlockById(t.blockId),o=_r(n,r,t);return Ms(e,o.x,o.y)&&Ms(e,o.right,o.bottom)}function rB(n,t){const e=ih(n),r=t.getBoundingClientRect();return r.top>=e.top&&r.top<=e.bottom||r.bottom<=e.bottom&&r.bottom>=e.top}function iB(n,t){const e=ih(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 fD(n,t){const e=ih(n),r=t.getBoundingClientRect();return Ms(e,r.x,r.y)||Ms(e,r.right,r.bottom)}function dD(n){if(!pg(n.rootContainer)){lD.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);fD(n,E)||E.scrollIntoView();return}if(e.range.start.blockId===e.range.end.blockId){const C=n.getBlockById(e.range.start.blockId);if(Re(C)&&rB(n,C)&&iB(n,C)>=95)return;const E=Ud(C);if(_t(n,E)&&rB(n,C)){if(iB(n,C)>=95)return;const x=Gt(E);if(x){_s(x,{elementToScroll:cn(n.rootContainer)});return}}}const i=r,o=n.getBlockById(i.blockId);if(uD(n,i))return;if(Re(o)){const C=Gt(o);if(C){["image"].includes(un(o))?setTimeout(()=>{_s(C,{elementToScroll:cn(n.rootContainer)})},500):_s(C,{elementToScroll:cn(n.rootContainer)});return}}const s=_r(n,o,i),l=o.getBoundingClientRect(),c=ne(o),d=B("div",["editor-block-anchor"],c),h=ur(o);d.style.top=`${(s.top-l.top)/h}px`,_s(d,{elementToScroll:cn(n.rootContainer)}),setTimeout(()=>{d.remove()},200)}function hD(n,t){if(t.isCollapsed())return!1;const e=ke(n.rootContainer),r=Ze(n.rootContainer),{start:i,end:o}=t;return i.blockId===st(e)&&i.offset===0&&o.blockId===st(r)&&o.offset===dt(n,r)}const oB=I("range-in-block");function sB(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 lB(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=me(t);if(o){for(;o&&!r.has(st(o));)o=me(o);p(oB,o,"no prev block while deleting a block"),i=ve(n,o,dt(n,o))}else{const s=Gt(t);p(oB,s,"no prev and next block while deleting a block"),i=ve(n,s,0)}return i}const mD=I("block-to-html");function A1(n,t,e,r){const i=Ns(n,t.type);if(i.convertTo)return i.convertTo(n,t,e,"html",r);if(i.blockKind!=="text")return`[${t.type}]`;p(mD,t.text,"no text");const o=ce(t.text);return`<div>${Bd(o)}</div>`}const aB=I("block-to-text");function gD(n,t,e){let r="";return t.forEach(i=>{if(p(aB,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 oh(n,t,e,r){const i=Ns(n,t.type);return i.convertTo?i.convertTo(n,t,e,"text",r):i.blockKind!=="text"?`[${t.type}]`:(p(aB,t.text,"no text"),gD(n,t.text,e))}function x1(n,t,e,r){const i=Ns(n,t.type);return i.convertTo?i.convertTo(n,t,e,"markdown",r):oh(n,t,e,r)}function sh(n,t){return t.blocks.root.map((i,o)=>A1(n,i,t,[{containerId:"root",blockIndex:o}])).join(`
|
|
25
|
+
`)}function cB(n,t){return`<!doctype html><html><head><meta charset="utf8" /></head><body>${sh(n,t)}</body></html>`}function Qs(n,t){return t.blocks.root.map((i,o)=>oh(n,i,t,[{containerId:"root",blockIndex:o}])).join(`
|
|
26
|
+
`)}function uB(n,t){const e=t.blocks.root.map((i,o)=>x1(n,i,t,[{containerId:"root",blockIndex:o}]));return e[e.length-1]=e[e.length-1].trimEnd(),e.join(`
|
|
27
|
+
`)}const pD=I("get-text-position");function ga(n,t){const e=t!=null?t:n.selection.range.start;e instanceof _e||p(pD,!1,`invalid insert pos type: ${typeof e}`);const{blockId:r}=e,i=n.getBlockById(r),o=bt(i),s=it(i),l=ft(s),{offset:c}=e;return{block:i,container:s,containerId:l,blockIndex:o,offset:c}}const pa=I("insert-text");function b1(n,t,e,r){var s;const i=n.doc.getBlockData(t,e);if(p(pa,i,"no block data"),p(pa,i.text,"no block text"),fn(i.text)===0)return p(pa,r===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,i.id);if(r===0)return;const o=qe(i.text,r-1,1).middle;if(!((s=o[0].attributes)!=null&&s.box))return o[0].attributes}function CD(n,t,e){const r=it(t),i=ft(r),o=bt(t);return b1(n,i,o,e)}function fB(n,t,e,r,i){const o=it(t),s=ft(o),l=bt(t),c=CD(n,t,e),d=Qd(e,r,c!=null?c:null);return n.doc.localUpdateBlockText(s,l,d,i),bn(n,t)}function dB(n,t,e,r){const i=it(t),o=ft(i),s=bt(t),l=Qd(e," ",r);return n.doc.localUpdateBlockText(o,s,l),bn(n,t)}function ED(n,t){let e=0;if(t===0)return!1;for(let r=0;r<n.length;r++){const i=n[r];p(pa,typeof i.insert=="string","invalid text op, no insert");const o=e+Hd(i);if(o===t)return!1;if(o>t)return!0;e=o}return!1}function v1(n,t,e,r,i){const o=n.doc.getBlockData(e,r);p(pa,o,"no block data"),p(pa,o.text,"no block text");const s=b1(n,e,r,i);s&&Object.keys(s).includes("link")&&(ED(o.text,i)||delete s.link);const l=Qd(i,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,r,l),bn(n,n.getBlockById(o.id))}function B1(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:r,offset:i}=ga(n);v1(n,t,e,r,i)}const lh=I("update-composition-text");function hB(n){const t=n.selection.range.start;t instanceof _e||p(lh,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,r=n.getBlockById(e);p(lh,et(n,r),"not a text kind block");const i=it(r),o=ft(i),s=bt(r),l=n.doc.getBlockData(o,s);p(lh,l,"no block data in doc"),p(lh,l.text,"no text data in text block");const c=Ot(r);zd(n,Ko(r),e,c,l.text)}function T1(n){O7(n)}function Ca(n,t,e,r,i,o){return n.doc.localInsertBlock(t,e,r,i,o),n.getBlockById(r.id)}const su=I("delete-block-text");function y1(n,t,e,r,i){if(!n.isBlockWritable(t))return su.error("block is not writable"),0;p(su,et(n,t),"block is not a text kind block");const o=it(t),s=ft(o),l=bt(t),c=n.doc.getBlockData(s,l);p(su,c,"no block data in doc"),p(su,c.text,"no text data in text block");let d=e;_n(t,e)||(d=Ho(t,d));let h=e+r;p(su,h<=dt(n,t),`invalid offset and count: ${e}, ${r}`),_n(t,h)||(h=Ws(t,h));const C=h-d,E=L3(d,C);return n.doc.localUpdateBlockText(s,l,E,i),console.log("delete"),C}const k1=I("break-text-block");function mB(n,t){const r=n.getBlockData(t).quoted;return r?{quoted:r}:{}}function Ea(n,t,e,r){p(k1,et(n,t),`block is not a text kind block: ${It(t)}`),p(k1,e>=0&&e<=dt(n,t),`invalid offset: ${e}`);const i=it(t),o=ft(i),s=bt(t),l=r!=null&&r.copyBlockAttributes?mB(n,t):{};if(!(r!=null&&r.forceInsertAfter)&&(e===0||e===dt(n,t))){const x=e===0?s:s+1,v={...mi(""),...l,...r==null?void 0:r.newBlockData},R=ve(n,t.id,0),L=Ca(n,o,x,v,R);return{block:t,newBlock:L}}p(k1,_n(t,e),"not a valid offset");const c=bn(n,t),{right:d}=In(c,e),h=fn(d);h>0&&y1(n,t,e,h);const C={...mi(d),...l,...r==null?void 0:r.newBlockData},E=Ca(n,o,s+1,C,ve(n,C.id,0));return{block:t,newBlock:E}}const AD=I("prepare-insert-new-block");function xD(n,t,e){if(t&&e!==void 0&&e!==null){const d=n.getContainerById(t),h=Ce(d);return p(AD,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=ft(it(i)),e=bt(i),!et(n,i))return{containerId:t,blockIndex:e+1};const s=r.offset;if(s===0||s===dt(n,i))return{containerId:t,blockIndex:s===0?e:e+1};const c=Ea(n,i,s).newBlock;return{containerId:t,blockIndex:bt(c)}}const bD=I("auto-insert-block");function gB(n,t,e,r,i,o){const s=xD(n,e,r);p(bD,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},c={anchor:l,focus:l};return Ca(n,s.containerId,s.blockIndex,t,i!=null?i:c,o)}const vD=I("delete-block");function ah(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(r=>{n.getChildContainerData(r).forEach(o=>{ah(n,o,e)})}))}function ch(n,t,e){const r=it(t),i=ft(r),o=bt(t),s=n.doc.getBlockData(i,o);return p(vD,s,"no block data in doc"),n.doc.localDeleteBlock(i,o,We(n,{anchor:e.start,focus:e.end})),s}function R1(n,t,e){return n.undoManager.runInGroup(()=>{const r=it(t);Lr(r)===1&&n.insertTextBlock("",ft(r),0);let i=e?Vo(n,e):null;if(!i){const l=n.selection.range;sB(t,l)?i=lB(n,t):i=l}const o=ch(n,t,i),s=[];return ah(n,o,s),s.length>0&&n.doc.localDeleteChildContainers(s),o})}function BD(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(i=>{ah(n,i,e)}),n.doc.localDeleteChildContainers(e)}function pB(n,t){const e=[...t];t.forEach(r=>{n.doc.getContainerBlocks(r).forEach(o=>{ah(n,o,e)})}),n.doc.localDeleteChildContainers(e)}const w1=I("merge-text-block");function CB(n,t,e){p(w1,et(n,t),"only text block can be merged"),p(w1,et(n,e),"only text block can be merged");const r=jo(n,t),i=jo(n,e),o=r.text,s=i.text;p(w1,o&&s,"block data has no text");const l=it(t),c=ft(l),d=bt(t),h=dt(n,t),C=v1(n,s,c,d,h),E=ve(n,t,fn(o));return R1(n,e,E),C}const gi=I("clear-selected-contents");function uh(n,t){p(gi,et(n,t.block),"not a text kind block");const{start:e,end:r}=t;p(gi,e.isSimple(),"not a simple block position"),p(gi,r.isSimple(),"not a simple block position");const i=e.offset,o=r.offset;p(gi,i<=o,`invalid delete text offset: ${i}, ${o}`),i!==o&&n.deleteTextFromBlock(t.block,i,o-i)}function EB(n,t,e){const r=ft(t),i=Ce(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 TD(n,t){const{block:e,start:r,end:i}=t;if(et(n,e)){uh(n,t);return}if(Re(e)||r.isSimple()){p(gi,i.isSimple(),"invalid range");const s=it(e),l=bt(e),c=n.insertTextBlock("",ft(s),l);n.selection.selectBlock(c,0),n.deleteBlock(e);return}p(gi,_t(n,e),"invalid block kind"),p(gi,!r.isSimple()&&!i.isSimple(),"invalid range"),la(n,e,r,i),n.selection.range.getSelectedContainers().forEach((s,l)=>{EB(n,s,{focus:l===0})})}function yD(n){if(!n.isWritable())return;const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(p(gi,e.length>0,"no selected block"),e.length===1){TD(n,e[0]);return}const r=e[0],i=r.block,o=it(i);p(gi,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(et(n,i)){uh(n,r);const h=ve(n,r.block,r.start.offset);if(e.slice(1,e.length-1).reverse().forEach(E=>n.deleteBlock(E.block)),et(n,l)){uh(n,s),n.mergeTextBlock(i,l,{focus:!0}),n.selection.setRange(h);return}n.deleteBlock(l),n.selection.setRange(h);return}if(et(n,l)){uh(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===Lr(o)){EB(n,o,{focus:!0});return}const c=me(i),d=Gt(l);p(gi,c||d,"no prev or next block"),e.forEach(h=>n.deleteBlock(h.block))}function S1(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),yD(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}const kD=I("core");function AB(n,t,e,r){const i=it(t),o=ft(i),s=bt(t);return n.doc.localUpdateBlockText(o,s,e,r),setTimeout(()=>{n.selection.updateSelection(null)}),bn(n,t)}function xB(n,t,e,r){if(!n.isBlockWritable(t)){kD.error("block is not writable");return}const i=n.getBlockText(t),o=dn.diff(i,e);AB(n,t,o,r)}function fh(n,t,e){const r=bn(n,t),i=typeof e=="string"?Xs(e):e,o=dn.diff(r,i);return AB(n,t,o)}const lu=I("update-block-data");function dh(n,t,e,r){const i=it(t),o=ft(i),s=bt(t),l=n.doc.getBlockData(o,s),c={insert:{},delete:[]},d=new Set(Object.keys(l)),h=new Set(Object.keys(e));return d.forEach(E=>{if(!h.has(E)){if(E==="id"||E==="type"||E==="text")return;lu.debug(`delete key: ${E}`),c.delete.push(E)}}),Object.entries(e).forEach(([E,x])=>{p(lu,E!=="id"&&E!=="type",`invalid block data delta, ${E}`);const v=l[E];if(x==null){v!=null&&(lu.debug(`delete key: ${E}`),c.delete.push(E));return}v!==x&&(Pc.default(v,x)||E==="text"&&dn.diff(v,x).length===0||(d.has(E)?(lu.debug(`replace key: ${E}`),c.delete.push(E)):lu.debug(`insert key: ${E}`),c.insert[E]=x))}),n.doc.localUpdateBlockData(o,s,c,r),jo(n,t)}function bB(n,t,e,r){const o={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,o,r)}function L1(n,t,e){if(!_t(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const i=qn(n,t).getChildContainers(n,t)[0],o=ke(i);L1(n,o,e)}function Ys(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 au=I("clone-block");function zo(n,t,e,r){const i=n.getBlockClass(e.type);if(i.blockToDoc)return i.blockToDoc(t,e,(h,C)=>(p(au,e!==C,"invalid child block"),zo(n,h,e,r)));let o={};const s=new Map,l=gt.default(e);l.children&&(l.children=l.children.map(h=>{const C=J(),E=t.blocks[h];p(au,Array.isArray(E),"invalid child blocks");const x=E.map(M=>zo(n,t,M,r)),v=Ys(x),{root:R,...L}=v.blocks;return o={...o,...L},o[C]=v.blocks.root,s.set(h,C),C}));const c=Array.from(s.entries()),d=h=>{for(const C of c){const[E,x]=C;{const v=`${E}/`;if(h.startsWith(v)){const R=h.substring(v.length),L=`${x}/${R}`;return au.debug(`replace key: ${h} -> ${L}`),L}}{const v=`${E}_`;if(h.startsWith(v)){const R=h.substring(v.length),L=`${x}_${R}`;return au.debug(`replace key: ${h} -> ${L}`),L}}}return h};return Array.from(Object.entries(l)).forEach(([h,C])=>{const E=d(h);E!==h&&delete l.key,l[E]=C}),l.id=J(),r&&(r.blockIdMap.set(e.id,l.id),s.forEach((h,C)=>r.containerIdMap.set(C,h))),{blocks:{root:[l],...o},meta:{},comments:{}}}function I1(n,t,e,r){const i=t.blocks[e];p(au,Array.isArray(i),"invalid child blocks");const o=i.map(l=>zo(n,t,l,r));return Ys(o)}function D1(n,t,e){const r=t.blocks.root.map(i=>zo(n.editorBlocks,t,i,e));return gt.default(Ys(r))}const vB=I("insert-doc");function BB(n,t,e,r,i){if(_t(n,t)){vB.warn("failed to insert doc into a complex block");return}const o=D1(n,r,i),s=it(t),l=bt(t),c=ft(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var F,G,q,rt;const d=[];Object.entries(o.blocks).forEach(([at,At])=>{at!=="root"&&d.push({containerId:at,blocks:At})}),d.length>0&&n.doc.localInsertChildContainers(d);const h=o.blocks.root;if(Re(t)){n.deleteBlock(t);let at;h.reverse().forEach(At=>{const Mt=n.insertBlock(c,l,At,void 0,{noFocus:!0});at||(at=Mt)}),at&&n.selection.selectBlock(at,dt(n,at));return}if(p(vB,et(n,t),"not a text block"),re(n,t)){const at=bt(t);let At,Mt=!1;for(let kt=0;kt<h.length;kt++){if(kt===0){const ue=n.getBlockByIndex(c,at);if(ue&&et(n,ue)&&re(n,ue)&&h[kt].type==="text"){n.insertTextToBlock(t,0,(F=h[kt].text)!=null?F:[]),Object.prototype.hasOwnProperty.call(h[kt],"heading")&&n.updateBlockData(ue,h[kt]);continue}Gi(ue)&&(Mt=!0)}const se=n.insertBlock(c,at+kt,h[kt],void 0,{noFocus:!0});kt===h.length-1&&(At=se)}At&&n.selection.selectBlock(At,dt(n,At)),Mt&&n.deleteBlock(t);return}if(h.length===1){const at=h[0];if(Wc(n,at.type)){n.insertTextToBlock(t,e,(G=at.text)!=null?G:[]);return}n.breakTextBlock(t,e),n.insertBlock(c,l+1,at);return}const C=e===dt(n,t),E=e===0,x=h[0],v=h[h.length-1];let R;!C&&!E?R=n.breakTextBlock(t,e,{forceInsertAfter:!0}):R=t;const L=E?l:l+1;C?(R=n.insertBlock(c,l+1,v),n.selection.selectBlock(R,dt(n,R))):(n.selection.selectBlock(R,0),Wc(n,v.type)?n.insertTextToBlock(R,0,(q=v.text)!=null?q:[]):n.insertBlock(c,L,v));const M=n.selection.range;let U=L;Wc(n,x.type)?E?(n.insertBlock(c,L,x),U+=1):n.insertTextToBlock(t,e,(rt=x.text)!=null?rt:[]):(n.insertBlock(c,L,x),U+=1),h.slice(1,h.length-1).reverse().forEach(at=>{n.insertBlock(c,U,at)}),n.selection.setRange(M)}),n.doc.endBatchUpdate()}function _1(n,t,e,r,i){const o=D1(n,r,i),s=ft(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 TB(n,t,e,r){const i=Lr(t);_1(n,t,i,e,r);for(let o=0;o<i;o++){const s=ke(t);n.deleteBlock(s)}}const cu=I("add-text-attribute");function RD(n,t,e,r){const{start:i,end:o}=e;p(cu,i.blockId===o.blockId&&i.blockId===st(t),"invalid range"),p(cu,r,"invalid attribute name");const s=n.getBlockText(t),l=fa(i.offset,o.offset-i.offset,s,r,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function yB(n,t,e,r,i){const{start:o,end:s}=e;p(cu,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(cu,r,"invalid attribute name");const l=n.getBlockText(t),c=nu(o.offset,s.offset-o.offset,l,r,i);return n.setBlockText(t,c),c}function Aa(n,t,e,r,i){const{start:o,end:s}=e;p(cu,o.blockId===s.blockId&&o.blockId===st(t),"invalid range");const l=n.getBlockText(t),c=E3(o.offset,s.offset-o.offset,l,r,i);return n.setBlockText(t,c),c}function kB(n,t,e,r){const i=fi(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{i.forEach(o=>{const{block:s,start:l,end:c}=o;if(!et(n,s))return;if(re(n,s)){r(n,st(s),t,e);return}const d=We(n,{anchor:l,focus:c});t==="color"||t==="backgroundColor"?Aa(n,s,d,t,e):(Aa(n,s,d,"color",null),Aa(n,s,d,"backgroundColor",null))})})}function RB(n,t,e){const r=fi(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:o,start:s,end:l}=i;if(!et(n,o))return;if(re(n,o)){(t==="clearColor"||t==="clearAll")&&e(n,st(o),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,st(o),"backgroundColor",null);return}const c=We(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Aa(n,o,c,"color",null),(t==="clearBackground"||t==="clearAll")&&Aa(n,o,c,"backgroundColor",null)})})}function wB(n,t,e){const r=t.getSelectedBlocks().filter(l=>et(n,l.block));if(r.length===0)return[null,null];const i=l=>{if(dt(n,l.block)===0)return e(n,st(l.block));const c=l.start,d=l.end,h=n.getBlockText(l.block);return b3(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 Qn=I("adjust-selection-pos");function SB(n){const t=[];for(;n;){const e=it(n);if(t.unshift(e),Qt(e))return t;const r=nt(e);p(Qn,r,"child container has not parent container"),n=r}p(Qn,!1,"should not come here: getParentContainers")}function LB(n,t){for(;t;){const e=it(t);if(e===n)return t;const r=nt(e);p(Qn,r,"could not find parent block for a child container"),t=r}p(Qn,!1,"no parent block in specified container")}function wD(n,t){const e=SB(n),r=SB(t);p(Qn,e.length>0&&r.length>0,"block has not parent container"),p(Qn,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=LB(i,n),s=LB(i,t);return{parentContainer:i,newBlock1:o,newBlock2:s}}function IB(n,t){let e=nt(t);for(p(Qn,e,"element is not in a block");e;){const r=it(e);p(Qn,Mr(r),"not a child container");const i=nt(r);if(p(Qn,i,"child container has not parent block"),i===n)return r;e=i}p(Qn,!1,"failed to find parent container in complex block")}function hh(n,t,e){const r=n.getBlockById(t.blockId),i=n.getBlockById(e.blockId);if(r===i)return t instanceof _e&&e instanceof _e?{anchor:t,focus:e}:t instanceof Ur&&e instanceof Ur?Vd(n,r,t,e):null;const o=it(r),s=it(i);if(o===s)return t instanceof Ur&&(t=lt(r,0,"home")),e instanceof Ur&&(e=lt(i,dt(n,i),"end")),p(Qn,t instanceof _e,"not valid position type"),p(Qn,e instanceof _e,"not valid position type"),{anchor:t,focus:e};if(r.contains(s))return null;if(i.contains(o)){if(t instanceof _e&&e instanceof Ur){const v=n.getContainerById(e.childContainerId);if(v===o)return{anchor:e,focus:e};const R=nt(o);if(R&&R===nt(v)){const L=Ee(R,ft(o)),M=Ee(R,ft(v));return Vd(n,R,L,M)}}return null}const l=bd(r,i)>0,{newBlock1:c,newBlock2:d}=wD(r,i);if(c===d){const v=c,R=IB(v,r),L=IB(v,i);return t=Ee(c,ft(R)),e=Ee(c,ft(L)),Qn.debug(`select in complex block: ${R.id}, ${L.id}`),Vd(n,v,t,e)}let h=l?dt(n,c):0;c===r&&t instanceof _e&&(h=t.offset);let E=l?0:dt(n,d);return d===i&&e instanceof _e&&(E=e.offset),t=lt(c,h,l?"end":"home"),e=lt(d,E,l?"home":"end"),{anchor:t,focus:e}}const SD=I("move-complex-block-position");function LD(n,t,e){const r=n.getBlockById(t.blockId);p(SD,_t(n,r),"is not a complex block");const i=qn(n,r),o=n.getContainerById(t.childContainerId),s=i.getNextContainer(n,r,o,e,{noWrap:!0});return s?Ee(r,ft(s)):null}const uu=I("move-simple-block-position");function DB(n,t){const e=xn(n,t,{visibleOnly:!0});p(uu,e.length>0,"complex block has not any child container");const r=e[0];return ke(r)}function _B(n,t){const e=xn(n,t,{visibleOnly:!0});p(uu,e.length>0,"complex block has not any child container");const r=e[e.length-1];return Ze(r)}function MB(n,t,e){const r=e?DB(n,t):_B(n,t);return _t(n,r)?MB(n,r,e):r}function ID(n,t){const e=n.getBlockById(t.blockId);return _t(n,e)&&t.offset===0?DB(n,e):$s(e)}function DD(n,t){const e=n.getBlockById(t.blockId);return _t(n,e)&&t.offset===1?_B(n,e):Vs(e)}function M1(n){return n==="ArrowLeft"||n==="ArrowUp"}function U1(n,t,e){const r=it(t);if(Qt(r))return null;const i=nt(r);p(uu,i,"child container has not parent block"),p(uu,_t(n,i),"is not a complex block");const o=qn(n,i).getNextContainer(n,i,r,e);return o?M1(e)?Ze(o):ke(o):U1(n,i,e)}function _D(n,t,e){const r=it(t);if(Qt(r))return null;const i=nt(r);if(p(uu,i,"child container has not parent block"),M1(e)){const l=me(i);if(l)return l}else{const l=Gt(i);if(l)return l}const o=U1(n,i,e);if(o)return o;let s=i;for(;!Qt(it(s));)s=nt(it(s));return M1(e)?me(s):Gt(s)}function MD(n,t,e){return!_t(n,t)||qn(n,t).enableKeyboardSelect?t:MB(n,t,e==="ArrowDown"||e==="ArrowRight")}function UD(n,t,e){const r=n.getBlockById(t.blockId),o=Zt(n,r).moveCaret(n,r,t,e);if(o)return o;let s=e==="ArrowDown"||e==="ArrowRight"?ID(n,t):DD(n,t);if(s||(s=U1(n,r,e),s||(s=_D(n,r,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!Qt(it(r)))return null;const l=n.insertTextBlock("",ft(n.rootContainer),Lr(n.rootContainer));return lt(l,0,"home")}return null}if(s=MD(n,s,e),et(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return o8(n,s,r,t,l);if(e==="ArrowUp")return i8(n,s,r,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?lt(s,dt(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?lt(s,0,"home"):null}function OD(n,t,e){if(t==="ArrowLeft")return e.start;const r=e.end,i=n.getBlockById(r.blockId);if(et(n,i))return r;const o=Gt(i);if(o)return lt(o,0,"home");if(!Qt(it(i))||n.readonly)return r;const s=n.insertTextBlock("",ft(n.rootContainer),Lr(n.rootContainer));return lt(s,0,"home")}function ND(n,t,e){const r=n.selection.range;let i;if(r instanceof Ge)e==="move"&&!r.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?i=OD(n,t,r):i=UD(n,r.getFocusedPos(),t);else if(i=LD(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=Ze(s);i=lt(l,0,"home")}else{const l=ke(s);i=lt(l,dt(n,l),"end")}}return i?e==="move"?{anchor:i,focus:i}:hh(n,r.anchor,i):null}function Go(n,t,e){const r=ND(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 UB(n){return Go(n,"ArrowLeft","move"),!0}function OB(n){return Go(n,"ArrowRight","move"),!0}function NB(n){return Go(n,"ArrowUp","move"),!0}function PB(n){if(Go(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=it(t);if(Qt(e)||Ze(e)!==t)return!0;const r=n.rootContainer;return n.insertTextBlock("",ft(r),Lr(r)),!0}function FB(n){return Go(n,"ArrowDown","select"),!0}function KB(n){return Go(n,"ArrowLeft","select"),!0}function VB(n){return Go(n,"ArrowRight","select"),!0}function $B(n){return Go(n,"ArrowUp","select"),!0}const HB=I("word-offset");function O1(n,t){const e=n.selection.range.focus;p(HB,e.isSimple(),"invalid range type");const r=n.getBlockById(e.blockId);if(re(n,r))return lt(r,0,"home");if(e.offset===0||!et(n,r)){const s=me(r);if(!s)return null;const l=lt(s,dt(n,s),"end");if(t==="select"&&et(n,s)){const c=m1(n,s,l.offset);return lt(s,c,"normal")}return l}const i=m1(n,r,e.offset);return lt(r,i,"normal")}function N1(n,t){const e=n.selection.range.focus;p(HB,e.isSimple(),"invalid range type");const r=n.getBlockById(e.blockId);if(re(n,r))return lt(r,0,"end");if(e.offset===dt(n,r)||!et(n,r)){const s=Gt(r);if(!s)return null;const l=lt(s,0,"home");if(t==="select"&&et(n,s)){const c=g1(n,s,l.offset);return lt(s,c,"end")}return l}const i=g1(n,r,e.offset);return lt(r,i,"normal")}function jB(n){if(!n.selection.range.focus.isSimple())return!1;const e=O1(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function zB(n){if(!n.selection.range.focus.isSimple())return!1;const e=N1(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function GB(n){if(!n.selection.range.focus.isSimple())return!1;const e=O1(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function WB(n){if(!n.selection.range.focus.isSimple())return!1;const e=N1(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}I("find-block");function P1(n,t){if(!_t(n,t))return t;const r=qn(n,t).getChildContainers(n,t)[0],o=Ce(r)[0];return P1(n,o)}function F1(n,t){if(!_t(n,t))return t;const e=qn(n,t).getChildContainers(n,t),r=e[e.length-1],i=Ce(r),o=i[i.length-1];return F1(n,o)}function K1(n){const t=F1(n,Ze(n.rootContainer)),e=lt(t,dt(n,t),"end");return n.selection.setSelection(e),!0}function qB(n){const t=P1(n,n.getFirstBlock()),e=lt(t,0,"home");return n.selection.setSelection(e),!0}function XB(n){const t=P1(n,n.getFirstBlock()),e=lt(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function V1(n){const t=F1(n,Ze(n.rootContainer)),e=lt(t,dt(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const QB=I("line-offset");function YB(n){const t=n.selection.range.focus;p(QB,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!et(n,e))return lt(e,0,"home");let i=y3(e,t).start;const{next:o}=Nd(e,i);return o&&hr(o)&&Xc(o)==="br"&&(i+=1),lt(e,i,"home")}function ZB(n){const t=n.selection.range.focus;p(QB,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===dt(n,e)||!et(n,e))return lt(e,dt(n,e),"end");const r=y3(e,t);return lt(e,r.end,"end")}function JB(n){if(!n.selection.range.focus.isSimple())return!1;const e=YB(n);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=ZB(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function e5(n){if(!n.selection.range.focus.isSimple())return!1;const e=YB(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function n5(n){if(!n.selection.range.focus.isSimple())return!1;const e=ZB(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const r5=I("find-block-position");function PD(n,t,e,r){p(r5,_t(n,t),"is not a complex block");const i=qn(n,t).getChildContainers(n,t);p(r5,i.length>0,"complex block has not any child container");const o=_r(n,e,r),s=o.left+o.width/2,l=o.top+o.height/2,c=Ov(n,t,s,l);return $1(n,c,e,r)}function $1(n,t,e,r){if(_t(n,t))return PD(n,t,e,r);const i=st(t);let o=Number.MAX_SAFE_INTEGER;const s=_r(n,e,r),l=s.left+s.width/2,c=s.top+s.height/2;let d=lt(i,0,"home");const h=dt(n,t);for(let C=0;C<=h;C++){const E=lt(i,C,"normal"),x=_r(n,t,E),v=Vi(x,l,c);v<o&&(o=v,d=E)}return d}const i5=I("page-offset");function FD(n,t){const e=nB(n)*.9,i=t.getBoundingClientRect().bottom-e;if(i<aD(n))return n.getFirstBlock();const o=me(t);if(!o)return n.getFirstBlock();let s=o;for(;s;){if(s.getBoundingClientRect().y<i)return s;s=me(s)}return n.getFirstBlock()}function KD(n,t){const e=nB(n)*.9,r=t.getBoundingClientRect(),i=cD(n),o=r.top+e;if(o>i)return n.getLastBlock();const s=Gt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>o)return l;l=Gt(l)}return n.getLastBlock()}function o5(n){const t=n.selection.range.focus;p(i5,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),r=FD(n,e);let i;return r===n.getFirstBlock()?i=lt(r,0,"home"):i=$1(n,r,e,t),i}function s5(n){const t=n.selection.range.focus;p(i5,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),r=KD(n,e);let i;return r===n.getLastBlock()?i=lt(r,dt(n,r),"end"):i=$1(n,r,e,t),i}function l5(n){if(!n.selection.range.focus.isSimple())return!1;const e=o5(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function a5(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 c5(n){if(!n.selection.range.focus.isSimple())return!1;const e=o5(n);if(!e)return!1;const r=hh(n,n.selection.getAnchorPos(),e);if(!r)return!1;const{anchor:i,focus:o}=r;return n.selection.setSelection(i,o),n.selection.updateLastCaretRect(),!0}function u5(n){if(!n.selection.range.focus.isSimple())return!1;const e=s5(n);if(!e)return!1;const r=hh(n,n.selection.getAnchorPos(),e);if(!r)return!1;const{anchor:i,focus:o}=r;return n.selection.setSelection(i,o),n.selection.updateLastCaretRect(),!0}const fu=I("select-all");function f5(n,t){const e=ke(n),r=Ze(n);return t.start.offset===0&&t.start.blockId===st(e)&&t.end.offset===dt(t.getEditor(),r)&&t.end.blockId===st(r)}function VD(n,t){const e=t.getEditor(),r=qn(e,n).getChildContainers(e,n),i=r[0],o=r[r.length-1],s=st(n);return t.start.blockId===s&&t.start.childContainerId===ft(i)&&t.end.blockId===s&&t.end.childContainerId===ft(o)}function $D(n,t){p(fu,t,"no parent block"),p(fu,_t(n,t),"not a complex block");const e=qn(n,t).getChildContainers(n,t),r=e[0],i=e[e.length-1];n.selection.setRange(We(n,{anchor:Ee(t,ft(r)),focus:Ee(t,ft(i))}))}function d5(n,t){const e=it(t);H1(n,e)}function h5(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&et(n,t)){const i=e.start,o=e.end,s=dt(n,t);if(i.offset>0||o.offset<s)return n.selection.selectBlock(t,0,s),!1}return z(n.rootContainer,"select-all"),d5(n,ke(n.rootContainer)),!1}return p(fu,!e.isSimple(),"invalid range type"),VD(t,e)?(d5(n,t),!1):(p(fu,t,"no parent block"),p(fu,_t(n,t),"not a complex block"),$D(n,t),!0)}function H1(n,t){const e=Ce(t),r=e[0],i=e[e.length-1],o=lt(r,0,"home"),s=lt(i,dt(n,i),"end");n.selection.setSelection(o,s,{noScroll:!0})}function HD(n){V1(n),n.focus()}const j1=I("selected-block-to-doc");function m5(n,t,e){!t.children||t.children.forEach(r=>{const i=n.getChildContainerData(r);i.forEach(o=>{m5(n,o,e)}),e.blocks[r]=gt.default(i)})}function mh(n,t){const e=Zt(n,t.block);if(e.selectionToDoc)return e.selectionToDoc(n,t);const r=gt.default(jo(n,t.block));if(et(n,t.block)){const o=t.start,s=t.end;if(p(j1,r.text,"no block text"),o.offset===s.offset)return{blocks:{root:[{...r,text:[]}]},meta:{},comments:{}};const{middle:l}=qe(r.text,o.offset,s.offset-o.offset);return{blocks:{root:[{...r,text:l}]},meta:{},comments:{}}}if(Re(t.block))return{blocks:{root:[r]},meta:{},comments:{}};p(j1,_t(n,t.block),"not complex block"),p(j1,r.children,"no children");const i={blocks:{root:[r]},meta:{},comments:{}};return m5(n,r,i),i}function z1(n,t){const e=lt(t,0,"normal"),r=lt(t,dt(n,t),"end");return mh(n,{block:t,start:e,end:r})}const jD=I("block-to-doc");function zD(n,t){p(jD,t.length>0,"invalid params, no blocks");const e=t.map(r=>z1(n,r));return Ys(e)}function gh(n){const e=n.selection.range.getSelectedBlocks().map(r=>mh(n,r));return Ys(e)}function g5(n,t){const e=n.getContainerById(t),o=Ce(e).map(s=>({start:lt(s,0,"home"),end:lt(s,dt(n,s),"end"),block:s})).map(s=>mh(n,s));return Ys(o)}const ph=I("editor-selection");class GD{constructor(t){g(this,"editor");g(this,"caret");g(this,"_range");g(this,"lastCaretRect");g(this,"handleBlockDelete",(t,e,r,i)=>{if(r||i.child)return;const o=this.range;if(sB(e,o)){ph.debug("adjust selection because remote deleted current block");const s=lB(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),r=st(e);this.caret=new oD(t);const i=lt(r,0,"normal");this._range=We(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){const i=lt(t,e,"normal");let o;r&&(o=lt(t,r,"normal")),this.setSelection(i,o)}setSelection(t,e,r){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const i=We(this.editor,{anchor:t,focus:e});if(this.range.isEqual(i))return this.range;const o=this._range;return this._range=i,this.selectionChanged(),this.updateFocusedBlock(o),Rt(this.editor.rootContainer,"select-all")&&(!i.isSimple()||!hD(this.editor,i))&&ot(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(){this.caret.update(),sD(this.editor)}getFocusedPos(){return this.range.focus}getAnchorPos(){return this.range.anchor}selectionChanging(t,e){return!0}selectionChanged(){this.updateSelection(),this.editor.emit("selectionChanged",this.editor)}updateLastCaretRect(){const t=this.range.focus;if(!Or(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=_r(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){dD(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=dt(this.editor,e)||p(ph,!1,"invalid block position, out of range");else{const r=t.childContainerId;!!this.editor.getContainerById(r)||p(ph,!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&&Rt(e,"focused")&&(ot(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=gh(this.editor);return t==="text"?Qs(this.editor,e):t==="markdown"?uB(this.editor,e):cB(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{ot(t,"focused"),ot(t,"child-focused")})}setBlockFocused(t){if(Rt(t,"focused"))return!1;z(t,"focused");let e=it(t);for(;Mr(e);){const r=nt(e);p(ph,r,"parent block not found"),z(r,"child-focused"),e=it(r)}return!0}}function WD(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,dt(n,e))}function qD(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!et(n,e))return;let r=O1(n,"select"),i=N1(n,"select");if(!r||!i)return;const o=t.blockId;r.blockId!==o&&(r=lt(e,0,"home")),i.blockId!==o&&(i=lt(e,dt(n,e),"end")),n.selection.setSelection(r,i)}class XD{constructor(t){g(this,"editor");g(this,"startPos",null);g(this,"lastCaretRect");g(this,"mouseDownEvent",null);g(this,"autoScroll",null);g(this,"handleMouseDown",(t,e)=>{var i;this.mouseDownEvent=t;const r=Fv(this.editor,t.x,t.y);if(r){if(r instanceof ui)return;if(!this.autoScroll&&e.autoScroll){const s=r.getSelectedBlocks(),l=cn(s[0].block);this.autoScroll=new Ld({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())}});g(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=$d(this.editor,t.x,t.y);if(!e)return;const r=hh(this.editor,this.startPos,e.end);if(!r)return;const{anchor:i,focus:o}=r;this.editor.selection.setSelection(i,o)});g(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){qD(this.editor)}handleTripleClick(t){WD(this.editor)}}function QD(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function YD(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const p5=I("delete-text");function C5(n,t,e,r){const i=r!=null?r:n.selection.range.start;i instanceof _e||p(p5,!1,`invalid insert pos type: ${typeof i}`);const{blockId:o}=i,s=n.getBlockById(o);p(p5,et(n,s),"block is not a text kind block");let{offset:l}=i;if(t==="backward"){if(l-e<0)return 0;if(!_n(s,l-e)){const c=Ho(s,l);e=l-c}}else if(t==="forward"&&l+e>dt(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function E5(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const ZD=I("handle-backspace");function G1(n,t){if(!re(n,t))return;const e=it(t);Lr(e)!==1&&n.deleteBlock(t)}function JD(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,r=n.getBlockById(e.blockId);if(et(n,r))if(e.offset===0){if(E5(n,r))return;const i=me(r);if(i){if(!n.isBlockWritable(i))return;if(et(n,i))n.mergeTextBlock(i,r,{focus:!0});else if(_t(n,i)){G1(n,r);const o=aa(n,i);o?n.selection.selectBlock(o,dt(n,o)):n.selection.selectBlock(i,0,dt(n,i))}else G1(n,r),p(ZD,Re(i),"prev block is not embed block"),n.selection.selectBlock(i,1)}else{const o=it(r);if(Mr(o)){const s=_v(n,o);if(s){if(!n.isBlockWritable(s))return;G1(n,r),n.selection.selectBlock(s,dt(n,s))}}}}else C5(n,"backward",1,null),n.selection.updateLastCaretRect();else{const i=bt(r),o=it(r);n.insertTextBlock("",ft(o),i),n.deleteBlock(r)}}function t_(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,r=n.getBlockById(e.blockId);if(et(n,r))if(e.offset===dt(n,r)){const i=Gt(r);if(i){if(!n.isBlockWritable(i))return;et(n,i)?n.mergeTextBlock(r,i,{focus:!0}):re(n,r)?n.deleteBlock(r,ve(n,i,0)):n.deleteBlock(i)}}else C5(n,"forward",1,null);else{const i=bt(r),o=it(r);n.insertTextBlock("",ft(o),i),n.deleteBlock(r)}}function e_(n){const{range:t}=n.selection,{start:e,end:r}=t,i=n.getBlockById(e.blockId),o=n.getBlockById(r.blockId);if(i!==o||!_t(n,i))return!1;if(Or(e))return!0;const s=la(n,i,e,r),l=xn(n,i);return s.length===l.length}function n_(n,t){if(e_(n)){const s=n.getFocusedBlock(),l=bt(s),c=ft(it(s));n.insertTextBlock("",c,l+1);return}const e=n.getFocusedBlock(),{start:r,end:i}=n.selection.range,o=r.blockId===i.blockId&&Re(e);if(!n.selection.range.isCollapsed()&&!o&&n.clearSelectedContents(),et(n,e)){if(re(n,e)&&E5(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 r_(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:r}=e;if(!et(n,r))return!1;const i=e.end;return n.insertBoxToBlock(r,i.offset,{type:"br",id:J(),box:!0,created:Date.now()}),!0}const i_=I("input-handler-actions");function o_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(n_(n),!0))}function s_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(t_(n),!0))}function l_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(JD(n),!0))}function a_(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(r_(n),!0))}function c_(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t,{toPlainText:!0})}).catch(t=>{i_.error(t)}),!0)}const Ch={ArrowDown:PB,ArrowUp:NB,ArrowLeft:UB,ArrowRight:OB,"Shift+ArrowDown":FB,"Shift+ArrowUp":$B,"Shift+ArrowLeft":KB,"Shift+ArrowRight":VB,"CtrlOrCmd+ArrowLeft":jB,"CtrlOrCmd+ArrowRight":zB,"CtrlOrCmd+Shift+ArrowLeft":GB,"CtrlOrCmd+Shift+ArrowRight":WB,"CtrlOrCmd+ArrowUp":qB,"CtrlOrCmd+ArrowDown":K1,"CtrlOrCmd+Shift+ArrowUp":XB,"CtrlOrCmd+Shift+ArrowDown":V1,"CtrlOrCmd+A":h5,Home:e5,End:n5,"Shift+Home":JB,"Shift+End":t5,PageUp:l5,PageDown:a5,"Shift+PageUp":c5,"Shift+PageDown":u5,"CtrlOrCmd+Z":QD,"CtrlOrCmd+Shift+Z":YD,Enter:o_,Delete:s_,Backspace:l_,"Shift+Enter":a_,"CtrlOrCmd+Shift+V":c_};function A5(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function x5(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=>{x5(n,l,e)})})}function b5(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):x5(t,i,e)})}async function u_(n,t){const e=t.filter(o=>o.indexOf(":")===-1),r=await n.doc.addResources(e),i=new Map;if(e.length!==r.length)return i;for(let o=0;o<e.length;o++)i.set(e[o],r[o]);return i}function f_(n,t){var o,s;const r=t.meta.serverId;if(!r||typeof r!="string")return!1;const i=(s=(o=n.doc).getServerMeta)==null?void 0:s.call(o);return!(!i||i.serverId!==r)}async function W1(n,t){const r=t.meta.resources;if(!r||Object.keys(r).length===0)return;let i=new Map;if(f_(n,t)){const s=Array.from(Object.keys(r));i=await u_(n,s),b5(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&&b5(n,t,o)}async function d_(n,t,e){await W1(n,t),n.undoManager.runInGroup(()=>{const{start:r,end:i}=n.selection.range,o=n.getBlockById(r.blockId);if(r.blockId===i.blockId&&Re(o)){const s=it(o),l=n.getBlockIndex(o),[c]=n.insertDocAt(s,l+1,t,e);c&&n.selection.selectBlock(c,dt(n,c))}else{n.clearSelectedContents();const{block:s,offset:l}=ga(n);n.insertDoc(s,l,t,e)}})}const h_=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function m_(n){let t;for(const e of h_)if(t=n[e],t)break;return t||null}function v5(n,t,e){if(t.type==="embed"){const s=t.embedData.src;if(s&&typeof s=="string")for(const l of s.split("|"))e.add(l);return}const r=t.text;r&&r.forEach(o=>{o.attributes&&o.attributes.src&&typeof o.attributes.src=="string"&&e.add(o.attributes.src)});const i=t.children;i&&i.forEach(o=>{n.blocks[o].forEach(l=>{v5(n,l,e)})})}function g_(n,t){const e=new Set;return t.blocks.root.forEach(i=>{const o=n.editorBlocks.getBlockClass(i.type);o.getResources?o.getResources(i).forEach(s=>{e.add(s)}):v5(t,i,e)}),Array.from(e)}function Eh(n,t){return he.isFirefox?`<!doctype html><html><head><meta charset="utf8" /></head><body><canvas data-editor-doc="${ji(JSON.stringify(t))}" id="ones-editor-doc">${n}</body></html>`:`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${ji(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function Ah(n,t){var o,s,l;const e=(l=(s=(o=n.doc).getServerMeta)==null?void 0:s.call(o))!=null?l:{},r=g_(n,t),i={};r.forEach(c=>{const d=n.doc.buildResourceUrl(c,{withToken:!0});i[c]=d}),t.meta={...e,resources:i}}function p_(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let r=gh(n);const i=e==null?void 0:e(n,t,r);if(i===!0)return;typeof i=="object"&&i!==null&&(r=i),Ah(n,r);const o=sh(n,r),s=Qs(n,r),l=Eh(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))}async function xh(n,t){if(!window.isSecureContext)throw new Error("Can't copy block in insecure context.");const e=z1(n,t);Ah(n,e);const r=sh(n,e),i=Qs(n,e),o=Eh(r,e);return yg([{type:"text/plain",data:new Blob([i],{type:"text/plain"})},{type:"text/html",data:new Blob([o],{type:"text/html"})}])}class C_{constructor(t){g(this,"editor");g(this,"handlers",[]);g(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)}});this.editor=t}onInsertText(t,e){if(!et(this.editor,this.editor.getFocusedBlock()))return;const{containerId:r,blockIndex:i,offset:o}=ga(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(!et(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:r,offset:i}=ga(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(!et(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText(e,r),this.editor.selection.caret.update();const{containerId:i,blockIndex:o,offset:s}=ga(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){p_(this.editor,t,(e,r,i)=>{for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,r,i);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}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;Re(r)&&this.editor.deleteBlock(r)}else S1(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(){z(this.editor.rootElement,"active")}onBlur(){ot(this.editor.rootElement,"active")}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){B1(this.editor,o)}defaultHandleKeydown(t,e){return A5(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 d_(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=m_(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 E_(n,t,e){const r=zi(t,e);return r.remove(),r}I("copy-dom-attributes");const B5=["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 A_(n,t){for(let l=0;l<B5.length;l++){const c=B5[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 T5(n){const t=Array.from(n.childNodes).filter(e=>!Yb(e));return t.forEach(e=>{e.remove()}),t}function y5(n,t,e){var d;const r=n.getContainerById(t),i=zi(r,e),o=Ko(i),s=n.doc.getBlockData(t,e),l=Zt(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=T5(h);T5(i),C.forEach(x=>{i.appendChild(x)});const E=_d(h);if(E){const x=_d(i);x&&x.remove(),i.appendChild(E)}A_(h,i)}hv(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)})}const x_=I("transform-selection");function k5(n,t,e,r){const{range:i}=n.selection,{anchor:o,focus:s}=i;if(o.blockId!==t&&s.blockId!==t)return i;p(x_,o.isSimple()&&s.isSimple(),"invalid text pos type");let l=o;if(o.blockId===t){const d=dn.transformCursor(o.offset,e,r);l=lt(t,d,"normal")}let c=s;if(s.blockId===t){const d=dn.transformCursor(s.offset,e,r);c=lt(t,d,"normal")}return We(n,{anchor:l,focus:c})}const b_=I("handle-block-text-changed");function v_(n,t,e,r,i){const o=n.getContainerById(t),s=zi(o,e),l=n.doc.getBlockData(t,e);if(p(b_,l.text,"no block text"),Wb(n,s).setBlockText(n,s,l.text),!i){const c=k5(n,l.id,r,i);n.selection.setRange(c,{noScroll:!0})}}function B_(n,t){const e=gt.default(n);return t.delete.forEach(i=>{delete e[i]}),{...e,...t.insert}}function R5(n,t,e,r){const i=Zt(n,t);i.handleDeleteBlock&&i.handleDeleteBlock(n,t,e,r),n.emit("blockDeleted",n,t,e,r)}function T_(n,t,e,r){const i=n.getBlockByIndex(t,e);i.querySelectorAll('[data-type="editor-block"]').forEach(o=>{R5(n,o,r,{child:!0})}),R5(n,i,r,{child:!1})}const Pr=I("editor-doc");class y_ extends ea{constructor(e,r,i){super();g(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(Pr,this.editor.isBlockWritable(i),`block is not writable, ${e}, ${r}`)}localUpdateBlockText(e,r,i,o){p(Pr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const s=this.getBlockData(e,r),l=s.text;p(Pr,l,`no text, ${e}, ${r}`);const c=k5(this.editor,s.id,i,!0),d=dn.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){p(Pr,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,r);if(!this.editor.isBlockWritable(s)){const h=Array.from(i.delete).filter(E=>E!=="comments"),C=Object.keys(i.insert).filter(E=>E!=="comments");(h.length>0||C.length>0)&&p(Pr,!1,`block is not writable, comment supported only, ${JSON.stringify(i)}}`)}const l=gt.default(this.getBlockData(e,r)),c=gt.default(B_(l,i));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,c,o));const d=this.externalDoc.localUpdateBlockData(e,r,i,o);return this.editor.selection.setRange(Vo(this.editor,o)),d}localInsertBlock(e,r,i,o,s){p(Pr,!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(Vo(this.editor,o),s),l}localDeleteBlock(e,r,i){p(Pr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const o=gt.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(Vo(this.editor,i)),s}localDeleteChildContainers(e){return p(Pr,!this.editor.readonly,"editor is readonly"),e.forEach(r=>{const i=gt.default(this.getContainerBlocks(r));this.localEvents.forEach(o=>o.onBeforeDeleteChildContainer(r,i))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainers(e){p(Pr,!this.editor.readonly,"editor is readonly");const r=gt.default(e);r.forEach(i=>{this.localEvents.forEach(o=>o.onBeforeInsertChildContainer(i.containerId,i.blocks))}),this.externalDoc.localInsertChildContainers(r)}onRequestReload(e){Pr.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)}),v_(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)}),y5(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);P9(this.editor,s,r,i),this.editor.emit("docChanged",this.editor,o)}onDeleteBlock(e,r,i){T_(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);E_(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)})}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()}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){Pr.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function w5(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 bh=I("undo-action");class xa{constructor(t,e,r){g(this,"beforeRange");g(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(bh,t,"no other action"),!1}combine(t){p(bh,!1,"no other")}setAfterRange(t){this.afterRange&&bh.warn("after range has already set"),this.afterRange=t}findContainerById(t,e){return!!t.doc.findContainerBlocks(e)}findBlockById(t,e){const r=t.doc.findContainerBlocks(this.containerId);return r?r.some(i=>i.id===e):!1}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 bh.warn(`container (${o}) not found, deleted by others?`),!1}}return!0}}const ba=I("block-action");class S5 extends xa{constructor(e,r,i,o,s){super(e,r,s);g(this,"blockData");g(this,"blockIndex");this.blockData=gt.default(o),this.blockIndex=i}deleteBlock(e,r){if(!this.findContainerById(e,this.containerId))return ba.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockData.id))return ba.warn(`block (${this.blockData.id}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const o=e.getBlockById(this.blockData.id);if(!o)return!1;try{p(ba,this.blockIndex===bt(o),"invalid block index"),ch(e,o,Vo(e,r))}catch(s){ba.warn(s.message),e.selection.selectBlock(o,0)}return!0}insertBlock(e,r){if(!this.findContainerById(e,this.containerId))return ba.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.checkBlockData(e,this.blockData))return!1;try{Ca(e,this.containerId,this.blockIndex,gt.default(this.blockData),r)}catch(i){ba.warn(i.message);const o=e.doc.getContainerBlocks(this.containerId),s=Math.min(o.length-1,this.blockIndex),l=e.getBlockByIndex(this.containerId,s);e.selection.selectBlock(l,0)}return!0}}I("insert-block-action");class k_ extends S5{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class R_ extends S5{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class w_ extends xa{constructor(e){super(e,ft(e.rootContainer),e.selection.range.toDocRange());g(this,"actions",[])}addAction(e){w5(this.actions,e),this.afterRange=e.afterRange}undo(e){let r=!1;return this.actions.concat().reverse().forEach(i=>{i.undo(e)&&(r=!0)}),r}redo(e){let r=!1;return this.actions.forEach(i=>{i.redo(e)&&(r=!0)}),r}setAfterRange(e){this.afterRange=e;const r=this.actions[this.actions.length-1];!r||r instanceof xa&&(r.afterRange||r.setAfterRange(e))}}const Wo=I("update-block-data-action");class vh extends xa{constructor(e,r,i,o,s,l){super(e,r,l);g(this,"beforeBlockData");g(this,"afterBlockData");g(this,"blockId");this.blockId=i,p(Wo,this.blockId===o.id,"invalid block id"),p(Wo,this.blockId===s.id,"invalid block id"),this.beforeBlockData=gt.default(o),this.afterBlockData=gt.default(s),p(Wo,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){if(!e.findBlockById(this.blockId))return Wo.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(Wo,i,"no container"),dh(e,r,vh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){if(!e.findBlockById(this.blockId))return Wo.warn(`block (${this.blockId}) not found, deleted by others?`),!1;p(Wo,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(Wo,i,"no container"),dh(e,r,vh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const r=gt.default(e);return delete r.id,delete r.type,r}}const Zs=I("update-block-text-action");class du extends xa{constructor(e,r,i,o,s,l){super(e,r,l);g(this,"beforeRichTextData");g(this,"afterRichTextData");g(this,"blockId");g(this,"type");this.blockId=i,this.beforeRichTextData=gt.default(o),this.afterRichTextData=gt.default(s),this.type=du.calType(o,s)}static calType(e,r){p(Zs,e,"no old data"),p(Zs,r,"no new data");const o=dn.diff(e,r),s=new Set;let l=!1;const c=h=>vb(h)?`cjk_${h}`:xb(h)?"number":Td(h)?"space":bb(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.findContainerById(e,this.containerId))return Zs.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return Zs.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?(fh(e,i,this.beforeRichTextData),!0):!1}redo(e){if(!this.findContainerById(e,this.containerId))return Zs.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return Zs.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?(fh(e,i,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof du)||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(Zs,e instanceof du,"invalid action type");const r=e;this.afterRichTextData=r.afterRichTextData,this.afterRange=e.afterRange}}const L5=I("child-container-action");class I5 extends xa{constructor(t,e,r){super(t,e,t.selection.range.toDocRange()),this.blocks=r}deleteChildContainer(t){return this.findContainerById(t,this.containerId)?(t.doc.localDeleteChildContainers([this.containerId]),!0):(L5.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}insertChildContainer(t){return this.findContainerById(t,this.containerId)?(L5.warn(`container (${this.containerId}) already exists`),!1):(t.doc.localInsertChildContainers([{containerId:this.containerId,blocks:gt.default(this.blocks)}]),!0)}}class S_ extends I5{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class L_ extends I5{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Fr=I("undo");class I_{constructor(t){g(this,"editor");g(this,"actions",[]);g(this,"undoCursor");g(this,"currentGroup",null);g(this,"groupCounter",0);g(this,"undoRedoing",!1);g(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):(w5(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(p(Fr,!this.currentGroup,"current group already exists"),this.currentGroup=new w_(this.editor),this.groupCounter=1):(p(Fr,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){p(Fr,this.currentGroup,"current group not exists"),p(Fr,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Fr.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 Fr.error(`failed to run action: ${e.message}`),e}finally{this.endGroup()}}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(Vo(this.editor,t.beforeRange))}catch(e){Fr.error(`undo: failed to restore caret pos: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}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(Vo(this.editor,e)):Fr.warn("no after range")}catch(e){Fr.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}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(),dn.diff(r,i).length!==0&&this.addAction(new du(this.editor,t,e,r,i,o)))}onBeforeUpdateBlockData(t,e,r,i,o){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new vh(this.editor,t,e,r,i,o);this.addAction(s)}onBeforeInsertBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),p(Fr,e>=0,"invalid block index"),p(Fr,r,"no block data"),this.addAction(new k_(this.editor,t,e,r,i)))}onBeforeDeleteBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new R_(this.editor,t,e,r,i)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new S_(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new L_(this.editor,t,e)))}}class D_{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 __{constructor(){g(this,"converters",[]);g(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new D_)}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 M_(n){n.editorBlocks.registerBlockClass(Mn),n.editorBlocks.registerBlockClass(Dv),n.editorBoxes.registerBoxClass(z3),n.editorBoxes.registerBoxClass(G3),n.editorBoxes.registerBoxClass(X3),n.editorBoxes.registerBoxClass(Q3),n.editorInsertions.registerInsertionClass(Y3),n.editorBlockRenders.registerRender(new Qb)}function U_(n,t){M_(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 Bh=I("range-commands");function D5(n,t){n.forEach(e=>{e.source=t,e.children&&D5(e.children,t)})}function _5(n,t,e){const r=st(t);p(Bh,r===e.start.blockId,"invalid start range"),p(Bh,r===e.end.blockId,"invalid end range");const i=n.editorCommandProviders.getCommandProviders();let o=[];if(i.forEach(s=>{const l=s.getAvailableCommands(n,t,e);D5(l,s.id),o.push(...l)}),i.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,o);l&&(o=l)}}),_t(n,t)){if(!sa(e.start))return o;p(Bh,!e.start.isSimple(),"invalid start pos"),p(Bh,!e.end.isSimple(),"invalid end pos");const s=e.start.childContainerId,l=ci(n,s),d=Ce(l)[0];if(d){const h=dt(n,d),C=We(n,{anchor:lt(d,0,"home"),focus:lt(d,h,"end")}),E=_5(n,d,C);o.push(...E)}}return o}function M5(n){const t=n.getEditor(),e=n.getSelectedBlocks(),r=[],i=n.isReverse()?e[0]:e[e.length-1],o=We(t,{anchor:i.start,focus:i.end});return _5(t,i.block,o).forEach(l=>{r.push(l)}),r}function U5(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.source),c={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,r,i,{}))return o[st(t)]=c,!0;let d=!1;return _t(n,t)&&la(n,t,e.start,e.end).forEach(E=>{Ce(E).forEach(v=>{const R=dt(n,v),L=We(n,{anchor:lt(v,0,"home"),focus:lt(v,R,"end")});U5(n,v,L,r,i,o)&&(d=!0)})}),s.forEach(C=>{C.afterExecuteCommand&&C.afterExecuteCommand(n,t,e,r,i,o)}),d}function O5(n,t,e){const r=n.getEditor(),i={},o=r.editorCommandProviders.getCommandProvider(t.source);return o.executeRangeCommand&&o.executeRangeCommand(r,n,t,e,i)||(n.getSelectedBlocks().forEach(l=>{const c=We(r,{anchor:l.start,focus:l.end});U5(r,l.block,c,t,e,i)}),r.focus()),i}const O_=I("command-providers");class N5{constructor(t){g(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(O_,e,`no command provider, id=${t}`),e}getCommands(t){return M5(t)}executeCommand(t,e,r){return this.editor.undoManager.runInGroup(()=>O5(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 N_(n,t){const e=it(t),r=ft(e),i=bt(t);y5(n,r,i)}const P_=I("table-scroll");class P5{constructor(t,e,r,i,o){g(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 F_{constructor(t){g(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)){P_.warn(`event has already registered: ${e}`);return}o.push(new P5(this.editor,t,e,r,i))}else{const s=new P5(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)}}const F5=I("update-block-text");function K_(n,t,e){const r=n.getBoxById(t.id),i=nt(r);p(F5,i,"no parent block"),p(F5,et(n,i),"not a text block");const o=n.getBlockText(i),s=O3(o,"id",t.id,t);xB(n,i,s,e)}function V_(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 $_(n){if(n.readonly)return!1;const t=fi(n);return!!n.isBlockWritable(t.map(e=>e.block))}class H_{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 j_{constructor(){g(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(li(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const ro=I("editor");class z_ extends ye.TypedEmitter{constructor(e,r,i){var o,s,l,c,d,h,C,E;super();g(this,"parent");g(this,"rootElement");g(this,"contentElement");g(this,"rootContainerObject");g(this,"rootContainer");g(this,"input");g(this,"selection");g(this,"selectionHandler");g(this,"doc");g(this,"id");g(this,"clientId");g(this,"compositingText","");g(this,"undoManager");g(this,"shortcuts",new j_);g(this,"dataConverter",new __);g(this,"editorBlocks",new wv(this));g(this,"editorBoxes",new q3(this));g(this,"editorInsertions",new J3(this));g(this,"editorEmbeds",new Lv(this));g(this,"editorDecorators",new tB(this));g(this,"editorCommandProviders",new N5(this));g(this,"editorBlockRenders",new R9(this));g(this,"blockHooks",[]);g(this,"domEvents",new F_(this));g(this,"customs",new Map);g(this,"options");g(this,"inputHandlers",new C_(this));g(this,"settingsProvider");g(this,"_readonly",!1);g(this,"getColor",e=>{const r=this.options.colors;return r.length===0?"#FF1A75":r[e%r.length]});ro.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},this.settingsProvider=(d=i==null?void 0:i.settingsProvider)!=null?d:new H_(this),U_(this,i==null?void 0:i.components),this.blockHooks.push(...(C=(h=i==null?void 0:i.components)==null?void 0:h.blockHooks)!=null?C:[]),this.id=(E=i==null?void 0:i.id)!=null?E:J(),this.clientId=J(),this.undoManager=new I_(this),this.doc=new y_(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=yv(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new rD(this,this.inputHandlers),this.selection=new GD(this),this.selectionHandler=new XD(this),i!=null&&i.shortcuts&&this.shortcuts.shortcuts.push(...i.shortcuts),he.isMobile&&z(this.rootElement,"mobile"),he.isSafari&&z(this.rootElement,"safari"),this._readonly&&z(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?z(this.rootElement,"readonly"):ot(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:cn(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(ro,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(){ro.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){L1(this,e,r)}isWritable(){return $_(this)}isBlockWritable(e){return V_(this,e)}getChildContainerData(e){const r=this.doc.getContainerBlocks(e);return(!r||!Array.isArray(r))&&(p(ro,r,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),p(ro,Array.isArray(r),`container data is not an array: ${JSON.stringify(r)}`)),r}createChildContainer(e,r,i){return kv(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(ro,Ps(r),"not an valid block element"),r!=null?r:null}findBoxById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(ro,Md(r),"not an valid box element"),r!=null?r:null}getBlockById(e){const r=this.findBlockById(e);return p(ro,r,`no block, id=${e}`),r}getBoxById(e){const r=this.findBoxById(e);return p(ro,r,`no box, id=${e}`),r}getBlockByIndex(e,r){const i=this.getContainerById(e);return zi(i,r)}getBlockIndex(e){if(typeof e=="string"){const r=this.getBlockById(e);return bt(r)}return bt(e)}getContainerById(e){return ci(this,e)}getParentContainer(e){return it(e)}reloadBlock(e){N_(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 Ca(this,e,r,i,o!=null?o:c,s)}insertEmbed(e,r,i,o,s){const l={id:J(),type:"embed",embedType:i,embedData:o};return this.insertBlock(e,r,l,s)}deleteBlock(e,r){R1(this,e,r)}mergeTextBlock(e,r){return CB(this,e,r)}breakTextBlock(e,r,i){return Ea(this,e,r,i).newBlock}getTextPosition(){return ga(this)}getBlockString(e,r){const i=this.getBlockText(e);return ce(i,r)}getBlockData(e){return jo(this,e)}getBoxData(e){return H3(this,e)}getBlockText(e){return bn(this,e)}setBlockText(e,r){xB(this,e,r)}deleteTextFromBlock(e,r,i,o){return y1(this,e,r,i,o)}insertTextToBlock(e,r,i,o){return fB(this,e,r,i,o)}insertBoxToBlock(e,r,i){return dB(this,e,r,i)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,r,i,o){BB(this,e,r,i,o)}insertDocAt(e,r,i,o){return _1(this,e,r,i,o)}deleteChildContainers(e){pB(this,e)}replaceBlockText(e,r){return fh(this,e,r)}updateBlockData(e,r,i){const o={...this.getBlockData(e),...r},{id:s,type:l,...c}=o;return dh(this,e,c,(i!=null?i:this.selection.range).toDocRange())}updateEmbedData(e,r,i){return bB(this,e,r,i)}updateBoxData(e,r){K_(this,e,r)}getSelectedText(){const e=gh(this);return Qs(this,e)}clearSelectedContents(){S1(this)}insertTextBlock(e,r,i,o){const s=mi(e!=null?e:"");return gB(this,s,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){T1(this);return}r?(this.compositingText="",yd()?e||T1(this):B1(this,e)):(this.compositingText=e,hB(this))}}function hu(n,t,e){return new z_(n,t,e)}function G_(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=ag.default(s.states,i.states)}},e=[];return n.forEach(r=>{r.forEach(i=>{t(e,i)})}),e}const W_=["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"];class mu extends ye.TypedEmitter{constructor(e){super();g(this,"users",new Map);g(this,"cursors",new Map);g(this,"addingUser",!1);g(this,"colors");this.colors=e&&e.length>0?e:W_}setCursor(e){this.addUser(e.user);const r=this.cursors.get(e.user.userId);if(r&&Pc.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&&Jd(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(Jd(l.range)){const{anchor:c,focus:d}=l.range;c.blockId===e.id&&(c.offset=dn.transformCursor(c.offset,r,i)),d.blockId===e.id&&(d.offset=dn.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 en=I("local-doc");class q1 extends ea{constructor(e,r){super();g(this,"doc");g(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[mi("")]}},this.serviceUrl=(r==null?void 0:r.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return gt.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(en,i,`no container data: ${e}`);const o=i[r];return p(en,o,`no block data: ${r}`),o}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(en,o.text,"no text for data");const s=dn.apply(o.text,i);return o.text=s,p(en,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(en,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(en,o,`no container data: ${e}`),p(en,r>=0&&r<=o.length,`invalid block index: ${r}, ${o.length}`),o.splice(r,0,i),p(en,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(en,i,`no container data: ${e}`),p(en,r>=0&&r<=i.length,`invalid block index: ${r}, ${i.length}`);const o=i[r];return i.splice(r,1),p(en,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(en,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){en.debug(`delete child containers: ${e}`),e.forEach(r=>{p(en,this.doc.blocks[r],`no child container: ${r}`),delete this.doc.blocks[r]}),e.forEach(r=>{p(en,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(en,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,r){p(en,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new mu}setDoc(e){this.doc=gt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,"change doc")})}destroy(){this.clearCallbacks()}}class q_{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function X1(n,t,e){n.addCustom(t,()=>{var o;const r=(o=e())!=null?o:void 0;return new q_(r)})}const K5=I("find-block");function V5(n,t){const e=Vs(t);if(!e){if(dr(t))return null;const r=Fs(t);return p(K5,r,"no parent block"),V5(n,r)}return _t(n,e)?aa(n,e,{visibleOnly:!0}):e}function $5(n,t){const e=$s(t);if(!e){if(dr(t))return null;const r=Fs(t);return p(K5,r,"no parent block"),$5(n,r)}return _t(n,e)?Hg(n,e,{visibleOnly:!0}):e}const X_=I("remote-cursor");class Q_{constructor(){g(this,"remoteUsers",new mu)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const r=e;this.handleUpdateUsers(r.users)}else e.type==="caret"?this.handleUpdateCaret(e):X_.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 Y_(n){const{blocks:t,meta:e,comments:r,...i}=n;return{rootBlocks:t,meta:e,comments:r,childBlocks:i}}function Z_(n){const{blocks:t,meta:e,comments:r}=n,{root:i,...o}=t;return{blocks:i,meta:e,comments:r,...o}}function io(n){const{childBlocks:t,meta:e,comments:r,rootBlocks:i}=Y_(gt.default(n));return{blocks:{root:i,...t},meta:e,comments:r}}function oo(n){return n==="root"?"blocks":n}function va(n){return n==="blocks"?"root":n}const J_={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new an.default(n)},apply(n,t){const e=new an.default(n),r=new an.default(t);return e.compose(r).ops},compose(n,t){const e=new an.default(n),r=new an.default(t);return e.compose(r).ops},diff(n,t){const e=new an.default(n),r=new an.default(t);return e.diff(r).ops},transform(n,t,e){const r=new an.default(n);return new an.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 an.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 qo={},Q1=Gx.default.EventEmitter;qo.EventEmitter=Q1,qo.mixin=tM;function tM(n){for(var t in Q1.prototype)n.prototype[t]=Q1.prototype[t]}var H5=["info","warn","error"];function j5(){var n={};H5.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var eM=j5;j5.prototype.setMethods=function(n){n=n||{};var t=this;H5.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var nM=eM,rM=new nM,z5=rM;function Js(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,Js):this.stack=new Error().stack}Js.prototype=Object.create(Error.prototype),Js.prototype.constructor=Js,Js.prototype.name="ShareDBError",Js.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_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_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_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var Th=Js,gu={},G5=iM;function iM(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 x=[];if(i(s[E],h,C,x),E++,x.length===1)h=x[0];else if(x.length===0){for(var v=E;v<s.length;v++)r(C,s[v]);h=null;break}else{for(var R=o(s.slice(E),x),L=0;L<R[0].length;L++)r(C,R[0][L]);for(var M=0;M<R[1].length;M++)r(c,R[1][M]);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 W5={exports:{}},Xo=W5.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||""}},Y1=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},Z1=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")},yh=function(n){for(var t=0;t<n.length;t++)Z1(n[t])};Xo.apply=function(n,t){var e;yh(t);for(var r=0;r<t.length;r++){var i=t[r];if(i.i!=null)n=Y1(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 so=Xo._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:Y1(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:Y1(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};Xo.compose=function(n,t){yh(n),yh(t);for(var e=n.slice(),r=0;r<t.length;r++)so(e,t[r]);return e},Xo.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),so(t,r)}return t};var J1=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};Xo.transformCursor=function(n,t,e){for(var r=e==="right",i=0;i<t.length;i++)n=J1(n,t[i],r);return n};var oM=Xo._tc=function(n,t,e,r){if(Z1(t),Z1(e),t.i!=null)so(n,{i:t.i,p:J1(t.p,e,r==="right")});else if(e.i!=null){var i=t.d;t.p<e.p&&(so(n,{d:i.slice(0,e.p-t.p),p:t.p}),i=i.slice(e.p-t.p)),i!==""&&so(n,{d:i,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)so(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)so(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=J1(o.p,e),so(n,o))}return n},sM=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};Xo.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=sM(n[t]);return n},G5(Xo,oM,yh,so);var kh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},lM=function(n){return!!n&&n.constructor===Object},Kr=function(n){return JSON.parse(JSON.stringify(n))},St={name:"json0",uri:"http://sharejs.org/types/JSONv0"},lo={};St.registerSubtype=function(n){lo[n.name]=n},St.create=function(n){return n===void 0?null:Kr(n)},St.invertComponent=function(n){var t={p:n.p};return n.t&&lo[n.t]&&(t.t=n.t,t.o=lo[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},St.invert=function(n){for(var t=n.slice().reverse(),e=[],r=0;r<t.length;r++)e.push(St.invertComponent(t[r]));return e},St.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!kh(n[t].p))throw new Error("Missing path")},St.checkList=function(n){if(!kh(n))throw new Error("Referenced element not a list")},St.checkObj=function(n){if(!lM(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function pu(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 Cu(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}St.apply=function(n,t){St.checkValidOp(t),t=Kr(t);for(var e={data:n},r=0;r<t.length;r++){var i=t[r];(i.si!=null||i.sd!=null)&&pu(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&&lo[i.t])s[l]=lo[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)St.checkList(s),s[l]=i.li;else if(i.li!==void 0)St.checkList(s),s.splice(l,0,i.li);else if(i.ld!==void 0)St.checkList(s),s.splice(l,1);else if(i.lm!==void 0){if(St.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)St.checkObj(s),s[l]=i.oi;else if(i.od!==void 0)St.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},St.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},St.incrementalApply=function(n,t,e){for(var r=0;r<t.length;r++){var i=[t[r]];n=St.apply(n,i),e(i,n)}return n};var aM=St.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};St.append=function(n,t){if(t=Kr(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)&&(pu(t),pu(e)),aM(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&lo[t.t]){if(e.o=lo[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(),Cu(t),n.push(t);Cu(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)&&(Cu(t),Cu(e)),n.push(t)},St.compose=function(n,t){St.checkValidOp(n),St.checkValidOp(t);for(var e=Kr(n),r=0;r<t.length;r++)St.append(e,t[r]);return e},St.normalize=function(n){var t=[];n=kh(n)?n:[n];for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=[]),St.append(t,r)}return t},St.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},St.canOpAffectPath=function(n,t){return St.commonLengthForOps({p:t},n)!=null},St.transformComponent=function(n,t,e,r){t=Kr(t);var i=St.commonLengthForOps(e,t),o=St.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=Kr(e);c.p=c.p.slice(s),t.ld=St.apply(Kr(t.ld),[c])}else if(t.od!==void 0){var c=Kr(e);c.p=c.p.slice(s),t.od=St.apply(Kr(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)&&(pu(t),c=Kr(e),pu(c)),c.t&&lo[c.t]){if(t.t&&t.t===c.t){var h=lo[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(),Cu(t),St.append(n,t);else(!kh(h)||h.length>0)&&(t.o=h,St.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=Kr(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],x=t.p[i],v=t.lm;(C<v||C===v&&x<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 x=t.p[i],v=t.lm,R=e.p[i],L=e.lm;if(R!==L)if(x===R)if(r==="left")t.p[i]=L,x===v&&(t.lm=L);else return n;else x>R&&t.p[i]--,x>L?t.p[i]++:x===L&&R>L&&(t.p[i]++,x===v&&t.lm++),(v>R||v===R&&v>x)&&t.lm--,v>L?t.lm++:v===L&&(L>R&&v>x||L<R&&v<x?r==="right"&&t.lm++:v>x?t.lm++:v===R&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var x=e.p[i],v=e.lm;C=t.p[i],C>x&&t.p[i]--,C>v&&t.p[i]++}else{var x=e.p[i],v=e.lm;C=t.p[i],C===x?t.p[i]=v:(C>x&&t.p[i]--,(C>v||C===v&&x>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")St.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 St.append(n,t),n},G5(St,St.transformComponent,St.checkValidOp,St.append);var cM=W5.exports;St.registerSubtype(cM);var uM=St,fM={type:uM};(function(n){n.defaultType=fM.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)})(gu);var Vr={};(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))}})(Vr);var q5=Array.isArray,X5=Object.keys,dM=Object.prototype.hasOwnProperty,hM=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=q5(t),i=q5(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=X5(t);if(s=E.length,s!==X5(e).length)return!1;for(o=s;o--!==0;)if(!dM.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},Q5=qo,mM=z5,Yn=Th,Rh=gu,$r=Vr,gM=$r.clone,pM=hM,Un=Yn.CODES,CM=Ft;function Ft(n,t,e){Q5.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}Q5.mixin(Ft),Ft.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())})},Ft.prototype._setType=function(n){if(typeof n=="string"&&(n=Rh.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new Yn(Un.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Ft.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Ft.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new Yn(Un.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 Yn(Un.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?Rh.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()},Ft.prototype.whenNothingPending=function(n){var t=this;$r.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Ft.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Ft.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Ft.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Ft.prototype._emitResponseError=function(n,t){if(n&&n.code===Un.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)},Ft.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){$r.callEach(e,i)}),n)return this._emitResponseError(n,r);this.ingestSnapshot(t,r),this._emitNothingPending()},Ft.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){$r.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()},Ft.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Un.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=wh(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var r=0;r<this.pendingOps.length;r++){var e=wh(this.pendingOps[r],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}}},Ft.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))},Ft.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()},Ft.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);EM(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Ft.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Ft.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Ft.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,r=e&&e.wantSubscribe===n;if(r){e.callback=AM([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Ft.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;$r.nextTick(function(){n._handleSubscribe()})}}};function EM(n,t,e){if(t){var r=n.pop();n.push(function(i){r&&r(i),e&&e(i)})}else n.push(e)}function AM(n){return n=n.filter($r.truthy),n.length?function(t){$r.callEach(n,t)}:null}Ft.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function xM(n){delete n.op,delete n.create,delete n.del}function wh(n,t){if(n.del)return xM(t);if(t.del)return new Yn(Un.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new Yn(Un.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new Yn(Un.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}}}Ft.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new Yn(Un.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===Rh.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=wh(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}},Ft.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 Yn(Un.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>=$r.MAX_SAFE_INTEGER)return this.emit("error",new Yn(Un.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)}},Ft.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var r=new Yn(Un.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;$r.nextTick(function(){i.flush()})},Ft.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)},Ft.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)}}},Ft.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!pM(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}}},Ft.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)},Ft.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=Rh.defaultType.uri),this.type){var i=new Yn(Un.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)},Ft.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new Yn(Un.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)},Ft.prototype.pause=function(){this.paused=!0},Ft.prototype.resume=function(){this.paused=!1,this.flush()},Ft.prototype.toSnapshot=function(){return{v:this.version,data:gM(this.data),type:this.type.uri}},Ft.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return mM.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();this.version++,this._clearInflightOp()},Ft.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=wh(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)},Ft.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=$r.callEach(t[i].callbacks,n)&&r;if(n&&!r)return e.emit("error",n)})},Ft.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=$r.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var tl={};tl.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var Y5=qo,Z5=tl.ACTIONS,bM=Vr,vM=On;function On(n,t,e,r,i,o,s){Y5.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}Y5.mixin(On),On.prototype.hasPending=function(){return!this.ready},On.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}},On.prototype.destroy=function(n){this.connection.canSend&&this.action===Z5.querySubscribe&&this.connection.send({a:Z5.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&bM.nextTick(n)},On.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},On.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},On.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},On.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()},On.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},On.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)},On.prototype._handleError=function(n){this.emit("error",n)},On.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)},On.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var J5=qo,BM=tl.ACTIONS,TM=Vr,t2=pi;function pi(n,t){if(J5.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={}}J5.mixin(pi),pi.prototype.submit=function(n,t){this.value=n,this.send(t)},pi.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},pi.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()})},pi.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},pi.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},pi.prototype._message=function(){return{a:BM.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},pi.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},pi.prototype._callbackOrEmit=function(n,t){if(t)return TM.nextTick(t,n);n&&this.emit("error",n)};var yM=Vr,e2=tp;function tp(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}tp.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},tp.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&yM.nextTick(n)};var ep={exports:{}};(function(n,t){(function(e,r){r(t)})(Dn,function(e){function r(y,S){S=S|0;for(var _=Math.max(y.length-S,0),N=Array(_),H=0;H<_;H++)N[H]=y[S+H];return N}var i=function(y){var S=r(arguments,1);return function(){var _=r(arguments);return y.apply(null,S.concat(_))}},o=function(y){return function(){var S=r(arguments),_=S.pop();y.call(this,S,_)}};function s(y){var S=typeof y;return y!=null&&(S=="object"||S=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function d(y){setTimeout(y,0)}function h(y){return function(S){var _=r(arguments,1);y(function(){S.apply(null,_)})}}var C;l?C=setImmediate:c?C=process.nextTick:C=d;var E=h(C);function x(y){return o(function(S,_){var N;try{N=y.apply(this,S)}catch(H){return _(H)}s(N)&&typeof N.then=="function"?N.then(function(H){v(_,null,H)},function(H){v(_,H.message?H:new Error(H))}):_(null,N)})}function v(y,S,_){try{y(S,_)}catch(N){E(R,N)}}function R(y){throw y}var L=typeof Symbol=="function";function M(y){return L&&y[Symbol.toStringTag]==="AsyncFunction"}function U(y){return M(y)?x(y):y}function F(y){return function(S){var _=r(arguments,1),N=o(function(H,$){var X=this;return y(S,function(Z,ct){U(Z).apply(X,H.concat(ct))},$)});return _.length?N.apply(this,_):N}}var G=typeof Dn=="object"&&Dn&&Dn.Object===Object&&Dn,q=typeof self=="object"&&self&&self.Object===Object&&self,rt=G||q||Function("return this")(),at=rt.Symbol,At=Object.prototype,Mt=At.hasOwnProperty,kt=At.toString,se=at?at.toStringTag:void 0;function ue(y){var S=Mt.call(y,se),_=y[se];try{y[se]=void 0;var N=!0}catch{}var H=kt.call(y);return N&&(S?y[se]=_:delete y[se]),H}var nr=Object.prototype,Se=nr.toString;function Pn(y){return Se.call(y)}var Li="[object Null]",yn="[object Undefined]",gn=at?at.toStringTag:void 0;function Ii(y){return y==null?y===void 0?yn:Li:gn&&gn in Object(y)?ue(y):Pn(y)}var mo="[object AsyncFunction]",xr="[object Function]",JE="[object GeneratorFunction]",tA="[object Proxy]";function eA(y){if(!s(y))return!1;var S=Ii(y);return S==xr||S==JE||S==mo||S==tA}var ds=9007199254740991;function pl(y){return typeof y=="number"&&y>-1&&y%1==0&&y<=ds}function Cl(y){return y!=null&&pl(y.length)&&!eA(y)}var go={};function Ht(){}function Di(y){return function(){if(y!==null){var S=y;y=null,S.apply(this,arguments)}}}var hs=typeof Symbol=="function"&&Symbol.iterator,fc=function(y){return hs&&y[hs]&&y[hs]()};function tm(y,S){for(var _=-1,N=Array(y);++_<y;)N[_]=S(_);return N}function pn(y){return y!=null&&typeof y=="object"}var El="[object Arguments]";function em(y){return pn(y)&&Ii(y)==El}var br=Object.prototype,nm=br.hasOwnProperty,nA=br.propertyIsEnumerable,Al=em(function(){return arguments}())?em:function(y){return pn(y)&&nm.call(y,"callee")&&!nA.call(y,"callee")},Be=Array.isArray;function xl(){return!1}var bl=typeof e=="object"&&e&&!e.nodeType&&e,rm=bl&&!0&&n&&!n.nodeType&&n,vl=rm&&rm.exports===bl,im=vl?rt.Buffer:void 0,Bl=im?im.isBuffer:void 0,ms=Bl||xl,Ef=9007199254740991,Af=/^(?:0|[1-9]\d*)$/;function xf(y,S){var _=typeof y;return S=S==null?Ef:S,!!S&&(_=="number"||_!="symbol"&&Af.test(y))&&y>-1&&y%1==0&&y<S}var bf="[object Arguments]",vf="[object Array]",Bf="[object Boolean]",Tf="[object Date]",yf="[object Error]",kf="[object Function]",rA="[object Map]",iA="[object Number]",oA="[object Object]",om="[object RegExp]",sm="[object Set]",sA="[object String]",lA="[object WeakMap]",aA="[object ArrayBuffer]",cA="[object DataView]",lm="[object Float32Array]",uA="[object Float64Array]",fA="[object Int8Array]",dA="[object Int16Array]",Rf="[object Int32Array]",hA="[object Uint8Array]",wf="[object Uint8ClampedArray]",mA="[object Uint16Array]",gA="[object Uint32Array]",fe={};fe[lm]=fe[uA]=fe[fA]=fe[dA]=fe[Rf]=fe[hA]=fe[wf]=fe[mA]=fe[gA]=!0,fe[bf]=fe[vf]=fe[aA]=fe[Bf]=fe[cA]=fe[Tf]=fe[yf]=fe[kf]=fe[rA]=fe[iA]=fe[oA]=fe[om]=fe[sm]=fe[sA]=fe[lA]=!1;function pA(y){return pn(y)&&pl(y.length)&&!!fe[Ii(y)]}function CA(y){return function(S){return y(S)}}var am=typeof e=="object"&&e&&!e.nodeType&&e,Tl=am&&!0&&n&&!n.nodeType&&n,EA=Tl&&Tl.exports===am,dc=EA&&G.process,cm=function(){try{var y=Tl&&Tl.require&&Tl.require("util").types;return y||dc&&dc.binding&&dc.binding("util")}catch{}}(),um=cm&&cm.isTypedArray,AA=um?CA(um):pA,xA=Object.prototype,bA=xA.hasOwnProperty;function vA(y,S){var _=Be(y),N=!_&&Al(y),H=!_&&!N&&ms(y),$=!_&&!N&&!H&&AA(y),X=_||N||H||$,Z=X?tm(y.length,String):[],ct=Z.length;for(var Ct in y)(S||bA.call(y,Ct))&&!(X&&(Ct=="length"||H&&(Ct=="offset"||Ct=="parent")||$&&(Ct=="buffer"||Ct=="byteLength"||Ct=="byteOffset")||xf(Ct,ct)))&&Z.push(Ct);return Z}var hc=Object.prototype;function BA(y){var S=y&&y.constructor,_=typeof S=="function"&&S.prototype||hc;return y===_}function mc(y,S){return function(_){return y(S(_))}}var TA=mc(Object.keys,Object),yA=Object.prototype,kA=yA.hasOwnProperty;function fm(y){if(!BA(y))return TA(y);var S=[];for(var _ in Object(y))kA.call(y,_)&&_!="constructor"&&S.push(_);return S}function gc(y){return Cl(y)?vA(y):fm(y)}function dm(y){var S=-1,_=y.length;return function(){return++S<_?{value:y[S],key:S}:null}}function RA(y){var S=-1;return function(){var N=y.next();return N.done?null:(S++,{value:N.value,key:S})}}function wA(y){var S=gc(y),_=-1,N=S.length;return function H(){var $=S[++_];return $==="__proto__"?H():_<N?{value:y[$],key:$}:null}}function SA(y){if(Cl(y))return dm(y);var S=fc(y);return S?RA(S):wA(y)}function vr(y){return function(){if(y===null)throw new Error("Callback was already called.");var S=y;y=null,S.apply(this,arguments)}}function yl(y){return function(S,_,N){if(N=Di(N||Ht),y<=0||!S)return N(null);var H=SA(S),$=!1,X=0,Z=!1;function ct(ut,xt){if(X-=1,ut)$=!0,N(ut);else{if(xt===go||$&&X<=0)return $=!0,N(null);Z||Ct()}}function Ct(){for(Z=!0;X<y&&!$;){var ut=H();if(ut===null){$=!0,X<=0&&N(null);return}X+=1,_(ut.value,ut.key,vr(ct))}Z=!1}Ct()}}function _i(y,S,_,N){yl(S)(y,U(_),N)}function ze(y,S){return function(_,N,H){return y(_,S,N,H)}}function Sf(y,S,_){_=Di(_||Ht);var N=0,H=0,$=y.length;$===0&&_(null);function X(Z,ct){Z?_(Z):(++H===$||ct===go)&&_(null)}for(;N<$;N++)S(y[N],N,vr(X))}var LA=ze(_i,1/0),Yr=function(y,S,_){var N=Cl(y)?Sf:LA;N(y,U(S),_)};function Zr(y){return function(S,_,N){return y(Yr,S,U(_),N)}}function Lf(y,S,_,N){N=N||Ht,S=S||[];var H=[],$=0,X=U(_);y(S,function(Z,ct,Ct){var ut=$++;X(Z,function(xt,Yt){H[ut]=Yt,Ct(xt)})},function(Z){N(Z,H)})}var pc=Zr(Lf),If=F(pc);function po(y){return function(S,_,N,H){return y(yl(_),S,U(N),H)}}var Mi=po(Lf),Df=ze(Mi,1),_f=F(Df);function gs(y,S){for(var _=-1,N=y==null?0:y.length;++_<N&&S(y[_],_,y)!==!1;);return y}function Mf(y){return function(S,_,N){for(var H=-1,$=Object(S),X=N(S),Z=X.length;Z--;){var ct=X[y?Z:++H];if(_($[ct],ct,$)===!1)break}return S}}var ps=Mf();function Cs(y,S){return y&&ps(y,S,gc)}function hm(y,S,_,N){for(var H=y.length,$=_+(N?1:-1);N?$--:++$<H;)if(S(y[$],$,y))return $;return-1}function IA(y){return y!==y}function mm(y,S,_){for(var N=_-1,H=y.length;++N<H;)if(y[N]===S)return N;return-1}function kl(y,S,_){return S===S?mm(y,S,_):hm(y,IA,_)}var Cc=function(y,S,_){typeof S=="function"&&(_=S,S=null),_=Di(_||Ht);var N=gc(y),H=N.length;if(!H)return _(null);S||(S=H);var $={},X=0,Z=!1,ct=Object.create(null),Ct=[],ut=[],xt={};Cs(y,function(pe,ae){if(!Be(pe)){Yt(ae,[pe]),ut.push(ae);return}var xe=pe.slice(0,pe.length-1),Tr=xe.length;if(Tr===0){Yt(ae,pe),ut.push(ae);return}xt[ae]=Tr,gs(xe,function(k){if(!y[k])throw new Error("async.auto task `"+ae+"` has a non-existent dependency `"+k+"` in "+xe.join(", "));sn(k,function(){Tr--,Tr===0&&Yt(ae,pe)})})}),JA(),Ne();function Yt(pe,ae){Ct.push(function(){Br(pe,ae)})}function Ne(){if(Ct.length===0&&X===0)return _(null,$);for(;Ct.length&&X<S;){var pe=Ct.shift();pe()}}function sn(pe,ae){var xe=ct[pe];xe||(xe=ct[pe]=[]),xe.push(ae)}function Vn(pe){var ae=ct[pe]||[];gs(ae,function(xe){xe()}),Ne()}function Br(pe,ae){if(!Z){var xe=vr(function(k,Ni){if(X--,arguments.length>2&&(Ni=r(arguments,1)),k){var bs={};Cs($,function($n,Vt){bs[Vt]=$n}),bs[pe]=Ni,Z=!0,ct=Object.create(null),_(k,bs)}else $[pe]=Ni,Vn(pe)});X++;var Tr=U(ae[ae.length-1]);ae.length>1?Tr($,xe):Tr(xe)}}function JA(){for(var pe,ae=0;ut.length;)pe=ut.pop(),ae++,gs(tx(pe),function(xe){--xt[xe]===0&&ut.push(xe)});if(ae!==H)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function tx(pe){var ae=[];return Cs(y,function(xe,Tr){Be(xe)&&kl(xe,pe,0)>=0&&ae.push(Tr)}),ae}};function Co(y,S){for(var _=-1,N=y==null?0:y.length,H=Array(N);++_<N;)H[_]=S(y[_],_,y);return H}var DA="[object Symbol]";function _A(y){return typeof y=="symbol"||pn(y)&&Ii(y)==DA}var MA=1/0,Uf=at?at.prototype:void 0,gm=Uf?Uf.toString:void 0;function Of(y){if(typeof y=="string")return y;if(Be(y))return Co(y,Of)+"";if(_A(y))return gm?gm.call(y):"";var S=y+"";return S=="0"&&1/y==-MA?"-0":S}function UA(y,S,_){var N=-1,H=y.length;S<0&&(S=-S>H?0:H+S),_=_>H?H:_,_<0&&(_+=H),H=S>_?0:_-S>>>0,S>>>=0;for(var $=Array(H);++N<H;)$[N]=y[N+S];return $}function OA(y,S,_){var N=y.length;return _=_===void 0?N:_,!S&&_>=N?y:UA(y,S,_)}function Nf(y,S){for(var _=y.length;_--&&kl(S,y[_],0)>-1;);return _}function NA(y,S){for(var _=-1,N=y.length;++_<N&&kl(S,y[_],0)>-1;);return _}function PA(y){return y.split("")}var FA="\\ud800-\\udfff",KA="\\u0300-\\u036f",VA="\\ufe20-\\ufe2f",de="\\u20d0-\\u20ff",le=KA+VA+de,$A="\\ufe0e\\ufe0f",HA="\\u200d",jA=RegExp("["+HA+FA+le+$A+"]");function zA(y){return jA.test(y)}var pm="\\ud800-\\udfff",GA="\\u0300-\\u036f",Cm="\\ufe20-\\ufe2f",WA="\\u20d0-\\u20ff",Ye=GA+Cm+WA,Pf="\\ufe0e\\ufe0f",Eo="["+pm+"]",Ec="["+Ye+"]",Rl="\\ud83c[\\udffb-\\udfff]",Fn="(?:"+Ec+"|"+Rl+")",Ff="[^"+pm+"]",Kf="(?:\\ud83c[\\udde6-\\uddff]){2}",Vf="[\\ud800-\\udbff][\\udc00-\\udfff]",Em="\\u200d",$f=Fn+"?",Hf="["+Pf+"]?",kn="(?:"+Em+"(?:"+[Ff,Kf,Vf].join("|")+")"+Hf+$f+")*",qA=Hf+$f+kn,Kn="(?:"+[Ff+Ec+"?",Ec,Kf,Vf,Eo].join("|")+")",XA=RegExp(Rl+"(?="+Rl+")|"+Kn+qA,"g");function Am(y){return y.match(XA)||[]}function Jr(y){return zA(y)?Am(y):PA(y)}function Ac(y){return y==null?"":Of(y)}var jf=/^\s+|\s+$/g;function ge(y,S,_){if(y=Ac(y),y&&(_||S===void 0))return y.replace(jf,"");if(!y||!(S=Of(S)))return y;var N=Jr(y),H=Jr(S),$=NA(N,H),X=Nf(N,H)+1;return OA(N,$,X).join("")}var Ui=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,zf=/,/,QA=/(=.+)?(\s*)$/,Gf=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function YA(y){return y=y.toString().replace(Gf,""),y=y.match(Ui)[2].replace(" ",""),y=y?y.split(zf):[],y=y.map(function(S){return ge(S.replace(QA,""))}),y}function xm(y,S){var _={};Cs(y,function(N,H){var $,X=M(N),Z=!X&&N.length===1||X&&N.length===0;if(Be(N))$=N.slice(0,-1),N=N[N.length-1],_[H]=$.concat($.length>0?ct:N);else if(Z)_[H]=N;else{if($=YA(N),N.length===0&&!X&&$.length===0)throw new Error("autoInject task functions require explicit parameters.");X||$.pop(),_[H]=$.concat(ct)}function ct(Ct,ut){var xt=Co($,function(Yt){return Ct[Yt]});xt.push(ut),U(N).apply(null,xt)}}),Cc(_,S)}function rr(){this.head=this.tail=null,this.length=0}function Wf(y,S){y.length=1,y.head=y.tail=S}rr.prototype.removeLink=function(y){return y.prev?y.prev.next=y.next:this.head=y.next,y.next?y.next.prev=y.prev:this.tail=y.prev,y.prev=y.next=null,this.length-=1,y},rr.prototype.empty=function(){for(;this.head;)this.shift();return this},rr.prototype.insertAfter=function(y,S){S.prev=y,S.next=y.next,y.next?y.next.prev=S:this.tail=S,y.next=S,this.length+=1},rr.prototype.insertBefore=function(y,S){S.prev=y.prev,S.next=y,y.prev?y.prev.next=S:this.head=S,y.prev=S,this.length+=1},rr.prototype.unshift=function(y){this.head?this.insertBefore(this.head,y):Wf(this,y)},rr.prototype.push=function(y){this.tail?this.insertAfter(this.tail,y):Wf(this,y)},rr.prototype.shift=function(){return this.head&&this.removeLink(this.head)},rr.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},rr.prototype.toArray=function(){for(var y=Array(this.length),S=this.head,_=0;_<this.length;_++)y[_]=S.data,S=S.next;return y},rr.prototype.remove=function(y){for(var S=this.head;S;){var _=S.next;y(S)&&this.removeLink(S),S=_}return this};function wl(y,S,_){if(S==null)S=1;else if(S===0)throw new Error("Concurrency must not be zero");var N=U(y),H=0,$=[],X=!1;function Z(xt,Yt,Ne){if(Ne!=null&&typeof Ne!="function")throw new Error("task callback must be a function");if(ut.started=!0,Be(xt)||(xt=[xt]),xt.length===0&&ut.idle())return E(function(){ut.drain()});for(var sn=0,Vn=xt.length;sn<Vn;sn++){var Br={data:xt[sn],callback:Ne||Ht};Yt?ut._tasks.unshift(Br):ut._tasks.push(Br)}X||(X=!0,E(function(){X=!1,ut.process()}))}function ct(xt){return function(Yt){H-=1;for(var Ne=0,sn=xt.length;Ne<sn;Ne++){var Vn=xt[Ne],Br=kl($,Vn,0);Br===0?$.shift():Br>0&&$.splice(Br,1),Vn.callback.apply(Vn,arguments),Yt!=null&&ut.error(Yt,Vn.data)}H<=ut.concurrency-ut.buffer&&ut.unsaturated(),ut.idle()&&ut.drain(),ut.process()}}var Ct=!1,ut={_tasks:new rr,concurrency:S,payload:_,saturated:Ht,unsaturated:Ht,buffer:S/4,empty:Ht,drain:Ht,error:Ht,started:!1,paused:!1,push:function(xt,Yt){Z(xt,!1,Yt)},kill:function(){ut.drain=Ht,ut._tasks.empty()},unshift:function(xt,Yt){Z(xt,!0,Yt)},remove:function(xt){ut._tasks.remove(xt)},process:function(){if(!Ct){for(Ct=!0;!ut.paused&&H<ut.concurrency&&ut._tasks.length;){var xt=[],Yt=[],Ne=ut._tasks.length;ut.payload&&(Ne=Math.min(Ne,ut.payload));for(var sn=0;sn<Ne;sn++){var Vn=ut._tasks.shift();xt.push(Vn),$.push(Vn),Yt.push(Vn.data)}H+=1,ut._tasks.length===0&&ut.empty(),H===ut.concurrency&&ut.saturated();var Br=vr(ct(xt));N(Yt,Br)}Ct=!1}},length:function(){return ut._tasks.length},running:function(){return H},workersList:function(){return $},idle:function(){return ut._tasks.length+H===0},pause:function(){ut.paused=!0},resume:function(){ut.paused!==!1&&(ut.paused=!1,E(ut.process))}};return ut}function Ao(y,S){return wl(y,1,S)}var Es=ze(_i,1);function ti(y,S,_,N){N=Di(N||Ht);var H=U(_);Es(y,function($,X,Z){H(S,$,function(ct,Ct){S=Ct,Z(ct)})},function($){N($,S)})}function xc(){var y=Co(arguments,U);return function(){var S=r(arguments),_=this,N=S[S.length-1];typeof N=="function"?S.pop():N=Ht,ti(y,S,function(H,$,X){$.apply(_,H.concat(function(Z){var ct=r(arguments,1);X(Z,ct)}))},function(H,$){N.apply(_,[H].concat($))})}}var bc=function(){return xc.apply(null,r(arguments).reverse())},qf=Array.prototype.concat,Sl=function(y,S,_,N){N=N||Ht;var H=U(_);Mi(y,S,function($,X){H($,function(Z){return Z?X(Z):X(null,r(arguments,1))})},function($,X){for(var Z=[],ct=0;ct<X.length;ct++)X[ct]&&(Z=qf.apply(Z,X[ct]));return N($,Z)})},bm=ze(Sl,1/0),vc=ze(Sl,1),Bc=function(){var y=r(arguments),S=[null].concat(y);return function(){var _=arguments[arguments.length-1];return _.apply(this,S)}};function Ll(y){return y}function xo(y,S){return function(_,N,H,$){$=$||Ht;var X=!1,Z;_(N,function(ct,Ct,ut){H(ct,function(xt,Yt){xt?ut(xt):y(Yt)&&!Z?(X=!0,Z=S(!0,ct),ut(null,go)):ut()})},function(ct){ct?$(ct):$(null,X?Z:S(!1))})}}function Cn(y,S){return S}var As=Zr(xo(Ll,Cn)),ei=po(xo(Ll,Cn)),Il=ze(ei,1);function Xf(y){return function(S){var _=r(arguments,1);_.push(function(N){var H=r(arguments,1);typeof console=="object"&&(N?console.error&&console.error(N):console[y]&&gs(H,function($){console[y]($)}))}),U(S).apply(null,_)}}var vm=Xf("dir");function Bm(y,S,_){_=vr(_||Ht);var N=U(y),H=U(S);function $(Z){if(Z)return _(Z);var ct=r(arguments,1);ct.push(X),H.apply(this,ct)}function X(Z,ct){if(Z)return _(Z);if(!ct)return _(null);N($)}X(null,!0)}function Qf(y,S,_){_=vr(_||Ht);var N=U(y),H=function($){if($)return _($);var X=r(arguments,1);if(S.apply(this,X))return N(H);_.apply(null,[null].concat(X))};N(H)}function Tm(y,S,_){Qf(y,function(){return!S.apply(this,arguments)},_)}function ym(y,S,_){_=vr(_||Ht);var N=U(S),H=U(y);function $(Z){if(Z)return _(Z);H(X)}function X(Z,ct){if(Z)return _(Z);if(!ct)return _(null);N($)}H(X)}function bo(y){return function(S,_,N){return y(S,N)}}function Tc(y,S,_){Yr(y,bo(U(S)),_)}function Dl(y,S,_,N){yl(S)(y,bo(U(_)),N)}var vo=ze(Dl,1);function yc(y){return M(y)?y:o(function(S,_){var N=!0;S.push(function(){var H=arguments;N?E(function(){_.apply(null,H)}):_.apply(null,H)}),y.apply(this,S),N=!1})}function ir(y){return!y}var Bo=Zr(xo(ir,ir)),_l=po(xo(ir,ir)),kc=ze(_l,1);function km(y){return function(S){return S==null?void 0:S[y]}}function xs(y,S,_,N){var H=new Array(S.length);y(S,function($,X,Z){_($,function(ct,Ct){H[X]=!!Ct,Z(ct)})},function($){if($)return N($);for(var X=[],Z=0;Z<S.length;Z++)H[Z]&&X.push(S[Z]);N(null,X)})}function or(y,S,_,N){var H=[];y(S,function($,X,Z){_($,function(ct,Ct){ct?Z(ct):(Ct&&H.push({index:X,value:$}),Z())})},function($){$?N($):N(null,Co(H.sort(function(X,Z){return X.index-Z.index}),km("value")))})}function Rc(y,S,_,N){var H=Cl(S)?xs:or;H(y,S,U(_),N||Ht)}var wc=Zr(Rc),Ml=po(Rc),Sc=ze(Ml,1);function Rm(y,S){var _=vr(S||Ht),N=U(yc(y));function H($){if($)return _($);N(H)}H()}var Lc=function(y,S,_,N){N=N||Ht;var H=U(_);Mi(y,S,function($,X){H($,function(Z,ct){return Z?X(Z):X(null,{key:ct,val:$})})},function($,X){for(var Z={},ct=Object.prototype.hasOwnProperty,Ct=0;Ct<X.length;Ct++)if(X[Ct]){var ut=X[Ct].key,xt=X[Ct].val;ct.call(Z,ut)?Z[ut].push(xt):Z[ut]=[xt]}return N($,Z)})},To=ze(Lc,1/0),K=ze(Lc,1),W=Xf("log");function j(y,S,_,N){N=Di(N||Ht);var H={},$=U(_);_i(y,S,function(X,Z,ct){$(X,Z,function(Ct,ut){if(Ct)return ct(Ct);H[Z]=ut,ct()})},function(X){N(X,H)})}var mt=ze(j,1/0),wt=ze(j,1);function Wt(y,S){return S in y}function Le(y,S){var _=Object.create(null),N=Object.create(null);S=S||Ll;var H=U(y),$=o(function(Z,ct){var Ct=S.apply(null,Z);Wt(_,Ct)?E(function(){ct.apply(null,_[Ct])}):Wt(N,Ct)?N[Ct].push(ct):(N[Ct]=[ct],H.apply(null,Z.concat(function(){var ut=r(arguments);_[Ct]=ut;var xt=N[Ct];delete N[Ct];for(var Yt=0,Ne=xt.length;Yt<Ne;Yt++)xt[Yt].apply(null,ut)})))});return $.memo=_,$.unmemoized=y,$}var Xt;c?Xt=process.nextTick:l?Xt=setImmediate:Xt=d;var Ic=h(Xt);function Yf(y,S,_){_=_||Ht;var N=Cl(S)?[]:{};y(S,function(H,$,X){U(H)(function(Z,ct){arguments.length>2&&(ct=r(arguments,1)),N[$]=ct,X(Z)})},function(H){_(H,N)})}function Rn(y,S){Yf(Yr,y,S)}function Ul(y,S,_){Yf(yl(S),y,_)}var Zf=function(y,S){var _=U(y);return wl(function(N,H){_(N[0],H)},S,1)},yo=function(y,S){var _=Zf(y,S);return _.push=function(N,H,$){if($==null&&($=Ht),typeof $!="function")throw new Error("task callback must be a function");if(_.started=!0,Be(N)||(N=[N]),N.length===0)return E(function(){_.drain()});H=H||0;for(var X=_._tasks.head;X&&H>=X.priority;)X=X.next;for(var Z=0,ct=N.length;Z<ct;Z++){var Ct={data:N[Z],priority:H,callback:$};X?_._tasks.insertBefore(X,Ct):_._tasks.push(Ct)}E(_.process)},delete _.unshift,_};function Ol(y,S){if(S=Di(S||Ht),!Be(y))return S(new TypeError("First argument to race must be an array of functions"));if(!y.length)return S();for(var _=0,N=y.length;_<N;_++)U(y[_])(S)}function ko(y,S,_,N){var H=r(y).reverse();ti(H,S,_,N)}function qt(y){var S=U(y);return o(function(N,H){return N.push(function(X,Z){if(X)H(null,{error:X});else{var ct;arguments.length<=2?ct=Z:ct=r(arguments,1),H(null,{value:ct})}}),S.apply(this,N)})}function wm(y){var S;return Be(y)?S=Co(y,qt):(S={},Cs(y,function(_,N){S[N]=qt.call(this,_)})),S}function Jf(y,S,_,N){Rc(y,S,function(H,$){_(H,function(X,Z){$(X,!Z)})},N)}var Nl=Zr(Jf),td=po(Jf),Sm=ze(td,1);function Lm(y){return function(){return y}}function Ro(y,S,_){var N=5,H=0,$={times:N,intervalFunc:Lm(H)};function X(ut,xt){if(typeof xt=="object")ut.times=+xt.times||N,ut.intervalFunc=typeof xt.interval=="function"?xt.interval:Lm(+xt.interval||H),ut.errorFilter=xt.errorFilter;else if(typeof xt=="number"||typeof xt=="string")ut.times=+xt||N;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof y=="function"?(_=S||Ht,S=y):(X($,y),_=_||Ht),typeof S!="function")throw new Error("Invalid arguments for async.retry");var Z=U(S),ct=1;function Ct(){Z(function(ut){ut&&ct++<$.times&&(typeof $.errorFilter!="function"||$.errorFilter(ut))?setTimeout(Ct,$.intervalFunc(ct)):_.apply(null,arguments)})}Ct()}var ni=function(y,S){S||(S=y,y=null);var _=U(S);return o(function(N,H){function $(X){_.apply(null,N.concat(X))}y?Ro(y,$,H):Ro($,H)})};function Pl(y,S){Yf(Es,y,S)}var Fl=Zr(xo(Boolean,Ll)),Oi=po(xo(Boolean,Ll)),Kl=ze(Oi,1);function ed(y,S,_){var N=U(S);pc(y,function($,X){N($,function(Z,ct){if(Z)return X(Z);X(null,{value:$,criteria:ct})})},function($,X){if($)return _($);_(null,Co(X.sort(H),km("value")))});function H($,X){var Z=$.criteria,ct=X.criteria;return Z<ct?-1:Z>ct?1:0}}function Vl(y,S,_){var N=U(y);return o(function(H,$){var X=!1,Z;function ct(){var Ct=y.name||"anonymous",ut=new Error('Callback function "'+Ct+'" timed out.');ut.code="ETIMEDOUT",_&&(ut.info=_),X=!0,$(ut)}H.push(function(){X||($.apply(null,arguments),clearTimeout(Z))}),Z=setTimeout(ct,S),N.apply(null,H)})}var Im=Math.ceil,$l=Math.max;function wo(y,S,_,N){for(var H=-1,$=$l(Im((S-y)/(_||1)),0),X=Array($);$--;)X[N?$:++H]=y,y+=_;return X}function So(y,S,_,N){var H=U(_);Mi(wo(0,y,1),S,H,N)}var Dm=ze(So,1/0),_m=ze(So,1);function Mm(y,S,_,N){arguments.length<=3&&(N=_,_=S,S=Be(y)?[]:{}),N=Di(N||Ht);var H=U(_);Yr(y,function($,X,Z){H(S,$,X,Z)},function($){N($,S)})}function Hl(y,S){var _=null,N;S=S||Ht,vo(y,function(H,$){U(H)(function(X,Z){arguments.length>2?N=r(arguments,1):N=Z,_=X,$(!X)})},function(){S(_,N)})}function jl(y){return function(){return(y.unmemoized||y).apply(null,arguments)}}function zl(y,S,_){_=vr(_||Ht);var N=U(S);if(!y())return _(null);var H=function($){if($)return _($);if(y())return N(H);var X=r(arguments,1);_.apply(null,[null].concat(X))};N(H)}function Um(y,S,_){zl(function(){return!y.apply(this,arguments)},S,_)}var nd=function(y,S){if(S=Di(S||Ht),!Be(y))return S(new Error("First argument to waterfall must be an array of functions"));if(!y.length)return S();var _=0;function N($){var X=U(y[_++]);$.push(vr(H)),X.apply(null,$)}function H($){if($||_===y.length)return S.apply(null,arguments);N(r(arguments,1))}N([])},ZA={apply:i,applyEach:If,applyEachSeries:_f,asyncify:x,auto:Cc,autoInject:xm,cargo:Ao,compose:bc,concat:bm,concatLimit:Sl,concatSeries:vc,constant:Bc,detect:As,detectLimit:ei,detectSeries:Il,dir:vm,doDuring:Bm,doUntil:Tm,doWhilst:Qf,during:ym,each:Tc,eachLimit:Dl,eachOf:Yr,eachOfLimit:_i,eachOfSeries:Es,eachSeries:vo,ensureAsync:yc,every:Bo,everyLimit:_l,everySeries:kc,filter:wc,filterLimit:Ml,filterSeries:Sc,forever:Rm,groupBy:To,groupByLimit:Lc,groupBySeries:K,log:W,map:pc,mapLimit:Mi,mapSeries:Df,mapValues:mt,mapValuesLimit:j,mapValuesSeries:wt,memoize:Le,nextTick:Ic,parallel:Rn,parallelLimit:Ul,priorityQueue:yo,queue:Zf,race:Ol,reduce:ti,reduceRight:ko,reflect:qt,reflectAll:wm,reject:Nl,rejectLimit:td,rejectSeries:Sm,retry:Ro,retryable:ni,seq:xc,series:Pl,setImmediate:E,some:Fl,someLimit:Oi,someSeries:Kl,sortBy:ed,timeout:Vl,times:Dm,timesLimit:So,timesSeries:_m,transform:Mm,tryEach:Hl,unmemoize:jl,until:Um,waterfall:nd,whilst:zl,all:Bo,allLimit:_l,allSeries:kc,any:Fl,anyLimit:Oi,anySeries:Kl,find:As,findLimit:ei,findSeries:Il,forEach:Tc,forEachSeries:vo,forEachLimit:Dl,forEachOf:Yr,forEachOfSeries:Es,forEachOfLimit:_i,inject:ti,foldl:ti,foldr:ko,select:wc,selectLimit:Ml,selectSeries:Sc,wrapSync:x};e.default=ZA,e.apply=i,e.applyEach=If,e.applyEachSeries=_f,e.asyncify=x,e.auto=Cc,e.autoInject=xm,e.cargo=Ao,e.compose=bc,e.concat=bm,e.concatLimit=Sl,e.concatSeries=vc,e.constant=Bc,e.detect=As,e.detectLimit=ei,e.detectSeries=Il,e.dir=vm,e.doDuring=Bm,e.doUntil=Tm,e.doWhilst=Qf,e.during=ym,e.each=Tc,e.eachLimit=Dl,e.eachOf=Yr,e.eachOfLimit=_i,e.eachOfSeries=Es,e.eachSeries=vo,e.ensureAsync=yc,e.every=Bo,e.everyLimit=_l,e.everySeries=kc,e.filter=wc,e.filterLimit=Ml,e.filterSeries=Sc,e.forever=Rm,e.groupBy=To,e.groupByLimit=Lc,e.groupBySeries=K,e.log=W,e.map=pc,e.mapLimit=Mi,e.mapSeries=Df,e.mapValues=mt,e.mapValuesLimit=j,e.mapValuesSeries=wt,e.memoize=Le,e.nextTick=Ic,e.parallel=Rn,e.parallelLimit=Ul,e.priorityQueue=yo,e.queue=Zf,e.race=Ol,e.reduce=ti,e.reduceRight=ko,e.reflect=qt,e.reflectAll=wm,e.reject=Nl,e.rejectLimit=td,e.rejectSeries=Sm,e.retry=Ro,e.retryable=ni,e.seq=xc,e.series=Pl,e.setImmediate=E,e.some=Fl,e.someLimit=Oi,e.someSeries=Kl,e.sortBy=ed,e.timeout=Vl,e.times=Dm,e.timesLimit=So,e.timesSeries=_m,e.transform=Mm,e.tryEach=Hl,e.unmemoize=jl,e.until=Um,e.waterfall=nd,e.whilst=zl,e.all=Bo,e.allLimit=_l,e.allSeries=kc,e.any=Fl,e.anyLimit=Oi,e.anySeries=Kl,e.find=As,e.findLimit=ei,e.findSeries=Il,e.forEach=Tc,e.forEachSeries=vo,e.forEachLimit=Dl,e.forEachOf=Yr,e.forEachOfSeries=Es,e.forEachOfLimit=_i,e.inject=ti,e.foldl=ti,e.foldr=ko,e.select=wc,e.selectLimit=Ml,e.selectSeries=Sc,e.wrapSync=x,Object.defineProperty(e,"__esModule",{value:!0})})})(ep,ep.exports);var n2={exports:{}},np=n2.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)?np(n,t):o};np.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=np(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 r2=qo,kM=t2,RM=e2,Sh=Vr,rp=ep.exports,wM=n2.exports,i2=tl.ACTIONS,o2=Ve;function Ve(n,t){if(r2.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}r2.mixin(Ve),Ve.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Ve.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Ve.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||wM();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Ve.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);rp.parallel([function(o){rp.each(e,function(s,l){t.localPresences[s].destroy(l)},o)},function(o){if(!t._wantsDestroy)return o();rp.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)})})},Ve.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?i2.presenceSubscribe:i2.presenceUnsubscribe,r=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[r]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,r,this)},Ve.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Ve.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Ve.prototype._receiveUpdate=function(n,t){var e=Sh.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var r=this,i=Sh.digOrCreate(this._remotePresenceInstances,t.id,function(){return r._createRemotePresence(t.id)});i.receiveUpdate(t)},Ve.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Ve.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()}},Ve.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Ve.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Ve.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)})},Ve.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Ve.prototype._callbackOrEmit=function(n,t){if(t)return Sh.nextTick(t,n);n&&this.emit("error",n)},Ve.prototype._createLocalPresence=function(n){return new kM(this,n)},Ve.prototype._createRemotePresence=function(n){return new RM(this,n)},Ve.prototype._callEachOrEmit=function(n,t){var e=Sh.callEach(n,t);!e&&t&&this.emit("error",t)};var Eu=t2,s2=Th,SM=Vr,l2=s2.CODES,LM=Hr;function Hr(n,t){Eu.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),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()}Hr.prototype=Object.create(Eu.prototype),Hr.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:l2.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,Eu.prototype.submit.call(this,n,t)},Hr.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createOrDelHandler),this._doc.removeListener("del",this._createOrDelHandler),this._doc.removeListener("load",this._loadHandler),this._doc.removeListener("destroy",this._destroyHandler),Eu.prototype.destroy.call(this,n)},Hr.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={})})}},Hr.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createOrDelHandler),this._doc.on("del",this._createOrDelHandler),this._doc.on("load",this._loadHandler),this._doc.on("destroy",this._destroyHandler)},Hr.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)}},Hr.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},Hr.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},Hr.prototype._message=function(){var n=Eu.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},Hr.prototype._transformPresence=function(n,t,e){var r=this._doc.type;if(!SM.supportsPresence(r))throw new s2(l2.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+r.name);return r.transformPresence(n,t,e)};var a2={};(function(n){var t=gu,e=Th,r=Vr,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 x=E.p,v=h,R=0;R<x.length;R++){var L=x[R];Object.prototype.toString.call(v)=="[object Array]"?x[R]=+L:v.constructor===Object&&(x[R]=L.toString()),v=v[L]}C<d.length-1&&(h=t.defaultType.apply(h,[E]))}}}}})(a2);var Au=e2,IM=a2,DM=pr;function pr(n,t){Au.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._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()}pr.prototype=Object.create(Au.prototype),pr.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},pr.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createDelHandler),this._doc.removeListener("del",this._createDelHandler),this._doc.removeListener("load",this._loadHandler),Au.prototype.destroy.call(this,n)},pr.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createDelHandler),this._doc.on("del",this._createDelHandler),this._doc.on("load",this._loadHandler)},pr.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))}})}},pr.prototype._handleOp=function(n,t,e){var r=e===this.src;this._transformAgainstOp(n,r),this._cacheOp(n,r),this._setPendingPresence()},Au.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},Au.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},pr.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)}},pr.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++):IM.transformPresence(this._pending,t,e)}var r=this._pending.v>=this._doc.version;return r&&this._stopCachingOps(),r},pr.prototype._startCachingOps=function(){this._opCache=[]},pr.prototype._stopCachingOps=function(){this._opCache=null},pr.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var c2=o2,_M=LM,MM=DM;function Ba(n,t,e){var r=Ba.channel(t,e);c2.call(this,n,r),this.collection=t,this.id=e}var UM=Ba;Ba.prototype=Object.create(c2.prototype),Ba.channel=function(n,t){return n+"."+t},Ba.prototype._createLocalPresence=function(n){return new _M(this,n)},Ba.prototype._createRemotePresence=function(n){return new MM(this,n)};var OM=NM;function NM(n,t,e,r,i){this.id=n,this.v=t,this.type=e,this.data=r,this.m=i}var PM=OM,u2=qo,f2=xu;function xu(n,t,e,r,i){if(u2.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}u2.mixin(xu),xu.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},xu.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},xu.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,r=new PM(this.id,t.v,t.type,t.data,e);this.callback(null,r)};var d2=f2,FM=Vr,KM=tl.ACTIONS,VM=ip;function ip(n,t,e,r,i,o){if(d2.call(this,n,t,e,r,o),!FM.isValidVersion(i))throw new Error("Snapshot version must be a positive integer or null");this.version=i}ip.prototype=Object.create(d2.prototype),ip.prototype._message=function(){return{a:KM.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var h2=f2,$M=Vr,HM=tl.ACTIONS,jM=op;function op(n,t,e,r,i,o){if(h2.call(this,n,t,e,r,o),!$M.isValidTimestamp(i))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=i}op.prototype=Object.create(h2.prototype),op.prototype._message=function(){return{a:HM.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var zM=CM,GM=vM,WM=o2,m2=UM,qM=VM,XM=jM,g2=qo,Ta=Th,ie=tl.ACTIONS,p2=gu,jr=Vr,bu=z5,vu=Ta.CODES;function C2(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var QM=yt;function yt(n){g2.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=C2(n),this.bindToSocket(n)}g2.mixin(yt),yt.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=C2(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{bu.warn("Failed to parse message",r);return}e.debug&&bu.info("RECV",JSON.stringify(i));var o={data:i};if(e.emit("receive",o),!!o.data)try{e.handleMessage(o.data)}catch(s){jr.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)}},yt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=E2(n.error,n),delete n.error),n.a){case ie.initLegacy:return this._handleLegacyInit(n);case ie.handshake:return this._handleHandshake(t,n);case ie.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case ie.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case ie.queryUnsubscribe:return;case ie.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 ie.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case ie.bulkSubscribe:case ie.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case ie.snapshotFetch:case ie.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case ie.fetch:var r=this.getExisting(n.c,n.d);r&&r._handleFetch(t,n.data);return;case ie.subscribe:case ie.unsubscribe:var r=this.getExisting(n.c,n.d);r&&r._handleSubscribe(t,n.data);return;case ie.op:var r=this.getExisting(n.c,n.d);r&&r._handleOp(t,n);return;case ie.presence:return this._handlePresence(t,n);case ie.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case ie.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case ie.presenceRequest:return this._handlePresenceRequest(t,n);case ie.pingPong:return this._handlePingPong(t);default:bu.warn("Ignoring unrecognized message",n)}};function E2(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}yt.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](E2(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 bu.error("Invalid bulk message",t)},yt.prototype._reset=function(){this.agent=null},yt.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 Ta(vu.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)}},yt.prototype.startBulk=function(){this.bulk||(this.bulk={})},yt.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},yt.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})}},yt.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)}},yt.prototype.sendFetch=function(n){return this._sendActions(ie.fetch,n,n.version)},yt.prototype.sendSubscribe=function(n){return this._sendActions(ie.subscribe,n,n.version)},yt.prototype.sendUnsubscribe=function(n){return this._sendActions(ie.unsubscribe,n)},yt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:ie.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)},yt.prototype.send=function(n){this.debug&&bu.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},yt.prototype.ping=function(){if(!this.canSend)throw new Ta(vu.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:ie.pingPong};this.send(n)},yt.prototype.close=function(){this.socket.close()},yt.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},yt.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),r=e[t];return r||(r=e[t]=new zM(this,n,t),this.emit("doc",r)),r._wantsDestroy=!1,r},yt.prototype._destroyDoc=function(n){!n._wantsDestroy||(jr.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},yt.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},yt.prototype._createQuery=function(n,t,e,r,i){var o=this.nextQueryId++,s=new GM(n,this,o,t,e,r,i);return this.queries[o]=s,s.send(),s},yt.prototype._destroyQuery=function(n){delete this.queries[n.id]},yt.prototype.createFetchQuery=function(n,t,e,r){return this._createQuery(ie.queryFetch,n,t,e,r)},yt.prototype.createSubscribeQuery=function(n,t,e,r){return this._createQuery(ie.querySubscribe,n,t,e,r)},yt.prototype.hasPending=function(){return!!(this._firstDoc(Lh)||this._firstQuery(Lh)||this._firstSnapshotRequest())};function Lh(n){return n.hasPending()}yt.prototype.hasWritePending=function(){return!!this._firstDoc(YM)};function YM(n){return n.hasWritePending()}yt.prototype.whenNothingPending=function(n){var t=this._firstDoc(Lh);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(Lh);if(e){e.once("ready",this._nothingPendingRetry(n));return}var r=this._firstSnapshotRequest();if(r){r.once("ready",this._nothingPendingRetry(n));return}jr.nextTick(n)},yt.prototype._nothingPendingRetry=function(n){var t=this;return function(){jr.nextTick(function(){t.whenNothingPending(n)})}},yt.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}}},yt.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},yt.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},yt.prototype.fetchSnapshot=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new qM(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},yt.prototype.fetchSnapshotByTimestamp=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new XM(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},yt.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},yt.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},yt.prototype._initializeHandshake=function(){this.send({a:ie.handshake,id:this.id})},yt.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},yt.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},yt.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new Ta(vu.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(p2.map[n.type]!==p2.defaultType)return this.emit("error",new Ta(vu.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new Ta(vu.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},yt.prototype.getPresence=function(n){var t=this,e=jr.digOrCreate(this._presences,n,function(){return new WM(t,n)});return e._wantsDestroy=!1,e},yt.prototype.getDocPresence=function(n,t){var e=m2.channel(n,t),r=this,i=jr.digOrCreate(this._presences,e,function(){return new m2(r,n,t)});return i._wantsDestroy=!1,i},yt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var r={a:n,ch:e.channel,seq:t};return this.send(r),r.seq},yt.prototype._addPresence=function(n){jr.digOrCreate(this._presences,n.channel,function(){return n})},yt.prototype._handlePresenceSubscribe=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},yt.prototype._handlePresenceUnsubscribe=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},yt.prototype._handlePresence=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},yt.prototype._handlePresenceRequest=function(n,t){var e=jr.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var A2=QM,ZM=gu;const Ih={err:1001,msg:"user auth error",name:"AuthError"},JM={err:1002,msg:"you don't have required permission",name:"PermissionError"},sp={err:1003,msg:"Too many user connected",name:"MaxUserError"},Bu={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},tU={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},eU={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},ya="x-live-editor-token",Tu="x-live-editor-base-url",vn=I("auth-connection");function nU(n){try{n()}catch(t){vn.error(t)}}class rU{constructor(t,e){g(this,"enabled",!0);g(this,"connection");g(this,"ws");g(this,"retryCount");g(this,"events",new zx.EventEmitter);g(this,"token",null);g(this,"resourceToken",null);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 ji(this.getBaseURL())}async auth(t){p(vn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,r=await window.fetch(e,{method:"GET",headers:{[ya]:t.token,[Tu]:this.getBase64BaseURL()},credentials:"include"});if(r.status!==200)throw new Error("http auth error");return 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:{[Tu]:ji(this.getBaseURL())}})}async init(t){const e=await this.auth(t);if(!this.enabled)return;this.resourceToken=e.read,this.ws=new s6.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(A2.prototype),p(vn,this.connection,"no this.connection"),this.ws,this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})};const r=this.connection.handleMessage.bind(this.connection);this.connection.handleMessage=i=>{var s;const o=i;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in o||o.a==="pong")this.handleMessage(o);else{Object.prototype.hasOwnProperty.call(o,"a")&&o.a!=="init"&&o.a!=="hs"&&(this.retryCount=0);try{r(o)}catch(l){if((l==null?void 0:l.type)==="writeConflict"){this.emitWriteConflictError(l,o);return}if((s=l==null?void 0:l.message)!=null&&s.startsWith("Cannot invert subtype")){this.emitWriteConflictError(l,o);return}throw l}}},A2.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,vn.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const t=await this.reauthFunc();if(await this.auth(t),!this.enabled){this.retryCount=10,setTimeout(()=>this.handleAuthError(),0);return}this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})}}}catch(t){vn.error(t),setTimeout(()=>this.handleAuthError(),0)}}else vn.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(Ih.msg);t.code=Ih.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Bu.msg);t.code=Bu.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===Ih.err)vn.warn("auth error"),this.handleAuthError();else if(r===sp.err)vn.warn(sp.msg),this.emitMaxUsersError();else if(r===Bu.err){vn.warn(Bu.msg);try{this.emitRequestReloadError()}catch(i){vn.error(`error occurred while process reload error: ${JSON.stringify(i)}`)}finally{this.end(!1)}}else vn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return p(vn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(p(vn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onAuthError(t){this.events.addListener("error",t)}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){p(vn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){p(vn,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e;this.enabled=!1,this.reauthFunc=void 0,this.events.removeAllListeners(),nU(()=>{var r;return(r=this.connection)==null?void 0:r.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}I("utils/file");function iU(){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}iU();async function oU(n){const e=n.size,r=Math.floor((e+102400-1)/102400),i=new l6.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 ji(o)}const Ci=I("sharedb-doc/client"),sU=Wx.default.create();class lU{constructor(t,e,r){g(this,"connection");g(this,"auth");g(this,"doc",null);g(this,"reauthFunc");g(this,"clientId",J());g(this,"getDoc",async()=>{const t=r=>new Promise((i,o)=>{r.fetch(s=>{s?o(s):i()})});p(Ci,!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),Ci.debug(e),e});this.auth=t;const i=`${e}/${this.auth.appId}/${this.auth.docId}`;ZM.register(hd.type),this.connection=new rU(i,r),this.reauthFunc=r}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(Ci,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)}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`;let i=[];t.forEach(l=>{const c=l.split("|");i.push(...c)}),i=Array.from(new Set(i));const o=i.map(l=>this.getFileUrlByHash(r,l,"",0,{[ya]:this.connection.token}));return await Promise.all(o)}async uploadFile(t,e,r,i,o){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=x=>{Ci.info(`on progress: ${x.loaded}`);let v=x.loaded*100/s;v>100&&(v=100),i(v)},c=await oU(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 Ci.info(E),i(100),Array.isArray(E.data)?E.data[0]:E.data}async uploadResource(t,e=()=>{},r){const o=`${this.apiServer()}/resources`;p(Ci,this.connection.token,"no connection token");const s=await this.uploadFile(o,t,{[ya]:this.connection.token},e,r);return p(Ci,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(Ci,r,"no token"),c.headers={...c.headers,[ya]:r,[Tu]:this.connection.getBase64BaseURL()};try{return await sU(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(Ci,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=qx.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(Ci,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/${ji(t)}`;return(await this.request(r)).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&&o.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const s=o.join("&");i+=`?${s}`}return i}}function aU(){return{blocks:[{id:J(),type:"text",text:[]}],comments:{},meta:{}}}const lp=I("block-ids");class cU{constructor(){g(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(lp,s!==void 0,"old id is not exists"),this.ids.delete(o),this.ids.set(o+1,s)}}const r=J();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(lp,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=J(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class uU{constructor(){g(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new cU,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(lp,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class x2{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 ap=I("op-parse-handler");class fU{constructor(t,e){g(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 uU,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&&(ap.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)){ap.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 x2,r.set(d,h)),h.delete(l.key)}else p(ap,!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 x2,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 $e=I("op-parser");class b2{}class cp{constructor(t){g(this,"key");this.key=t}}function dU(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($e,s.id,"block id is required"),p($e,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 up(n,t,e,r){if(e==="upsert"&&dU(n,t,r))return;p($e,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($e,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),p($e,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($e,i.length===0,`invalid block ops.length !== 0, ${JSON.stringify(i)}`)}else if(Array.isArray(l)){p($e,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];p($e,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const d=l[1];if(c==="text"){if(p($e,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 cp(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 b2),e==="upsert"&&c.i&&r.onInsertBlock(n,o,c.i),i.shift()}else{p($e,typeof l=="string","data is not string"),p($e,l!=="text","data !== 'text'"),p($e,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 cp(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i),i.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof b2?r.onDeleteBlock(n,o):l instanceof cp?r.onDeleteBlockData(n,o,l.key):p($e,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function hU(n,t,e){$e.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function mU(n,t,e){const r=n[1],i=n[2];p($e,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),p($e,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?$e.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):$e.error(`unknown comment op, ${JSON.stringify(n)}`)}function fp(n,t,e){const r=n[0];if(Array.isArray(r)){r.forEach(s=>{fp(s,t,e)});return}const i=r;if(p($e,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){hU(n);return}if(i==="comments"){mU(n,t,e);return}const o=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{up(o,s,t,e)}):n.slice(1).forEach(s=>{up(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($e,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),up(o,n.slice(1),t,e)}function dp(n,t,e){const r=new fU(t,e);for(let i=0;i<2;i++){const o=i===0?"remove":"upsert",s=gt.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{fp(c,o,r)}):fp(s,o,r)}r.end()}const gU=I("sharedb-comments");function hp(n){const t=n.blocks;p(gU,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)}),gt.default(e)}function v2(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 mp(n,t){const e=Z_(t),{comments:r,meta:i,blocks:o,...s}=e,l={...n,blocks:o,...s},c=gt.default(l);return delete c.children,c}const oe=I("sharedb-doc/doc-container"),B2="ot-json1";hd.type.registerSubtype(J_.type),hd.type.name=B2,hd.type.invert=null;class yu extends ea{constructor(e,r,i=!0){super();g(this,"doc");g(this,"client");g(this,"localPresence");g(this,"remoteCaretHandler",new Q_);g(this,"batching",0);g(this,"status","clean");g(this,"disableLogout");g(this,"destroyed",!1);g(this,"handleNothingPending",()=>{this.setStatus("clean")});g(this,"handleCreate",()=>{this.handleReload("doc created")});g(this,"handleDel",()=>{});g(this,"handleReload",e=>{this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)})});g(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()});g(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});g(this,"insertObject",async(e,r,i)=>{const o=[e,r,{i}];return this.submitOp(o)});g(this,"deleteObject",async(e,r)=>{const i=[e,r,{r:!0}];return this.submitOp(i)});g(this,"replaceObject",async(e,r,i)=>{const o=[e,r,{r:!0,i}];return this.submitOp(o)});g(this,"updateObject",async(e,r,i)=>{const o=this.data()[e][r],s=[e,r];return Object.entries(i).forEach(([l,c])=>{if(!Pc.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)});g(this,"broadcastMessage",async e=>{const r={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(r)});g(this,"data",()=>this.doc.data);g(this,"submitOp",async e=>new Promise((r,i)=>{if(this.destroyed){oe.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},o=>{o?(oe.error(`invalid op, ${o.message}, ${JSON.stringify(e)}`),i(o),oe.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):r()}),this.doc.data||(oe.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));g(this,"createDoc",async e=>new Promise((r,i)=>{this.doc.create(e,B2,o=>{o?i(o):r()})}));g(this,"submitInsertChildContainers",async e=>{if(e.length===0)return Promise.resolve();const r=e.map(({containerId:i,blocks:o})=>[oo(i),{i:o}]);return this.submitOp([r])});g(this,"submitDeleteChildContainer",async e=>{const r=[oo(e),{r:!0}];return this.submitOp(r)});g(this,"submitInsertBlock",async(e,r,i)=>{const o=[oo(e),r,{i}];return this.submitOp(o)});g(this,"submitDeleteBlock",async(e,r)=>{const i=[oo(e),r,{r:!0}];return this.submitOp(i)});g(this,"submitUpdateBlockData",async(e,r,i)=>{if(i.delete.length===0&&Object.keys(i.insert).length===0)return Promise.resolve();const o=[oo(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)});g(this,"submitUpdateRichText",async(e,r,i)=>{const o=[oo(e),r,"text",{e:i,et:"rich-text"}];return this.submitOp(o)});g(this,"handleOp",(e,r,i)=>{if(this.destroyed){oe.warn("handleOp: destroyed");return}try{dp(e,this,!!r)}catch(o){throw oe.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(oe,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const r=new lU(e.auth,e.serverUrl,e.reauthFunc),i=await r.getDoc(),o=new yu(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||aU())}return await o.initPresence(),await o.subscribe(),o.initEvents(),o}catch(r){throw oe.error(r),oe.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.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(J()),e())})}})}subscribe(){return new Promise((e,r)=>{this.doc.subscribe(i=>{i?r(i):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return io(this.data())}getContainerBlocks(e){const r=this.data();p(oe,r,"no doc data");const i=r[oo(e)];return p(oe,i,`no container data: ${e}`),gt.default(i)}findContainerBlocks(e){const r=this.data();p(oe,r,"no doc data");const i=r[oo(e)];return i!=null?i:null}getBlockData(e,r){const i=this.data();p(oe,i,"no doc data");const o=i[oo(e)];p(oe,o,`no container data: ${e}`);const s=o[r];return p(oe,s,`no block data: ${r}`),gt.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(oe,o.text,"no block text");const s=gt.default(o.text);this.submitUpdateRichText(e,r,i);const l=dn.apply(s,i);return p(oe,l,"no block text"),l}localUpdateBlockData(e,r,i){const o=gt.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=>v2(r))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const r=this.data().comments[e];return hp(r)}localCreateComment(e,r){const i=mp(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=mp(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(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onDeleteBlock)==null?void 0:s.call(o,va(e),r,i)})}onInsertBlock(e,r,i,o){p(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,va(e),r,i,o)})}onUpdateBlockData(e,r,i,o){p(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,va(e),r,i,o)})}onUpdateBlockText(e,r,i,o){p(oe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,va(e),r,i,o)})}onDeleteContainer(e,r){p(oe,this.callbacks.length>0,"no callbacks"),p(oe,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,va(e),r)})}onCreateContainer(e,r,i){p(oe,this.callbacks.length>0,"no callbacks"),p(oe,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,va(e),r,i)})}onDeleteComment(e,r){p(oe,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(oe,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(oe,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)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}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 io(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return io(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:io(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:io(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){dp(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}I("remote-cursor");class T2{constructor(t){g(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});g(this,"broadcastCaretPos",Ke.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));g(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 y2=I("remote-cursor-decorator");class gp{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(y2,typeof s=="string","invalid path containerId"),p(y2,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),d=fn(r);return i.getSimpleCursors(c.id).forEach((C,E)=>{E>d&&(E=d);const x=C.map(R=>({id:J(),type:"remote-cursor",name:R.user.displayName,time:R.time,rainbowIndex:R.user.rainbowIndex})),v=o.get(E);v?v.push(...x):o.set(E,x)}),{insertions:o}}}const pp=I("sharedb-doc/share-db-server"),pU=Wx.default.create();class CU{constructor(t,e){g(this,"auth");g(this,"clientId",J());this.serverUrl=e,this.auth=t}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(pp,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 ji(this.getBaseURL())}async request(t,e){var o;const r=this.auth.token,i=e||{};i.url=t,i.headers||(i.headers={}),p(pp,r,"no token"),i.headers={...i.headers,[ya]:r,[Tu]:this.getBase64BaseURL()};try{return await pU(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=qx.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(pp,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}}I("sharedb-doc/share-db-server");class k2 extends ea{constructor(e){super();g(this,"remoteUsers",new mu);g(this,"client");this.options=e,this.client=new CU(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 io(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return io(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:io(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:io(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){dp(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}class R2 extends ye.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,r){if(Qt(ci(this.editor,t)))return;const i=this.editor.getBlockByIndex(t,e),o=nt(this.editor.getContainerById(t));o&&this.emit("change",this.editor,o,i,r)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}destroy(){this.editor.doc.unregisterCallback(this)}}function EU(n,t){n.addCustom("child-block-tracker",()=>new R2(n)).addListener("change",t)}function AU(n,t){n.addCustom("child-block-tracker",()=>new R2(n)).removeListener("change",t)}const Cst="",xU={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"}},bU={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},vU={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"}};D.mergeLang({"zh-CN":xU,"en-US":bU,"ja-JP":vU});const Est="";I("button");function Cr(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&&z(o,"checked"),r.indexOf("disabled")!==-1&&(o.disabled=!0),r.indexOf("primary")!==-1&&z(o,"primary")),o}const Ast="",Dh=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
28
28
|
<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"/>
|
|
29
29
|
</svg>
|
|
30
30
|
`,w2=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -606,7 +606,7 @@ Available method signatures are:
|
|
|
606
606
|
</clipPath>
|
|
607
607
|
</defs>
|
|
608
608
|
</svg>
|
|
609
|
-
`,KU=Object.freeze(Object.defineProperty({__proto__:null,ClearIcon:dT,CloseIcon:Dh,PrevIcon:w2,NextIcon:S2,MoreIcon:Cp,TextColorIcon:Ep,ArrowDownIcon:_h,ArrowUpIcon:BU,ArrowLeftIcon:TU,ArrowRightIcon:Ap,DeleteRowIcon:L2,DeleteColIcon:I2,MergeCellIcon:D2,SplitCellIcon:_2,DeleteTableIcon:M2,Heading1Icon:Mh,Heading2Icon:Uh,Heading3Icon:Oh,Heading4Icon:Nh,Heading5Icon:Ph,Heading6Icon:Fh,Heading7Icon:Kh,Heading8Icon:Vh,HeadingNIcon:yU,OrderedListIcon:U2,UnorderedListIcon:O2,CheckListIcon:N2,BlockquoteIcon:P2,AlignCenterIcon:Hh,AlignLeftIcon:ka,AlignRightIcon:$h,ImageIcon:F2,ImageMenuIcon:K2,ImageErrorIcon:bp,ImageEmptyIcon:$2,LinkIcon:yp,LinkOffIcon:H2,WarningIcon:xp,PasteSpecialIcon:V2,LaunchIcon:vp,CodeIcon:rT,AudioIcon:J2,GraphIcon:kU,VideoIcon:tT,FileIcon:RU,MathIcon:SU,MathMenuIcon:j2,TableIcon:LU,TableMenuIcon:z2,BilibiliIcon:W2,YoukuIcon:q2,ModaoIcon:Q2,FigmaIcon:X2,EditIcon:jh,CommentIcon:el,RefreshIcon:G2,HelpIcon:Bp,CheckMarkIcon:Tp,TextIcon:Ra,RightArrowIcon:wU,TencentVideoIcon:Y2,WebPageIcon:Z2,UmlIcon:eT,DividingLineIcon:nT,HeadingH1Icon:IU,HeadingH2Icon:DU,HeadingH3Icon:_U,HeadingH4Icon:MU,HeadingH5Icon:UU,HeadingH6Icon:OU,HeadingH7Icon:NU,HeadingH8Icon:PU,CheckboxIcon:kp,QuoteIcon:Rp,LinkHrefIcon:FU,OrderedIcon:Sp,UnorderedIcon:wp,CopyIcon:iT,CutIcon:oT,DeleteIcon:sT,LockBlockIcon:lT,UnLockBlockIcon:aT,InsertBeforeIcon:cT,InsertAfterIcon:uT,MentionIcon:fT,CircleAddIcon:hT,LoadingIcon:mT,DragIcon:Lp,UmlBrandIcon:zh,OnesLoadingIcon:gT,BoldIcon:pT,ItalicIcon:CT,UnderlineIcon:ET,LineThroughIcon:AT,SubscriptIcon:bT,SuperscriptIcon:vT,InlineCodeIcon:xT,ToMindMapIcon:BT,FitIcon:TT,FullScreenIcon:Ip,ExitFullScreenIcon:yT,CaretDownIcon:kT,StatusIcon:RT},Symbol.toStringTag,{value:"Module"}));function wT(){const n=B("span",["editor-loading-icon"],null);return n.innerHTML=gT,n}const xst="";function VU(n,t){const e=B("button",["editor-checkbox-wrapper"],null);e.setAttribute("data-button-id",n),t!=null&&t.includes("checked")&&z(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 bst="",wa=I("ui-command-bar-base"),$U={itemElementTag:"div",tippyArrow:!1},YE=class extends ye.TypedEmitter{constructor(e,r,i){var o,s;super();g(this,"content");g(this,"items");g(this,"subBar",null);g(this,"parentItem",null);g(this,"closeable",null);g(this,"closeReason",null);g(this,"options");g(this,"id");g(this,"header",null);g(this,"footer",null);g(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing&&!Hs(e.target)){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){this.close("cancelBar");return}if(e.key==="ArrowUp"){const r=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[r].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const r=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[r].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const r=this.getSelectedItem();r&&r.children&&this.showSubCommandBar(r.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const r=this.getSelectedItemIndex();if(r===-1)return;const i=this.items[r],o=this.getItemElementById(i.id);o&&this.emit("click",this,i,o)}}}});g(this,"handleDocumentMouseDown",e=>{if(e.target instanceof Element&&!this.isInCommandBar(e.target)){const r=this.listeners("closing");for(let i=0;i<r.length;i++)if(r[i](this,e)===!1)return;this.close("clickBackground")}});g(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),Lb(this.id)});g(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&z(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&Sb(this.id)});g(this,"lastEnterPauseTime",0);g(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});g(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)});g(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)&&(ot(r,"selected"),this.emit("selectionChange",this,""))});g(this,"handleItemClick",e=>{const r=this.getParentCommandItemElement(e.target);if(!r)return;const i=this.getItemElementId(r),o=this.items.find(s=>s.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}o.element||(this.emit("click",this,o,r),this.options.autoClose&&this.close("clickItem"))}});g(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=cn(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:J(),this.options={...$U,...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&&ot(r,"selected")}selectItem(e){const r=this.getSelectedItem();if(r){if(r.id===e)return;const o=r.id,s=this.getItemElementById(o);s&&ot(s,"selected")}const i=this.getItemElementById(e);i?(z(i,"selected"),this.emit("selectionChange",this,i.getAttribute("data-id")||""),this.options.disableSelectedScroll||i.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const r=this.getSelectedItem();if(!r)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.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=YE.createSubCommandBar(r,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=o,this.subBar.on("click",(c,d,h)=>{this.emit("click",c,d,h)}),this.subBar.on("close",()=>{var c;(c=this.subBar)==null||c.destroy(),this.subBar=null,ot(i,"active")}),r.beforePopup&&r.beforePopup(o),this.subBar.manualShow(i,this.getSubBarOptions(r)),z(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(wa,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(wa,i,`can not find command item for id: ${r}`),i}return null}getItemElementId(e){const r=e.getAttribute("data-id");return p(wa,r,"no data-id attribute"),r}getItemElementById(e){const r=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return p(wa,r,`no exists command item, id=${e}`),r}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(Rt(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)&&z(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(wa,e.children&&e.children.length>0,"no item children");const o=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(o);return p(wa,s,`no creator for command type: ${o}`),s(e,r,i)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let nl=YE;g(nl,"commandBarCreators",new Map),I("ui-command-bar");class Gh extends nl{constructor(){super(...arguments);g(this,"tippyInstance",null)}manualShow(e,r){var i,o,s;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=a6.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 ST=I("ui-base");class Sa extends Gh{constructor(t,e){var o;const i=[{id:(o=e==null?void 0:e.id)!=null?o:`popup-${J()}`,name:"",element:t}];super(i,void 0,{disablePageScroll:!0,id:e==null?void 0:e.id})}initCommandBarElement(t){z(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];p(ST,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return p(ST,e,"no item element"),e}}const ao=I("filterable-list");function LT(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")&&(z(t,"selected"),Ls(Tp,["list-item-selected-icon"],t)),(r=n.states)!=null&&r.includes("disabled")&&z(t,"disabled"),t}function IT(n){const t=B("div",["list-root"],null);return n.forEach(e=>{t.appendChild(LT(e))}),n.length||t.appendChild(LT({id:"placeholder",states:["disabled"],name:D.t("search.emptyTips")})),t}function DT(n,t){let e=n,r=null;return t&&(e=n.filter(i=>i.id===t?(r={...i,states:["selected"]},!1):{...i,states:void 0})),r?[...e,r]:[...e]}function HU(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=IT(DT(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function _T(n,t,e){const r=n.querySelector(".list");p(ao,r,"no list root");const i=IT(DT(t,e)),o=r.querySelector(".list-root");if(p(ao,o,"no exists menu"),jc(o,i),e){const s=r.querySelector(".list-item.selected");s&&(p(ao,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class jU{constructor(t,e){g(this,"root");g(this,"visibleItems");g(this,"selectedId");g(this,"filter","");g(this,"onSelected",null);g(this,"handleKeydown",t=>{this.processKeyDown(t)});g(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");p(ao,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});g(this,"handleClick",t=>{this.processClick(t)});var r;this.items=t,this.options=e,this.root=HU(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(ao,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(ao,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,_T(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");p(ao,t,"no input"),t.focus()}moveSelectedItemIntoView(){const t=this.root.querySelector(".list-item.selected");t&&(p(ao,t,"no selected menu item"),t.scrollIntoView({block:"nearest"}))}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");p(ao,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),_T(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 zU extends jU{constructor(e,r,i){super(e,i);g(this,"popup");g(this,"onShow",null);g(this,"onHide",null);g(this,"custom",null);g(this,"handleShow",()=>{this.onShow&&this.onShow(this)});g(this,"handleHide",()=>{this.onHide&&this.onHide(this)});g(this,"handleShown",()=>{this.focus()});this.popup=new Sa(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 vst="",Bst="";function GU(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 WU(n,t){var e,r;if(z(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-maxwidth","800"),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=Ap,t.appendChild(o)}if((r=n.states)!=null&&r.includes("checked")){const o=B("div",["menu-item-checked-icon"],null);o.innerHTML=Tp,t.appendChild(o)}}}}class rl extends Gh{constructor(t,e,r){super(t,e,{autoClose:!0,disablePageScroll:!0,...r})}manualShow(t,e){const r={theme:"menu",...e};super.manualShow(t,r)}initCommandBarElement(t){z(t,"menu")}initItemElement(t,e){WU(t,e)}}function qU(n,t,e){var r;return new rl((r=n.children)!=null?r:[],t,{...e,parentItem:n})}function MT(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=_h}n.states&&(n.states.indexOf("checked")!==-1&&z(r,"checked"),n.states.indexOf("disabled")!==-1&&(r.disabled=!0))}class ku extends Gh{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){z(t,"toolbar")}initItemElement(t,e){MT(t,e,this.options)}}function XU(n,t,e){var r;return new ku((r=n.children)!=null?r:[],t,{...e,parentItem:n})}class QU extends nl{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){z(t,"toolbar","fixed")}initItemElement(t,e){MT(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 Tst="";nl.registerManualCommandBar("menu",qU),nl.registerManualCommandBar("toolbar",XU);const yst="",UT=I("ui-base");class Ru extends Gh{constructor(e,r){super(Ru.getCommandItems(e,r),void 0,{disablePageScroll:!0,...r});g(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){z(e,"dialog","manual")}initItemElement(e,r){}show(e,r){this.manualShow(e,{...r,theme:"light"})}get dialogContent(){const e=this.items[0];p(UT,e,"no dialog item");const r=e.element;return p(UT,r,"no item element"),r}static getCommandItems(e,r){var s;return[{id:(s=r==null?void 0:r.id)!=null?s:`manual-dialog-${J()}`,name:"",element:e}]}}const kst="",YU=I("ui-base");class OT{constructor(t){g(this,"menu");g(this,"currentText","");g(this,"handleSearchText");g(this,"handleClick",Ke.default((t,e)=>{this.options.onClickItem(this,e)},300,{leading:!0,trailing:!1}));g(this,"handleShow",t=>{});g(this,"handleClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});g(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.options=t,this.menu=new rl([],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=Ke.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)}}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||D.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()}async handleSearchTextPure(t){this.currentText=t;const e="auto-suggest";try{await Sr.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{Sr.release(e)}}highlightText(t,e){YU.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 x=s.charAt(C);let v=!1;E.endsWith(" ")&&(v=!0,E=E.trimEnd()),c+=`<span class="highlight">${E}${x===" "||v?" ":""}</span>`}else c+=s.charAt(C),C++}return C<s.length&&(c+=s.substring(C)),c},o=s=>{if(Rt(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 Dp{constructor(t,e){g(this,"root");g(this,"input");g(this,"text");g(this,"dropdownIcon");g(this,"clearIcon");g(this,"autoSuggest");g(this,"labels");g(this,"items",[]);g(this,"handleClick",()=>{this.autoSuggest.popup(this.root),this.input.focus()});g(this,"handleClickItem",(t,e)=>{var r,i;(i=(r=this.options)==null?void 0:r.onClickItem)==null||i.call(r,e)});g(this,"handleInput",()=>{this.autoSuggest.handleSearchText(this.input.value),this.updatePlaceholder()});g(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)});g(this,"handleQueryItems",async(t,e)=>this.items.filter(i=>{var o;return(o=this.options)!=null&&o.filter?this.options.filter(i,e):!0}));g(this,"handleShow",()=>{z(this.root,"active"),this.input.focus()});g(this,"handleClose",()=>{var t,e;(e=(t=this.options)==null?void 0:t.onClose)==null||e.call(t),ot(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}=Dp.createDropdown(t,this.labels);this.root=r,this.input=i,this.text=o,this.clearIcon=s,this.dropdownIcon=l,this.autoSuggest=new OT({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=dT;const c=B("div",["dropdown-icon"],r);return c.innerHTML=_h,{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),z(this.root,"empty")}else ot(this.root,"empty")}}const ZU=[-1,6,0,1,2,3,4,5],JU=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],NT=I("color-palette");function PT(n,t,e,r){p(NT,n>0,"no color in palette");const i=t||1;p(NT,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 tO(n){const t=B("button",["color-button"],null),e=ZU[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=Ep,t}function eO(n){const t=B("button",["background-color-button"],null),e=JU[n];return t.setAttribute("data-color-index",`${e}`),t}function nO(){const n=B("div",["clear-button-container"],null),t=B("button",["clear-button"],n);return t.innerText=D.t("colorPalette.reset"),n}function rO(n){const t=B("div",["color-palette"],null);return n.color!==!1&&(B("div",["bar-desc"],t,D.t("colorPalette.colorDesc")),t.appendChild(PT(8,1,tO,"color"))),n.backgroundColor!==!1&&(B("div",["bar-desc"],t,D.t("colorPalette.backgroundDesc")),t.appendChild(PT(16,2,eO,"background-color"))),n.clearColorButton!==!1&&t.appendChild(nO()),t}function iO(n,t,e){const r=t==="color"?"color":"background-color",i=n.querySelector(`.${r} button.selected`);i&&ot(i,"selected"),e===null&&(e=-1);const o=n.querySelector(`.${r} button[data-color-index="${e}"]`);o&&z(o,"selected")}const Rst="",oO={};class sO extends ye.TypedEmitter{constructor(e=oO){super();g(this,"root");g(this,"handleClick",e=>{const r=e.target;if(!r||!(r instanceof Element))return;const i=r.closest("button");if(!i)return;if(Rt(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)||(Rt(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=rO(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,r){iO(this.root,e,r)}}class FT{constructor(t,e){g(this,"name","Color Palette");g(this,"element");g(this,"palette");g(this,"closeable",null);this.id=t,this.palette=new sO(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function lO(){const n=B("button",["color-button"],null);return n.innerHTML=Ep,n}function _p(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 KT extends ye.TypedEmitter{constructor(e){super();g(this,"id","text-color-item");g(this,"name",D.t("colorPalette.name"));g(this,"dropdown",!0);g(this,"manualShowChildren",!0);g(this,"children",[]);g(this,"element");g(this,"colorPaletteItem");g(this,"latestColors",[null,null]);g(this,"handlePaletteClick",(e,r)=>{this.emit("onClick",e,r)});g(this,"setLatestColors",(e,r)=>{e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=r:this.latestColors[1]=r:this.latestColors=[null,null],_p(this.element,this.latestColors)});g(this,"beforePopup",()=>{this.updatePaletteColor(this.latestColors),this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new FT("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=lO()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,_p(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,_p(this.element,this.latestColors)}}const wst="";function Wh(n,t){const e=B("div",["editor-input-wrap"],n);if(t!=null&&t.className&&z(e,t==null?void 0:t.className),t.label){const s=B("div",["editor-input-label"],e);B("span",[],s,t.label),t.required&&z(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),ot(e,"error")}),i.addEventListener("keydown",s=>{var l;(l=t.onKeyDown)==null||l.call(t,s)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:s=>{z(e,"error"),o.innerText=s},focus:()=>{setTimeout(()=>{i.focus()})}}}function Mp(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 aO extends OT{constructor(e,r){super(r);g(this,"handleClose",()=>{var e,r;Mp(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)||dt(this.editor,o)<i)return;const s=qi(this.editor,o,ve(this.editor,o,i));if(s.length===0)return;const l=s[0],c=Yi(this.editor,o,"editor-auto-suggest-menu",l);super.popup(c,{noEvent:!0})}}const Up=I("auto-suggest-menu");class Op{constructor(t,e){g(this,"order",100);g(this,"menu");g(this,"anchor",null);g(this,"close",()=>{this.menu.close()});g(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(ce(In(bn(t,o),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});g(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=ce(nh(t,o,i));if(p(Up,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});g(this,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});g(this,"onShow",(t,e,r,i)=>{var o;if((o=this.options)!=null&&o.onShow)return this.options.onShow(this,e,r,i)});g(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});g(this,"queryItems",(t,e)=>this.options.queryItems(this,e));g(this,"renderMenuItem",(t,e)=>{var i,o;return(o=(i=this.options).renderMenuItem)==null?void 0:o.call(i,this,e)});g(this,"hasExistsMenuThemeCommandBar",()=>!!document.querySelector('div.tippy-box[data-theme="menu"]'));this.editor=t,this.options=e,this.menu=new aO(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)||Ag(e.key)?!1:kb(e)&&!Us(e)?(setTimeout(()=>{this.resetItems()}),!1):xg(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,r,i){this.anchor={blockId:st(t),offset:e,leftText:r,trigger:i};const o=ft(it(t)),s=bt(t);this.menu.popupInEditor(o,s,e)}handleAfterInsertText(t,e,r,i,o){var h,C;const s=t.selection.range.start;if(!s.isSimple())return!1;const l=t.getBlockByIndex(e,r);if(Gi(l))return!1;const{blockId:c,offset:d}=s;if(st(l)!==c)return!1;if((h=this.menu)!=null&&h.isVisible)this.resetItems();else if(this.options.trigger.indexOf(o)!==-1){if(i>0&&this.options.needSpaceBeforeTrigger&&(((C=t.getBlockData(l).text)==null?void 0:C.reduce((R,L)=>R+L.insert,""))||"")[i-1]!==" "||this.hasExistsMenuThemeCommandBar())return!1;const E=ce(nh(t,l,d));this.popup(l,d,E,o)}return!1}handleUpdateCompositionText(t,e,r,i,o){var d;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,r);return st(c)!==l||(d=this.menu)!=null&&d.isVisible&&this.resetItems(),!1}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=ce(nh(t,o,i));if(p(Up,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);Up.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 cO(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const uO={"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"},...cO()};function Bn(n){var t;return(t=uO[n])==null?void 0:t.shortcut}function fO(n){var t;return(t=n.subText)!=null?t:""}const Ei=I("table-dom");function Ai(n){return`${st(n)}_scroll`}function Me(n){const t=n.querySelector("div[data-type=table-content] >table");return p(Ei,t instanceof HTMLTableElement,"invalid table"),t}function xi(n,t){const r=n.getCustom(Ai(t)).contentElement.firstElementChild;p(Ei,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(Ei,i,"no table tools"),i}function dO(n,t){return n.findCustom(Ai(t))?xi(n,t):null}function VT(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function wu(n){const t=n.querySelector(":scope div[data-type=editor-container]");return p(Ei,t,"no child container in cell"),t}function hO(n){const r=VT(n).map(i=>{const o=wu(i),s=ft(o),l=i.colSpan,c=i.rowSpan;return`${s}/${l}/${c}`}).join();return md.default(r)}function He(n){return It(n)==="table"}function Np(n){const t=it(n);if(Qt(t))return null;const e=nt(t);return p(Ei,e,"no parent block"),He(e)?t:Np(e)}function co(n){if(He(n))return n;const t=it(n);if(Qt(t))return null;const e=nt(t);return p(Ei,e,"no parent block"),He(e)?e:co(e)}function mO(n,t){const e=n.querySelector("colgroup");p(Ei,e,"no colgroup");const r=e.children[t];return p(Ei,r,"no col"),p(Ei,r instanceof HTMLTableColElement,`invalid col: ${r.tagName}`),r}function $T(n){try{return Me(n),!0}catch{return!1}}function gO(n){return ne(n).querySelector(":scope > .block-helper")}function HT(n){const t=nt(n.contentElement);p(Ei,t,"no block");const e=gO(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`}}const zr=I("doc-table-grid");class pO{constructor(t){g(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){p(zr,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){p(zr,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return p(zr,e,"get cell, no cell"),e}getCellAllowEmpty(t){return p(zr,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 qh{constructor(t){g(this,"_data");g(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new pO(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(zr,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(zr,o===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(i=>{i.forEach(o=>{p(zr,o,"no cell"),p(zr,o.containerId,"no containerId")})})}getCell(t){const{col:e,row:r}=t,i=this._rows[r];p(zr,i,`get cell, no row: ${r}`);const o=i.getCell(e);return p(zr,o,`get cell, no cell: ${e}`),o}getRow(t){const e=this._rows[t];return p(zr,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Xh=I("table-data");function CO(n){const t=n.firstElementChild;return p(Xh,t,"no child element for cell"),p(Xh,Wi(t),"cell first child is not a container"),p(Xh,Mr(t),"cell first child is not a container"),t}function EO(n){const t=nt(n);p(Xh,t,"no parent block for table");const e=[],r={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const d=CO(c),h=ft(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:st(t),type:It(t),rows:i,cols:o,children:e,colsWidth:Array(o).fill(100),...r}}function il(n){return new qh(n)}function AO(n){return il(EO(n))}const Xe=I("table-grid"),xO=60;class bO{constructor(t,e){g(this,"containerId");g(this,"row");g(this,"col");g(this,"colSpan");g(this,"rowSpan");g(this,"virtual");g(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(Xe,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);p(Xe,t.length===1,"containers !== 1"),p(Xe,Wi(t[0]),"not a container");const e=t[0];return p(Xe,Mr(e),"not a child container"),e}}class vO{constructor(t,e){g(this,"_cells",[]);e.forEach(r=>{this._cells.push(new bO(t,r))})}get cells(){return this._cells}getCell(t){return p(Xe,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 ZE=class{constructor(t){g(this,"_rows",[]);this.table=t,AO(t).forEach(i=>{this._rows.push(new vO(t,i))});const r=this.colCount;this._rows.forEach(i=>{p(Xe,i.cells.length===r,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(p(Xe,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(Xe,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(Xe,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(Xe,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(Xe,!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(Xe,r<=i,"min > max"),p(Xe,r>=0,"min < 0"),p(Xe,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(Xe,r<=i,"min > max"),p(Xe,r>=0,"min < 0"),p(Xe,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 x=r;x<=i;x++)for(let v=o;v<=s;v++)l.push(this.getCell({row:x,col:v}));const c=this.toRealCells(l);let d=1e4,h=1e4,C=-1,E=-1;return c.forEach(x=>{h=Math.min(x.col,h),d=Math.min(x.row,d),E=Math.max(x.col+x.colSpan-1,E),C=Math.max(x.row+x.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 x=this.getCell({row:C,col:E});x.virtual||r.push(x)}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)}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(Xe,r,"cell not found"),r}getCellByCellElement(t){const e=wu(t);return this.getCellByContainerId(ft(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=hO(t),r=this.caches.getSync(e,()=>(Xe.debug("create table grid"),new ZE(t)));return r.table!==t?(this.caches.delete(e),this.fromTable(t)):r}static fromBlock(t){return this.fromTable(Me(t))}};let Lt=ZE;g(Lt,"caches",new lb(xO));function Qh(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const BO=I("table-selection-range");function Gr(n,t,e){var U,F,G,q;const r=Lt.fromBlock(n),i=t,o=e,s=r.getCellByContainerId(i.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=i.custom,d=o.custom,h=(U=c==null?void 0:c.rowIndex)!=null?U:s.row,C=(F=c==null?void 0:c.colIndex)!=null?F:s.col,E=(G=d==null?void 0:d.rowIndex)!=null?G:l.row+l.rowSpan-1,x=(q=d==null?void 0:d.colIndex)!=null?q:l.col+l.colSpan-1,v=Math.min(h,E),R=Math.max(h,E),L=Math.min(C,x),M=Math.max(C,x);return{fromRow:v,toRow:R,fromCol:L,toCol:M}}function Pp(n,t){const e=new Set,r=new Set,i=n.selection.range;if(!i.isSimple()&&i.start.blockId===st(t)){const o=Lt.fromBlock(t),{start:s,end:l}=i;p(BO,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:d,fromRow:h,toRow:C}=Gr(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 Su(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const r=n.getBlockById(t.start.blockId);if(He(r)){const i=it(r),o=nt(i);o&&(e=co(o))}else e=co(r)}else{const r=n.getBlockById(t.start.blockId),i=co(r),o=n.getBlockById(t.end.blockId),s=co(o);i===s&&(e=i)}return e}const La=I("delete-columns");function jT(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{fromRow:s,toRow:l}=Gr(t,e.start,e.end),c=Lt.fromBlock(t);return s===0&&l===c.rowCount-1}function Fp(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var F,G;const e=t.getBlockById(n.start.blockId);if(!jT(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:r,toCol:i}=Gr(e,n.start,n.end),o=Lt.fromBlock(e);if(r===0&&i===o.colCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(q=>q.containerId);for(let q=0;q<l.length;q++){const rt=l[q];for(let at=r;at<=i;at++){const At=rt[at];s.add(At)}rt.splice(r,i-r+1)}const c=new Set(l.flat()),d=new Set(Array.from(s).filter(q=>!c.has(q))),h=i-r+1,C=new Map,E=new Map;s.forEach(q=>{if(d.has(q))return;const rt=o.getCellByContainerId(q);if(p(La,rt.colSpan>1,"invalid effected cell, colSpan === 1"),rt.col<r){p(La,c.has(q),"invalid effected cell, not exists");let ue=rt.col+rt.colSpan-1;ue>i&&(ue=i);const nr=ue-r+1,Se=rt.colSpan-nr;C.set(q,Se);return}p(La,rt.col<=i,"invalid effected cell, col > endCol");const at=rt.col,At=rt.col+rt.colSpan-1,Mt=rt.col-r,kt=At-at+1-h+Mt;p(La,kt>0,"invalid effected cell, newSpanned <= 0");const se=no(t.doc);E.set(q,{newContainerId:se,colSpan:kt})});for(let q=0;q<l.length;q++){const rt=l[q];for(let at=r;at<rt.length;at++){const At=rt[at],Mt=E.get(At);Mt&&(rt[at]=Mt.newContainerId)}}const x=gt.default(t.getBlockData(e));((F=x.colsWidth)!=null?F:new Array(x.cols).fill(0)).splice(r,i-r+1),d.forEach(q=>{Qh(x,q)}),C.forEach((q,rt)=>{p(La,q>=1,"invalid modified colSpan, colSpan < 1"),q===1?x[`${rt}_colSpan`]=void 0:x[`${rt}_colSpan`]=q}),E.forEach((q,rt)=>{Qh(x,rt);const{newContainerId:at,colSpan:At}=q;p(La,At>=1,"invalid newContainerData, colSpan < 1"),At>1&&(x[`${at}_colSpan`]=At);const Mt=o.getCellByContainerId(rt).rowSpan;Mt>1&&(x[`${at}_rowSpan`]=Mt)});const R=(G=l[0][r])!=null?G:l[0][r-1],L=t.getChildContainerData(R)[0],M=Lt.virtualCellContainersGridToChildren(l),U={...x,cols:x.cols-h,children:M};il(U),t.updateBlockData(e,U,ve(t,L.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const Ia=I("delete-rows");function zT(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{fromCol:s,toCol:l}=Gr(t,e.start,e.end),c=Lt.fromBlock(t);return s===0&&l===c.colCount-1}function Kp(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!zT(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:r,toRow:i}=Gr(e,n.start,n.end),o=Lt.fromBlock(e);if(r===0&&i===o.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(U=>U.containerId);for(let U=i;U>=r;U--)l[U].forEach(G=>s.add(G)),l.splice(U,1);const c=new Set(l.flat()),d=new Set(Array.from(s).filter(U=>!c.has(U))),h=i-r+1,C=new Map,E=new Map;s.forEach(U=>{if(d.has(U))return;const F=o.getCellByContainerId(U);if(p(Ia,F.rowSpan>1,"invalid effected cell, rowSpan === 1"),F.row<r){p(Ia,c.has(U),"invalid effected cell, not exists");let Mt=F.row+F.rowSpan-1;Mt>i&&(Mt=i);const kt=Mt-r+1,se=F.rowSpan-kt;C.set(U,se);return}p(Ia,F.row<=i,"invalid effected cell, col > endCol");const G=F.row,q=F.row+F.rowSpan-1,rt=F.row-r,at=q-G+1-h+rt;p(Ia,at>0,"invalid effected cell, newSpanned <= 0");const At=no(t.doc);E.set(U,{newContainerId:At,rowSpan:at})});for(let U=r;U<l.length;U++){const F=l[U];for(let G=0;G<F.length;G++){const q=F[G],rt=E.get(q);rt&&(F[G]=rt.newContainerId)}}const x=gt.default(t.getBlockData(e));d.forEach(U=>{Qh(x,U)}),C.forEach((U,F)=>{p(Ia,U>=1,"invalid modified rowSpan, rowSpan < 1"),U===1?x[`${F}_rowSpan`]=void 0:x[`${F}_rowSpan`]=U}),E.forEach((U,F)=>{Qh(x,F);const{newContainerId:G,rowSpan:q}=U;p(Ia,q>=1,"invalid newContainerData, rowSpan < 1"),q>1&&(x[`${G}_rowSpan`]=q);const rt=o.getCellByContainerId(F).colSpan;rt>1&&(x[`${G}_colSpan`]=rt)});const v=l[r]?l[r][0]:l[r-1][0],R=t.getChildContainerData(v)[0],L=Lt.virtualCellContainersGridToChildren(l),M={...x,rows:x.rows-h,children:L};il(M),t.updateBlockData(e,M,ve(t,R.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const Lu=I("table-range");function Yh(n){p(Lu,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;p(Lu,!t.isSimple(),"invalid start pos type"),p(Lu,!e.isSimple(),"invalid end pos type");const r=n.getEditor();p(Lu,t.blockId===e.blockId,"invalid range, not same block");const i=r.getBlockById(t.blockId);p(Lu,It(i)==="table","invalid block type, not a table block");const o=Me(i),s=Lt.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),x=s.getCell({row:d,col:C}),v=s.getCell({row:h,col:E});return{editor:r,block:i,table:o,startCell:x,endCell:v,startRow:d,startCol:C,endRow:h,endCol:E}}const Vp=I("split-cell");function $p(n,t,e){n.undoManager.runInGroup(()=>{const r=Lt.fromBlock(t),i=r.getRealCell(e);p(Vp,!i.virtual,"should not split virtual cell"),p(Vp,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 x=C+i.row,v=E+i.col,R=no(n.doc);o[x][v]=R}const s=n.getBlockData(t),l=gt.default(s);l[`${i.containerId}_colSpan`]=null,l[`${i.containerId}_rowSpan`]=null,l.children=Lt.virtualCellContainersGridToChildren(o);const d=n.getChildContainerData(i.containerId)[0];p(Vp,d,"no child block");const h=ve(n,d.id,0);il(l),n.updateBlockData(t,l,h)})}function TO(n,t,e){e.forEach(r=>{const i=Lt.fromBlock(t).getCell(r);(i.virtual||i.colSpan>1||i.rowSpan>1)&&$p(n,t,r)})}function GT(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{startCell:s,endCell:l}=Yh(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function Hp(n){const{editor:t,block:e,startRow:r,startCol:i,endRow:o,endCol:s}=Yh(n),l=[];for(let c=r;c<=o;c++)for(let d=i;d<=s;d++)l.push({row:c,col:d});return TO(t,e,l),!0}const Da=I("merge-cells");function WT(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{startCell:s,endCell:l}=Yh(e);return s.cell!==l.cell}function qT(n){const t=Yh(n),e=t.editor;e.undoManager.runInGroup(()=>{const r=t.endCell,i=r.row+r.rowSpan-1,o=r.col+r.colSpan-1,s=st(t.block);Hp(n);const l=e.getBlockById(s),c=Me(l),{startRow:d,startCol:h}=t,C=gt.default(e.getBlockData(l));p(Da,C.children,"no table children");const E=Lt.fromTable(c),x=[];for(let Mt=d;Mt<=i;Mt++)for(let kt=h;kt<=o;kt++){const se=E.getCell({row:Mt,col:kt});p(Da,!se.virtual,"cell is virtual"),x.push(se)}p(Da,x.length>0,"no selected cells");const v=x[0],R=x.slice(1),L=E.getCellByContainerId(v.containerId).container,M=[];R.forEach(Mt=>{const kt=E.getCellByContainerId(Mt.containerId).container,se=ft(kt);if(!Jc(e,kt)){const ue=gB(e,se);if(Jc(e,L)){const nr=Ce(L)[0];e.insertDocAt(L,0,ue),e.deleteBlock(nr)}else e.insertDocAt(L,Lr(L),ue)}M.push(se)});const U=ft(L),F=o-h+1,G=i-d+1;C[`${U}_colSpan`]=F,C[`${U}_rowSpan`]=G,M.forEach(Mt=>{p(Da,C.children,"no table children");const kt=C.children.indexOf(Mt);p(Da,kt>0,"no deleted container"),C.children.splice(kt,1)});const q=C,at=e.getChildContainerData(U)[0];p(Da,at,"no child block");const At=ve(e,at.id,0);il(q),e.updateBlockData(l,q,At),e.deleteChildContainers(M)})}const jp=10,yO=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Zh{constructor(){g(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,r){if(It(e)!=="table")return[];const i={blockId:st(e),blockKind:Ir(t,e),blockType:It(e)},o=[];WT(t,e,r)&&o.push({id:"table/merge-cells",name:D.t("table.mergeCell"),icon:D2,groupIndex:jp,...i}),GT(t,e,r)&&o.push({id:"table/split-cell",name:D.t("table.splitCell"),icon:_2,groupIndex:jp,...i});const s=jT(t,e,r),l=zT(t,e,r);return s&&l&&o.push({id:"table/delete",name:D.t("table.deleteTable"),icon:M2,groupIndex:jp,...i}),o}executeCommand(t,e,r,i,o,s){return It(e)!=="table"||!new Set(yO).has(i.id)?!1:i.id==="table/merge-cells"?(qT(r),!0):i.id==="table/split-cell"?(Hp(r),!0):i.id==="table/delete-columns"?(Fp(r),!0):i.id==="table/delete-rows"?(Kp(r),!0):i.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var XT=(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))(XT||{});const _a=6,Iu=20,zp="table-cell-menu-btn";function kO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,r)}function RO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,r)}function wO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,r)}function SO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,r)}function LO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,r)}function IO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,r)}function DO(n,t,e){if(!n.isBlockWritable(t))return;const i={...gt.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,i)}const ol=I("table-cell-dom");function _O(n,t,e){let r=n.getBlockById(e);for(;r;){const i=r.closest("td");p(ol,i,"no parent cell");const o=nt(i);if(p(ol,o,"no parent block"),o===t)return i;r=o}return p(ol,!1,"filed to get cell by child block id"),null}function Qo(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return p(ol,e.childContainerId,"block position must have childContainerId attribute"),e;const i=_O(n,t,e.blockId),o=ft(wu(i));return Ee(t,o)}function Gp(n,t){const e=n.selection.range,r=Qo(n,t,e.start),i=Qo(n,t,e.end);return Gr(t,r,i)}function QT(n,t,e,r){p(ol,He(t),"invalid table block");const i=xi(n,t),o=ne(t),s=()=>{const c=i.querySelector(".table-border-bar-container.top");p(ol,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)?z(h,"danger"):ot(h,"danger")})},l=()=>{const c=o.querySelector(".table-border-bar-container.left");p(ol,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)?z(h,"danger"):ot(h,"danger")})};s(),l()}function Yo(n,t,e=!0,r){const o=Lt.fromBlock(t).map(h=>h),{fromCol:s,toCol:l,fromRow:c,toRow:d}=Gp(n,t);for(let h=0;h<o.length;h++){const C=o[h];for(let E=0;E<C.length;E++){const x=C[E],v=r?E>=s&&E+x.colSpan-1<=l:h>=c&&h+x.rowSpan-1<=d;e&&v?x.virtual||z(x.cell,"danger"):x.virtual||ot(x.cell,"danger")}}}function Zo(n,t,e=!0,r){const i=new Set,o=new Set;if(!e){QT(n,t,Array.from(i),Array.from(o));return}const{fromCol:s,toCol:l,fromRow:c,toRow:d}=Gp(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);QT(n,t,Array.from(i),Array.from(o))}function YT(n,t,e){const{fromCol:r,toCol:i,fromRow:o,toRow:s}=Gp(n,t),l=Lt.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}),We(n,{anchor:Ee(t,c.containerId,{colIndex:r,rowIndex:0}),focus:Ee(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}),We(n,{anchor:Ee(t,c.containerId,{colIndex:0,rowIndex:o}),focus:Ee(t,d.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}const ZT=["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 JT(n){return`style-bg-color-${n}`}function Du(n){return`${n}_background`}function MO(n,t,e){const r=Me(n),s=(e!=null?e:Lt.fromTable(r)).getCell(t).cell;for(let l=0;l<ZT.length;l++){const c=ZT[l];if(Rt(s,c))return c}}function ty(n,t,e){if(!n.isBlockWritable(t))return;const r=n.selection.range,o={...gt.default(n.getBlockData(t))},s=Qo(n,t,r.start),l=Qo(n,t,r.end);if(r.isSimple()){const c=s.childContainerId;e===-1?o[Du(c)]=void 0:o[Du(c)]=JT(e)}else{const c=Lt.fromBlock(t),d=Gr(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 x=c.getCell({row:C,col:E});!h.has(x.containerId)&&x.col>=d.fromCol&&x.row>=d.fromRow&&x.col+x.colSpan-1<=d.toCol&&x.row+x.rowSpan-1<=d.toRow&&(h.add(x.containerId),e===-1?o[Du(x.containerId)]=void 0:o[Du(x.containerId)]=JT(e))}}n.updateBlockData(t,o)}function UO(n,t,e){if(!n.isBlockWritable(t))return;const i={...gt.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,i)}const ey=I("table-chart");function OO(n,t){const e=dO(n,t);if(e){const r=e.querySelector(".editor-table-chart");if(r){const i=r.chartObject;i&&i.destroy(),r.remove()}}}async function NO(n,t){if(!n.contains(t)||!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){OO(n,t);return}const i=[],o=Lt.fromBlock(t),s=["line","bar","pie","radar"];let l=o.getCell({row:0,col:0}).container.innerText.trim().toLowerCase();new Set(s).has(l)||(l=s[0]);const c=[];for(let R=1;R<o.colCount;R++)c.push(o.getCell({row:0,col:R}).container.innerText);for(let R=1;R<o.rowCount;R++){const L=o.getCell({row:R,col:0}),U=L.container.innerText,F=[];for(let ue=1;ue<o.colCount;ue++){const nr=o.getCell({row:R,col:ue}).container.innerText,Se=Number.parseFloat(nr)||0;F.push(Se)}let G;const q=MO(t,L,o);q?G=window.getComputedStyle(n.rootElement).getPropertyValue(`--${q}`).trim():G=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[rt,at,At,Mt]=G?og.fromString(G).toRgbaArray():[];if(!rt&&!at&&!At&&!Mt){const ue=(R-1)%n.options.colors.length;G=n.options.colors[ue],[rt,at,At,Mt]=og.fromString(G).toRgbaArray()}const kt=G,se=og.fromRgba([rt,at,At,Mt/3]).toHexString();i.push({label:U,data:F,borderColor:kt,backgroundColor:se,borderWidth:2})}const d=xi(n,t);let h=null,C=d.querySelector(".editor-table-chart");C?h=C.chartObject:C=B("div",["editor-table-chart"],d);const E=C;p(ey,E,"no chart container");const x=n.getComponentOptions("table"),v=(x==null?void 0:x.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await Ds(v,"editor-chartjs");let R=!1;(h&&h.config.data.datasets.length>i.length||h&&h.config.data.datasets[0].data.length>i[0].data.length)&&(R=!0),h&&(l!==h.config.type||R)&&(h.destroy(),h=null,Array.from(C.querySelectorAll(".editor-chartjs-canvas")).forEach(U=>{U.remove()}));const L=lg.default({},{type:l,data:{datasets:i,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(h)lg.default(h.config,L),h.update();else{const U=B("canvas",["editor-chartjs-canvas"],E).getContext("2d");h=new window.Chart(U,L),C.chartObject=h}}catch(R){ey.error(`failed to resolve chart cdn: ${JSON.stringify(R)}`)}}async function ny(n,t){await Sr.lock("updateTableChart");try{await NO(n,t)}finally{Sr.release("updateTableChart")}}const ry=Ke.default(ny,1e3);let iy=null;function Wp(n,t,e){if(iy!==t&&(ry.flush(),iy=t),e.updateNow){ny(n,t);return}ry(n,t)}function qp(n,t){He(t)&&Wp(n,t,{updateNow:!1})}function PO(n,t){He(t)&&Wp(n,t,{updateNow:!0})}const Er={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"},Jh={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},Jo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function _u(n,t){return n.containers.get(t)}function oy(n){return n.closest(`.${Jo.SCROLL_CONTAINER}`)}function Wr(n){return n.firstElementChild}function Tn(n){return n.closest(`.${Jo.CONTAINER}`)}function Mu(n){const t=Tn(n);let e=t.querySelector(`:scope >.${Jo.TOOL}`);return e||(e=B("div",[Jo.TOOL],t)),e}function FO(n){return Tn(n).firstElementChild}function KO(n,t){const e=_u(n,Tn(t));return e!=null&&e.barFloatWindowBottom?typeof e.barFloatWindowBottom=="function"?e.barFloatWindowBottom():e.barFloatWindowBottom:0}function Ar(n,t){const e=ur(n);return t/e}function Uu(n){const t=window.getComputedStyle(n),e=ur(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Ma(n){const t=ur(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function VO(n,t){const e=ur(n);return n[t]*e}function Xp(n,t){const e=Tn(t),r=_u(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 $O(n,t){const e=Xp(n,t),{maxLeft:r}=e;t.style.marginLeft=`${Ar(t,0-r)}px`,t.style.paddingLeft=`${Ar(t,r)}px`}function HO(n,t){const e=Xp(n,t);t.style.marginRight=`${Ar(t,0-e.maxRight)}px`}function jO(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 sy=I("scroll-bar-handle"),zO=2;function Ua(n){const t=Mu(n);let e=t.querySelector(`.${Jh.SCROLL_BAR}`);return e||(e=B("div",[Jh.SCROLL_BAR],t)),p(sy,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||B("div",[],e),e}function t0(n,t){const e=oy(t),r=Ua(e),{scrollWidth:i,clientWidth:o}=Ma(e),{paddingLeft:s,paddingRight:l}=Uu(t),c=Xp(n,e),{originWidth:d,maxRight:h}=c;HO(n,e),$O(n,e);const C=i-o;p(sy,r.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),r.style.width=`${Ar(e,d+h-s-l)}px`,r.firstElementChild.style.width=`${Ar(e,d+h+C-s-l)}px`}function GO(n,t){const e=Wr(n),{paddingLeft:r}=Uu(e);if(Rt(t,"fixed")){const o=Tn(n).getBoundingClientRect();t.style.left=`${Ar(n,o.left+r)}px`}else t.style.left=`${Ar(n,r)}px`}function Oa(n,t){var U;const e=n.getParentScrollContainer(),r=jO(e),i=t.getBoundingClientRect(),o=Ua(t),s=o.getBoundingClientRect(),l=_u(n,Tn(t)),c=KO(n,t),d=Wr(t),{paddingTop:h,paddingBottom:C}=Uu(d),{scrollWidth:E,clientWidth:x}=Ma(t),v=document.documentElement.clientHeight-c,R=r.top+Ma(e).clientHeight-v,L=v+Math.min(0,R);if(E>x&&i.top+h<L-s.height&&i.bottom>L-s.height+C&&!((U=l==null?void 0:l.isSetScale)!=null&&U.call(l))){l!=null&&l.allowScrollBarFixed&&z(o,Jh.FIXED);const F=R>0?c:0;o.style.bottom=`${Math.max(document.documentElement.clientHeight-r.bottom,0)+zO+F}px`}else ot(o,Jh.FIXED),o.style.bottom=`${Ar(t,C-s.height)}px`;GO(t,o)}class WO{constructor(t,e){g(this,"intersectionObserver");g(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Tn(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});g(this,"handleIntersectionEntry",t=>{const e=t.target;Oa(this.scrollCore,e);const r=Wr(e);t0(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 sl=I("container-scroll-shadow");function ly(n,t,e){const r=n,i=t.getBoundingClientRect(),o=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=Uu(e);r.style.top=`${Ar(t,o.top-i.top+s)}px`,r.style.bottom=`${Ar(t,i.bottom-o.bottom+l)}px`}function ay(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function qO(n){const t=Mu(n);p(sl,t,"no container tools");let e=t.querySelector(`.${Er.LEFT}`);if(!e){const l=Wr(n),c=[Er.COMMON,Er.LEFT];e=B("div",c,t),p(sl,e instanceof HTMLDivElement,"invalid child for container tools"),ly(e,n,l)}p(sl,e instanceof HTMLElement,"invalid child for container tools");const i=Tn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.left=`${Ar(n,o.left-i.left)}px`;const s=Ma(n).scrollLeft;p(sl,e instanceof HTMLDivElement,"invalid child for container tools"),ay(e,s),z(e,Er.ACTIVE)}function XO(n){const t=Mu(n);let e=t.querySelector(`.${Er.RIGHT}`);if(!e){const h=Wr(n),C=[Er.COMMON,Er.RIGHT];e=B("div",C,t),p(sl,e instanceof HTMLDivElement,"no div, create shadow failed"),ly(e,n,h)}p(sl,e instanceof HTMLElement,"");const i=Tn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.right=`${Ar(n,i.right-o.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Ma(n),d=s-l-c;p(sl,e instanceof HTMLDivElement,"no shadow element"),ay(e,d),z(e,Er.ACTIVE)}function QO(n){const e=Mu(n).querySelector(`.${Er.LEFT}`);e&&ot(e,Er.ACTIVE)}function YO(n){const e=Mu(n).querySelector(`.${Er.RIGHT}`);e&&ot(e,Er.ACTIVE)}function Ou(n){const{scrollLeft:t,scrollWidth:e,clientWidth:r}=Ma(n),i=Wr(n),{paddingLeft:o,paddingRight:s}=Uu(i),l=VO(i,"offsetLeft");e-o<=r-s||e-o<=t+r-s?YO(n):XO(n),i&&t>=l+o?qO(n):QO(n)}class ZO{constructor(t,e){g(this,"resizeObserver");g(this,"handleResizeEntry",t=>{const e=t.target,r=Wr(e);Ou(e),t0(this.scrollCore,r),Oa(this.scrollCore,e),this.callback(e)});g(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Tn(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new Ss(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 cy=I("container-scroll-observer");class JO{constructor(t,e){g(this,"handleContentScroll",t=>{const e=t.target;p(cy,e instanceof Element,"invalid target for scroll event");const r=Ua(e);r.removeEventListener("scroll",this.handleScroll);const i=!0;this.fixScrollXPos(e,e.scrollLeft,i),this.bind(r),Ou(e),this.callback(e)});g(this,"handleScroll",t=>{const e=t.target;p(cy,e instanceof HTMLElement,"");const r=e.scrollLeft,i=!1,o=FO(e);this.unbindContentScroll(o),this.fixScrollXPos(o,r,i),this.bindContentScroll(o),Ou(o),this.callback(o)});g(this,"handlePrevent",t=>{t.stopPropagation()});g(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});g(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});g(this,"bindContentScroll",Ke.default(this.bindContentScrollCore,300));g(this,"bind",Ke.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,r){const i=Ua(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 tN{constructor(t){g(this,"scrollContainers",new Set);g(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Oa(this.scrollCore,t)})});g(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});g(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 eN=I("scroll-wrap-resize-observer");class nN{constructor(t){g(this,"resizeObserver");g(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Tn(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});g(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;p(eN,e instanceof HTMLElement,"invalid target for observer entry");const r=oy(e);t0(this.scrollCore,e),Ou(r),Oa(this.scrollCore,r)});this.scrollCore=t,this.resizeObserver=new Ss(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 rN{constructor(t,e){g(this,"resizeObserver");g(this,"scrollContainersMap",new Map);g(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const r=Wr(e);Ou(e),t0(this.scrollCore,r),Oa(this.scrollCore,e),this.callback(e)})});g(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 Ss(this.handleResize)}bind(t){var i,o;const e=Tn(t),r=(i=_u(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=Tn(t),r=(o=_u(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 Sst="";class iN extends ye.TypedEmitter{constructor(e){super();g(this,"containerIntersectionObserver",null);g(this,"containerResizeObserver",null);g(this,"containerScrollObserver",null);g(this,"parentContainerScrollObserver",null);g(this,"scrollWrapResizeObserve",null);g(this,"locatingContainerResizeObserver",null);g(this,"isWindowEventBind",!1);g(this,"containers",new Map);g(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});g(this,"handleResize",e=>{this.emit("resize",this,e)});g(this,"handleIntersection",e=>{const r=e.target,i=Wr(r);e.isIntersecting?(this.load(),this.bindCore(r,i)):this.unbindCore(r,i)});g(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(r=>{Oa(this,r)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new ZO(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new JO(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new tN(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new nN(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new rN(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=Ua(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=Ua(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(Tn(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 WO(this,this.handleIntersection)),this.containerIntersectionObserver.bind(i)}unbind(e){var o;const r=e.firstElementChild,i=Wr(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 uy=I("scroll-container"),e0=new Map;class oN extends ye.TypedEmitter{constructor(){super(...arguments);g(this,"scrollListener");g(this,"options");g(this,"scrollContainerElement");g(this,"init",e=>{this.options=e;const r=B("div",[Jo.CONTAINER],e.parentElement);he.isMac&&z(r,Jo.MAC);const i=B("div",[Jo.SCROLL_CONTAINER],r),o=B("div",[Jo.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=e0.get(s),this.scrollListener||(this.scrollListener=new iN(s),e0.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});g(this,"handleContainerScroll",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)});g(this,"handleResize",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return p(uy,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),Wr(this.scrollContainerElement)}get scrollOptions(){return p(uy,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=Tn(this.contentElement);e&&e0.forEach((i,o)=>{i.unbind(e),i.containers.size===0&&(this.handleBaseListenerDestroy(i),e0.delete(o))})}}function sN(){return new oN}const Qp=I("column-width");function lN(n,t,e){mO(n,t).style.width=`${e}px`}function aN(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const r=Lt.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)}),Qp.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],x=(d-C)/(c-h);for(let v=h+1;v<c;v++)i[v]=C+x*(v-h)}Qp.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 Qp.debug(`widths: ${s.join()}`),s}function Nu(n){return Array.from(n.querySelector("colgroup").children).map(r=>r.getBoundingClientRect().width||Number.parseInt(r.style.width,10))}const Yp=200,cN=40,uN=I("table-resize-gripper"),fy=7,Zp=(fy-1)/2,fN=3;function dN(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)<=Zp&&d.top<=e&&e<=d.bottom)return c}}return null}function hN(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Jp(n,t){return xi(n,t).querySelector(".table-resize-gripper")}function dy(n,t){const e=Jp(n,t);p(uN,!e,"resize gripper has already exists");const r=xi(n,t),i=B("div",["table-resize-gripper","table-indicator"],r);return B("div",["table-resize-gripper-indicator"],i),i}function hy(n,t,e){let r=Jp(n,t);r||(r=dy(n,t));const o=Me(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=o.height,d=n.getCustom(Ai(t)).contentElement.getBoundingClientRect(),h=s.right-d.left;r.style.left=`${h-Zp-_a-Iu}px`,r.style.top=`${l}px`,r.style.height=`${c}px`,r.style.width=`${fy}px`}function tC(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function mN(n,t,e){const i={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,i)}function gN(n,t,e,r){const i=t,o=Lt.fromTable(e),s=o.getCellByCellElement(i),l=s.col+s.colSpan-1,c=Nu(e);let d=r;const h=(E,x)=>{const v=x+1,R=E.col+E.colSpan;return c.slice(v,R).reduce((M,U)=>M+U,0)},C=new Set;for(let E=0;E<o.rowCount;E++){const x=o.getCell({row:E,col:l});if(C.has(x.cell))continue;C.add(x.cell);const v=x.cell,R=v.getBoundingClientRect();let L=r-R.left+Zp-fN;const M=wu(v),U=Fg(n,M)||cN*x.colSpan,F=h(x,l),G=U-F;L<G&&(L=G);const q=R.left+L;d=Math.max(d,q)}return d}const pN=I("table-resize-drag-drop");class CN{constructor(t,e,r,i){g(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=gN(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;p(pN,c,"no dragging cell");const E=Lt.fromTable(s).getCellByCellElement(c),x=E.col+E.colSpan-1,v=Nu(s),R=v.slice(0,x).reduce((M,U)=>M+U,0),L=h-R;if(lN(s,x,L),L){const M=parseFloat(s.style.width);s.style.width=`${M+(L-v[x])}px`}hy(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,r,i,o){const s=Nu(t.data.table);mN(this.editor,t.data.block,s),tC(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function EN(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const r=nt(e);return!r||!n.contains(r)||!He(r)?null:r}I("table-resize");class AN{constructor(t){g(this,"draggingRefCell",null);g(this,"handleMouseMove",(t,e)=>{if(t.readonly||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const r=e.target;if(!(r instanceof Element)||r.closest(".table-indicator"))return;const o=e,s=EN(t,o);if(!s||!$T(s)||!t.isBlockWritable(s)){tC(t);return}this.updateGripper(s,o.x,o.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=Me(t),o=dN(i,e,r);if(o){if(!Jp(this.editor,t)){if(hN(this.editor))return;const l=dy(this.editor,t),c={block:t,table:i,draggingRefCell:o};Cg(new CN(this.editor,l,c,d=>{this.updateGripper(t,d.x,d.y)}))}hy(this.editor,t,o)}else tC(this.editor)}}function my(n){n.addCustom("table-mouse-event-handler",t=>new AN(t))}const gy=I("table-insert-column");function py(n,t,e){n.undoManager.runInGroup(()=>{var E;const r=Me(t),i=Lt.fromTable(r),o=i.colCount;p(gy,e>=0&&e<=o,`insert index ${e} is out of range [0, ${o}]`);const s=i.map(x=>x.containerId),l=new Set;n.doc.beginBatchUpdate();for(let x=0;x<s.length;x++){const v=s[x],R=v[e-1],L=v[e];if(e===0||e===v.length||R!==L){const M=no(n.doc);v.splice(e,0,M)}else v.splice(e,0,R),l.add(R)}n.doc.endBatchUpdate();const c=gt.default(n.getBlockData(t));l.forEach(x=>{const v=`${x}_colSpan`,R=c[v];p(gy,typeof R=="number"&&R>1,`no colSpan for containerId ${x}, ${R}`),c[v]=R+1});const d=((E=c.colsWidth)==null?void 0:E.concat())||new Array(c.cols).fill(0);d.splice(e,0,Yp);const h=Lt.virtualCellContainersGridToChildren(s),C={...c,cols:c.cols+1,children:h,colsWidth:d};il(C),n.updateBlockData(t,C)})}const n0=I("table-insert-row");function eC(n,t,e){n.undoManager.runInGroup(()=>{const r=Me(t),i=Lt.fromTable(r),o=i.rowCount;p(n0,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 x=e>0&&s[e-1][E],v=e<i.rowCount&&s[e][E];if(p(n0,x||v,"no top and bottom cell"),e===0||e===i.rowCount||x!==v){const R=no(n.doc);c.push(R)}else p(n0,x,"no top cell"),c.push(x),l.add(x)}n.doc.endBatchUpdate(),s.splice(e,0,c);const d=gt.default(n.getBlockData(t));l.forEach(E=>{const x=`${E}_rowSpan`,v=d[x];p(n0,typeof v=="number"&&v>1,`no rowSpan for containerId ${E}, ${v}`),d[x]=v+1});const h=Lt.virtualCellContainersGridToChildren(s),C={...d,rows:d.rows+1,children:h};il(C),n.updateBlockData(t,C)})}const nC=I("paste-table-in-table-block");function xN(n,t,e,r,i){let o=Lt.fromBlock(e);const s=t.blocks.root[0];p(nC,s,"no table data"),p(nC,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,x=C+d,v=E+h,R=[];for(let L=C;L<x&&L<o.colCount;L++)for(let M=E;M<v&&M<o.rowCount;M++){const U=o.getCell({col:L,row:M});U.virtual?U.virtual&&R.push({col:L,row:M}):(U.colSpan>1||U.rowSpan>1)&&R.push({col:L,row:M})}n.undoManager.runInGroup(()=>{if(n.doc.beginBatchUpdate(),R.forEach(F=>{const G=Lt.fromBlock(e).getCell(F);(G.colSpan>1||G.rowSpan>1)&&$p(n,e,F)}),x>o.colCount)for(let F=o.colCount;F<x;F++)py(n,e,F);if(v>o.rowCount)for(let F=o.rowCount;F<v;F++)eC(n,e,F);o=Lt.fromBlock(e);const L=new qh(l);let M;for(let F=0;F<L.colCount;F++)for(let G=0;G<L.rowCount;G++){const q=L.getCell({col:F,row:G});if(!q.virtual){const rt=I1(n.editorBlocks,t,q.containerId,i),at=C+F,At=E+G,Mt={col:at,row:At},kt=o.getCellContainer(Mt);T5(n,kt,rt,i),M=kt}}n.doc.endBatchUpdate(),p(nC,M,"no last container");const U=Ze(M);n.selection.selectBlock(U,dt(n,U))})}const rC=I("paste-in-table-block");class bN{constructor(t){g(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,x,v,R;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=it(i);if(Qt(o))return this.pasteData=void 0,!1;if(!Jc(t,o))return this.pasteData=void 0,!1;const s=nt(o);if(p(rC,s,"no parent block"),!He(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;rC.debug("paste child table in table");const d=Lt.fromBlock(s).getCellByContainerId(ft(o)).cell;W1(t,e);const h={blockIdMap:new Map,containerIdMap:new Map,boxIdMap:new Map};xN(t,e,s,d,h),p(rC,this.pasteData,"invalid paste data");const C=[];t.input.forEach(L=>{C.push(L)});for(let L=0;L<C.length&&!await((x=(E=C[L]).handleAfterPasteDoc)==null?void 0:x.call(E,t,e,h));L++);for(let L=0;L<C.length&&!await((R=(v=C[L]).handleAfterPaste)==null?void 0:R.call(v,t,this.pasteData.event,this.pasteData.doc));L++);return this.pasteData=void 0,!0}}function Cy(n){n.addCustom("table-block-paste-event",t=>new bN(t))}const iC=I("table-select-columns");function vN(n,t,e,r,i){p(iC,He(t),"is not a table block");const o=Lt.fromBlock(t);p(iC,e>=0&&e<o.colCount,"invalid from"),p(iC,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=Ee(t,s.containerId,{colIndex:e,rowIndex:0}),d=Ee(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 oC=I("table-select-columns");function BN(n,t,e,r,i){p(oC,He(t),"is not a table block");const o=Lt.fromBlock(t);p(oC,e>=0&&e<o.rowCount,"invalid from"),p(oC,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=Ee(t,s.containerId,{rowIndex:e,colIndex:0}),d=Ee(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 Lst="",Ey=I("get-toolbar-reference-client");function Ay(n,t){const e=n.selection.range;if(!e.isSimple()){p(Ey,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);p(Ey,_t(n,s),"not a complex block");const l=Zt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const r=e.isReverse()?t.start:t.end,i=We(n,{anchor:r,focus:r}),o=qi(n,t.block,i);if(o.length!==0)return o[0]}function TN(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 r0(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=ag.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=r0(i),TN(s))}),e}function i0(n){return n.findCustom("toolbar-handler")}const Ist="";class yN{constructor(){g(this,"linkPopup",null);g(this,"form",{});g(this,"onFinished",null);g(this,"onClose",null);g(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:r}=this.form,i=this.formatUrl(r.getInputValue());(t=this.onFinished)==null||t.call(this,e.getInputValue()||i,i),this._destroy()}catch{}});g(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});g(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});g(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector('[data-button-id="submit-button"]');t.disabled=!1});g(this,"handleTextKeyboard",t=>{var e;if(!t.isComposing){if(t.key==="Enter"){(e=this.form.linkUrl)==null||e.getField().focus(),t.stopPropagation();return}t.key==="Escape"&&this.handleClose()}});g(this,"handleUrlKeyboard",t=>{if(!t.isComposing){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(D.t("link.urlPlaceholder")),new Error(D.t("link.urlPlaceholder"))}formatUrl(t){if(!t)return"";try{new URL(t)}catch{return`${window.location.protocol}//${t}`}return t}editLink(t){var h,C;const{target:e,linkText:r,linkUrl:i,onFinished:o,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new Sa(this.createPopupContent(r,i)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:l}),this.onFinished=o,s&&(this.onClose=s);const c=(h=this.linkPopup)==null?void 0:h.content.querySelector('[data-button-id="submit-button"]'),d=(C=this.linkPopup)==null?void 0:C.content.querySelector('[data-button-id="cancel-button"]');c==null||c.addEventListener("click",this.handleOk),d==null||d.addEventListener("click",this.handleClose)}createPopupContent(t,e){const r=B("div",["link-popup-content"],null);this.form.linkText=Wh(r,{label:D.t("link.textLabel"),required:!1,placeholder:D.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Wh(r,{className:"link-popup-gap",label:D.t("link.urlLabel"),required:!0,placeholder:D.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const i=B("div",["link-popup-footer"],r),o=Cr("cancel-button",D.t("link.cancelText"));i.appendChild(o);const s=Cr("submit-button",D.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 Pu(n,t){n.addCustom("link-editor",()=>new yN).editLink(t)}const kN=I("link-popup");function RN(n){return Rt(n,"link")}function Fu(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function wN(n,t,e){var i,o,s,l;if(n.isBlockWritable(t)&&e&&hr(e)){const c=e,d=(o=(i=n.editorBoxes.getBoxClass(Xc(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&&et(n,t)&&RN(e)){const c=B("a",["link-href-button"],null,Fu(e));c.href=Fu(e),c.target="_blank",c.rel="noopener noreferrer";const d=[{id:"link-text",name:Fu(e),disableTooltip:!0,element:c},{id:"edit-link",name:D.t("link.edit"),icon:jh},{id:"remove-link",name:D.t("link.remove"),icon:H2}];return{element:e,commands:d}}return pv(n,t,"hovering-toolbar")}function xy(n,t,e){var l;const r=$o(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 SN(n,t,e){const[r,i]=xy(n,t,e);n.selection.selectBlock(t,r.start,r.end);const o=Fu(e),s=(h,C)=>{try{const E=n.getBlockText(t),x=a1(E,r.start,r.end-r.start),v=to(x,r.start,h,{link:C});n.setBlockText(t,v),n.selection.selectBlock(t,r.start+h.length),n.focus()}catch(E){kN.error(E)}},l=()=>{n.selection.selectBlock(t,r.end),n.focus()},c=qi(n,t,n.selection.range)[0];if(!c)return;const d=Yi(n,t,"link-button-anchor",c);Pu(n,{target:d,linkText:i,linkUrl:o,onFinished:s,onClose:l})}function LN(n,t,e){const[r]=xy(n,t,e),i=n.getBlockText(t),o=Fu(e),s=fa(r.start,r.end-r.start,i,"link",o);n.setBlockText(t,s),n.selection.selectBlock(t,r.end)}function IN(n,t,e,r){var s,l,c;if(e){if(n.isBlockWritable(t)&&hr(e)){const h=e,C=(l=(s=n.editorBoxes.getBoxClass(Xc(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=i0(n);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},400),r.id==="edit-link"?SN(n,t,e):r.id==="remove-link"&&LN(n,t,e);return}const i=gv(n,t);if(!i)return;const o=(c=i.blockCommands)==null?void 0:c["hovering-toolbar"];!o||o.executeCommand(n,t,r)}function o0(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const DN=[Mh,Uh,Oh,Nh,Ph,Fh,Kh,Vh];class _N{constructor(t){g(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=o0();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,r){if(et(t,e)){const i=st(e),o=It(e),s=Ir(t,e),c=t.getBlockData(e).heading,d=[];for(let C=0;C<this.getHeadingIndex();C++)d.push({id:`heading-${C+1}`,name:D.t("commands.heading",{name:`${C+1}`}),icon:DN[C],states:c===C+1?["checked"]:[],value:`${C+1}`});const h=C=>{var x;const E=B("span",["toolbar-item-name-container"],null);for(const v of C.children)if((x=v.states)!=null&&x.includes("checked"))return E.innerHTML=v.icon||Ra,E;return E.innerHTML=Ra,E};return[{id:"turn-into",name:D.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:D.t("commands.text"),icon:Ra,states:c?[]:["checked"]},...d],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,r){t.updateBlockData(e,{heading:r})}executeCommand(t,e,r,i){if(et(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 MN=8,we=I("list-block"),s0=I("list-block");function Kt(n){return It(n)==="list"}function Ue(n){p(s0,Kt(n),"not a list block")}function Zn(n){Ue(n);const t=n.getAttribute("data-list-type");return p(s0,t,"no list type"),t}function l0(n){return Kt(n)&&Zn(n)==="text-only"}function Jn(n){var t,e;return Ue(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function nn(n){var t,e;return Ue(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Na(n){Ue(n);const t=n.getAttribute("data-list-group-id");return p(s0,t,"no group id"),t}function ts(n){var o,s,l,c,d;Ue(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(s0,i,"no group id"),{type:t,start:e,level:r,groupId:i}}function sC(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 UN(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 ON="abcdefghijklmnopqrstuvwxyz";function by(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),r=ON[t];return e?by(e)+r:r}function NN(n){return`${n}`}const vy=[NN,by,UN];function PN(n,t){const e=vy[(n-1)%vy.length];return e(t)}function FN(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}function es(n,t){Ue(n);const{level:e,groupId:r,type:i}=ts(n);let o=me(n);for(;o;){if(!Kt(o))return null;const{level:s,groupId:l,type:c}=ts(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=me(o)}return null}function By(n){return es(n,{ignoreGroupId:!0})}function ll(n){Ue(n);const{level:t,groupId:e,type:r}=ts(n);let i=Gt(n);for(;i;){if(Kt(i)){const{level:o,groupId:s,type:l}=ts(i);if(t===o&&e===s&&(l==="text-only"||r==="text-only"||r===l))return i;if(o<t)return null}i=Gt(i)}return null}function Ty(n){Ue(n);const t=[];let e=es(n);for(;e;)t.unshift(e),e=es(e);return t}function Pa(n){Ue(n);const t=[];let e=ll(n);for(;e;)t.push(e),e=ll(e);return t}function Ku(n){Ue(n);let t=es(n);for(;t;){const e=es(t);if(!e)return t;t=e}return n}function KN(n){Ue(n);let t=ll(n);for(;t;){const e=ll(t);if(!e)return t;t=e}return null}function yy(n,t){const e=Ty(n),r=Pa(n);return t.withSelf?[...e,n,...r]:[...e,...r]}function a0(n){Ue(n);let t=n;const e=Ty(n);e.length>0&&(t=e[0]);const r=me(t);return!r||!Kt(r)?null:nn(r)<nn(t)?r:null}function VN(n,t){Ue(n);let e=n;for(;e;){const r=nn(e);if(r===t)return e;if(r>t)e=a0(e);else if(r<t)return null}return null}function $N(n){let t=Ku(n);for(;;){const e=a0(t);if(!e)return t;t=Ku(e)}}class HN{constructor(){g(this,"nodeMap",new Map);g(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 ky(n,t){const e=$N(t),r=new HN;r.addNode(null,e);let i=Gt(e);for(;i&&Kt(i);){if(l0(i)){r.addNode(null,i),i=Gt(i);continue}if(nn(i)===0&&Zn(i)!==Zn(e))break;const s=a0(i);r.addNode(s,i),i=Gt(i)}return r.rootNodes}function jN(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 Ry(){const e=(document.exitFullscreen||document.webkitExitFullscreen).bind(document)();try{document.fullscreenElement=null}catch{}return e}function lC(n){return Rt(n,"editor-in-mindmap-first")}function aC(n){if(p(we,Kt(n),"not a list block"),Rt(n,"editor-in-mindmap-first")||!qc(n))return!0;const t=n.classList,e="editor-mindmap-root-";return!!Array.from(t).find(i=>{if(i.startsWith(e))return i})}function zN(n,t,e){const r=it(n);if(t){const s=it(t);p(we,r===s,"invalid block container")}const i=bt(n);if(t){const s=bt(t);p(we,i<=s,"invalid block index")}if(z(n,...e),!t||t===n)return;let o=Gt(n);for(;o!==t;)p(we,o,"no next button"),z(o,...e),o=Gt(o);o&&z(o,...e)}function GN(n){const t=`editor-mindmap-root-${n.id}`,r=it(n).querySelectorAll(`.${t}`);return r[r.length-1]}async function WN(n,t,e){const r=ne(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=()=>{ot(r,"fullscreen"),i.innerHTML=Ip,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,D.t("mindmap.fullScreen")),aC(t)&&setTimeout(()=>{o()},300)};if(document.fullscreenElement===r){try{await Ry()}catch(l){we.error(l)}s()}else{try{z(r,"fullscreen"),await jN(r),o()}catch(l){we.error(l)}i.innerHTML=yT,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,D.t("mindmap.exitFullscreen"))}r.onfullscreenchange=()=>{document.fullscreenElement||s()}}function cC(n,t,e,r,i){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=Cr(e,r,i,[]);return s.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,r),z(s,"mindmap-button"),t.appendChild(s),s}function uC(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function qN(n){return uC(n,"mindmap-fullscreen")}function XN(n){return uC(n,"mindmap-fit")}function QN(n){return uC(n,"mindmap-close")}function YN(n,t,e,r){const i=cC(n,t,"mindmap-close",D.t("mindmap.close"),Dh);!i||n.domEvents.addEventListener(i,"click",()=>{r.closeMindmap(n,e)})}function ZN(n,t,e,r){const i=cC(n,t,"mindmap-fit",D.t("mindmap.autoFit"),TT);!i||n.domEvents.addEventListener(i,"click",()=>{r.fitMindmap(n,e)})}function JN(n,t,e,r){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const o=cC(n,t,"mindmap-fullscreen",D.t("mindmap.fullScreen"),Ip);!o||n.domEvents.addEventListener(o,"click",()=>{WN(n,e,r)})}function tP(n,t){const e=_d(t);if(!e)return;const r=XN(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=QN(e);i&&(i.remove(),n.domEvents.removeAllListeners(i));const o=qN(e);o&&(o.remove(),n.domEvents.removeAllListeners(o))}const Fa=new Map;function fC(n,t,e){const r=(s,l)=>{s.forEach(c=>{l?z(c.block,"to-mindmap-highlight"):ot(c.block,"to-mindmap-highlight"),r(c.children,l)})},i=ky(n,t);if(i.length===0)return;const o=i[0].block;if(e){const s=Fa.get(o);s&&(s.forEach(l=>l.cancel()),Fa.delete(o)),r(i,!0)}else{const s=setTimeout(()=>{r(i,!1),Fa.delete(o)},300),l=()=>{clearTimeout(s),Fa.delete(o)},c=Fa.get(o);c?c.push({cancel:l}):Fa.set(o,[{cancel:l}])}}const{Markmap:eP}=u6;function nP(n,t){Ue(t);const e=ky(n,t),r=e[0].block,i=d=>({t:"text",v:Ot(d.block).textContent,d:1,c:d.children.length>0?d.children.map(C=>i(C)):void 0});let o=null;e.length>1?o={t:"root",v:"root",d:0,c: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 c0(n,t,e,r){const{root:i,block:o,last:s}=nP(n,t);r.selectBlock&&n.selection.selectBlock(o,0,0),fC(n,o,!1),r.saveData&&n.updateBlockData(o,{viewAsMindmap:!0});const l=ne(o);let c=l.querySelector(".editor-mindmap-svg");if(r.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const M="http://www.w3.org/2000/svg",U=l.getBoundingClientRect(),F=document.fullscreenElement===l,G=F?`${U.width}`:`${t.getBoundingClientRect().width}`,q=F?`${U.height}`:"600",rt=document.createElementNS(M,"svg");rt.setAttributeNS(null,"viewBox",`0 0 ${G} ${q}`),rt.setAttributeNS(null,"width","100%"),rt.setAttributeNS(null,"height",q),rt.style.display="block",rt.style.width="100%",rt.style.height=`${q}px`,rt.classList.add("editor-mindmap-svg"),l.appendChild(rt),c=rt}const d=o,C=`editor-mindmap-root-${st(o)}`;z(d,"editor-in-mindmap-first",C,"readonly"),d.contentEditable="false";const E=Gt(o);E&&bt(E)<=bt(s.block)&&zN(E,s.block,["block-hidden",C]);const x=(M,U)=>{if(U.length>0){const F=U[0].parentElement;F&&(F.style.width="100vw",F.style.maxWidth="200px")}U.forEach(F=>{z(F,"editor-mindmap-node")})},v=new eP(c,{...e,autoFit:!0});v.viewHooks.transformHtml.tap(x),v.setData(i),v.fit();const R=ne(o);let L=R.querySelector(".mindmap-toolbar");L||(L=B("div",["mindmap-toolbar"],R)),ZN(n,L,d,r.mindmapTools),JN(n,L,d,r.mindmapTools),YN(n,L,d,r.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(o,0),n.input.focus()}),d.mindMap=v}function rP(n){const t=B("div",["list-to-mindmap-wrap"],null),e=Cr("list-to-mindmap",D.t("mindmap.viewAsMindMap"),BT,[],n.clientId);return t.appendChild(e),t}async function wy(n,t){const e=`editor-mindmap-root-${t.id}`,r=it(t);Ce(r).forEach(l=>{Rt(l,e)&&ot(l,e,"editor-in-mindmap-first","block-hidden")});const o=ne(t);document.fullscreenElement===o&&await Ry();const s=o.querySelector(".editor-mindmap-svg");!s||(p(we,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),tP(n,t))}function iP(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(i=>{if(i.startsWith(e))return i})}async function Sy(n,t){!iP(t)||(n.updateBlockData(t,{viewAsMindmap:null}),wy(n,t),n.selection.selectBlock(t,0))}function oP(n,t){const e=t.mindMap;e&&e.fit()}const u0={toMindmap:c0,closeMindmap:Sy,fitMindmap:oP},Dst="";class f0{constructor(t){g(this,"toMindmapButton");g(this,"currentBlock",null);g(this,"handleHoveringBlock",t=>{t&&Kt(t)&&Zn(t)!=="unchecked"&&Zn(t)!=="checked"&&this.editor.isWritable()?ne(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove()});g(this,"handleMouseEnter",()=>{const t=nt(this.toMindmapButton);p(we,t&&Kt(t),"no parent list"),fC(this.editor,t,!0),this.currentBlock=t});g(this,"handleMouseLeave",()=>{this.currentBlock&&(fC(this.editor,this.currentBlock,!1),this.currentBlock=null)});g(this,"handleClick",()=>{const t=nt(this.toMindmapButton);p(we,t&&Kt(t),"no parent list"),c0(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:u0})});this.editor=t,be.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=rP(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(f0)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}function sP(n,t,e){var r;t==="beginDrag"&&((r=f0.get(n))==null||r.hide())}function Ka(n,t,e,r){var o;const i=(o=r==null?void 0:r.groupId)!=null?o:J();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 dC(n,t,e,r){const i=yy(t,{withSelf:!0});i.length!==0&&Ka(n,i,e,r)}class d0{constructor(t,e){g(this,"listStart",0);g(this,"listBrother",null);if(this.editor=t,l0(e))return;const r=Ku(e),i=Jn(r);this.listStart=i,r===e?this.listBrother=ll(r):this.listBrother=r}fix(){!this.listBrother||dC(this.editor,this.listBrother,this.listStart)}}class al{constructor(t,e,r){g(this,"listStart");g(this,"listBrother",null);this.editor=t,this.options=r;const i=Ku(e),o=Jn(i);this.listStart=o,this.listBrother=i,r!=null&&r.resetStart&&(this.listStart=1)}fix(){!this.listBrother||dC(this.editor,this.listBrother,this.listStart,this.options)}}class Ly{constructor(t,e,r){g(this,"listStart");g(this,"listNextBrothers",[]);this.editor=t,this.listNextBrothers=Pa(e);const{start:i,resetStart:o}=r||{};this.listStart=o?1:i!=null?i:1}fix(){!this.listNextBrothers.length||Ka(this.editor,this.listNextBrothers,this.listStart)}}function lP(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function hC(n,t,e,r){if(we.debug("drag a block on a list block"),!et(n,t))return!1;p(we,Kt(e),"target is not a list block");const{type:i,start:o,level:s,groupId:l}=ts(e),c=r==="after"?o+1:o,d=n.getBlockData(t),h={id:J(),type:"list",groupId:l,level:s,start:c,text:d.text,...sC(i)};lP(n,e,h);let C=bt(e);const E=it(e);r==="after"&&(C+=1);let x=null;Kt(t)&&(x=new d0(n,t));const v=n.insertBlock(ft(E),C,h,th(h.id,0));return n.deleteBlock(t),new al(n,v).fix(),x==null||x.fix(),!0}function aP(n,t,e,r){if(we.debug("drag a list between text blocks"),r==="after"){const d=Gt(e);if(d&&Kt(d))return hC(n,t,d,"before")}if(r==="before"){const d=me(e);if(d&&Kt(d))return hC(n,t,d,"after")}const o={...n.getBlockData(t),groupId:J(),start:1,level:1};let s=bt(e);const l=it(e);r==="after"&&(s+=1),n.insertBlock(ft(l),s,o,th(o.id,0));const c=new d0(n,t);return n.deleteBlock(t),c.fix(),!0}function cP(n,t,e,r,i){if(wd(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,Kt(c),"target is not a list block"),hC(n,s,c,r)):aP(n,s,c,r)}function Iy(n,t){if(!n.isWritable())return!1;const e=n.selection.range,i=n.editorCommandProviders.getCommands(e).find(o=>o.id===t);return i?(n.editorCommandProviders.executeCommand(e,i,{}),!0):!1}const uP={"Shift+CtrlOrCmd+L":n=>Iy(n,"unordered-list"),"Shift+CtrlOrCmd+U":n=>Iy(n,"ordered-list")};function h0(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function fP(n,t){let e;const r=h0(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 Dy(n,t){const e=h0(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 mC(n){return n.readonly||!n.isWritable()}function dP(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;et(n,r)&&fP(n,r)}),!0}function hP(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;et(n,r)&&Dy(n,r)}),!0}function mP(n){return mC(n)?!1:n.undoManager.runInGroup(()=>(dP(n),!0))}function gP(n){return mC(n)?!1:n.undoManager.runInGroup(()=>(hP(n),!0))}function pP(n){if(mC(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!et(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!h0(t)))return Dy(n,t),!0}class gC{renderBlock(t,e,r){const{padding:i}=r;return i?{attributes:{"block-padding-level":i}}:{}}}const _st="",CP={Tab:mP,"Shift+Tab":gP,Backspace:pP};function EP(n,t,e=1){if(!t)return null;let r=me(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 Kt(r)?r:null}r=me(r)}return null}function AP(n,t){const e=n.getAttribute("data-style-heading"),r=EP(n,e);if(r)return r;const i=me(n);if(i&&Kt(i)&&Zn(i)===t)return i;const o=Gt(n);return o&&Kt(o)&&Zn(o)===t?o:null}function xP(n,t,e){var R,L,M;const r=(R=e.data)!=null?R:{};let i=1;if(Kt(t))i=nn(t);else{const U=h0(t);U&&(i=U+1),i>8&&(i=8)}const o=(L=r.listType)!=null?L:"ordered";if(o==="text-only")return null;const s=n.getBlockData(t);let l=(M=s.text)!=null?M:[],d=ce(l);const h=e.offset||0;h<=fn(l)&&(l=In(l,h).right,d=d.substring(0,h));let C=1;o==="ordered"&&(C=Number.parseInt(d,10)||1);let E=J();const x=AP(t,o);if(x)if(nn(x)===i){if(bt(t)>bt(x))C=Jn(x)+1;else{const U=Jn(x);U>1&&(C=U-1),new Ly(n,x,{start:C+1}).fix()}E=Na(x)}else{const U=VN(x,i);U&&(C=Jn(U)+1)}else Kt(t)&&new Ly(n,t,{start:1}).fix();const v={id:J(),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:(U,F)=>{new al(U,F).fix()}}}function Va(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function bP(n){var e,r;if(n.checkbox)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${PN(t,(r=n.start)!=null?r:1)}.`:FN(t)}function m0(n){return n==="checked"||n==="unchecked"}function _y(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=Va(i),d=Va(l);return c!==d&&(!m0(c)||!m0(d))||(i.level||1)>(l.level||1)}function My(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=Va(i),d=Va(l);return c!==d&&(!m0(c)||!m0(d))||(i.level||1)>(l.level||1)}function vP(n,t,e,r,i){var s,l,c;const o=t;if(r==="text")return((s=Mn.convertTo)==null?void 0:s.call(Mn,n,t,e,"text",i))||"";if(r==="markdown"){let d=((l=Mn.convertTo)==null?void 0:l.call(Mn,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,_y(n,t,e,i)&&(d=`${d}`),My(n,t,e,i)&&(d=`${d}`,h<=1&&(d+=`
|
|
609
|
+
`,KU=Object.freeze(Object.defineProperty({__proto__:null,ClearIcon:dT,CloseIcon:Dh,PrevIcon:w2,NextIcon:S2,MoreIcon:Cp,TextColorIcon:Ep,ArrowDownIcon:_h,ArrowUpIcon:BU,ArrowLeftIcon:TU,ArrowRightIcon:Ap,DeleteRowIcon:L2,DeleteColIcon:I2,MergeCellIcon:D2,SplitCellIcon:_2,DeleteTableIcon:M2,Heading1Icon:Mh,Heading2Icon:Uh,Heading3Icon:Oh,Heading4Icon:Nh,Heading5Icon:Ph,Heading6Icon:Fh,Heading7Icon:Kh,Heading8Icon:Vh,HeadingNIcon:yU,OrderedListIcon:U2,UnorderedListIcon:O2,CheckListIcon:N2,BlockquoteIcon:P2,AlignCenterIcon:Hh,AlignLeftIcon:ka,AlignRightIcon:$h,ImageIcon:F2,ImageMenuIcon:K2,ImageErrorIcon:bp,ImageEmptyIcon:$2,LinkIcon:yp,LinkOffIcon:H2,WarningIcon:xp,PasteSpecialIcon:V2,LaunchIcon:vp,CodeIcon:rT,AudioIcon:J2,GraphIcon:kU,VideoIcon:tT,FileIcon:RU,MathIcon:SU,MathMenuIcon:j2,TableIcon:LU,TableMenuIcon:z2,BilibiliIcon:W2,YoukuIcon:q2,ModaoIcon:Q2,FigmaIcon:X2,EditIcon:jh,CommentIcon:el,RefreshIcon:G2,HelpIcon:Bp,CheckMarkIcon:Tp,TextIcon:Ra,RightArrowIcon:wU,TencentVideoIcon:Y2,WebPageIcon:Z2,UmlIcon:eT,DividingLineIcon:nT,HeadingH1Icon:IU,HeadingH2Icon:DU,HeadingH3Icon:_U,HeadingH4Icon:MU,HeadingH5Icon:UU,HeadingH6Icon:OU,HeadingH7Icon:NU,HeadingH8Icon:PU,CheckboxIcon:kp,QuoteIcon:Rp,LinkHrefIcon:FU,OrderedIcon:Sp,UnorderedIcon:wp,CopyIcon:iT,CutIcon:oT,DeleteIcon:sT,LockBlockIcon:lT,UnLockBlockIcon:aT,InsertBeforeIcon:cT,InsertAfterIcon:uT,MentionIcon:fT,CircleAddIcon:hT,LoadingIcon:mT,DragIcon:Lp,UmlBrandIcon:zh,OnesLoadingIcon:gT,BoldIcon:pT,ItalicIcon:CT,UnderlineIcon:ET,LineThroughIcon:AT,SubscriptIcon:bT,SuperscriptIcon:vT,InlineCodeIcon:xT,ToMindMapIcon:BT,FitIcon:TT,FullScreenIcon:Ip,ExitFullScreenIcon:yT,CaretDownIcon:kT,StatusIcon:RT},Symbol.toStringTag,{value:"Module"}));function wT(){const n=B("span",["editor-loading-icon"],null);return n.innerHTML=gT,n}const xst="";function VU(n,t){const e=B("button",["editor-checkbox-wrapper"],null);e.setAttribute("data-button-id",n),t!=null&&t.includes("checked")&&z(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 bst="",wa=I("ui-command-bar-base"),$U={itemElementTag:"div",tippyArrow:!1},YE=class extends ye.TypedEmitter{constructor(e,r,i){var o,s;super();g(this,"content");g(this,"items");g(this,"subBar",null);g(this,"parentItem",null);g(this,"closeable",null);g(this,"closeReason",null);g(this,"options");g(this,"id");g(this,"header",null);g(this,"footer",null);g(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing&&!Hs(e.target)){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){this.close("cancelBar");return}if(e.key==="ArrowUp"){const r=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[r].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const r=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[r].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const r=this.getSelectedItem();r&&r.children&&this.showSubCommandBar(r.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const r=this.getSelectedItemIndex();if(r===-1)return;const i=this.items[r],o=this.getItemElementById(i.id);o&&this.emit("click",this,i,o)}}}});g(this,"handleDocumentMouseDown",e=>{if(e.target instanceof Element&&!this.isInCommandBar(e.target)){const r=this.listeners("closing");for(let i=0;i<r.length;i++)if(r[i](this,e)===!1)return;this.close("clickBackground")}});g(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),Lb(this.id)});g(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&z(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&Sb(this.id)});g(this,"lastEnterPauseTime",0);g(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});g(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)});g(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)&&(ot(r,"selected"),this.emit("selectionChange",this,""))});g(this,"handleItemClick",e=>{const r=this.getParentCommandItemElement(e.target);if(!r)return;const i=this.getItemElementId(r),o=this.items.find(s=>s.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}o.element||(this.emit("click",this,o,r),this.options.autoClose&&this.close("clickItem"))}});g(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=cn(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:J(),this.options={...$U,...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&&ot(r,"selected")}selectItem(e){const r=this.getSelectedItem();if(r){if(r.id===e)return;const o=r.id,s=this.getItemElementById(o);s&&ot(s,"selected")}const i=this.getItemElementById(e);i?(z(i,"selected"),this.emit("selectionChange",this,i.getAttribute("data-id")||""),this.options.disableSelectedScroll||i.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const r=this.getSelectedItem();if(!r)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.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=YE.createSubCommandBar(r,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=o,this.subBar.on("click",(c,d,h)=>{this.emit("click",c,d,h)}),this.subBar.on("close",()=>{var c;(c=this.subBar)==null||c.destroy(),this.subBar=null,ot(i,"active")}),r.beforePopup&&r.beforePopup(o),this.subBar.manualShow(i,this.getSubBarOptions(r)),z(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(wa,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(wa,i,`can not find command item for id: ${r}`),i}return null}getItemElementId(e){const r=e.getAttribute("data-id");return p(wa,r,"no data-id attribute"),r}getItemElementById(e){const r=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return p(wa,r,`no exists command item, id=${e}`),r}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(Rt(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)&&z(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(wa,e.children&&e.children.length>0,"no item children");const o=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(o);return p(wa,s,`no creator for command type: ${o}`),s(e,r,i)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let nl=YE;g(nl,"commandBarCreators",new Map),I("ui-command-bar");class Gh extends nl{constructor(){super(...arguments);g(this,"tippyInstance",null)}manualShow(e,r){var i,o,s;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=a6.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 ST=I("ui-base");class Sa extends Gh{constructor(t,e){var o;const i=[{id:(o=e==null?void 0:e.id)!=null?o:`popup-${J()}`,name:"",element:t}];super(i,void 0,{disablePageScroll:!0,id:e==null?void 0:e.id})}initCommandBarElement(t){z(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];p(ST,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return p(ST,e,"no item element"),e}}const ao=I("filterable-list");function LT(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")&&(z(t,"selected"),Ls(Tp,["list-item-selected-icon"],t)),(r=n.states)!=null&&r.includes("disabled")&&z(t,"disabled"),t}function IT(n){const t=B("div",["list-root"],null);return n.forEach(e=>{t.appendChild(LT(e))}),n.length||t.appendChild(LT({id:"placeholder",states:["disabled"],name:D.t("search.emptyTips")})),t}function DT(n,t){let e=n,r=null;return t&&(e=n.filter(i=>i.id===t?(r={...i,states:["selected"]},!1):{...i,states:void 0})),r?[...e,r]:[...e]}function HU(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=IT(DT(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function _T(n,t,e){const r=n.querySelector(".list");p(ao,r,"no list root");const i=IT(DT(t,e)),o=r.querySelector(".list-root");if(p(ao,o,"no exists menu"),jc(o,i),e){const s=r.querySelector(".list-item.selected");s&&(p(ao,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class jU{constructor(t,e){g(this,"root");g(this,"visibleItems");g(this,"selectedId");g(this,"filter","");g(this,"onSelected",null);g(this,"handleKeydown",t=>{this.processKeyDown(t)});g(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");p(ao,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});g(this,"handleClick",t=>{this.processClick(t)});var r;this.items=t,this.options=e,this.root=HU(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(ao,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(ao,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,_T(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");p(ao,t,"no input"),t.focus()}moveSelectedItemIntoView(){const t=this.root.querySelector(".list-item.selected");t&&(p(ao,t,"no selected menu item"),t.scrollIntoView({block:"nearest"}))}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");p(ao,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),_T(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 zU extends jU{constructor(e,r,i){super(e,i);g(this,"popup");g(this,"onShow",null);g(this,"onHide",null);g(this,"custom",null);g(this,"handleShow",()=>{this.onShow&&this.onShow(this)});g(this,"handleHide",()=>{this.onHide&&this.onHide(this)});g(this,"handleShown",()=>{this.focus()});this.popup=new Sa(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 vst="",Bst="";function GU(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 WU(n,t){var e,r;if(z(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-maxwidth","800"),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=Ap,t.appendChild(o)}if((r=n.states)!=null&&r.includes("checked")){const o=B("div",["menu-item-checked-icon"],null);o.innerHTML=Tp,t.appendChild(o)}}}}class rl extends Gh{constructor(t,e,r){super(t,e,{autoClose:!0,disablePageScroll:!0,...r})}manualShow(t,e){const r={theme:"menu",...e};super.manualShow(t,r)}initCommandBarElement(t){z(t,"menu")}initItemElement(t,e){WU(t,e)}}function qU(n,t,e){var r;return new rl((r=n.children)!=null?r:[],t,{...e,parentItem:n})}function MT(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=_h}n.states&&(n.states.indexOf("checked")!==-1&&z(r,"checked"),n.states.indexOf("disabled")!==-1&&(r.disabled=!0))}class ku extends Gh{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){z(t,"toolbar")}initItemElement(t,e){MT(t,e,this.options)}}function XU(n,t,e){var r;return new ku((r=n.children)!=null?r:[],t,{...e,parentItem:n})}class QU extends nl{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){z(t,"toolbar","fixed")}initItemElement(t,e){MT(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 Tst="";nl.registerManualCommandBar("menu",qU),nl.registerManualCommandBar("toolbar",XU);const yst="",UT=I("ui-base");class Ru extends Gh{constructor(e,r){super(Ru.getCommandItems(e,r),void 0,{disablePageScroll:!0,...r});g(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){z(e,"dialog","manual")}initItemElement(e,r){}show(e,r){this.manualShow(e,{...r,theme:"light"})}get dialogContent(){const e=this.items[0];p(UT,e,"no dialog item");const r=e.element;return p(UT,r,"no item element"),r}static getCommandItems(e,r){var s;return[{id:(s=r==null?void 0:r.id)!=null?s:`manual-dialog-${J()}`,name:"",element:e}]}}const kst="",YU=I("ui-base");class OT{constructor(t){g(this,"menu");g(this,"currentText","");g(this,"handleSearchText");g(this,"handleClick",Ke.default((t,e)=>{this.options.onClickItem(this,e)},300,{leading:!0,trailing:!1}));g(this,"handleShow",t=>{});g(this,"handleClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});g(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.options=t,this.menu=new rl([],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=Ke.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)}}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||D.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()}async handleSearchTextPure(t){this.currentText=t;const e="auto-suggest";try{await Sr.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{Sr.release(e)}}highlightText(t,e){YU.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 x=s.charAt(C);let v=!1;E.endsWith(" ")&&(v=!0,E=E.trimEnd()),c+=`<span class="highlight">${E}${x===" "||v?" ":""}</span>`}else c+=s.charAt(C),C++}return C<s.length&&(c+=s.substring(C)),c},o=s=>{if(Rt(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 Dp{constructor(t,e){g(this,"root");g(this,"input");g(this,"text");g(this,"dropdownIcon");g(this,"clearIcon");g(this,"autoSuggest");g(this,"labels");g(this,"items",[]);g(this,"handleClick",()=>{this.autoSuggest.popup(this.root),this.input.focus()});g(this,"handleClickItem",(t,e)=>{var r,i;(i=(r=this.options)==null?void 0:r.onClickItem)==null||i.call(r,e)});g(this,"handleInput",()=>{this.autoSuggest.handleSearchText(this.input.value),this.updatePlaceholder()});g(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)});g(this,"handleQueryItems",async(t,e)=>this.items.filter(i=>{var o;return(o=this.options)!=null&&o.filter?this.options.filter(i,e):!0}));g(this,"handleShow",()=>{z(this.root,"active"),this.input.focus()});g(this,"handleClose",()=>{var t,e;(e=(t=this.options)==null?void 0:t.onClose)==null||e.call(t),ot(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}=Dp.createDropdown(t,this.labels);this.root=r,this.input=i,this.text=o,this.clearIcon=s,this.dropdownIcon=l,this.autoSuggest=new OT({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=dT;const c=B("div",["dropdown-icon"],r);return c.innerHTML=_h,{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),z(this.root,"empty")}else ot(this.root,"empty")}}const ZU=[-1,6,0,1,2,3,4,5],JU=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],NT=I("color-palette");function PT(n,t,e,r){p(NT,n>0,"no color in palette");const i=t||1;p(NT,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 tO(n){const t=B("button",["color-button"],null),e=ZU[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=Ep,t}function eO(n){const t=B("button",["background-color-button"],null),e=JU[n];return t.setAttribute("data-color-index",`${e}`),t}function nO(){const n=B("div",["clear-button-container"],null),t=B("button",["clear-button"],n);return t.innerText=D.t("colorPalette.reset"),n}function rO(n){const t=B("div",["color-palette"],null);return n.color!==!1&&(B("div",["bar-desc"],t,D.t("colorPalette.colorDesc")),t.appendChild(PT(8,1,tO,"color"))),n.backgroundColor!==!1&&(B("div",["bar-desc"],t,D.t("colorPalette.backgroundDesc")),t.appendChild(PT(16,2,eO,"background-color"))),n.clearColorButton!==!1&&t.appendChild(nO()),t}function iO(n,t,e){const r=t==="color"?"color":"background-color",i=n.querySelector(`.${r} button.selected`);i&&ot(i,"selected"),e===null&&(e=-1);const o=n.querySelector(`.${r} button[data-color-index="${e}"]`);o&&z(o,"selected")}const Rst="",oO={};class sO extends ye.TypedEmitter{constructor(e=oO){super();g(this,"root");g(this,"handleClick",e=>{const r=e.target;if(!r||!(r instanceof Element))return;const i=r.closest("button");if(!i)return;if(Rt(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)||(Rt(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=rO(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,r){iO(this.root,e,r)}}class FT{constructor(t,e){g(this,"name","Color Palette");g(this,"element");g(this,"palette");g(this,"closeable",null);this.id=t,this.palette=new sO(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function lO(){const n=B("button",["color-button"],null);return n.innerHTML=Ep,n}function _p(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 KT extends ye.TypedEmitter{constructor(e){super();g(this,"id","text-color-item");g(this,"name",D.t("colorPalette.name"));g(this,"dropdown",!0);g(this,"manualShowChildren",!0);g(this,"children",[]);g(this,"element");g(this,"colorPaletteItem");g(this,"latestColors",[null,null]);g(this,"handlePaletteClick",(e,r)=>{this.emit("onClick",e,r)});g(this,"setLatestColors",(e,r)=>{e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=r:this.latestColors[1]=r:this.latestColors=[null,null],_p(this.element,this.latestColors)});g(this,"beforePopup",()=>{this.updatePaletteColor(this.latestColors),this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new FT("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=lO()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,_p(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,_p(this.element,this.latestColors)}}const wst="";function Wh(n,t){const e=B("div",["editor-input-wrap"],n);if(t!=null&&t.className&&z(e,t==null?void 0:t.className),t.label){const s=B("div",["editor-input-label"],e);B("span",[],s,t.label),t.required&&z(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),ot(e,"error")}),i.addEventListener("keydown",s=>{var l;(l=t.onKeyDown)==null||l.call(t,s)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:s=>{z(e,"error"),o.innerText=s},focus:()=>{setTimeout(()=>{i.focus()})}}}function Mp(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 aO extends OT{constructor(e,r){super(r);g(this,"handleClose",()=>{var e,r;Mp(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)||dt(this.editor,o)<i)return;const s=qi(this.editor,o,ve(this.editor,o,i));if(s.length===0)return;const l=s[0],c=Yi(this.editor,o,"editor-auto-suggest-menu",l);super.popup(c,{noEvent:!0})}}const Up=I("auto-suggest-menu");class Op{constructor(t,e){g(this,"order",100);g(this,"menu");g(this,"anchor",null);g(this,"close",()=>{this.menu.close()});g(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(ce(In(bn(t,o),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});g(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=ce(nh(t,o,i));if(p(Up,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});g(this,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});g(this,"onShow",(t,e,r,i)=>{var o;if((o=this.options)!=null&&o.onShow)return this.options.onShow(this,e,r,i)});g(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});g(this,"queryItems",(t,e)=>this.options.queryItems(this,e));g(this,"renderMenuItem",(t,e)=>{var i,o;return(o=(i=this.options).renderMenuItem)==null?void 0:o.call(i,this,e)});g(this,"hasExistsMenuThemeCommandBar",()=>!!document.querySelector('div.tippy-box[data-theme="menu"]'));this.editor=t,this.options=e,this.menu=new aO(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)||Ag(e.key)?!1:kb(e)&&!Us(e)?(setTimeout(()=>{this.resetItems()}),!1):xg(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,r,i){this.anchor={blockId:st(t),offset:e,leftText:r,trigger:i};const o=ft(it(t)),s=bt(t);this.menu.popupInEditor(o,s,e)}handleAfterInsertText(t,e,r,i,o){var h,C;const s=t.selection.range.start;if(!s.isSimple())return!1;const l=t.getBlockByIndex(e,r);if(Gi(l))return!1;const{blockId:c,offset:d}=s;if(st(l)!==c)return!1;if((h=this.menu)!=null&&h.isVisible)this.resetItems();else if(this.options.trigger.indexOf(o)!==-1){if(i>0&&this.options.needSpaceBeforeTrigger&&(((C=t.getBlockData(l).text)==null?void 0:C.reduce((R,L)=>R+L.insert,""))||"")[i-1]!==" "||this.hasExistsMenuThemeCommandBar())return!1;const E=ce(nh(t,l,d));this.popup(l,d,E,o)}return!1}handleUpdateCompositionText(t,e,r,i,o){var d;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,r);return st(c)!==l||(d=this.menu)!=null&&d.isVisible&&this.resetItems(),!1}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=ce(nh(t,o,i));if(p(Up,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);Up.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 cO(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const uO={"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"},...cO()};function Bn(n){var t;return(t=uO[n])==null?void 0:t.shortcut}function fO(n){var t;return(t=n.subText)!=null?t:""}const Ei=I("table-dom");function Ai(n){return`${st(n)}_scroll`}function Me(n){const t=n.querySelector("div[data-type=table-content] >table");return p(Ei,t instanceof HTMLTableElement,"invalid table"),t}function xi(n,t){const r=n.getCustom(Ai(t)).contentElement.firstElementChild;p(Ei,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(Ei,i,"no table tools"),i}function dO(n,t){return n.findCustom(Ai(t))?xi(n,t):null}function VT(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function wu(n){const t=n.querySelector(":scope div[data-type=editor-container]");return p(Ei,t,"no child container in cell"),t}function hO(n){const r=VT(n).map(i=>{const o=wu(i),s=ft(o),l=i.colSpan,c=i.rowSpan;return`${s}/${l}/${c}`}).join();return md.default(r)}function He(n){return It(n)==="table"}function Np(n){const t=it(n);if(Qt(t))return null;const e=nt(t);return p(Ei,e,"no parent block"),He(e)?t:Np(e)}function co(n){if(He(n))return n;const t=it(n);if(Qt(t))return null;const e=nt(t);return p(Ei,e,"no parent block"),He(e)?e:co(e)}function mO(n,t){const e=n.querySelector("colgroup");p(Ei,e,"no colgroup");const r=e.children[t];return p(Ei,r,"no col"),p(Ei,r instanceof HTMLTableColElement,`invalid col: ${r.tagName}`),r}function $T(n){try{return Me(n),!0}catch{return!1}}function gO(n){return ne(n).querySelector(":scope > .block-helper")}function HT(n){const t=nt(n.contentElement);p(Ei,t,"no block");const e=gO(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`}}const zr=I("doc-table-grid");class pO{constructor(t){g(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){p(zr,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){p(zr,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return p(zr,e,"get cell, no cell"),e}getCellAllowEmpty(t){return p(zr,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 qh{constructor(t){g(this,"_data");g(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new pO(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(zr,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(zr,o===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(i=>{i.forEach(o=>{p(zr,o,"no cell"),p(zr,o.containerId,"no containerId")})})}getCell(t){const{col:e,row:r}=t,i=this._rows[r];p(zr,i,`get cell, no row: ${r}`);const o=i.getCell(e);return p(zr,o,`get cell, no cell: ${e}`),o}getRow(t){const e=this._rows[t];return p(zr,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Xh=I("table-data");function CO(n){const t=n.firstElementChild;return p(Xh,t,"no child element for cell"),p(Xh,Wi(t),"cell first child is not a container"),p(Xh,Mr(t),"cell first child is not a container"),t}function EO(n){const t=nt(n);p(Xh,t,"no parent block for table");const e=[],r={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const d=CO(c),h=ft(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:st(t),type:It(t),rows:i,cols:o,children:e,colsWidth:Array(o).fill(100),...r}}function il(n){return new qh(n)}function AO(n){return il(EO(n))}const Xe=I("table-grid"),xO=60;class bO{constructor(t,e){g(this,"containerId");g(this,"row");g(this,"col");g(this,"colSpan");g(this,"rowSpan");g(this,"virtual");g(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(Xe,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);p(Xe,t.length===1,"containers !== 1"),p(Xe,Wi(t[0]),"not a container");const e=t[0];return p(Xe,Mr(e),"not a child container"),e}}class vO{constructor(t,e){g(this,"_cells",[]);e.forEach(r=>{this._cells.push(new bO(t,r))})}get cells(){return this._cells}getCell(t){return p(Xe,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 ZE=class{constructor(t){g(this,"_rows",[]);this.table=t,AO(t).forEach(i=>{this._rows.push(new vO(t,i))});const r=this.colCount;this._rows.forEach(i=>{p(Xe,i.cells.length===r,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(p(Xe,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(Xe,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(Xe,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(Xe,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(Xe,!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(Xe,r<=i,"min > max"),p(Xe,r>=0,"min < 0"),p(Xe,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(Xe,r<=i,"min > max"),p(Xe,r>=0,"min < 0"),p(Xe,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 x=r;x<=i;x++)for(let v=o;v<=s;v++)l.push(this.getCell({row:x,col:v}));const c=this.toRealCells(l);let d=1e4,h=1e4,C=-1,E=-1;return c.forEach(x=>{h=Math.min(x.col,h),d=Math.min(x.row,d),E=Math.max(x.col+x.colSpan-1,E),C=Math.max(x.row+x.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 x=this.getCell({row:C,col:E});x.virtual||r.push(x)}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)}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(Xe,r,"cell not found"),r}getCellByCellElement(t){const e=wu(t);return this.getCellByContainerId(ft(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=hO(t),r=this.caches.getSync(e,()=>(Xe.debug("create table grid"),new ZE(t)));return r.table!==t?(this.caches.delete(e),this.fromTable(t)):r}static fromBlock(t){return this.fromTable(Me(t))}};let Lt=ZE;g(Lt,"caches",new lb(xO));function Qh(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const BO=I("table-selection-range");function Gr(n,t,e){var U,F,G,q;const r=Lt.fromBlock(n),i=t,o=e,s=r.getCellByContainerId(i.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=i.custom,d=o.custom,h=(U=c==null?void 0:c.rowIndex)!=null?U:s.row,C=(F=c==null?void 0:c.colIndex)!=null?F:s.col,E=(G=d==null?void 0:d.rowIndex)!=null?G:l.row+l.rowSpan-1,x=(q=d==null?void 0:d.colIndex)!=null?q:l.col+l.colSpan-1,v=Math.min(h,E),R=Math.max(h,E),L=Math.min(C,x),M=Math.max(C,x);return{fromRow:v,toRow:R,fromCol:L,toCol:M}}function Pp(n,t){const e=new Set,r=new Set,i=n.selection.range;if(!i.isSimple()&&i.start.blockId===st(t)){const o=Lt.fromBlock(t),{start:s,end:l}=i;p(BO,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:d,fromRow:h,toRow:C}=Gr(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 Su(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const r=n.getBlockById(t.start.blockId);if(He(r)){const i=it(r),o=nt(i);o&&(e=co(o))}else e=co(r)}else{const r=n.getBlockById(t.start.blockId),i=co(r),o=n.getBlockById(t.end.blockId),s=co(o);i===s&&(e=i)}return e}const La=I("delete-columns");function jT(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{fromRow:s,toRow:l}=Gr(t,e.start,e.end),c=Lt.fromBlock(t);return s===0&&l===c.rowCount-1}function Fp(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var F,G;const e=t.getBlockById(n.start.blockId);if(!jT(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:r,toCol:i}=Gr(e,n.start,n.end),o=Lt.fromBlock(e);if(r===0&&i===o.colCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(q=>q.containerId);for(let q=0;q<l.length;q++){const rt=l[q];for(let at=r;at<=i;at++){const At=rt[at];s.add(At)}rt.splice(r,i-r+1)}const c=new Set(l.flat()),d=new Set(Array.from(s).filter(q=>!c.has(q))),h=i-r+1,C=new Map,E=new Map;s.forEach(q=>{if(d.has(q))return;const rt=o.getCellByContainerId(q);if(p(La,rt.colSpan>1,"invalid effected cell, colSpan === 1"),rt.col<r){p(La,c.has(q),"invalid effected cell, not exists");let ue=rt.col+rt.colSpan-1;ue>i&&(ue=i);const nr=ue-r+1,Se=rt.colSpan-nr;C.set(q,Se);return}p(La,rt.col<=i,"invalid effected cell, col > endCol");const at=rt.col,At=rt.col+rt.colSpan-1,Mt=rt.col-r,kt=At-at+1-h+Mt;p(La,kt>0,"invalid effected cell, newSpanned <= 0");const se=no(t.doc);E.set(q,{newContainerId:se,colSpan:kt})});for(let q=0;q<l.length;q++){const rt=l[q];for(let at=r;at<rt.length;at++){const At=rt[at],Mt=E.get(At);Mt&&(rt[at]=Mt.newContainerId)}}const x=gt.default(t.getBlockData(e));((F=x.colsWidth)!=null?F:new Array(x.cols).fill(0)).splice(r,i-r+1),d.forEach(q=>{Qh(x,q)}),C.forEach((q,rt)=>{p(La,q>=1,"invalid modified colSpan, colSpan < 1"),q===1?x[`${rt}_colSpan`]=void 0:x[`${rt}_colSpan`]=q}),E.forEach((q,rt)=>{Qh(x,rt);const{newContainerId:at,colSpan:At}=q;p(La,At>=1,"invalid newContainerData, colSpan < 1"),At>1&&(x[`${at}_colSpan`]=At);const Mt=o.getCellByContainerId(rt).rowSpan;Mt>1&&(x[`${at}_rowSpan`]=Mt)});const R=(G=l[0][r])!=null?G:l[0][r-1],L=t.getChildContainerData(R)[0],M=Lt.virtualCellContainersGridToChildren(l),U={...x,cols:x.cols-h,children:M};il(U),t.updateBlockData(e,U,ve(t,L.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const Ia=I("delete-rows");function zT(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{fromCol:s,toCol:l}=Gr(t,e.start,e.end),c=Lt.fromBlock(t);return s===0&&l===c.colCount-1}function Kp(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!zT(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:r,toRow:i}=Gr(e,n.start,n.end),o=Lt.fromBlock(e);if(r===0&&i===o.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(U=>U.containerId);for(let U=i;U>=r;U--)l[U].forEach(G=>s.add(G)),l.splice(U,1);const c=new Set(l.flat()),d=new Set(Array.from(s).filter(U=>!c.has(U))),h=i-r+1,C=new Map,E=new Map;s.forEach(U=>{if(d.has(U))return;const F=o.getCellByContainerId(U);if(p(Ia,F.rowSpan>1,"invalid effected cell, rowSpan === 1"),F.row<r){p(Ia,c.has(U),"invalid effected cell, not exists");let Mt=F.row+F.rowSpan-1;Mt>i&&(Mt=i);const kt=Mt-r+1,se=F.rowSpan-kt;C.set(U,se);return}p(Ia,F.row<=i,"invalid effected cell, col > endCol");const G=F.row,q=F.row+F.rowSpan-1,rt=F.row-r,at=q-G+1-h+rt;p(Ia,at>0,"invalid effected cell, newSpanned <= 0");const At=no(t.doc);E.set(U,{newContainerId:At,rowSpan:at})});for(let U=r;U<l.length;U++){const F=l[U];for(let G=0;G<F.length;G++){const q=F[G],rt=E.get(q);rt&&(F[G]=rt.newContainerId)}}const x=gt.default(t.getBlockData(e));d.forEach(U=>{Qh(x,U)}),C.forEach((U,F)=>{p(Ia,U>=1,"invalid modified rowSpan, rowSpan < 1"),U===1?x[`${F}_rowSpan`]=void 0:x[`${F}_rowSpan`]=U}),E.forEach((U,F)=>{Qh(x,F);const{newContainerId:G,rowSpan:q}=U;p(Ia,q>=1,"invalid newContainerData, rowSpan < 1"),q>1&&(x[`${G}_rowSpan`]=q);const rt=o.getCellByContainerId(F).colSpan;rt>1&&(x[`${G}_colSpan`]=rt)});const v=l[r]?l[r][0]:l[r-1][0],R=t.getChildContainerData(v)[0],L=Lt.virtualCellContainersGridToChildren(l),M={...x,rows:x.rows-h,children:L};il(M),t.updateBlockData(e,M,ve(t,R.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const Lu=I("table-range");function Yh(n){p(Lu,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;p(Lu,!t.isSimple(),"invalid start pos type"),p(Lu,!e.isSimple(),"invalid end pos type");const r=n.getEditor();p(Lu,t.blockId===e.blockId,"invalid range, not same block");const i=r.getBlockById(t.blockId);p(Lu,It(i)==="table","invalid block type, not a table block");const o=Me(i),s=Lt.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),x=s.getCell({row:d,col:C}),v=s.getCell({row:h,col:E});return{editor:r,block:i,table:o,startCell:x,endCell:v,startRow:d,startCol:C,endRow:h,endCol:E}}const Vp=I("split-cell");function $p(n,t,e){n.undoManager.runInGroup(()=>{const r=Lt.fromBlock(t),i=r.getRealCell(e);p(Vp,!i.virtual,"should not split virtual cell"),p(Vp,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 x=C+i.row,v=E+i.col,R=no(n.doc);o[x][v]=R}const s=n.getBlockData(t),l=gt.default(s);l[`${i.containerId}_colSpan`]=null,l[`${i.containerId}_rowSpan`]=null,l.children=Lt.virtualCellContainersGridToChildren(o);const d=n.getChildContainerData(i.containerId)[0];p(Vp,d,"no child block");const h=ve(n,d.id,0);il(l),n.updateBlockData(t,l,h)})}function TO(n,t,e){e.forEach(r=>{const i=Lt.fromBlock(t).getCell(r);(i.virtual||i.colSpan>1||i.rowSpan>1)&&$p(n,t,r)})}function GT(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{startCell:s,endCell:l}=Yh(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function Hp(n){const{editor:t,block:e,startRow:r,startCol:i,endRow:o,endCol:s}=Yh(n),l=[];for(let c=r;c<=o;c++)for(let d=i;d<=s;d++)l.push({row:c,col:d});return TO(t,e,l),!0}const Da=I("merge-cells");function WT(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||It(t)!=="table")return!1;const{startCell:s,endCell:l}=Yh(e);return s.cell!==l.cell}function qT(n){const t=Yh(n),e=t.editor;e.undoManager.runInGroup(()=>{const r=t.endCell,i=r.row+r.rowSpan-1,o=r.col+r.colSpan-1,s=st(t.block);Hp(n);const l=e.getBlockById(s),c=Me(l),{startRow:d,startCol:h}=t,C=gt.default(e.getBlockData(l));p(Da,C.children,"no table children");const E=Lt.fromTable(c),x=[];for(let Mt=d;Mt<=i;Mt++)for(let kt=h;kt<=o;kt++){const se=E.getCell({row:Mt,col:kt});p(Da,!se.virtual,"cell is virtual"),x.push(se)}p(Da,x.length>0,"no selected cells");const v=x[0],R=x.slice(1),L=E.getCellByContainerId(v.containerId).container,M=[];R.forEach(Mt=>{const kt=E.getCellByContainerId(Mt.containerId).container,se=ft(kt);if(!Jc(e,kt)){const ue=g5(e,se);if(Jc(e,L)){const nr=Ce(L)[0];e.insertDocAt(L,0,ue),e.deleteBlock(nr)}else e.insertDocAt(L,Lr(L),ue)}M.push(se)});const U=ft(L),F=o-h+1,G=i-d+1;C[`${U}_colSpan`]=F,C[`${U}_rowSpan`]=G,M.forEach(Mt=>{p(Da,C.children,"no table children");const kt=C.children.indexOf(Mt);p(Da,kt>0,"no deleted container"),C.children.splice(kt,1)});const q=C,at=e.getChildContainerData(U)[0];p(Da,at,"no child block");const At=ve(e,at.id,0);il(q),e.updateBlockData(l,q,At),e.deleteChildContainers(M)})}const jp=10,yO=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Zh{constructor(){g(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,r){if(It(e)!=="table")return[];const i={blockId:st(e),blockKind:Ir(t,e),blockType:It(e)},o=[];WT(t,e,r)&&o.push({id:"table/merge-cells",name:D.t("table.mergeCell"),icon:D2,groupIndex:jp,...i}),GT(t,e,r)&&o.push({id:"table/split-cell",name:D.t("table.splitCell"),icon:_2,groupIndex:jp,...i});const s=jT(t,e,r),l=zT(t,e,r);return s&&l&&o.push({id:"table/delete",name:D.t("table.deleteTable"),icon:M2,groupIndex:jp,...i}),o}executeCommand(t,e,r,i,o,s){return It(e)!=="table"||!new Set(yO).has(i.id)?!1:i.id==="table/merge-cells"?(qT(r),!0):i.id==="table/split-cell"?(Hp(r),!0):i.id==="table/delete-columns"?(Fp(r),!0):i.id==="table/delete-rows"?(Kp(r),!0):i.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var XT=(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))(XT||{});const _a=6,Iu=20,zp="table-cell-menu-btn";function kO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,r)}function RO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,r)}function wO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,r)}function SO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,r)}function LO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,r)}function IO(n,t){if(!n.isBlockWritable(t))return;const r={...gt.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,r)}function DO(n,t,e){if(!n.isBlockWritable(t))return;const i={...gt.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,i)}const ol=I("table-cell-dom");function _O(n,t,e){let r=n.getBlockById(e);for(;r;){const i=r.closest("td");p(ol,i,"no parent cell");const o=nt(i);if(p(ol,o,"no parent block"),o===t)return i;r=o}return p(ol,!1,"filed to get cell by child block id"),null}function Qo(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return p(ol,e.childContainerId,"block position must have childContainerId attribute"),e;const i=_O(n,t,e.blockId),o=ft(wu(i));return Ee(t,o)}function Gp(n,t){const e=n.selection.range,r=Qo(n,t,e.start),i=Qo(n,t,e.end);return Gr(t,r,i)}function QT(n,t,e,r){p(ol,He(t),"invalid table block");const i=xi(n,t),o=ne(t),s=()=>{const c=i.querySelector(".table-border-bar-container.top");p(ol,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)?z(h,"danger"):ot(h,"danger")})},l=()=>{const c=o.querySelector(".table-border-bar-container.left");p(ol,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)?z(h,"danger"):ot(h,"danger")})};s(),l()}function Yo(n,t,e=!0,r){const o=Lt.fromBlock(t).map(h=>h),{fromCol:s,toCol:l,fromRow:c,toRow:d}=Gp(n,t);for(let h=0;h<o.length;h++){const C=o[h];for(let E=0;E<C.length;E++){const x=C[E],v=r?E>=s&&E+x.colSpan-1<=l:h>=c&&h+x.rowSpan-1<=d;e&&v?x.virtual||z(x.cell,"danger"):x.virtual||ot(x.cell,"danger")}}}function Zo(n,t,e=!0,r){const i=new Set,o=new Set;if(!e){QT(n,t,Array.from(i),Array.from(o));return}const{fromCol:s,toCol:l,fromRow:c,toRow:d}=Gp(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);QT(n,t,Array.from(i),Array.from(o))}function YT(n,t,e){const{fromCol:r,toCol:i,fromRow:o,toRow:s}=Gp(n,t),l=Lt.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}),We(n,{anchor:Ee(t,c.containerId,{colIndex:r,rowIndex:0}),focus:Ee(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}),We(n,{anchor:Ee(t,c.containerId,{colIndex:0,rowIndex:o}),focus:Ee(t,d.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}const ZT=["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 JT(n){return`style-bg-color-${n}`}function Du(n){return`${n}_background`}function MO(n,t,e){const r=Me(n),s=(e!=null?e:Lt.fromTable(r)).getCell(t).cell;for(let l=0;l<ZT.length;l++){const c=ZT[l];if(Rt(s,c))return c}}function ty(n,t,e){if(!n.isBlockWritable(t))return;const r=n.selection.range,o={...gt.default(n.getBlockData(t))},s=Qo(n,t,r.start),l=Qo(n,t,r.end);if(r.isSimple()){const c=s.childContainerId;e===-1?o[Du(c)]=void 0:o[Du(c)]=JT(e)}else{const c=Lt.fromBlock(t),d=Gr(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 x=c.getCell({row:C,col:E});!h.has(x.containerId)&&x.col>=d.fromCol&&x.row>=d.fromRow&&x.col+x.colSpan-1<=d.toCol&&x.row+x.rowSpan-1<=d.toRow&&(h.add(x.containerId),e===-1?o[Du(x.containerId)]=void 0:o[Du(x.containerId)]=JT(e))}}n.updateBlockData(t,o)}function UO(n,t,e){if(!n.isBlockWritable(t))return;const i={...gt.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,i)}const ey=I("table-chart");function OO(n,t){const e=dO(n,t);if(e){const r=e.querySelector(".editor-table-chart");if(r){const i=r.chartObject;i&&i.destroy(),r.remove()}}}async function NO(n,t){if(!n.contains(t)||!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){OO(n,t);return}const i=[],o=Lt.fromBlock(t),s=["line","bar","pie","radar"];let l=o.getCell({row:0,col:0}).container.innerText.trim().toLowerCase();new Set(s).has(l)||(l=s[0]);const c=[];for(let R=1;R<o.colCount;R++)c.push(o.getCell({row:0,col:R}).container.innerText);for(let R=1;R<o.rowCount;R++){const L=o.getCell({row:R,col:0}),U=L.container.innerText,F=[];for(let ue=1;ue<o.colCount;ue++){const nr=o.getCell({row:R,col:ue}).container.innerText,Se=Number.parseFloat(nr)||0;F.push(Se)}let G;const q=MO(t,L,o);q?G=window.getComputedStyle(n.rootElement).getPropertyValue(`--${q}`).trim():G=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[rt,at,At,Mt]=G?og.fromString(G).toRgbaArray():[];if(!rt&&!at&&!At&&!Mt){const ue=(R-1)%n.options.colors.length;G=n.options.colors[ue],[rt,at,At,Mt]=og.fromString(G).toRgbaArray()}const kt=G,se=og.fromRgba([rt,at,At,Mt/3]).toHexString();i.push({label:U,data:F,borderColor:kt,backgroundColor:se,borderWidth:2})}const d=xi(n,t);let h=null,C=d.querySelector(".editor-table-chart");C?h=C.chartObject:C=B("div",["editor-table-chart"],d);const E=C;p(ey,E,"no chart container");const x=n.getComponentOptions("table"),v=(x==null?void 0:x.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await Ds(v,"editor-chartjs");let R=!1;(h&&h.config.data.datasets.length>i.length||h&&h.config.data.datasets[0].data.length>i[0].data.length)&&(R=!0),h&&(l!==h.config.type||R)&&(h.destroy(),h=null,Array.from(C.querySelectorAll(".editor-chartjs-canvas")).forEach(U=>{U.remove()}));const L=lg.default({},{type:l,data:{datasets:i,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(h)lg.default(h.config,L),h.update();else{const U=B("canvas",["editor-chartjs-canvas"],E).getContext("2d");h=new window.Chart(U,L),C.chartObject=h}}catch(R){ey.error(`failed to resolve chart cdn: ${JSON.stringify(R)}`)}}async function ny(n,t){await Sr.lock("updateTableChart");try{await NO(n,t)}finally{Sr.release("updateTableChart")}}const ry=Ke.default(ny,1e3);let iy=null;function Wp(n,t,e){if(iy!==t&&(ry.flush(),iy=t),e.updateNow){ny(n,t);return}ry(n,t)}function qp(n,t){He(t)&&Wp(n,t,{updateNow:!1})}function PO(n,t){He(t)&&Wp(n,t,{updateNow:!0})}const Er={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"},Jh={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},Jo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function _u(n,t){return n.containers.get(t)}function oy(n){return n.closest(`.${Jo.SCROLL_CONTAINER}`)}function Wr(n){return n.firstElementChild}function Tn(n){return n.closest(`.${Jo.CONTAINER}`)}function Mu(n){const t=Tn(n);let e=t.querySelector(`:scope >.${Jo.TOOL}`);return e||(e=B("div",[Jo.TOOL],t)),e}function FO(n){return Tn(n).firstElementChild}function KO(n,t){const e=_u(n,Tn(t));return e!=null&&e.barFloatWindowBottom?typeof e.barFloatWindowBottom=="function"?e.barFloatWindowBottom():e.barFloatWindowBottom:0}function Ar(n,t){const e=ur(n);return t/e}function Uu(n){const t=window.getComputedStyle(n),e=ur(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Ma(n){const t=ur(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function VO(n,t){const e=ur(n);return n[t]*e}function Xp(n,t){const e=Tn(t),r=_u(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 $O(n,t){const e=Xp(n,t),{maxLeft:r}=e;t.style.marginLeft=`${Ar(t,0-r)}px`,t.style.paddingLeft=`${Ar(t,r)}px`}function HO(n,t){const e=Xp(n,t);t.style.marginRight=`${Ar(t,0-e.maxRight)}px`}function jO(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 sy=I("scroll-bar-handle"),zO=2;function Ua(n){const t=Mu(n);let e=t.querySelector(`.${Jh.SCROLL_BAR}`);return e||(e=B("div",[Jh.SCROLL_BAR],t)),p(sy,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||B("div",[],e),e}function t0(n,t){const e=oy(t),r=Ua(e),{scrollWidth:i,clientWidth:o}=Ma(e),{paddingLeft:s,paddingRight:l}=Uu(t),c=Xp(n,e),{originWidth:d,maxRight:h}=c;HO(n,e),$O(n,e);const C=i-o;p(sy,r.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),r.style.width=`${Ar(e,d+h-s-l)}px`,r.firstElementChild.style.width=`${Ar(e,d+h+C-s-l)}px`}function GO(n,t){const e=Wr(n),{paddingLeft:r}=Uu(e);if(Rt(t,"fixed")){const o=Tn(n).getBoundingClientRect();t.style.left=`${Ar(n,o.left+r)}px`}else t.style.left=`${Ar(n,r)}px`}function Oa(n,t){var U;const e=n.getParentScrollContainer(),r=jO(e),i=t.getBoundingClientRect(),o=Ua(t),s=o.getBoundingClientRect(),l=_u(n,Tn(t)),c=KO(n,t),d=Wr(t),{paddingTop:h,paddingBottom:C}=Uu(d),{scrollWidth:E,clientWidth:x}=Ma(t),v=document.documentElement.clientHeight-c,R=r.top+Ma(e).clientHeight-v,L=v+Math.min(0,R);if(E>x&&i.top+h<L-s.height&&i.bottom>L-s.height+C&&!((U=l==null?void 0:l.isSetScale)!=null&&U.call(l))){l!=null&&l.allowScrollBarFixed&&z(o,Jh.FIXED);const F=R>0?c:0;o.style.bottom=`${Math.max(document.documentElement.clientHeight-r.bottom,0)+zO+F}px`}else ot(o,Jh.FIXED),o.style.bottom=`${Ar(t,C-s.height)}px`;GO(t,o)}class WO{constructor(t,e){g(this,"intersectionObserver");g(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Tn(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});g(this,"handleIntersectionEntry",t=>{const e=t.target;Oa(this.scrollCore,e);const r=Wr(e);t0(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 sl=I("container-scroll-shadow");function ly(n,t,e){const r=n,i=t.getBoundingClientRect(),o=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=Uu(e);r.style.top=`${Ar(t,o.top-i.top+s)}px`,r.style.bottom=`${Ar(t,i.bottom-o.bottom+l)}px`}function ay(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function qO(n){const t=Mu(n);p(sl,t,"no container tools");let e=t.querySelector(`.${Er.LEFT}`);if(!e){const l=Wr(n),c=[Er.COMMON,Er.LEFT];e=B("div",c,t),p(sl,e instanceof HTMLDivElement,"invalid child for container tools"),ly(e,n,l)}p(sl,e instanceof HTMLElement,"invalid child for container tools");const i=Tn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.left=`${Ar(n,o.left-i.left)}px`;const s=Ma(n).scrollLeft;p(sl,e instanceof HTMLDivElement,"invalid child for container tools"),ay(e,s),z(e,Er.ACTIVE)}function XO(n){const t=Mu(n);let e=t.querySelector(`.${Er.RIGHT}`);if(!e){const h=Wr(n),C=[Er.COMMON,Er.RIGHT];e=B("div",C,t),p(sl,e instanceof HTMLDivElement,"no div, create shadow failed"),ly(e,n,h)}p(sl,e instanceof HTMLElement,"");const i=Tn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.right=`${Ar(n,i.right-o.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Ma(n),d=s-l-c;p(sl,e instanceof HTMLDivElement,"no shadow element"),ay(e,d),z(e,Er.ACTIVE)}function QO(n){const e=Mu(n).querySelector(`.${Er.LEFT}`);e&&ot(e,Er.ACTIVE)}function YO(n){const e=Mu(n).querySelector(`.${Er.RIGHT}`);e&&ot(e,Er.ACTIVE)}function Ou(n){const{scrollLeft:t,scrollWidth:e,clientWidth:r}=Ma(n),i=Wr(n),{paddingLeft:o,paddingRight:s}=Uu(i),l=VO(i,"offsetLeft");e-o<=r-s||e-o<=t+r-s?YO(n):XO(n),i&&t>=l+o?qO(n):QO(n)}class ZO{constructor(t,e){g(this,"resizeObserver");g(this,"handleResizeEntry",t=>{const e=t.target,r=Wr(e);Ou(e),t0(this.scrollCore,r),Oa(this.scrollCore,e),this.callback(e)});g(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Tn(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new Ss(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 cy=I("container-scroll-observer");class JO{constructor(t,e){g(this,"handleContentScroll",t=>{const e=t.target;p(cy,e instanceof Element,"invalid target for scroll event");const r=Ua(e);r.removeEventListener("scroll",this.handleScroll);const i=!0;this.fixScrollXPos(e,e.scrollLeft,i),this.bind(r),Ou(e),this.callback(e)});g(this,"handleScroll",t=>{const e=t.target;p(cy,e instanceof HTMLElement,"");const r=e.scrollLeft,i=!1,o=FO(e);this.unbindContentScroll(o),this.fixScrollXPos(o,r,i),this.bindContentScroll(o),Ou(o),this.callback(o)});g(this,"handlePrevent",t=>{t.stopPropagation()});g(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});g(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});g(this,"bindContentScroll",Ke.default(this.bindContentScrollCore,300));g(this,"bind",Ke.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,r){const i=Ua(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 tN{constructor(t){g(this,"scrollContainers",new Set);g(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Oa(this.scrollCore,t)})});g(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});g(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 eN=I("scroll-wrap-resize-observer");class nN{constructor(t){g(this,"resizeObserver");g(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Tn(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});g(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;p(eN,e instanceof HTMLElement,"invalid target for observer entry");const r=oy(e);t0(this.scrollCore,e),Ou(r),Oa(this.scrollCore,r)});this.scrollCore=t,this.resizeObserver=new Ss(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 rN{constructor(t,e){g(this,"resizeObserver");g(this,"scrollContainersMap",new Map);g(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const r=Wr(e);Ou(e),t0(this.scrollCore,r),Oa(this.scrollCore,e),this.callback(e)})});g(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 Ss(this.handleResize)}bind(t){var i,o;const e=Tn(t),r=(i=_u(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=Tn(t),r=(o=_u(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 Sst="";class iN extends ye.TypedEmitter{constructor(e){super();g(this,"containerIntersectionObserver",null);g(this,"containerResizeObserver",null);g(this,"containerScrollObserver",null);g(this,"parentContainerScrollObserver",null);g(this,"scrollWrapResizeObserve",null);g(this,"locatingContainerResizeObserver",null);g(this,"isWindowEventBind",!1);g(this,"containers",new Map);g(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});g(this,"handleResize",e=>{this.emit("resize",this,e)});g(this,"handleIntersection",e=>{const r=e.target,i=Wr(r);e.isIntersecting?(this.load(),this.bindCore(r,i)):this.unbindCore(r,i)});g(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(r=>{Oa(this,r)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new ZO(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new JO(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new tN(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new nN(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new rN(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=Ua(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=Ua(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(Tn(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 WO(this,this.handleIntersection)),this.containerIntersectionObserver.bind(i)}unbind(e){var o;const r=e.firstElementChild,i=Wr(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 uy=I("scroll-container"),e0=new Map;class oN extends ye.TypedEmitter{constructor(){super(...arguments);g(this,"scrollListener");g(this,"options");g(this,"scrollContainerElement");g(this,"init",e=>{this.options=e;const r=B("div",[Jo.CONTAINER],e.parentElement);he.isMac&&z(r,Jo.MAC);const i=B("div",[Jo.SCROLL_CONTAINER],r),o=B("div",[Jo.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=e0.get(s),this.scrollListener||(this.scrollListener=new iN(s),e0.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});g(this,"handleContainerScroll",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)});g(this,"handleResize",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return p(uy,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),Wr(this.scrollContainerElement)}get scrollOptions(){return p(uy,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=Tn(this.contentElement);e&&e0.forEach((i,o)=>{i.unbind(e),i.containers.size===0&&(this.handleBaseListenerDestroy(i),e0.delete(o))})}}function sN(){return new oN}const Qp=I("column-width");function lN(n,t,e){mO(n,t).style.width=`${e}px`}function aN(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const r=Lt.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)}),Qp.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],x=(d-C)/(c-h);for(let v=h+1;v<c;v++)i[v]=C+x*(v-h)}Qp.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 Qp.debug(`widths: ${s.join()}`),s}function Nu(n){return Array.from(n.querySelector("colgroup").children).map(r=>r.getBoundingClientRect().width||Number.parseInt(r.style.width,10))}const Yp=200,cN=40,uN=I("table-resize-gripper"),fy=7,Zp=(fy-1)/2,fN=3;function dN(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)<=Zp&&d.top<=e&&e<=d.bottom)return c}}return null}function hN(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Jp(n,t){return xi(n,t).querySelector(".table-resize-gripper")}function dy(n,t){const e=Jp(n,t);p(uN,!e,"resize gripper has already exists");const r=xi(n,t),i=B("div",["table-resize-gripper","table-indicator"],r);return B("div",["table-resize-gripper-indicator"],i),i}function hy(n,t,e){let r=Jp(n,t);r||(r=dy(n,t));const o=Me(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=o.height,d=n.getCustom(Ai(t)).contentElement.getBoundingClientRect(),h=s.right-d.left;r.style.left=`${h-Zp-_a-Iu}px`,r.style.top=`${l}px`,r.style.height=`${c}px`,r.style.width=`${fy}px`}function tC(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function mN(n,t,e){const i={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,i)}function gN(n,t,e,r){const i=t,o=Lt.fromTable(e),s=o.getCellByCellElement(i),l=s.col+s.colSpan-1,c=Nu(e);let d=r;const h=(E,x)=>{const v=x+1,R=E.col+E.colSpan;return c.slice(v,R).reduce((M,U)=>M+U,0)},C=new Set;for(let E=0;E<o.rowCount;E++){const x=o.getCell({row:E,col:l});if(C.has(x.cell))continue;C.add(x.cell);const v=x.cell,R=v.getBoundingClientRect();let L=r-R.left+Zp-fN;const M=wu(v),U=Fg(n,M)||cN*x.colSpan,F=h(x,l),G=U-F;L<G&&(L=G);const q=R.left+L;d=Math.max(d,q)}return d}const pN=I("table-resize-drag-drop");class CN{constructor(t,e,r,i){g(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=gN(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;p(pN,c,"no dragging cell");const E=Lt.fromTable(s).getCellByCellElement(c),x=E.col+E.colSpan-1,v=Nu(s),R=v.slice(0,x).reduce((M,U)=>M+U,0),L=h-R;if(lN(s,x,L),L){const M=parseFloat(s.style.width);s.style.width=`${M+(L-v[x])}px`}hy(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,r,i,o){const s=Nu(t.data.table);mN(this.editor,t.data.block,s),tC(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function EN(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const r=nt(e);return!r||!n.contains(r)||!He(r)?null:r}I("table-resize");class AN{constructor(t){g(this,"draggingRefCell",null);g(this,"handleMouseMove",(t,e)=>{if(t.readonly||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const r=e.target;if(!(r instanceof Element)||r.closest(".table-indicator"))return;const o=e,s=EN(t,o);if(!s||!$T(s)||!t.isBlockWritable(s)){tC(t);return}this.updateGripper(s,o.x,o.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=Me(t),o=dN(i,e,r);if(o){if(!Jp(this.editor,t)){if(hN(this.editor))return;const l=dy(this.editor,t),c={block:t,table:i,draggingRefCell:o};Cg(new CN(this.editor,l,c,d=>{this.updateGripper(t,d.x,d.y)}))}hy(this.editor,t,o)}else tC(this.editor)}}function my(n){n.addCustom("table-mouse-event-handler",t=>new AN(t))}const gy=I("table-insert-column");function py(n,t,e){n.undoManager.runInGroup(()=>{var E;const r=Me(t),i=Lt.fromTable(r),o=i.colCount;p(gy,e>=0&&e<=o,`insert index ${e} is out of range [0, ${o}]`);const s=i.map(x=>x.containerId),l=new Set;n.doc.beginBatchUpdate();for(let x=0;x<s.length;x++){const v=s[x],R=v[e-1],L=v[e];if(e===0||e===v.length||R!==L){const M=no(n.doc);v.splice(e,0,M)}else v.splice(e,0,R),l.add(R)}n.doc.endBatchUpdate();const c=gt.default(n.getBlockData(t));l.forEach(x=>{const v=`${x}_colSpan`,R=c[v];p(gy,typeof R=="number"&&R>1,`no colSpan for containerId ${x}, ${R}`),c[v]=R+1});const d=((E=c.colsWidth)==null?void 0:E.concat())||new Array(c.cols).fill(0);d.splice(e,0,Yp);const h=Lt.virtualCellContainersGridToChildren(s),C={...c,cols:c.cols+1,children:h,colsWidth:d};il(C),n.updateBlockData(t,C)})}const n0=I("table-insert-row");function eC(n,t,e){n.undoManager.runInGroup(()=>{const r=Me(t),i=Lt.fromTable(r),o=i.rowCount;p(n0,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 x=e>0&&s[e-1][E],v=e<i.rowCount&&s[e][E];if(p(n0,x||v,"no top and bottom cell"),e===0||e===i.rowCount||x!==v){const R=no(n.doc);c.push(R)}else p(n0,x,"no top cell"),c.push(x),l.add(x)}n.doc.endBatchUpdate(),s.splice(e,0,c);const d=gt.default(n.getBlockData(t));l.forEach(E=>{const x=`${E}_rowSpan`,v=d[x];p(n0,typeof v=="number"&&v>1,`no rowSpan for containerId ${E}, ${v}`),d[x]=v+1});const h=Lt.virtualCellContainersGridToChildren(s),C={...d,rows:d.rows+1,children:h};il(C),n.updateBlockData(t,C)})}const nC=I("paste-table-in-table-block");function xN(n,t,e,r,i){let o=Lt.fromBlock(e);const s=t.blocks.root[0];p(nC,s,"no table data"),p(nC,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,x=C+d,v=E+h,R=[];for(let L=C;L<x&&L<o.colCount;L++)for(let M=E;M<v&&M<o.rowCount;M++){const U=o.getCell({col:L,row:M});U.virtual?U.virtual&&R.push({col:L,row:M}):(U.colSpan>1||U.rowSpan>1)&&R.push({col:L,row:M})}n.undoManager.runInGroup(()=>{if(n.doc.beginBatchUpdate(),R.forEach(F=>{const G=Lt.fromBlock(e).getCell(F);(G.colSpan>1||G.rowSpan>1)&&$p(n,e,F)}),x>o.colCount)for(let F=o.colCount;F<x;F++)py(n,e,F);if(v>o.rowCount)for(let F=o.rowCount;F<v;F++)eC(n,e,F);o=Lt.fromBlock(e);const L=new qh(l);let M;for(let F=0;F<L.colCount;F++)for(let G=0;G<L.rowCount;G++){const q=L.getCell({col:F,row:G});if(!q.virtual){const rt=I1(n.editorBlocks,t,q.containerId,i),at=C+F,At=E+G,Mt={col:at,row:At},kt=o.getCellContainer(Mt);TB(n,kt,rt,i),M=kt}}n.doc.endBatchUpdate(),p(nC,M,"no last container");const U=Ze(M);n.selection.selectBlock(U,dt(n,U))})}const rC=I("paste-in-table-block");class bN{constructor(t){g(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,x,v,R;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=it(i);if(Qt(o))return this.pasteData=void 0,!1;if(!Jc(t,o))return this.pasteData=void 0,!1;const s=nt(o);if(p(rC,s,"no parent block"),!He(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;rC.debug("paste child table in table");const d=Lt.fromBlock(s).getCellByContainerId(ft(o)).cell;W1(t,e);const h={blockIdMap:new Map,containerIdMap:new Map,boxIdMap:new Map};xN(t,e,s,d,h),p(rC,this.pasteData,"invalid paste data");const C=[];t.input.forEach(L=>{C.push(L)});for(let L=0;L<C.length&&!await((x=(E=C[L]).handleAfterPasteDoc)==null?void 0:x.call(E,t,e,h));L++);for(let L=0;L<C.length&&!await((R=(v=C[L]).handleAfterPaste)==null?void 0:R.call(v,t,this.pasteData.event,this.pasteData.doc));L++);return this.pasteData=void 0,!0}}function Cy(n){n.addCustom("table-block-paste-event",t=>new bN(t))}const iC=I("table-select-columns");function vN(n,t,e,r,i){p(iC,He(t),"is not a table block");const o=Lt.fromBlock(t);p(iC,e>=0&&e<o.colCount,"invalid from"),p(iC,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=Ee(t,s.containerId,{colIndex:e,rowIndex:0}),d=Ee(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 oC=I("table-select-columns");function BN(n,t,e,r,i){p(oC,He(t),"is not a table block");const o=Lt.fromBlock(t);p(oC,e>=0&&e<o.rowCount,"invalid from"),p(oC,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=Ee(t,s.containerId,{rowIndex:e,colIndex:0}),d=Ee(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 Lst="",Ey=I("get-toolbar-reference-client");function Ay(n,t){const e=n.selection.range;if(!e.isSimple()){p(Ey,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);p(Ey,_t(n,s),"not a complex block");const l=Zt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const r=e.isReverse()?t.start:t.end,i=We(n,{anchor:r,focus:r}),o=qi(n,t.block,i);if(o.length!==0)return o[0]}function TN(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 r0(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=ag.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=r0(i),TN(s))}),e}function i0(n){return n.findCustom("toolbar-handler")}const Ist="";class yN{constructor(){g(this,"linkPopup",null);g(this,"form",{});g(this,"onFinished",null);g(this,"onClose",null);g(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:r}=this.form,i=this.formatUrl(r.getInputValue());(t=this.onFinished)==null||t.call(this,e.getInputValue()||i,i),this._destroy()}catch{}});g(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});g(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});g(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector('[data-button-id="submit-button"]');t.disabled=!1});g(this,"handleTextKeyboard",t=>{var e;if(!t.isComposing){if(t.key==="Enter"){(e=this.form.linkUrl)==null||e.getField().focus(),t.stopPropagation();return}t.key==="Escape"&&this.handleClose()}});g(this,"handleUrlKeyboard",t=>{if(!t.isComposing){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(D.t("link.urlPlaceholder")),new Error(D.t("link.urlPlaceholder"))}formatUrl(t){if(!t)return"";try{new URL(t)}catch{return`${window.location.protocol}//${t}`}return t}editLink(t){var h,C;const{target:e,linkText:r,linkUrl:i,onFinished:o,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new Sa(this.createPopupContent(r,i)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:l}),this.onFinished=o,s&&(this.onClose=s);const c=(h=this.linkPopup)==null?void 0:h.content.querySelector('[data-button-id="submit-button"]'),d=(C=this.linkPopup)==null?void 0:C.content.querySelector('[data-button-id="cancel-button"]');c==null||c.addEventListener("click",this.handleOk),d==null||d.addEventListener("click",this.handleClose)}createPopupContent(t,e){const r=B("div",["link-popup-content"],null);this.form.linkText=Wh(r,{label:D.t("link.textLabel"),required:!1,placeholder:D.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Wh(r,{className:"link-popup-gap",label:D.t("link.urlLabel"),required:!0,placeholder:D.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const i=B("div",["link-popup-footer"],r),o=Cr("cancel-button",D.t("link.cancelText"));i.appendChild(o);const s=Cr("submit-button",D.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 Pu(n,t){n.addCustom("link-editor",()=>new yN).editLink(t)}const kN=I("link-popup");function RN(n){return Rt(n,"link")}function Fu(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function wN(n,t,e){var i,o,s,l;if(n.isBlockWritable(t)&&e&&hr(e)){const c=e,d=(o=(i=n.editorBoxes.getBoxClass(Xc(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&&et(n,t)&&RN(e)){const c=B("a",["link-href-button"],null,Fu(e));c.href=Fu(e),c.target="_blank",c.rel="noopener noreferrer";const d=[{id:"link-text",name:Fu(e),disableTooltip:!0,element:c},{id:"edit-link",name:D.t("link.edit"),icon:jh},{id:"remove-link",name:D.t("link.remove"),icon:H2}];return{element:e,commands:d}}return pv(n,t,"hovering-toolbar")}function xy(n,t,e){var l;const r=$o(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 SN(n,t,e){const[r,i]=xy(n,t,e);n.selection.selectBlock(t,r.start,r.end);const o=Fu(e),s=(h,C)=>{try{const E=n.getBlockText(t),x=a1(E,r.start,r.end-r.start),v=to(x,r.start,h,{link:C});n.setBlockText(t,v),n.selection.selectBlock(t,r.start+h.length),n.focus()}catch(E){kN.error(E)}},l=()=>{n.selection.selectBlock(t,r.end),n.focus()},c=qi(n,t,n.selection.range)[0];if(!c)return;const d=Yi(n,t,"link-button-anchor",c);Pu(n,{target:d,linkText:i,linkUrl:o,onFinished:s,onClose:l})}function LN(n,t,e){const[r]=xy(n,t,e),i=n.getBlockText(t),o=Fu(e),s=fa(r.start,r.end-r.start,i,"link",o);n.setBlockText(t,s),n.selection.selectBlock(t,r.end)}function IN(n,t,e,r){var s,l,c;if(e){if(n.isBlockWritable(t)&&hr(e)){const h=e,C=(l=(s=n.editorBoxes.getBoxClass(Xc(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=i0(n);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},400),r.id==="edit-link"?SN(n,t,e):r.id==="remove-link"&&LN(n,t,e);return}const i=gv(n,t);if(!i)return;const o=(c=i.blockCommands)==null?void 0:c["hovering-toolbar"];!o||o.executeCommand(n,t,r)}function o0(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const DN=[Mh,Uh,Oh,Nh,Ph,Fh,Kh,Vh];class _N{constructor(t){g(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=o0();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,r){if(et(t,e)){const i=st(e),o=It(e),s=Ir(t,e),c=t.getBlockData(e).heading,d=[];for(let C=0;C<this.getHeadingIndex();C++)d.push({id:`heading-${C+1}`,name:D.t("commands.heading",{name:`${C+1}`}),icon:DN[C],states:c===C+1?["checked"]:[],value:`${C+1}`});const h=C=>{var x;const E=B("span",["toolbar-item-name-container"],null);for(const v of C.children)if((x=v.states)!=null&&x.includes("checked"))return E.innerHTML=v.icon||Ra,E;return E.innerHTML=Ra,E};return[{id:"turn-into",name:D.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:D.t("commands.text"),icon:Ra,states:c?[]:["checked"]},...d],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,r){t.updateBlockData(e,{heading:r})}executeCommand(t,e,r,i){if(et(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 MN=8,we=I("list-block"),s0=I("list-block");function Kt(n){return It(n)==="list"}function Ue(n){p(s0,Kt(n),"not a list block")}function Zn(n){Ue(n);const t=n.getAttribute("data-list-type");return p(s0,t,"no list type"),t}function l0(n){return Kt(n)&&Zn(n)==="text-only"}function Jn(n){var t,e;return Ue(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function nn(n){var t,e;return Ue(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Na(n){Ue(n);const t=n.getAttribute("data-list-group-id");return p(s0,t,"no group id"),t}function ts(n){var o,s,l,c,d;Ue(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(s0,i,"no group id"),{type:t,start:e,level:r,groupId:i}}function sC(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 UN(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 ON="abcdefghijklmnopqrstuvwxyz";function by(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),r=ON[t];return e?by(e)+r:r}function NN(n){return`${n}`}const vy=[NN,by,UN];function PN(n,t){const e=vy[(n-1)%vy.length];return e(t)}function FN(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}function es(n,t){Ue(n);const{level:e,groupId:r,type:i}=ts(n);let o=me(n);for(;o;){if(!Kt(o))return null;const{level:s,groupId:l,type:c}=ts(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=me(o)}return null}function By(n){return es(n,{ignoreGroupId:!0})}function ll(n){Ue(n);const{level:t,groupId:e,type:r}=ts(n);let i=Gt(n);for(;i;){if(Kt(i)){const{level:o,groupId:s,type:l}=ts(i);if(t===o&&e===s&&(l==="text-only"||r==="text-only"||r===l))return i;if(o<t)return null}i=Gt(i)}return null}function Ty(n){Ue(n);const t=[];let e=es(n);for(;e;)t.unshift(e),e=es(e);return t}function Pa(n){Ue(n);const t=[];let e=ll(n);for(;e;)t.push(e),e=ll(e);return t}function Ku(n){Ue(n);let t=es(n);for(;t;){const e=es(t);if(!e)return t;t=e}return n}function KN(n){Ue(n);let t=ll(n);for(;t;){const e=ll(t);if(!e)return t;t=e}return null}function yy(n,t){const e=Ty(n),r=Pa(n);return t.withSelf?[...e,n,...r]:[...e,...r]}function a0(n){Ue(n);let t=n;const e=Ty(n);e.length>0&&(t=e[0]);const r=me(t);return!r||!Kt(r)?null:nn(r)<nn(t)?r:null}function VN(n,t){Ue(n);let e=n;for(;e;){const r=nn(e);if(r===t)return e;if(r>t)e=a0(e);else if(r<t)return null}return null}function $N(n){let t=Ku(n);for(;;){const e=a0(t);if(!e)return t;t=Ku(e)}}class HN{constructor(){g(this,"nodeMap",new Map);g(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 ky(n,t){const e=$N(t),r=new HN;r.addNode(null,e);let i=Gt(e);for(;i&&Kt(i);){if(l0(i)){r.addNode(null,i),i=Gt(i);continue}if(nn(i)===0&&Zn(i)!==Zn(e))break;const s=a0(i);r.addNode(s,i),i=Gt(i)}return r.rootNodes}function jN(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 Ry(){const e=(document.exitFullscreen||document.webkitExitFullscreen).bind(document)();try{document.fullscreenElement=null}catch{}return e}function lC(n){return Rt(n,"editor-in-mindmap-first")}function aC(n){if(p(we,Kt(n),"not a list block"),Rt(n,"editor-in-mindmap-first")||!qc(n))return!0;const t=n.classList,e="editor-mindmap-root-";return!!Array.from(t).find(i=>{if(i.startsWith(e))return i})}function zN(n,t,e){const r=it(n);if(t){const s=it(t);p(we,r===s,"invalid block container")}const i=bt(n);if(t){const s=bt(t);p(we,i<=s,"invalid block index")}if(z(n,...e),!t||t===n)return;let o=Gt(n);for(;o!==t;)p(we,o,"no next button"),z(o,...e),o=Gt(o);o&&z(o,...e)}function GN(n){const t=`editor-mindmap-root-${n.id}`,r=it(n).querySelectorAll(`.${t}`);return r[r.length-1]}async function WN(n,t,e){const r=ne(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=()=>{ot(r,"fullscreen"),i.innerHTML=Ip,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,D.t("mindmap.fullScreen")),aC(t)&&setTimeout(()=>{o()},300)};if(document.fullscreenElement===r){try{await Ry()}catch(l){we.error(l)}s()}else{try{z(r,"fullscreen"),await jN(r),o()}catch(l){we.error(l)}i.innerHTML=yT,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,D.t("mindmap.exitFullscreen"))}r.onfullscreenchange=()=>{document.fullscreenElement||s()}}function cC(n,t,e,r,i){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=Cr(e,r,i,[]);return s.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,r),z(s,"mindmap-button"),t.appendChild(s),s}function uC(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function qN(n){return uC(n,"mindmap-fullscreen")}function XN(n){return uC(n,"mindmap-fit")}function QN(n){return uC(n,"mindmap-close")}function YN(n,t,e,r){const i=cC(n,t,"mindmap-close",D.t("mindmap.close"),Dh);!i||n.domEvents.addEventListener(i,"click",()=>{r.closeMindmap(n,e)})}function ZN(n,t,e,r){const i=cC(n,t,"mindmap-fit",D.t("mindmap.autoFit"),TT);!i||n.domEvents.addEventListener(i,"click",()=>{r.fitMindmap(n,e)})}function JN(n,t,e,r){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const o=cC(n,t,"mindmap-fullscreen",D.t("mindmap.fullScreen"),Ip);!o||n.domEvents.addEventListener(o,"click",()=>{WN(n,e,r)})}function tP(n,t){const e=_d(t);if(!e)return;const r=XN(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=QN(e);i&&(i.remove(),n.domEvents.removeAllListeners(i));const o=qN(e);o&&(o.remove(),n.domEvents.removeAllListeners(o))}const Fa=new Map;function fC(n,t,e){const r=(s,l)=>{s.forEach(c=>{l?z(c.block,"to-mindmap-highlight"):ot(c.block,"to-mindmap-highlight"),r(c.children,l)})},i=ky(n,t);if(i.length===0)return;const o=i[0].block;if(e){const s=Fa.get(o);s&&(s.forEach(l=>l.cancel()),Fa.delete(o)),r(i,!0)}else{const s=setTimeout(()=>{r(i,!1),Fa.delete(o)},300),l=()=>{clearTimeout(s),Fa.delete(o)},c=Fa.get(o);c?c.push({cancel:l}):Fa.set(o,[{cancel:l}])}}const{Markmap:eP}=u6;function nP(n,t){Ue(t);const e=ky(n,t),r=e[0].block,i=d=>({t:"text",v:Ot(d.block).textContent,d:1,c:d.children.length>0?d.children.map(C=>i(C)):void 0});let o=null;e.length>1?o={t:"root",v:"root",d:0,c: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 c0(n,t,e,r){const{root:i,block:o,last:s}=nP(n,t);r.selectBlock&&n.selection.selectBlock(o,0,0),fC(n,o,!1),r.saveData&&n.updateBlockData(o,{viewAsMindmap:!0});const l=ne(o);let c=l.querySelector(".editor-mindmap-svg");if(r.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const M="http://www.w3.org/2000/svg",U=l.getBoundingClientRect(),F=document.fullscreenElement===l,G=F?`${U.width}`:`${t.getBoundingClientRect().width}`,q=F?`${U.height}`:"600",rt=document.createElementNS(M,"svg");rt.setAttributeNS(null,"viewBox",`0 0 ${G} ${q}`),rt.setAttributeNS(null,"width","100%"),rt.setAttributeNS(null,"height",q),rt.style.display="block",rt.style.width="100%",rt.style.height=`${q}px`,rt.classList.add("editor-mindmap-svg"),l.appendChild(rt),c=rt}const d=o,C=`editor-mindmap-root-${st(o)}`;z(d,"editor-in-mindmap-first",C,"readonly"),d.contentEditable="false";const E=Gt(o);E&&bt(E)<=bt(s.block)&&zN(E,s.block,["block-hidden",C]);const x=(M,U)=>{if(U.length>0){const F=U[0].parentElement;F&&(F.style.width="100vw",F.style.maxWidth="200px")}U.forEach(F=>{z(F,"editor-mindmap-node")})},v=new eP(c,{...e,autoFit:!0});v.viewHooks.transformHtml.tap(x),v.setData(i),v.fit();const R=ne(o);let L=R.querySelector(".mindmap-toolbar");L||(L=B("div",["mindmap-toolbar"],R)),ZN(n,L,d,r.mindmapTools),JN(n,L,d,r.mindmapTools),YN(n,L,d,r.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(o,0),n.input.focus()}),d.mindMap=v}function rP(n){const t=B("div",["list-to-mindmap-wrap"],null),e=Cr("list-to-mindmap",D.t("mindmap.viewAsMindMap"),BT,[],n.clientId);return t.appendChild(e),t}async function wy(n,t){const e=`editor-mindmap-root-${t.id}`,r=it(t);Ce(r).forEach(l=>{Rt(l,e)&&ot(l,e,"editor-in-mindmap-first","block-hidden")});const o=ne(t);document.fullscreenElement===o&&await Ry();const s=o.querySelector(".editor-mindmap-svg");!s||(p(we,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),tP(n,t))}function iP(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(i=>{if(i.startsWith(e))return i})}async function Sy(n,t){!iP(t)||(n.updateBlockData(t,{viewAsMindmap:null}),wy(n,t),n.selection.selectBlock(t,0))}function oP(n,t){const e=t.mindMap;e&&e.fit()}const u0={toMindmap:c0,closeMindmap:Sy,fitMindmap:oP},Dst="";class f0{constructor(t){g(this,"toMindmapButton");g(this,"currentBlock",null);g(this,"handleHoveringBlock",t=>{t&&Kt(t)&&Zn(t)!=="unchecked"&&Zn(t)!=="checked"&&this.editor.isWritable()?ne(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove()});g(this,"handleMouseEnter",()=>{const t=nt(this.toMindmapButton);p(we,t&&Kt(t),"no parent list"),fC(this.editor,t,!0),this.currentBlock=t});g(this,"handleMouseLeave",()=>{this.currentBlock&&(fC(this.editor,this.currentBlock,!1),this.currentBlock=null)});g(this,"handleClick",()=>{const t=nt(this.toMindmapButton);p(we,t&&Kt(t),"no parent list"),c0(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:u0})});this.editor=t,be.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=rP(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(f0)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}function sP(n,t,e){var r;t==="beginDrag"&&((r=f0.get(n))==null||r.hide())}function Ka(n,t,e,r){var o;const i=(o=r==null?void 0:r.groupId)!=null?o:J();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 dC(n,t,e,r){const i=yy(t,{withSelf:!0});i.length!==0&&Ka(n,i,e,r)}class d0{constructor(t,e){g(this,"listStart",0);g(this,"listBrother",null);if(this.editor=t,l0(e))return;const r=Ku(e),i=Jn(r);this.listStart=i,r===e?this.listBrother=ll(r):this.listBrother=r}fix(){!this.listBrother||dC(this.editor,this.listBrother,this.listStart)}}class al{constructor(t,e,r){g(this,"listStart");g(this,"listBrother",null);this.editor=t,this.options=r;const i=Ku(e),o=Jn(i);this.listStart=o,this.listBrother=i,r!=null&&r.resetStart&&(this.listStart=1)}fix(){!this.listBrother||dC(this.editor,this.listBrother,this.listStart,this.options)}}class Ly{constructor(t,e,r){g(this,"listStart");g(this,"listNextBrothers",[]);this.editor=t,this.listNextBrothers=Pa(e);const{start:i,resetStart:o}=r||{};this.listStart=o?1:i!=null?i:1}fix(){!this.listNextBrothers.length||Ka(this.editor,this.listNextBrothers,this.listStart)}}function lP(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function hC(n,t,e,r){if(we.debug("drag a block on a list block"),!et(n,t))return!1;p(we,Kt(e),"target is not a list block");const{type:i,start:o,level:s,groupId:l}=ts(e),c=r==="after"?o+1:o,d=n.getBlockData(t),h={id:J(),type:"list",groupId:l,level:s,start:c,text:d.text,...sC(i)};lP(n,e,h);let C=bt(e);const E=it(e);r==="after"&&(C+=1);let x=null;Kt(t)&&(x=new d0(n,t));const v=n.insertBlock(ft(E),C,h,th(h.id,0));return n.deleteBlock(t),new al(n,v).fix(),x==null||x.fix(),!0}function aP(n,t,e,r){if(we.debug("drag a list between text blocks"),r==="after"){const d=Gt(e);if(d&&Kt(d))return hC(n,t,d,"before")}if(r==="before"){const d=me(e);if(d&&Kt(d))return hC(n,t,d,"after")}const o={...n.getBlockData(t),groupId:J(),start:1,level:1};let s=bt(e);const l=it(e);r==="after"&&(s+=1),n.insertBlock(ft(l),s,o,th(o.id,0));const c=new d0(n,t);return n.deleteBlock(t),c.fix(),!0}function cP(n,t,e,r,i){if(wd(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,Kt(c),"target is not a list block"),hC(n,s,c,r)):aP(n,s,c,r)}function Iy(n,t){if(!n.isWritable())return!1;const e=n.selection.range,i=n.editorCommandProviders.getCommands(e).find(o=>o.id===t);return i?(n.editorCommandProviders.executeCommand(e,i,{}),!0):!1}const uP={"Shift+CtrlOrCmd+L":n=>Iy(n,"unordered-list"),"Shift+CtrlOrCmd+U":n=>Iy(n,"ordered-list")};function h0(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function fP(n,t){let e;const r=h0(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 Dy(n,t){const e=h0(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 mC(n){return n.readonly||!n.isWritable()}function dP(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;et(n,r)&&fP(n,r)}),!0}function hP(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;et(n,r)&&Dy(n,r)}),!0}function mP(n){return mC(n)?!1:n.undoManager.runInGroup(()=>(dP(n),!0))}function gP(n){return mC(n)?!1:n.undoManager.runInGroup(()=>(hP(n),!0))}function pP(n){if(mC(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!et(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!h0(t)))return Dy(n,t),!0}class gC{renderBlock(t,e,r){const{padding:i}=r;return i?{attributes:{"block-padding-level":i}}:{}}}const _st="",CP={Tab:mP,"Shift+Tab":gP,Backspace:pP};function EP(n,t,e=1){if(!t)return null;let r=me(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 Kt(r)?r:null}r=me(r)}return null}function AP(n,t){const e=n.getAttribute("data-style-heading"),r=EP(n,e);if(r)return r;const i=me(n);if(i&&Kt(i)&&Zn(i)===t)return i;const o=Gt(n);return o&&Kt(o)&&Zn(o)===t?o:null}function xP(n,t,e){var R,L,M;const r=(R=e.data)!=null?R:{};let i=1;if(Kt(t))i=nn(t);else{const U=h0(t);U&&(i=U+1),i>8&&(i=8)}const o=(L=r.listType)!=null?L:"ordered";if(o==="text-only")return null;const s=n.getBlockData(t);let l=(M=s.text)!=null?M:[],d=ce(l);const h=e.offset||0;h<=fn(l)&&(l=In(l,h).right,d=d.substring(0,h));let C=1;o==="ordered"&&(C=Number.parseInt(d,10)||1);let E=J();const x=AP(t,o);if(x)if(nn(x)===i){if(bt(t)>bt(x))C=Jn(x)+1;else{const U=Jn(x);U>1&&(C=U-1),new Ly(n,x,{start:C+1}).fix()}E=Na(x)}else{const U=VN(x,i);U&&(C=Jn(U)+1)}else Kt(t)&&new Ly(n,t,{start:1}).fix();const v={id:J(),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:(U,F)=>{new al(U,F).fix()}}}function Va(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function bP(n){var e,r;if(n.checkbox)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${PN(t,(r=n.start)!=null?r:1)}.`:FN(t)}function m0(n){return n==="checked"||n==="unchecked"}function _y(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=Va(i),d=Va(l);return c!==d&&(!m0(c)||!m0(d))||(i.level||1)>(l.level||1)}function My(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=Va(i),d=Va(l);return c!==d&&(!m0(c)||!m0(d))||(i.level||1)>(l.level||1)}function vP(n,t,e,r,i){var s,l,c;const o=t;if(r==="text")return((s=Mn.convertTo)==null?void 0:s.call(Mn,n,t,e,"text",i))||"";if(r==="markdown"){let d=((l=Mn.convertTo)==null?void 0:l.call(Mn,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,_y(n,t,e,i)&&(d=`${d}`),My(n,t,e,i)&&(d=`${d}`,h<=1&&(d+=`
|
|
610
610
|
`)),d}if(r==="html"){let d=((c=Mn.convertTo)==null?void 0:c.call(Mn,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 _y(n,t,e,i)&&(d=`<${h}${C?` style="${C}"`:""}>${d}`),My(n,t,e,i)&&(d=`${d}</${h}>`),d}return""}function Uy(n){const t=B("label",["editor-check-list-wrapper"],null);n&&z(t,"editor-check-list-wrapper-checked");const e=B("span",["editor-check-box"],t);return B("span",["editor-check-box-inner"],e),t}function BP(n,t){const e=Va(t);if(!(e==="text-only"&&!t.level)){if(e==="checked"){n.append(Uy(!0));return}if(e==="unchecked"){n.append(Uy(!1));return}n.innerText=bP(t)}}function TP(n){const t=B("div",["list-container"],null),e=B("button",["list-marker"],t);return BP(e,n),t}function $a(n,t){Ue(t);const e=n.getBlockData(t),r={id:J(),type:"text",text:e.text};e.heading&&(r.heading=e.heading),e.heading&&(r.heading=e.heading);const i=new d0(n,t),o=it(t),s=bt(t);n.deleteBlock(t);const l=th(r.id,0);if(Jc(n,o)&&!Qt(o)){const c=ke(o);n.insertBlock(ft(o),s,r,l),n.deleteBlock(c)}else n.insertBlock(ft(o),s,r,l);i.fix()}function yP(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Kt(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:($a(n,t),!0)}function Oy(n){let t=Gt(n);if(!t)return null;const e=ll(n);for(;t!==e;){if(p(we,t,"no next block"),Kt(t))return nn(t)>nn(n)?t:null;if(t=Gt(t),!t)return null}return null}function pC(n){const t=[];let e=Oy(n);if(!e)return t;for(;e;){const r=ll(e);t.push({block:e,children:pC(e)}),e=r}return t}function kP(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 Ny(n,t){return nn(t)!==1}function Py(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&&Py(n,r.children,i.groupId)})}function CC(n,t){if(!Ny(n,t))return!1;const e=nn(t);if(e===1)return!1;let r=J(),i=1,o=Zn(t);const s=e-1,l=a0(t);l&&(r=Na(l),i=Jn(l)+1,o!=="text-only"&&(o=Zn(l)));const c=pC(t),d=n.getBlockData(t),h={...d,groupId:r,level:s,start:i,...sC(o)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),Py(n,c,d.groupId),n.doc.endBatchUpdate(),new al(n,t).fix();const E=Oy(t);return E&&new al(n,E,{resetStart:!0,resetGroupId:!0}).fix(),!0}const RP=I("list-block");function wP(n,t,e){p(RP,Kt(t),"not a list block");const r={...n.getBlockData(t),id:J()};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 SP(n){if(Ue(n),!l0(n))return n;let t=es(n);for(;t;){if(!l0(t))return t;t=es(t)}return null}function LP(n,t,e,r){const i=new al(n,r),o=Jn(r)+1;Ea(n,t,e,{forceInsertAfter:!0,newBlockData:wP(n,r,{start:o})}),i.fix()}function IP(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Kt(l)&&dt(n,l)===0)return nn(l)===1?$a(n,l):CC(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Kt(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const r=e.offset,o=(s=r===dt(n,t)?SP(t):t)!=null?s:t;return LP(n,t,r,o),!0}function Fy(n){p(we,Kt(n),"not a list block");const{level:t}=ts(n);let e=me(n);for(;e;){if(Kt(e)){const{level:r}=ts(e);if(t===r)return e;if(r<t)return null}e=me(e)}return null}function Ky(n,t){return Ue(t),Fy(t)?nn(t)<MN:!1}function DP(n,t,e){let r=me(t);p(we,r,"no prev brother");const i=nn(e);for(;r;){if(r===e)return null;if(Kt(r)&&nn(r)===i+1)return r;r=me(r)}return null}function Vy(n,t){if(!Ky(n,t))return!1;Ue(t);const e=Fy(t);p(we,e,"no list prev brother");const r=e,i=DP(n,t,r),o=nn(r)+1;let s=J(),l=1,c=Zn(t);i&&(s=Na(i),l=Jn(i)+1,c=Zn(i));const d=pC(t),C={...n.getBlockData(t),groupId:s,level:o,start:l,...sC(c)};return n.updateBlockData(t,C),n.doc.beginBatchUpdate(),kP(d).forEach(x=>{const v=n.getBlockData(x);n.updateBlockData(x,{...v,level:(v.level||1)+1})}),n.doc.endBatchUpdate(),!0}function _P(n,t,e){return t.length===0||!t.every(r=>Kt(r.block))?!1:e==="increase"?Ky(n,t[0].block):Ny(n,t[0].block)}function $y(n,t,e){if(!_P(n,t,e))return!1;const r=t[0].block,i=nn(r),o=t.filter(d=>nn(d.block)<=i),s=yy(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 al(n,c[0])),o.forEach(h=>{e==="increase"?Vy(n,h.block):CC(n,h.block)}),d==null||d.fix()}),!0}function MP(n,t){return Vy(n,t)}function UP(n,t){return CC(n,t)}function OP(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return $y(n,t,"increase"),!0;const e=t[0].block;if(!Kt(e))return!1;const r=new d0(n,e);return MP(n,e)&&(r.fix(),new al(n,e).fix()),!0}function NP(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return $y(n,t,"decrease"),!0;const e=t[0].block;return Kt(e)?(UP(n,e),!0):!1}class PP{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const r=t.selection.range.getSelectedBlocks();if(r.length===0||!r.some(o=>Kt(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||!Kt(e.block)||li(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>IP(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>yP(this.editor))}handleTab(t){return li(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>NP(this.editor)):this.editor.undoManager.runInGroup(()=>OP(this.editor))}}class FP{constructor(t){g(this,"effectedBlockIds",new Map);g(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;Kt(o)&&e.add(o)});const r=new Map;Array.from(e.values()).forEach(i=>{var c;const o=Ku(i),{start:s}=ts(o);r.set(st(o),s);const l=(c=KN(i))!=null?c:i;r.set(st(l),s)}),this.effectedBlockIds=r});g(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const r=this.editor.findBlockById(t);!r||dC(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 KP=I("customize-list-start-menu");class VP{constructor(t){g(this,"popup");g(this,"block",null);g(this,"show",(t,e)=>{const r=e.querySelector("div.list-container");p(KP,r,"list-block mark does not exist"),this.block=e,this.popup.manualShow(r,{theme:"light"})});g(this,"createDialogContent",()=>{const t=B("div",["customize-start-panel"],null);B("span",["customize-start-panel-title"],t,D.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const r=B("button",["customize-start-panel-button"],t,D.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(r,"click",this.handleOk),t});g(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=Jn(t);!r||!i||requestAnimationFrame(()=>{i.focus(),i.value=String(o)})});g(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(()=>{Ka(this.editor,[r,...Pa(r)],i,{resetGroupId:!0})}),this.popup.close("clickItem"))});g(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 Sa(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 $P(n,t){return Na(n)===Na(t)}function HP(n,t){const e=By(t);return e?$P(e,t)?Jn(e)!==Jn(t)-1:!0:!1}function jP(n,t){return es(t)?!0:Jn(t)!==1}function zP(n,t){return Ue(t),[{id:"continue-numbering",name:D.t("list.continueList"),states:HP(n,t)?[]:["disabled"]},{id:"start-new-list",name:D.t("list.restartList"),states:jP(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:D.t("list.changeNumber")}]}function GP(n,t,e){var r,i;if(Ue(t),e.id==="continue-numbering"){const o=By(t);o&&Ka(n,[t,...Pa(t)],Jn(o)+1,{resetGroupId:!0,groupId:Na(o)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{Ka(n,[t,...Pa(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 VP(n)).show(n,t)}}class WP{constructor(t){g(this,"menu");g(this,"handleClick",(t,e)=>{const r=ra(e,"div.list-container");if(r&&this.editor.isWritable()){const i=nt(r);p(we,i,"no parent block"),Ue(i);const o=t.getBlockData(i);if(o&&o.checkbox){t.updateBlockData(i,{...o,checkbox:o.checkbox==="checked"?"unchecked":"checked"});return}if(Zn(i)==="unordered")return;this.menu.updateItems(this.getCommandItems(i)),this.menu.manualShow(r),this.activeList(r,!0)}});g(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});g(this,"handleMenuClick",(t,e)=>{var i;const r=(i=this.menu.tippyInstance)==null?void 0:i.reference;if(r){const o=nt(r);o&&GP(this.editor,o,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new rl([]),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 zP(this.editor,t)}activeList(t,e){const r=nt(t);!r||(e?(z(t,"active"),z(r,"active")):(ot(t,"active"),ot(r,"active")))}}class qP{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(!Kt(i)||!aC(i))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const o=Vs(i);return o&&t.selection.selectBlock(o,dt(t,o)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const o=$s(i);return o&&t.selection.selectBlock(o,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&Sy(t,i),!0}}function XP(n,t,e,r,i){X1(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new qP(n)),n.input.addHandler(new PP(n)),n.addCustom("list-clear-selection-handler",()=>new FP(n)),n.addCustom("list-marker-menu",()=>new WP(n))})});const o=Mn.createBlockContent(n,t,e,r,i),s=i,{level:l,start:c,groupId:d}=s,h=Va(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=TP(s);return r.insertBefore(C,o),s.viewAsMindmap?setTimeout(()=>{const E=n.getBlockById(i.id);E&&c0(n,E,{},{mindmapTools:u0,saveData:!1})}):setTimeout(()=>{const E=n.getBlockById(i.id);E&&wy(n,E)}),o}const QP={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"}},YP={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"}},ZP={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"}};D.mergeLang({"zh-CN":QP,"en-US":YP,"ja-JP":ZP});const Mst="",Hy={...Mn,blockType:"list",createBlockContent:XP,convertFrom:xP,convertTo:vP,handleDrop:cP,notify:sP},EC=I("paragraph");class JP{constructor(t){g(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){const r=[],i={"unordered-list":[D.t("commands.unordered"),fr("CtrlOrCmd+Shift+L"),O2],"ordered-list":[D.t("commands.ordered"),fr("CtrlOrCmd+Shift+U"),U2],"check-list":[D.t("commands.check"),void 0,N2],link:[D.t("commands.link"),fr("CtrlOrCmd+K"),yp],quoted:[D.t("commands.quote"),void 0,P2]};if(et(t,e)){const o=st(e),s=It(e),l=Ir(t,e),c=t.getBlockData(e);Object.entries(i).forEach(([d,[h,C,E]])=>{const x=[];if(this.isChecked(c,d)&&x.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&x.push("disabled")}r.push({blockId:o,blockType:s,blockKind:l,id:d,name:h,desc:C,states:x,icon:E,groupIndex:600})})}return r}convertLink(t,e,r){p(EC,Or(e.start),""),p(EC,Or(e.start),"");const i="bottom-start",o=e.start.offset,s=e.end.offset,l=(x,v)=>{t.undoManager.runInGroup(()=>{try{const R=t.selection.range.isCollapsed();let L;if(R){L=to(t.getBlockText(r),s,x,{link:v}),t.setBlockText(r,L);return}L=Yd(t.getBlockText(r),o,s,x),L=nu(o,x.length,L,"link",v),t.setBlockText(r,L),t.selection.selectBlock(r,o+x.length),t.focus()}catch(R){EC.error(R)}})},c=()=>{t.selection.selectBlock(r,s),t.focus()},d=qi(t,r,e)[0];if(!d)return;const h=Yi(t,r,"link-button-anchor",d),C=t.getBlockText(r),E=da(C,o);Pu(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=Od(t,e,"list",{offset:0,data:{listType:r}});i&&t.undoManager.runInGroup(()=>{const o=bt(e),s=it(e);t.insertBlock(ft(s),o,i.blockData),t.deleteBlock(e)})}executeCommand(t,e,r,i){var c;if(!et(t,e))return!1;const o=i.id,s=(c=i.states)==null?void 0:c.includes("checked");let l=!1;if(o==="unordered-list"&&(s?$a(t,e):this.convertToList(t,e,"unordered"),l=!0),o==="ordered-list"&&(s?$a(t,e):this.convertToList(t,e,"ordered"),l=!0),o==="check-list"&&(s?$a(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=i0(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 tF={left:ka,right:$h,center:Hh};class eF{constructor(t){g(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,r){Object.keys(tF).includes(r)?t.updateBlockData(e,{align:r}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,r){if(et(t,e)){const i=st(e),o=It(e),s=Ir(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||ka,h;return h.innerHTML=ka,h};return[{id:"align",name:D.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:D.t("commands.alignLeft"),icon:ka,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:D.t("commands.alignCenter"),icon:Hh,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:D.t("commands.alignRight"),icon:$h,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,r,i){if(!et(t,e))return!1;if(i.id.startsWith("align")){const o=i.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,o),!0}return!1}}function jy(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 ou(n,r,e.start.offset).charType==="box"}const nF=I("toolbar-handler"),rF={id:"",name:"",type:"separator"};class Ha{constructor(t){g(this,"toolbar");g(this,"toolbarType","object");g(this,"mouseDown",!1);g(this,"oldRange",null);g(this,"hoveringBlock",null);g(this,"hoveringTextChild",null);g(this,"_disableTextToolbar",!1);g(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.showTextToolbar("click")):this.hoveringBlock&&IN(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});g(this,"handleClose",()=>{Mp(this.editor)&&this.editor.focus()});g(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const r=db(e);if(this.hoveringBlock===r)return!1}return!0});g(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});g(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});g(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)}});g(this,"handleSelectionChange",Ke.default(t=>{var r;if(p(nF,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 ku([],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),be.get(t).addListener("childChange",this.handleHoveringBlockChildChange),be.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new _N(t)),t.editorCommandProviders.registerCommandProvider(new JP(t)),t.editorCommandProviders.registerCommandProvider(new eF(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),be.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.showTextToolbar(t)}showTextToolbar(t){var R,L;if(this._disableTextToolbar||!this.editor.isWritable())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(Re(i.block)){t==="click"&&this.showObjectToolbar(null);return}if(_t(this.editor,i.block)&&e.isSimple())return}if(jy(this.editor))return;if(Gi(i.block)){this.toolbar.close("selectionChange");return}const o=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;o.forEach(M=>{const U=M.groupIndex,F=s.get(U);F?F.push(M):s.set(U,[M])});const l=[[]],c=Array.from(s.entries()).sort((M,U)=>M[0]-U[0]);for(let M=0;M<c.length;M++){const[,U]=c[M];if(U.length===0)continue;let F=l[l.length-1];F.length>0&&F[F.length-1].groupIndex!==U[U.length-1].groupIndex&&(F=[],l.push(F)),F.push(...r0(U))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((M,U)=>{const F=M.sort((G,q)=>{var rt,at;return((rt=G.order)!=null?rt:0)-((at=q.order)!=null?at:0)});d.push(...F),U!==l.length-1&&d.push(rF)}),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,x=Ay(this.editor,E),v=Yi(this.editor,E.block,"editor-quick-menu",x);this.toolbar.manualShow(v,{placement:C?"bottom":"top",offset:[0,C?5:10]}),(L=(R=this.toolbar.tippyInstance)==null?void 0:R.popperInstance)==null||L.update()}showObjectToolbar(t){var l,c,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,r=this.hoveringTextChild,{commands:i,element:o}=wN(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(x=>{const{y:v}=x;E.includes(v)||E.push(v)}),E.length>1){if(h=r?C[C.length-1]:C[0],t)for(let x=0;x<C.length;x++){const v=C[x],R=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(R.x<t.clientX&&t.clientX<R.right&&R.y<t.clientY&&t.clientY<R.bottom){h=v;break}}}else{if(h=o.getBoundingClientRect(),r){const x=r.getBoundingClientRect();return new DOMRect(x.x,x.y,x.width,x.height)}return new DOMRect(C[0].x,C[0].y,C[0].width,C[0].height)}if(t){const x=h.y,v=t.clientX;return new DOMRect(v,x,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 Ha(e))}static get(t){return t.getCustom("toolbar-handler")}}function g0(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function zy(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function AC(n,t){const r=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:r?void 0:!0})}function xC(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 bC(n,t,e){if(!n.selection.range.focus.isSimple())return;const i=n.getBlockData(t);let o;switch(e){case"unordered-list":o=xC(i,"unordered-list")?void 0:"unordered";break;case"ordered-list":o=xC(i,"ordered-list")?void 0:"ordered";break;case"check-list":o=xC(i,"check-list")?void 0:"unchecked";break}if(o){const s=Od(n,t,"list",{offset:0,data:{listType:o}});s&&n.undoManager.runInGroup(()=>{const l=bt(t),c=it(t);n.deleteBlock(t);const d=n.insertBlock(ft(c),l,s.blockData);s.onConverted&&s.onConverted(n,d)})}else $a(n,t)}const iF=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:g0,applyAlignStyle:zy,applyQuoteStyle:AC,applyList:bC},Symbol.toStringTag,{value:"Module"})),oF=[Mh,Uh,Oh,Nh,Ph,Fh,Kh,Vh],sF={Unordered:wp,Ordered:Sp,Checkbox:kp,Quote:Rp};function Gy(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(r=>Gy(r,t))}function lF(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:Ra,name:D.t("commands.text"),order:0,group:"basics",value:"text"}]}}function vC(n=1){var i;const t={name:"basic",insertBlockCommandItems:[]};let e=o0();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:oF[r-1],name:D.t("quickMenu.basic.heading.title",{heading:String(r)}),order:r,group:"basics",value:String(r),subText:Bn(o)}),r++}return t}function aF(){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:D.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:sF[e],value:e.toLocaleLowerCase(),group:"basics",order:10+r,subText:Bn(i)})}),n}class Wy{constructor(t){this.withPlainText=t}getCommands(){const t=lF(),e=vC(),r=aF();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...r.insertBlockCommandItems||[]]}updateBlock(t,e,r,i){const{value:o,id:s}=i;return s.startsWith("heading-")?g0(t,r,Number.parseInt(o!=null?o:"1",10)||1):o==="ordered"||o==="unordered"||o==="checkbox"?bC(t,r,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[o]):o==="quote"&&AC(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"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=ft(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 qy={basics:100,system:200,common:300,thirdParty:400};class BC{constructor(){g(this,"dataUrl","");g(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const cF=I("mathjax-converter"),uF="MathJax-script",fF=30,Xy=8;async function dF(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 Ds(e,uF)}function hF(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function TC(n,t){const e="mathjax2Svg";try{await Sr.lock(e),hF(),await dF(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 cF.error(r),r}finally{Sr.release(e)}}function mF(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)*Xy+fF,e.height=parseInt(i,10)*Xy)}return e}async function Qy(n,t){const e=await TC(n,t);return e?await Bg(e,"image/svg+xml"):""}async function Yy(n,t){const r=await TC(n,t),i=new File([r],"math.svg");return(await n.doc.uploadResource(i)).resourceId}async function gF(n,t){const e=await TC(n,t),r=mF(e),i=e,o=new File([i],"math.svg");return{resourceId:(await n.doc.uploadResource(o)).resourceId,...r}}const Zy=I("edit-mathjax");class pF{constructor(){g(this,"editMathjaxPopup",null);g(this,"onChange",null);g(this,"tex","");g(this,"observer",null);g(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))}});g(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close("cancelBar")),this.handleChange(t.target.value))});g(this,"handleChange",Ke.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 Sa(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(Zy,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return p(Zy,t,"no textarea"),t}destroy(){var t,e;this.onChange=null,(t=this.observer)==null||t.disconnect(),(e=this.editMathjaxPopup)==null||e.removeAllListeners()}}function Jy(n,t,e,r,i){n.addCustom("mathjax-editor",()=>new pF).editMathjax(t,e.trim(),r,i)}function tk(){return{insert:" ",attributes:{id:J(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function p0(n,t){const e=n.getBoxData(t),r=nt(t);if(!r)return;const i=$o(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 Sr.lock("convertAndUploadMathjax");const c=await Yy(n,s);n.updateBoxData({...e,tex:s,src:c})}catch(c){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new BC).setError(c),n.updateBoxData({...e,tex:s,src:""})}finally{Sr.release("convertAndUploadMathjax"),l&&n.focus()}};Jy(n,t,e.tex,o)}const ek=I("mathjax-box");function yC(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,yC)}async function CF(n,t,e){try{if(!t.tex.trim())return;const r=await Qy(n,t.tex),i=n.findBoxById(t.id);if(!i)return;const o=Qc(i);o.innerHTML="";const s=B("img",["mathjax"],o);s.src=r,e.setDataUrl(r),n.domEvents.addEventListener(s,"load",yC)}catch(r){e.setError(r);const i=n.findBoxById(t.id);if(!i)return;const o=i.querySelector(".mathjax-tex-text");z(o,"mathjax-error"),o.innerText=r.message,n.selection.updateSelection(null)}}function EF(n,t,e,r){const i=r,o=n.addCustom(`mathjax-box-${i.id}`,()=>new BC);if(i.src||o.dataUrl){const c=B("img",["mathjax"],e);c.src=n.doc.buildResourceUrl(i.src||o.dataUrl),n.domEvents.addEventListener(c,"load",yC);return}const s=["mathjax-tex-text"];let l=i.tex;l.trim()?o.error&&(l=o.error.message,s.push("mathjax-error")):l=D.t("mathjax.emptyText"),B("span",s,e,l),CF(n,i,o)}function AF(n,t){const e={id:J(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return Yy(n,t).then(r=>{if(!n.findBoxById(e.id))return;const o={...e,src:r};n.updateBoxData(o)}).catch(r=>{ek.error(`failed to convert and upload mathjax: ${JSON.stringify(r)}`)}),e}function xF(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 bF(n,t,e){const r=nt(t);p(ek,r,"failed to get block"),!(n.readonly||!n.isBlockWritable(r))&&p0(n,t)}function vF(){return{abstract:D.t("mathjax.abstract")}}const nk={boxType:"math",updateBoxContent:EF,convertFrom:AF,convertTo:xF,handleClickBox:bF,getBoxProperties:vF};async function BF(n,t,e){try{const r=t.embedData,i=await Qy(n,r.mathjaxText),o=n.findBlockById(t.id);if(!o)return;const s=Ot(o);s.innerHTML="";const l=B("img",["mathjax"],s);l.src=i,e.setDataUrl(i)}catch(r){e.setError(r)}}function TF(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=nt(t.target);if(!e||!Re(e)||un(e)!=="math")return;const r=Ot(e),i=r.querySelector("img")||r.querySelector("span.mathjax-tex-text");if(!i||!ee(i,t.target))return;const s=n.getBlockData(e).embedData;Jy(n,i,s.mathjaxText,async l=>{const{resourceId:c,width:d,height:h}=await gF(n,l),C={mathjaxText:l,src:c,width:d,height:h};n.updateEmbedData(e,C)},{placement:"bottom"})}function yF(n,t,e){const r=e.embedData,{src:i,width:o}=r,s=n.addCustom(`mathjax-block-${e.id}`,()=>new BC);if(n.domEvents.addEventListener(t,"click",TF),!r.mathjaxText.trim()){B("span",["mathjax-tex-text"],t,D.t("mathjax.emptyText"));return}if(i||s.dataUrl){const l=B("img",["mathjax"],t);l.src=n.doc.buildResourceUrl(i||s.dataUrl),o&&(l.style.minWidth=`${o}px`,setTimeout(()=>{const c=t.getBoundingClientRect().width;o>c?(z(t,"mathjax-overflow"),t.style.overflow="auto",t.style.setProperty("--mathjax-width",`${o}px`)):(ot(t,"mathjax-overflow"),t.removeAttribute("data-mathjax-width"),t.style.removeProperty("--mathjax-width"))}));return}s.error,B("span",["mathjax-tex-text"],t,r.mathjaxText),BF(n,e,s)}function kF(n,t,e){if(!et(n,t))return null;const r=n.getBlockString(t).trim();if(!r||!r.startsWith("$$")||!r.endsWith("$$"))return null;const i=Eg(r,"$");if(!i)return null;const o={mathjaxText:i,src:""};return{blockData:{id:J(),type:"embed",embedType:"math",embedData:o}}}function RF(n){return{name:"Mathjax"}}function wF(n,t){var r;const e=Ot(t);n.domEvents.removeAllListeners(e),n.findCustom("mathjax-editor")&&((r=n.getCustom("mathjax-editor").editMathjaxPopup)==null||r.close("cancelBar"))}function SF(n,t,e,r){const i=t.embedData;return r==="html"?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:r==="markdown"?`
|
|
611
611
|
$$${i.mathjaxText}$$
|
|
612
612
|
`:i.mathjaxText}function LF(){return{abstract:D.t("mathjax.abstract")}}const IF={embedType:"math",createEmbedContent:yF,getOptions:RF,convertFrom:kF,handleDeleteBlock:wF,convertTo:SF,getBlockProperties:LF},Ust="",DF={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},_F={mathjax:{emptyText:"Empty formula",abstract:"Formula"}},MF={mathjax:{emptyText:"\u6570\u5F0F\u306A\u3057",abstract:"\u6570\u5F0F"}};D.mergeLang({"zh-CN":DF,"en-US":_F,"ja-JP":MF});function UF(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=In(o,r);if(!ce(s).endsWith("$$$$"))return!1;const c=r-4,d=r,h={id:J(),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);p0(n,C)})}),!0}class OF{handleAfterInsertText(t,e,r,i,o){return!!(o===" "&&UF(t,e,r,i))}}var rn={exports:{}};/**
|
|
@@ -635,7 +635,7 @@ __p += '`),zt&&(tt+=`' +
|
|
|
635
635
|
function print() { __p += __j.call(arguments, '') }
|
|
636
636
|
`:`;
|
|
637
637
|
`)+tt+`return __p
|
|
638
|
-
}`;var Nt=DL(function(){return Wt(w,Et+"return "+tt).apply(e,O)});if(Nt.source=tt,Mx(Nt))throw Nt;return Nt}function oit(a){return te(a).toLowerCase()}function sit(a){return te(a).toUpperCase()}function lit(a,u,m){if(a=te(a),a&&(m||u===e))return xo(a);if(!a||!(u=sr(u)))return a;var A=or(a),T=or(u),w=Il(A,T),O=Xf(A,T)+1;return ys(A,w,O).join("")}function ait(a,u,m){if(a=te(a),a&&(m||u===e))return a.slice(0,Rc(a)+1);if(!a||!(u=sr(u)))return a;var A=or(a),T=Xf(A,or(u))+1;return ys(A,0,T).join("")}function cit(a,u,m){if(a=te(a),a&&(m||u===e))return a.replace(wf,"");if(!a||!(u=sr(u)))return a;var A=or(a),T=Il(A,or(u));return ys(A,T).join("")}function uit(a,u){var m=kt,A=se;if(Te(u)){var T="separator"in u?u.separator:T;m="length"in u?Ut(u.length):m,A="omission"in u?sr(u.omission):A}a=te(a);var w=a.length;if(bo(a)){var O=or(a);w=O.length}if(m>=w)return a;var P=m-xs(A);if(P<1)return A;var V=O?ys(O,0,P).join(""):a.slice(0,P);if(T===e)return V+A;if(O&&(P+=V.length-P),Ux(T)){if(a.slice(P).search(T)){var Q,Y=V;for(T.global||(T=Ic(T.source,te(dc.exec(T))+"g")),T.lastIndex=0;Q=T.exec(Y);)var tt=Q.index;V=V.slice(0,tt===e?P:tt)}}else if(a.indexOf(sr(T),P)!=P){var ht=V.lastIndexOf(T);ht>-1&&(V=V.slice(0,ht))}return V+A}function fit(a){return a=te(a),a&&sA.test(a)?a.replace(om,wc):a}var dit=_c(function(a,u,m){return a+(m?" ":"")+u.toUpperCase()}),Px=_S("toUpperCase");function IL(a,u,m){return a=te(a),u=m?e:u,u===e?Tc(a)?Rm(a):rr(a):a.match(u)||[]}var DL=Pt(function(a,u){try{return kn(a,e,u)}catch(m){return Mx(m)?m:new wt(m)}}),hit=Mo(function(a,u){return Kn(u,function(m){m=Ki(m),Do(a,m,Dx(a[m],a))}),a});function mit(a){var u=a==null?0:a.length,m=vt();return a=u?ge(a,function(A){if(typeof A[1]!="function")throw new Rn(s);return[m(A[0]),A[1]]}):[],Pt(function(A){for(var T=-1;++T<u;){var w=a[T];if(kn(w[0],this,A))return kn(w[1],this,A)}})}function git(a){return PJ(yr(a,C))}function Fx(a){return function(){return a}}function pit(a,u){return a==null||a!==a?u:a}var Cit=US(),Eit=US(!0);function Gn(a){return a}function Kx(a){return fS(typeof a=="function"?a:yr(a,C))}function Ait(a){return hS(yr(a,C))}function xit(a,u){return mS(a,yr(u,C))}var bit=Pt(function(a,u){return function(m){return od(m,a,u)}}),vit=Pt(function(a,u){return function(m){return od(a,m,u)}});function Vx(a,u,m){var A=tn(u),T=Pm(u,A);m==null&&!(Te(u)&&(T.length||!A.length))&&(m=u,u=a,a=this,T=Pm(u,tn(u)));var w=!(Te(m)&&"chain"in m)||!!m.chain,O=Oo(a);return Kn(T,function(P){var V=u[P];a[P]=V,O&&(a.prototype[P]=function(){var Q=this.__chain__;if(w||Q){var Y=a(this.__wrapped__),tt=Y.__actions__=Hn(this.__actions__);return tt.push({func:V,args:arguments,thisArg:a}),Y.__chain__=Q,Y}return V.apply(a,Ui([this.value()],arguments))})}),a}function Bit(){return Ye._===this&&(Ye._=Sm),this}function $x(){}function Tit(a){return a=Ut(a),Pt(function(u){return gS(u,a)})}var yit=Ax(ge),kit=Ax(Am),Rit=Ax(Gf);function _L(a){return kx(a)?bc(Ki(a)):ett(a)}function wit(a){return function(u){return a==null?e:Xl(a,u)}}var Sit=NS(),Lit=NS(!0);function Hx(){return[]}function jx(){return!1}function Iit(){return{}}function Dit(){return""}function _it(){return!0}function Mit(a,u){if(a=Ut(a),a<1||a>gn)return[];var m=xr,A=_(a,xr);u=vt(u),a-=xr;for(var T=Bc(A,u);++m<a;)u(m);return T}function Uit(a){return Dt(a)?ge(a,Ki):lr(a)?[a]:Hn(JS(te(a)))}function Oit(a){var u=++wm;return te(a)+u}var Nit=jm(function(a,u){return a+u},0),Pit=xx("ceil"),Fit=jm(function(a,u){return a/u},1),Kit=xx("floor");function Vit(a){return a&&a.length?Nm(a,Gn,ox):e}function $it(a,u){return a&&a.length?Nm(a,vt(u,2),ox):e}function Hit(a){return xc(a,Gn)}function jit(a,u){return xc(a,vt(u,2))}function zit(a){return a&&a.length?Nm(a,Gn,cx):e}function Git(a,u){return a&&a.length?Nm(a,vt(u,2),cx):e}var Wit=jm(function(a,u){return a*u},1),qit=xx("round"),Xit=jm(function(a,u){return a-u},0);function Qit(a){return a&&a.length?vc(a,Gn):0}function Yit(a,u){return a&&a.length?vc(a,vt(u,2)):0}return k.after=Ant,k.ary=uL,k.assign=srt,k.assignIn=TL,k.assignInWith=rg,k.assignWith=lrt,k.at=art,k.before=fL,k.bind=Dx,k.bindAll=hit,k.bindKey=dL,k.castArray=Int,k.chain=lL,k.chunk=Ptt,k.compact=Ftt,k.concat=Ktt,k.cond=mit,k.conforms=git,k.constant=Fx,k.countBy=Qet,k.create=crt,k.curry=hL,k.curryRight=mL,k.debounce=gL,k.defaults=urt,k.defaultsDeep=frt,k.defer=xnt,k.delay=bnt,k.difference=Vtt,k.differenceBy=$tt,k.differenceWith=Htt,k.drop=jtt,k.dropRight=ztt,k.dropRightWhile=Gtt,k.dropWhile=Wtt,k.fill=qtt,k.filter=Zet,k.flatMap=ent,k.flatMapDeep=nnt,k.flatMapDepth=rnt,k.flatten=rL,k.flattenDeep=Xtt,k.flattenDepth=Qtt,k.flip=vnt,k.flow=Cit,k.flowRight=Eit,k.fromPairs=Ytt,k.functions=Ert,k.functionsIn=Art,k.groupBy=int,k.initial=Jtt,k.intersection=tet,k.intersectionBy=eet,k.intersectionWith=net,k.invert=brt,k.invertBy=vrt,k.invokeMap=snt,k.iteratee=Kx,k.keyBy=lnt,k.keys=tn,k.keysIn=zn,k.map=Ym,k.mapKeys=Trt,k.mapValues=yrt,k.matches=Ait,k.matchesProperty=xit,k.memoize=Jm,k.merge=krt,k.mergeWith=yL,k.method=bit,k.methodOf=vit,k.mixin=Vx,k.negate=tg,k.nthArg=Tit,k.omit=Rrt,k.omitBy=wrt,k.once=Bnt,k.orderBy=ant,k.over=yit,k.overArgs=Tnt,k.overEvery=kit,k.overSome=Rit,k.partial=_x,k.partialRight=pL,k.partition=cnt,k.pick=Srt,k.pickBy=kL,k.property=_L,k.propertyOf=wit,k.pull=set,k.pullAll=oL,k.pullAllBy=aet,k.pullAllWith=cet,k.pullAt=uet,k.range=Sit,k.rangeRight=Lit,k.rearg=ynt,k.reject=dnt,k.remove=fet,k.rest=knt,k.reverse=Lx,k.sampleSize=mnt,k.set=Irt,k.setWith=Drt,k.shuffle=gnt,k.slice=det,k.sortBy=Ent,k.sortedUniq=Aet,k.sortedUniqBy=xet,k.split=eit,k.spread=Rnt,k.tail=bet,k.take=vet,k.takeRight=Bet,k.takeRightWhile=Tet,k.takeWhile=yet,k.tap=Vet,k.throttle=wnt,k.thru=Qm,k.toArray=bL,k.toPairs=RL,k.toPairsIn=wL,k.toPath=Uit,k.toPlainObject=BL,k.transform=_rt,k.unary=Snt,k.union=ket,k.unionBy=Ret,k.unionWith=wet,k.uniq=Let,k.uniqBy=Iet,k.uniqWith=Det,k.unset=Mrt,k.unzip=Ix,k.unzipWith=sL,k.update=Urt,k.updateWith=Ort,k.values=Oc,k.valuesIn=Nrt,k.without=_et,k.words=IL,k.wrap=Lnt,k.xor=Met,k.xorBy=Uet,k.xorWith=Oet,k.zip=Net,k.zipObject=Pet,k.zipObjectDeep=Fet,k.zipWith=Ket,k.entries=RL,k.entriesIn=wL,k.extend=TL,k.extendWith=rg,Vx(k,k),k.add=Nit,k.attempt=DL,k.camelCase=Vrt,k.capitalize=SL,k.ceil=Pit,k.clamp=Prt,k.clone=Dnt,k.cloneDeep=Mnt,k.cloneDeepWith=Unt,k.cloneWith=_nt,k.conformsTo=Ont,k.deburr=LL,k.defaultTo=pit,k.divide=Fit,k.endsWith=$rt,k.eq=ii,k.escape=Hrt,k.escapeRegExp=jrt,k.every=Yet,k.find=Jet,k.findIndex=eL,k.findKey=drt,k.findLast=tnt,k.findLastIndex=nL,k.findLastKey=hrt,k.floor=Kit,k.forEach=aL,k.forEachRight=cL,k.forIn=mrt,k.forInRight=grt,k.forOwn=prt,k.forOwnRight=Crt,k.get=Ox,k.gt=Nnt,k.gte=Pnt,k.has=xrt,k.hasIn=Nx,k.head=iL,k.identity=Gn,k.includes=ont,k.indexOf=Ztt,k.inRange=Frt,k.invoke=Brt,k.isArguments=Zl,k.isArray=Dt,k.isArrayBuffer=Fnt,k.isArrayLike=jn,k.isArrayLikeObject=Pe,k.isBoolean=Knt,k.isBuffer=ks,k.isDate=Vnt,k.isElement=$nt,k.isEmpty=Hnt,k.isEqual=jnt,k.isEqualWith=znt,k.isError=Mx,k.isFinite=Gnt,k.isFunction=Oo,k.isInteger=CL,k.isLength=eg,k.isMap=EL,k.isMatch=Wnt,k.isMatchWith=qnt,k.isNaN=Xnt,k.isNative=Qnt,k.isNil=Znt,k.isNull=Ynt,k.isNumber=AL,k.isObject=Te,k.isObjectLike=Ie,k.isPlainObject=fd,k.isRegExp=Ux,k.isSafeInteger=Jnt,k.isSet=xL,k.isString=ng,k.isSymbol=lr,k.isTypedArray=Uc,k.isUndefined=trt,k.isWeakMap=ert,k.isWeakSet=nrt,k.join=ret,k.kebabCase=zrt,k.last=Rr,k.lastIndexOf=iet,k.lowerCase=Grt,k.lowerFirst=Wrt,k.lt=rrt,k.lte=irt,k.max=Vit,k.maxBy=$it,k.mean=Hit,k.meanBy=jit,k.min=zit,k.minBy=Git,k.stubArray=Hx,k.stubFalse=jx,k.stubObject=Iit,k.stubString=Dit,k.stubTrue=_it,k.multiply=Wit,k.nth=oet,k.noConflict=Bit,k.noop=$x,k.now=Zm,k.pad=qrt,k.padEnd=Xrt,k.padStart=Qrt,k.parseInt=Yrt,k.random=Krt,k.reduce=unt,k.reduceRight=fnt,k.repeat=Zrt,k.replace=Jrt,k.result=Lrt,k.round=qit,k.runInContext=K,k.sample=hnt,k.size=pnt,k.snakeCase=tit,k.some=Cnt,k.sortedIndex=het,k.sortedIndexBy=met,k.sortedIndexOf=get,k.sortedLastIndex=pet,k.sortedLastIndexBy=Cet,k.sortedLastIndexOf=Eet,k.startCase=nit,k.startsWith=rit,k.subtract=Xit,k.sum=Qit,k.sumBy=Yit,k.template=iit,k.times=Mit,k.toFinite=No,k.toInteger=Ut,k.toLength=vL,k.toLower=oit,k.toNumber=wr,k.toSafeInteger=ort,k.toString=te,k.toUpper=sit,k.trim=lit,k.trimEnd=ait,k.trimStart=cit,k.truncate=uit,k.unescape=fit,k.uniqueId=Oit,k.upperCase=dit,k.upperFirst=Px,k.each=aL,k.eachRight=cL,k.first=iL,Vx(k,function(){var a={};return Pi(k,function(u,m){qt.call(k.prototype,m)||(a[m]=u)}),a}(),{chain:!1}),k.VERSION=r,Kn(["bind","bindKey","curry","curryRight","partial","partialRight"],function(a){k[a].placeholder=k}),Kn(["drop","take"],function(a,u){Vt.prototype[a]=function(m){m=m===e?1:S(Ut(m),0);var A=this.__filtered__&&!u?new Vt(this):this.clone();return A.__filtered__?A.__takeCount__=_(m,A.__takeCount__):A.__views__.push({size:_(m,xr),type:a+(A.__dir__<0?"Right":"")}),A},Vt.prototype[a+"Right"]=function(m){return this.reverse()[a](m).reverse()}}),Kn(["filter","map","takeWhile"],function(a,u){var m=u+1,A=m==Se||m==Li;Vt.prototype[a]=function(T){var w=this.clone();return w.__iteratees__.push({iteratee:vt(T,3),type:m}),w.__filtered__=w.__filtered__||A,w}}),Kn(["head","last"],function(a,u){var m="take"+(u?"Right":"");Vt.prototype[a]=function(){return this[m](1).value()[0]}}),Kn(["initial","tail"],function(a,u){var m="drop"+(u?"":"Right");Vt.prototype[a]=function(){return this.__filtered__?new Vt(this):this[m](1)}}),Vt.prototype.compact=function(){return this.filter(Gn)},Vt.prototype.find=function(a){return this.filter(a).head()},Vt.prototype.findLast=function(a){return this.reverse().find(a)},Vt.prototype.invokeMap=Pt(function(a,u){return typeof a=="function"?new Vt(this):this.map(function(m){return od(m,a,u)})}),Vt.prototype.reject=function(a){return this.filter(tg(vt(a)))},Vt.prototype.slice=function(a,u){a=Ut(a);var m=this;return m.__filtered__&&(a>0||u<0)?new Vt(m):(a<0?m=m.takeRight(-a):a&&(m=m.drop(a)),u!==e&&(u=Ut(u),m=u<0?m.dropRight(-u):m.take(u-a)),m)},Vt.prototype.takeRightWhile=function(a){return this.reverse().takeWhile(a).reverse()},Vt.prototype.toArray=function(){return this.take(xr)},Pi(Vt.prototype,function(a,u){var m=/^(?:filter|find|map|reject)|While$/.test(u),A=/^(?:head|last)$/.test(u),T=k[A?"take"+(u=="last"?"Right":""):u],w=A||/^find/.test(u);!T||(k.prototype[u]=function(){var O=this.__wrapped__,P=A?[1]:arguments,V=O instanceof Vt,Q=P[0],Y=V||Dt(O),tt=function(jt){var zt=T.apply(k,Ui([jt],P));return A&&ht?zt[0]:zt};Y&&m&&typeof Q=="function"&&Q.length!=1&&(V=Y=!1);var ht=this.__chain__,Et=!!this.__actions__.length,Bt=w&&!ht,Nt=V&&!Et;if(!w&&Y){O=Nt?O:new Vt(this);var Tt=a.apply(O,P);return Tt.__actions__.push({func:Qm,args:[tt],thisArg:e}),new $n(Tt,ht)}return Bt&&Nt?a.apply(this,P):(Tt=this.thru(tt),Bt?A?Tt.value()[0]:Tt.value():Tt)})}),Kn(["pop","push","shift","sort","splice","unshift"],function(a){var u=Ul[a],m=/^(?:push|sort|unshift)$/.test(a)?"tap":"thru",A=/^(?:pop|shift)$/.test(a);k.prototype[a]=function(){var T=arguments;if(A&&!this.__chain__){var w=this.value();return u.apply(Dt(w)?w:[],T)}return this[m](function(O){return u.apply(Dt(O)?O:[],T)})}}),Pi(Vt.prototype,function(a,u){var m=k[u];if(m){var A=m.name+"";qt.call(sn,A)||(sn[A]=[]),sn[A].push({name:u,func:m})}}),sn[Hm(e,M).name]=[{name:"wrapper",func:e}],Vt.prototype.clone=cJ,Vt.prototype.reverse=uJ,Vt.prototype.value=fJ,k.prototype.at=$et,k.prototype.chain=Het,k.prototype.commit=jet,k.prototype.next=zet,k.prototype.plant=Wet,k.prototype.reverse=qet,k.prototype.toJSON=k.prototype.valueOf=k.prototype.value=Xet,k.prototype.first=k.prototype.head,$l&&(k.prototype[$l]=Get),k},To=Lc();Eo?((Eo.exports=To)._=To,Pf._=To):Ye._=To}).call(Dn)})(rn,rn.exports);function NF(n,t,e,r){Wh(n,{className:"status-input",defaultValue:t,onChange:e,onKeyDown:r,maxLength:32})}const rk=["Blue","Grey","Yellow","Red","Green","Purple"];function PF(){const n=B("div",["status-color-palette"],null);for(const t of rk){const e=B("button",["status-box-button"],null);e.setAttribute("data-color",rn.exports.lowerCase(t)),e.setAttribute("title",D.t(`status.color.${rn.exports.lowerCase(t)}`)),n.appendChild(e)}return n}class FF{constructor(){g(this,"root",PF());g(this,"changeColor",t=>{for(const r of Array.from(this.root.querySelectorAll(":scope > button")))r.classList.remove("selected");const e=this.root.querySelector(`button[data-color="${rn.exports.lowerCase(t)}"]`);e==null||e.classList.add("selected")})}}function ik(n){var o;const t=rk[0],e=(o=n.settingsProvider.getItem(`statusBox.lastColor.${rn.exports.lowerCase(t)}`))!=null?o:D.t(`status.colorDefaultTitle.${rn.exports.lowerCase(t)}`);return{insert:" ",attributes:{id:J(),type:"status",box:!0,title:e,subtle:!1,created:Date.now(),color:t}}}function KF(n,t){localStorage.setItem(`statusBox.lastColor.${rn.exports.lowerCase(t.color)}`,t.title)}function VF(n,t){var e;return(e=localStorage.getItem(`statusBox.lastColor.${rn.exports.lowerCase(t)}`))!=null?e:D.t(`status.colorDefaultTitle.${rn.exports.lowerCase(t)}`)}class $F{constructor(t,e,r,i){g(this,"root");g(this,"ro");g(this,"mo");this.editor=t;const o=B("a",r,null,this.replaceTitleSpace(e));this.root=o,i.appendChild(o),this.observeResize(),this.observeRemoval()}replaceTitleSpace(t){return t.replace(/\s/g,"\xA0")}check(){return this.root.scrollWidth>this.root.offsetWidth}observeResize(){this.ro=new ResizeObserver(rn.exports.debounce(t=>{for(const e of t)if(this.check()){const r=this.root.textContent||"";e.target.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,r)}else e.target.removeAttribute(`data-editor-tooltip-${this.editor.clientId}`)},200)),this.ro.observe(this.root)}handleContentChange(){if(this.check()){const t=this.root.textContent||"";this.root.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,t)}else this.root.removeAttribute(`data-editor-tooltip-${this.editor.clientId}`)}observeRemoval(){this.mo=new MutationObserver(t=>{t.forEach(e=>{e.target===this.root&&e.type==="childList"&&this.handleContentChange(),e.removedNodes.forEach(r=>{r===this.root&&(this.unbindResizeObserver(),this.unbindMutationObserver())})})}),this.root.parentElement&&(this.mo.observe(this.root.parentElement,{childList:!0}),this.mo.observe(this.root,{childList:!0}))}unbindResizeObserver(){var t;(t=this.ro)==null||t.unobserve(this.root)}unbindMutationObserver(){var t;(t=this.mo)==null||t.disconnect()}rebind(t){this.unbindResizeObserver(),this.unbindMutationObserver(),this.root=t,this.observeResize(),this.observeRemoval()}changeTag(t,e){this.root.textContent=this.replaceTitleSpace(t),this.root.className=e.join(" ")}destroy(){this.unbindResizeObserver(),this.unbindMutationObserver()}}class kC{static create(t,e,r,i){const{title:o,id:s}=r;if(this.tagRef.has(s)){const c=this.tagRef.get(s);return c==null||c.changeTag(o||D.t("status.empty"),e),i.appendChild(c==null?void 0:c.root),setTimeout(()=>{c==null||c.rebind(Qc(t.getBoxById(s)).firstChild)}),c}const l=new $F(t,o,e,i);return this.tagRef.set(s,l),setTimeout(()=>{l.rebind(Qc(t.getBoxById(s)).firstChild)}),l}static remove(t){const e=this.tagRef.get(t);this.tagRef.delete(t),e==null||e.destroy()}}g(kC,"tagRef",new Map);const C0=I("StatusBoxEditor");class RC{constructor(t){g(this,"linkPopup",null);g(this,"boxElement");g(this,"statusPalette",new FF);g(this,"isEditing",!1);g(this,"editorStatus",t=>{if(!this.editor.isWritable())return;const e=this.editor.getBoxData(t);this.linkPopup=new Sa(this.createPopupContent(e.title,e.color,e.subtle),{id:"status-box-popup"}),this.linkPopup.on("show",this.handleShow),this.linkPopup.on("close",this.handClose),this.linkPopup.manualShow(t,{theme:"light",placement:"bottom-start",offset:[5,5]}),this.boxElement=t});g(this,"handleShow",()=>{this.focus()});g(this,"handClose",()=>{var r;p(C0,this.boxElement,"boxElement not found");const t=this.editor.getBoxData(this.boxElement),e=nt(this.boxElement);if(p(C0,e,"block not found"),t.title)KF(this.editor,t);else{const i=$o(e,this.boxElement);this.editor.deleteTextFromBlock(e,i.start,1),kC.remove(t.id)}this.editor.focus(),(r=this.linkPopup)==null||r.destroy(),this.linkPopup=null,this.boxElement=void 0,this.isEditing=!1});g(this,"handleKeyDown",t=>{var e;t.key==="Enter"&&((e=this.linkPopup)==null||e.close(null))});g(this,"onColorChange",t=>{var o,s;if(!(t.target instanceof HTMLElement)||t.target.closest("[data-color]")===null)return;const e=rn.exports.upperCase(t.target.getAttribute("data-color"));p(C0,this.boxElement,"boxElement not found");const r=this.editor.getBoxData(this.boxElement);this.statusPalette.changeColor(e);const i={...r,color:e};if(!this.isEditing){const l=(s=(o=this.linkPopup)==null?void 0:o.popper)==null?void 0:s.querySelector("input"),c=VF(this.editor,e);l&&(l.value=c),i.title=c}this.editor.updateBoxData(i,{noFocus:!0}),this.focus()});g(this,"changeTitle",t=>{const e=t.target.value;p(C0,this.boxElement,"boxElement not found");const i={...this.editor.getBoxData(this.boxElement),title:e.trim()};this.editor.updateBoxData(i,{noFocus:!0}),this.isEditing=!0});this.editor=t,this.statusPalette.root.addEventListener("click",this.onColorChange)}focus(){setTimeout(()=>{var t,e,r,i,o,s;(r=(e=(t=this.linkPopup)==null?void 0:t.popper)==null?void 0:e.querySelector("input"))==null||r.focus(),(s=(o=(i=this.linkPopup)==null?void 0:i.popper)==null?void 0:o.querySelector("input"))==null||s.select()},100)}createPopupContent(t,e,r){const i=B("div",["status-box-editor-popup"],null);return NF(i,t,this.changeTitle,this.handleKeyDown),this.isEditing=!1,i.appendChild(this.statusPalette.root),this.statusPalette.changeColor(e),i}destroy(){var t;(t=this.linkPopup)==null||t.destroy()}}const Ost="";function HF(n,t,e,r){const i=r,{title:o,subtle:s,color:l}=i,c=s?["box-status-common",`box-status-${rn.exports.lowerCase(l)}-subtle`]:["box-status-common",`box-status-${rn.exports.lowerCase(l)}`];o||c.push("box-status-empty"),kC.create(n,c,r,e),n.addCustom("status-box",d=>new RC(d))}function jF(n,t){return{abstract:D.t("status.command.name")}}function zF(n,t){n.getCustom("status-box").editorStatus(t)}function GF(n,t){const{title:e}=t;return e!=null?e:""}async function WF(n,t){const{title:e}=t;return[{insert:e!=null?e:""}]}const ok={boxType:"status",updateBoxContent:HF,getBoxProperties:jF,handleClickBox:zF,convertTo:GF,toStandardText:WF},qF=I("status-box-command");class ja{static get commands(){return[{id:this.id,name:D.t("status.command.name"),icon:RT,order:650,group:"common",subText:"/status"}]}static insertStatus(t,e,r){var c;const i=t.getBlockByIndex(e,r),o=ik(t),{start:s}=t.selection.range;p(qF,Or(s),"invalid block position"),t.insertBoxToBlock(i,s.offset,o.attributes);const l=t.getBoxById((c=o.attributes)==null?void 0:c.id);t.addCustom("status-box",d=>new RC(d)).editorStatus(l)}static insertEmptyBlockStatus(t,e,r){var l;let i=t.getBlockByIndex(e,r);(!i||!re(t,i))&&(i=t.insertTextBlock([],e,r));const o=ik(t);t.setBlockText(i,[o]);const s=t.getBoxById((l=o.attributes)==null?void 0:l.id);return t.addCustom("status-box",c=>new RC(c)).editorStatus(s),i}}g(ja,"id","insert-status");const XF={"en-US":{status:{empty:"\u8BBE\u7F6E\u72B6\u6001",command:{name:"\u72B6\u6001"},color:{red:"\u7EA2\u8272",yellow:"\u9EC4\u8272",green:"\u7EFF\u8272",blue:"\u84DD\u8272",purple:"\u7D2B\u8272",grey:"\u7070\u8272"},colorDefaultTitle:{red:"\u672A\u5F00\u59CB",yellow:"\u8FDB\u884C\u4E2D",green:"\u5DF2\u5B8C\u6210",blue:"\u5DF2\u5F52\u6863",purple:"\u5DF2\u53D6\u6D88",grey:"\u6682\u505C"}}},"zh-CN":{status:{empty:"\u672A\u5F00\u59CB",command:{name:"\u72B6\u6001"},color:{red:"\u7EA2\u8272",yellow:"\u9EC4\u8272",green:"\u7EFF\u8272",blue:"\u84DD\u8272",purple:"\u7D2B\u8272",grey:"\u7070\u8272"},colorDefaultTitle:{red:"\u672A\u5F00\u59CB",yellow:"\u8FDB\u884C\u4E2D",green:"\u5DF2\u5B8C\u6210",blue:"\u5DF2\u5F52\u6863",purple:"\u5DF2\u53D6\u6D88",grey:"\u6682\u505C"}}},"ja-JP":{status:{empty:"\u672A\u5F00\u59CB",command:{name:"\u72B6\u6001"},color:{red:"\u7EA2\u8272",yellow:"\u9EC4\u8272",green:"\u7EFF\u8272",blue:"\u84DD\u8272",purple:"\u7D2B\u8272",grey:"\u7070\u8272"},colorDefaultTitle:{red:"\u672A\u5F00\u59CB",yellow:"\u8FDB\u884C\u4E2D",green:"\u5DF2\u5B8C\u6210",blue:"\u5DF2\u5F52\u6863",purple:"\u5DF2\u53D6\u6D88",grey:"\u6682\u505C"}}}};D.mergeLang(XF);const za=I("inline-box-items");function QF(n,t,e){return n.undoManager.runInGroup(()=>{var s;let r=n.getBlockByIndex(t,e);(!r||!re(n,r))&&(r=n.insertTextBlock([],t,e));const i=tk();n.setBlockText(r,[i]);const o=(s=i.attributes)==null?void 0:s.id;return p(za,o,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(o);p0(n,l)},100),r})}function YF(n,t,e){let r=n.getBlockByIndex(t,e),i="bottom-start";return(!r||!re(n,r))&&(i="top-start",r=n.insertTextBlock([],t,e)),Pu(n,{target:r,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{re(n,r)||(r=n.insertTextBlock([],t,e));const d=gr(l,{link:c}),h=gr(" ",null),C=[d,h];n.insertTextToBlock(r,0,C),n.selection.selectBlock(r,fn(C)),n.focus()}catch(d){za.error(d)}})},onClose:()=>{n.focus()},placement:i}),r}function ZF(n,t,e){return n.undoManager.runInGroup(()=>{var l;const r=n.getBlockByIndex(t,e),i=n.selection.range;p(za,Or(i.start),"invalid block position");const o=tk();n.insertBoxToBlock(r,i.start.offset,o.attributes);const s=(l=o.attributes)==null?void 0:l.id;return p(za,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);p0(n,c)},100),r})}function JF(n,t,e){const r=n.getBlockByIndex(t,e),i=n.selection.range;p(za,Or(i.start),"invalid block position");const o=qi(n,r,i);if(o.length===0)return;const s=o[0],l=Yi(n,r,"quick-menu-inline-link",s);Pu(n,{target:l,linkText:"",linkUrl:"",onFinished:(h,C)=>{n.undoManager.runInGroup(()=>{try{const E=n.getBlockText(r),x=to(E,i.start.offset,h,{link:C});n.setBlockText(r,x),n.selection.selectBlock(r,i.start.offset+h.length),n.focus()}catch(E){za.error(E)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class sk{getCommands(){return[{id:"insert-math",name:D.t("quickMenu.inlineBox.math"),icon:j2,order:900,group:"common",subText:Bn("insert-math")},{id:"insert-link",name:D.t("quickMenu.inlineBox.link"),icon:yp,order:400,group:"common",subText:Bn("insert-link")},...ja.commands]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return ZF(t,e.containerId,e.blockIndex);case"insert-link":return JF(t,e.containerId,e.blockIndex);case ja.id:return ja.insertStatus(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return QF(t,e.containerId,e.blockIndex);case"insert-link":return YF(t,e.containerId,e.blockIndex);case ja.id:return ja.insertEmptyBlockStatus(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,r){if(r.from==="quick-menu"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=ft(o),l=t.getBlockIndex(i);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else r.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:r.containerId,blockIndex:r.blockIndex}));return null}}function tK(n,t={withPlainText:!1}){var o,s;const{withPlainText:e}=t,r=(s=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:s.commandProviders;if(!r)return[];const i=[];return[...r,new Wy(e),new sk].forEach(l=>{const c=l.getCommands(n);i.push(...c.map(d=>({...d,itemType:"insert-block",commandProvider:l})))}),i}function eK(n,t={withPlainText:!1}){const e=[];return n.editorBlocks.forEach(r=>{if(!r.getOptions)return;const i=r.getOptions(n);!i.insertBlockCommandItems||(i.insertBlockCommandItems.forEach(o=>{Gy(o,i)}),e.push(...i.insertBlockCommandItems))}),e.push(...tK(n,t)),e}function wC(n,t={withPlainText:!1}){const e=eK(n,t),r=new Map;e.forEach(s=>{var d;const l=(d=s.group)!=null?d:"";let c=r.get(l);c?c.items.push(s):(c={group:l,order:s.groupOrder||qy[l]||1e3,items:[s]},r.set(l,c))});const i=Array.from(r.values());i.sort((s,l)=>s.order-l.order),i.forEach(s=>{s.items.sort((l,c)=>{var d,h;return((d=l.order)!=null?d:0)-((h=c.order)!=null?h:0)})});const o=[];return i.forEach((s,l)=>{const c=`blockMenu.section.${s.group||"common"}`,d=D.t(c),h=d===c?s.group:d;o.push({id:`section-${l}`,name:h,type:"section",group:s.group,itemType:"insert-block"}),o.push(...s.items.map(C=>({...C})))}),o}function nK(n,t,e){const r=n.getFocusedBlock();if(!r)return;const i=n.getParentContainer(r),o=ft(i);let l=n.getBlockIndex(r);if(re(n,r)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:o,blockIndex:l,item:t})}const lk=I("quick-menu"),rK={id:"quick-menu",trigger:["/"]},iK=5;class E0{constructor(t,e=rK){g(this,"suggest");g(this,"items");g(this,"maxHeading");g(this,"firstEmptyOffset",-1);g(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const r=new Set,i=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,""),o=this.items.filter(s=>{if(s.type==="section")return!0;if(s.name.toLocaleLowerCase().indexOf(i)!==-1||fO(s).toLocaleLowerCase().indexOf(i)!==-1)return r.add(s.group),!0;const l=`blockMenu.section.${s.group||"common"}`,c=D.t(l),d=c===l?s.group:c;return(d==null?void 0:d.toLocaleLowerCase().indexOf(i))!==-1?(r.add(s.group),!0):!1}).filter(s=>s.type==="section"?r.has(s.group):!0);return o.length?this.firstEmptyOffset=-1:this.handleEmptySearch(),o}return this.items});g(this,"onClose",()=>{this.firstEmptyOffset=-1});g(this,"onShow",(t,e,r,i)=>{const o=this.editor.getBlockByIndex(e,r);if(!dr(o)){const s=nt(it(o));if(s&&It(s)==="code")return!1}return!0});g(this,"onClickItem",(t,e)=>{const r=e;r.itemType==="insert-block"&&(p(lk,r.blockOptions||r.commandProvider,"invalid quick item, no block options or command provider"),p(lk,this.suggest.anchor,"invalid suggest, no anchor"),this.options.id==="empty-block-menu"&&this.editor.focus(),nK(this.editor,r,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=o0(),this.suggest=new Op(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=wC(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const r=o0();if(r!==this.maxHeading){const i=new Wy,s=i.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:i}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=r}}handleEmptySearch(){const t=this.editor.selection.getFocusedPos();if(this.firstEmptyOffset===-1){if(t.isSimple()){const{offset:e}=t;this.firstEmptyOffset=e-1}}else if(t.isSimple()){const{offset:e}=t;e-this.firstEmptyOffset>iK&&(this.suggest.close(),this.firstEmptyOffset=-1)}}}class A0{constructor(t){g(this,"instance");g(this,"mousedown",!1);g(this,"currentInstance",null);g(this,"attributeName",[]);g(this,"attributeDesc","");g(this,"_lastClickButtonId","");g(this,"observer",null);g(this,"observerCallback",null);g(this,"createContent",t=>{let e="",r=0;for(;r<this.attributeName.length&&!e;)t.hasAttribute(this.attributeName[r])&&(e=t.getAttribute(this.attributeName[r])||""),r++;const i=t.getAttribute(this.attributeDesc);if(!i)return e;const o=B("div",[],null);return B("span",[],o,e),i&&B("span",["editor-tooltip-desc"],o,i),o});g(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});g(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});g(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});g(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});g(this,"handleShow",t=>{var i;const e=t.reference;if(!e||!ee(document.body,e)||window.isDragging||this.mousedown)return!1;const r=Number.parseInt((i=e.getAttribute("data-tooltip-hide-at"))!=null?i:"",10);if(r&&Date.now()-r<1e3)return!1;if(this._lastClickButtonId===e.getAttribute("data-button-id"))return this._lastClickButtonId="",!1;if(this.attributeName.every(o=>!e.hasAttribute(o)))return!1;if(t.reference){const o={};if(t.reference.hasAttribute("data-editor-tooltip-placement")&&(o.placement=t.reference.getAttribute("data-editor-tooltip-placement")||"top"),t.reference.hasAttribute("data-editor-tooltip-offset-x")||t.reference.hasAttribute("data-editor-tooltip-offset-y")){const l=t.reference.getAttribute("data-editor-tooltip-offset-x"),c=t.reference.getAttribute("data-editor-tooltip-offset-y");o.offset=[l?Number.parseInt(l,10):0,c?Number.parseInt(c,10):0]}t.reference.hasAttribute("data-editor-tooltip-maxwidth")&&(o.maxWidth=Number.parseInt(t.reference.getAttribute("data-editor-tooltip-maxwidth")||"350",10)),t.reference.hasAttribute("data-editor-tooltip-allow-markdown")&&(o.allowHTML=!0);const s=document.body;if(o.appendTo=this.fixContainerForFullscreen(s),Object.keys(o).length&&t.setProps(o),t.reference.hasAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`)){const l=t.reference.getAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`);t.setContent(l||"")}}return!0});this.editor=t;const e=t.clientId;this.attributeName=[`data-editor-tooltip-${e}`,`data-editor-tooltip-${e}-dynamic`,"data-editor-tooltip-common"],this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=ig.delegate(document.body,{theme:"editor-tooltip",maxWidth:400,delay:200,target:this.attributeName.map(r=>`[${r}]`).join(","),content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden,hideOnClick:!1}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}set lastClickButtonId(t){this._lastClickButtonId=t,t&&setTimeout(()=>{this._lastClickButtonId===t&&(this._lastClickButtonId="")},500)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Ke.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,r={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,r)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}fixContainerForFullscreen(t){return t.closest("body")&&document.fullscreenElement&&!document.fullscreenElement.contains(t)?document.fullscreenElement:t}}const oK={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-sub":"subscript","text/style-super":"superscript",link:"link"};function sK(n,t){const e=new Set(Object.keys(oK)),r=t.filter(o=>e.has(o.id));return r0(r)}function Vu(n,t){if(!n.isWritable())return!1;const e=n.selection.range,r=n.editorCommandProviders.getCommands(e),o=sK(n,r).find(s=>s.id===`text/${t}`||s.id==="link");return o?(n.editorCommandProviders.executeCommand(e,o,{}),Ha.get(n).update("selectionChange"),!0):!1}function lK(n,t){const e=n.selection.focusedBlock;if(!n.isWritable()||!et(n,e))return!1;const r=n.getBlockData(e).heading,i={id:`heading-${t}`,source:"BlockTurnIntoCommandProvider",value:String(t)};return Number(r)===t&&(i.id="text",i.value=null),n.editorCommandProviders.executeCommand(n.selection.range,i,{}),!0}const SC={"CtrlOrCmd+B":n=>Vu(n,"style-bold"),"CtrlOrCmd+I":n=>Vu(n,"style-italic"),"CtrlOrCmd+U":n=>Vu(n,"style-underline"),"CtrlOrCmd+D":n=>Vu(n,"style-strikethrough"),"CtrlOrCmd+K":n=>Vu(n,"link"),...(()=>{const n={};for(let t=1;t<=8;t++)n[`CtrlOrCmd+${t}`]=e=>lK(e,t);return n})()},aK={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u5217\u8868",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88",edit:"\u7F16\u8F91",remove:"\u53D6\u6D88\u94FE\u63A5"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"}},cK={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"To-do list",quote:"Quote"},inlineBox:{math:"Formula",link:"Link"}},link:{textLabel:"Text",urlLabel:"Link address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter link",submitText:"Confirm",cancelText:"Cancel",edit:"Edit",remove:"Remove link"},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"To-do list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Center text",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"}},uK={quickMenu:{basic:{heading:{title:"\u898B\u51FA\u3057{heading}",space:"{markdown}\u30B9\u30DA\u30FC\u30B9"},unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",checkbox:"\u30D0\u30C3\u30AF\u30ED\u30B0",quote:"\u5F15\u7528"},inlineBox:{math:"\u6570\u5F0F",link:"URL"}},link:{textLabel:"\u30C6\u30AD\u30B9\u30C8",urlLabel:"URL",textPlaceholder:"\u30C6\u30AD\u30B9\u30C8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",urlPlaceholder:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",submitText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB",edit:"\u7DE8\u96C6",remove:"\u30EA\u30F3\u30AF\u3092\u89E3\u9664"},commands:{unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",check:"\u30D0\u30C3\u30AF\u30ED\u30B0",link:"URL",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u63C3\u3048",alignRight:"\u53F3\u63C3\u3048",alignCenter:"\u4E2D\u592E\u63C3\u3048",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u898B\u51FA\u3057{name}",headingGroup:"\u30BF\u30A4\u30C8\u30EB\u30B9\u30BF\u30A4\u30EB",text:"\u672C\u6587"}};D.mergeLang({"zh-CN":aK,"en-US":cK,"ja-JP":uK});const Vst="";function cl(n,...t){const e=Cr(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function ak(n){const t=i0(n);t==null||t.hide();const e=n.findCustom("table-border-bar");e==null||e.closeToolbar()}function fK(n){return B("div",["insert-column-button","drop-marker"],n)}const dK=I("row-height");function ck(n){const t=Lt.fromTable(n),e=n.rows;p(dK,e.length===t.rowCount,"row count mismatch");const r=Array(t.rowCount).fill(0);for(let i=0;i<e.length;){let o=1,l=e[i].getBoundingClientRect().height,c=i+1;for(;c<e.length;){const d=e[c];if(d.cells.length!==0)break;o++,c++,l+=d.getBoundingClientRect().height}for(let d=0;d<o;d++)r[i+d]=l/o;i=c}return r}const hK=I("table-border-bar-dom");function uk(n){var c;const t=nt(n.contentElement);p(hK,t,"no block");const r=ne(t).querySelector(".table-border-bar-container.left"),o=Ot(t).offsetLeft-_a,s=((c=n.scrollOptions.paddingLeft)!=null?c:0)+o,l=Math.min(n.contentElement.offsetLeft-o,n.rootElement.scrollLeft-s);r&&(r.style.left=`${-l}px`)}const ns=I("table-border-bar-dom");function Ga(n,t){p(ns,He(t),"invalid table block");const e=Me(t),r=xi(n,t),i=ne(t),o=(C,E,x)=>{const v=B("div",["button-root",E],C),R=B("div",["button-container",E],v);v.setAttribute(`data-${E}-index`,`${x}`),R.setAttribute(`data-editor-tooltip-${n.clientId}`,E==="left"?D.t("table.insertRow"):D.t("table.insertCol")),B("span",["insert-indicator"],R),fK(R)},{selectedRows:s,selectedColumns:l}=Pp(n,t),c=()=>{const C=r.querySelector(".table-border-bar-container.top");p(ns,C,"no top border bar container");const E=B("div",["table-border-bar-container","top"],null),x=B("div",["table-border-bar","top"],E),v=aN(e),L=Lt.fromTable(e).colCount;n.selection.range.isSimple()&&o(x,"top",0);for(let M=0;M<L;M++){const U=M===L-1?v[M]+2:v[M],F=B("span",["table-border-bar-cell","top"],x);l.has(M)&&F.classList.add("selected"),F.setAttribute("data-top-index",`${M}`),F.style.width=`${U}px`,n.selection.range.isSimple()&&o(x,"top",M+1)}jc(C,E)},d=()=>{const C=i.querySelector(".table-border-bar-container.left");p(ns,C,"no left border bar container");const E=B("div",["table-border-bar-container","left"],null),x=B("div",["table-border-bar","left"],E);B("span",["table-border-bar-cell","corner"],x);const v=ck(e);n.selection.range.isSimple()&&o(x,"left",0),Array.from(e.rows).forEach((R,L,M)=>{const U=B("span",["table-border-bar-cell","left"],x);s.has(L)&&U.classList.add("selected"),U.setAttribute("data-left-index",`${L}`);const F=L===M.length-1?v[L]+2:v[L];U.style.height=`${F}px`,n.selection.range.isSimple()&&o(x,"left",L+1)}),jc(C,E)};c(),d();const h=n.findCustom(Ai(t));h&&uk(h)}function fk(n,t){const e=t.target;if(!(e instanceof Element))return;const r=nt(e);p(ns,r&&He(r),"invalid table block"),Ga(n,r),n.selection.caret.update()}function x0(n,t){const e=t.target;if(!(e instanceof Element))return;const r=nt(e);p(ns,r&&He(r),"invalid table block");const i=e.closest(".button-root");if(i){if(i.classList.contains("top")){const o=parseInt(i.getAttribute("data-top-index")||"0",10);py(n,r,o),Ga(n,r)}else if(i.classList.contains("left")){const o=parseInt(i.getAttribute("data-left-index")||"0",10);eC(n,r,o),Ga(n,r)}}}function b0(n,t){var s;ak(n),t.preventDefault(),t.stopPropagation();let e=null,r,i;const o=l=>{var c;if(l.target instanceof HTMLElement&&r&&e&&i!==void 0){const d=nt(l.target),h=l.target.closest(".table-border-bar");if(d===e&&h){const C=parseInt((c=l.target.getAttribute(`data-${r}-index`))!=null?c:"0",10),E=Math.min(i,C),x=Math.abs(i-C)+1;Rt(l.target,"top")&&r==="top"?vN(n,d,E,x,{reverse:!0}):Rt(l.target,"left")&&r==="left"&&BN(n,d,E,x,{reverse:!0})}}l.type==="mouseup"&&(e=null,i=void 0,r=void 0,document.body.removeEventListener("mousemove",o),document.body.removeEventListener("mouseup",o))};t.target instanceof HTMLElement&&Rt(t.target,"table-border-bar-cell")&&(e=nt(t.target),Rt(t.target,"top")?r="top":Rt(t.target,"left")&&(r="left"),r&&e&&(i=parseInt((s=t.target.getAttribute(`data-${r}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",o),document.body.addEventListener("mouseup",o)))}function dk(n){const t=n.selection.range,e=Su(n,t);e&&Ga(n,e)}function mK(n,t){p(ns,He(t),"invalid table block");const e=xi(n,t),r=ne(t),i=B("div",["table-border-bar-container","top"],e),o=B("div",["table-border-bar-container","left"],r);Ga(n,t),n.domEvents.addEventListener(Ot(t),"scroll",fk),n.domEvents.addEventListener(i,"click",x0),n.domEvents.addEventListener(o,"click",x0),n.domEvents.addEventListener(i,"mousedown",b0),n.domEvents.addEventListener(o,"mousedown",b0),n.addListener("afterClearSelection",dk)}function hk(n,t){if(!n.isWritable())return;if(xi(n,t).querySelector(".table-border-bar-container")){Ga(n,t);return}mK(n,t)}function mk(n,t){p(ns,He(t),"invalid table block");const e=xi(n,t),r=ne(t),i=e.querySelectorAll(".table-border-bar-container"),o=r.querySelectorAll(".table-border-bar-container");i.forEach(s=>{n.domEvents.removeEventListener(s,"click",x0),n.domEvents.removeEventListener(s,"mousedown",b0),s.remove()}),o.forEach(s=>{n.domEvents.removeEventListener(s,"click",x0),n.domEvents.removeEventListener(s,"mousedown",b0),s.remove()}),n.domEvents.removeEventListener(Ot(t),"scroll",fk),n.addListener("afterClearSelection",dk)}function gK(n,t){p(ns,He(t),"invalid table block");const r=xi(n,t).querySelector(".table-border-bar-container.top");return r?r.getBoundingClientRect().height:0}class pK{constructor(t,e){g(this,"toolbar");g(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(e==="delete-columns"?(Yo(this.editor,this.tableBlock,!0,!0),Zo(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Yo(this.editor,this.tableBlock,!0,!1),Zo(this.editor,this.tableBlock,!0,!1)):(Yo(this.editor,this.tableBlock,!1),Zo(this.editor,this.tableBlock,!1)))});g(this,"handleClick",(t,e,r)=>{e.id==="delete-columns"?Fp(this.editor.selection.range):e.id==="delete-rows"&&Kp(this.editor.selection.range)});g(this,"handleToolbarClose",()=>{this.tableBlock&&Su(this.editor,this.editor.selection.range)===this.tableBlock&&(Yo(this.editor,this.tableBlock,!1),Zo(this.editor,this.tableBlock,!1))});this.editor=t,this.tableBlock=e;const r=t.options.componentsOptions.popover;this.toolbar=new ku([],void 0,{id:"table-row-column-toolbar",overflowBoundary:r==null?void 0:r.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick),this.toolbar.addListener("close",this.handleToolbarClose)}close(){this.toolbar.close("cancelBar")}update(){var i,o,s;const{selectedColumns:t,selectedRows:e}=Pp(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close("cancelBar");return}if(t.size===0&&e.size===0){this.toolbar.close("cancelBar");return}const r=qi(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!r){this.toolbar.close("cancelBar");return}if(t.size>0){const l={id:"delete-columns",name:D.t("table.deleteSelectCol"),icon:I2};this.toolbar.updateItems([l]);const c=Yi(this.editor,this.tableBlock,"table-row-column-delete",r);this.toolbar.manualShow(c,{placement:"top",offset:[0,5]})}else{const l={id:"delete-rows",name:D.t("table.deleteSelectRow"),icon:L2};this.toolbar.updateItems([l]);const h=ne(this.tableBlock).querySelector(".table-border-bar-container.left").getBoundingClientRect(),C=new DOMRect(Math.max(h.left,r.left-_a),r.top,_a,r.height),E=Yi(this.editor,this.tableBlock,"table-row-column-delete",C);this.toolbar.manualShow(E,{placement:"left",offset:[0,5]});const x=this.editor.options.componentsOptions.popover;(i=this.toolbar.tippyInstance)==null||i.setProps({popperOptions:{modifiers:[{name:"flip",options:{boundary:x==null?void 0:x.overflowBoundary,fallbackPlacements:["left","right"]}}]}})}(s=(o=this.toolbar.tippyInstance)==null?void 0:o.popperInstance)==null||s.update()}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const LC=I("table-border-bar");class CK{constructor(t,e){g(this,"toolbar");g(this,"resizeObserver",null);g(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():mk(this.editor,this.tableBlock)});g(this,"handleBlockUpdated",()=>{var t;(t=this.resizeObserver)==null||t.disconnect(),setTimeout(()=>{var r;const e=this.editor.getBlockById(st(this.tableBlock));(r=this.resizeObserver)==null||r.observe(Me(e))})});g(this,"handleScroll",()=>{var t;(t=this.toolbar)==null||t.update()});g(this,"handleTableResize",()=>{!this.editor.isWritable()||this.update()});this.editor=t,this.tableBlock=e,p(LC,this.tableBlock,"no table block"),LC.debug("create table border bar"),hk(this.editor,this.tableBlock),this.resizeObserver=new Ss(this.handleTableResize),this.resizeObserver.observe(Me(this.tableBlock));const r=t.getComponentOptions("table");r!=null&&r.hideToolbar||(this.toolbar=new pK(this.editor,this.tableBlock)),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){var t;(t=this.toolbar)==null||t.close()}destroy(){var t,e;LC.debug("destroy table border bar"),(t=this.resizeObserver)==null||t.disconnect(),this.resizeObserver=null,mk(this.editor,this.tableBlock),(e=this.toolbar)==null||e.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){var t;hk(this.editor,this.tableBlock),(t=this.toolbar)==null||t.update()}}const EK=I("table-border-bar");class AK{constructor(t){g(this,"activeTableBar",null);g(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||ee(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});g(this,"handleSelectionChanged",t=>{setTimeout(()=>{var i;const e=t.selection.range,r=Su(t,e);((i=this.activeTableBar)==null?void 0:i.tableBlock)!==r&&this.activeTableBar&&this.hide(),r&&this.show(r)})});g(this,"handleScroll",()=>{var t;(t=this.activeTableBar)==null||t.handleScroll()});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new CK(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(p(EK,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function gk(n,t){const e=n.addCustom("table-border-bar",r=>new AK(r));t==="update"&&e.update()}const Nn=I("table-cell-menu"),xK="style-bg-color-";class bK{constructor(t){g(this,"activeTableBlock",null);g(this,"targetButton",null);g(this,"manualMenu",null);g(this,"colorPaletteItem",null);g(this,"handlePrevent",(t,e)=>{e.stopPropagation()});g(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});g(this,"handleSelectionChanged",t=>{const e=t.selection.range,r=Su(t,e);if(this.hide(),this.activeTableBlock!==r&&(this.activeTableBlock=r),this.activeTableBlock){const i=Lt.fromBlock(this.activeTableBlock),o=e.isReverse()?e.start:e.end;let s=null;o instanceof Ur?t.getBlockById(o.blockId)===this.activeTableBlock?s=i.getCellByContainerId(o.childContainerId):s=this.getCellByChildBlockId(i,o.blockId):o.blockId!==this.activeTableBlock.id&&(s=this.getCellByChildBlockId(i,o.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});g(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});g(this,"createBkgColorItem",()=>{const t=B("div",["cell-background-color-item"],null);B("span",[],t,D.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();B("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const i=B("span",["item-sub-indicator"],t);return i.innerHTML=Ap,t});g(this,"handleCommand",t=>{var i;p(Nn,this.activeTableBlock,"no target table block");const e=((i=t.states)==null?void 0:i.includes("checked"))||!1,r=t.value;switch(t.id){case"delete-select-row":Kp(YT(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":Fp(YT(this.editor,this.activeTableBlock,!0));break;case"merge-cell":qT(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":DO(this.editor,this.activeTableBlock,r==="show-border");break;case"show-chart":UO(this.editor,this.activeTableBlock,r==="show-chart"),Wp(this.editor,this.activeTableBlock,{updateNow:!0});break}});g(this,"handleToolbarClose",()=>{this.targetButton&&ot(this.targetButton,"active"),this.activeTableBlock&&Su(this.editor,this.editor.selection.range)===this.activeTableBlock&&(Yo(this.editor,this.activeTableBlock,!1),Zo(this.editor,this.activeTableBlock,!1)),this.editor.focus()});g(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(p(Nn,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Yo(this.editor,this.activeTableBlock,!0,!1),Zo(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Yo(this.editor,this.activeTableBlock,!0,!0),Zo(this.editor,this.activeTableBlock,!0,!0)):(Yo(this.editor,this.activeTableBlock,!1),Zo(this.editor,this.activeTableBlock,!1)))});g(this,"handleClick",(t,e)=>{var r;p(Nn,this.activeTableBlock,"no target table block"),p(Nn,this.targetButton,"no target button"),ak(this.editor),Rt(this.targetButton,"active")?(ot(this.targetButton,"active"),(r=this.manualMenu)==null||r.close("clickItem")):(z(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new rl(this.createCommandMenu(),void 0,{id:"table-cell-menu"}),this.manualMenu.on("click",(i,o)=>{var s;this.handleCommand(o),(s=this.manualMenu)==null||s.close("clickItem")}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",this.handleToolbarClose)),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"})),e.stopPropagation()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close("cancelBar"),this.targetButton&&(ot(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let r=this.editor.getBlockById(e);for(;r;){const i=r.closest("td");p(Nn,i,"no parent cell");const o=nt(i);if(p(Nn,o,"no parent block"),Me(o)===t.table)return t.getCellByCellElement(i);r=o}return p(Nn,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${zp}`)||t.appendChild(this.targetButton):(this.targetButton=B("button",[zp],t),this.targetButton.innerHTML=_h,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent),this.editor.domEvents.addEventListener(this.targetButton,"dblclick",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),p(Nn,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=Lt.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:r,row:i}=this.getCellByChildBlockId(t,e.start.blockId);$p(this.editor,this.activeTableBlock,{col:r,row:i})}else Hp(this.editor.selection.range)}}getSelectedBkgColorIndex(){var s;p(Nn,this.activeTableBlock,"no target table block");const t=this.editor.selection.range,e=Qo(this.editor,this.activeTableBlock,t.focus),r=this.editor.getBlockData(this.activeTableBlock),i=e.childContainerId,o=r[`${i}_background`];return o?Number.parseInt((s=o.substring(xK.length))!=null?s:"0",10):-1}createCommandMenu(){p(Nn,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=WT(this.editor,this.activeTableBlock,this.editor.selection.range);let r=this.editor.selection.range;if(r.isSimple()){const h=Qo(this.editor,this.activeTableBlock,r.start);r=We(this.editor,{anchor:h,focus:h})}const i=GT(this.editor,this.activeTableBlock,r),o=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,d=t.chart;return this.colorPaletteItem=new FT("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(h,C)=>{var E;switch(p(Nn,this.activeTableBlock,"no target table block"),h){case"clearColor":ty(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":ty(this.editor,this.activeTableBlock,C);break}(E=this.manualMenu)==null||E.close("clickItem")}),[{id:"cell-background-color",name:D.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:D.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:D.t("table.splitCell"),states:i?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:D.t("table.deleteSelectRow")},{id:"delete-select-col",name:D.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:D.t("table.tableConfigKey"),children:[{id:"row-title",name:D.t("table.tableConfig.rowTitle"),states:o?["checked"]:[]},{id:"col-title",name:D.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:D.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?D.t("table.tableConfig.showBorder"):D.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:d?D.t("table.tableConfig.hideChart"):D.t("table.tableConfig.showChart"),value:d?"hide-chart":"show-chart"}]}]}handleRowTitle(t){p(Nn,this.activeTableBlock,"no target table block"),t?SO(this.editor,this.activeTableBlock):wO(this.editor,this.activeTableBlock)}handleColTitle(t){p(Nn,this.activeTableBlock,"no target table block"),t?RO(this.editor,this.activeTableBlock):kO(this.editor,this.activeTableBlock)}handleStripeStyle(t){p(Nn,this.activeTableBlock,"no target table block"),t?IO(this.editor,this.activeTableBlock):LO(this.editor,this.activeTableBlock)}}function pk(n){n.addCustom("table-cell-menu",t=>new bK(t))}const v0=I("table-container");function IC(n){const t=n.closest("td");return p(v0,t,"no parent cell for a table cell container"),t}function Ck(n){const t=Me(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function DC(n,t,e,r){const i=Lt.fromBlock(n),o=i.getCellByContainerId(ft(t));if(e==="ArrowDown"){const s=i.getBottomCell(o);return s?s.container:null}if(e==="ArrowUp"){const s=i.getTopCell(o);return s?s.container:null}if(e==="ArrowLeft"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(v0,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return r!=null&&r.noWrap&&i.getCellByContainerId(ft(c)).row!==o.row?null:c}if(e==="ArrowRight"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(v0,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return r!=null&&r.noWrap&&i.getCellByContainerId(ft(c)).row!==o.row?null:c}p(v0,!1,`invalid navigation type: ${e}`)}const vK=12,BK=90,B0=23,Ek=2;class TK{constructor(t){g(this,"scrollTableBlock",null);g(this,"autoScrollDir",null);g(this,"autoScrollTimer",null);g(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const r=nt(e);if(r&&ee(this.editor.rootContainer,r)){const i=co(r);i&&(this.scrollTableBlock=i,document.addEventListener("mousemove",this.handleAutoScroll))}}});g(this,"handleAutoScroll",f6.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=window.innerHeight-this.getBarFloatWindowBottom(e),l=i.getBoundingClientRect(),c=Math.min(l.bottom,s),d=Math.max(l.top,0);o.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):o.top<d&&t.clientY<=d?this.setAutoScroll("top"):r.scrollLeft>0&&t.clientX<o.left?this.setAutoScroll("left"):r.scrollLeft<r.scrollWidth-r.offsetWidth&&t.clientX>o.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));g(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});g(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId),i=co(r);if(i){const o=t.getCustom(Ai(i)),s=o.rootElement.getBoundingClientRect(),l=_r(t,r,e.start);if(s.left>l.left){const c=e.start.offset===0?vK:Ek;o.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?BK:Ek;o.rootElement.scrollLeft+=l.right-s.right+c}}}else{const r=t.getBlockById(e.start.blockId),i=co(r),o=t.getBlockById(e.end.blockId),s=co(o);if(i&&i===s){const l=t.getCustom(Ai(i)),c=l.rootElement.getBoundingClientRect();let d=null;if(e.isSimple())d=e.isReverse()?_r(t,r,e.start):_r(t,o,e.end);else{const h=IC(ci(t,e.start.childContainerId)),C=IC(ci(t,e.end.childContainerId));d=e.isReverse()?h.getBoundingClientRect():C.getBoundingClientRect()}c.left>d.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-d.left:c.right<d.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=d.right-c.right)}}});g(this,"handleScroll",t=>{HT(t),this.editor.selection.caret.update()});g(this,"handleReset",t=>{HT(t),this.editor.selection.caret.update();const e=this.editor.findCustom("table-border-bar");e&&e.handleScroll(),uk(t)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}getBarFloatWindowBottom(t){return t.scrollOptions.barFloatWindowBottom?typeof t.scrollOptions.barFloatWindowBottom=="number"?t.scrollOptions.barFloatWindowBottom:t.scrollOptions.barFloatWindowBottom():0}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=i===document.documentElement?window.innerHeight:i.offsetHeight,l=window.innerHeight-this.getBarFloatWindowBottom(e),c=i.getBoundingClientRect(),d=Math.min(c.bottom,l),h=Math.max(c.top,0);this.autoScrollDir==="left"&&(r.scrollLeft-=B0,r.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(r.scrollLeft+=B0,r.scrollLeft>=r.scrollWidth-r.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(i.scrollTop+=B0,(i.scrollTop>=i.scrollHeight-s||o.bottom<=d)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(i.scrollTop-=B0,(i.scrollTop<=0||o.top>=h)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function Ak(n){return n.addCustom("table-scroll-events",t=>new TK(t))}const yK=I("table-doc-change-handler");class kK{constructor(t){this.editor=t,this.editor.addListener("docChanged",this.handleDocChanged)}handleDocChanged(t,e){if(!e){const{start:r,end:i}=t.selection.range;if(!t.findBlockById(r.blockId)||!t.findBlockById(i.blockId)){t.selection.selectBlock(t.getBlockByIndex("root",0),0);return}if(sa(r)){const o=t.getBlockById(r.blockId);if(!He(o))return;if(p(yK,sa(i),"invalid range"),!Pd(t,r.childContainerId)||!Pd(t,i.childContainerId)){t.selection.selectBlock(o,0);return}let s=null,l=null;const c=(d,h)=>{const C=h.getCellById(d.childContainerId),{colIndex:E=0,rowIndex:x=0}=d.custom;let v=-1,R=-1;return(C.col>E||C.col+C.colSpan-1<E)&&(v=C.col),(C.row>x||C.row+C.rowSpan-1<x)&&(R=C.row),v!==-1||R!==-1?Ee(o,d.childContainerId,{colIndex:v===-1?E:v,rowIndex:R===-1?x:R}):null};if(r.custom){const d=Lt.fromBlock(o);s=c(r,d),l=c(i,d)}(s!==null||l!==null)&&(t.selection.range.isReverse()?t.selection.setSelection(l!=null?l:i,s!=null?s:r):t.selection.setSelection(s!=null?s:r,l!=null?l:i))}}}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged)}}function xk(n){n.addCustom("table-doc-change-handler",t=>new kK(t))}const bi=I("create-content");function bk(n,t,e){var C;const r=new qh(e),i=e.rows,o=e.cols;p(bi,i>=1,`invalid rows: ${i}`),p(bi,o>=1,`invalid cols: ${o}`),p(bi,e.children,"no table children");const s=B("table",[],null),l=(C=e.colsWidth)!=null?C:new Array(e.cols).fill(0),c=B("colgroup",[],s);for(let E=0;E<r.colCount;E++){const x=B("col",[],c);l[E]&&(x.style.width=`${l[E]}px`)}const d=B("tbody",[],s);let h=0;for(let E=0;E<i;E++){const x=B("tr",[],d);for(let v=0;v<o;v++){const R=r.getCell({col:v,row:E});if(R.virtual)p(bi,R.colSpan>1||R.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const L=e.children[h],M=B("td",[],x);R.colSpan>1&&(M.colSpan=R.colSpan),R.rowSpan>1&&(M.rowSpan=R.rowSpan);const U=e[Du(L)];U&&z(M,U),v===0&&e.hasColTitle&&z(M,XT.COL_TITLE_ITEM),n.createChildContainer(t,M,L),h+=1}}}return p(bi,h===e.children.length,"container count mismatch"),s.style.width=`${l.reduce((E,x)=>x+E,0)}px`,e.noBorder&&z(s,"no-border"),e.chart&&z(s,"editor-table-chart"),e.isStripeStyle&&z(s,"stripe"),e.hasRowTitle&&z(s,"row-title"),e.hasColTitle&&z(s,"col-title"),s}function RK(n,t,e,r,i){p(bi,i.type==="table","not table data"),p(bi,ft(e)===t[t.length-1].containerId,"invalid path");const o=i,s=Ks(r,"div");try{const l=B("div",[],null);l.setAttribute("data-type","table-content");const c=bk(n,t,o);c.classList.add("drag-preview-element"),l.appendChild(c);const d=n.getComponentOptions("table");my(n),Cy(n),gk(n,"create"),xk(n),d!=null&&d.hideCellMenu||pk(n),EU(n,qp);const h=n.addCustom(Ai(r),()=>sN());h.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Qt(e)?n.scrollContainer:e,locatingContainer:Qt(e)?(d==null?void 0:d.locatingContainer)||n.parent:e,paddingLeft:_a+Iu,paddingTop:_a+Iu,paddingBottom:Iu/2,paddingRight:Iu/2,barFloatWindowBottom:d==null?void 0:d.barFloatWindowBottom,allowScrollBarFixed:d==null?void 0:d.allowScrollBarFixed,isSetScale:d==null?void 0:d.isSetScale});const C=Ak(n);h.on("scroll",C.handleReset),h.on("resize",C.handleReset),setTimeout(()=>{PO(n,r)})}catch{const c=`invalid table data: ${JSON.stringify(o)}`;bi.error(c);const d=B("div",["error"],s);d.innerText=c}return s}function wK(n,t,e){p(bi,e.type==="table","not table data");const r=e,i=Ot(t);try{const o=Me(t),s=Ko(t),l=bk(n,s,r);l.classList.add("drag-preview-element"),o.insertAdjacentElement("afterend",l),o.remove();const c=n.getComponentOptions("table");my(n),Cy(n),gk(n,"update"),xk(n),c!=null&&c.hideCellMenu||pk(n),qp(n,t)}catch{const s=`invalid table data: ${JSON.stringify(r)}`;bi.error(s);const l=B("div",["error"],i);l.innerText=s}}function SK(n,t){let e,r,i=!1;if([...t].every(E=>E==="|")?(r=t.length,e=Array(r).fill(""),i=!0):(e=Eg(t,"|").split("|"),r=e.length),r<2)return null;const o=3,s=r,l=[];for(let E=0;E<3;E++)e.forEach(x=>{l.push(no(n.doc,E===0?x:""))});const c=Array(s).fill(Yp),d=l[i?0:s],h=n.doc.getContainerBlocks(d)[0].id;return{blockData:{id:J(),type:"table",rows:o,cols:s,children:l,colsWidth:c},focusBlockId:h}}function LK(n,t){const e=t.rows,r=t.cols;if(e<1||r<1)return null;const i=[];for(let d=0;d<e;d++)for(let h=0;h<r;h++)i.push(no(n.doc));const o=Array(r).fill(Yp),s=i[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:J(),type:"table",rows:e,cols:r,children:i,colsWidth:o},focusBlockId:l}}const _C=I("get-selected-containers");function vk(n,t,e,r){p(_C,e.blockId===r.blockId,"only allow select in single table block"),p(_C,st(t)===e.blockId,"only allow select in single table block");const i=Lt.fromBlock(t),o=i.getCellByContainerId(e.childContainerId),s=i.getCellByContainerId(r.childContainerId);if(e.custom===void 0||r.custom===void 0)return i.getCells(o,s).map(L=>i.getCellContainer(L));const{fromCol:l,toCol:c,fromRow:d,toRow:h}=Gr(t,e,r),C=new Set,E=[];return i.sub({row:d,col:l},{row:h,col:c}).forEach(v=>{v.forEach(R=>{const L=i.getCellByContainerId(R.containerId);L.col<l||L.row<d||L.col+L.colSpan-1>c||L.row+L.rowSpan-1>h||C.has(R.containerId)||(C.add(R.containerId),E.push(L.container))})}),E}function IK(n,t,e){p(_C,t.blockId===e.blockId,"only allow select in single table block");const r=n.getBlockById(t.blockId);return vk(n,r,t,e)}const Bk=I("table-selection-to-doc");function DK(n,t){const{start:e,end:r,block:i}=t,o=It(i);p(Bk,o==="table",`invalid block type: ${o}`);const s=n.getBlockData(i);if(e.isSimple()&&r.isSimple())return zo(n.editorBlocks,n.doc.toJSON(),s);p(Bk,!e.isSimple()&&!r.isSimple(),"invalid block pos type");const l=Lt.fromBlock(i),{fromCol:c,toCol:d,fromRow:h,toRow:C}=Gr(i,e,r),E={},x=[],v=n.doc.toJSON();let R={};l.sub({row:h,col:c},{row:C,col:d}).forEach((rt,at)=>{rt.forEach((At,Mt)=>{const kt=At.containerId;if(x.indexOf(kt)!==-1)return;x.push(kt);let se;if(At.virtual){const Se=l.getCellByContainerId(At.containerId),Pn=c+Mt;let Li=Se.col+Se.colSpan-1;Li>d&&(Li=d);const yn=Li-Pn+1;yn>1&&(E[`${kt}_colSpan`]=yn);const gn=h+at;let Ii=Se.row+Se.rowSpan-1;Ii>C&&(Ii=C);const mo=Ii-gn+1;mo>1&&(E[`${kt}_rowSpan`]=mo),se=eo()}else{if(se=I1(n.editorBlocks,v,kt),At.col+At.colSpan>d+1){const Se=d-At.col+1;Se>1&&(E[`${kt}_colSpan`]=Se)}else At.colSpan>1&&(E[`${kt}_colSpan`]=At.colSpan);if(At.row+At.rowSpan>C+1){const Se=C-At.row+1;Se>1&&(E[`${kt}_rowSpan`]=Se)}else At.rowSpan>1&&(E[`${kt}_rowSpan`]=At.rowSpan)}const{root:ue,...nr}=se.blocks;R={...R,...nr,[kt]:ue}})});const M=Nu(Me(i)).slice(c,d+1);return{blocks:{root:[{id:J(),type:o,children:x,colsWidth:M,rows:C-h+1,cols:d-c+1,...E}],...R},meta:{},comments:{}}}function _K(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function MK(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function UK(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function OK(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function NK(n,t,e){const r=t.col,i=t.row,o=e.col,s=e.row,l={left:r,top:i,right:o,bottom:s};let c=!1;do{if(c=!1,!_K(n,l)){l.top--,c=!0;continue}if(!MK(n,l)){l.left--,c=!0;continue}if(!UK(n,l)){l.bottom++,c=!0;continue}if(!OK(n,l)){l.right++,c=!0;continue}}while(c);return l}function PK(n,t,e,r){if(e.custom!==void 0||r.custom!==void 0)return{anchor:e,focus:r};const i=Lt.fromBlock(t),o=i.map(F=>F.containerId),s=i.getCellByContainerId(e.childContainerId),l=i.getCellByContainerId(r.childContainerId),c=Math.min(s.row,l.row),d=Math.max(s.row,l.row),h=Math.min(s.col,l.col),C=Math.max(s.col,l.col),E=NK(o,{row:c,col:h},{row:d,col:C}),x=i.getCell({row:E.top,col:E.left}),v=i.getCell({row:E.bottom,col:E.right}),R=i.getCell({row:E.top,col:E.right}),L=i.getCell({row:E.bottom,col:E.left});let M,U;return s.row<=l.row?s.col<=l.col?(M=x,U=v):(M=R,U=L):s.col<l.col?(M=L,U=R):(M=v,U=x),console.log(`move ${M.col}, ${M.row}, -> ${U.col}, ${U.row}`),{anchor:Ee(t,M.containerId),focus:Ee(t,U.containerId)}}function Tk(n,t,e){if(e.isSimple())return[Me(t).getBoundingClientRect()];const r=Me(t),i=r.getBoundingClientRect(),{fromCol:o,fromRow:s,toCol:l,toRow:c}=Gr(t,e.start,e.end),d=Nu(r),h=d.slice(0,o).reduce((R,L)=>R+L,0),C=h+d.slice(o,l+1).reduce((R,L)=>R+L,0),E=ck(r);let x=E.slice(0,s).reduce((R,L)=>R+L,0);const v=x+E.slice(s,c+1).reduce((R,L)=>R+L,0);if(s===0){const R=gK(n,t);x-=R}return[new DOMRect(i.left+h,i.top+x,C-h,v-x)]}I("table-size");const FK=40;function T0(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),r=Number.parseInt(e.borderLeft,10),i=Number.parseInt(e.borderRight,10);return(r+i)/2}function KK(n,t,e){const r=Fg(n,e.container);return r!==void 0?r+T0(t):FK*e.colSpan-T0(t)}function VK(n,t,e,r){let i=0;const o=e.colCount;for(let s=0;s<o;s++){const l=e.getCell({col:s,row:r});if(l.virtual)continue;let c=KK(n,t,l);const d=Rv(l.container,{withPadding:!0});d&&d>c&&(c=d),i+=c+T0(t)}return i}function $K(n,t){const e=Me(t),r=Lt.fromTable(e);let i=0;for(let s=0;s<r.rowCount;s++)i=Math.max(i,VK(n,e,r,s));const o=T0(e);return i+=o,i}const uo=I("table-creator");async function HK(n,t){return n.undoManager.runInGroup(()=>{var c,d;const e=t.item,r=(c=e.colCount)!=null?c:5,i=(d=e.rowCount)!=null?d:3,o=LK(n,{cols:r,rows:i});if(!o)return null;const{blockData:s,focusBlockId:l}=o;return n.insertBlock(t.containerId,t.blockIndex,s,ve(n,l,0))})}class jK{constructor(){g(this,"id","insert-table");g(this,"name","Create table");g(this,"element");g(this,"closeable",null);g(this,"colCount");g(this,"rowCount");g(this,"setCloseable",t=>{this.closeable=t});g(this,"destroy",()=>{this.closeable=null});g(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);g(this,"handleTableCreatorClick",t=>{var E,x;t.preventDefault(),t.stopPropagation();const e=t.target;p(uo,e instanceof HTMLElement,"invalid event target");const r=e.closest(".table-creator");p(uo,r,"no table creator");const i=r.querySelectorAll(".active");if(i.length===0)return;const s=i[i.length-1].id;p(uo,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const d=s.substring(l.length).split("-");p(uo,d.length===2,"invalid cell id");const h=Number.parseInt(d[0],10)+1,C=Number.parseInt(d[1],10)+1;uo.debug(`${h}, ${C}`),this.colCount=C,this.rowCount=h,(E=this.closeable)==null||E.click(this,this.element),(x=this.closeable)==null||x.close("clickItem"),this.handleTableCreatorLeave()});g(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const r=this.getTableCreatorCellId(t,e),i=document.getElementById(r);i&&ot(i,"active")}});g(this,"handleTableCreatorCellEnter",t=>{const e=t.target;p(uo,e instanceof HTMLElement,"invalid event target");const r=e.id,i="table-creator-cell-";p(uo,r.startsWith(i),"invalid cell id");const s=r.substring(i.length).split("-");p(uo,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let d=0;d<9;d++)for(let h=0;h<9;h++){const C=this.getTableCreatorCellId(d,h),E=document.getElementById(C);p(uo,E,"no cell"),d<=l&&h<=c?z(E,"active"):ot(E,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=B("div",["table-creator"],null),e=(r,i,o)=>{const s=B("div",["table-creator-cell"],r);return s.id=this.getTableCreatorCellId(i,o),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let r=0;r<9;r++){const i=B("div",["table-creator-row"],t);for(let o=0;o<9;o++)e(i,r,o).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function zK(){return new jK}function GK(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function yk(n){const t=GK(n);return n.length+t}function WK(n,t,e=[]){let r=0;if(!e||e.length===0)return r;for(let i=n;i<n+t;i+=1)r+=e[i]||0;return r}function qK(n,t){const e=yk(n),r=t-e;return r>0?n+" ".repeat(r):n}function XK(n,t,e,r,i){var l;const o=t,s=new qh(o);if(r==="markdown"||r==="text"){const c=M=>e.blocks[M].map((G,q)=>r==="markdown"?x1(n,G,e,[...i,{containerId:M,blockIndex:q}]):oh(n,G,e,[...i,{containerId:M,blockIndex:q}])),d=M=>c(M).join(" ").replace(/\n/g," ").trim(),h=new Map,C=new Map;for(let M=0;M<s.colCount;M++){let U=0;for(let F=0;F<s.rowCount;F++){const G=s.getCell({row:F,col:M});let q="";G.virtual||(q=d(G.containerId)),h.set(`${F},${M}`,q),U=Math.max(U,yk(q))}C.set(M,U)}const E=M=>{const U=h.get(`${M.row},${M.col}`)||"",F=C.get(M.col)||0;return qK(U,F)};if(r==="text"){const M=[];for(let U=0;U<s.colCount;U++){const F=E({row:0,col:U});M.push(F)}for(let U=1;U<s.rowCount;U++)for(let F=0;F<s.colCount;F++){const G=E({row:U,col:F});M.push(G)}return M.join(`
|
|
638
|
+
}`;var Nt=DL(function(){return Wt(w,Et+"return "+tt).apply(e,O)});if(Nt.source=tt,Mx(Nt))throw Nt;return Nt}function oit(a){return te(a).toLowerCase()}function sit(a){return te(a).toUpperCase()}function lit(a,u,m){if(a=te(a),a&&(m||u===e))return xo(a);if(!a||!(u=sr(u)))return a;var A=or(a),T=or(u),w=Il(A,T),O=Xf(A,T)+1;return ys(A,w,O).join("")}function ait(a,u,m){if(a=te(a),a&&(m||u===e))return a.slice(0,Rc(a)+1);if(!a||!(u=sr(u)))return a;var A=or(a),T=Xf(A,or(u))+1;return ys(A,0,T).join("")}function cit(a,u,m){if(a=te(a),a&&(m||u===e))return a.replace(wf,"");if(!a||!(u=sr(u)))return a;var A=or(a),T=Il(A,or(u));return ys(A,T).join("")}function uit(a,u){var m=kt,A=se;if(Te(u)){var T="separator"in u?u.separator:T;m="length"in u?Ut(u.length):m,A="omission"in u?sr(u.omission):A}a=te(a);var w=a.length;if(bo(a)){var O=or(a);w=O.length}if(m>=w)return a;var P=m-xs(A);if(P<1)return A;var V=O?ys(O,0,P).join(""):a.slice(0,P);if(T===e)return V+A;if(O&&(P+=V.length-P),Ux(T)){if(a.slice(P).search(T)){var Q,Y=V;for(T.global||(T=Ic(T.source,te(dc.exec(T))+"g")),T.lastIndex=0;Q=T.exec(Y);)var tt=Q.index;V=V.slice(0,tt===e?P:tt)}}else if(a.indexOf(sr(T),P)!=P){var ht=V.lastIndexOf(T);ht>-1&&(V=V.slice(0,ht))}return V+A}function fit(a){return a=te(a),a&&sA.test(a)?a.replace(om,wc):a}var dit=_c(function(a,u,m){return a+(m?" ":"")+u.toUpperCase()}),Px=_S("toUpperCase");function IL(a,u,m){return a=te(a),u=m?e:u,u===e?Tc(a)?Rm(a):rr(a):a.match(u)||[]}var DL=Pt(function(a,u){try{return kn(a,e,u)}catch(m){return Mx(m)?m:new wt(m)}}),hit=Mo(function(a,u){return Kn(u,function(m){m=Ki(m),Do(a,m,Dx(a[m],a))}),a});function mit(a){var u=a==null?0:a.length,m=vt();return a=u?ge(a,function(A){if(typeof A[1]!="function")throw new Rn(s);return[m(A[0]),A[1]]}):[],Pt(function(A){for(var T=-1;++T<u;){var w=a[T];if(kn(w[0],this,A))return kn(w[1],this,A)}})}function git(a){return PJ(yr(a,C))}function Fx(a){return function(){return a}}function pit(a,u){return a==null||a!==a?u:a}var Cit=US(),Eit=US(!0);function Gn(a){return a}function Kx(a){return fS(typeof a=="function"?a:yr(a,C))}function Ait(a){return hS(yr(a,C))}function xit(a,u){return mS(a,yr(u,C))}var bit=Pt(function(a,u){return function(m){return od(m,a,u)}}),vit=Pt(function(a,u){return function(m){return od(a,m,u)}});function Vx(a,u,m){var A=tn(u),T=Pm(u,A);m==null&&!(Te(u)&&(T.length||!A.length))&&(m=u,u=a,a=this,T=Pm(u,tn(u)));var w=!(Te(m)&&"chain"in m)||!!m.chain,O=Oo(a);return Kn(T,function(P){var V=u[P];a[P]=V,O&&(a.prototype[P]=function(){var Q=this.__chain__;if(w||Q){var Y=a(this.__wrapped__),tt=Y.__actions__=Hn(this.__actions__);return tt.push({func:V,args:arguments,thisArg:a}),Y.__chain__=Q,Y}return V.apply(a,Ui([this.value()],arguments))})}),a}function Bit(){return Ye._===this&&(Ye._=Sm),this}function $x(){}function Tit(a){return a=Ut(a),Pt(function(u){return gS(u,a)})}var yit=Ax(ge),kit=Ax(Am),Rit=Ax(Gf);function _L(a){return kx(a)?bc(Ki(a)):ett(a)}function wit(a){return function(u){return a==null?e:Xl(a,u)}}var Sit=NS(),Lit=NS(!0);function Hx(){return[]}function jx(){return!1}function Iit(){return{}}function Dit(){return""}function _it(){return!0}function Mit(a,u){if(a=Ut(a),a<1||a>gn)return[];var m=xr,A=_(a,xr);u=vt(u),a-=xr;for(var T=Bc(A,u);++m<a;)u(m);return T}function Uit(a){return Dt(a)?ge(a,Ki):lr(a)?[a]:Hn(JS(te(a)))}function Oit(a){var u=++wm;return te(a)+u}var Nit=jm(function(a,u){return a+u},0),Pit=xx("ceil"),Fit=jm(function(a,u){return a/u},1),Kit=xx("floor");function Vit(a){return a&&a.length?Nm(a,Gn,ox):e}function $it(a,u){return a&&a.length?Nm(a,vt(u,2),ox):e}function Hit(a){return xc(a,Gn)}function jit(a,u){return xc(a,vt(u,2))}function zit(a){return a&&a.length?Nm(a,Gn,cx):e}function Git(a,u){return a&&a.length?Nm(a,vt(u,2),cx):e}var Wit=jm(function(a,u){return a*u},1),qit=xx("round"),Xit=jm(function(a,u){return a-u},0);function Qit(a){return a&&a.length?vc(a,Gn):0}function Yit(a,u){return a&&a.length?vc(a,vt(u,2)):0}return k.after=Ant,k.ary=uL,k.assign=srt,k.assignIn=TL,k.assignInWith=rg,k.assignWith=lrt,k.at=art,k.before=fL,k.bind=Dx,k.bindAll=hit,k.bindKey=dL,k.castArray=Int,k.chain=lL,k.chunk=Ptt,k.compact=Ftt,k.concat=Ktt,k.cond=mit,k.conforms=git,k.constant=Fx,k.countBy=Qet,k.create=crt,k.curry=hL,k.curryRight=mL,k.debounce=gL,k.defaults=urt,k.defaultsDeep=frt,k.defer=xnt,k.delay=bnt,k.difference=Vtt,k.differenceBy=$tt,k.differenceWith=Htt,k.drop=jtt,k.dropRight=ztt,k.dropRightWhile=Gtt,k.dropWhile=Wtt,k.fill=qtt,k.filter=Zet,k.flatMap=ent,k.flatMapDeep=nnt,k.flatMapDepth=rnt,k.flatten=rL,k.flattenDeep=Xtt,k.flattenDepth=Qtt,k.flip=vnt,k.flow=Cit,k.flowRight=Eit,k.fromPairs=Ytt,k.functions=Ert,k.functionsIn=Art,k.groupBy=int,k.initial=Jtt,k.intersection=tet,k.intersectionBy=eet,k.intersectionWith=net,k.invert=brt,k.invertBy=vrt,k.invokeMap=snt,k.iteratee=Kx,k.keyBy=lnt,k.keys=tn,k.keysIn=zn,k.map=Ym,k.mapKeys=Trt,k.mapValues=yrt,k.matches=Ait,k.matchesProperty=xit,k.memoize=Jm,k.merge=krt,k.mergeWith=yL,k.method=bit,k.methodOf=vit,k.mixin=Vx,k.negate=tg,k.nthArg=Tit,k.omit=Rrt,k.omitBy=wrt,k.once=Bnt,k.orderBy=ant,k.over=yit,k.overArgs=Tnt,k.overEvery=kit,k.overSome=Rit,k.partial=_x,k.partialRight=pL,k.partition=cnt,k.pick=Srt,k.pickBy=kL,k.property=_L,k.propertyOf=wit,k.pull=set,k.pullAll=oL,k.pullAllBy=aet,k.pullAllWith=cet,k.pullAt=uet,k.range=Sit,k.rangeRight=Lit,k.rearg=ynt,k.reject=dnt,k.remove=fet,k.rest=knt,k.reverse=Lx,k.sampleSize=mnt,k.set=Irt,k.setWith=Drt,k.shuffle=gnt,k.slice=det,k.sortBy=Ent,k.sortedUniq=Aet,k.sortedUniqBy=xet,k.split=eit,k.spread=Rnt,k.tail=bet,k.take=vet,k.takeRight=Bet,k.takeRightWhile=Tet,k.takeWhile=yet,k.tap=Vet,k.throttle=wnt,k.thru=Qm,k.toArray=bL,k.toPairs=RL,k.toPairsIn=wL,k.toPath=Uit,k.toPlainObject=BL,k.transform=_rt,k.unary=Snt,k.union=ket,k.unionBy=Ret,k.unionWith=wet,k.uniq=Let,k.uniqBy=Iet,k.uniqWith=Det,k.unset=Mrt,k.unzip=Ix,k.unzipWith=sL,k.update=Urt,k.updateWith=Ort,k.values=Oc,k.valuesIn=Nrt,k.without=_et,k.words=IL,k.wrap=Lnt,k.xor=Met,k.xorBy=Uet,k.xorWith=Oet,k.zip=Net,k.zipObject=Pet,k.zipObjectDeep=Fet,k.zipWith=Ket,k.entries=RL,k.entriesIn=wL,k.extend=TL,k.extendWith=rg,Vx(k,k),k.add=Nit,k.attempt=DL,k.camelCase=Vrt,k.capitalize=SL,k.ceil=Pit,k.clamp=Prt,k.clone=Dnt,k.cloneDeep=Mnt,k.cloneDeepWith=Unt,k.cloneWith=_nt,k.conformsTo=Ont,k.deburr=LL,k.defaultTo=pit,k.divide=Fit,k.endsWith=$rt,k.eq=ii,k.escape=Hrt,k.escapeRegExp=jrt,k.every=Yet,k.find=Jet,k.findIndex=eL,k.findKey=drt,k.findLast=tnt,k.findLastIndex=nL,k.findLastKey=hrt,k.floor=Kit,k.forEach=aL,k.forEachRight=cL,k.forIn=mrt,k.forInRight=grt,k.forOwn=prt,k.forOwnRight=Crt,k.get=Ox,k.gt=Nnt,k.gte=Pnt,k.has=xrt,k.hasIn=Nx,k.head=iL,k.identity=Gn,k.includes=ont,k.indexOf=Ztt,k.inRange=Frt,k.invoke=Brt,k.isArguments=Zl,k.isArray=Dt,k.isArrayBuffer=Fnt,k.isArrayLike=jn,k.isArrayLikeObject=Pe,k.isBoolean=Knt,k.isBuffer=ks,k.isDate=Vnt,k.isElement=$nt,k.isEmpty=Hnt,k.isEqual=jnt,k.isEqualWith=znt,k.isError=Mx,k.isFinite=Gnt,k.isFunction=Oo,k.isInteger=CL,k.isLength=eg,k.isMap=EL,k.isMatch=Wnt,k.isMatchWith=qnt,k.isNaN=Xnt,k.isNative=Qnt,k.isNil=Znt,k.isNull=Ynt,k.isNumber=AL,k.isObject=Te,k.isObjectLike=Ie,k.isPlainObject=fd,k.isRegExp=Ux,k.isSafeInteger=Jnt,k.isSet=xL,k.isString=ng,k.isSymbol=lr,k.isTypedArray=Uc,k.isUndefined=trt,k.isWeakMap=ert,k.isWeakSet=nrt,k.join=ret,k.kebabCase=zrt,k.last=Rr,k.lastIndexOf=iet,k.lowerCase=Grt,k.lowerFirst=Wrt,k.lt=rrt,k.lte=irt,k.max=Vit,k.maxBy=$it,k.mean=Hit,k.meanBy=jit,k.min=zit,k.minBy=Git,k.stubArray=Hx,k.stubFalse=jx,k.stubObject=Iit,k.stubString=Dit,k.stubTrue=_it,k.multiply=Wit,k.nth=oet,k.noConflict=Bit,k.noop=$x,k.now=Zm,k.pad=qrt,k.padEnd=Xrt,k.padStart=Qrt,k.parseInt=Yrt,k.random=Krt,k.reduce=unt,k.reduceRight=fnt,k.repeat=Zrt,k.replace=Jrt,k.result=Lrt,k.round=qit,k.runInContext=K,k.sample=hnt,k.size=pnt,k.snakeCase=tit,k.some=Cnt,k.sortedIndex=het,k.sortedIndexBy=met,k.sortedIndexOf=get,k.sortedLastIndex=pet,k.sortedLastIndexBy=Cet,k.sortedLastIndexOf=Eet,k.startCase=nit,k.startsWith=rit,k.subtract=Xit,k.sum=Qit,k.sumBy=Yit,k.template=iit,k.times=Mit,k.toFinite=No,k.toInteger=Ut,k.toLength=vL,k.toLower=oit,k.toNumber=wr,k.toSafeInteger=ort,k.toString=te,k.toUpper=sit,k.trim=lit,k.trimEnd=ait,k.trimStart=cit,k.truncate=uit,k.unescape=fit,k.uniqueId=Oit,k.upperCase=dit,k.upperFirst=Px,k.each=aL,k.eachRight=cL,k.first=iL,Vx(k,function(){var a={};return Pi(k,function(u,m){qt.call(k.prototype,m)||(a[m]=u)}),a}(),{chain:!1}),k.VERSION=r,Kn(["bind","bindKey","curry","curryRight","partial","partialRight"],function(a){k[a].placeholder=k}),Kn(["drop","take"],function(a,u){Vt.prototype[a]=function(m){m=m===e?1:S(Ut(m),0);var A=this.__filtered__&&!u?new Vt(this):this.clone();return A.__filtered__?A.__takeCount__=_(m,A.__takeCount__):A.__views__.push({size:_(m,xr),type:a+(A.__dir__<0?"Right":"")}),A},Vt.prototype[a+"Right"]=function(m){return this.reverse()[a](m).reverse()}}),Kn(["filter","map","takeWhile"],function(a,u){var m=u+1,A=m==Se||m==Li;Vt.prototype[a]=function(T){var w=this.clone();return w.__iteratees__.push({iteratee:vt(T,3),type:m}),w.__filtered__=w.__filtered__||A,w}}),Kn(["head","last"],function(a,u){var m="take"+(u?"Right":"");Vt.prototype[a]=function(){return this[m](1).value()[0]}}),Kn(["initial","tail"],function(a,u){var m="drop"+(u?"":"Right");Vt.prototype[a]=function(){return this.__filtered__?new Vt(this):this[m](1)}}),Vt.prototype.compact=function(){return this.filter(Gn)},Vt.prototype.find=function(a){return this.filter(a).head()},Vt.prototype.findLast=function(a){return this.reverse().find(a)},Vt.prototype.invokeMap=Pt(function(a,u){return typeof a=="function"?new Vt(this):this.map(function(m){return od(m,a,u)})}),Vt.prototype.reject=function(a){return this.filter(tg(vt(a)))},Vt.prototype.slice=function(a,u){a=Ut(a);var m=this;return m.__filtered__&&(a>0||u<0)?new Vt(m):(a<0?m=m.takeRight(-a):a&&(m=m.drop(a)),u!==e&&(u=Ut(u),m=u<0?m.dropRight(-u):m.take(u-a)),m)},Vt.prototype.takeRightWhile=function(a){return this.reverse().takeWhile(a).reverse()},Vt.prototype.toArray=function(){return this.take(xr)},Pi(Vt.prototype,function(a,u){var m=/^(?:filter|find|map|reject)|While$/.test(u),A=/^(?:head|last)$/.test(u),T=k[A?"take"+(u=="last"?"Right":""):u],w=A||/^find/.test(u);!T||(k.prototype[u]=function(){var O=this.__wrapped__,P=A?[1]:arguments,V=O instanceof Vt,Q=P[0],Y=V||Dt(O),tt=function(jt){var zt=T.apply(k,Ui([jt],P));return A&&ht?zt[0]:zt};Y&&m&&typeof Q=="function"&&Q.length!=1&&(V=Y=!1);var ht=this.__chain__,Et=!!this.__actions__.length,Bt=w&&!ht,Nt=V&&!Et;if(!w&&Y){O=Nt?O:new Vt(this);var Tt=a.apply(O,P);return Tt.__actions__.push({func:Qm,args:[tt],thisArg:e}),new $n(Tt,ht)}return Bt&&Nt?a.apply(this,P):(Tt=this.thru(tt),Bt?A?Tt.value()[0]:Tt.value():Tt)})}),Kn(["pop","push","shift","sort","splice","unshift"],function(a){var u=Ul[a],m=/^(?:push|sort|unshift)$/.test(a)?"tap":"thru",A=/^(?:pop|shift)$/.test(a);k.prototype[a]=function(){var T=arguments;if(A&&!this.__chain__){var w=this.value();return u.apply(Dt(w)?w:[],T)}return this[m](function(O){return u.apply(Dt(O)?O:[],T)})}}),Pi(Vt.prototype,function(a,u){var m=k[u];if(m){var A=m.name+"";qt.call(sn,A)||(sn[A]=[]),sn[A].push({name:u,func:m})}}),sn[Hm(e,M).name]=[{name:"wrapper",func:e}],Vt.prototype.clone=cJ,Vt.prototype.reverse=uJ,Vt.prototype.value=fJ,k.prototype.at=$et,k.prototype.chain=Het,k.prototype.commit=jet,k.prototype.next=zet,k.prototype.plant=Wet,k.prototype.reverse=qet,k.prototype.toJSON=k.prototype.valueOf=k.prototype.value=Xet,k.prototype.first=k.prototype.head,$l&&(k.prototype[$l]=Get),k},To=Lc();Eo?((Eo.exports=To)._=To,Pf._=To):Ye._=To}).call(Dn)})(rn,rn.exports);function NF(n,t,e,r){Wh(n,{className:"status-input",defaultValue:t,onChange:e,onKeyDown:r,maxLength:32})}const rk=["Blue","Grey","Yellow","Red","Green","Purple"];function PF(){const n=B("div",["status-color-palette"],null);for(const t of rk){const e=B("button",["status-box-button"],null);e.setAttribute("data-color",rn.exports.lowerCase(t)),e.setAttribute("title",D.t(`status.color.${rn.exports.lowerCase(t)}`)),n.appendChild(e)}return n}class FF{constructor(){g(this,"root",PF());g(this,"changeColor",t=>{for(const r of Array.from(this.root.querySelectorAll(":scope > button")))r.classList.remove("selected");const e=this.root.querySelector(`button[data-color="${rn.exports.lowerCase(t)}"]`);e==null||e.classList.add("selected")})}}function ik(n){var o;const t=rk[0],e=(o=n.settingsProvider.getItem(`statusBox.lastColor.${rn.exports.lowerCase(t)}`))!=null?o:D.t(`status.colorDefaultTitle.${rn.exports.lowerCase(t)}`);return{insert:" ",attributes:{id:J(),type:"status",box:!0,title:e,subtle:!1,created:Date.now(),color:t}}}function KF(n,t){localStorage.setItem(`statusBox.lastColor.${rn.exports.lowerCase(t.color)}`,t.title)}function VF(n,t){var e;return(e=localStorage.getItem(`statusBox.lastColor.${rn.exports.lowerCase(t)}`))!=null?e:D.t(`status.colorDefaultTitle.${rn.exports.lowerCase(t)}`)}class $F{constructor(t,e,r,i){g(this,"root");g(this,"ro");g(this,"mo");this.editor=t;const o=B("a",r,null,this.replaceTitleSpace(e));this.root=o,i.appendChild(o),this.observeResize(),this.observeRemoval()}replaceTitleSpace(t){return t.replace(/\s/g,"\xA0")}check(){return this.root.scrollWidth>this.root.offsetWidth}observeResize(){this.ro=new ResizeObserver(rn.exports.debounce(t=>{for(const e of t)if(this.check()){const r=this.root.textContent||"";e.target.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,r)}else e.target.removeAttribute(`data-editor-tooltip-${this.editor.clientId}`)},200)),this.ro.observe(this.root)}handleContentChange(){if(this.check()){const t=this.root.textContent||"";this.root.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,t)}else this.root.removeAttribute(`data-editor-tooltip-${this.editor.clientId}`)}observeRemoval(){this.mo=new MutationObserver(t=>{t.forEach(e=>{e.target===this.root&&e.type==="childList"&&this.handleContentChange(),e.removedNodes.forEach(r=>{r===this.root&&(this.unbindResizeObserver(),this.unbindMutationObserver())})})}),this.root.parentElement&&(this.mo.observe(this.root.parentElement,{childList:!0}),this.mo.observe(this.root,{childList:!0}))}unbindResizeObserver(){var t;(t=this.ro)==null||t.unobserve(this.root)}unbindMutationObserver(){var t;(t=this.mo)==null||t.disconnect()}rebind(t){this.unbindResizeObserver(),this.unbindMutationObserver(),this.root=t,this.observeResize(),this.observeRemoval()}changeTag(t,e){this.root.textContent=this.replaceTitleSpace(t),this.root.className=e.join(" ")}destroy(){this.unbindResizeObserver(),this.unbindMutationObserver()}}class kC{static create(t,e,r,i){const{title:o,id:s}=r;if(this.tagRef.has(s)){const c=this.tagRef.get(s);return c==null||c.changeTag(o||D.t("status.empty"),e),i.appendChild(c==null?void 0:c.root),setTimeout(()=>{c==null||c.rebind(Qc(t.getBoxById(s)).firstChild)}),c}const l=new $F(t,o,e,i);return this.tagRef.set(s,l),setTimeout(()=>{l.rebind(Qc(t.getBoxById(s)).firstChild)}),l}static remove(t){const e=this.tagRef.get(t);this.tagRef.delete(t),e==null||e.destroy()}}g(kC,"tagRef",new Map);const C0=I("StatusBoxEditor");class RC{constructor(t){g(this,"linkPopup",null);g(this,"boxElement");g(this,"statusPalette",new FF);g(this,"isEditing",!1);g(this,"editorStatus",t=>{if(!this.editor.isWritable())return;const e=this.editor.getBoxData(t);this.linkPopup=new Sa(this.createPopupContent(e.title,e.color,e.subtle),{id:"status-box-popup"}),this.linkPopup.on("show",this.handleShow),this.linkPopup.on("close",this.handClose),this.linkPopup.manualShow(t,{theme:"light",placement:"bottom-start",offset:[5,5]}),this.boxElement=t});g(this,"handleShow",()=>{this.focus()});g(this,"handClose",()=>{var r;p(C0,this.boxElement,"boxElement not found");const t=this.editor.getBoxData(this.boxElement),e=nt(this.boxElement);if(p(C0,e,"block not found"),t.title)KF(this.editor,t);else{const i=$o(e,this.boxElement);this.editor.deleteTextFromBlock(e,i.start,1),kC.remove(t.id)}this.editor.focus(),(r=this.linkPopup)==null||r.destroy(),this.linkPopup=null,this.boxElement=void 0,this.isEditing=!1});g(this,"handleKeyDown",t=>{var e;t.key==="Enter"&&((e=this.linkPopup)==null||e.close(null))});g(this,"onColorChange",t=>{var o,s;if(!(t.target instanceof HTMLElement)||t.target.closest("[data-color]")===null)return;const e=rn.exports.upperCase(t.target.getAttribute("data-color"));p(C0,this.boxElement,"boxElement not found");const r=this.editor.getBoxData(this.boxElement);this.statusPalette.changeColor(e);const i={...r,color:e};if(!this.isEditing){const l=(s=(o=this.linkPopup)==null?void 0:o.popper)==null?void 0:s.querySelector("input"),c=VF(this.editor,e);l&&(l.value=c),i.title=c}this.editor.updateBoxData(i,{noFocus:!0}),this.focus()});g(this,"changeTitle",t=>{const e=t.target.value;p(C0,this.boxElement,"boxElement not found");const i={...this.editor.getBoxData(this.boxElement),title:e.trim()};this.editor.updateBoxData(i,{noFocus:!0}),this.isEditing=!0});this.editor=t,this.statusPalette.root.addEventListener("click",this.onColorChange)}focus(){setTimeout(()=>{var t,e,r,i,o,s;(r=(e=(t=this.linkPopup)==null?void 0:t.popper)==null?void 0:e.querySelector("input"))==null||r.focus(),(s=(o=(i=this.linkPopup)==null?void 0:i.popper)==null?void 0:o.querySelector("input"))==null||s.select()},100)}createPopupContent(t,e,r){const i=B("div",["status-box-editor-popup"],null);return NF(i,t,this.changeTitle,this.handleKeyDown),this.isEditing=!1,i.appendChild(this.statusPalette.root),this.statusPalette.changeColor(e),i}destroy(){var t;(t=this.linkPopup)==null||t.destroy()}}const Ost="";function HF(n,t,e,r){const i=r,{title:o,subtle:s,color:l}=i,c=s?["box-status-common",`box-status-${rn.exports.lowerCase(l)}-subtle`]:["box-status-common",`box-status-${rn.exports.lowerCase(l)}`];o||c.push("box-status-empty"),kC.create(n,c,r,e),n.addCustom("status-box",d=>new RC(d))}function jF(n,t){return{abstract:D.t("status.command.name")}}function zF(n,t){n.getCustom("status-box").editorStatus(t)}function GF(n,t){const{title:e}=t;return e!=null?e:""}async function WF(n,t){const{title:e}=t;return[{insert:e!=null?e:""}]}const ok={boxType:"status",updateBoxContent:HF,getBoxProperties:jF,handleClickBox:zF,convertTo:GF,toStandardText:WF},qF=I("status-box-command");class ja{static get commands(){return[{id:this.id,name:D.t("status.command.name"),icon:RT,order:650,group:"common",subText:"/status"}]}static insertStatus(t,e,r){var c;const i=t.getBlockByIndex(e,r),o=ik(t),{start:s}=t.selection.range;p(qF,Or(s),"invalid block position"),t.insertBoxToBlock(i,s.offset,o.attributes);const l=t.getBoxById((c=o.attributes)==null?void 0:c.id);t.addCustom("status-box",d=>new RC(d)).editorStatus(l)}static insertEmptyBlockStatus(t,e,r){var l;let i=t.getBlockByIndex(e,r);(!i||!re(t,i))&&(i=t.insertTextBlock([],e,r));const o=ik(t);t.setBlockText(i,[o]);const s=t.getBoxById((l=o.attributes)==null?void 0:l.id);return t.addCustom("status-box",c=>new RC(c)).editorStatus(s),i}}g(ja,"id","insert-status");const XF={"en-US":{status:{empty:"\u8BBE\u7F6E\u72B6\u6001",command:{name:"\u72B6\u6001"},color:{red:"\u7EA2\u8272",yellow:"\u9EC4\u8272",green:"\u7EFF\u8272",blue:"\u84DD\u8272",purple:"\u7D2B\u8272",grey:"\u7070\u8272"},colorDefaultTitle:{red:"\u5DF2\u5EF6\u671F",yellow:"\u8FDB\u884C\u4E2D",green:"\u5DF2\u5B8C\u6210",blue:"\u672A\u5F00\u59CB",purple:"\u5DF2\u53D6\u6D88",grey:"\u6682\u505C"}}},"zh-CN":{status:{empty:"\u672A\u5F00\u59CB",command:{name:"\u72B6\u6001"},color:{red:"\u7EA2\u8272",yellow:"\u9EC4\u8272",green:"\u7EFF\u8272",blue:"\u84DD\u8272",purple:"\u7D2B\u8272",grey:"\u7070\u8272"},colorDefaultTitle:{red:"\u672A\u5F00\u59CB",yellow:"\u8FDB\u884C\u4E2D",green:"\u5DF2\u5B8C\u6210",blue:"\u5DF2\u5F52\u6863",purple:"\u5DF2\u53D6\u6D88",grey:"\u6682\u505C"}}},"ja-JP":{status:{empty:"\u8BBE\u7F6E\u72B6\u6001",command:{name:"\u72B6\u6001"},color:{red:"\u7EA2\u8272",yellow:"\u9EC4\u8272",green:"\u7EFF\u8272",blue:"\u84DD\u8272",purple:"\u7D2B\u8272",grey:"\u7070\u8272"},colorDefaultTitle:{red:"\u672A\u5F00\u59CB",yellow:"\u8FDB\u884C\u4E2D",green:"\u5DF2\u5B8C\u6210",blue:"\u672A\u5F00\u59CB",purple:"\u5DF2\u53D6\u6D88",grey:"\u6682\u505C"}}}};D.mergeLang(XF);const za=I("inline-box-items");function QF(n,t,e){return n.undoManager.runInGroup(()=>{var s;let r=n.getBlockByIndex(t,e);(!r||!re(n,r))&&(r=n.insertTextBlock([],t,e));const i=tk();n.setBlockText(r,[i]);const o=(s=i.attributes)==null?void 0:s.id;return p(za,o,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(o);p0(n,l)},100),r})}function YF(n,t,e){let r=n.getBlockByIndex(t,e),i="bottom-start";return(!r||!re(n,r))&&(i="top-start",r=n.insertTextBlock([],t,e)),Pu(n,{target:r,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{re(n,r)||(r=n.insertTextBlock([],t,e));const d=gr(l,{link:c}),h=gr(" ",null),C=[d,h];n.insertTextToBlock(r,0,C),n.selection.selectBlock(r,fn(C)),n.focus()}catch(d){za.error(d)}})},onClose:()=>{n.focus()},placement:i}),r}function ZF(n,t,e){return n.undoManager.runInGroup(()=>{var l;const r=n.getBlockByIndex(t,e),i=n.selection.range;p(za,Or(i.start),"invalid block position");const o=tk();n.insertBoxToBlock(r,i.start.offset,o.attributes);const s=(l=o.attributes)==null?void 0:l.id;return p(za,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);p0(n,c)},100),r})}function JF(n,t,e){const r=n.getBlockByIndex(t,e),i=n.selection.range;p(za,Or(i.start),"invalid block position");const o=qi(n,r,i);if(o.length===0)return;const s=o[0],l=Yi(n,r,"quick-menu-inline-link",s);Pu(n,{target:l,linkText:"",linkUrl:"",onFinished:(h,C)=>{n.undoManager.runInGroup(()=>{try{const E=n.getBlockText(r),x=to(E,i.start.offset,h,{link:C});n.setBlockText(r,x),n.selection.selectBlock(r,i.start.offset+h.length),n.focus()}catch(E){za.error(E)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class sk{getCommands(){return[{id:"insert-math",name:D.t("quickMenu.inlineBox.math"),icon:j2,order:900,group:"common",subText:Bn("insert-math")},{id:"insert-link",name:D.t("quickMenu.inlineBox.link"),icon:yp,order:400,group:"common",subText:Bn("insert-link")},...ja.commands]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return ZF(t,e.containerId,e.blockIndex);case"insert-link":return JF(t,e.containerId,e.blockIndex);case ja.id:return ja.insertStatus(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return QF(t,e.containerId,e.blockIndex);case"insert-link":return YF(t,e.containerId,e.blockIndex);case ja.id:return ja.insertEmptyBlockStatus(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,r){if(r.from==="quick-menu"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=ft(o),l=t.getBlockIndex(i);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else r.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:r.containerId,blockIndex:r.blockIndex}));return null}}function tK(n,t={withPlainText:!1}){var o,s;const{withPlainText:e}=t,r=(s=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:s.commandProviders;if(!r)return[];const i=[];return[...r,new Wy(e),new sk].forEach(l=>{const c=l.getCommands(n);i.push(...c.map(d=>({...d,itemType:"insert-block",commandProvider:l})))}),i}function eK(n,t={withPlainText:!1}){const e=[];return n.editorBlocks.forEach(r=>{if(!r.getOptions)return;const i=r.getOptions(n);!i.insertBlockCommandItems||(i.insertBlockCommandItems.forEach(o=>{Gy(o,i)}),e.push(...i.insertBlockCommandItems))}),e.push(...tK(n,t)),e}function wC(n,t={withPlainText:!1}){const e=eK(n,t),r=new Map;e.forEach(s=>{var d;const l=(d=s.group)!=null?d:"";let c=r.get(l);c?c.items.push(s):(c={group:l,order:s.groupOrder||qy[l]||1e3,items:[s]},r.set(l,c))});const i=Array.from(r.values());i.sort((s,l)=>s.order-l.order),i.forEach(s=>{s.items.sort((l,c)=>{var d,h;return((d=l.order)!=null?d:0)-((h=c.order)!=null?h:0)})});const o=[];return i.forEach((s,l)=>{const c=`blockMenu.section.${s.group||"common"}`,d=D.t(c),h=d===c?s.group:d;o.push({id:`section-${l}`,name:h,type:"section",group:s.group,itemType:"insert-block"}),o.push(...s.items.map(C=>({...C})))}),o}function nK(n,t,e){const r=n.getFocusedBlock();if(!r)return;const i=n.getParentContainer(r),o=ft(i);let l=n.getBlockIndex(r);if(re(n,r)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:o,blockIndex:l,item:t})}const lk=I("quick-menu"),rK={id:"quick-menu",trigger:["/"]},iK=5;class E0{constructor(t,e=rK){g(this,"suggest");g(this,"items");g(this,"maxHeading");g(this,"firstEmptyOffset",-1);g(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const r=new Set,i=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,""),o=this.items.filter(s=>{if(s.type==="section")return!0;if(s.name.toLocaleLowerCase().indexOf(i)!==-1||fO(s).toLocaleLowerCase().indexOf(i)!==-1)return r.add(s.group),!0;const l=`blockMenu.section.${s.group||"common"}`,c=D.t(l),d=c===l?s.group:c;return(d==null?void 0:d.toLocaleLowerCase().indexOf(i))!==-1?(r.add(s.group),!0):!1}).filter(s=>s.type==="section"?r.has(s.group):!0);return o.length?this.firstEmptyOffset=-1:this.handleEmptySearch(),o}return this.items});g(this,"onClose",()=>{this.firstEmptyOffset=-1});g(this,"onShow",(t,e,r,i)=>{const o=this.editor.getBlockByIndex(e,r);if(!dr(o)){const s=nt(it(o));if(s&&It(s)==="code")return!1}return!0});g(this,"onClickItem",(t,e)=>{const r=e;r.itemType==="insert-block"&&(p(lk,r.blockOptions||r.commandProvider,"invalid quick item, no block options or command provider"),p(lk,this.suggest.anchor,"invalid suggest, no anchor"),this.options.id==="empty-block-menu"&&this.editor.focus(),nK(this.editor,r,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=o0(),this.suggest=new Op(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=wC(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const r=o0();if(r!==this.maxHeading){const i=new Wy,s=i.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:i}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=r}}handleEmptySearch(){const t=this.editor.selection.getFocusedPos();if(this.firstEmptyOffset===-1){if(t.isSimple()){const{offset:e}=t;this.firstEmptyOffset=e-1}}else if(t.isSimple()){const{offset:e}=t;e-this.firstEmptyOffset>iK&&(this.suggest.close(),this.firstEmptyOffset=-1)}}}class A0{constructor(t){g(this,"instance");g(this,"mousedown",!1);g(this,"currentInstance",null);g(this,"attributeName",[]);g(this,"attributeDesc","");g(this,"_lastClickButtonId","");g(this,"observer",null);g(this,"observerCallback",null);g(this,"createContent",t=>{let e="",r=0;for(;r<this.attributeName.length&&!e;)t.hasAttribute(this.attributeName[r])&&(e=t.getAttribute(this.attributeName[r])||""),r++;const i=t.getAttribute(this.attributeDesc);if(!i)return e;const o=B("div",[],null);return B("span",[],o,e),i&&B("span",["editor-tooltip-desc"],o,i),o});g(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});g(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});g(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});g(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});g(this,"handleShow",t=>{var i;const e=t.reference;if(!e||!ee(document.body,e)||window.isDragging||this.mousedown)return!1;const r=Number.parseInt((i=e.getAttribute("data-tooltip-hide-at"))!=null?i:"",10);if(r&&Date.now()-r<1e3)return!1;if(this._lastClickButtonId===e.getAttribute("data-button-id"))return this._lastClickButtonId="",!1;if(this.attributeName.every(o=>!e.hasAttribute(o)))return!1;if(t.reference){const o={};if(t.reference.hasAttribute("data-editor-tooltip-placement")&&(o.placement=t.reference.getAttribute("data-editor-tooltip-placement")||"top"),t.reference.hasAttribute("data-editor-tooltip-offset-x")||t.reference.hasAttribute("data-editor-tooltip-offset-y")){const l=t.reference.getAttribute("data-editor-tooltip-offset-x"),c=t.reference.getAttribute("data-editor-tooltip-offset-y");o.offset=[l?Number.parseInt(l,10):0,c?Number.parseInt(c,10):0]}t.reference.hasAttribute("data-editor-tooltip-maxwidth")&&(o.maxWidth=Number.parseInt(t.reference.getAttribute("data-editor-tooltip-maxwidth")||"350",10)),t.reference.hasAttribute("data-editor-tooltip-allow-markdown")&&(o.allowHTML=!0);const s=document.body;if(o.appendTo=this.fixContainerForFullscreen(s),Object.keys(o).length&&t.setProps(o),t.reference.hasAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`)){const l=t.reference.getAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`);t.setContent(l||"")}}return!0});this.editor=t;const e=t.clientId;this.attributeName=[`data-editor-tooltip-${e}`,`data-editor-tooltip-${e}-dynamic`,"data-editor-tooltip-common"],this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=ig.delegate(document.body,{theme:"editor-tooltip",maxWidth:400,delay:200,target:this.attributeName.map(r=>`[${r}]`).join(","),content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden,hideOnClick:!1}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}set lastClickButtonId(t){this._lastClickButtonId=t,t&&setTimeout(()=>{this._lastClickButtonId===t&&(this._lastClickButtonId="")},500)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Ke.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,r={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,r)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}fixContainerForFullscreen(t){return t.closest("body")&&document.fullscreenElement&&!document.fullscreenElement.contains(t)?document.fullscreenElement:t}}const oK={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-sub":"subscript","text/style-super":"superscript",link:"link"};function sK(n,t){const e=new Set(Object.keys(oK)),r=t.filter(o=>e.has(o.id));return r0(r)}function Vu(n,t){if(!n.isWritable())return!1;const e=n.selection.range,r=n.editorCommandProviders.getCommands(e),o=sK(n,r).find(s=>s.id===`text/${t}`||s.id==="link");return o?(n.editorCommandProviders.executeCommand(e,o,{}),Ha.get(n).update("selectionChange"),!0):!1}function lK(n,t){const e=n.selection.focusedBlock;if(!n.isWritable()||!et(n,e))return!1;const r=n.getBlockData(e).heading,i={id:`heading-${t}`,source:"BlockTurnIntoCommandProvider",value:String(t)};return Number(r)===t&&(i.id="text",i.value=null),n.editorCommandProviders.executeCommand(n.selection.range,i,{}),!0}const SC={"CtrlOrCmd+B":n=>Vu(n,"style-bold"),"CtrlOrCmd+I":n=>Vu(n,"style-italic"),"CtrlOrCmd+U":n=>Vu(n,"style-underline"),"CtrlOrCmd+D":n=>Vu(n,"style-strikethrough"),"CtrlOrCmd+K":n=>Vu(n,"link"),...(()=>{const n={};for(let t=1;t<=8;t++)n[`CtrlOrCmd+${t}`]=e=>lK(e,t);return n})()},aK={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u5217\u8868",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88",edit:"\u7F16\u8F91",remove:"\u53D6\u6D88\u94FE\u63A5"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"}},cK={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"To-do list",quote:"Quote"},inlineBox:{math:"Formula",link:"Link"}},link:{textLabel:"Text",urlLabel:"Link address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter link",submitText:"Confirm",cancelText:"Cancel",edit:"Edit",remove:"Remove link"},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"To-do list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Center text",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"}},uK={quickMenu:{basic:{heading:{title:"\u898B\u51FA\u3057{heading}",space:"{markdown}\u30B9\u30DA\u30FC\u30B9"},unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",checkbox:"\u30D0\u30C3\u30AF\u30ED\u30B0",quote:"\u5F15\u7528"},inlineBox:{math:"\u6570\u5F0F",link:"URL"}},link:{textLabel:"\u30C6\u30AD\u30B9\u30C8",urlLabel:"URL",textPlaceholder:"\u30C6\u30AD\u30B9\u30C8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",urlPlaceholder:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",submitText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB",edit:"\u7DE8\u96C6",remove:"\u30EA\u30F3\u30AF\u3092\u89E3\u9664"},commands:{unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",check:"\u30D0\u30C3\u30AF\u30ED\u30B0",link:"URL",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u63C3\u3048",alignRight:"\u53F3\u63C3\u3048",alignCenter:"\u4E2D\u592E\u63C3\u3048",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u898B\u51FA\u3057{name}",headingGroup:"\u30BF\u30A4\u30C8\u30EB\u30B9\u30BF\u30A4\u30EB",text:"\u672C\u6587"}};D.mergeLang({"zh-CN":aK,"en-US":cK,"ja-JP":uK});const Vst="";function cl(n,...t){const e=Cr(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function ak(n){const t=i0(n);t==null||t.hide();const e=n.findCustom("table-border-bar");e==null||e.closeToolbar()}function fK(n){return B("div",["insert-column-button","drop-marker"],n)}const dK=I("row-height");function ck(n){const t=Lt.fromTable(n),e=n.rows;p(dK,e.length===t.rowCount,"row count mismatch");const r=Array(t.rowCount).fill(0);for(let i=0;i<e.length;){let o=1,l=e[i].getBoundingClientRect().height,c=i+1;for(;c<e.length;){const d=e[c];if(d.cells.length!==0)break;o++,c++,l+=d.getBoundingClientRect().height}for(let d=0;d<o;d++)r[i+d]=l/o;i=c}return r}const hK=I("table-border-bar-dom");function uk(n){var c;const t=nt(n.contentElement);p(hK,t,"no block");const r=ne(t).querySelector(".table-border-bar-container.left"),o=Ot(t).offsetLeft-_a,s=((c=n.scrollOptions.paddingLeft)!=null?c:0)+o,l=Math.min(n.contentElement.offsetLeft-o,n.rootElement.scrollLeft-s);r&&(r.style.left=`${-l}px`)}const ns=I("table-border-bar-dom");function Ga(n,t){p(ns,He(t),"invalid table block");const e=Me(t),r=xi(n,t),i=ne(t),o=(C,E,x)=>{const v=B("div",["button-root",E],C),R=B("div",["button-container",E],v);v.setAttribute(`data-${E}-index`,`${x}`),R.setAttribute(`data-editor-tooltip-${n.clientId}`,E==="left"?D.t("table.insertRow"):D.t("table.insertCol")),B("span",["insert-indicator"],R),fK(R)},{selectedRows:s,selectedColumns:l}=Pp(n,t),c=()=>{const C=r.querySelector(".table-border-bar-container.top");p(ns,C,"no top border bar container");const E=B("div",["table-border-bar-container","top"],null),x=B("div",["table-border-bar","top"],E),v=aN(e),L=Lt.fromTable(e).colCount;n.selection.range.isSimple()&&o(x,"top",0);for(let M=0;M<L;M++){const U=M===L-1?v[M]+2:v[M],F=B("span",["table-border-bar-cell","top"],x);l.has(M)&&F.classList.add("selected"),F.setAttribute("data-top-index",`${M}`),F.style.width=`${U}px`,n.selection.range.isSimple()&&o(x,"top",M+1)}jc(C,E)},d=()=>{const C=i.querySelector(".table-border-bar-container.left");p(ns,C,"no left border bar container");const E=B("div",["table-border-bar-container","left"],null),x=B("div",["table-border-bar","left"],E);B("span",["table-border-bar-cell","corner"],x);const v=ck(e);n.selection.range.isSimple()&&o(x,"left",0),Array.from(e.rows).forEach((R,L,M)=>{const U=B("span",["table-border-bar-cell","left"],x);s.has(L)&&U.classList.add("selected"),U.setAttribute("data-left-index",`${L}`);const F=L===M.length-1?v[L]+2:v[L];U.style.height=`${F}px`,n.selection.range.isSimple()&&o(x,"left",L+1)}),jc(C,E)};c(),d();const h=n.findCustom(Ai(t));h&&uk(h)}function fk(n,t){const e=t.target;if(!(e instanceof Element))return;const r=nt(e);p(ns,r&&He(r),"invalid table block"),Ga(n,r),n.selection.caret.update()}function x0(n,t){const e=t.target;if(!(e instanceof Element))return;const r=nt(e);p(ns,r&&He(r),"invalid table block");const i=e.closest(".button-root");if(i){if(i.classList.contains("top")){const o=parseInt(i.getAttribute("data-top-index")||"0",10);py(n,r,o),Ga(n,r)}else if(i.classList.contains("left")){const o=parseInt(i.getAttribute("data-left-index")||"0",10);eC(n,r,o),Ga(n,r)}}}function b0(n,t){var s;ak(n),t.preventDefault(),t.stopPropagation();let e=null,r,i;const o=l=>{var c;if(l.target instanceof HTMLElement&&r&&e&&i!==void 0){const d=nt(l.target),h=l.target.closest(".table-border-bar");if(d===e&&h){const C=parseInt((c=l.target.getAttribute(`data-${r}-index`))!=null?c:"0",10),E=Math.min(i,C),x=Math.abs(i-C)+1;Rt(l.target,"top")&&r==="top"?vN(n,d,E,x,{reverse:!0}):Rt(l.target,"left")&&r==="left"&&BN(n,d,E,x,{reverse:!0})}}l.type==="mouseup"&&(e=null,i=void 0,r=void 0,document.body.removeEventListener("mousemove",o),document.body.removeEventListener("mouseup",o))};t.target instanceof HTMLElement&&Rt(t.target,"table-border-bar-cell")&&(e=nt(t.target),Rt(t.target,"top")?r="top":Rt(t.target,"left")&&(r="left"),r&&e&&(i=parseInt((s=t.target.getAttribute(`data-${r}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",o),document.body.addEventListener("mouseup",o)))}function dk(n){const t=n.selection.range,e=Su(n,t);e&&Ga(n,e)}function mK(n,t){p(ns,He(t),"invalid table block");const e=xi(n,t),r=ne(t),i=B("div",["table-border-bar-container","top"],e),o=B("div",["table-border-bar-container","left"],r);Ga(n,t),n.domEvents.addEventListener(Ot(t),"scroll",fk),n.domEvents.addEventListener(i,"click",x0),n.domEvents.addEventListener(o,"click",x0),n.domEvents.addEventListener(i,"mousedown",b0),n.domEvents.addEventListener(o,"mousedown",b0),n.addListener("afterClearSelection",dk)}function hk(n,t){if(!n.isWritable())return;if(xi(n,t).querySelector(".table-border-bar-container")){Ga(n,t);return}mK(n,t)}function mk(n,t){p(ns,He(t),"invalid table block");const e=xi(n,t),r=ne(t),i=e.querySelectorAll(".table-border-bar-container"),o=r.querySelectorAll(".table-border-bar-container");i.forEach(s=>{n.domEvents.removeEventListener(s,"click",x0),n.domEvents.removeEventListener(s,"mousedown",b0),s.remove()}),o.forEach(s=>{n.domEvents.removeEventListener(s,"click",x0),n.domEvents.removeEventListener(s,"mousedown",b0),s.remove()}),n.domEvents.removeEventListener(Ot(t),"scroll",fk),n.addListener("afterClearSelection",dk)}function gK(n,t){p(ns,He(t),"invalid table block");const r=xi(n,t).querySelector(".table-border-bar-container.top");return r?r.getBoundingClientRect().height:0}class pK{constructor(t,e){g(this,"toolbar");g(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(e==="delete-columns"?(Yo(this.editor,this.tableBlock,!0,!0),Zo(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Yo(this.editor,this.tableBlock,!0,!1),Zo(this.editor,this.tableBlock,!0,!1)):(Yo(this.editor,this.tableBlock,!1),Zo(this.editor,this.tableBlock,!1)))});g(this,"handleClick",(t,e,r)=>{e.id==="delete-columns"?Fp(this.editor.selection.range):e.id==="delete-rows"&&Kp(this.editor.selection.range)});g(this,"handleToolbarClose",()=>{this.tableBlock&&Su(this.editor,this.editor.selection.range)===this.tableBlock&&(Yo(this.editor,this.tableBlock,!1),Zo(this.editor,this.tableBlock,!1))});this.editor=t,this.tableBlock=e;const r=t.options.componentsOptions.popover;this.toolbar=new ku([],void 0,{id:"table-row-column-toolbar",overflowBoundary:r==null?void 0:r.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick),this.toolbar.addListener("close",this.handleToolbarClose)}close(){this.toolbar.close("cancelBar")}update(){var i,o,s;const{selectedColumns:t,selectedRows:e}=Pp(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close("cancelBar");return}if(t.size===0&&e.size===0){this.toolbar.close("cancelBar");return}const r=qi(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!r){this.toolbar.close("cancelBar");return}if(t.size>0){const l={id:"delete-columns",name:D.t("table.deleteSelectCol"),icon:I2};this.toolbar.updateItems([l]);const c=Yi(this.editor,this.tableBlock,"table-row-column-delete",r);this.toolbar.manualShow(c,{placement:"top",offset:[0,5]})}else{const l={id:"delete-rows",name:D.t("table.deleteSelectRow"),icon:L2};this.toolbar.updateItems([l]);const h=ne(this.tableBlock).querySelector(".table-border-bar-container.left").getBoundingClientRect(),C=new DOMRect(Math.max(h.left,r.left-_a),r.top,_a,r.height),E=Yi(this.editor,this.tableBlock,"table-row-column-delete",C);this.toolbar.manualShow(E,{placement:"left",offset:[0,5]});const x=this.editor.options.componentsOptions.popover;(i=this.toolbar.tippyInstance)==null||i.setProps({popperOptions:{modifiers:[{name:"flip",options:{boundary:x==null?void 0:x.overflowBoundary,fallbackPlacements:["left","right"]}}]}})}(s=(o=this.toolbar.tippyInstance)==null?void 0:o.popperInstance)==null||s.update()}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const LC=I("table-border-bar");class CK{constructor(t,e){g(this,"toolbar");g(this,"resizeObserver",null);g(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():mk(this.editor,this.tableBlock)});g(this,"handleBlockUpdated",()=>{var t;(t=this.resizeObserver)==null||t.disconnect(),setTimeout(()=>{var r;const e=this.editor.getBlockById(st(this.tableBlock));(r=this.resizeObserver)==null||r.observe(Me(e))})});g(this,"handleScroll",()=>{var t;(t=this.toolbar)==null||t.update()});g(this,"handleTableResize",()=>{!this.editor.isWritable()||this.update()});this.editor=t,this.tableBlock=e,p(LC,this.tableBlock,"no table block"),LC.debug("create table border bar"),hk(this.editor,this.tableBlock),this.resizeObserver=new Ss(this.handleTableResize),this.resizeObserver.observe(Me(this.tableBlock));const r=t.getComponentOptions("table");r!=null&&r.hideToolbar||(this.toolbar=new pK(this.editor,this.tableBlock)),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){var t;(t=this.toolbar)==null||t.close()}destroy(){var t,e;LC.debug("destroy table border bar"),(t=this.resizeObserver)==null||t.disconnect(),this.resizeObserver=null,mk(this.editor,this.tableBlock),(e=this.toolbar)==null||e.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){var t;hk(this.editor,this.tableBlock),(t=this.toolbar)==null||t.update()}}const EK=I("table-border-bar");class AK{constructor(t){g(this,"activeTableBar",null);g(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||ee(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});g(this,"handleSelectionChanged",t=>{setTimeout(()=>{var i;const e=t.selection.range,r=Su(t,e);((i=this.activeTableBar)==null?void 0:i.tableBlock)!==r&&this.activeTableBar&&this.hide(),r&&this.show(r)})});g(this,"handleScroll",()=>{var t;(t=this.activeTableBar)==null||t.handleScroll()});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new CK(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(p(EK,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function gk(n,t){const e=n.addCustom("table-border-bar",r=>new AK(r));t==="update"&&e.update()}const Nn=I("table-cell-menu"),xK="style-bg-color-";class bK{constructor(t){g(this,"activeTableBlock",null);g(this,"targetButton",null);g(this,"manualMenu",null);g(this,"colorPaletteItem",null);g(this,"handlePrevent",(t,e)=>{e.stopPropagation()});g(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});g(this,"handleSelectionChanged",t=>{const e=t.selection.range,r=Su(t,e);if(this.hide(),this.activeTableBlock!==r&&(this.activeTableBlock=r),this.activeTableBlock){const i=Lt.fromBlock(this.activeTableBlock),o=e.isReverse()?e.start:e.end;let s=null;o instanceof Ur?t.getBlockById(o.blockId)===this.activeTableBlock?s=i.getCellByContainerId(o.childContainerId):s=this.getCellByChildBlockId(i,o.blockId):o.blockId!==this.activeTableBlock.id&&(s=this.getCellByChildBlockId(i,o.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});g(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});g(this,"createBkgColorItem",()=>{const t=B("div",["cell-background-color-item"],null);B("span",[],t,D.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();B("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const i=B("span",["item-sub-indicator"],t);return i.innerHTML=Ap,t});g(this,"handleCommand",t=>{var i;p(Nn,this.activeTableBlock,"no target table block");const e=((i=t.states)==null?void 0:i.includes("checked"))||!1,r=t.value;switch(t.id){case"delete-select-row":Kp(YT(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":Fp(YT(this.editor,this.activeTableBlock,!0));break;case"merge-cell":qT(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":DO(this.editor,this.activeTableBlock,r==="show-border");break;case"show-chart":UO(this.editor,this.activeTableBlock,r==="show-chart"),Wp(this.editor,this.activeTableBlock,{updateNow:!0});break}});g(this,"handleToolbarClose",()=>{this.targetButton&&ot(this.targetButton,"active"),this.activeTableBlock&&Su(this.editor,this.editor.selection.range)===this.activeTableBlock&&(Yo(this.editor,this.activeTableBlock,!1),Zo(this.editor,this.activeTableBlock,!1)),this.editor.focus()});g(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(p(Nn,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Yo(this.editor,this.activeTableBlock,!0,!1),Zo(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Yo(this.editor,this.activeTableBlock,!0,!0),Zo(this.editor,this.activeTableBlock,!0,!0)):(Yo(this.editor,this.activeTableBlock,!1),Zo(this.editor,this.activeTableBlock,!1)))});g(this,"handleClick",(t,e)=>{var r;p(Nn,this.activeTableBlock,"no target table block"),p(Nn,this.targetButton,"no target button"),ak(this.editor),Rt(this.targetButton,"active")?(ot(this.targetButton,"active"),(r=this.manualMenu)==null||r.close("clickItem")):(z(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new rl(this.createCommandMenu(),void 0,{id:"table-cell-menu"}),this.manualMenu.on("click",(i,o)=>{var s;this.handleCommand(o),(s=this.manualMenu)==null||s.close("clickItem")}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",this.handleToolbarClose)),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"})),e.stopPropagation()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close("cancelBar"),this.targetButton&&(ot(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let r=this.editor.getBlockById(e);for(;r;){const i=r.closest("td");p(Nn,i,"no parent cell");const o=nt(i);if(p(Nn,o,"no parent block"),Me(o)===t.table)return t.getCellByCellElement(i);r=o}return p(Nn,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${zp}`)||t.appendChild(this.targetButton):(this.targetButton=B("button",[zp],t),this.targetButton.innerHTML=_h,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent),this.editor.domEvents.addEventListener(this.targetButton,"dblclick",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),p(Nn,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=Lt.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:r,row:i}=this.getCellByChildBlockId(t,e.start.blockId);$p(this.editor,this.activeTableBlock,{col:r,row:i})}else Hp(this.editor.selection.range)}}getSelectedBkgColorIndex(){var s;p(Nn,this.activeTableBlock,"no target table block");const t=this.editor.selection.range,e=Qo(this.editor,this.activeTableBlock,t.focus),r=this.editor.getBlockData(this.activeTableBlock),i=e.childContainerId,o=r[`${i}_background`];return o?Number.parseInt((s=o.substring(xK.length))!=null?s:"0",10):-1}createCommandMenu(){p(Nn,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=WT(this.editor,this.activeTableBlock,this.editor.selection.range);let r=this.editor.selection.range;if(r.isSimple()){const h=Qo(this.editor,this.activeTableBlock,r.start);r=We(this.editor,{anchor:h,focus:h})}const i=GT(this.editor,this.activeTableBlock,r),o=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,d=t.chart;return this.colorPaletteItem=new FT("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(h,C)=>{var E;switch(p(Nn,this.activeTableBlock,"no target table block"),h){case"clearColor":ty(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":ty(this.editor,this.activeTableBlock,C);break}(E=this.manualMenu)==null||E.close("clickItem")}),[{id:"cell-background-color",name:D.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:D.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:D.t("table.splitCell"),states:i?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:D.t("table.deleteSelectRow")},{id:"delete-select-col",name:D.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:D.t("table.tableConfigKey"),children:[{id:"row-title",name:D.t("table.tableConfig.rowTitle"),states:o?["checked"]:[]},{id:"col-title",name:D.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:D.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?D.t("table.tableConfig.showBorder"):D.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:d?D.t("table.tableConfig.hideChart"):D.t("table.tableConfig.showChart"),value:d?"hide-chart":"show-chart"}]}]}handleRowTitle(t){p(Nn,this.activeTableBlock,"no target table block"),t?SO(this.editor,this.activeTableBlock):wO(this.editor,this.activeTableBlock)}handleColTitle(t){p(Nn,this.activeTableBlock,"no target table block"),t?RO(this.editor,this.activeTableBlock):kO(this.editor,this.activeTableBlock)}handleStripeStyle(t){p(Nn,this.activeTableBlock,"no target table block"),t?IO(this.editor,this.activeTableBlock):LO(this.editor,this.activeTableBlock)}}function pk(n){n.addCustom("table-cell-menu",t=>new bK(t))}const v0=I("table-container");function IC(n){const t=n.closest("td");return p(v0,t,"no parent cell for a table cell container"),t}function Ck(n){const t=Me(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function DC(n,t,e,r){const i=Lt.fromBlock(n),o=i.getCellByContainerId(ft(t));if(e==="ArrowDown"){const s=i.getBottomCell(o);return s?s.container:null}if(e==="ArrowUp"){const s=i.getTopCell(o);return s?s.container:null}if(e==="ArrowLeft"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(v0,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return r!=null&&r.noWrap&&i.getCellByContainerId(ft(c)).row!==o.row?null:c}if(e==="ArrowRight"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(v0,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return r!=null&&r.noWrap&&i.getCellByContainerId(ft(c)).row!==o.row?null:c}p(v0,!1,`invalid navigation type: ${e}`)}const vK=12,BK=90,B0=23,Ek=2;class TK{constructor(t){g(this,"scrollTableBlock",null);g(this,"autoScrollDir",null);g(this,"autoScrollTimer",null);g(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const r=nt(e);if(r&&ee(this.editor.rootContainer,r)){const i=co(r);i&&(this.scrollTableBlock=i,document.addEventListener("mousemove",this.handleAutoScroll))}}});g(this,"handleAutoScroll",f6.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=window.innerHeight-this.getBarFloatWindowBottom(e),l=i.getBoundingClientRect(),c=Math.min(l.bottom,s),d=Math.max(l.top,0);o.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):o.top<d&&t.clientY<=d?this.setAutoScroll("top"):r.scrollLeft>0&&t.clientX<o.left?this.setAutoScroll("left"):r.scrollLeft<r.scrollWidth-r.offsetWidth&&t.clientX>o.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));g(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});g(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId),i=co(r);if(i){const o=t.getCustom(Ai(i)),s=o.rootElement.getBoundingClientRect(),l=_r(t,r,e.start);if(s.left>l.left){const c=e.start.offset===0?vK:Ek;o.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?BK:Ek;o.rootElement.scrollLeft+=l.right-s.right+c}}}else{const r=t.getBlockById(e.start.blockId),i=co(r),o=t.getBlockById(e.end.blockId),s=co(o);if(i&&i===s){const l=t.getCustom(Ai(i)),c=l.rootElement.getBoundingClientRect();let d=null;if(e.isSimple())d=e.isReverse()?_r(t,r,e.start):_r(t,o,e.end);else{const h=IC(ci(t,e.start.childContainerId)),C=IC(ci(t,e.end.childContainerId));d=e.isReverse()?h.getBoundingClientRect():C.getBoundingClientRect()}c.left>d.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-d.left:c.right<d.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=d.right-c.right)}}});g(this,"handleScroll",t=>{HT(t),this.editor.selection.caret.update()});g(this,"handleReset",t=>{HT(t),this.editor.selection.caret.update();const e=this.editor.findCustom("table-border-bar");e&&e.handleScroll(),uk(t)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}getBarFloatWindowBottom(t){return t.scrollOptions.barFloatWindowBottom?typeof t.scrollOptions.barFloatWindowBottom=="number"?t.scrollOptions.barFloatWindowBottom:t.scrollOptions.barFloatWindowBottom():0}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=i===document.documentElement?window.innerHeight:i.offsetHeight,l=window.innerHeight-this.getBarFloatWindowBottom(e),c=i.getBoundingClientRect(),d=Math.min(c.bottom,l),h=Math.max(c.top,0);this.autoScrollDir==="left"&&(r.scrollLeft-=B0,r.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(r.scrollLeft+=B0,r.scrollLeft>=r.scrollWidth-r.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(i.scrollTop+=B0,(i.scrollTop>=i.scrollHeight-s||o.bottom<=d)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(i.scrollTop-=B0,(i.scrollTop<=0||o.top>=h)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function Ak(n){return n.addCustom("table-scroll-events",t=>new TK(t))}const yK=I("table-doc-change-handler");class kK{constructor(t){this.editor=t,this.editor.addListener("docChanged",this.handleDocChanged)}handleDocChanged(t,e){if(!e){const{start:r,end:i}=t.selection.range;if(!t.findBlockById(r.blockId)||!t.findBlockById(i.blockId)){t.selection.selectBlock(t.getBlockByIndex("root",0),0);return}if(sa(r)){const o=t.getBlockById(r.blockId);if(!He(o))return;if(p(yK,sa(i),"invalid range"),!Pd(t,r.childContainerId)||!Pd(t,i.childContainerId)){t.selection.selectBlock(o,0);return}let s=null,l=null;const c=(d,h)=>{const C=h.getCellById(d.childContainerId),{colIndex:E=0,rowIndex:x=0}=d.custom;let v=-1,R=-1;return(C.col>E||C.col+C.colSpan-1<E)&&(v=C.col),(C.row>x||C.row+C.rowSpan-1<x)&&(R=C.row),v!==-1||R!==-1?Ee(o,d.childContainerId,{colIndex:v===-1?E:v,rowIndex:R===-1?x:R}):null};if(r.custom){const d=Lt.fromBlock(o);s=c(r,d),l=c(i,d)}(s!==null||l!==null)&&(t.selection.range.isReverse()?t.selection.setSelection(l!=null?l:i,s!=null?s:r):t.selection.setSelection(s!=null?s:r,l!=null?l:i))}}}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged)}}function xk(n){n.addCustom("table-doc-change-handler",t=>new kK(t))}const bi=I("create-content");function bk(n,t,e){var C;const r=new qh(e),i=e.rows,o=e.cols;p(bi,i>=1,`invalid rows: ${i}`),p(bi,o>=1,`invalid cols: ${o}`),p(bi,e.children,"no table children");const s=B("table",[],null),l=(C=e.colsWidth)!=null?C:new Array(e.cols).fill(0),c=B("colgroup",[],s);for(let E=0;E<r.colCount;E++){const x=B("col",[],c);l[E]&&(x.style.width=`${l[E]}px`)}const d=B("tbody",[],s);let h=0;for(let E=0;E<i;E++){const x=B("tr",[],d);for(let v=0;v<o;v++){const R=r.getCell({col:v,row:E});if(R.virtual)p(bi,R.colSpan>1||R.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const L=e.children[h],M=B("td",[],x);R.colSpan>1&&(M.colSpan=R.colSpan),R.rowSpan>1&&(M.rowSpan=R.rowSpan);const U=e[Du(L)];U&&z(M,U),v===0&&e.hasColTitle&&z(M,XT.COL_TITLE_ITEM),n.createChildContainer(t,M,L),h+=1}}}return p(bi,h===e.children.length,"container count mismatch"),s.style.width=`${l.reduce((E,x)=>x+E,0)}px`,e.noBorder&&z(s,"no-border"),e.chart&&z(s,"editor-table-chart"),e.isStripeStyle&&z(s,"stripe"),e.hasRowTitle&&z(s,"row-title"),e.hasColTitle&&z(s,"col-title"),s}function RK(n,t,e,r,i){p(bi,i.type==="table","not table data"),p(bi,ft(e)===t[t.length-1].containerId,"invalid path");const o=i,s=Ks(r,"div");try{const l=B("div",[],null);l.setAttribute("data-type","table-content");const c=bk(n,t,o);c.classList.add("drag-preview-element"),l.appendChild(c);const d=n.getComponentOptions("table");my(n),Cy(n),gk(n,"create"),xk(n),d!=null&&d.hideCellMenu||pk(n),EU(n,qp);const h=n.addCustom(Ai(r),()=>sN());h.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Qt(e)?n.scrollContainer:e,locatingContainer:Qt(e)?(d==null?void 0:d.locatingContainer)||n.parent:e,paddingLeft:_a+Iu,paddingTop:_a+Iu,paddingBottom:Iu/2,paddingRight:Iu/2,barFloatWindowBottom:d==null?void 0:d.barFloatWindowBottom,allowScrollBarFixed:d==null?void 0:d.allowScrollBarFixed,isSetScale:d==null?void 0:d.isSetScale});const C=Ak(n);h.on("scroll",C.handleReset),h.on("resize",C.handleReset),setTimeout(()=>{PO(n,r)})}catch{const c=`invalid table data: ${JSON.stringify(o)}`;bi.error(c);const d=B("div",["error"],s);d.innerText=c}return s}function wK(n,t,e){p(bi,e.type==="table","not table data");const r=e,i=Ot(t);try{const o=Me(t),s=Ko(t),l=bk(n,s,r);l.classList.add("drag-preview-element"),o.insertAdjacentElement("afterend",l),o.remove();const c=n.getComponentOptions("table");my(n),Cy(n),gk(n,"update"),xk(n),c!=null&&c.hideCellMenu||pk(n),qp(n,t)}catch{const s=`invalid table data: ${JSON.stringify(r)}`;bi.error(s);const l=B("div",["error"],i);l.innerText=s}}function SK(n,t){let e,r,i=!1;if([...t].every(E=>E==="|")?(r=t.length,e=Array(r).fill(""),i=!0):(e=Eg(t,"|").split("|"),r=e.length),r<2)return null;const o=3,s=r,l=[];for(let E=0;E<3;E++)e.forEach(x=>{l.push(no(n.doc,E===0?x:""))});const c=Array(s).fill(Yp),d=l[i?0:s],h=n.doc.getContainerBlocks(d)[0].id;return{blockData:{id:J(),type:"table",rows:o,cols:s,children:l,colsWidth:c},focusBlockId:h}}function LK(n,t){const e=t.rows,r=t.cols;if(e<1||r<1)return null;const i=[];for(let d=0;d<e;d++)for(let h=0;h<r;h++)i.push(no(n.doc));const o=Array(r).fill(Yp),s=i[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:J(),type:"table",rows:e,cols:r,children:i,colsWidth:o},focusBlockId:l}}const _C=I("get-selected-containers");function vk(n,t,e,r){p(_C,e.blockId===r.blockId,"only allow select in single table block"),p(_C,st(t)===e.blockId,"only allow select in single table block");const i=Lt.fromBlock(t),o=i.getCellByContainerId(e.childContainerId),s=i.getCellByContainerId(r.childContainerId);if(e.custom===void 0||r.custom===void 0)return i.getCells(o,s).map(L=>i.getCellContainer(L));const{fromCol:l,toCol:c,fromRow:d,toRow:h}=Gr(t,e,r),C=new Set,E=[];return i.sub({row:d,col:l},{row:h,col:c}).forEach(v=>{v.forEach(R=>{const L=i.getCellByContainerId(R.containerId);L.col<l||L.row<d||L.col+L.colSpan-1>c||L.row+L.rowSpan-1>h||C.has(R.containerId)||(C.add(R.containerId),E.push(L.container))})}),E}function IK(n,t,e){p(_C,t.blockId===e.blockId,"only allow select in single table block");const r=n.getBlockById(t.blockId);return vk(n,r,t,e)}const Bk=I("table-selection-to-doc");function DK(n,t){const{start:e,end:r,block:i}=t,o=It(i);p(Bk,o==="table",`invalid block type: ${o}`);const s=n.getBlockData(i);if(e.isSimple()&&r.isSimple())return zo(n.editorBlocks,n.doc.toJSON(),s);p(Bk,!e.isSimple()&&!r.isSimple(),"invalid block pos type");const l=Lt.fromBlock(i),{fromCol:c,toCol:d,fromRow:h,toRow:C}=Gr(i,e,r),E={},x=[],v=n.doc.toJSON();let R={};l.sub({row:h,col:c},{row:C,col:d}).forEach((rt,at)=>{rt.forEach((At,Mt)=>{const kt=At.containerId;if(x.indexOf(kt)!==-1)return;x.push(kt);let se;if(At.virtual){const Se=l.getCellByContainerId(At.containerId),Pn=c+Mt;let Li=Se.col+Se.colSpan-1;Li>d&&(Li=d);const yn=Li-Pn+1;yn>1&&(E[`${kt}_colSpan`]=yn);const gn=h+at;let Ii=Se.row+Se.rowSpan-1;Ii>C&&(Ii=C);const mo=Ii-gn+1;mo>1&&(E[`${kt}_rowSpan`]=mo),se=eo()}else{if(se=I1(n.editorBlocks,v,kt),At.col+At.colSpan>d+1){const Se=d-At.col+1;Se>1&&(E[`${kt}_colSpan`]=Se)}else At.colSpan>1&&(E[`${kt}_colSpan`]=At.colSpan);if(At.row+At.rowSpan>C+1){const Se=C-At.row+1;Se>1&&(E[`${kt}_rowSpan`]=Se)}else At.rowSpan>1&&(E[`${kt}_rowSpan`]=At.rowSpan)}const{root:ue,...nr}=se.blocks;R={...R,...nr,[kt]:ue}})});const M=Nu(Me(i)).slice(c,d+1);return{blocks:{root:[{id:J(),type:o,children:x,colsWidth:M,rows:C-h+1,cols:d-c+1,...E}],...R},meta:{},comments:{}}}function _K(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function MK(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function UK(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function OK(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function NK(n,t,e){const r=t.col,i=t.row,o=e.col,s=e.row,l={left:r,top:i,right:o,bottom:s};let c=!1;do{if(c=!1,!_K(n,l)){l.top--,c=!0;continue}if(!MK(n,l)){l.left--,c=!0;continue}if(!UK(n,l)){l.bottom++,c=!0;continue}if(!OK(n,l)){l.right++,c=!0;continue}}while(c);return l}function PK(n,t,e,r){if(e.custom!==void 0||r.custom!==void 0)return{anchor:e,focus:r};const i=Lt.fromBlock(t),o=i.map(F=>F.containerId),s=i.getCellByContainerId(e.childContainerId),l=i.getCellByContainerId(r.childContainerId),c=Math.min(s.row,l.row),d=Math.max(s.row,l.row),h=Math.min(s.col,l.col),C=Math.max(s.col,l.col),E=NK(o,{row:c,col:h},{row:d,col:C}),x=i.getCell({row:E.top,col:E.left}),v=i.getCell({row:E.bottom,col:E.right}),R=i.getCell({row:E.top,col:E.right}),L=i.getCell({row:E.bottom,col:E.left});let M,U;return s.row<=l.row?s.col<=l.col?(M=x,U=v):(M=R,U=L):s.col<l.col?(M=L,U=R):(M=v,U=x),console.log(`move ${M.col}, ${M.row}, -> ${U.col}, ${U.row}`),{anchor:Ee(t,M.containerId),focus:Ee(t,U.containerId)}}function Tk(n,t,e){if(e.isSimple())return[Me(t).getBoundingClientRect()];const r=Me(t),i=r.getBoundingClientRect(),{fromCol:o,fromRow:s,toCol:l,toRow:c}=Gr(t,e.start,e.end),d=Nu(r),h=d.slice(0,o).reduce((R,L)=>R+L,0),C=h+d.slice(o,l+1).reduce((R,L)=>R+L,0),E=ck(r);let x=E.slice(0,s).reduce((R,L)=>R+L,0);const v=x+E.slice(s,c+1).reduce((R,L)=>R+L,0);if(s===0){const R=gK(n,t);x-=R}return[new DOMRect(i.left+h,i.top+x,C-h,v-x)]}I("table-size");const FK=40;function T0(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),r=Number.parseInt(e.borderLeft,10),i=Number.parseInt(e.borderRight,10);return(r+i)/2}function KK(n,t,e){const r=Fg(n,e.container);return r!==void 0?r+T0(t):FK*e.colSpan-T0(t)}function VK(n,t,e,r){let i=0;const o=e.colCount;for(let s=0;s<o;s++){const l=e.getCell({col:s,row:r});if(l.virtual)continue;let c=KK(n,t,l);const d=Rv(l.container,{withPadding:!0});d&&d>c&&(c=d),i+=c+T0(t)}return i}function $K(n,t){const e=Me(t),r=Lt.fromTable(e);let i=0;for(let s=0;s<r.rowCount;s++)i=Math.max(i,VK(n,e,r,s));const o=T0(e);return i+=o,i}const uo=I("table-creator");async function HK(n,t){return n.undoManager.runInGroup(()=>{var c,d;const e=t.item,r=(c=e.colCount)!=null?c:5,i=(d=e.rowCount)!=null?d:3,o=LK(n,{cols:r,rows:i});if(!o)return null;const{blockData:s,focusBlockId:l}=o;return n.insertBlock(t.containerId,t.blockIndex,s,ve(n,l,0))})}class jK{constructor(){g(this,"id","insert-table");g(this,"name","Create table");g(this,"element");g(this,"closeable",null);g(this,"colCount");g(this,"rowCount");g(this,"setCloseable",t=>{this.closeable=t});g(this,"destroy",()=>{this.closeable=null});g(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);g(this,"handleTableCreatorClick",t=>{var E,x;t.preventDefault(),t.stopPropagation();const e=t.target;p(uo,e instanceof HTMLElement,"invalid event target");const r=e.closest(".table-creator");p(uo,r,"no table creator");const i=r.querySelectorAll(".active");if(i.length===0)return;const s=i[i.length-1].id;p(uo,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const d=s.substring(l.length).split("-");p(uo,d.length===2,"invalid cell id");const h=Number.parseInt(d[0],10)+1,C=Number.parseInt(d[1],10)+1;uo.debug(`${h}, ${C}`),this.colCount=C,this.rowCount=h,(E=this.closeable)==null||E.click(this,this.element),(x=this.closeable)==null||x.close("clickItem"),this.handleTableCreatorLeave()});g(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const r=this.getTableCreatorCellId(t,e),i=document.getElementById(r);i&&ot(i,"active")}});g(this,"handleTableCreatorCellEnter",t=>{const e=t.target;p(uo,e instanceof HTMLElement,"invalid event target");const r=e.id,i="table-creator-cell-";p(uo,r.startsWith(i),"invalid cell id");const s=r.substring(i.length).split("-");p(uo,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let d=0;d<9;d++)for(let h=0;h<9;h++){const C=this.getTableCreatorCellId(d,h),E=document.getElementById(C);p(uo,E,"no cell"),d<=l&&h<=c?z(E,"active"):ot(E,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=B("div",["table-creator"],null),e=(r,i,o)=>{const s=B("div",["table-creator-cell"],r);return s.id=this.getTableCreatorCellId(i,o),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let r=0;r<9;r++){const i=B("div",["table-creator-row"],t);for(let o=0;o<9;o++)e(i,r,o).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function zK(){return new jK}function GK(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function yk(n){const t=GK(n);return n.length+t}function WK(n,t,e=[]){let r=0;if(!e||e.length===0)return r;for(let i=n;i<n+t;i+=1)r+=e[i]||0;return r}function qK(n,t){const e=yk(n),r=t-e;return r>0?n+" ".repeat(r):n}function XK(n,t,e,r,i){var l;const o=t,s=new qh(o);if(r==="markdown"||r==="text"){const c=M=>e.blocks[M].map((G,q)=>r==="markdown"?x1(n,G,e,[...i,{containerId:M,blockIndex:q}]):oh(n,G,e,[...i,{containerId:M,blockIndex:q}])),d=M=>c(M).join(" ").replace(/\n/g," ").trim(),h=new Map,C=new Map;for(let M=0;M<s.colCount;M++){let U=0;for(let F=0;F<s.rowCount;F++){const G=s.getCell({row:F,col:M});let q="";G.virtual||(q=d(G.containerId)),h.set(`${F},${M}`,q),U=Math.max(U,yk(q))}C.set(M,U)}const E=M=>{const U=h.get(`${M.row},${M.col}`)||"",F=C.get(M.col)||0;return qK(U,F)};if(r==="text"){const M=[];for(let U=0;U<s.colCount;U++){const F=E({row:0,col:U});M.push(F)}for(let U=1;U<s.rowCount;U++)for(let F=0;F<s.colCount;F++){const G=E({row:U,col:F});M.push(G)}return M.join(`
|
|
639
639
|
`)}const x=[];let v="|",R="|";for(let M=0;M<s.colCount;M++){const U=E({row:0,col:M});v+=` ${U} |`;const F="-".repeat((C.get(M)||0)+2);R+=`${F}|`}x.push(v),x.push(R);for(let M=1;M<s.rowCount;M++){let U="|";for(let F=0;F<s.colCount;F++){const G=E({row:M,col:F});U+=` ${G} |`}x.push(U)}return`${x.join(`
|
|
640
640
|
`)}
|
|
641
641
|
`}if(r==="html"){const c=C=>e.blocks[C].map((v,R)=>A1(n,v,e,[...i,{containerId:C,blockIndex:R}])).join(`
|
|
@@ -657,7 +657,7 @@ ${l}`:r==="markdown"?`\`\`\`${i.language}
|
|
|
657
657
|
${s}
|
|
658
658
|
\`\`\`
|
|
659
659
|
${l}`:`<p><pre><code>${Bd(s)}</code></pre></p>
|
|
660
|
-
<p>${Bd(l)}</p>`}const HC={blockType:"code",blockKind:"complex",createBlockContent:WV,getBlockTextLength:qV,getRangeFromPoint:XV,moveCaret:QV,getCaretRect:YV,updateSelection:ZV,clearSelection:JV,getChildContainers:t$,getNextContainer:e$,getSelectedContainers:n$,convertFrom:CV,handleBlockElementUpdated:r$,getOptions:o$,getBlockProperties:s$,convertTo:l$},jC={...Mn,blockType:"code-line"};class a${constructor(t){g(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!Hu(this.editor,e))return;const r=e,i=t.range.focus.offset,o=Kv(this.editor,r,i,"code-caret");o.scrollIntoView({block:"nearest"}),setTimeout(()=>{o.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function c$(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!Hu(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{fi(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function u$(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!Hu(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{fi(n).forEach(i=>{const o=ce(n.getBlockText(i.block));for(let s=0;s<e.length;s++){const l=e[s];if(o.startsWith(l)){n.deleteTextFromBlock(i.block,0,l.length);break}}})}),!0}function f$(n){const t=n.getFocusedBlock(),e=it(t);if(Qt(e))return;const r=nt(e);if(!r||It(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!fB(e,i))return H1(n,e),!0}const d$={Tab:c$,"Shift+Tab":u$,"CtrlOrCmd+A":f$},ju=I("code-text-decorate");class k0{decorateText(t,e,r){if(p(ju,e.length>0,"invalid path"),e.length===1)return{};const i=e[e.length-2];if(t.doc.getBlockData(i.containerId,i.blockIndex).type!=="code")return{};const s=r;if(s.length===0)return{};const l=ce(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(R=>{if(!R)return Jl.default.languages.plain;const L=R.replace(/\s/g,"").toLocaleLowerCase();return Jl.default.languages[L]||Jl.default.languages.plain})(c.language),C=Jl.default.tokenize(l,h),E=(R,L)=>{if(p(ju,R,"no token"),typeof R=="string")return[{insert:R,attributes:gt.default(L)}];p(ju,R instanceof Jl.default.Token,"invalid token type");const M=R.content,U=gt.default(L);return U[`style-code-${R.type}`]=!0,typeof M=="string"?[{insert:M,attributes:U}]:Array.isArray(M)?M.map(q=>E(q,U)).flat():(p(ju,M instanceof Jl.default.Token,"invalid token"),E(M,U))},v=C.map(R=>E(R,{})).flat();return p(ju,fn(v)===fn(s),"failed to highlight code, text length mismatch"),{text:v}}}const h$={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},m$={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},g$={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":h$,"en-US":m$,"ja-JP":g$});function p$(n,t,e,r){const i=n.getBlockByIndex(t,e);if(dt(n,i)!==r)return!1;const o=ce(n.getBlockText(i));if(![...o].every(h=>h==="|")||o.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,i,{offset:r});if(!l)return!1;const{blockData:c,focusBlockId:d}=l;return c?(n.undoManager.runInGroup(()=>{var C;const h=n.insertBlock(t,e,c,ve(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const C$={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},E$={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function R0(n,t,e,r,i){const o=n.getContainerById(t);if(!Qt(o)){const s=nt(o);if(s&&vi(s))return!0}return!1}function $k(n,t,e,r,i){if(R0(n,t))return!1;if(i==="enter"&&p$(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=ce(In(n.getBlockText(o),r).left),l=i==="enter"?C$:E$;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var v;const h=Od(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const x=n.insertBlock(t,e,C,ve(n,E!=null?E:C.id,0));return n.deleteBlock(o),(v=h.onConverted)==null||v.call(h,n,x),{newBlock:x,focusBlockId:E}})}return!1}function A$(n,t,e,r){const i=n.getBlockByIndex(t,e);return n.getBlockString(i,{boxReplacement:" "}).substring(0,r)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{quoted:!0},ve(n,i,0))}),!0)}const x$={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function b$(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=x$[o];if(!s)return!1;const l=n.getBlockData(i).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{heading:s},ve(n,i,0))}),!0}function v$(n,t,e,r){return!!(b$(n,t,e,r)||A$(n,t,e,r))}const B$=I("match-text-style");function T$(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),r=e.lastIndexOf(t);return r===-1?-1:r===0?0:e.substring(r-1).startsWith(t)?-1:r}const y$={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function k$(n,t,e,r){var E,x;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=In(o,r),l=c1(s),c=fn(s)-l.length,d=Object.entries(y$);for(const[v,R]of d){const L=T$(l,v);if(L===-1)continue;const M=c+L,U=r,F=v.length,G=ce(qe(o,M+F,U-M-F*2).middle);if(R.type==="style"){const q={};R.styles.forEach(at=>{q[at]=!0});const rt=Xs(G,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,rt)})}else if(R.type==="box")try{const q=(x=(E=n.editorBoxes.getBoxClass(R.boxType)).convertFrom)==null?void 0:x.call(E,n,G);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertBoxToBlock(i,M,q)})}catch(q){B$.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const v=C.index,R=C[1],L=C[2],M=v,U=r,G={...da(o,M),link:L};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,Xs(R,G))}),!0}return!1}class w0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(R0(t,e))return!1;if(v$(t,e,r,i)||k$(t,e,r,i))return!0}return!1}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(et(t,t.getBlockByIndex(i,o))){if(li(e,"Enter")){if($k(t,i,o,s,"enter"))return!0}else if(li(e,"Space")&&$k(t,i,o,s,"space"))return!0}return!1}}const R$={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};D.mergeLang(R$);function zu(n,t){const e=jo(n,t);return!!(et(n,t)&&e.text&&fn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function Hk(n,t){var r;Ot(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function Gu(n,t,e){var i;if(Hk(n,t),!zu(n,t))return;const r=Ot(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=ne(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function w$(n){const t=n.getAttribute("data-style-heading");return t?D.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?D.t("placeholder.quote"):null}function S$(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?D.t("placeholder.list"):D.t("placeholder.mention"):null}function jk(n){switch(It(n)){case"text":return w$(n);case"list":return S$(n);default:return null}}function L$(n){if(dr(n))return!1;const t=nt(it(n));return t?It(t)==="code":!1}function I$(n){return!dr(n)}function D$(n,t){var h,C;const e=n.selection.focusedBlock,r=It(e),i=t.contentPlaceholder||D.t("placeholder.default");let o=i;if(r&&Wc(n,r)&&e){if(!n.isBlockWritable(e)||L$(e))return;I$(e)&&(o=D.t("placeholder.common.contentInTable")),o=(h=jk(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:Gt(s);if(!l)return;const c=Gt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&zu(n,l)){Gu(n,l,(C=jk(l))!=null?C:i);return}const d=n.getFocusedBlock();!zu(n,d)||d===s&&!t.hideTitle||Gu(n,d,o)}function _$(n,t){var i,o;const e=n.getFirstBlock(),r=Ot(e);zu(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:D.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function M$(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function U$(n,t){M$(n),n.selection.range.isCollapsed()&&(t.hideTitle||_$(n,t),D$(n,t))}const qst="";function O$(n){for(let t=0;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const zk=I("enforce-title");class zC{constructor(t,e={headingLevel:1}){g(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});g(this,"reload",t=>{this.handleChanged(t),this.applyPlaceholder(t)});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange),setTimeout(()=>{t.addListener("load",this.reload)})}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange),t.removeListener("load",this.reload)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(!this.isDocumentTitleBlock(i,o)||!li(e,"Enter"))return!1;let l=!1,c=null;Lr(t.rootContainer)===2&&(c=zi(t.rootContainer,1),dt(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ft(t.rootContainer));p(zk,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=mi("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ft(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(zk,o.text,"invalid text block");const s=t.getBlockById(o.id);if(O$(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=mi(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ft(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=ve(t,c.id,dt(t,C))),ch(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ft(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,r;!((e=this.options)!=null&&e.titlePlaceholder)&&!((r=this.options)!=null&&r.contentPlaceholder)||U$(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}function qr(n){return It(n)==="embed"&&un(n)==="image"}async function Gk(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 N$(n){const t=await ia(n);return Gk(t)}function rs(n){return typeof n=="number"}const P$=I("image-data"),Wu=1e3,Wk=400,F$=10;function Xa(n){return n.src.startsWith("empty:")||!n.src}function K$(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function qk(n){return`${md.default(n)}_width`}function Xk(n){return`${md.default(n)}_height`}function Qk(n){return`${n}_flex`}function Yk(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function Qa(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?Wu:i.width,s=i.height==="auto"?o/t:i.height/t;return o/s}).reduce((i,o)=>i+o,0);n.forEach(i=>{const o=i.width==="auto"?Wu:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function Ya(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=qk(i),l=Xk(i),c=Qk(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),{src:i,width:d!=null?d:"auto",height:h!=null?h:"auto",flex:C,virtualSize:!d||!h}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),Qa(e),e}function Xr(n){const t=n.embedData;return Ya(n.embedData).length>1?100:t.widthPercent}function V$(n,t,e,r){const i=Ya(t.embedData);if(i.length>1||r)return"100%";const o=Xr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=Yk(e);return`${Math.min(s*o/100,l)}px`}return rs(i[0].width)?`${i[0].width}px`:"auto"}function hn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{const s=i.src||`empty:${o}`,l=qk(s);l&&rs(i.width)&&(r[l]=i.width);const c=Xk(s);c&&rs(i.height)&&(r[c]=i.height),p(P$,i.flex,"no image flex");const d=Qk(o);r[d]=i.flex}),r}function $$(n,t,e,r){const i=Ya(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${Wk}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=Xr(t);if(!s){if(i.length!==1||rs(i[0].width))return"";const C=i[0].height;return C==="auto"?"auto":`${C}px`}let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,Yk(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?Wu:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*F$;const c=i.reduce((h,C)=>h+C.flex,0);let d=0;for(const h of i){const C=l*h.flex/c,E=h.width==="auto"?Wu:h.width,x=C/E*h.height;d=Math.max(x,d)}return`${d}px`}function H$(n){return n.reduce((e,r)=>e+r.flex,0)}function j$(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function GC(n){return ne(n).querySelector(".block-resizer")}function z$(n){const t=GC(n);t&&ot(t,"active")}function Zk(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function G$(n,t,e,r){const i=GC(n);if(i)return z(i,"active"),Zk(n,t,i),i;const o=ne(n),s=B("div",["block-resizer"],o);return Zk(n,t,s),e.resize.forEach(l=>{j$(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function WC(n,t){const e=GC(n);if(!e||!ee(n,t))return;const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const Xst="",W$=I("block-resizer");class qu extends ye.TypedEmitter{constructor(e,r){super();g(this,"resizableElement");g(this,"block",null);g(this,"startRect",null);g(this,"startPos",null);g(this,"resizeType",null);g(this,"enabled",!1);g(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const r=this.getResizableElement();if(!r||e.button!==0)return;const i=e.target;if(!i||!(i instanceof HTMLElement))return;const o=i.getAttribute("data-resize-type");!o||(this.bindEvents(),this.startRect=r.getBoundingClientRect(),this.startPos=e,this.resizeType=o,Vc(window.getComputedStyle(i).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});g(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const i=e.x-this.startPos.x,o=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=o),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=o),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=i),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=i);const C=d>c?d-c:0,E=h>l?h-l:0,x=new DOMRect(c,l,C,E);this.emit("resizing",this,x);const v=this.getResizableElement();v&&WC(this.block,v)});g(this,"handleMouseUp",e=>{if(e.button!==0)return;Vc(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||WC(this.block,r)});this.editor=e,this.options=r}enableResize(e,r){this.block=e,this.resizableElement=r,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(z$(this.block),this.enabled=!1)}update(e,r){this.block=e,this.resizableElement=r,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&WC(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Ot(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(W$,ee(this.block,e),"not a block child element"),G$(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const q$=I("image-dom");function Jk(n){return n.querySelector(".uploading-progress-mask")}function X$(n){const t=Jk(n);if(t)return t;const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e);return B("div",["uploading-progress-bar-value"],r),r}function Q$(n){const e=X$(n).querySelector(".uploading-progress-bar-value");return p(q$,e,"no progress value"),e}function tR(n,t){const e=Q$(n);e.style.width=`${t}%`}function Y$(n){var t;(t=Jk(n))==null||t.remove()}function Xu(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||it(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=V$(n,t,o,s),c=$$(n,t,o,s),d=Ot(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function Z$(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function J$(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=Z$(t.headers).toLocaleLowerCase();let i="";if(r){const s=cg.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function is(n,t){const e=typeof t=="string"?t:st(t);return n.getCustom(`image-${e}`)}function S0(n,t){if(!t||!(t instanceof Node))return null;const e=nt(t);return e?is(n,e):null}function Ti(n){return Array.from(n.querySelectorAll(".image-container"))}const qC=I("table-resize-drag-drop");class tH{constructor(t,e,r,i){g(this,"cursor","col-resize");g(this,"initWidths");this.editor=t,this.elem=e,this.data=r,this.mouseDownEvent=i;const o=this.data.block,l=is(this.editor,o).getImages(),c=this.data.splitterIndex;p(qC,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Ti(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;is(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=is(this.editor,s),c=gt.default(l.getImages()),d=this.data.splitterIndex;p(qC,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const R=[...this.initWidths];R[d]+=E,R[d+1]-=E;const L=Ti(s);p(qC,L.length===c.length,"invalid image data");const M=R.reduce((G,q)=>G+q,0);for(let G=0;G<c.length;G++){const q=R[G]/M;c[G].flex=q,L[G].style.flexGrow=`${q}`}const U=gt.default(this.editor.getBlockData(s)),F=hn(c,Xr(U));U.embedData=F,Xu(this.editor,U,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=is(this.editor,s),d=Ti(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function eR(n){var t;return!n||!(n instanceof HTMLElement)?null:Rt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function eH(n,t){var s;const e=eR(t.target);if(!e)return;const r=nt(e);if(!r)return;is(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};Cg(new tH(n,e,o,t))}function nH(n,t){t.preventDefault(),t.stopPropagation();const e=eR(t.target);if(!e)return;const r=nt(e);!r||is(n,r).resetFlex()}function rH(n,t,e,r){const i=B("div",["image-splitter"],e);B("div",["image-splitter-indicator"],i),i.setAttribute("data-index",`${r}`),n.domEvents.addEventListener(i,"mousedown",eH),n.domEvents.addEventListener(i,"dblclick",nH)}const iH=I("image-item");function nR(n){return!n||!(n instanceof Node)?null:nt(n)}function rR(n){const t=nR(n);return t?Ti(t):[]}function XC(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function Qu(n){const t=XC(n);return t?rR(n).indexOf(t):-1}async function oH(n,t){const e=S0(n,t.target);if(!e)return;const r=Qu(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(Xa(o)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),(o.height==="auto"||o.width==="auto")&&e.fixImageSize(r,i),o.virtualSize&&e.fixImageSize(r,i),!o||!K$(o)||o.downloading))return;o.downloading=!0;const s=await J$(o.src);s?e.replaceImage(r,s):iH.warn(`failed to download image: ${o.src}`)}function sH(n,t,e){if(t.querySelector(".load-error"))return;const i=e.src.startsWith("http:")||e.src.startsWith("https:"),o=B("div",["load-error"],t),s=B("div",["error-icon"],o);s.innerHTML=bp;const l=B("div",["error-message"],o);i?(l.innerHTML=D.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=D.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&uH(c,d.target)}))}function QC(n,t){setTimeout(()=>{if(ee(n.rootContainer,t)){const e=n.getBlockData(t);Xu(n,e,null,null)}})}function lH(n,t){const e=S0(n,t.target);if(!e)return;const r=Qu(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=XC(t.target);if(!o)return;z(o,"error","error-load");const s=nt(o);s&&QC(n,s),o.innerHTML="",sH(n,o,i)}function aH(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=bp;const s=B("div",["error-message"],i);s.innerHTML=D.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=S0(l,c.target),h=Qu(c.target);!d||h===-1||d.replaceImage(h,e)})}function iR(n,t,e,r,i){const o=Ti(t)[e];!o||(z(o,"error","error-upload"),QC(n,t),o.innerHTML="",aH(n,o,i))}function oR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),Xa(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=$2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",oH),n.domEvents.addEventListener(c,"error",lH),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=xp,d.setAttribute(`data-editor-tooltip-${n.clientId}`,D.t("image.load.remote.tooltip"))}return l}function cH(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&rH(n,t,o,l-1),oR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function sR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=oR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),QC(n,t)}function Yu(n,t){return Ti(n)[t]}function uH(n,t){const e=nR(t);if(!e)return;const r=Qu(t);if(r===-1)return;const i=S0(n,t);if(!i)return;const o=i.getImages()[r];sR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function lR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function aR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=zc(t.name);if(r&&!r.includes(rn.exports.lowerCase(o))){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function cR(n){return n.startsWith("image/")}const uR=I("image-object");class Oe{constructor(t,e){g(this,"images",[]);g(this,"selectedIndex",-1);g(this,"blockResizer");g(this,"resizing",!1);g(this,"parentContainerResizerObserver",null);g(this,"autoFix",!1);g(this,"handleMouseDown",async(t,e)=>{const r=Qu(e.target);if(r===-1)return;const i=this.images[r];Xa(i)||this.setSelectedIndex(r)});g(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});g(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||it(e)===t&&Xu(this.editor,this.blockData,e,null)});g(this,"handleResizing",(t,e)=>{const r=this.editor.findBlockById(this.blockData.id);if(!r)return;this.autoFix||this.setAutoFix(!0);const i=r.querySelector(".images");i.style.height="";const s=this.editor.rootContainer.getBoundingClientRect().width,l=r.getBoundingClientRect();let c=e.width>l.width?l.width:e.width;c<50&&(c=50);const d=c*100/s;this.blockData.embedData.widthPercent=d,Xu(this.editor,this.blockData,r,null)});g(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});g(this,"fixImageSizes",Ke.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new qu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=Ya(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,r){const i=cH(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Mr(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Ss(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),Xu(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Xr(this.blockData)}isEmpty(){return this.images.length===1&&Xa(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const i=Yu(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=Yu(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=Yu(e,t);if(Rt(r,"error"))return;const i=lR(this.editor),o=await oa(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Yu(t,0);!this.isEmpty()&&this.images.length===1&&!Rt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const r=this.images[t];Xa(r)||(rs(r.width)&&!rs(r.height)?r.height=r.width/e.naturalWidth*e.naturalHeight:rs(r.height)&&!rs(r.width)?r.width=r.height/e.naturalHeight*e.naturalWidth:(r.width=e.naturalWidth,r.height=e.naturalHeight),r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=gt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,Qa(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=hn(r,Xr(this.blockData));return this.editor.updateEmbedData(e,i),!0}async replaceImage(t,e){const r=this.editor.findBlockById(this.blockData.id);if(!r)return!1;try{const o=await ia(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await Gk(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,Qa(this.images);const h=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};sR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return iR(this.editor,r,t,o,e),!1}const i=Yu(r,t);if(!i)return!1;z(i,"uploading"),tR(i,0),z(r,"media-block-uploading");try{const o=await this.editor.doc.uploadResource(e,{onProgress:c=>{tR(i,c)}});ot(i,"uploading"),this.images[t].src=o.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=hn(this.images,Xr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){uR.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),Y$(i),iR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(uR,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(e,r)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=gt.default(this.images);e[0].flex=NaN,Qa(e);const r=hn(e,Xr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=Ya(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new Oe(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=st(e),t.getCustom(`image-${r}`)}}const Qst="",Yst="";function L0(n){const t=ne(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function YC(n,t,e){const r=L0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const fR=40,fH=20;class dH{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=nt(r);if(c&&ee(t.rootContainer,c))return c}let i=e.clientX,o=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;i<s&&s-i<fR&&(i+=fR);let l=document.elementFromPoint(i,o);if(l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}if(o-=fH,l=document.elementFromPoint(i,o),l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}return null}destroy(){}}class hH extends E0{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});g(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const r=this.editor.selection.focusedBlock;this.suggest.popup(r,0,"","")}setBlock(e){this.currentBlock=e}}function mH(n,t,e){const r=Ug(n,t);if(!r)return[];const i=[];return Object.values(r).forEach(o=>{e!=null&&e.has(o.group)||i.push(...o.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:o.group})))}),i}function ZC(n,t,e={withPlainText:!1}){const r=wC(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function gH(n,t,e,r=!1){var h,C,E;const i=it(t);let o=t;if(o&&Kt(o)&&aC(o)){if(!r){const x=GN(o);o=(h=Gt(x))!=null?h:x}u0.closeMindmap(n,t)}let l=bt(o);re(n,o)||r||(l+=1);const c=ft(i),d=e;return d.commandProvider?d.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:c,blockIndex:l}):(E=(C=d.blockOptions)==null?void 0:C.handleInsertEmptyBlock)==null?void 0:E.call(C,n,{containerId:c,blockIndex:l,item:e})}function pH(n,t){const e=Ir(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class dR{constructor(t,e,r){g(this,"source","text-style");g(this,"id","text-style-item");g(this,"name","Text styles");g(this,"element");g(this,"textStylesTooltips",{});g(this,"createHeadingItemElement",(t,e,r)=>{var o;const i=vC();this.createItem("text",Ra,e,pH(this.editor,t)),(o=i.insertBlockCommandItems)==null||o.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,r?r===Number(s.value):!1)})});g(this,"createListItemElement",(t,e,r)=>{const{checkbox:i,ordered:o}=r,l=It(t)==="list",c=l&&o===!1&&!i,d=l&&o,h=l&&!!i;this.createItem("unordered-list",wp,e,c),this.createItem("ordered-list",Sp,e,d),this.createItem("check-list",kp,e,h)});g(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const r=e.target instanceof Element?e.target:e.target.parentElement;if(!r)return;const i=r.closest(".text-style-item");if(!i)return;const o=i.id,s="heading-";if(o==="text"&&g0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&g0(t,this.block,d)}if(o==="blockquote"&&AC(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");zy(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&bC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});g(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:D.t("commands.text")},blockquote:{title:D.t("commands.quote")},"align-left":{title:D.t("commands.alignLeft")},"align-center":{title:D.t("commands.alignCenter")},"align-right":{title:D.t("commands.alignRight")},"unordered-list":{title:D.t("commands.unordered")},"ordered-list":{title:D.t("commands.ordered")},"check-list":{title:D.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:D.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",Rp,i,!!c)}const s=o.align||"left";return this.createItem("align-left",ka,i,s==="left"),this.createItem("align-center",Hh,i,s==="center"),this.createItem("align-right",$h,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=Ls(e,o,r);s.id=t;const l=this.textStylesTooltips[t];if(!l)return;const{title:c,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,c),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,fr(d))}}function hR(){return{source:"separator",type:"separator",id:`section-${J()}`,name:""}}const mR={copy:iT,cut:oT,delete:sT,"lock-block":lT,"unlock-block":aT,comment:el},CH=["image","video"];function EH(n,t,e){const r=[],i=et(n,t),o=Re(t)&&CH.includes(un(t)),s=o&&(un(t)!=="image"||un(t)==="image"&&Ti(t).length===1);if(i?r.push(new dR(n,t,e)):o&&s&&r.push(new dR(n,t,{...e,fromEmbed:!0})),!re(n,t)||lC(t)){(i||o&&s)&&r.push(hR());const l=mH(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in mR&&(c.icon=mR[c.id])}),r.push(...l)}return re(n,t)&&!lC(t)?r.push(...ZC(n,"insert-block")):r.push(hR(),{id:"insert-block-before",icon:cT,name:D.t("blockMenu.command.insertAbove"),children:ZC(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:uT,name:D.t("blockMenu.command.insertAfter"),children:ZC(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function AH(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;Av(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&gH(n,t,e,e.source==="insert-block-before")}const xH=I("exclusive-block");function JC(n,t,e,r){var l;z(t,"block-exclusive");const i=Zt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",D.t("exclusive.tips",{editor:r,embedType:s||D.t("exclusive.fallbackAbstract")}))}function gR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function bH(n,t,e,r,i){xH.debug(`block ${st(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?JC(n,t,r,i):gR(t)}function Zu(n){return n.classList.contains("block-exclusive")}function pR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&bH(n,r,t.exclusive,t.userId,t.displayName)})}class os{constructor(t){g(this,"exclusiveBlockIds",new Set);g(this,"exclusiveBlockTimer",0);g(this,"remoteExclusiveBlockIds",new Map);g(this,"handleUserChanged",t=>{const e=new Set(t.map(i=>i.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([i,o])=>{if(!e.has(o.userId)){this.remoteExclusiveBlockIds.delete(i);const s={...o,exclusive:!1};pR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;pR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>st(o)),exclusive:e};this.editor.doc.broadcastMessage(i)}exclusiveBlock(t){this.exclusiveBlockIds.has(st(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(st(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(st(t))||(this.exclusiveBlockIds.delete(st(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new os(t))}static register(t){return this.get(t)}}function tE(n,t){os.get(n).exclusiveBlock(t)}function eE(n,t){os.get(n).unexclusiveBlock(t)}class CR{writable(t,e){if(Array.isArray(e)){for(const r of e)if(Zu(r))return!1;return}if(Zu(e))return!1}create(t,e,r,i,o){const s=os.get(t).getExclusiveMessage(o.id);s&&JC(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=os.get(t).getExclusiveMessage(o.id);s?JC(t,i,s.userId,s.displayName):gR(i)}}const Zst="",vH={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},BH={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},TH={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};D.mergeLang({"zh-CN":vH,"en-US":BH,"ja-JP":TH});function Ju(n,t){return n.getBlockData(t).lock}function I0(n,t){return!!Ju(n,t)}function tf(n,t){const e=Ju(n,t);return e?e.userId===n.doc.getUser().userId:!1}function nE(n,t){const e=Ju(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function yH(n,t){if(n.readonly||!n.isBlockWritable(t)||I0(n,t)&&!tf(n,t))return;const e=n.doc.getUser(),r={userId:e.userId,displayName:e.displayName,locked:Date.now()},o={...n.getBlockData(t),lock:r};n.updateBlockData(t,o)}function kH(n,t){if(!tf(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const RH=10,wH=80,SH=50;class rE{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;if(!i||!i.blockId)return;const o=t.getBlockById(i.blockId);i.type==="lock"?yH(t,o):i.type==="unlock"&&kH(t,o)})}create(t,e,r,i,o){const s=o.lock;s&&(s.userId!==t.doc.getUser().userId?z(i,"locked-by-others"):z(i,"locked-by-self"))}update(t,e,r,i,o){const s=o.lock;if(s)if(s.userId!==t.doc.getUser().userId){z(i,"locked-by-others");const l=t.selection.focusedBlock;(l===i||ee(i,l))&&(et(t,i)||It(i)==="code")&&t.insertTextBlock("",ft(r),bt(i)+1)}else z(i,"locked-by-self");else ot(i,"locked-by-others"),ot(i,"locked-by-self")}writable(t,e){let r=[];Array.isArray(e)?r=e:r.push(e);for(const i of r){if(nE(t,i))return!1;if(dr(i))return;let o=Fs(i);for(;o;){if(nE(t,o))return!1;o=Fs(o)}}}commands(t,e){const r=I0(t,e),i=tf(t,e),o=Zu(e),s={blockId:st(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(r)if(i)l.id="unlock-block",l.name=D.t("locker.unlock"),s.type="unlock";else{const c=Ju(t,e);let d=(c==null?void 0:c.displayName)||"";const h=D.getCurrentLang()==="ja-JP",C=Fb(d,RH,h?SH:wH);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=D.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=D.t("locker.lock"),l.states=["disabled"]):l.name=D.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Jst="",LH={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},IH={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},DH={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":LH,"en-US":IH,"ja-JP":DH});class D0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const _H=I("standard-block-actions");class MH{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;try{const o=t.getBlockById(i);if(r.id==="delete"){t.deleteBlock(o);return}r.id==="copy"&&xh(t,o),r.id==="cut"&&(xh(t,o),t.deleteBlock(o))}catch(o){_H.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=I0(t,e),i=r&&tf(t,e),o=st(e),s=VC(),l=Zu(e),c={id:"copy",name:D.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:fr("CtrlOrCmd+C"),operation:D.t("copyCutProperty.copy")})},d={id:"cut",name:D.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:fr("CtrlOrCmd+X"),operation:D.t("copyCutProperty.cut")})},h={id:"delete",name:D.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const ER=I("block-menu");class UH{constructor(t){g(this,"menu");g(this,"currentBlock",null);g(this,"commandBlock",null);g(this,"handleShow",()=>{p(ER,this.currentBlock,"no target block before show block menu");const t=EH(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});g(this,"handleClose",()=>{Mp(this.editor)&&this.editor.focus()});g(this,"handleItemClick",(t,e)=>{p(ER,this.commandBlock,"no command block before show block menu"),AH(this.editor,this.commandBlock,e),e.element||this.close()});g(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new rl([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new MH)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const OH=1e3;async function NH(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=OH?"":(await Xx.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const PH=I("drag-preview-image");class FH{constructor(t){g(this,"startPosition",null);g(this,"dragContainer",null);g(this,"handleDragStart",async(t,e)=>{const r=t.target;p(PH,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=mT;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),x=this.editor.rootContainer.getBoundingClientRect(),v=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(x.width/2,v.width)}px`,this.dragContainer=s;const L=await NH(this.editor,e);L?l.src=L:z(s,"drag-placeholder"),mg(s,{status:"loaded"})});g(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:r}=t;if(e===0&&r===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:i,y:o}=this.startPosition,s=e-i,l=r-o;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});g(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const AR="drag-preview-element";function KH(n){if(Rt(n,AR))return n;const t=n.querySelector(`.${AR}`);return t||(Re(n)?Ot(n):n)}const _0=I("block-menu-drag-handler");function iE(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class VH{constructor(t,e){g(this,"dragPreview");g(this,"autoScroll");g(this,"oldPos",{x:0,y:0});g(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(p(_0,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:r,y:i}=t;this.oldPos={x:r,y:i},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});g(this,"handleDragStart",t=>{var s,l;const e=cn(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Ld({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(_0,r,"no dragged block"),(l=(s=Zt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=iE(t,"dragstart");GH(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=KH(r);this.dragPreview.handleDragStart(t,o),this.autoScroll.active(),z(r,"dragging"),z(this.editor.contentElement,"dragging")});g(this,"handleDrag",t=>{const{target:e,x:r,y:i}=t;if(this.oldPos.x===r&&this.oldPos.y===i)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:r,y:i},p(_0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=iE(t,"dragover");this.editor.contentElement.dispatchEvent(o)});g(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(_0,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(i=this.autoScroll)==null||i.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const r=iE(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new FH(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class ef{constructor(t){g(this,"highlightedBlockId","");g(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=st(t),z(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new ef(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class xR{constructor(t){g(this,"buttonElement");g(this,"emptyBlockMenu");g(this,"blockMenu");g(this,"dragHandler");g(this,"handleHoverBlock",(t,e,r)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const i=this.editor.getCustom("editor-tooltip");if(i&&i.visible()&&(i.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(r.target)||this.buttonElement.remove());return}const o=Ud(t);Gi(o)||(this.updateButton(o),YC(o,this.buttonElement,Number.MAX_SAFE_INTEGER))});g(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const r=this.blockMenu.currentBlock;if(!r)return;this.editor.selection.selectBlock(r,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{ef.get(this.editor).highlightBlock(r)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});g(this,"updatePlaceholder",t=>{Gu(this.editor,t,D.t("blockMenu.button.searchPlaceholder"))});g(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;if(this.blockMenu.currentBlock){const r=st(this.blockMenu.currentBlock);if(!this.editor.findBlockById(r)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const e=re(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new hH(t),this.blockMenu=new UH(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new VH(this.editor,this);const e=be.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new dH),ef.register(this.editor)}destroy(){be.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=B("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,D.t("blockMenu.button.tips")),t.innerHTML=Lp,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=hT,this.buttonElement.setAttribute(e,D.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=Lp,this.buttonElement.setAttribute(e,D.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),re(this.editor,t)&&!(Kt(t)&&lC(t))?this.setButtonType("insert"):this.setButtonType("move")}}const $H={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
660
|
+
<p>${Bd(l)}</p>`}const HC={blockType:"code",blockKind:"complex",createBlockContent:WV,getBlockTextLength:qV,getRangeFromPoint:XV,moveCaret:QV,getCaretRect:YV,updateSelection:ZV,clearSelection:JV,getChildContainers:t$,getNextContainer:e$,getSelectedContainers:n$,convertFrom:CV,handleBlockElementUpdated:r$,getOptions:o$,getBlockProperties:s$,convertTo:l$},jC={...Mn,blockType:"code-line"};class a${constructor(t){g(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!Hu(this.editor,e))return;const r=e,i=t.range.focus.offset,o=Kv(this.editor,r,i,"code-caret");o.scrollIntoView({block:"nearest"}),setTimeout(()=>{o.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function c$(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!Hu(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{fi(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function u$(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!Hu(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{fi(n).forEach(i=>{const o=ce(n.getBlockText(i.block));for(let s=0;s<e.length;s++){const l=e[s];if(o.startsWith(l)){n.deleteTextFromBlock(i.block,0,l.length);break}}})}),!0}function f$(n){const t=n.getFocusedBlock(),e=it(t);if(Qt(e))return;const r=nt(e);if(!r||It(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!f5(e,i))return H1(n,e),!0}const d$={Tab:c$,"Shift+Tab":u$,"CtrlOrCmd+A":f$},ju=I("code-text-decorate");class k0{decorateText(t,e,r){if(p(ju,e.length>0,"invalid path"),e.length===1)return{};const i=e[e.length-2];if(t.doc.getBlockData(i.containerId,i.blockIndex).type!=="code")return{};const s=r;if(s.length===0)return{};const l=ce(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(R=>{if(!R)return Jl.default.languages.plain;const L=R.replace(/\s/g,"").toLocaleLowerCase();return Jl.default.languages[L]||Jl.default.languages.plain})(c.language),C=Jl.default.tokenize(l,h),E=(R,L)=>{if(p(ju,R,"no token"),typeof R=="string")return[{insert:R,attributes:gt.default(L)}];p(ju,R instanceof Jl.default.Token,"invalid token type");const M=R.content,U=gt.default(L);return U[`style-code-${R.type}`]=!0,typeof M=="string"?[{insert:M,attributes:U}]:Array.isArray(M)?M.map(q=>E(q,U)).flat():(p(ju,M instanceof Jl.default.Token,"invalid token"),E(M,U))},v=C.map(R=>E(R,{})).flat();return p(ju,fn(v)===fn(s),"failed to highlight code, text length mismatch"),{text:v}}}const h$={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},m$={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},g$={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":h$,"en-US":m$,"ja-JP":g$});function p$(n,t,e,r){const i=n.getBlockByIndex(t,e);if(dt(n,i)!==r)return!1;const o=ce(n.getBlockText(i));if(![...o].every(h=>h==="|")||o.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,i,{offset:r});if(!l)return!1;const{blockData:c,focusBlockId:d}=l;return c?(n.undoManager.runInGroup(()=>{var C;const h=n.insertBlock(t,e,c,ve(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const C$={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},E$={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function R0(n,t,e,r,i){const o=n.getContainerById(t);if(!Qt(o)){const s=nt(o);if(s&&vi(s))return!0}return!1}function $k(n,t,e,r,i){if(R0(n,t))return!1;if(i==="enter"&&p$(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=ce(In(n.getBlockText(o),r).left),l=i==="enter"?C$:E$;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var v;const h=Od(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const x=n.insertBlock(t,e,C,ve(n,E!=null?E:C.id,0));return n.deleteBlock(o),(v=h.onConverted)==null||v.call(h,n,x),{newBlock:x,focusBlockId:E}})}return!1}function A$(n,t,e,r){const i=n.getBlockByIndex(t,e);return n.getBlockString(i,{boxReplacement:" "}).substring(0,r)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{quoted:!0},ve(n,i,0))}),!0)}const x$={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function b$(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=x$[o];if(!s)return!1;const l=n.getBlockData(i).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{heading:s},ve(n,i,0))}),!0}function v$(n,t,e,r){return!!(b$(n,t,e,r)||A$(n,t,e,r))}const B$=I("match-text-style");function T$(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),r=e.lastIndexOf(t);return r===-1?-1:r===0?0:e.substring(r-1).startsWith(t)?-1:r}const y$={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function k$(n,t,e,r){var E,x;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=In(o,r),l=c1(s),c=fn(s)-l.length,d=Object.entries(y$);for(const[v,R]of d){const L=T$(l,v);if(L===-1)continue;const M=c+L,U=r,F=v.length,G=ce(qe(o,M+F,U-M-F*2).middle);if(R.type==="style"){const q={};R.styles.forEach(at=>{q[at]=!0});const rt=Xs(G,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,rt)})}else if(R.type==="box")try{const q=(x=(E=n.editorBoxes.getBoxClass(R.boxType)).convertFrom)==null?void 0:x.call(E,n,G);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertBoxToBlock(i,M,q)})}catch(q){B$.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const v=C.index,R=C[1],L=C[2],M=v,U=r,G={...da(o,M),link:L};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,Xs(R,G))}),!0}return!1}class w0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(R0(t,e))return!1;if(v$(t,e,r,i)||k$(t,e,r,i))return!0}return!1}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(et(t,t.getBlockByIndex(i,o))){if(li(e,"Enter")){if($k(t,i,o,s,"enter"))return!0}else if(li(e,"Space")&&$k(t,i,o,s,"space"))return!0}return!1}}const R$={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};D.mergeLang(R$);function zu(n,t){const e=jo(n,t);return!!(et(n,t)&&e.text&&fn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function Hk(n,t){var r;Ot(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function Gu(n,t,e){var i;if(Hk(n,t),!zu(n,t))return;const r=Ot(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=ne(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function w$(n){const t=n.getAttribute("data-style-heading");return t?D.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?D.t("placeholder.quote"):null}function S$(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?D.t("placeholder.list"):D.t("placeholder.mention"):null}function jk(n){switch(It(n)){case"text":return w$(n);case"list":return S$(n);default:return null}}function L$(n){if(dr(n))return!1;const t=nt(it(n));return t?It(t)==="code":!1}function I$(n){return!dr(n)}function D$(n,t){var h,C;const e=n.selection.focusedBlock,r=It(e),i=t.contentPlaceholder||D.t("placeholder.default");let o=i;if(r&&Wc(n,r)&&e){if(!n.isBlockWritable(e)||L$(e))return;I$(e)&&(o=D.t("placeholder.common.contentInTable")),o=(h=jk(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:Gt(s);if(!l)return;const c=Gt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&zu(n,l)){Gu(n,l,(C=jk(l))!=null?C:i);return}const d=n.getFocusedBlock();!zu(n,d)||d===s&&!t.hideTitle||Gu(n,d,o)}function _$(n,t){var i,o;const e=n.getFirstBlock(),r=Ot(e);zu(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:D.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function M$(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function U$(n,t){M$(n),n.selection.range.isCollapsed()&&(t.hideTitle||_$(n,t),D$(n,t))}const qst="";function O$(n){for(let t=0;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const zk=I("enforce-title");class zC{constructor(t,e={headingLevel:1}){g(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});g(this,"reload",t=>{this.handleChanged(t),this.applyPlaceholder(t)});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange),setTimeout(()=>{t.addListener("load",this.reload)})}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange),t.removeListener("load",this.reload)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(!this.isDocumentTitleBlock(i,o)||!li(e,"Enter"))return!1;let l=!1,c=null;Lr(t.rootContainer)===2&&(c=zi(t.rootContainer,1),dt(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ft(t.rootContainer));p(zk,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=mi("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ft(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(zk,o.text,"invalid text block");const s=t.getBlockById(o.id);if(O$(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=mi(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ft(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=ve(t,c.id,dt(t,C))),ch(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ft(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,r;!((e=this.options)!=null&&e.titlePlaceholder)&&!((r=this.options)!=null&&r.contentPlaceholder)||U$(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}function qr(n){return It(n)==="embed"&&un(n)==="image"}async function Gk(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 N$(n){const t=await ia(n);return Gk(t)}function rs(n){return typeof n=="number"}const P$=I("image-data"),Wu=1e3,Wk=400,F$=10;function Xa(n){return n.src.startsWith("empty:")||!n.src}function K$(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function qk(n){return`${md.default(n)}_width`}function Xk(n){return`${md.default(n)}_height`}function Qk(n){return`${n}_flex`}function Yk(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function Qa(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?Wu:i.width,s=i.height==="auto"?o/t:i.height/t;return o/s}).reduce((i,o)=>i+o,0);n.forEach(i=>{const o=i.width==="auto"?Wu:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function Ya(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=qk(i),l=Xk(i),c=Qk(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),{src:i,width:d!=null?d:"auto",height:h!=null?h:"auto",flex:C,virtualSize:!d||!h}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),Qa(e),e}function Xr(n){const t=n.embedData;return Ya(n.embedData).length>1?100:t.widthPercent}function V$(n,t,e,r){const i=Ya(t.embedData);if(i.length>1||r)return"100%";const o=Xr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=Yk(e);return`${Math.min(s*o/100,l)}px`}return rs(i[0].width)?`${i[0].width}px`:"auto"}function hn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{const s=i.src||`empty:${o}`,l=qk(s);l&&rs(i.width)&&(r[l]=i.width);const c=Xk(s);c&&rs(i.height)&&(r[c]=i.height),p(P$,i.flex,"no image flex");const d=Qk(o);r[d]=i.flex}),r}function $$(n,t,e,r){const i=Ya(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${Wk}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=Xr(t);if(!s){if(i.length!==1||rs(i[0].width))return"";const C=i[0].height;return C==="auto"?"auto":`${C}px`}let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,Yk(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?Wu:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*F$;const c=i.reduce((h,C)=>h+C.flex,0);let d=0;for(const h of i){const C=l*h.flex/c,E=h.width==="auto"?Wu:h.width,x=C/E*h.height;d=Math.max(x,d)}return`${d}px`}function H$(n){return n.reduce((e,r)=>e+r.flex,0)}function j$(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function GC(n){return ne(n).querySelector(".block-resizer")}function z$(n){const t=GC(n);t&&ot(t,"active")}function Zk(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function G$(n,t,e,r){const i=GC(n);if(i)return z(i,"active"),Zk(n,t,i),i;const o=ne(n),s=B("div",["block-resizer"],o);return Zk(n,t,s),e.resize.forEach(l=>{j$(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function WC(n,t){const e=GC(n);if(!e||!ee(n,t))return;const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const Xst="",W$=I("block-resizer");class qu extends ye.TypedEmitter{constructor(e,r){super();g(this,"resizableElement");g(this,"block",null);g(this,"startRect",null);g(this,"startPos",null);g(this,"resizeType",null);g(this,"enabled",!1);g(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const r=this.getResizableElement();if(!r||e.button!==0)return;const i=e.target;if(!i||!(i instanceof HTMLElement))return;const o=i.getAttribute("data-resize-type");!o||(this.bindEvents(),this.startRect=r.getBoundingClientRect(),this.startPos=e,this.resizeType=o,Vc(window.getComputedStyle(i).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});g(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const i=e.x-this.startPos.x,o=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=o),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=o),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=i),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=i);const C=d>c?d-c:0,E=h>l?h-l:0,x=new DOMRect(c,l,C,E);this.emit("resizing",this,x);const v=this.getResizableElement();v&&WC(this.block,v)});g(this,"handleMouseUp",e=>{if(e.button!==0)return;Vc(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||WC(this.block,r)});this.editor=e,this.options=r}enableResize(e,r){this.block=e,this.resizableElement=r,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(z$(this.block),this.enabled=!1)}update(e,r){this.block=e,this.resizableElement=r,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&WC(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Ot(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(W$,ee(this.block,e),"not a block child element"),G$(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const q$=I("image-dom");function Jk(n){return n.querySelector(".uploading-progress-mask")}function X$(n){const t=Jk(n);if(t)return t;const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e);return B("div",["uploading-progress-bar-value"],r),r}function Q$(n){const e=X$(n).querySelector(".uploading-progress-bar-value");return p(q$,e,"no progress value"),e}function tR(n,t){const e=Q$(n);e.style.width=`${t}%`}function Y$(n){var t;(t=Jk(n))==null||t.remove()}function Xu(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||it(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=V$(n,t,o,s),c=$$(n,t,o,s),d=Ot(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function Z$(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function J$(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=Z$(t.headers).toLocaleLowerCase();let i="";if(r){const s=cg.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function is(n,t){const e=typeof t=="string"?t:st(t);return n.getCustom(`image-${e}`)}function S0(n,t){if(!t||!(t instanceof Node))return null;const e=nt(t);return e?is(n,e):null}function Ti(n){return Array.from(n.querySelectorAll(".image-container"))}const qC=I("table-resize-drag-drop");class tH{constructor(t,e,r,i){g(this,"cursor","col-resize");g(this,"initWidths");this.editor=t,this.elem=e,this.data=r,this.mouseDownEvent=i;const o=this.data.block,l=is(this.editor,o).getImages(),c=this.data.splitterIndex;p(qC,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Ti(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;is(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=is(this.editor,s),c=gt.default(l.getImages()),d=this.data.splitterIndex;p(qC,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const R=[...this.initWidths];R[d]+=E,R[d+1]-=E;const L=Ti(s);p(qC,L.length===c.length,"invalid image data");const M=R.reduce((G,q)=>G+q,0);for(let G=0;G<c.length;G++){const q=R[G]/M;c[G].flex=q,L[G].style.flexGrow=`${q}`}const U=gt.default(this.editor.getBlockData(s)),F=hn(c,Xr(U));U.embedData=F,Xu(this.editor,U,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=is(this.editor,s),d=Ti(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function eR(n){var t;return!n||!(n instanceof HTMLElement)?null:Rt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function eH(n,t){var s;const e=eR(t.target);if(!e)return;const r=nt(e);if(!r)return;is(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};Cg(new tH(n,e,o,t))}function nH(n,t){t.preventDefault(),t.stopPropagation();const e=eR(t.target);if(!e)return;const r=nt(e);!r||is(n,r).resetFlex()}function rH(n,t,e,r){const i=B("div",["image-splitter"],e);B("div",["image-splitter-indicator"],i),i.setAttribute("data-index",`${r}`),n.domEvents.addEventListener(i,"mousedown",eH),n.domEvents.addEventListener(i,"dblclick",nH)}const iH=I("image-item");function nR(n){return!n||!(n instanceof Node)?null:nt(n)}function rR(n){const t=nR(n);return t?Ti(t):[]}function XC(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function Qu(n){const t=XC(n);return t?rR(n).indexOf(t):-1}async function oH(n,t){const e=S0(n,t.target);if(!e)return;const r=Qu(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(Xa(o)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),(o.height==="auto"||o.width==="auto")&&e.fixImageSize(r,i),o.virtualSize&&e.fixImageSize(r,i),!o||!K$(o)||o.downloading))return;o.downloading=!0;const s=await J$(o.src);s?e.replaceImage(r,s):iH.warn(`failed to download image: ${o.src}`)}function sH(n,t,e){if(t.querySelector(".load-error"))return;const i=e.src.startsWith("http:")||e.src.startsWith("https:"),o=B("div",["load-error"],t),s=B("div",["error-icon"],o);s.innerHTML=bp;const l=B("div",["error-message"],o);i?(l.innerHTML=D.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=D.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&uH(c,d.target)}))}function QC(n,t){setTimeout(()=>{if(ee(n.rootContainer,t)){const e=n.getBlockData(t);Xu(n,e,null,null)}})}function lH(n,t){const e=S0(n,t.target);if(!e)return;const r=Qu(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=XC(t.target);if(!o)return;z(o,"error","error-load");const s=nt(o);s&&QC(n,s),o.innerHTML="",sH(n,o,i)}function aH(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=bp;const s=B("div",["error-message"],i);s.innerHTML=D.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=S0(l,c.target),h=Qu(c.target);!d||h===-1||d.replaceImage(h,e)})}function iR(n,t,e,r,i){const o=Ti(t)[e];!o||(z(o,"error","error-upload"),QC(n,t),o.innerHTML="",aH(n,o,i))}function oR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),Xa(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=$2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",oH),n.domEvents.addEventListener(c,"error",lH),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=xp,d.setAttribute(`data-editor-tooltip-${n.clientId}`,D.t("image.load.remote.tooltip"))}return l}function cH(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&rH(n,t,o,l-1),oR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function sR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=oR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),QC(n,t)}function Yu(n,t){return Ti(n)[t]}function uH(n,t){const e=nR(t);if(!e)return;const r=Qu(t);if(r===-1)return;const i=S0(n,t);if(!i)return;const o=i.getImages()[r];sR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function lR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function aR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=zc(t.name);if(r&&!r.includes(rn.exports.lowerCase(o))){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function cR(n){return n.startsWith("image/")}const uR=I("image-object");class Oe{constructor(t,e){g(this,"images",[]);g(this,"selectedIndex",-1);g(this,"blockResizer");g(this,"resizing",!1);g(this,"parentContainerResizerObserver",null);g(this,"autoFix",!1);g(this,"handleMouseDown",async(t,e)=>{const r=Qu(e.target);if(r===-1)return;const i=this.images[r];Xa(i)||this.setSelectedIndex(r)});g(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});g(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||it(e)===t&&Xu(this.editor,this.blockData,e,null)});g(this,"handleResizing",(t,e)=>{const r=this.editor.findBlockById(this.blockData.id);if(!r)return;this.autoFix||this.setAutoFix(!0);const i=r.querySelector(".images");i.style.height="";const s=this.editor.rootContainer.getBoundingClientRect().width,l=r.getBoundingClientRect();let c=e.width>l.width?l.width:e.width;c<50&&(c=50);const d=c*100/s;this.blockData.embedData.widthPercent=d,Xu(this.editor,this.blockData,r,null)});g(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});g(this,"fixImageSizes",Ke.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new qu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=Ya(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,r){const i=cH(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Mr(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Ss(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),Xu(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Xr(this.blockData)}isEmpty(){return this.images.length===1&&Xa(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const i=Yu(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=Yu(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=Yu(e,t);if(Rt(r,"error"))return;const i=lR(this.editor),o=await oa(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Yu(t,0);!this.isEmpty()&&this.images.length===1&&!Rt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const r=this.images[t];Xa(r)||(rs(r.width)&&!rs(r.height)?r.height=r.width/e.naturalWidth*e.naturalHeight:rs(r.height)&&!rs(r.width)?r.width=r.height/e.naturalHeight*e.naturalWidth:(r.width=e.naturalWidth,r.height=e.naturalHeight),r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=gt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,Qa(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=hn(r,Xr(this.blockData));return this.editor.updateEmbedData(e,i),!0}async replaceImage(t,e){const r=this.editor.findBlockById(this.blockData.id);if(!r)return!1;try{const o=await ia(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await Gk(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,Qa(this.images);const h=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};sR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return iR(this.editor,r,t,o,e),!1}const i=Yu(r,t);if(!i)return!1;z(i,"uploading"),tR(i,0),z(r,"media-block-uploading");try{const o=await this.editor.doc.uploadResource(e,{onProgress:c=>{tR(i,c)}});ot(i,"uploading"),this.images[t].src=o.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=hn(this.images,Xr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){uR.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),Y$(i),iR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(uR,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=hn(this.images,Xr(this.blockData));this.editor.updateEmbedData(e,r)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=gt.default(this.images);e[0].flex=NaN,Qa(e);const r=hn(e,Xr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=Ya(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new Oe(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=st(e),t.getCustom(`image-${r}`)}}const Qst="",Yst="";function L0(n){const t=ne(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function YC(n,t,e){const r=L0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const fR=40,fH=20;class dH{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=nt(r);if(c&&ee(t.rootContainer,c))return c}let i=e.clientX,o=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;i<s&&s-i<fR&&(i+=fR);let l=document.elementFromPoint(i,o);if(l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}if(o-=fH,l=document.elementFromPoint(i,o),l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}return null}destroy(){}}class hH extends E0{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});g(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const r=this.editor.selection.focusedBlock;this.suggest.popup(r,0,"","")}setBlock(e){this.currentBlock=e}}function mH(n,t,e){const r=Ug(n,t);if(!r)return[];const i=[];return Object.values(r).forEach(o=>{e!=null&&e.has(o.group)||i.push(...o.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:o.group})))}),i}function ZC(n,t,e={withPlainText:!1}){const r=wC(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function gH(n,t,e,r=!1){var h,C,E;const i=it(t);let o=t;if(o&&Kt(o)&&aC(o)){if(!r){const x=GN(o);o=(h=Gt(x))!=null?h:x}u0.closeMindmap(n,t)}let l=bt(o);re(n,o)||r||(l+=1);const c=ft(i),d=e;return d.commandProvider?d.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:c,blockIndex:l}):(E=(C=d.blockOptions)==null?void 0:C.handleInsertEmptyBlock)==null?void 0:E.call(C,n,{containerId:c,blockIndex:l,item:e})}function pH(n,t){const e=Ir(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class dR{constructor(t,e,r){g(this,"source","text-style");g(this,"id","text-style-item");g(this,"name","Text styles");g(this,"element");g(this,"textStylesTooltips",{});g(this,"createHeadingItemElement",(t,e,r)=>{var o;const i=vC();this.createItem("text",Ra,e,pH(this.editor,t)),(o=i.insertBlockCommandItems)==null||o.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,r?r===Number(s.value):!1)})});g(this,"createListItemElement",(t,e,r)=>{const{checkbox:i,ordered:o}=r,l=It(t)==="list",c=l&&o===!1&&!i,d=l&&o,h=l&&!!i;this.createItem("unordered-list",wp,e,c),this.createItem("ordered-list",Sp,e,d),this.createItem("check-list",kp,e,h)});g(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const r=e.target instanceof Element?e.target:e.target.parentElement;if(!r)return;const i=r.closest(".text-style-item");if(!i)return;const o=i.id,s="heading-";if(o==="text"&&g0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&g0(t,this.block,d)}if(o==="blockquote"&&AC(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");zy(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&bC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});g(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:D.t("commands.text")},blockquote:{title:D.t("commands.quote")},"align-left":{title:D.t("commands.alignLeft")},"align-center":{title:D.t("commands.alignCenter")},"align-right":{title:D.t("commands.alignRight")},"unordered-list":{title:D.t("commands.unordered")},"ordered-list":{title:D.t("commands.ordered")},"check-list":{title:D.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:D.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",Rp,i,!!c)}const s=o.align||"left";return this.createItem("align-left",ka,i,s==="left"),this.createItem("align-center",Hh,i,s==="center"),this.createItem("align-right",$h,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=Ls(e,o,r);s.id=t;const l=this.textStylesTooltips[t];if(!l)return;const{title:c,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,c),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,fr(d))}}function hR(){return{source:"separator",type:"separator",id:`section-${J()}`,name:""}}const mR={copy:iT,cut:oT,delete:sT,"lock-block":lT,"unlock-block":aT,comment:el},CH=["image","video"];function EH(n,t,e){const r=[],i=et(n,t),o=Re(t)&&CH.includes(un(t)),s=o&&(un(t)!=="image"||un(t)==="image"&&Ti(t).length===1);if(i?r.push(new dR(n,t,e)):o&&s&&r.push(new dR(n,t,{...e,fromEmbed:!0})),!re(n,t)||lC(t)){(i||o&&s)&&r.push(hR());const l=mH(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in mR&&(c.icon=mR[c.id])}),r.push(...l)}return re(n,t)&&!lC(t)?r.push(...ZC(n,"insert-block")):r.push(hR(),{id:"insert-block-before",icon:cT,name:D.t("blockMenu.command.insertAbove"),children:ZC(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:uT,name:D.t("blockMenu.command.insertAfter"),children:ZC(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function AH(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;Av(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&gH(n,t,e,e.source==="insert-block-before")}const xH=I("exclusive-block");function JC(n,t,e,r){var l;z(t,"block-exclusive");const i=Zt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",D.t("exclusive.tips",{editor:r,embedType:s||D.t("exclusive.fallbackAbstract")}))}function gR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function bH(n,t,e,r,i){xH.debug(`block ${st(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?JC(n,t,r,i):gR(t)}function Zu(n){return n.classList.contains("block-exclusive")}function pR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&bH(n,r,t.exclusive,t.userId,t.displayName)})}class os{constructor(t){g(this,"exclusiveBlockIds",new Set);g(this,"exclusiveBlockTimer",0);g(this,"remoteExclusiveBlockIds",new Map);g(this,"handleUserChanged",t=>{const e=new Set(t.map(i=>i.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([i,o])=>{if(!e.has(o.userId)){this.remoteExclusiveBlockIds.delete(i);const s={...o,exclusive:!1};pR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;pR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>st(o)),exclusive:e};this.editor.doc.broadcastMessage(i)}exclusiveBlock(t){this.exclusiveBlockIds.has(st(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(st(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(st(t))||(this.exclusiveBlockIds.delete(st(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new os(t))}static register(t){return this.get(t)}}function tE(n,t){os.get(n).exclusiveBlock(t)}function eE(n,t){os.get(n).unexclusiveBlock(t)}class CR{writable(t,e){if(Array.isArray(e)){for(const r of e)if(Zu(r))return!1;return}if(Zu(e))return!1}create(t,e,r,i,o){const s=os.get(t).getExclusiveMessage(o.id);s&&JC(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=os.get(t).getExclusiveMessage(o.id);s?JC(t,i,s.userId,s.displayName):gR(i)}}const Zst="",vH={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},BH={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},TH={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};D.mergeLang({"zh-CN":vH,"en-US":BH,"ja-JP":TH});function Ju(n,t){return n.getBlockData(t).lock}function I0(n,t){return!!Ju(n,t)}function tf(n,t){const e=Ju(n,t);return e?e.userId===n.doc.getUser().userId:!1}function nE(n,t){const e=Ju(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function yH(n,t){if(n.readonly||!n.isBlockWritable(t)||I0(n,t)&&!tf(n,t))return;const e=n.doc.getUser(),r={userId:e.userId,displayName:e.displayName,locked:Date.now()},o={...n.getBlockData(t),lock:r};n.updateBlockData(t,o)}function kH(n,t){if(!tf(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const RH=10,wH=80,SH=50;class rE{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;if(!i||!i.blockId)return;const o=t.getBlockById(i.blockId);i.type==="lock"?yH(t,o):i.type==="unlock"&&kH(t,o)})}create(t,e,r,i,o){const s=o.lock;s&&(s.userId!==t.doc.getUser().userId?z(i,"locked-by-others"):z(i,"locked-by-self"))}update(t,e,r,i,o){const s=o.lock;if(s)if(s.userId!==t.doc.getUser().userId){z(i,"locked-by-others");const l=t.selection.focusedBlock;(l===i||ee(i,l))&&(et(t,i)||It(i)==="code")&&t.insertTextBlock("",ft(r),bt(i)+1)}else z(i,"locked-by-self");else ot(i,"locked-by-others"),ot(i,"locked-by-self")}writable(t,e){let r=[];Array.isArray(e)?r=e:r.push(e);for(const i of r){if(nE(t,i))return!1;if(dr(i))return;let o=Fs(i);for(;o;){if(nE(t,o))return!1;o=Fs(o)}}}commands(t,e){const r=I0(t,e),i=tf(t,e),o=Zu(e),s={blockId:st(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(r)if(i)l.id="unlock-block",l.name=D.t("locker.unlock"),s.type="unlock";else{const c=Ju(t,e);let d=(c==null?void 0:c.displayName)||"";const h=D.getCurrentLang()==="ja-JP",C=Fb(d,RH,h?SH:wH);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=D.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=D.t("locker.lock"),l.states=["disabled"]):l.name=D.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Jst="",LH={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},IH={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},DH={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":LH,"en-US":IH,"ja-JP":DH});class D0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const _H=I("standard-block-actions");class MH{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;try{const o=t.getBlockById(i);if(r.id==="delete"){t.deleteBlock(o);return}r.id==="copy"&&xh(t,o),r.id==="cut"&&(xh(t,o),t.deleteBlock(o))}catch(o){_H.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=I0(t,e),i=r&&tf(t,e),o=st(e),s=VC(),l=Zu(e),c={id:"copy",name:D.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:fr("CtrlOrCmd+C"),operation:D.t("copyCutProperty.copy")})},d={id:"cut",name:D.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:fr("CtrlOrCmd+X"),operation:D.t("copyCutProperty.cut")})},h={id:"delete",name:D.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const ER=I("block-menu");class UH{constructor(t){g(this,"menu");g(this,"currentBlock",null);g(this,"commandBlock",null);g(this,"handleShow",()=>{p(ER,this.currentBlock,"no target block before show block menu");const t=EH(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});g(this,"handleClose",()=>{Mp(this.editor)&&this.editor.focus()});g(this,"handleItemClick",(t,e)=>{p(ER,this.commandBlock,"no command block before show block menu"),AH(this.editor,this.commandBlock,e),e.element||this.close()});g(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new rl([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new MH)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const OH=1e3;async function NH(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=OH?"":(await Xx.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const PH=I("drag-preview-image");class FH{constructor(t){g(this,"startPosition",null);g(this,"dragContainer",null);g(this,"handleDragStart",async(t,e)=>{const r=t.target;p(PH,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=mT;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),x=this.editor.rootContainer.getBoundingClientRect(),v=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(x.width/2,v.width)}px`,this.dragContainer=s;const L=await NH(this.editor,e);L?l.src=L:z(s,"drag-placeholder"),mg(s,{status:"loaded"})});g(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:r}=t;if(e===0&&r===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:i,y:o}=this.startPosition,s=e-i,l=r-o;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});g(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const AR="drag-preview-element";function KH(n){if(Rt(n,AR))return n;const t=n.querySelector(`.${AR}`);return t||(Re(n)?Ot(n):n)}const _0=I("block-menu-drag-handler");function iE(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class VH{constructor(t,e){g(this,"dragPreview");g(this,"autoScroll");g(this,"oldPos",{x:0,y:0});g(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(p(_0,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:r,y:i}=t;this.oldPos={x:r,y:i},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});g(this,"handleDragStart",t=>{var s,l;const e=cn(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Ld({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(_0,r,"no dragged block"),(l=(s=Zt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=iE(t,"dragstart");GH(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=KH(r);this.dragPreview.handleDragStart(t,o),this.autoScroll.active(),z(r,"dragging"),z(this.editor.contentElement,"dragging")});g(this,"handleDrag",t=>{const{target:e,x:r,y:i}=t;if(this.oldPos.x===r&&this.oldPos.y===i)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:r,y:i},p(_0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=iE(t,"dragover");this.editor.contentElement.dispatchEvent(o)});g(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(_0,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(i=this.autoScroll)==null||i.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const r=iE(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new FH(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class ef{constructor(t){g(this,"highlightedBlockId","");g(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=st(t),z(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new ef(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class xR{constructor(t){g(this,"buttonElement");g(this,"emptyBlockMenu");g(this,"blockMenu");g(this,"dragHandler");g(this,"handleHoverBlock",(t,e,r)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const i=this.editor.getCustom("editor-tooltip");if(i&&i.visible()&&(i.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(r.target)||this.buttonElement.remove());return}const o=Ud(t);Gi(o)||(this.updateButton(o),YC(o,this.buttonElement,Number.MAX_SAFE_INTEGER))});g(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const r=this.blockMenu.currentBlock;if(!r)return;this.editor.selection.selectBlock(r,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{ef.get(this.editor).highlightBlock(r)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});g(this,"updatePlaceholder",t=>{Gu(this.editor,t,D.t("blockMenu.button.searchPlaceholder"))});g(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;if(this.blockMenu.currentBlock){const r=st(this.blockMenu.currentBlock);if(!this.editor.findBlockById(r)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const e=re(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new hH(t),this.blockMenu=new UH(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new VH(this.editor,this);const e=be.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new dH),ef.register(this.editor)}destroy(){be.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=B("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,D.t("blockMenu.button.tips")),t.innerHTML=Lp,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=hT,this.buttonElement.setAttribute(e,D.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=Lp,this.buttonElement.setAttribute(e,D.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),re(this.editor,t)&&!(Kt(t)&&lC(t))?this.setButtonType("insert"):this.setButtonType("move")}}const $H={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
661
661
|
\u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},HH={blockMenu:{section:{basics:"Basic",system:"System",styles:"Styles",common:"Common",actions:"Actions",thirdParty:"Third-party content"},command:{insertAbove:"Insert above",insertAfter:"Insert below",copy:"Copy",cut:"Cut",delete:"Delete"},button:{searchPlaceholder:"Search",tips:`Hold to drag
|
|
662
662
|
Click to open the menu`,insertTips:"Click to add block"}}},jH={blockMenu:{section:{basics:"\u4E00\u822C",system:"\u30B7\u30B9\u30C6\u30E0",styles:"\u30B9\u30BF\u30A4\u30EB",common:"\u4E00\u822C",actions:"\u64CD\u4F5C",thirdParty:"\u5916\u90E8\u30B3\u30F3\u30C6\u30F3\u30C4"},command:{insertAbove:"\u4E0A\u306B\u633F\u5165",insertAfter:"\u4E0B\u306B\u633F\u5165",copy:"\u8907\u88FD",cut:"\u5207\u308B",delete:"\u524A\u9664"},button:{searchPlaceholder:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",tips:"\u3092\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u30AF\u30EA\u30C3\u30AF\u3067\u30E1\u30CB\u30E5\u30FC\u3092\u8868\u793A",insertTips:"\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0"}}};D.mergeLang({"zh-CN":$H,"en-US":HH,"ja-JP":jH});const tlt="";class zH{constructor(){g(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function M0(n){return n.addCustom("drag-data",()=>new zH)}function oE(n,t){if(!t)return null;const e=M0(n).getData();return!e||e.editorId!==n.id?null:e}function bR(n,t){const e=oE(n,t);return e?n.findBlockById(e.blockId):null}function GH(n,t,e){if(!t.dataTransfer)return;const i=it(e),o=ft(i),s=st(e),l={type:"block",editorId:n.id,containerId:o,blockId:s};M0(n).setData(l)}function WH(n,t,e,r,i){if(!t.dataTransfer)return;const s=it(e),l=ft(s),c=st(e),d={type:"custom",customType:r,editorId:n.id,containerId:l,blockId:c,data:i};M0(n).setData(d)}function nf(n){M0(n).clearData()}const qH=I("drop-indicator"),rf=2;class XH{constructor(t){g(this,"indicator");g(this,"target",null);this.editor=t,this.indicator=B("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const r=this.getIndicatorRect(t,e),i=this.editor.rootElement.getBoundingClientRect(),o=r.top-i.top,s=r.left-i.left;this.indicator.style.top=`${o}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${r.width}px`,this.indicator.style.height=`${r.height}px`,this.indicator.style.display="",this.target={block:t,insertPos:e}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(t,e){if(typeof e!="string")return e.rect;if(e==="before"){const l=Vs(t);if(!l){p(qH,Mr(it(t)),"block does not in a child container");const C=t.getBoundingClientRect(),E=this.getViewRect(t);return new DOMRect(E.x,C.y,E.width,rf)}const c=l.getBoundingClientRect(),d=t.getBoundingClientRect(),h=this.getViewRect(t);return new DOMRect(h.x,(c.bottom+d.top)/2,h.width,rf)}const r=$s(t);if(!r){const l=t.getBoundingClientRect(),c=this.getViewRect(t);return new DOMRect(c.x,l.bottom,c.width,rf)}const i=t.getBoundingClientRect(),o=r.getBoundingClientRect(),s=this.getViewRect(t);return new DOMRect(s.x,(i.bottom+o.top)/2,s.width,rf)}getViewRect(t){const e=cn(t,{horizontal:!0}),r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),o=Math.max(i.x-r.x,0),s=Math.max(r.right-i.right,0);return new DOMRect(r.x+o,r.y,Math.max(r.width-o-s,0),rf)}}const QH=I("find-drop-target");function YH(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(Wi(e)&&Mr(e))return e;const r=e.firstElementChild;return r&&Wi(r)&&Mr(r)?r:null}function ZH(n,t){const s=t,l=n;for(let c=0;c<2;c++){const d=l+c*50;for(let h=0;h<5;h++){const C=s+h*8,E=document.elementFromPoint(d,C);if(E){const R=nt(E);if(R)return R}if(h===0)continue;const x=s-h*8,v=document.elementFromPoint(d,x);if(v){const R=nt(v);if(R)return R}}}return null}function JH(n,t,e){const r=document.elementFromPoint(t,e);if(r){const h=nt(r);if(h&&!_t(n,h))return h}const i=new Set,o=YH(t,e);if(o){const h=o.getBoundingClientRect();e<h.top+h.height/2?i.add(ke(o)):i.add(Ze(o))}const s=ZH(t,e);s&&i.add(s);const l=Array.from(i),c=h=>{for(let C=0;C<l.length;C++){const E=l[C];if(h!==E&&ee(h,E))return!0}return!1},d=l.filter(h=>!c(h));return d.length>0?d[0]:null}function sE(n,t){if(n.readonly)return!1;const e=it(t);if(Qt(e))return!0;const r=nt(e);return p(QH,r,"no parent block"),n.isBlockWritable(r)?sE(n,r):!1}const tj=I("drop-target");function ej(n,t){let e={};return/image/.test(t.type)?e=n.editorEmbeds.getEmbedClass("image"):/audio/.test(t.type)?e=n.editorEmbeds.getEmbedClass("audio"):/video/.test(t.type)&&(e=n.editorEmbeds.getEmbedClass("video")),p(tj,e,`unSupport file type ${t.type}`),e}async function vR(n,t,e,r){var o,s;let i=r;for(const l of t){const c=ej(n,l);c.getOptions&&await((s=(o=c.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(o,n,{containerId:e,blockIndex:i,data:{file:l}}))&&(i+=1)}}class nj{constructor(t){g(this,"handleDrop",(t,e,r,i)=>{if(Array.isArray(e)){const o=e;if(o.length>0){const s=ft(r);return vR(t,o,s,i),!0}}return!1});this.editor=t}}class of{constructor(t){g(this,"indicator");g(this,"lastDropOverResult");g(this,"handlers",[]);g(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=o=>{var d,h;const s=oE(this.editor,o.dataTransfer),l=bR(this.editor,o.dataTransfer),c=this.findTargetBlock(l,o.x,o.y);if(c&&ee(this.editor.rootContainer,c)){const C=this.findInsertPos(l,c,o.x,o.y,(h=s!=null?s:(d=o.dataTransfer)==null?void 0:d.items)!=null?h:null);if(C)return this.indicator.show(c,C),"move"}return this.indicator.hide(),"none"},r=(o,s)=>{o.dataTransfer&&(o.dataTransfer.dropEffect=s),s==="move"&&o.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const o=this.lastDropOverResult.dropEffect;r(t,o);return}const i=e(t);r(t,i),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:i}});g(this,"handleDrop",t=>{var o,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=oE(this.editor,t.dataTransfer),r=Array.from((s=(o=t.dataTransfer)==null?void 0:o.files)!=null?s:[]);if(!e&&r.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none"),nf(this.editor);return}const i=this.indicator.target;if(i){const{block:l,insertPos:c}=i,d=bR(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Zt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:r,c,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus(),nf(this.editor);return}if(d){const C=Zt(this.editor,d);if(C.handleDrop&&C.handleDrop(this.editor,d,e!=null?e:r,c,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus(),nf(this.editor);return}}if(typeof c=="string"){const C=it(l);let E=bt(l);if(c==="after"){E+=1;let x=Gt(l);for(;x&&!qc(x);)E+=1,x=Gt(x)}t.preventDefault();for(let x=0;x<this.handlers.length;x++)if(this.handlers[x].handleDrop(this.editor,d!=null?d:r,C,E)){this.editor.focus(),nf(this.editor);return}if(d){const x=this.editor.getBlockData(d),v=zo(this.editor.editorBlocks,this.editor.doc.toJSON(),x),[R]=this.editor.insertDocAt(C,E,v);this.editor.selection.selectBlock(R,0),ef.get(this.editor).highlightBlock(R),this.editor.deleteBlock(d),this.editor.focus()}}})}nf(this.editor)});g(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new XH(this.editor),this.handlers.push(new nj(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(t){this.handlers.push(t)}static register(t){return t.addCustom("drop-target",()=>new of(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||$s(e)===t&&t||!sE(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Vs(e)===t&&t||!sE(this.editor,e)||Qt(it(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!ee(t,e)}findTargetBlock(t,e,r){let i=JH(this.editor,e,r);if(!i||!ee(this.editor.rootContainer,i))return null;const o=it(i),s=nt(o);return s&&It(s)==="code"&&(i=s),this.canDrop(t,i)?i:null}findInsertPos(t,e,r,i,o){let s=e;for(;s;){const c=Zt(this.editor,s);if(c.handleDropOver){const d=c.handleDropOver(this.editor,s,o,r,i);if(d)return d;if(d===!1)return null}s=Fs(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=i&&i<=l.bottom){if(i<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return i<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<i&&this.canInsertAfter(t,e)?"after":""}}function BR(n,t,e){const r=Oe.getImageObject(n,t),i=gt.default(r.getImages());if(i.length===1){n.deleteBlock(t);return}if(e===-1||e>=i.length)return;const o=H$(i);if(i.splice(e,1),i.length===1){const l=i[0],c=100*(l.flex/o);l.flex=1;const d=hn([l],c);n.updateEmbedData(t,d);return}i[0].flex=NaN,Qa(i);const s=hn(i,r.getWidthPercent());n.updateEmbedData(t,s)}function rj(n,t,e,r){if(t.length===0||r==="after"||r==="before")return!1;let i=r.data;const o=Oe.getImageObject(n,e),s=gt.default(o.getImages()),l=[],c=[];t.forEach(C=>{cR(C.type)&&s.length+l.length<6?l.push(C):c.push(C)}),l.forEach(C=>{try{aR(n,C)}catch{return}const E={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(i,0,E);const x=hn(s,o.getWidthPercent());n.updateEmbedData(e,x),o.replaceImage(i,C),i+=1});const d=n.getBlockIndex(e)+1,h=ft(it(e));return vR(n,c,h,d),!0}function ij(n,t,e,r,i){var s,l,c;if(wd(e))return rj(n,e,t,r);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const o=e.data;if(i.isSourceBlock){const d=i.targetBlock,h=it(d);let C=bt(d);r==="after"&&(C+=1);const x=100*(o.boundingRect.width/n.rootContainer.getBoundingClientRect().width),v=hn([o.image],x),R={id:J(),type:"embed",embedType:"image",embedData:v},L=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;L&&(R.align=L),n.insertBlock(ft(h),C,R),BR(n,t,o.index),(c=n.findCustom("drag-handler"))==null||c.handleDragEnd()}else{if(typeof r=="string")return;const d=t;let h=r.data;const C=Oe.getImageObject(n,d),E=gt.default(C.getImages());h>E.length&&(h=E.length),n.undoManager.runInGroup(()=>{var v,R;C.setAutoFix(!0);const x=n.getBlockById(e.blockId);if(x===d){const L=o.index,M=h,U=o.image;if(L===M||M===L+1)return;let F=M;L<M?(E.splice(M,0,U),E.splice(L,1),F-=1):(E.splice(L,1),E.splice(M,0,U));const G=hn(E,C.getWidthPercent());n.updateEmbedData(d,G),C.setSelectedIndex(F),(v=n.findCustom("drag-handler"))==null||v.handleDragEnd()}else{E.splice(h,0,o.image),E[0].flex=NaN,Qa(E);const L=hn(E,C.getWidthPercent());n.updateEmbedData(d,L),BR(n,x,o.index),(R=n.findCustom("drag-handler"))==null||R.handleDragEnd(),C.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const oj=2;function U0(n,t,e){const r=Ti(t);if(e<=0){const s=r[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===r.length){const s=r[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const i=r[e-1].getBoundingClientRect(),o=r[e].getBoundingClientRect();return new DOMRect((o.left+i.right)/2-1,i.top,oj,i.height)}function sj(n,t,e,r,i){for(let o=0;o<e.length;o++){const l=e[o].getBoundingClientRect();if(r<=l.right)return r<=l.left+l.width/2?{rect:U0(n,t,o),data:o}:{rect:U0(n,t,o+1),data:o+1}}return r>e[e.length-1].getBoundingClientRect().right?{rect:U0(n,t,e.length),data:e.length}:{rect:U0(n,t,e.length),data:0}}function lj(n,t,e,r,i){const o=Ti(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>cR(s.type))||o.length>=6)return}else{if((e==null?void 0:e.type)==="block"||o.length>=6&&(e==null?void 0:e.blockId)!==st(t))return;const s=st(t);if(o.length===1&&s===(e==null?void 0:e.blockId))return}return sj(n,t,o,r)}async function aj(n){return await Xx.default.toSvg(n)}function lE(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class cj{constructor(t){g(this,"img");g(this,"dragContainer",null);g(this,"autoScroll",null);g(this,"imageContainer",null);g(this,"startPosition",null);g(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement)||t.button!==0)return;const r=nt(e);if(!r||!qr(r)||!this.editor.isBlockWritable(r)||this.editor.readonly)return;const i=Oe.getImageObject(this.editor,r);if(this.imageContainer=XC(t.target),!this.imageContainer)return;const s=rR(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=i.getImages()[s];if(!l)return;const{x:c,y:d}=t;this.startPosition={x:c,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},C=lE(t,"dragstart");WH(this.editor,C,r,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});g(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=nt(this.imageContainer);if(!e)return;const{x:r,y:i}=t,{width:o,height:s}=t.target.getBoundingClientRect(),l=ne(e),c=B("div",["drag-container"],l);c.style.left=`${r-o/4}px`,c.style.top=`${i-s/4}px`,c.style.width=`${Math.max(o/2,16)}px`,c.style.height=`${s/2}px`,this.dragContainer=c,z(this.editor.contentElement,"dragging");const d=cn(e);this.autoScroll=new Ld({scrollElement:d,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active();const h=B("img",["drag-target"],c),E=await aj(this.imageContainer);E&&(h.src=E)});g(this,"handleDrag",t=>{var o;const{x:e,y:r}=t;if(((o=this.startPosition)==null?void 0:o.x)===e&&this.startPosition.y===r)return;if(window.isDragging||(window.isDragging=!0,this.handleDragStart(t)),this.startPosition&&this.dragContainer){const{x:s,y:l}=t;if(s===0&&l===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:c,y:d}=this.startPosition,h=s-c,C=l-d;this.dragContainer.style.transform=`translate(${h}px, ${C}px)`,this.dragContainer.style.opacity="0.5"}const i=lE(t,"dragover");this.editor.contentElement.dispatchEvent(i)});g(this,"handleDragEnd",t=>{var e;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(e=this.autoScroll)==null||e.inactive(),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const r=lE(t,"drop");this.editor.contentElement.dispatchEvent(r)}});this.editor=t,this.editor.rootContainer.addEventListener("mousedown",this.handleMouseDown),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("mousedown",this.handleMouseDown)}}class uj{constructor(t){g(this,"handleFocusBlockChanged",(t,e,r)=>{const o=this.editor.getFocusedBlock();if(o&&qr(o)){const s=Oe.getImageObject(this.editor,o);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}r&&qr(r)&&t.findCustom(`image-${r.id}`)&&Oe.getImageObject(this.editor,r).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class fj{constructor(t){g(this,"currentResizer",null);g(this,"handleHoveringBlockChange",(t,e)=>{window.isDragging||(e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t)))});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){qr(t)&&Oe.getImageObject(this.editor,t).disableResizer()}enable(t){if(qr(t)){const e=Oe.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const dj={image:{title:"\u56FE\u7247",upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-3">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},hj={image:{title:"Image",upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>',remote:{failed:'<div class="line-1">Failed to load image</div><div class="line-2">This picture is from an expired external link</div><div class="line-3">Please save the original image to local drives and upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"This picture is from an external link. If the link expires, the picture will not be available. It's recommended to save it to local drives and add it to the page."}},abstract:"Image"}},mj={image:{title:"\u753B\u50CF",upload:{failed:'<div class="line-1">\u753B\u50CF\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\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 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>'},load:{failed:'<div class="line-1">\u753B\u50CF\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 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>',remote:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u3053\u306E\u753B\u50CF\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B URL \u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u306E\u3067\u3001\u8868\u793A\u3067\u304D\u307E\u305B\u3093</div><div class="line-3">\u753B\u50CF\u3092\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C0\u3057\u3066\u304F\u3060\u3055\u3044 <a href="" class="retry-upload">\u753B\u50CF\u30EA\u30F3\u30AF\u3092\u958B\u304F</a></div>',tooltip:"\u3053\u306E\u753B\u50CF\u306F\u5916\u90E8\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B\u305F\u3081\u3001\u30EA\u30F3\u30AF\u304C\u7121\u52B9\u306B\u306A\u308B\u3068\u3001\u8868\u793A\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\u306E\u3067\u3001\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3001\u30DA\u30FC\u30B8\u306B\u633F\u5165\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059"}},abstract:"\u753B\u50CF"}};D.mergeLang({"zh-CN":dj,"en-US":hj,"ja-JP":mj});function gj(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=In(o,r),l=ce(s);let c=r;if(l.endsWith("![]()"))c-=5;else if(l.endsWith("![]"))c-=3;else return!1;const d=r;return oa("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,c,d-c);let C=e+1;ce(n.getBlockText(i)).trim()?(Ea(n,i,c,{forceInsertAfter:!0}),c===0&&(n.deleteBlock(i),C--)):(n.deleteBlock(i),C--),Og(n,"image",t,C,{file:h})})}),!0}class pj{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(R0(t,e))return!1;if(gj(t,e,r,i))return!0}return!1}}function Cj(n){const t=n.getFocusedBlock(),e=$s(t);if(e&&qr(e)){n.selection.selectBlock(e,0);const r=Oe.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function Ej(n){const t=n.getFocusedBlock(),e=Vs(t);if(e&&qr(e)){n.selection.selectBlock(e,0);const r=Oe.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function Aj(n){const e=n.getFocusedBlock();if(e&&qr(e)){const r=Oe.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(i.length-1),!0;if(o>0)return r.setSelectedIndex(o-1),!0}}}function xj(n){const e=n.getFocusedBlock();if(e&&qr(e)){const r=Oe.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(0),!0;if(o<i.length-1)return r.setSelectedIndex(o+1),!0}}}function aE(n){const e=n.getFocusedBlock();if(e&&qr(e)){const r=Oe.getImageObject(n,e);if(r.getImages().length>0){const o=r.getSelectedIndex();if(o!==-1)return r.removeImage(o),!0}}}const bj={ArrowLeft:Aj,ArrowRight:xj,ArrowUp:Ej,ArrowDown:Cj,Delete:aE,Backspace:aE},vj=I("copy-image");function Bj(n,t,e,r){const i=e.getImages()[r],o=e.getImages().length===1?e.getWidthPercent():i.flex*100,s=hn([i],o),l={id:J(),type:"embed",embedType:"image",embedData:s},c=n.options.componentsOptions.image;c!=null&&c.defaultAlign&&(l.align=c.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const C=h.getContext("2d");if(!C)return;const E={},x={};try{C.drawImage(t,0,0,h.width,h.height);const F=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),G=vg(F),q=new File([G],`${Date.now()}.png`,{type:"image/png"});E["image/png"]=q}catch(U){vj.error(U)}Ah(n,d);const R=`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`,L=Eh(R,d),M=new Blob([L],{type:"text/html"});return E["text/html"]=M,x["text/html"]=L,[E,x]}function Tj(n,t,e,r,i){const o=Bj(n,t,e,r);if(!o)return;const[s,l]=o;if(s){const c=Object.entries(s).map(([d,h])=>({type:d,data:h}));return yg(c).then(d=>{if(!d&&i){const h=i.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function TR(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const i=n.getFocusedBlock();if(i&&qr(i)){const o=Oe.getImageObject(n,i);if(o.getImages().length>0){const l=o.getSelectedIndex();if(l!==-1){const d=Ti(i)[l].querySelector("img");if(d)return Tj(n,d,o,l,t)}}}}class yj{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,r){if(!window.isSecureContext)return;if(TR(t,e))return!0}handleBeforeCut(t,e){if(TR(t,e))return aE(t),!0}destroy(){}}class cE{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,r){return Object.values(e.blocks).forEach(i=>{i.forEach(o=>{if(o.type==="embed"&&o.embedType==="image"){const s=o.embedData;if(Array.isArray(s.src))return;let l=r.blockIdMap.get(o.id);for(;l&&r.blockIdMap.get(l);)l=r.blockIdMap.get(l);l&&is(t,l).setAutoFix(!0)}})}),!1}destroy(){}}const kj=I("image-embed");function Rj(n,t,e,r,i,o){Oe.create(n,e).createContent(i,o,t),n.addCustom("image-select-handler",()=>new uj(n)),n.addCustom("image-copy-handler",()=>new yj(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new cj(n));const l=n.addCustom("image-resizer",()=>new fj(n)),c=e.embedData;Xa(c)?l.disable(o):l.currentResizer===o&&l.enable(o)})}function wj(n,t,e,r){const i=t.embedData,o=Ya(i);return r==="html"?o.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):r==="markdown"?`${o.map(l=>`})`).join(`
|
|
663
663
|
`)}
|
|
@@ -728,7 +728,7 @@ ${s}
|
|
|
728
728
|
<path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
729
729
|
</svg>`,VG=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
|
|
730
730
|
<path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
731
|
-
</svg>`,llt="",$0="reply-editor-editing",{t:yE}=D;class $G{constructor(t,e,r,i){g(this,"root");g(this,"components");g(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});g(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,r=t.getDoc();f1(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{Rt(this.root,$0)||(z(this.root,$0),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!Rt(this.root,$0)||ot(this.root,$0)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,o=r.getDoc(),s=V0({editor:t,commentGroupId:e.groupId,abstract:this.groupItem.comment.abstract});i.localCreateComment(s,o),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{Rt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{ot(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=B("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=cl(this.root,Jt.QuickReply,yE("comment.placeholder"));ho(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=B("div",["quick-reply-editor"],this.root),i=eo(),o=new TE(this.mainEditor,t,i);o.editor.addListener("docChanged",this.handleDocChange),o.editor.addListener("focus",this.handleFocus),o.editor.input.addHandler(new MG(this.groupItem)),r.append(o.root);const s=B("div",["reply-editor-actions"],r),l=Cr(Jt.QuickReplyCancel,yE("common.cancel"));ho(l,Jt.QuickReplyCancel);const c=Cr(Jt.QuickReplyOk,yE("comment.send"),void 0,["primary","disabled"]);return ho(c,Jt.QuickReplyOk),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:o,replyEditorContainer:r,okButton:c}}}const ls=I("comment-group-item");class HG extends ye.TypedEmitter{constructor(e,r,i,o){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>B("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=B("div",["comment-children-list-container"],this.root);return new FG({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});g(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));p(ls,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{ot(i,aw)});const r=e[e.length-1];z(r,aw)});g(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),r=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');p(ls,e,"switchUpButton not exist"),p(ls,r,"switchDownButton not exist"),ot(r,"disabled"),ot(e,"disabled"),this.root.previousElementSibling===null&&z(e,"disabled"),this.root.nextElementSibling===null&&z(r,"disabled")});g(this,"handleReadonlyChanged",e=>{e.readonly?z(this.root,"readonly"):ot(this.root,"readonly")});g(this,"getCommentEditor",()=>this.mainItem.getCommentEditor());g(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=r,this.comment=i,this.groupList=o,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new Ss(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return uw(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,o=new $G(e,r,i,this);return this.root.append(o.root),o}createHeader(){const{comment:e}=this,r=B("div",["comment-item-head"],this.root),i=B("span",["item-head-quote"],r);i.innerText=e.abstract;const o=B("span",["item-head-switch"],r),s=cl(o,Jt.SwitchUp,"up",KG),l=cl(o,Jt.SwitchDown,"down",VG);return ho(s,Jt.SwitchUp),ho(l,Jt.SwitchDown),r}createItem(){const e=B("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:o,groupList:s}=this,l=new bw({mainEditor:r,commentsProvider:i,comment:o,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(r=>r.comment.id===e):null}handleCreateComment(e){return p(ls,ec(e),"invalid comment, not a child comment"),p(ls,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){const r=this.childrenList.findItem(e.id);if(!r){ls.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(ls,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(ls,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const jG=I("arrange=items"),Bw=20;function Tw(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return-1;const r=n.scrollContainer.getBoundingClientRect(),i=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-r.top+i}function yw(n,t){return Number.parseInt(t.root.style.top,10)}function kw(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let o=i;o<t.length;o++){const s=t[o],l=s.comment,c=Tw(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),o===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else s.root.style.top=`${c}px`;continue}const d=t[o-1],h=yw(n,d)+d.root.getBoundingClientRect().height;h>c?s.root.style.top=`${h+Bw}px`:s.root.style.top=`${c}px`}for(let o=i-1;o>=0;o--){const s=t[o],l=s.comment,c=Tw(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const d=s.root.getBoundingClientRect(),h=c+d.height,C=t[o+1];p(jG,C,"no next item");const E=yw(n,C);E<h?s.root.style.top=`${E-d.height-Bw}px`:s.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const H0=I("comment-group-item-handler");class zG{constructor(t,e){g(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});g(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});g(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});g(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});g(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});g(this,"handleCommentItemReply",(t,e)=>{const r=t.findCommentItem(e);p(H0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:o}=r,s=i.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:J(),box:!0,created:Date.now(),text:o.displayName,iconUrl:o.avatarUrl,mentionId:o.userId};s.editor.insertBoxToBlock(l,0,c)});g(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});g(this,"handleCommentItemOk",(t,e)=>{const r=t.findCommentItem(e);p(H0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:o,getCommentEditor:s}=r,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(o,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(H0,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let o=!1;if((c=i.blocks)!=null&&c.length||(o=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];o=!!h.text&&fn(h.text)===0}if(o){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:s}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),s.show()});g(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItemAsGroupId(t.comment.groupId);if(!e)return;const{quickReply:r}=e;t.getCommentEditor().edit(),r.hide()});g(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItemAsGroupId(t.comment.groupId);if(!e)return;const{quickReply:r}=e,{comment:i}=t;this.commentsProvider.localDeleteComment(i.id),r.show()});g(this,"execute",(t,e,r,i)=>{const o=kG(t);if(!o||wG(o))return;const s=RG(o);switch(s){case Jt.SwitchUp:this.handleSwitchUp(i);break;case Jt.SwitchDown:this.handleSwitchDown(i);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,r);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,r);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,r);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;H0.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const j0=I("comment-group-list");class GG extends ff{constructor(e,r,i){super(e,r,i,ss(e,r),{});g(this,"groupItemHandlers");g(this,"closeEditing",e=>{const r=this.items.find(i=>i.comment.id===e);r&&([r,...r.childrenList.items].forEach(i=>{!i.getCommentEditor().editor.readonly&&i.getCommentEditor().isEmpty()&&this.groupItemHandlers.handleCommentItemCancel(r,i.comment.id)}),r.quickReply.getReplyEditor().isEmpty()&&r.quickReply.cancel())});g(this,"setFirstEditingCommentActive",()=>{const e=this.findFirstEditingComment();e!==-1&&this.setActiveItem(e)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const r=e.target.closest(".comment-group-item-root");if(!r)return;const i=yG(e.target),o=this.items.findIndex(s=>s.root===r);if(o!==-1){this.activeIndex!==o&&this.setActiveItem(o);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[o],i,o)}});g(this,"handleDocumentClick",e=>{if(!e.target||!(e.target instanceof Element)||e.target.closest(".comment-group-item-root.active"))return;const i=this.items[this.activeIndex];!i||[i.findCommentItem(i.comment.id),...i.childrenList.items].some(s=>{var c;const l=(c=s==null?void 0:s.moreMenu.tippyInstance)==null?void 0:c.popper;return!!(l!=null&&l.contains(e.target))})||i!=null&&i.comment&&setTimeout(()=>{this.closeEditing(i.comment.id)})});g(this,"handleSelectionChanged",()=>{setTimeout(()=>{var r;const e=pw(this.editor);if(e.length>0){if(((r=this.activeItem)==null?void 0:r.comment.id)&&e.includes(this.activeItem.comment.id))return;const i=e[0],o=this.items.findIndex(s=>s.comment.groupId===i);this.setActiveItem(o),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});g(this,"handleEditorResize",()=>{this.updateItemsLayout()});g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"handleItemResize",()=>{this.updateItemsLayout()});g(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const r=document.elementFromPoint(e.clientX,e.clientY);if(!r||!(r instanceof HTMLElement)||!this.editor.scrollContainer.contains(r))return;const i=this.container.querySelector(".comment-group-item-root");if(!i)return;const o=Number.parseFloat(i.style.top),s=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(o)&&!Number.isNaN(s)&&o<s&&kw(this.editor,this.items,null,Math.min(o+(0-e.deltaY)*3,s))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(j0,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Ke.default(()=>{const e=ss(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const o=e[i];if(!this.findGroupItem(o.groupId)){this.handleCreateComment(o,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const o=this.items[i];e.findIndex(s=>s.groupId===o.comment.groupId)===-1&&(this.deleteItem(o.comment.id),r=!0)}r&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(o=>o.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new zG(this,r),document.addEventListener("click",this.handleDocumentClick)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners(),document.removeEventListener("click",this.handleDocumentClick)}updateItemsLayout(){kw(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,r){const i=new HG(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{ot(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=ss(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}insertItem(e,r){const i=super.insertItem(e);return i?(r!=null&&r.active&&this.setActiveItem(this.items.indexOf(i)),this.updateItemsLayout(),i.addListener("resize",this.handleItemResize),i):null}findFirstEditingComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if((!i.quickReply.getReplyEditor().isEmpty()||e)&&!i.quickReply.getReplyEditor().editor.readonly)return r;const o=[i,...i.childrenList.items];for(let s=0;s<o.length;s++){const l=o[s];if(!l.getCommentEditor().editor.readonly&&(!l.getCommentEditor().isEmpty()||e))return r}}return-1}isEditing(){return this.findFirstEditingComment()!==-1}setActiveItem(e,r){if(p(j0,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const i=this.container.querySelector(".comment-group-item-root.active");if(i){const o=this.items[this.activeIndex];setTimeout(()=>{this.closeEditing(o.comment.id)}),ot(i,"active")}if(e!==-1){const o=this.items[e];z(o.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,r)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(r=>r.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,r){if(ec(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(j0,!i,"comment group item has already exists");const o={children:[],...e};p(j0,o.children,"not a comment group");const s=this.insertItem(o,{active:r});if(!!s&&r){const l=this.items.indexOf(s);this.setActiveItem(l),s.quickReply.hide(),setTimeout(()=>{s.edit()},300)}}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?(this.deleteItem(i.comment.id),this.updateItemsLayout()):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&(this.deleteItem(i.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){const r=this.findItemAsGroupId(e.groupId);if(r&&r.comment.id!==e.id){r.handleUpdateChildComment(e);return}const i=this.findItem(e.id);i&&i.handleUpdateMainComment(e)}}const WG="comment-mini";I("comment-list");class qG extends ye.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"groupsContainer");g(this,"list");g(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});g(this,"updateCommentCount",()=>{var r,i;const e=IG(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var o,s;const i=this.list.activeItem;Ew(this.editor,(s=(o=i==null?void 0:i.comment)==null?void 0:o.groupId)!=null?s:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=Rt(this.root,WG);(i=(r=this.commentOptions)==null?void 0:r.onUpdateLayout)==null||i.call(r,this.editor,{expand:e})});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-web-comment-root"],null),this.groupsContainer=B("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r),this.updateCommentCount()}onDeleteComment(e,r){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}createList(){return new GG(this.editor,this.commentsProvider,this.groupsContainer)}isEditing(){return this.list.isEditing()}setFirstEditingCommentActive(){this.list.setFirstEditingCommentActive()}show(e){var r;if(ot(this.root,"hidden"),e){const i=this.list.findItemIndex(e);this.list.setActiveItem(i)}(r=this.commentOptions)==null||r.controller.showCommentList()}hide(){z(this.root,"hidden")}}class XG extends ff{constructor({editor:t,parent:e,commentsProvider:r,comments:i}){super(t,r,e,i,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:r}=this;return new vw(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const z0=I("mobile-comment-group-item"),QG=20;class YG extends ye.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>B("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=new vw(r,i,o);return e.append(s.root),s});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=B("div",["mobile-comment-children-list-container"],e);return new XG({editor:r,commentsProvider:i,comments:o.children,parent:s})});g(this,"handleTouchEnd",()=>{var o;const{scroller:e}=this,{pullThreshold:r=QG}=(o=this.editor.getComponentOptions("comment"))!=null?o:{};let i=null;if(e.y>e.minScrollY+r?(i=this.root.previousElementSibling,i||this.emit("onReachTop")):e.y<e.maxScrollY-r&&(i=this.root.nextElementSibling,i||this.emit("onReachBottom")),i){const s=i.id;this.emit("onSwitchGroup",s,cw)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=B("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const o=B("div",["mobile-group-item"],this.root),s=B("div",["mobile-group-item-space"],null),l=B("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=B("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),o.append(s,l,c),this.scroller=new Qx.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return uw(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(z0,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){z0.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(z0,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(z0,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const kE=I("mobile-group-list");class ZG extends ff{constructor(e,r,i,o){super(e,r,i,ss(e,r),{});g(this,"scroller");g(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});g(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const r=this.findItemIndex(e);let i=null;return r===0?i=this.items[r+1].root.id:i=this.items[r-1].root.id,super.deleteItem(e)?(this.scrollToGroup(i,cw),!0):!1});g(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});g(this,"handleReachBottom",()=>{this.emit("onReachBottom")});g(this,"handleReachTop",()=>{this.emit("onReachTop")});g(this,"scrollToGroup",(e,r=0)=>{const i=this.findGroupItem(e);p(kE,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),Ew(this.editor,i.comment.groupId)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"updateComments",Ke.default(()=>{const e=ss(this.editor,this.commentsProvider);for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1);continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(o=>o.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new Qx.default(o),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new YG(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=ss(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(ec(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const i=this.findItem(e.id);p(kE,!i,"comment group item has already exists");const o={children:[],...e};p(kE,o.children,"not a comment group"),this.insertItem(o),this.scroller.refresh()}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?this.deleteItem(i.comment.id):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&this.deleteItem(i.comment.id);return}}}handleUpdateComment(e){if(ec(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const JG=I("mobile-comment-list"),{t:Rw}=D;class tW extends ye.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"list");g(this,"mask");g(this,"pullInfoContainer");g(this,"handleRootClick",e=>{const r=e.target;p(JG,r instanceof Element,"invalid target"),!(r.closest(".mobile-group-item-abstract")||r.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});g(this,"hidePullInfo",Ke.default(()=>{ot(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;ot(this.root,"hidden"),z(document.documentElement,"disabled-scroll"),(r=this.commentOptions)==null||r.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});g(this,"hide",()=>{z(this.root,"hidden"),ot(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mobile-comments-root"],null),this.mask=B("div",["mobile-comment-mask"],this.root);const i=B("div",["mobile-comment-groups-container"],this.root),o=B("div",["mobile-comment-groups-scroll-container"],i);this.list=new ZG(this.editor,this.commentsProvider,o,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=B("div",["mobile-comment-pull-info-container"],this.root);return B("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=Rw(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=r,z(this.pullInfoContainer,"active"),this.hidePullInfo()}isEditing(){return!1}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function ww(n,t){const e=ss(n,t),r=new Map;for(const i of e){const o=fw(n,i.groupId);if(!!o)if(r.has(o)){const s=r.get(o);gw(i).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=gw(i),l=new Set(s.map(c=>c.id));r.set(o,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,o])=>({blockId:i,...o}))}const eW=I("mini-group-item");class nW{constructor(t,e){g(this,"root");g(this,"blockId");g(this,"comment");g(this,"miniCommentItem");g(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=B("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new PG(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return fw(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);p(eW,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class rW extends ff{constructor(e,r,i){super(e,r,i,ww(e,r),{});g(this,"fixListOps",Ke.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));g(this,"handleDocChanged",Ke.default(()=>{this.updateMiniCommentsGroup()},100));g(this,"updateMiniCommentsGroup",()=>{const e=ww(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=r,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new nW(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,r){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const iW=I("mini-comments-list");class oW extends ye.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=B("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new rW(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(iW,i instanceof HTMLElement,"The target is not a valid html element");const o=i.closest(".mini-comment-item");o&&this.emit("onItemClick",o.id)});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){}show(){ot(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function Sw(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const r=t.block,i=ve(n,r,t.start.offset,t.end.offset),o=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;y5(n,r,i,o,s)}function sW(n,t,e){const r=fi(n).map(s=>s.block),i=AE(n,r),o=V0({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{fi(n,{simpleBlockOnly:!0}).forEach(c=>{!et(n,c.block)||Sw(n,c,o)});const l=eo();e.localCreateComment(o,l)}),o}class lW{constructor(t,e){g(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,r){const i=t.selection.range;if(et(t,e)&&!r.isCollapsed()&&i.isSimple()){const o=st(e),s=It(e),l=Ir(t,e);return[{id:"add-comment",name:D.t("comment.command"),blockId:o,blockType:s,blockKind:l,groupIndex:1e3,icon:el}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,r,i,o){if(r.id==="add-comment"){this.editorComments.showCommentList();const s=sW(t,e,this.provider);return o["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class Lw{constructor(t,e){g(this,"commentList",null);g(this,"mobileCommentList",null);g(this,"miniCommentList");g(this,"showComment",(t,e)=>{var r,i;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((r=this.mobileCommentList)==null||r.show(e)),t==="web"&&((i=this.commentList)==null||i.show(e))});g(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});g(this,"handleCommentListClose",()=>{this.showComment("mini")});g(this,"handleOnSelectComment",()=>{this.showComment("web")});g(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new lW(e,this)),t.blockHooks.push(new vG(this.provider,this)),this.isMobile?(this.mobileCommentList=new tW(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new qG(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new oW(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new BG)}get commentProvider(){return this.provider}get isMobile(){return he.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}setFirstEditingCommentActive(){var t;(t=this.commentList)==null||t.setFirstEditingCommentActive()}isEditing(){var t,e;return((t=this.commentList)==null?void 0:t.isEditing())||((e=this.mobileCommentList)==null?void 0:e.isEditing())||!1}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const alt="",aW={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u5B9A",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u6DFB\u52A0\u6279\u6CE8\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},cW={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotation or mention someone",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},uW={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u5B9A",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0\u3059\u308B\u304B\u30E1\u30F3\u30D0\u30FC\u3092\u30E1\u30F3\u30B7\u30E7\u30F3",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};D.mergeLang({"zh-CN":aW,"en-US":cW,"ja-JP":uW});class Iw{renderText(t,e,r){const i=[],o={};return Object.entries(r).forEach(([s,l])=>{s.startsWith("comment-")&&(i.push("comment"),o[s]=l)}),{classes:i,attributes:o}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const o=["comment"],s={};return i.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:o,attributes:s}}updateBlock(t,e,r,i){const o=i.comments;ot(r,"comment"),Array.from(r.attributes).forEach(s=>{s.name.startsWith("comment-")&&r.removeAttribute(s.name)}),!(!o||o.length===0)&&(z(r,"comment"),o.forEach(s=>{r.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class fW{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,o)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Gu(t,e,D.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function dW(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const s=new Set(i);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const o=r.text;if(!!o&&et(n,t)){const s=Xg(o,`comment-${e.toLocaleLowerCase()}`,e);Pc.default(o,s)||n.setBlockText(t,s)}}const hW=I("editor-comment");function mW(n){const t=n.getCustom("editor-comments");if(p(hW,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Ko(s);if(l.length>=2){const{containerId:c}=l[l.length-1],d=nt(ci(n,c));if(d&&It(d)==="code"){xE(n,d,t.commentProvider);return}}xE(n,s,t.commentProvider);return}const e=fi(n,{simpleBlockOnly:!0}),r=e.map(s=>s.block),i=AE(n,r),o=V0({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{et(n,l.block)?Sw(n,l,o):lw(n,l.block,o)});const s=eo();t.commentProvider.localCreateComment(o,s)})}const RE=I("text-styles");function gW(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([o])=>!!o.startsWith("style-"));return new Map(i)};if(n.length===0)return new Map;let e=t(n[0]);for(let r=1;r<n.length;r++){const i=t(n[r]);e=new Map(Array.from(e.entries()).filter(([o,s])=>i.get(o)===s))}return e}function pW(n,t,e,r,i){p(RE,e.isSimple(),"invalid range");const{start:o,end:s}=e;p(RE,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(RE,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=fa(o.offset,s.offset-o.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=fa(o.offset,s.offset-o.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=fa(o.offset,s.offset-o.offset,c,r,void 0,{ignoreValue:!0}):c=nu(o.offset,s.offset-o.offset,c,r,i),n.setBlockText(t,c),c}const dl=I("text-commands");function Dw(n){const t={id:"more",name:D.t("commands.more"),icon:Cp,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[D.t("commands.bold"),fr("CtrlOrCmd+B"),pT],"style-italic":[D.t("commands.italic"),fr("CtrlOrCmd+I"),CT],"style-underline":[D.t("commands.underline"),fr("CtrlOrCmd+U"),ET],"style-strikethrough":[D.t("commands.strikethrough"),fr("CtrlOrCmd+D"),AT],"style-code":[D.t("commands.code"),void 0,xT]},r={"style-super":[D.t("commands.superscript"),void 0,vT],"style-sub":[D.t("commands.subscript"),void 0,bT]};if(fn(n)===0){const l=Object.entries(e).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h}));return t.children=Object.entries(r).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h})),l.concat(t)}const i=gW(n);function o([l,[c,d,h]]){const C=i.get(l);return C!==void 0?{id:l,name:c,value:C,states:C===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:c,icon:h,desc:d}}const s=Object.entries(e).map(o);return t.children=Object.entries(r).map(o),s.concat(t)}function CW(n,t){const e=st(t),r=It(t),i=Ir(n,t);return Dw([]).map(o=>({blockId:e,blockType:r,blockKind:i,...o,groupIndex:500}))}function EW(n,t,e){p(dl,e.isSimple(),"nor a simple range");const{start:r,end:i}=e;p(dl,r.isSimple(),"is not a simple block position"),p(dl,i.isSimple(),"is not a simple block position"),p(dl,et(n,t),"invalid block type, not a text kind block");const o=st(t);p(dl,r.blockId===o&&i.blockId===o,"invalid range");const s=n.getBlockText(t);let l=[];r.offset===i.offset?r.offset!==0&&(l=qe(s,r.offset-1,1).middle):l=qe(s,r.offset,i.offset-r.offset).middle;const c=It(t),d=Ir(n,t);return Dw(l).map((h,C)=>({blockId:o,blockType:c,blockKind:d,...h,groupIndex:500,order:C*100}))}function AW(n,t,e,r,i,o){if(!et(n,t))return!1;if(!r.startsWith("style-"))return dl.warn(`unknown command: ${r}`),!1;const s=i==null?void 0:i.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return dl.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const c=pW(n,t,e,r,s);return o.result=c,!0}const xW=I("text-command-provider");class Ri{constructor(t){g(this,"id","TextCommandProvider");g(this,"emptyTextBlockAttributes",new Map);g(this,"colorItem");g(this,"updateButtonColor",t=>{const e=w5(this.editor,t,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(e)});g(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")k5(this.editor,t,e,this.setEmptyTextBlockColor);else{const r=["clearAll","clearColor","clearBackground"];R5(this.editor,r[e],this.setEmptyTextBlockColor)}this.colorItem.setLatestColors(t,e)});g(this,"getEmptyTextBlockColor",(t,e)=>{const r=this.getEmptyBlockTextAttributes(t,e);return Qg(r)});g(this,"setEmptyTextBlockColor",(t,e,r,i)=>{var s;const o=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};A3(o,r,i),this.emptyTextBlockAttributes.set(e,o)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new KT(t)),this.colorItem.addListener("onClick",this.handleChangeColor)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,r){if(!et(t,e))return[];let i;dt(t,e)===0?i=this.getCommandsOnEmptyText(t,e).map(Ri.toTextCommand):i=EW(t,e,r).map(Ri.toTextCommand),this.updateButtonColor(r);const s={...this.colorItem,blockId:st(e),blockKind:Ir(t,e),blockType:It(e),groupIndex:500,order:350};return i.push(s),i}executeCommand(t,e,r,i,o,s){if(!et(t,e))return!1;let l=o.value;l===void 0&&(l=!i.value);const c=Ri.fromTextCommandId(i.id);if(c.startsWith("style-")){if(c==="style-font")return this.handleChangeColor(o.type,l),!0;if(dt(t,e)===0)return this.executeCommandOnEmptyText(e,i,{value:l})}return AW(t,e,r,c,{value:l},s)}executeCommandOnEmptyText(t,e,r){let i=this.emptyTextBlockAttributes.get(st(t));i||(i={},this.emptyTextBlockAttributes.set(st(t),i));const o=Ri.fromTextCommandId(e.id),s=r.value;return s==null||s===!1?(delete i[o],!0):(i[o]=r.value,!0)}getCommandsOnEmptyText(t,e){const r=CW(t,e);return this.setCommandsStates(r,e)}setCommandsStates(t,e){var o;const r=st(e),i=(o=this.emptyTextBlockAttributes.get(r))!=null?o:{};return t.map(s=>{const l=i[s.id],c=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:c}})}getEmptyBlockTextAttributes(t,e){var i;const r=gt.default((i=this.emptyTextBlockAttributes.get(e))!=null?i:{});if(Array.from(Object.entries(r)).forEach(([o,s])=>{s||delete r[o]}),Object.keys(r).length!==0)return r}static toTextCommand(t){return t.children&&(t.children=t.children.map(Ri.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return p(xW,t.startsWith(e),`invalid item id: ${t}`),t.substring(e.length)}static fromTextCommand(t){return{...t,id:this.fromTextCommandId(t.id)}}static toTextCommands(t){return t.map(Ri.toTextCommand)}static fromTextCommands(t){return t.map(Ri.fromTextCommand)}}function _w(n){const t=n.findCustom("toolbar-handler");t==null||t.disableTextToolbar(),t==null||t.hide(),setTimeout(()=>{t==null||t.enableTextToolbar()},300)}function bW(n){n.undoManager.canUndo()&&_w(n)}function vW(n){n.undoManager.canRedo()&&_w(n)}const BW={"CtrlOrCmd+Z":bW,"CtrlOrCmd+Shift+Z":vW},TW={commands:{bold:"\u7C97\u4F53",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strikethrough:"\u5220\u9664\u7EBF",code:"\u884C\u5185\u4EE3\u7801",subscript:"\u4E0B\u6807",superscript:"\u4E0A\u6807",more:"\u66F4\u591A"}},yW={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},kW={commands:{bold:"\u592A\u5B57",italic:"\u659C\u4F53",underline:"\u4E0B\u7DDA",strikethrough:"\u53D6\u308A\u6D88\u3057\u7DDA",code:"\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",subscript:"\u4E0B\u4ED8\u304D\u6587\u5B57",superscript:"\u4E0A\u4ED8\u304D\u6587\u5B57",more:"\u305D\u306E\u4ED6"}};D.mergeLang({"zh-CN":TW,"en-US":yW,"ja-JP":kW});const RW={embedProperties:{edit:"\u7F16\u8F91",addComment:"\u6DFB\u52A0\u6279\u6CE8"}},wW={embedProperties:{edit:"Edit",addComment:"Add annotation"}},SW={embedProperties:{edit:"\u7DE8\u96C6",addComment:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0"}};D.mergeLang({"zh-CN":RW,"en-US":wW,"ja-JP":SW});const Mw=I("embed-block-properties");function df(n,t){var e;for(const r of n.blockHooks){const i=(e=r.commands)==null?void 0:e.call(r,n,t);if(!!i&&i.group==="block-comment-actions")return i.executeCommand(n,t,i.commands[0]),!0}return!1}class wE{constructor(t,e,r){g(this,"group","hovering-toolbar");g(this,"_commands",[{id:"edit",name:D.t("embedProperties.edit"),icon:jh},{id:"add-comment",name:D.t("embedProperties.addComment"),icon:el}]);this.editor=t,this.block=e,this.properties=r}get commands(){var i,o,s;if(this.editor.readonly)return[];let t=this._commands;const{enableComments:e=!0}=this.editor.options;e||(t=t.filter(l=>l.id!=="add-comment")),t.forEach(l=>{(l.id==="add-comment"||l.id==="edit")&&(l.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});let r=(i=this.properties)!=null&&i.presetIds?t.filter(l=>{var c,d;return(d=(c=this.properties)==null?void 0:c.presetIds)==null?void 0:d.includes(l.id)}):[...t];return(s=(o=this.properties)==null?void 0:o.extCommands)!=null&&s.length&&(r.length&&r.push({id:J(),type:"separator",name:""}),r.push(...this.properties.extCommands)),r.length<=3&&(r=r.filter(l=>l.id!=="separator")),r}executeCommand(t,e,r){var i,o;if(!((o=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&o.call(i,t,e,r))){if(r.id==="add-comment"){df(t,e)||Mw.error("failed to add comment to block");return}Mw.error(`unknown command: ${JSON.stringify(r)}`)}}}function SE(n,t,e){return{blockCommands:{"hovering-toolbar":new wE(n,t,e)}}}class hf{constructor(t){g(this,"blockResizer");g(this,"handleResizing",(t,e)=>{var i,o;const r=t.getBlock();if(r){if(((o=(i=Zt(this.editor,r)).notify)==null?void 0:o.call(i,this.editor,"resize",{block:r,rect:e}))===!0)return;const s=Math.max(e.height,100),d={...this.editor.getBlockData(r).embedData,height:s};this.editor.updateEmbedData(r,d)}});g(this,"handleHoveringBlockChange",(t,e)=>{e&&Re(e)&&Rt(e,"resizable")&&this.disableResizer(),t&&Re(t)&&Rt(t,"resizable")&&this.editor.isBlockWritable(t)&&this.tryEnableResizer(t)});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange),this.blockResizer=new qu(this.editor,{resize:["bottom"]}),this.blockResizer.addListener("resizing",this.handleResizing)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}tryEnableResizer(t){this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}static get(t){return t.addCustom("EmbedBlockResizer",()=>new hf(t))}static register(t,e){return z(e,"resizable"),t.addCustom("EmbedBlockResizer",()=>new hf(t))}}var Uw=(n=>(n.Card="card",n.Preview="preview",n))(Uw||{});const LW=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
731
|
+
</svg>`,llt="",$0="reply-editor-editing",{t:yE}=D;class $G{constructor(t,e,r,i){g(this,"root");g(this,"components");g(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});g(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,r=t.getDoc();f1(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{Rt(this.root,$0)||(z(this.root,$0),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!Rt(this.root,$0)||ot(this.root,$0)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,o=r.getDoc(),s=V0({editor:t,commentGroupId:e.groupId,abstract:this.groupItem.comment.abstract});i.localCreateComment(s,o),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{Rt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{ot(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=B("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=cl(this.root,Jt.QuickReply,yE("comment.placeholder"));ho(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=B("div",["quick-reply-editor"],this.root),i=eo(),o=new TE(this.mainEditor,t,i);o.editor.addListener("docChanged",this.handleDocChange),o.editor.addListener("focus",this.handleFocus),o.editor.input.addHandler(new MG(this.groupItem)),r.append(o.root);const s=B("div",["reply-editor-actions"],r),l=Cr(Jt.QuickReplyCancel,yE("common.cancel"));ho(l,Jt.QuickReplyCancel);const c=Cr(Jt.QuickReplyOk,yE("comment.send"),void 0,["primary","disabled"]);return ho(c,Jt.QuickReplyOk),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:o,replyEditorContainer:r,okButton:c}}}const ls=I("comment-group-item");class HG extends ye.TypedEmitter{constructor(e,r,i,o){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>B("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=B("div",["comment-children-list-container"],this.root);return new FG({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});g(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));p(ls,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{ot(i,aw)});const r=e[e.length-1];z(r,aw)});g(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),r=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');p(ls,e,"switchUpButton not exist"),p(ls,r,"switchDownButton not exist"),ot(r,"disabled"),ot(e,"disabled"),this.root.previousElementSibling===null&&z(e,"disabled"),this.root.nextElementSibling===null&&z(r,"disabled")});g(this,"handleReadonlyChanged",e=>{e.readonly?z(this.root,"readonly"):ot(this.root,"readonly")});g(this,"getCommentEditor",()=>this.mainItem.getCommentEditor());g(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=r,this.comment=i,this.groupList=o,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new Ss(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return uw(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,o=new $G(e,r,i,this);return this.root.append(o.root),o}createHeader(){const{comment:e}=this,r=B("div",["comment-item-head"],this.root),i=B("span",["item-head-quote"],r);i.innerText=e.abstract;const o=B("span",["item-head-switch"],r),s=cl(o,Jt.SwitchUp,"up",KG),l=cl(o,Jt.SwitchDown,"down",VG);return ho(s,Jt.SwitchUp),ho(l,Jt.SwitchDown),r}createItem(){const e=B("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:o,groupList:s}=this,l=new bw({mainEditor:r,commentsProvider:i,comment:o,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(r=>r.comment.id===e):null}handleCreateComment(e){return p(ls,ec(e),"invalid comment, not a child comment"),p(ls,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){const r=this.childrenList.findItem(e.id);if(!r){ls.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(ls,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(ls,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const jG=I("arrange=items"),Bw=20;function Tw(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return-1;const r=n.scrollContainer.getBoundingClientRect(),i=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-r.top+i}function yw(n,t){return Number.parseInt(t.root.style.top,10)}function kw(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let o=i;o<t.length;o++){const s=t[o],l=s.comment,c=Tw(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),o===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else s.root.style.top=`${c}px`;continue}const d=t[o-1],h=yw(n,d)+d.root.getBoundingClientRect().height;h>c?s.root.style.top=`${h+Bw}px`:s.root.style.top=`${c}px`}for(let o=i-1;o>=0;o--){const s=t[o],l=s.comment,c=Tw(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const d=s.root.getBoundingClientRect(),h=c+d.height,C=t[o+1];p(jG,C,"no next item");const E=yw(n,C);E<h?s.root.style.top=`${E-d.height-Bw}px`:s.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const H0=I("comment-group-item-handler");class zG{constructor(t,e){g(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});g(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});g(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});g(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});g(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});g(this,"handleCommentItemReply",(t,e)=>{const r=t.findCommentItem(e);p(H0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:o}=r,s=i.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:J(),box:!0,created:Date.now(),text:o.displayName,iconUrl:o.avatarUrl,mentionId:o.userId};s.editor.insertBoxToBlock(l,0,c)});g(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});g(this,"handleCommentItemOk",(t,e)=>{const r=t.findCommentItem(e);p(H0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:o,getCommentEditor:s}=r,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(o,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(H0,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let o=!1;if((c=i.blocks)!=null&&c.length||(o=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];o=!!h.text&&fn(h.text)===0}if(o){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:s}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),s.show()});g(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItemAsGroupId(t.comment.groupId);if(!e)return;const{quickReply:r}=e;t.getCommentEditor().edit(),r.hide()});g(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItemAsGroupId(t.comment.groupId);if(!e)return;const{quickReply:r}=e,{comment:i}=t;this.commentsProvider.localDeleteComment(i.id),r.show()});g(this,"execute",(t,e,r,i)=>{const o=kG(t);if(!o||wG(o))return;const s=RG(o);switch(s){case Jt.SwitchUp:this.handleSwitchUp(i);break;case Jt.SwitchDown:this.handleSwitchDown(i);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,r);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,r);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,r);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;H0.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const j0=I("comment-group-list");class GG extends ff{constructor(e,r,i){super(e,r,i,ss(e,r),{});g(this,"groupItemHandlers");g(this,"closeEditing",e=>{const r=this.items.find(i=>i.comment.id===e);r&&([r,...r.childrenList.items].forEach(i=>{!i.getCommentEditor().editor.readonly&&i.getCommentEditor().isEmpty()&&this.groupItemHandlers.handleCommentItemCancel(r,i.comment.id)}),r.quickReply.getReplyEditor().isEmpty()&&r.quickReply.cancel())});g(this,"setFirstEditingCommentActive",()=>{const e=this.findFirstEditingComment();e!==-1&&this.setActiveItem(e)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const r=e.target.closest(".comment-group-item-root");if(!r)return;const i=yG(e.target),o=this.items.findIndex(s=>s.root===r);if(o!==-1){this.activeIndex!==o&&this.setActiveItem(o);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[o],i,o)}});g(this,"handleDocumentClick",e=>{if(!e.target||!(e.target instanceof Element)||e.target.closest(".comment-group-item-root.active"))return;const i=this.items[this.activeIndex];!i||[i.findCommentItem(i.comment.id),...i.childrenList.items].some(s=>{var c;const l=(c=s==null?void 0:s.moreMenu.tippyInstance)==null?void 0:c.popper;return!!(l!=null&&l.contains(e.target))})||i!=null&&i.comment&&setTimeout(()=>{this.closeEditing(i.comment.id)})});g(this,"handleSelectionChanged",()=>{setTimeout(()=>{var r;const e=pw(this.editor);if(e.length>0){if(((r=this.activeItem)==null?void 0:r.comment.id)&&e.includes(this.activeItem.comment.id))return;const i=e[0],o=this.items.findIndex(s=>s.comment.groupId===i);this.setActiveItem(o),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});g(this,"handleEditorResize",()=>{this.updateItemsLayout()});g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"handleItemResize",()=>{this.updateItemsLayout()});g(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const r=document.elementFromPoint(e.clientX,e.clientY);if(!r||!(r instanceof HTMLElement)||!this.editor.scrollContainer.contains(r))return;const i=this.container.querySelector(".comment-group-item-root");if(!i)return;const o=Number.parseFloat(i.style.top),s=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(o)&&!Number.isNaN(s)&&o<s&&kw(this.editor,this.items,null,Math.min(o+(0-e.deltaY)*3,s))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(j0,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Ke.default(()=>{const e=ss(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const o=e[i];if(!this.findGroupItem(o.groupId)){this.handleCreateComment(o,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const o=this.items[i];e.findIndex(s=>s.groupId===o.comment.groupId)===-1&&(this.deleteItem(o.comment.id),r=!0)}r&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(o=>o.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new zG(this,r),document.addEventListener("click",this.handleDocumentClick)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners(),document.removeEventListener("click",this.handleDocumentClick)}updateItemsLayout(){kw(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,r){const i=new HG(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{ot(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=ss(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}insertItem(e,r){const i=super.insertItem(e);return i?(r!=null&&r.active&&this.setActiveItem(this.items.indexOf(i)),this.updateItemsLayout(),i.addListener("resize",this.handleItemResize),i):null}findFirstEditingComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if((!i.quickReply.getReplyEditor().isEmpty()||e)&&!i.quickReply.getReplyEditor().editor.readonly)return r;const o=[i,...i.childrenList.items];for(let s=0;s<o.length;s++){const l=o[s];if(!l.getCommentEditor().editor.readonly&&(!l.getCommentEditor().isEmpty()||e))return r}}return-1}isEditing(){return this.findFirstEditingComment()!==-1}setActiveItem(e,r){if(p(j0,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const i=this.container.querySelector(".comment-group-item-root.active");if(i){const o=this.items[this.activeIndex];setTimeout(()=>{this.closeEditing(o.comment.id)}),ot(i,"active")}if(e!==-1){const o=this.items[e];z(o.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,r)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(r=>r.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,r){if(ec(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(j0,!i,"comment group item has already exists");const o={children:[],...e};p(j0,o.children,"not a comment group");const s=this.insertItem(o,{active:r});if(!!s&&r){const l=this.items.indexOf(s);this.setActiveItem(l),s.quickReply.hide(),setTimeout(()=>{s.edit()},300)}}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?(this.deleteItem(i.comment.id),this.updateItemsLayout()):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&(this.deleteItem(i.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){const r=this.findItemAsGroupId(e.groupId);if(r&&r.comment.id!==e.id){r.handleUpdateChildComment(e);return}const i=this.findItem(e.id);i&&i.handleUpdateMainComment(e)}}const WG="comment-mini";I("comment-list");class qG extends ye.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"groupsContainer");g(this,"list");g(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});g(this,"updateCommentCount",()=>{var r,i;const e=IG(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var o,s;const i=this.list.activeItem;Ew(this.editor,(s=(o=i==null?void 0:i.comment)==null?void 0:o.groupId)!=null?s:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=Rt(this.root,WG);(i=(r=this.commentOptions)==null?void 0:r.onUpdateLayout)==null||i.call(r,this.editor,{expand:e})});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-web-comment-root"],null),this.groupsContainer=B("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r),this.updateCommentCount()}onDeleteComment(e,r){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}createList(){return new GG(this.editor,this.commentsProvider,this.groupsContainer)}isEditing(){return this.list.isEditing()}setFirstEditingCommentActive(){this.list.setFirstEditingCommentActive()}show(e){var r;if(ot(this.root,"hidden"),e){const i=this.list.findItemIndex(e);this.list.setActiveItem(i)}(r=this.commentOptions)==null||r.controller.showCommentList()}hide(){z(this.root,"hidden")}}class XG extends ff{constructor({editor:t,parent:e,commentsProvider:r,comments:i}){super(t,r,e,i,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:r}=this;return new vw(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const z0=I("mobile-comment-group-item"),QG=20;class YG extends ye.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>B("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=new vw(r,i,o);return e.append(s.root),s});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=B("div",["mobile-comment-children-list-container"],e);return new XG({editor:r,commentsProvider:i,comments:o.children,parent:s})});g(this,"handleTouchEnd",()=>{var o;const{scroller:e}=this,{pullThreshold:r=QG}=(o=this.editor.getComponentOptions("comment"))!=null?o:{};let i=null;if(e.y>e.minScrollY+r?(i=this.root.previousElementSibling,i||this.emit("onReachTop")):e.y<e.maxScrollY-r&&(i=this.root.nextElementSibling,i||this.emit("onReachBottom")),i){const s=i.id;this.emit("onSwitchGroup",s,cw)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=B("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const o=B("div",["mobile-group-item"],this.root),s=B("div",["mobile-group-item-space"],null),l=B("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=B("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),o.append(s,l,c),this.scroller=new Qx.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return uw(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(z0,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){z0.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(z0,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(z0,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const kE=I("mobile-group-list");class ZG extends ff{constructor(e,r,i,o){super(e,r,i,ss(e,r),{});g(this,"scroller");g(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});g(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const r=this.findItemIndex(e);let i=null;return r===0?i=this.items[r+1].root.id:i=this.items[r-1].root.id,super.deleteItem(e)?(this.scrollToGroup(i,cw),!0):!1});g(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});g(this,"handleReachBottom",()=>{this.emit("onReachBottom")});g(this,"handleReachTop",()=>{this.emit("onReachTop")});g(this,"scrollToGroup",(e,r=0)=>{const i=this.findGroupItem(e);p(kE,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),Ew(this.editor,i.comment.groupId)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"updateComments",Ke.default(()=>{const e=ss(this.editor,this.commentsProvider);for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1);continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(o=>o.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new Qx.default(o),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new YG(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=ss(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(ec(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const i=this.findItem(e.id);p(kE,!i,"comment group item has already exists");const o={children:[],...e};p(kE,o.children,"not a comment group"),this.insertItem(o),this.scroller.refresh()}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?this.deleteItem(i.comment.id):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&this.deleteItem(i.comment.id);return}}}handleUpdateComment(e){if(ec(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const JG=I("mobile-comment-list"),{t:Rw}=D;class tW extends ye.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"list");g(this,"mask");g(this,"pullInfoContainer");g(this,"handleRootClick",e=>{const r=e.target;p(JG,r instanceof Element,"invalid target"),!(r.closest(".mobile-group-item-abstract")||r.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});g(this,"hidePullInfo",Ke.default(()=>{ot(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;ot(this.root,"hidden"),z(document.documentElement,"disabled-scroll"),(r=this.commentOptions)==null||r.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});g(this,"hide",()=>{z(this.root,"hidden"),ot(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mobile-comments-root"],null),this.mask=B("div",["mobile-comment-mask"],this.root);const i=B("div",["mobile-comment-groups-container"],this.root),o=B("div",["mobile-comment-groups-scroll-container"],i);this.list=new ZG(this.editor,this.commentsProvider,o,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=B("div",["mobile-comment-pull-info-container"],this.root);return B("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=Rw(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=r,z(this.pullInfoContainer,"active"),this.hidePullInfo()}isEditing(){return!1}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function ww(n,t){const e=ss(n,t),r=new Map;for(const i of e){const o=fw(n,i.groupId);if(!!o)if(r.has(o)){const s=r.get(o);gw(i).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=gw(i),l=new Set(s.map(c=>c.id));r.set(o,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,o])=>({blockId:i,...o}))}const eW=I("mini-group-item");class nW{constructor(t,e){g(this,"root");g(this,"blockId");g(this,"comment");g(this,"miniCommentItem");g(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=B("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new PG(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return fw(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);p(eW,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class rW extends ff{constructor(e,r,i){super(e,r,i,ww(e,r),{});g(this,"fixListOps",Ke.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));g(this,"handleDocChanged",Ke.default(()=>{this.updateMiniCommentsGroup()},100));g(this,"updateMiniCommentsGroup",()=>{const e=ww(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=r,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new nW(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,r){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const iW=I("mini-comments-list");class oW extends ye.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=B("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new rW(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(iW,i instanceof HTMLElement,"The target is not a valid html element");const o=i.closest(".mini-comment-item");o&&this.emit("onItemClick",o.id)});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){}show(){ot(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function Sw(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const r=t.block,i=ve(n,r,t.start.offset,t.end.offset),o=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;yB(n,r,i,o,s)}function sW(n,t,e){const r=fi(n).map(s=>s.block),i=AE(n,r),o=V0({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{fi(n,{simpleBlockOnly:!0}).forEach(c=>{!et(n,c.block)||Sw(n,c,o)});const l=eo();e.localCreateComment(o,l)}),o}class lW{constructor(t,e){g(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,r){const i=t.selection.range;if(et(t,e)&&!r.isCollapsed()&&i.isSimple()){const o=st(e),s=It(e),l=Ir(t,e);return[{id:"add-comment",name:D.t("comment.command"),blockId:o,blockType:s,blockKind:l,groupIndex:1e3,icon:el}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,r,i,o){if(r.id==="add-comment"){this.editorComments.showCommentList();const s=sW(t,e,this.provider);return o["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class Lw{constructor(t,e){g(this,"commentList",null);g(this,"mobileCommentList",null);g(this,"miniCommentList");g(this,"showComment",(t,e)=>{var r,i;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((r=this.mobileCommentList)==null||r.show(e)),t==="web"&&((i=this.commentList)==null||i.show(e))});g(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});g(this,"handleCommentListClose",()=>{this.showComment("mini")});g(this,"handleOnSelectComment",()=>{this.showComment("web")});g(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new lW(e,this)),t.blockHooks.push(new vG(this.provider,this)),this.isMobile?(this.mobileCommentList=new tW(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new qG(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new oW(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new BG)}get commentProvider(){return this.provider}get isMobile(){return he.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}setFirstEditingCommentActive(){var t;(t=this.commentList)==null||t.setFirstEditingCommentActive()}isEditing(){var t,e;return((t=this.commentList)==null?void 0:t.isEditing())||((e=this.mobileCommentList)==null?void 0:e.isEditing())||!1}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const alt="",aW={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u5B9A",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u6DFB\u52A0\u6279\u6CE8\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},cW={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotation or mention someone",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},uW={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u5B9A",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0\u3059\u308B\u304B\u30E1\u30F3\u30D0\u30FC\u3092\u30E1\u30F3\u30B7\u30E7\u30F3",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};D.mergeLang({"zh-CN":aW,"en-US":cW,"ja-JP":uW});class Iw{renderText(t,e,r){const i=[],o={};return Object.entries(r).forEach(([s,l])=>{s.startsWith("comment-")&&(i.push("comment"),o[s]=l)}),{classes:i,attributes:o}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const o=["comment"],s={};return i.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:o,attributes:s}}updateBlock(t,e,r,i){const o=i.comments;ot(r,"comment"),Array.from(r.attributes).forEach(s=>{s.name.startsWith("comment-")&&r.removeAttribute(s.name)}),!(!o||o.length===0)&&(z(r,"comment"),o.forEach(s=>{r.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class fW{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,o)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Gu(t,e,D.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function dW(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const s=new Set(i);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const o=r.text;if(!!o&&et(n,t)){const s=Xg(o,`comment-${e.toLocaleLowerCase()}`,e);Pc.default(o,s)||n.setBlockText(t,s)}}const hW=I("editor-comment");function mW(n){const t=n.getCustom("editor-comments");if(p(hW,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Ko(s);if(l.length>=2){const{containerId:c}=l[l.length-1],d=nt(ci(n,c));if(d&&It(d)==="code"){xE(n,d,t.commentProvider);return}}xE(n,s,t.commentProvider);return}const e=fi(n,{simpleBlockOnly:!0}),r=e.map(s=>s.block),i=AE(n,r),o=V0({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{et(n,l.block)?Sw(n,l,o):lw(n,l.block,o)});const s=eo();t.commentProvider.localCreateComment(o,s)})}const RE=I("text-styles");function gW(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([o])=>!!o.startsWith("style-"));return new Map(i)};if(n.length===0)return new Map;let e=t(n[0]);for(let r=1;r<n.length;r++){const i=t(n[r]);e=new Map(Array.from(e.entries()).filter(([o,s])=>i.get(o)===s))}return e}function pW(n,t,e,r,i){p(RE,e.isSimple(),"invalid range");const{start:o,end:s}=e;p(RE,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(RE,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=fa(o.offset,s.offset-o.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=fa(o.offset,s.offset-o.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=fa(o.offset,s.offset-o.offset,c,r,void 0,{ignoreValue:!0}):c=nu(o.offset,s.offset-o.offset,c,r,i),n.setBlockText(t,c),c}const dl=I("text-commands");function Dw(n){const t={id:"more",name:D.t("commands.more"),icon:Cp,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[D.t("commands.bold"),fr("CtrlOrCmd+B"),pT],"style-italic":[D.t("commands.italic"),fr("CtrlOrCmd+I"),CT],"style-underline":[D.t("commands.underline"),fr("CtrlOrCmd+U"),ET],"style-strikethrough":[D.t("commands.strikethrough"),fr("CtrlOrCmd+D"),AT],"style-code":[D.t("commands.code"),void 0,xT]},r={"style-super":[D.t("commands.superscript"),void 0,vT],"style-sub":[D.t("commands.subscript"),void 0,bT]};if(fn(n)===0){const l=Object.entries(e).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h}));return t.children=Object.entries(r).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h})),l.concat(t)}const i=gW(n);function o([l,[c,d,h]]){const C=i.get(l);return C!==void 0?{id:l,name:c,value:C,states:C===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:c,icon:h,desc:d}}const s=Object.entries(e).map(o);return t.children=Object.entries(r).map(o),s.concat(t)}function CW(n,t){const e=st(t),r=It(t),i=Ir(n,t);return Dw([]).map(o=>({blockId:e,blockType:r,blockKind:i,...o,groupIndex:500}))}function EW(n,t,e){p(dl,e.isSimple(),"nor a simple range");const{start:r,end:i}=e;p(dl,r.isSimple(),"is not a simple block position"),p(dl,i.isSimple(),"is not a simple block position"),p(dl,et(n,t),"invalid block type, not a text kind block");const o=st(t);p(dl,r.blockId===o&&i.blockId===o,"invalid range");const s=n.getBlockText(t);let l=[];r.offset===i.offset?r.offset!==0&&(l=qe(s,r.offset-1,1).middle):l=qe(s,r.offset,i.offset-r.offset).middle;const c=It(t),d=Ir(n,t);return Dw(l).map((h,C)=>({blockId:o,blockType:c,blockKind:d,...h,groupIndex:500,order:C*100}))}function AW(n,t,e,r,i,o){if(!et(n,t))return!1;if(!r.startsWith("style-"))return dl.warn(`unknown command: ${r}`),!1;const s=i==null?void 0:i.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return dl.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const c=pW(n,t,e,r,s);return o.result=c,!0}const xW=I("text-command-provider");class Ri{constructor(t){g(this,"id","TextCommandProvider");g(this,"emptyTextBlockAttributes",new Map);g(this,"colorItem");g(this,"updateButtonColor",t=>{const e=wB(this.editor,t,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(e)});g(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")kB(this.editor,t,e,this.setEmptyTextBlockColor);else{const r=["clearAll","clearColor","clearBackground"];RB(this.editor,r[e],this.setEmptyTextBlockColor)}this.colorItem.setLatestColors(t,e)});g(this,"getEmptyTextBlockColor",(t,e)=>{const r=this.getEmptyBlockTextAttributes(t,e);return Qg(r)});g(this,"setEmptyTextBlockColor",(t,e,r,i)=>{var s;const o=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};A3(o,r,i),this.emptyTextBlockAttributes.set(e,o)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new KT(t)),this.colorItem.addListener("onClick",this.handleChangeColor)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,r){if(!et(t,e))return[];let i;dt(t,e)===0?i=this.getCommandsOnEmptyText(t,e).map(Ri.toTextCommand):i=EW(t,e,r).map(Ri.toTextCommand),this.updateButtonColor(r);const s={...this.colorItem,blockId:st(e),blockKind:Ir(t,e),blockType:It(e),groupIndex:500,order:350};return i.push(s),i}executeCommand(t,e,r,i,o,s){if(!et(t,e))return!1;let l=o.value;l===void 0&&(l=!i.value);const c=Ri.fromTextCommandId(i.id);if(c.startsWith("style-")){if(c==="style-font")return this.handleChangeColor(o.type,l),!0;if(dt(t,e)===0)return this.executeCommandOnEmptyText(e,i,{value:l})}return AW(t,e,r,c,{value:l},s)}executeCommandOnEmptyText(t,e,r){let i=this.emptyTextBlockAttributes.get(st(t));i||(i={},this.emptyTextBlockAttributes.set(st(t),i));const o=Ri.fromTextCommandId(e.id),s=r.value;return s==null||s===!1?(delete i[o],!0):(i[o]=r.value,!0)}getCommandsOnEmptyText(t,e){const r=CW(t,e);return this.setCommandsStates(r,e)}setCommandsStates(t,e){var o;const r=st(e),i=(o=this.emptyTextBlockAttributes.get(r))!=null?o:{};return t.map(s=>{const l=i[s.id],c=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:c}})}getEmptyBlockTextAttributes(t,e){var i;const r=gt.default((i=this.emptyTextBlockAttributes.get(e))!=null?i:{});if(Array.from(Object.entries(r)).forEach(([o,s])=>{s||delete r[o]}),Object.keys(r).length!==0)return r}static toTextCommand(t){return t.children&&(t.children=t.children.map(Ri.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return p(xW,t.startsWith(e),`invalid item id: ${t}`),t.substring(e.length)}static fromTextCommand(t){return{...t,id:this.fromTextCommandId(t.id)}}static toTextCommands(t){return t.map(Ri.toTextCommand)}static fromTextCommands(t){return t.map(Ri.fromTextCommand)}}function _w(n){const t=n.findCustom("toolbar-handler");t==null||t.disableTextToolbar(),t==null||t.hide(),setTimeout(()=>{t==null||t.enableTextToolbar()},300)}function bW(n){n.undoManager.canUndo()&&_w(n)}function vW(n){n.undoManager.canRedo()&&_w(n)}const BW={"CtrlOrCmd+Z":bW,"CtrlOrCmd+Shift+Z":vW},TW={commands:{bold:"\u7C97\u4F53",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strikethrough:"\u5220\u9664\u7EBF",code:"\u884C\u5185\u4EE3\u7801",subscript:"\u4E0B\u6807",superscript:"\u4E0A\u6807",more:"\u66F4\u591A"}},yW={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},kW={commands:{bold:"\u592A\u5B57",italic:"\u659C\u4F53",underline:"\u4E0B\u7DDA",strikethrough:"\u53D6\u308A\u6D88\u3057\u7DDA",code:"\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",subscript:"\u4E0B\u4ED8\u304D\u6587\u5B57",superscript:"\u4E0A\u4ED8\u304D\u6587\u5B57",more:"\u305D\u306E\u4ED6"}};D.mergeLang({"zh-CN":TW,"en-US":yW,"ja-JP":kW});const RW={embedProperties:{edit:"\u7F16\u8F91",addComment:"\u6DFB\u52A0\u6279\u6CE8"}},wW={embedProperties:{edit:"Edit",addComment:"Add annotation"}},SW={embedProperties:{edit:"\u7DE8\u96C6",addComment:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0"}};D.mergeLang({"zh-CN":RW,"en-US":wW,"ja-JP":SW});const Mw=I("embed-block-properties");function df(n,t){var e;for(const r of n.blockHooks){const i=(e=r.commands)==null?void 0:e.call(r,n,t);if(!!i&&i.group==="block-comment-actions")return i.executeCommand(n,t,i.commands[0]),!0}return!1}class wE{constructor(t,e,r){g(this,"group","hovering-toolbar");g(this,"_commands",[{id:"edit",name:D.t("embedProperties.edit"),icon:jh},{id:"add-comment",name:D.t("embedProperties.addComment"),icon:el}]);this.editor=t,this.block=e,this.properties=r}get commands(){var i,o,s;if(this.editor.readonly)return[];let t=this._commands;const{enableComments:e=!0}=this.editor.options;e||(t=t.filter(l=>l.id!=="add-comment")),t.forEach(l=>{(l.id==="add-comment"||l.id==="edit")&&(l.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});let r=(i=this.properties)!=null&&i.presetIds?t.filter(l=>{var c,d;return(d=(c=this.properties)==null?void 0:c.presetIds)==null?void 0:d.includes(l.id)}):[...t];return(s=(o=this.properties)==null?void 0:o.extCommands)!=null&&s.length&&(r.length&&r.push({id:J(),type:"separator",name:""}),r.push(...this.properties.extCommands)),r.length<=3&&(r=r.filter(l=>l.id!=="separator")),r}executeCommand(t,e,r){var i,o;if(!((o=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&o.call(i,t,e,r))){if(r.id==="add-comment"){df(t,e)||Mw.error("failed to add comment to block");return}Mw.error(`unknown command: ${JSON.stringify(r)}`)}}}function SE(n,t,e){return{blockCommands:{"hovering-toolbar":new wE(n,t,e)}}}class hf{constructor(t){g(this,"blockResizer");g(this,"handleResizing",(t,e)=>{var i,o;const r=t.getBlock();if(r){if(((o=(i=Zt(this.editor,r)).notify)==null?void 0:o.call(i,this.editor,"resize",{block:r,rect:e}))===!0)return;const s=Math.max(e.height,100),d={...this.editor.getBlockData(r).embedData,height:s};this.editor.updateEmbedData(r,d)}});g(this,"handleHoveringBlockChange",(t,e)=>{e&&Re(e)&&Rt(e,"resizable")&&this.disableResizer(),t&&Re(t)&&Rt(t,"resizable")&&this.editor.isBlockWritable(t)&&this.tryEnableResizer(t)});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange),this.blockResizer=new qu(this.editor,{resize:["bottom"]}),this.blockResizer.addListener("resizing",this.handleResizing)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}tryEnableResizer(t){this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}static get(t){return t.addCustom("EmbedBlockResizer",()=>new hf(t))}static register(t,e){return z(e,"resizable"),t.addCustom("EmbedBlockResizer",()=>new hf(t))}}var Uw=(n=>(n.Card="card",n.Preview="preview",n))(Uw||{});const LW=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
732
732
|
<path d="M6.49669 1C4.80282 1 3.0118 2.3515 3.0118 3.76237L3 10.6206M6.49669 1C8.41943 1 10.0154 2.60058 10.0154 4.17342M6.49669 1C7.43289 1 8.28684 1.42118 8.90405 1.96796C9.50746 2.50252 10.0154 3.29036 10.0154 4.17342M10.0154 4.17342L10.0154 9.61446C10.0154 10.4166 9.23033 11.2316 8 11.2316C6.91283 11.2316 6.01026 10.5735 6.01026 9.87981L5.98457 5.04102M3 10.6206C3 13.1126 5.38055 15 8 15M3 10.6206C3 12.9301 5.13252 15 8 15M8 15C10.6194 15 13 13.1988 13 10.7068M8 15C10.8675 15 13 13.0162 13 10.7068M13 10.7068V5.04102" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"/>
|
|
733
733
|
<path d="M13 4V10C13 12.7614 10.7614 15 8 15C5.23858 15 3 12.7614 3 10V4.5" stroke="currentColor"/>
|
|
734
734
|
<path d="M10 9V4.5C10 2.567 8.433 1 6.5 1C4.567 1 3 2.567 3 4.5" stroke="currentColor"/>
|
|
@@ -955,4 +955,4 @@ ${o.mermaidText}
|
|
|
955
955
|
${o.flowchartText}
|
|
956
956
|
\`\`\`\`\`\``}return""}const CY={embedType:"flowchart",convertFrom:mY,handleUpdateBlock:hY,createEmbedContent:dY,getBlockProperties:gY,convertTo:pY},EY=I("plantuml-helper");function M4(n,t){var l;let r=((l=(n.getComponentOptions("plantuml")||{}).cdn)==null?void 0:l.plantuml)||XQ;r.endsWith("/")||(r+="/");const i=h6.default.encode(t);p(EY,i,i),r+=i;const s=new URLSearchParams(document.location.search).get("doc");return bg(r,{id:`${s}-${J()}`})}async function AY(n,t){try{const e=await $E(n,t);return(await n.doc.uploadResource(e)).resourceId}catch{return Promise.resolve(t)}}class cc extends GE{constructor(t){super(t,"plantuml","plantumlText")}static get(t,e){return t.addCustom(`plantuml-${e.id}`,()=>new cc(t))}code2ObjectUrl(t){return Promise.resolve(M4(this.editor,t))}code2ResourceId(t){const e=M4(this.editor,t);return AY(this.editor,e)}destroy(){}}function xY(n,t,e){cc.get(n,e).createEmbedContent(t,e)}function bY(n,t,e){const r=cc.get(n,e),i=Ot(t);return r.updateEmbedContent(i,e),!0}function vY(n,t,e){const{data:r}=e,i=n.getBlockString(t).trim();if(!r||r.embedType!=="plantuml"||i!=="```plantuml"||!et(n,t))return null;const o={src:"",plantumlText:""};return{blockData:{id:J(),type:"embed",embedType:"plantuml",embedData:o},onConverted:(c,d)=>{cc.get(c,c.getBlockData(d)).editGraph(Ot(d))}}}function BY(n,t){return cc.get(n,n.getBlockData(t)).getBlockProperties(t)}function TY(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`})`;if(o.flowchartText)return`\`\`\`plantuml\`\`\`
|
|
957
957
|
${o.flowchartText}
|
|
958
|
-
\`\`\`\`\`\``}return""}const yY={embedType:"plantuml",convertFrom:vY,handleUpdateBlock:bY,createEmbedContent:xY,getBlockProperties:BY,convertTo:TY},Rlt="",kY="hr",RY={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},wY={dividingLine:{type:"Dividing-Line",abstract:"Dividing-Line"}},SY={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};D.mergeLang({"zh-CN":RY,"en-US":wY,"ja-JP":SY});function LY(n,t){const e=B("div",["editor-embed-container"],t);B("hr",["editor-embed-hr"],e)}function IY(n,t,e,r){return r==="html"?"<hr />":r==="markdown"?"---":"------------"}function DY(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:D.t("dividingLine.type"),icon:nT,order:500,group:"common",subText:Bn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:r}=t;return n.insertEmbed(e,r,kY,{})}}}function _Y(n,t,e){const{data:r}=e;if(!r||r.embedType!=="dividing-line"||!et(n,t))return null;const i={};return{blockData:{id:J(),type:"embed",embedType:"hr",embedData:i}}}function MY(){return{abstract:D.t("dividingLine.abstract")}}const UY={embedType:"hr",createEmbedContent:LY,convertTo:IY,getOptions:DY,convertFrom:_Y,getBlockProperties:MY},wlt="",Slt="",OY={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"}}},NY={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"}}},PY={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"}}};D.mergeLang({"zh-CN":OY,"en-US":NY,"ja-JP":PY});var Qr=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(Qr||{}),pf=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(pf||{});const U4=10*1024*1024,FY=["wav","mp3","aac","ogg","webm","flac"],KY=["ogg","mp4","webm"],VY=()=>{};function O4(n){var h,C,E,x,v,R;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:FY,s=(E=e==null?void 0:e.video)!=null?E:KY,l=(x=r==null?void 0:r.audio)!=null?x:U4,c=(v=r==null?void 0:r.video)!=null?v:U4,d=(R=i==null?void 0:i.onError)!=null?R:VY;return{allowedMedias:{audio:o,video:s},maxSize:{audio:l,video:c},callbacks:{onError:d}}}function $Y(n,t){const e=o=>o.map(s=>`.${s}`).join(","),{allowedMedias:r}=O4(n),i=r[t];return i?e(i):"*"}function HY(n,t,e){const{maxSize:r,callbacks:i,allowedMedias:o}=O4(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=zc(n.name);if(l&&!l.includes(rn.exports.lowerCase(c))){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 jY(n){return n===pf.Empty||n===pf.Error}const Qe=I("media");class zY extends ye.TypedEmitter{constructor(e){super();g(this,"mediaContainer",null);g(this,"media",null);g(this,"abstract",null);g(this,"handleMediaLoadError",(e,r)=>{if(!r.target||!(r.target instanceof Node)||!(r.target instanceof Element?r.target:r.target.parentElement))return;const o=nt(r.target);if(!o||!o.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",st(o))});g(this,"handleUploadFile",async e=>{p(Qe,this.abstract,"no abstract"),p(Qe,this.mediaContainer,"The media element not exist");const{editor:r}=this.options,i=nt(this.mediaContainer);p(Qe,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){Qe.error(s),this.emit("mediaError",r,"upload_error",o.id),this.renderRetry(e,s)}ot(i,"media-block-uploading")});g(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(Qe,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){p(Qe,this.abstract,"no abstract");const{editor:e,createMediaElement:r}=this.options,{mediaIcon:i,mediaName:o}=this.abstract;p(Qe,this.mediaContainer,"The media element not exist");const s=nt(this.mediaContainer);p(Qe,s,"The block element not exist");const l=e.getBlockData(s),c=l.embedData.src,d=B("div",["media-error","embed-selected-content","embed-hover-content"],null),h=B("span",["media-error-icon"],d);h.innerHTML=i;const C=B("div",[],d);C.innerHTML=D.t("media.load.failed",{name:o}),d.appendChild(C);const E=C.querySelector(".retry-upload");return p(Qe,E,"The element not exist"),e.domEvents.addEventListener(E,"click",(x,v)=>{const R=B("div",["media-element"],null),L=this.getResourceUrl(c),M=r(x,R,l,L);this.unbindMediaEvent(),this.media=M,this.bindMediaEvent(),this.updateMediaContent(R)}),this.setFullScreen(),d}renderRetry(e,r){var E,x;p(Qe,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=D.t("media.upload.failed",{name:s});(((E=r.response)==null?void 0:E.status)===420||((x=r.response)==null?void 0:x.status)===413)&&(h=D.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(Qe,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(l),this.setFullScreen()}renderProgress(e,r){p(Qe,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=nt(this.mediaContainer);p(Qe,l,"The element not exist"),z(l,"media-block-uploading");const c=B("div",["media-progress"],null);s(c,o,r),this.updateMediaContent(c)}this.setFullScreen()}renderMediaElement(e){p(Qe,this.mediaContainer,"The media element not exist");const r=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:i,updateMediaElement:o,editor:s}=this.options,l=this.getResourceUrl(e.embedData.src);if(r){const c=o(s,r,e,l);this.unbindMediaEvent(),this.media=c,this.bindMediaEvent()}else{const c=B("div",["media-element"],null),d=i(s,c,e,l);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent(),this.updateMediaContent(c)}}renderEmpty(e){p(Qe,this.abstract,"no abstract"),p(Qe,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){const{editor:r}=this.options;return r.doc.buildResourceUrl(e)}setFullScreen(){p(Qe,this.mediaContainer,"The media element not exist"),z(this.mediaContainer,"full-screen")}removeFullScreen(){p(Qe,this.mediaContainer,"The media element not exist"),ot(this.mediaContainer,"full-screen")}updateBlockAlign(e,r){const i=nt(r);p(Qe,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),jY(i)?i===pf.Empty&&this.renderEmpty(e):this.renderMediaElement(e)}setAbstract(e){this.abstract=e}}I("media-embed");const GY="left";class N4{constructor(){g(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=$Y(t,this.embedType);if(o=o!=null?o:await oa(s,{}),!o)return null;const{mediaType:l}=this.getAbstract();try{HY(o,t,l)}catch{return null}const c={id:J(),type:"embed",embedType:this.embedType,embedData:{src:pf.Empty}};l==="video"&&(c.align=GY);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 zY({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:Bn(`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=Ot(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"?``:s}}function P4(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 F4(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const WY=I("media-audio");class qY extends N4{constructor(){super(...arguments);g(this,"embedType",Qr.AUDIO);g(this,"updateProgressElement",F4);g(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:J2,mediaName:D.t(`media.${Qr.AUDIO}.menuItem`),menuItem:D.t(`media.${Qr.AUDIO}.menuItem`),order:800,mediaType:Qr.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${Qr.AUDIO}.abstract`)}`}}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .audio-container > audio");return p(WY,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",P4(e,r)}}const XY=new qY;I("video-resizer");function K4(n){return n&&Re(n)&&un(n)==="video"}const QY=50;class WE{constructor(t){g(this,"currentResizableElement",null);g(this,"resizing",!1);g(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&K4(e)&&this.disableBlockResize(e),t&&K4(t)&&this.editor.isBlockWritable(t))){const r=this.getVideoElement(t);if(!r)return;this.enableBlockResize(t,r)}});g(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,QY),i);this.currentResizableElement.style.width=`${o}px`,this.currentResizableElement.style.pointerEvents="none"});g(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,be.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Ot(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${st(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${st(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const r=this.editor.addCustom(`${st(t)}-resizer`,()=>new qu(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 YY=I("video");class ZY extends N4{constructor(){super(...arguments);g(this,"embedType",Qr.VIDEO);g(this,"updateProgressElement",F4);g(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 WE(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});g(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,P4(e,r),ia(i).then(s=>{const l=e.querySelector(".progress-video");l&&_g(e)&&(l.src=s)})})}getAbstract(){return{mediaName:D.t(`media.${Qr.VIDEO}.menuItem`),mediaIcon:tT,menuItem:D.t(`media.${Qr.VIDEO}.menuItem`),order:700,mediaType:Qr.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${Qr.VIDEO}.abstract`)}`}}handleMediaError(e,r,i){const o=e.addCustom("video-resizer",()=>new WE(e)),s=e.getBlockById(i);o.disableBlockResize(s)}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .video-container > video");p(YY,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 WE(e)).updateResizer(l)}),s}}const JY=new ZY,V4=[MC,HC,jC,Hy],qE=[L4,tQ,aY,CY,yY,IF,UY,JY,XY,Mj,d4,JW],$4=[nk,g4,Fw,ok];function tZ(n,t,e){var i,o,s,l;si.level=(i=e.logLevel)!=null?i:ws.DEBUG;const r=hu(n,t,{components:{blocks:[...V4,...((o=e==null?void 0:e.components)==null?void 0:o.blocks)||[]],embeds:[...qE,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[...$4,...((l=e.components)==null?void 0:l.boxes)||[]],textRenders:[new gC],options:{...e.componentsOptions}}});return r.readonly=!0,r.addCustom("heading-collapse",()=>new UE(r)),r.addCustom("editor-tooltip",()=>new A0(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 H4{constructor(t){this.createOptions=t,t.lang&&D.setLang(t.lang)}createHistoryEditor(t,e){return tZ(t,e,this.createOptions)}}I("create-editor");function j4(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=hu(t,e,{shortcuts:[Ch],components:{blocks:s,commandProviders:[new Zh],decorators:[new k0],embeds:l,boxes:c,options:o}});if(d.input.addHandler(new w0),d.input.addHandler(new uE(d)),d.input.addHandler(new pE(d)),d.input.addHandler(new fW(d)),d.input.addHandler(new D0),d.addCustom("image-paste-handler",()=>new cE(d)),(h=n.options.componentsOptions)!=null&&h.mention){const E=n.options.componentsOptions.mention;d.addCustom("mention",()=>new m4(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 eZ(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),r=new Set;e.forEach(i=>{const o=nt(i);o&&r.add(o)}),r.forEach(i=>{dW(n,i,t)})}class nZ{constructor(t){g(this,"listeners",new Set);g(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&&eZ(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 j4(this.editor,{root:t,childDoc:e,doc:this.doc})}allowEdit(t){return t.userId===this.doc.getUser().userId}}class rZ{constructor(t,e){g(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 hp(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 j4(this.editor,{root:t,childDoc:e,doc:this.localDoc})}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const iZ={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}"}},oZ={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}"}},sZ={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"}};D.mergeLang({"zh-CN":iZ,"en-US":oZ,"ja-JP":sZ});const lZ="UEsDBBQABgAIAAAAIQBk9WPugQEAACkGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0lMtqwzAQRfeF/oPRtsRKuiilxMmij2UbaArdKvI4EdULaZzH33fsJKYUJy5NsjHIM/feowHNcLw2OllCiMrZjA3SPkvASpcrO8/Yx/Sld8+SiMLmQjsLGdtAZOPR9dVwuvEQE1LbmLEFon/gPMoFGBFT58FSpXDBCKRjmHMv5JeYA7/t9++4dBbBYg8rDzYaPkEhSo3J85p+b0kC6MiSx21jlZUx4b1WUiDV+dLmv1J6u4SUlHVPXCgfb6iB8daEqnI4YKd7o9EElUMyEQFfhaEuvnIh57mTpSFletymhdMVhZLQ6Cs3H5yEGGnmRqcIxtMNIDVC2T1/G4csIzrzaTRXpJkE5+PgZJzGtPKDgAqaGR6chS3NDALRn38YjXUnRMSNhnh+gq1vdzwgkuASADvnToQVzN4vRvHDvBOkoNypmGk4P0Zj3QmBtIpg+z39VdQ2xyKps36AtNrCP669312Vuuf/9PKaRLI++X5QrcUc8pZsXi/60TcAAAD//wMAUEsDBBQABgAIAAAAIQAekRq37wAAAE4CAAALAAgCX3JlbHMvLnJlbHMgogQCKKAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJLBasMwDEDvg/2D0b1R2sEYo04vY9DbGNkHCFtJTBPb2GrX/v082NgCXelhR8vS05PQenOcRnXglF3wGpZVDYq9Cdb5XsNb+7x4AJWFvKUxeNZw4gyb5vZm/cojSSnKg4tZFYrPGgaR+IiYzcAT5SpE9uWnC2kiKc/UYySzo55xVdf3mH4zoJkx1dZqSFt7B6o9Rb6GHbrOGX4KZj+xlzMtkI/C3rJdxFTqk7gyjWop9SwabDAvJZyRYqwKGvC80ep6o7+nxYmFLAmhCYkv+3xmXBJa/ueK5hk/Nu8hWbRf4W8bnF1B8wEAAP//AwBQSwMEFAAGAAgAAAAhADPCW79BAQAA5wQAABwACAF3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJQxT8MwEIV3JP5D5B07LVAQatoFkDqwQJFYneSSWI3tyL6Q9t9zojRNRYkYPN6z7r1P57Pny62uo09wXlmTsAmPWQQms7kyZcLe189X9yzyKE0ua2sgYTvwbLm4vJi/Qi2RmnylGh+Ri/EJqxCbByF8VoGWntsGDJ0U1mmJVLpSNDLbyBLENI5nwg092OLEM1rlCXOrnPLXuwb+422LQmXwaLNWg8EzEQKpF8hQuhIwYd/lXpxwMmPiPMN1SAaPu5qG2EPs67H4u5DxhTW4lmk9GEMvjUFMQ0KYVqfgaMeOEL00BjEJCZG1Hq3+oLQegvOjKhSCHl2LWUiaipxcrczmSPNj23UdT6XKW55ZLQ7HLzan5KctgjPyT8TbkIgdpG+ASHc0WN+BODarm6BP6BfFQTkgiJPvafEFAAD//wMAUEsDBBQABgAIAAAAIQBOMo6QFgYAAKYkAAARAAAAd29yZC9kb2N1bWVudC54bWzUWttu40QYvkfiHSJfLRKtz4eYTVeOD7uVQKoo+wCuPUmstT3WeNI0XC0XC1wguOBiuWClLgjBE4AEiIdZ0T28BTM+JM6h7cTZkm0vEnv+mW+++eb7/0yc3r13lsSdU4DyCKY9TtwXuA5IAxhG6bDHPfzM2zO4To79NPRjmIIeNwU5d+/g/ffuTswQBuMEpLhDINLcnGRBjxthnJk8nwcjkPj5fhIFCOZwgPcDmPBwMIgCwE8gCnlJEIXiKkMwAHlO5rP99NTPuQouOGNDC5E/IYMpoMIHIx9hcDbHEDcGUfkub6wCSS2AyAolcRVK3hhK4ymrFSClFRBhtYKktkNaszitHZK0iqS3Q5JXkYx2SCt2SlYNDjOQkuAAosTH5BYN+cRHj8bZHgHOfBydRHGEpwRT0GoYP0oftWBERs0QEjncGEHnExiCWA5rFNjjxig1q/F7s/GUulmOr97qEYhl/eUQpyoOxcp5BGKiBUzzUZTNMjxpi0aCoxrk9KpFnCZx3W+SiYzpcll5ckop54As9Cv9k7hkfjWiKDDsCIWYjWChsDhnzSQhLpxP3EqahrgiYwGpAaQVAC0AjAW/xjAqDD6YZyjFiRhTo8Ypd4XiRHNhRcY6tkymAZCDzSDUmkc+TRoryobb2fY+guNsjhZth3Y4L0ITehzYAKuyfzMl8+3IHI/8jNSmJDAPhylE/klMGBEzd4gfO8UO0FeyrfStuARnHVoIuANyfDmB4ZS+ZySimJmP/EPiHEV2dE+3La5oJcUf01a9+iOtJjkqhZ/2OEEQJE1z5FmTAwb+OMY04nUVRRfryFGjqZjwCBVvx3gaE4bmqR/3uAfAp2cukeNpDJVdYj8d1h1AuvfwmEb5KszPkMqX6tqDKc7JoFGUEi7Az7GVR35z4MTEBy/Pv3rz0w+0CZeBZZwrp6ajxIXBlMwaMT2l6wh9lUHMRcnejpjSDYrJoND2GksMGquOY+iu7exIY/m2ayyzaKwaqi4YNNd3obFy2zVWGDTW+7Il296uaoX6LmisMugkKIpouJqwI5202+5FjUFjTfQ8S7OMHWms33aNdQaNJd3qqoq8q5pq3HaNDRaNNcFzRafLoLGtaF2JdlzReDFSaFw1NTTeRMf1XBVLNcSux+KHnXOVBddQLEm6DVxVSxf6nubdPNfFPLNhCCqWdRxBOHARIj3wNCNf1YbIT46xj3CVi6WxA5jmMAb7MRzeWUqQtQhuGi6Mf/H4xxGIY/hhh3xbjMMXj5998BFDrsiSZnuiYjPoZLiC7fV3rVM+zTFI9uEY72eI1KA4baPWnZZyiYYu2oLFlK6u2C3OzqtyLURaytXME8Zvv//+9fOr8y8unj1lWKjqeroraMpWvliMFAutmoq9WDp9aJohGzrLN7o2M7asLrVj6MMbM8/8gBgqQyAH6BRwB5RlZ8l/1HgFrSO0NH29Wws7e5jGUQoa+zvbLgwuQ26YiBGX2SOvn39z8eWT0ik3tbAzvIzMuiuXbkRndSfW+1rRlb7nKExng00SeDuXXcK1qwiWJi99hmme4uiaRfNkJ1wXt2u78+Dr35+8+vPXJTeMSNVGxDuPOsiMyILRYahR/qMoxxBNSREuTbdox+vy4UGNem06MPB+8/0/L7/9ZdluM+JvV6SX539c/P0dg7eFru3alrhUs1VH6kuqPD/gULUcRVAdd51fFiM35m21L3ueJNOJGlwFQ1FFxZ0beQ3Xcrs3WkDV1FjA4qfrx8RZR4QYOSlko3JX0nFS9ozi07juJ8xih2HdVjy65mcDGlmyljCbK5rbf/H109fPf7u6FjfA2R5Rq47sCZq2JL/ueo5o2VfK//8oXf0g8K4rvcf0c4DrGX25v3TElmzV1foiLe47tfrGZf16xWbiLMlTh/yTCmauWA4CfDST+jopimUNjz8nwQnxhSQp9LmgOSLXqqFUWZoNP/EpIoYZaVfKLigajvD89gRiDJP5fQwGjegI+CEg8+oCfSRmDiDEjdvhGBe31XQBjKle1cmE9imaQxjcR/SnOJOeho4iHBCWslYM4ut1F5flD3P8/B+MDv4DAAD//wMAUEsDBBQABgAIAAAAIQC29GeY0gYAAMkgAAAVAAAAd29yZC90aGVtZS90aGVtZTEueG1s7FlLixtHEL4H8h+Guct6zehhrDXSSPJr1zbetYOPvVJrpq2eadHd2rUwhmCfcgkEnJBDDLnlEEIMMcTkkh9jsEmcH5HqHkkzLfXEj12DCbuCVT++qv66qrq6NHPh4v2YOkeYC8KSjls9V3EdnIzYmCRhx719MCy1XEdIlIwRZQnuuAss3Is7n392AZ2XEY6xA/KJOI86biTl7Hy5LEYwjMQ5NsMJzE0Yj5GELg/LY46OQW9My7VKpVGOEUlcJ0ExqL0xmZARdg6USndnpXxA4V8ihRoYUb6vVGNDQmPH06r6EgsRUO4cIdpxYZ0xOz7A96XrUCQkTHTciv5zyzsXymshKgtkc3JD/beUWwqMpzUtx8PDtaDn+V6ju9avAVRu4wbNQWPQWOvTADQawU5TLqbOZi3wltgcKG1adPeb/XrVwOf017fwXV99DLwGpU1vCz8cBpkNc6C06W/h/V671zf1a1DabGzhm5Vu32saeA2KKEmmW+iK36gHq92uIRNGL1vhbd8bNmtLeIYq56IrlU9kUazF6B7jQwBo5yJJEkcuZniCRoALECWHnDi7JIwg8GYoYQKGK7XKsFKH/+rj6Zb2KDqPUU46HRqJrSHFxxEjTmay414FrW4O8urFi5ePnr989PvLx49fPvp1ufa23GWUhHm5Nz9988/TL52/f/vxzZNv7XiRx7/+5avXf/z5X+qlQeu7Z6+fP3v1/dd//fzEAu9ydJiHH5AYC+c6PnZusRg2aFkAH/L3kziIEMlLdJNQoAQpGQt6ICMDfX2BKLLgeti04x0O6cIGvDS/ZxDej/hcEgvwWhQbwD3GaI9x656uqbXyVpgnoX1xPs/jbiF0ZFs72PDyYD6DuCc2lUGEDZo3KbgchTjB0lFzbIqxRewuIYZd98iIM8Em0rlLnB4iVpMckEMjmjKhyyQGvyxsBMHfhm327jg9Rm3q+/jIRMLZQNSmElPDjJfQXKLYyhjFNI/cRTKykdxf8JFhcCHB0yGmzBmMsRA2mRt8YdC9BmnG7vY9uohNJJdkakPuIsbyyD6bBhGKZ1bOJIny2CtiCiGKnJtMWkkw84SoPvgBJYXuvkOw4e63n+3bkIbsAaJm5tx2JDAzz+OCThC2Ke/y2EixXU6s0dGbh0Zo72JM0TEaY+zcvmLDs5lh84z01QiyymVss81VZMaq6idYQK2kihuLY4kwQnYfh6yAz95iI/EsUBIjXqT5+tQMmQFcdbE1XuloaqRSwtWhtZO4IWJjf4Vab0bICCvVF/Z4XXDDf+9yxkDm3gfI4PeWgcT+zrY5QNRYIAuYAwRVhi3dgojh/kxEHSctNrfKTcxDm7mhvFH0xCR5awW0Ufv4H6/2gQrj1Q9PLdjTqXfswJNUOkXJZLO+KcJtVjUB42Py6Rc1fTRPbmK4RyzQs5rmrKb539c0Ref5rJI5q2TOKhm7yEeoZLLiRT8CWj3o0Vriwqc+E0LpvlxQvCt02SPg7I+HMKg7Wmj9kGkWQXO5nIELOdJthzP5BZHRfoRmsExVrxCKpepQODMmoHDSw1bdaoLO4z02Tker1dVzTRBAMhuHwms1DmWaTEcbzewB3lq97oX6QeuKgJJ9HxK5xUwSdQuJ5mrwLST0zk6FRdvCoqXUF7LQX0uvwOXkIPVI3PdSRhBuENJj5adUfuXdU/d0kTHNbdcs22srrqfjaYNELtxMErkwjODy2Bw+ZV+3M5ca9JQptmk0Wx/D1yqJbOQGmpg95xjOXN0HNSM067gT+MkEzXgG+oTKVIiGSccdyaWhPySzzLiQfSSiFKan0v3HRGLuUBJDrOfdQJOMW7XWVHv8RMm1K5+e5fRX3sl4MsEjWTCSdWEuVWKdPSFYddgcSO9H42PnkM75LQSG8ptVZcAxEXJtzTHhueDOrLiRrpZH0Xjfkh1RRGcRWt4o+WSewnV7TSe3D810c1dmf7mZw1A56cS37tuF1EQuaRZcIOrWtOePj3fJ51hled9glabuzVzXXuW6olvi5BdCjlq2mEFNMbZQy0ZNaqdYEOSWW4dm0R1x2rfBZtSqC2JVV+re1ottdngPIr8P1eqcSqGpwq8WjoLVK8k0E+jRVXa5L505Jx33QcXvekHND0qVlj8oeXWvUmr53Xqp6/v16sCvVvq92kMwioziqp+uPYQf+3SxfG+vx7fe3cerUvvciMVlpuvgshbW7+6rteJ39w4Byzxo1IbtervXKLXr3WHJ6/dapXbQ6JX6jaDZH/YDv9UePnSdIw32uvXAawxapUY1CEpeo6Lot9qlplerdb1mtzXwug+Xtoadr75X5tW8dv4FAAD//wMAUEsDBBQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAd29yZC9zZXR0aW5ncy54bWy0Vttu2zgQfV9g/8HQ8zq6WHZsoU4R3zYp4nZRebHPlETZRHgRSMqu8/U7pETLu3ELp0VeEmrOzJkh53DoDx+/MdrbY6mI4FMvvAm8Hua5KAjfTr2/N6v+2OspjXiBqOB46h2x8j7e/f7bh0OisNbgpnpAwVXC8qm307pKfF/lO8yQuhEV5gCWQjKk4VNufYbkc131c8EqpElGKNFHPwqCkdfSiKlXS560FH1GcimUKLUJSURZkhy3/1yEvCZvE7IQec0w1zajLzGFGgRXO1Ipx8Z+lg3AnSPZ/2gTe0ad3yEMrtjuQcjiFHFNeSagkiLHSkGDGHUFEt4ljl8RnXLfQO52i5YKwsPArs4rH76NIHpFMMrxt7dxjFsOHyLPeUjxNp7RiYd0BxuOfq6YMwKF30YxdHWoI+t2pOg1PW6gJ5JJJJsb1DaY5cnjlguJMgrlQKN70Kuerc78hS2bf3YJOe/gIr8IwXqHpMIyBzXDFAgCzzdABtXBaFiIz0KntZSi5sUDRmD7LrwSQrcwKFCUqUYa8iZbiRjc/amXU4x4Q1/gEtVUb1CWalGB0x7B1m+jNnu+QxLlwJZWKAcdzwXXUlDnV5i0c5gjEmTeRtipYla1wqvlEzqKWp8haTOxgIEjBofznym0FgWMFAiV5PoumgBbTTg8L+H/iQRMWEkKvDFNSfWR4hVsJiUv+J4Xn2qlCTDaWfQLFfyoAMxN5i8go82xwiuMdA3H9k7JbGdWlFRrAqKQj7wAWb1bMlKWWEICAkJbg5yIFAd7zo1S3ysvKOwfcIZbPNiATJ9nQmvBHo7VDs761zpp9e+fyxme50K5xVe4YifXYBEHw8WyqdSgHRJEo9FicAkJV9Eyvr+EjJfBfDW7hMxm0WB+ewmZx6NJNLmILMPJ+GIFCyhiPL+IfHc/q0kc39qe+KcTYYl5dv+SbmWuVY81EXPEMklQb20eZt94ZPJ5RrjDMwzzFJ8jaZ05sN9vAMUQpStosANsc1hSEFUtcGnXdI3ktuNtPeRFK8y8TycuM26x/BMGZ9WgB4mq5ro4lzCO20jC9RNhzq7qLHVRHF6AMwim8Je9tOfUHc8h0SA/O3aekJWx9cW8P/9shIeR0veKoKn3sjOmRvlUpka1eI2qqhF/tg2nHiXbnQ5NmIavAn7S2Y9sG7VYZLGowewHys1mwbtddLbI2c78Bs426Gyxs8Wdbehsw842craRse1g3ElK+DPcQ7c09lJQKg64eOjwVyb3SuUERJAeWdY9PjcNRomCwVDBO6WFdNgfFgvjpBD5o3ls48Y+nIwXy8mg0XY4tO+btrMDjvYrLmdI4aJRt/tpffcvAAAA//8DAFBLAwQUAAYACAAAACEAQMH/8TkBAAAjAwAAFAAAAHdvcmQvd2ViU2V0dGluZ3MueG1snNJfT8IwEADwdxO/w9J36CCykIVBYgzGF2OifoDS3aCx7S294sBP720CYnhhvvT//XLXdrbYOZt8QiCDvhCjYSoS8BpL49eFeH9bDqYioah8qSx6KMQeSCzmtzezJm9g9Qox8klKWPGUO12ITYx1LiXpDThFQ6zB82aFwanI07CWToWPbT3Q6GoVzcpYE/dynKaZODDhGgWrymh4QL114GMXLwNYFtHTxtR01JprtAZDWQfUQMT1OPvjOWX8iRndXUDO6ICEVRxyMYeMOorDR2k3cvYXmPQDxhdApmHXz5geDMmR544p+znZyTHlmfO/ZM4Agn7E5JgH7V1bkdP509pjUCvLEr9RwtecdHDbcrZt1w35+Jx/LdbROPMFSwz3ARuCINtlZS02L8+PPJF/vvb8GwAA//8DAFBLAwQUAAYACAAAACEAOdtFTLkFAAAnWgAAEgAAAHdvcmQvbnVtYmVyaW5nLnhtbOyczW7qRhiG95V6D8j7xP8/oEOOwECV6rQ60knV9WAGsGKPrbGB0FV7Ke266q430EvpDfQWOuOxzZ9DbIMw5MwmDuP5Xs/3zjfDk0nCh48vvtdaQhy5AeoK8r0ktCBygomLZl3hp6fRnSW0ohigCfACBLvCGkbCx4dvv/mw6qCFP4aYdGwRDRR1VqHTFeZxHHZEMXLm0AfRve86OIiCaXzvBL4YTKeuA8VVgCeiIslS8l2IAwdGEdGxAVqCSEjlnJdyahMMViSYCmqiMwc4hi8bDbmyiC62RetQSKkhRDJU5EMptbKUIdJRHQhptYTIqA6U9HpKBckZ9ZSUQyWznpJ6qGTVUzooJ/+wwIMQInJzGmAfxOQlnok+wM+L8I4IhyB2x67nxmuiKRmZDHDRc40RkahcwVcnlRVM0Q8m0FMnmUrQFRYYddL4uzyeDr3D4tNLFoHL5M9CBoGz8CGKk8xFDD3iRYCiuRvmK9yvq0ZuzjOR5bEklr6X9VuFcsnl8tr2NGBWbgTLDD/13/fYyI8rylKJGaESeUSZIew+MxuJT6pw8+Ba1myZK5fcQDIB5UDAcGDJDT/TsFIN0dmsUKrjllwamQ6bFarjboyVS+5j+4PZEohgNQk9G0e09rcyCmenle13OFiEGzX3NLXHzSa0ojxQQSst/+0lGZ02mC9zEJK9yXc6jzMUYDD2yIhIMbdIPbaSGaBfybTSS/ItfGnRjUB4IPwCxlGMgRP/uPBbO68eSQERDiIiHQwJ/GDayFCnN40h7mMInmkXqoIiKt9ZAo+0jJS+ItuKINI7/sKL3U9wCb2ndQizPkmrR1tZr9gPveyeatvSUJE0dsdb0hsuuWTPSsaSdZZZL0JhIz9vHC88D8Z5/BN8yW/9++sfefv3TtbqwWnaPfyM6cVFNB3a3BU0hdrQmQM0S3iQviZ9xbwzTi+jAMURNTFyXFJgP5PelCCjJLpHLNpvcxGRn8ApIG6wx4+Tr25uJWuNfskalCRfMX2mmKSx75J8ukv//F7VJEu7nEkbO2T9bTuU0+3477e/q/ohK8alDDmevnqO9P+snL5hXUf6bJM7Mf2/qqavyNJ1pK83UvyKfrEt83j6RiPFr7QvthkeT99spPhV9Uq2PquR4lfNxrY+cQfg6DOO0p1ch+4Uua1LumWw/KvTXbsvGX1LS+O3p+sMdJc+r/xkXRPblYEZznY7dnC2Oz19znbV0udsx9mOsx1nuwunX5HtlDpsp2rKSB5ItdlOaxu2aitWbms+Xfzk7kIndzXW9OXwjsMchzkOc4Xpc5hroPg5zHGYuwWYU2vBXNvWTcsasvyLYW6+HmN38sMRpDN7pqbpmpabm09a4l0cek5XsI2BNVRNu8Y0hl/itZeP55MbxZ8BBjMMwnnhPH8FJ3y5rZakS0N5dAZ2fl9nfrlBw/5Is4b9s7x5XDM4VrWI7hepRZImtSVJYlUFUQxidwnP9JPGLcPmvkHMsjMbdMs4um8QazmzQbcMrPsGXccSuyKk3TfoOpbYFUHvvkHXscRuB4vpLl4HiwdqXxqw/KufcQ7aQ0Oib/2ZrfmEvv8zTn6ayU8z+WkmP818M31+mtlA8fPTTH6aeQvYRjG3Mrbplq0aZttm+VfHNsM2FG3YTk9Dt6frDNhWY7FybOPYtsmeYxvHNo5tHNsaTZ9jWwPFfzvYRk+8K2ObOVBHqmFpLP/q2NYb9CRTVtL47el679jGIe317DmkNVD6HNI4pHFI45DWaPoc0o5DGv2te3VIG/ZNc9QbsPyrQxrZGwzLlL/Kf/vgZ2sc2zi2cWx7M32ObQ0UP8c2jm1Xgm0owTWUffIKbdphtywjNZVDBWHsDbQwLPmf3VfC2BtPYVj2x+RFYQefD7gJM4+EsY2uMEw7EsY2iMKw5JMEXwljC6swLJvrojBWkIVhGcYlYezKIPrhfwAAAP//AwBQSwMEFAAGAAgAAAAhAPiVyO/8DgAA85kAAA8AAAB3b3JkL3N0eWxlcy54bWzsXd9zo0YSfr+q+x8oPSUPG/+QLTtbcVJr2T67btdxVt5L3eMIRhZnYHSA1uv89TczDAjUDKKHjuu8m6RqLQH9MczXX890A5qffvkSR95nnmahSM5GBz/sjzye+CIIk4ez0af7qzenIy/LWRKwSCT8bPTMs9EvP//9bz89vc3y54hnngRIsrexfzZa5vnq7d5e5i95zLIfxIoncudCpDHL5df0YS9m6eN69cYX8Yrl4TyMwvx573B/fzIyMGkfFLFYhD6/EP465kmu7fdSHklEkWTLcJWVaE990J5EGqxS4fMskxcdRwVezMKkgjk4AkBx6KciE4v8B3kxpkUaSpof7OtPcbQBOMYBHAKAic+/4DBODcaetKzjhAEOZ1LhhEENx60xNYCM4yCOy3Zkz7G6oth/e/OQiJTNI4kkOfJkN3saWP0rW6v+6I/y8J+lwwbCv+ALto7yTH1N71Lz1XzTf65Ekmfe01uW+WF4L9slweNQnuf6XZKFI7mHsyx/l4WsvvPSbFP7l+rAVks/y2ubz8MgHO2pk2Z/yJ2fWXQ2Ojwqt0xVIxrbIpY8lNt48mZ6W2/M2eiPpdk0l7hnI5a+mb1Thnvm2oq/tSteVd+Ko7a6R+pJqmtWiFzu5Yv3wn/kwSyXO85G++pUcuOnm7s0FKkU8tnoxx/NxhmPw+swCHhSOzBZhgH/fcmTTxkPNtt/u9JiNBt8sU7k5/HJRFMWZcHlF5+vlLTl3oSp3rtVBpE6eh1uTq7N/1uCHZg+a7Nfcqbim3ewDaGbj4I4VBZZ7WrbMddb166PQp1o/FInOnqpEx2/1IkmL3Wik5c60elLnUjD/JknCpOAfymECE8DUHfhWNSIxrGIDY1j0RIaxyIVNI5FCWgci6OjcSx+jMaxuCkCJxe+zQtrzj62eHs37u4xwg1395Dghrt7BHDD3R3w3XB3x3c33N3h3A13d/R2w90drPG4xVTLu5EyS/LBKlsIkSci517OvwxHY4nE0kkfDZ4a9HhKcpEEMEVkMwPxYDSf6e+7PUSL1H08z1U25omFtwgf1inPBjecJ595JLN2jwWBxCMETHm+Ti094uLTKV/wlCc+p3RsOtAoTLiXrOM5gW+u2AMZFk8C4u4rEUmCQuXQbJ0vlUhCAqeOmZ+K4U0TjCw+vA+z4X2lQLzzdRRxIqxbGhfTWMNzAw0zPDXQMMMzAw0zPDGocUbVRQaNqKcMGlGHGTSifiv8k6rfDBpRvxk0on4zaMP77T7MIx3i67OOg/61u2kkVJl+cDtm4UPC5ARg+HBjaqbeHUvZQ8pWS0+VkNth69eMPc+5CJ69e4oxrUKimtdrF5nKqw6T9fAObaBRiavCI5JXhUcksApvuMQ+yGmymqBd0+Qzs/U8bxWtRuol2hmL1sWEdrjaWD7cwzYCuArTjEwG7bAEHnyrprOKTorIt2nl8IZtsIbLajsqkTbPQBK0MhL+I00Yvn5e8VSmZY+Dka5EFIknHtAhzvJUFL5Wl/yhpqSX5C/j1ZJloc6VGhD9h/ryBr/3ga0GX9BdxMKEhrfLNzELI49uBnF9/+G9dy9WKs1UHUMDeC7yXMRkmKYS+N3vfP49TQPfySQ4eSa62ndE5SENNg0JBpkCSQRESHKaGSYhyRiq8f7Jn+eCpQEN2l3Ki2dqck6EOGPxqph0EGhLxsUnGX8IZkMa718sDVVdiEpU9yRgtbJhtp7/h/vDQ92t8EgqQ7+uc11/1FNdbU0HN3ya0IAbPkXQbMrhQfkvwcU24IZfbAOO6mKnEcuy0HoL1RmP6nJLPOrrHZ78GTwRiXSxjug6sAQk68ESkKwLRbSOk4zyijUe4QVrPOrrJXQZjUdQktN4/0jDgIwMDUbFhAajokGDUXGgwUgJGP6ETg1s+GM6NbDhz+oUYERTgBoYlZ+RDv9Ed3lqYFR+psGo/EyDUfmZBqPys/GFxxcLOQmmG2JqkFQ+V4OkG2iSnMcrkbL0mQjyMuIPjKBAWqDdpWKhXrYQSfEQNwGkqlFHhJPtAo6K5N/5nKxpCouyXQQVURZFQhDV1jYDjrZsPru2y0y/czG4CXcR8/lSRAFPLddkt5X58mzFfFOmB7f7epU934cPy9ybLatqfx1msr/TskzYG2a7T9jW55PDDrMPPAjXcdlQ+DLFZNzfWHt0w7h856XDeDOTaFge97SE55zsttzMkhuWJz0t4TlPe1pqnTYsu/RwwdLHVkc46fKfKsezON9JlxdVxq2n7XKkyrLNBU+6vKghFe+d76u7BZCdfpqx2/cTj90eoyI7CkZOdpTeurJDdAnsI/8cqpEdEzT1+aqnJ0Dc15PoXpHzt7Uo6vaNG079X+q6kROnJONeK864/42rRpSx92PvcGOH6B137BC9A5AdolckspqjQpIdpXdsskP0DlJ2CHS0giMCLlpBe1y0gvYu0QqiuESrAbMAO0Tv6YAdAi1UCIEW6oCZgh0CJVRg7iRUiIIWKoRACxVCoIUKJ2A4oUJ7nFChvYtQIYqLUCEKWqgQAi1UCIEWKoRACxVCoIXqOLe3mjsJFaKghQoh0EKFEGih6vniAKFCe5xQob2LUCGKi1AhClqoEAItVAiBFiqEQAsVQqCFCiFQQgXmTkKFKGihQgi0UCEEWqjFq4buQoX2OKFCexehQhQXoUIUtFAhBFqoEAItVAiBFiqEQAsVQqCECsydhApR0EKFEGihQgi0UPXNwgFChfY4oUJ7F6FCFBehQhS0UCEEWqgQAi1UCIEWKoRACxVCoIQKzJ2EClHQQoUQaKFCiC7/NLcobY/ZH+CrntYn9vvfujKN+lh/lbsONe4PVbbKjtX/XYRzIR691hcPxzrf6AcSzqNQ6BK15bZ6HVc/EoG68fnrtPsNnzr6wB9dMu9C6HumAPyoryWoqRx1uXzdEiR5R12eXrcEs86jruhbtwTD4FFX0NW6LB9KkcMRMO4KMzXjA4t5V7SumcMu7orRNUPYw12RuWYIO7grHtcMjz0VnLetj3v206R6vhQgdLljDeHEjtDllpCrMhxDYfQlzY7Qlz07Ql8a7QgoPq0weGLtUGiG7VBuVEOZYal2F6odAUs1RHCiGsC4Uw2hnKmGUG5Uw8CIpRoiYKl2D852BCeqAYw71RDKmWoI5UY1HMqwVEMELNUQAUv1wAHZCuNONYRyphpCuVENJ3dYqiEClmqIgKUaIjhRDWDcqYZQzlRDKDeqQZaMphoiYKmGCFiqIYIT1QDGnWoI5Uw1hOqiWldRGlSjGK6Z4yZhNUPcgFwzxAXnmqFDtlSzdsyWagiO2RLkquQcly3VSbMj9GXPjtCXRjsCik8rDJ5YOxSaYTuUG9W4bKmNaneh2hGwVOOyJSvVuGypk2pcttRJNS5bslONy5baqMZlS21UuwdnO4IT1bhsqZNqXLbUSTUuW7JTjcuW2qjGZUttVOOypTaqBw7IVhh3qnHZUifVuGzJTjUuW2qjGpcttVGNy5baqMZlS1aqcdlSJ9W4bKmTaly2ZKcaly21UY3LltqoxmVLbVTjsiUr1bhsqZNqXLbUSTUuW/ogTUKCn4CaxSzNPbrfi7tm2TJnw3+c8FOS8kxEn3ng0V7qe9RV7j01lr9S2Hq1O3l8LvtM/QJ67XWloPgFWAOoD7wJqmWqlLFqiWeW7jKbdYPN7Vr9Oc1kTm2O2d8/Pz8cT43UVsXSZFnxZqk8Rv1a0dloPNGvJKkvH9dqDTS2zoVpvTbZM43Z0fyqweb+8wFo8mbBLN2eOZM99avqYXBBifqxxZbtysnK7eVppkuWFns37l8eYwRu75+Lo/3ji8tG/zxyvrqV59fb1BfJOc/0t03XzdXvlHG1qJoRvyh+/On956gCr/ehZWE4qcRyrTrv3+yaNxaGa92pV4Vr3eNnZ6P7MOaZd8ufvI8iZon3nemkzJvOvje9rv/1VfjYdIP6T2HodeV0aDkbqd+9N0xtFpYrb5TXF5Yb60hTWx/OxVsOrd5i4hiNtxz28JamlP9kB7L7TxlBvir/GZuJQ2NhQr1toP+Mrf5jHgqh8Z/x6/GfUpVfl/9QxJojq6+Y6EbjK0evx1e0Rv5ffSWcFhfk7DPlSDzEZ46tPmMeAKPxmePX4zNaK19DfBnoGcUKs22eYcY6Gs+YvB7P0Ir4yzMeTqyeYTIyGs84eT2eUc70vppxZqCHnFo9xBS3aDzk9PV4iFbGq4gdhyfq/3bPKDfeh2oV8gtDZiPp6ek+vmSO+eYnxy0VIrN0UPXbN3rhoG3HsqwvZHGKchJVlbnafcTe7lzVKTvarOuYnaWtotRp9VrjtrtaKNszjwonkh9uEuXET2aV96KlwRdWQMn9Ux5FH1hxtFjZD434QmlP7j3Y1780ubV/XiyaYLVPdXXdCrDXbEzxtdtPimUUw+K1D2slUZWQW7pbv4M0tKd7+rC/zmTXzNQB2+1rVPS2W2l2egfeJphtRcdWHdhiovFwazy0B7y/KnlIQouim43QQyJCTZ3wmyV0SGkNSWhRBbMROiYi1BTuvl1C/xw1FmUpG3lHROSZ6PLqyXup4hOSxKJOZCPxmIhEU9r6phRITlVRuLFRNSGiygT/v6gaQlVRSbFRdUJElSn+fJOhkZyyorRho+yUiDKTwH9d6nqZAkaj/tXBp17ibptHvbGNvX5Pv5xe7k+vzoujTEFpdR7U0nt9nFoI2qyb9oe6raE+rJhftlD32eapmCr532GrPwPbqjDgdOaybOBwalVSM5eeLasu8iPOCqHVjpZfF2Ek916eXE4u9YNl2heu9MY58x8fUrFOgn43mKciyUTE9O+BbFx8FsaztX4oy3h2/bBWl9aLsFbuHDFdT9QXwZM3n2a0weUmUWXJVpes7cKFFWuRrZ//EnVv0eagCgKJSCof0mHb+JD+DByQ1HVoWNwMCNVTiNuUbfYMZayshbWUGZvMTS8Pfjw1CaxhrjlMHk/G002YNbF32WzoujzaSH1A52weiCyfh9zupJZHJql6a3eNFtd5k/3jy+Mp1iMPLq4uLhzGrKoPVZF08/vy2/2nn87d7G7ru/qgBXtrbFJm1F2XZB0XH8Jo68kfve+msi5Ha2MAwnZPKZafsp//BwAA//8DAFBLAwQUAAYACAAAACEAzJJQVH0BAADxAgAAEQAIAWRvY1Byb3BzL2NvcmUueG1sIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAjJLLTsMwEEX3SPxD5H1qJ+WlKE3FQ6yoQKIViJ2xJ60hsS17IPTvcZI2JYgFO4/n+GRy7Xz+VVfRJzivjJ6RZMJIBFoYqfR6RlbL2/iCRB65lrwyGmZkC57Mi+OjXNhMGAcPzlhwqMBHwaR9JuyMbBBtRqkXG6i5nwRCh2ZpXM0xlG5NLRfvfA00ZeyM1oBccuS0FcZ2MJKdUopBaT9c1QmkoFBBDRo9TSYJPbAIrvZ/Hug6P8ha4dbCn+i+OdBfXg1g0zSTZtqhYf6EPi/uHrtfjZVusxJAilyKDBVWUOT0sAwr//H6BgL77aEIa+GAo3HFQglnvCkxui9LJSBaeXAdvSfa7N9h2xgnffCMqoBJ8MIpi+FG+6+MNgJdcY+LcMWlAnm1LS5Pz9OzTvOr0bIOPlX7NoqkI4Yy3wXdDwUyCgFlfZz7ztP0+mZ5S4qUpUnMTuIpW7I0O00zxl7auUbnD8J6N8A/jdOMnYyNe0EfzfiRFt8AAAD//wMAUEsDBBQABgAIAAAAIQAiURHx1QEAAN4DAAAQAAgBZG9jUHJvcHMvYXBwLnhtbCCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJxTwW7bMAy9D9g/GLo3crKh6AJFxZBi6GFDA8Rtz5xMJ8JsSZDYINnXj7YTT9l2mk/vkfTTE0mp+2PXFgeMyXq3EvNZKQp0xtfW7VbiufpycyeKROBqaL3DlThhEvf6/Tu1iT5gJIupYAmXVmJPFJZSJrPHDtKM044zjY8dENO4k75prMEHb946dCQXZXkr8UjoaqxvwiQoRsXlgf5XtPam95deqlNgPa0q7EILhJrOYFZ7Oio5xVXlCdrKdqjnJccnpjaww6TnSo5AvfpYJ724U3JEar2HCIa4h3p++0HJjKvPIbTWAHF39Tdrok++oeJpsFz0/yuZlyi+xhbNW7R00mwjp+qrdaOREbCxCLsIYX92NzG1NdDimhugG2gTKvk7oB4R+uFuwPb+DrQ8oCEfi2R/8ngXovgOCfu2rcQBogVHYiwbyYDbkCjqylLL2hMfYF6WY/uxNzmC68KBDB4YX7sbTkhPDd+N/mF2npsdPIxWMzu5s8sZf6iufRfAcX/lhLjBP9JzqPxDvxrnHl4Hs6m/WtpvA5h+OJ/KfP5ZRm05ijUPdJrJFFCPfIPY9vr8r9thfan5O9Fv1Mv4XHnbZiV/wwpdYrwI0zvSvwAAAP//AwBQSwMEFAAGAAgAAAAhAIg/pb/hAAAAVQEAABgAKABjdXN0b21YbWwvaXRlbVByb3BzMS54bWwgoiQAKKAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnJDBasMwEETvhf6D2bsiObFdEyyHuE4g19JCroq8tgWWZCS5tJT+e2V6So89LbPDzhu2OnzoKXlH55U1HNINgwSNtJ0yA4e31zMpIfFBmE5M1iAHY+FQPz5Und93IggfrMNLQJ3EhYrz0nL4ykvW5E87Rsr2nJLilDXkmKUNKTKWt8fnU8pY8Q1JRJsY4zmMIcx7Sr0cUQu/sTOaaPbWaRGidAO1fa8ktlYuGk2g25hA5RLx+qonqNc+v9cv2Pt7uVZbnPov5aZuk7KDE/P4CbSu6B/Uqu9eUf8AAAD//wMAUEsDBBQABgAIAAAAIQDBJ8sItgAAACEBAAATACgAY3VzdG9tWG1sL2l0ZW0xLnhtbCCiJAAooCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACskE0OgjAQRq9CegCKLlgQfmKiWzEhcV/KAE3aGdIOBm5v1egJXE7mfS/zTdlsziYP8MEQVuKQZiIJrHBQlhAqgSSauuyLjlavISSRxlD0lZiZl0LKoGdwKqS0AMbdSN4pjqOfJI2j0XAmvTpAlscsy2Vvemto8mqZd/GR/UfVgQXNMHS823i2PN1Ondl4vgyGY7P2LWjRGoR0CzYGXuBVuQhHViT37wtyUZfyV7h+AgAA//8DAFBLAwQUAAYACAAAACEAdD85esIAAAAoAQAAHgAIAWN1c3RvbVhtbC9fcmVscy9pdGVtMS54bWwucmVscyCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIzPsYrDMAwG4P3g3sFob5zcUMoRp0spdDtKDroaR0lMY8tYamnfvuamK3ToKIn/+1G7vYVFXTGzp2igqWpQGB0NPk4Gfvv9agOKxcbBLhTRwB0Ztt3nR3vExUoJ8ewTq6JENjCLpG+t2c0YLFeUMJbLSDlYKWOedLLubCfUX3W91vm/Ad2TqQ6DgXwYGlD9PeE7No2jd7gjdwkY5UWFdhcWCqew/GQqjaq3eUIx4AXD36qpigm6a/XTf90DAAD//wMAUEsDBBQABgAIAAAAIQDrgGBMUwMAAI8OAAASAAAAd29yZC9mb250VGFibGUueG1szJbPb9MwFMfvSPwPUU7jwJqkXZdV66Y2WzQk2IEVAUc3cVqL2I7itF3/AA6IE+LI38C4gwb/DNPYf8FznLRZm25LQbBGzY9n+5vnT57f8+7+KQ21MY4F4aytm5uGrmHmcZ+wQVt/0XMf27omEsR8FHKG2/oUC31/7+GD3Ukr4CwRGoxnokW9tj5MkqhVqwlviCkSmzzCDBoDHlOUwGM8qFEUvxlFjz1OI5SQPglJMq1ZhtHUM5n4Lio8CIiHD7g3opgl6fhajENQ5EwMSSRytcld1CY89qOYe1gImDMNlR5FhM1kzMaSECVezAUPkk2YTOZRKgXDTSO9o+FcYKuagLUk0PTwaTUNO9OowciiDvGr6TRnOsQv6KznTEFA4GoSW7kfYkrljKjXejJgPEb9EJTgG2mAWUuF5Rm8lZf0FrrvZfGqTVoMURjwEj62DHKRNkWIcYFNaB2jsK0bW8bST6/Jjt4QxQJLmbRj40CZA0RJOM2tPvbAr4SMsWqNSOIN88Yxion0WTUJMoCGkegb8Fb1q+vKYsJyzN+tLNasT26pX7d4qY6tDGZmMQt94J01BWIJSI9QLLRjPNGec4pYKRYLjqZRBzwN+Ftw1yjFktO6jiVOdasQgaVoWB17e04km9syEfsmIoqH61Yj4qCQ9GOygoSbEpBHAzhYlUiICRGiEomOdNY6TGegSDSkwdjuVosN9bxTkcQBZoNXJAsKFCbHYM19vvz87vLrj2wyS5RMiBcIabhmRyklu1lGCY0SvgakbgFS3XbcbcftLEIym7dAknQrQnqWZy/tNTrCKmwWWF18P/t1/uXq09urbx9WEetCXMl4knGVnisQqx5X6XqyiivM6jhu3dmy1kFmVkS2kHO0jSOM0qSsOSePygAuJqmVDJsZvWyF/oUs5eMAjcLkxoQB+w8eovKSorzaWTNjUO7juMytgJxif/m7HsrSYamMN88XrjOzzPPFzu2Zs2q+OCH0ZFSaLS7O3v88/3gvskU2j0K5tWzbzadfOVv8WbnVNrrcn96PsGc86cUj3JtGeK1lkFcL7SkZDJPVNSNrvw+x8H8rR7bRKPAq226oovBvthuHEkenmD4caWmUbDfukD5u3XhlN2LvNwAAAP//AwBQSwECLQAUAAYACAAAACEAZPVj7oEBAAApBgAAEwAAAAAAAAAAAAAAAAAAAAAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLAQItABQABgAIAAAAIQAekRq37wAAAE4CAAALAAAAAAAAAAAAAAAAALoDAABfcmVscy8ucmVsc1BLAQItABQABgAIAAAAIQAzwlu/QQEAAOcEAAAcAAAAAAAAAAAAAAAAANoGAAB3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAE4yjpAWBgAApiQAABEAAAAAAAAAAAAAAAAAXQkAAHdvcmQvZG9jdW1lbnQueG1sUEsBAi0AFAAGAAgAAAAhALb0Z5jSBgAAySAAABUAAAAAAAAAAAAAAAAAog8AAHdvcmQvdGhlbWUvdGhlbWUxLnhtbFBLAQItABQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAAAAAAAAAAAAAAKcWAAB3b3JkL3NldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQBAwf/xOQEAACMDAAAUAAAAAAAAAAAAAAAAAMsaAAB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQA520VMuQUAACdaAAASAAAAAAAAAAAAAAAAADYcAAB3b3JkL251bWJlcmluZy54bWxQSwECLQAUAAYACAAAACEA+JXI7/wOAADzmQAADwAAAAAAAAAAAAAAAAAfIgAAd29yZC9zdHlsZXMueG1sUEsBAi0AFAAGAAgAAAAhAMySUFR9AQAA8QIAABEAAAAAAAAAAAAAAAAASDEAAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhACJREfHVAQAA3gMAABAAAAAAAAAAAAAAAAAA/DMAAGRvY1Byb3BzL2FwcC54bWxQSwECLQAUAAYACAAAACEAiD+lv+EAAABVAQAAGAAAAAAAAAAAAAAAAAAHNwAAY3VzdG9tWG1sL2l0ZW1Qcm9wczEueG1sUEsBAi0AFAAGAAgAAAAhAMEnywi2AAAAIQEAABMAAAAAAAAAAAAAAAAARjgAAGN1c3RvbVhtbC9pdGVtMS54bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAABVOQAAY3VzdG9tWG1sL19yZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAOuAYExTAwAAjw4AABIAAAAAAAAAAAAAAAAAWzsAAHdvcmQvZm9udFRhYmxlLnhtbFBLBQYAAAAADwAPANQDAADePgAAAAA=",aZ=()=>vg(lZ);async function cZ(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 z4(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};const e=await ia(new File([t],"",{})),r=await cZ(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}}function uZ(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 fZ(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 G4(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let r;switch(e%3){case 0:r=pt.LevelFormat.DECIMAL;break;case 1:r=pt.LevelFormat.LOWER_LETTER;break;default:r=pt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:r,text:`%${e+1}. `,alignment:pt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(e+1)),hanging:pt.convertInchesToTwip(.2)}}}}})}function dZ(){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:pt.LevelFormat.BULLET,text:t,alignment:pt.AlignmentType.START,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(n+1)),hanging:pt.convertInchesToTwip(.2)}}}}})}function hZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:pt.LevelFormat.BULLET,text:"\u2611",alignment:pt.AlignmentType.START,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(n+1)),hanging:pt.convertInchesToTwip(.2)}}}}))}function mZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:pt.LevelFormat.BULLET,text:"\u2610",alignment:pt.AlignmentType.START,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(n+1)),hanging:pt.convertInchesToTwip(.2)}}}}))}var Cf=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))(Cf||{});const gZ=[{levels:G4(),reference:"number-numbering-reference"},{levels:dZ(),reference:"number-bullet-reference"},{levels:hZ(),reference:"checked-bullet-reference"},{levels:mZ(),reference:"unchecked-bullet-reference"}];function pZ(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 CZ(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 EZ(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 AZ=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function W4(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(AZ);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 on(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 q4(n,t,e){for(let r=0;r<=e;++r){const i=`${t}${r}`;if(on(n,i))return i}}function Z0(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function XE(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function X4(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function xZ(n){const t=on(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"&&Z0(n,"inline-style-font-size",s),o==="color"&&Z0(n,"inline-style-color",s),o==="background-color"&&Z0(n,"inline-style-background-color",s),o==="font-family"&&Z0(n,"inline-style-font-family",s)}}function bZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function vZ(n){const t=`${on(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function BZ(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 TZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function yZ(n){return on(n,"inline-style-font-family")}function kZ(n){const t=on(n,"inline-style-background-color");return W4(t)}function RZ(n){const t=on(n,"inline-style-color");return W4(t)}function wZ(n){xZ(n);const t=on(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!on(n,"style-code"),link:X4(on(n,"link")),size:vZ(n),text:t?TZ(n):BZ(n)||n.insert,bold:!!on(n,"style-bold"),underline:!!on(n,"style-underline"),italics:!!on(n,"style-italic"),strike:!!on(n,"style-strikethrough"),superScript:!!on(n,"style-super"),subScript:!!on(n,"style-sub"),math:on(n,"type")==="math"?on(n,"src"):void 0,mention:t,fontFamily:yZ(n),background:kZ(n),color:t?"338fe5":pZ(q4(n,"style-color-",6))||RZ(n),highlight:q4(n,"style-bg-color-",13)}}function SZ(){return[new pt.Paragraph({border:{top:{color:"auto",style:pt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new pt.Paragraph({spacing:{line:0}})]}function LZ(){return new pt.Paragraph({children:[new pt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function IZ(){return new pt.Paragraph({children:[new pt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function DZ(n,t){return new pt.Paragraph({children:[new pt.ExternalHyperlink({children:[new pt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function Q4(n){if(n.heading!=null)return`Heading${n.heading}`}function Y4(n){if(n.alignment!=null){if(n.alignment==="center")return pt.AlignmentType.CENTER;if(n.alignment==="right")return pt.AlignmentType.RIGHT;if(n.alignment==="left")return pt.AlignmentType.LEFT}}function _Z(n){if(n.indent)return{left:pt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:pt.convertInchesToTwip(.3*n.padding)}}function MZ(n){return{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function UZ(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function Z4(n,t){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 new pt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:pt.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?UZ(n.fontFamily):void 0,shading:n.background?MZ(n.background):void 0,color:n.color,highlight:CZ(n.highlight)})}function OZ(n,t){if(n.link)return new pt.ExternalHyperlink({children:[Z4(n,t)],link:n.link})}async function J4(n,t,e,r,i){const o=await i(n,t,e);if(o==null)return;const s=await z4({width:r||0,height:0,src:e},o);return new pt.ImageRun({data:o,transformation:{width:s.width||100,height:s.height||20}})}function NZ(n){if(n.heading||n.heading)return n.heading}function PZ(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function FZ(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function KZ(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(wZ(o))}return e}}function VZ(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 $Z(n,t){if(n.type==="embed"&&n.embedType&&XE(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 HZ(n){if(n.padding)return n.padding}function jZ(n){return!!(n.type==="embed"&&n.embedType&&XE(n.embedType)&&n.embedData&&n.embedData.src)}async function J0(n,t,e){return{quoted:!!n.quoted,heading:NZ(n),alignment:PZ(n),indent:FZ(n),padding:HZ(n),texts:await KZ(n,e),list:VZ(n),images:$Z(n,t),border:jZ(n)}}async function zZ(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 J0(l,e,r));i.push(s)}return i}const GZ=I("to-docx");function WZ(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 qZ(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 XZ(n){p(GZ,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=WZ(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=EZ(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 x=0;x<h;x++)E===0&&(C+=r?r[l+x]:80),!(E===0&&x===0)&&(i[s+E][l+x].from=[s,l]);i[s][l].width=C}}return qZ(n,t,e,i),i}async function QZ(n,t,e,r,i,o,s,l,c,d){async function h(x){if(l){const v=await l(i,o,x);if(v){await r.addDoc(n,v,d);return}}if(x.type==="text"||x.textOnly===!0){const v=await J0(x,s,c);await r.addTextBlock(v);return}if(x.type==="code"){const v=await zZ(x,e,s,c);await r.addCodeBlockObject(v);return}if(x.type==="list"&&x.textOnly!==!0){const v=await J0(x,s,c);await r.addListBlockObject(n,v);return}if(x.type==="embed"&&x.embedType){const v=x,R=v.embedData,L=v.embedType;if(XE(L)){const M=await J0(x,s,c);await r.addImagesBlockObject(x,M,d)}else x.embedType==="hr"?r.addSeparatorBlock():x.embedType==="video"?r.addVideoPlaceholder():x.embedType==="audio"?r.addAudioPlaceholder():x.embedType==="webpage"?r.addHyperlinkParagraph(X4(R.src),R.title):r.addOtherEmbedBlock(L,x.embedData);return}if(x.type==="table"){let v=[];if(x.colsWidth)v=x.colsWidth;else{const L=x.cols;v=new Array(L);for(let M=0;M<v.length;M++)v[M]=100;x.colsWidth=v}const R=XZ(x);await r.addTableMatrix(v,R,e),r.addEmptyParagraph()}}function C(x){const v=[];for(const{type:R,data:L}of x.embedData.exportSpec){if(R==="text"){const M={id:J(),text:[{insert:L}],type:"text"};v.push(M);continue}if(R==="image"){const M={id:J(),type:"embed",embedType:"image",align:"left",embedData:{src:L}};v.push(M);continue}if(R==="link"){const M={id:J(),type:"embed",embedType:"webpage",embedData:{src:L.url,title:L.title}};v.push(M);continue}}return v}function E(x){var v;return(v=x==null?void 0:x.embedData)!=null&&v.exportSpec?C(x):[x]}for(const x of t)for(const v of E(x))await h(v)}function YZ(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const ZZ=I("to-docx");class JZ{constructor(t,e,r,i,o,s){g(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 pt.Paragraph({heading:Q4(t),alignment:Y4(t),children:await this.paragraphsFromBlockTexts(t),indent:_Z(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new pt.Paragraph({text:`[${D.t("docx.imageExportFailed")}]`,shading:{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=bZ(this.defaultFontSize,t.heading),r=[];for(const i of t.texts){if(i.link){const o=OZ(i,e);o&&r.push(o);continue}if(i.box&&i.box.type&&i.box.type==="br"){r.push(new pt.TextRun({text:"",break:1}));continue}if(i.box&&i.box.type&&i.box.type==="image"){const o=await J4(this.appId,this.docId,i.box.src,i.box.width,this.readImageFunc);o&&r.push(o);continue}if(i.math){const o=await J4(this.appId,this.docId,i.math,0,this.readImageFunc);o&&r.push(o);continue}r.push(Z4(i,e))}return r}async addCodeBlockObject(t){for(const e of t)for(const r of e){const i={style:pt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new pt.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=G4([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]=Cf.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[i]=Cf.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[i]=Cf.UNCHECKED:this.state.listRefMap[i]=Cf.BULLET;const o=Q4(e);e.texts&&this.paragraphs.push(new pt.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 pt.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=await this.readImageFunc(this.appId,this.docId,c.src);if(d)return z4(c,d);i.push(c.src)}));fZ(o,r,t.embedData);const s=uZ(o,r),l={style:pt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new pt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:Y4(e)||pt.AlignmentType.CENTER,children:s.map(c=>this.imageDimWithBufferToImageRun(c)).flatMap((c,d,h)=>c==null?[]:h.length-1!==d?[c,new pt.TextRun({text:" "})]:c)})),i.forEach(c=>{this.addHyperlinkParagraph(c)})}addSeparatorBlock(){SZ().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new pt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(LZ())}addAudioPlaceholder(){this.paragraphs.push(IZ())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(DZ(t,e))}async addTableMatrix(t,e,r){const i=t.map(o=>o!==0?o*15:1500);this.paragraphs.push(new pt.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 pt.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:pt.WidthType.DXA,size:i.width*15},shading:i.color?{fill:i.color,type:pt.ShadingType.CLEAR,color:"auto"}:void 0}))}return r}async generateTableRows(t,e){const r=[];for(const i of t)r.push(new pt.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 addOtherEmbedBlock(){}}class tJ{constructor(t,e,r,i,o,s,l,c){g(this,"convertBlocks",async(t,e,r,i,o,s,l=720)=>{const c=new JZ(i,o,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await QZ(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 pt.ImportDotx,o=this.templateData?await i.extract(this.templateData):void 0,s=t.blocks.root;p(ZZ,s,"data must have blocks");const l=YZ(),c=await this.convertBlocks("blocks",s,t,e,r,l),d=this.backgroundImageOptions?{default:new pt.Header({children:[new pt.Paragraph({children:[new pt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new pt.Document({numbering:{config:[...gZ,...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 pt.Packer.toBlob(h)}}async function eJ(n,t,e,r){const i=n.doc.buildResourceUrl(r,{withToken:!0});let o=await Kk(i);if(!o)return;if(o.type.indexOf("/svg")!==-1){const l=await Nk(o);l&&(o=new File([l],o.name))}return await o.arrayBuffer()}async function nJ(n,t,e){const r=n.editorBlocks.getBlockClass(e.type);if(r.toStandardDoc)return r.toStandardDoc(n,e,t)}async function rJ(n,t){const e=t.attributes,r=n.editorBoxes.getBoxClass(e.type);if(r.toStandardText)return r.toStandardText(n,e)}async function iJ(n,t){let{template:e,download:r,backgroundImageOptions:i}=t!=null?t:{};e||(e=aZ());const o=n.doc.toJSON(),s=(C,E,x)=>eJ(n,C,E,x),l=async(C,E,x)=>nJ(n,o,x),c=async C=>rJ(n,C),h=await new tJ(e,o,md.default,s,void 0,l,c,i).convert("_appId","_docId");if(r){const C=URL.createObjectURL(h),E=document.createElement("a");E.setAttribute("download",`${Fk(n)}.docx`),E.setAttribute("href",`${C}`),E.click(),E.remove()}return h}const QE=I("create-editor");async function oJ(n,t){var s,l,c,d,h,C,E,x,v,R,L,M,U,F;p(QE,n,"app does not exists"),t.lang&&D.setLang(t.lang),si.level=(s=t.logLevel)!=null?s:ws.DEBUG;const e=t.onReauth?async()=>{var at;const G=t.user.userId,q=t.docId,rt=await((at=t.onReauth)==null?void 0:at.call(t,G,q,t.permission));return{userId:G,docId:q,permission:t.permission,appId:t.appId,token:rt,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},i=await yu.load(r),o=hu(n,i,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,components:{blocks:[...V4,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...qE,...((c=t.components)==null?void 0:c.embeds)||[]],boxes:[...$4,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Zh,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new k0,new gp],insertions:[p1],blockHooks:[new rE,new CR,...((C=t.components)==null?void 0:C.blockHooks)||[]],textRenders:[new Iw,new gC],options:{...t.componentsOptions}},shortcuts:[BW,d$,bj,UC,sw,CP,SC,oq,Ch,uP,...t.shortcuts||[]],colors:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"]});if(o.editorCommandProviders.registerCommandProvider(new Ri(o)),o.input.addHandler(new qq),o.input.addHandler(new w0),o.input.addHandler(new OF),o.input.addHandler(new pj),o.input.addHandler(new zC(o,{hideTitle:t.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),o.input.addHandler(new E0(o,(E=t.componentsOptions)==null?void 0:E.quickMenu)),o.input.addHandler(new uE(o)),o.input.addHandler(new pE(o)),o.input.addHandler(new D0),o.doc.registerCallback(new Xq(o)),o.addCustom("remote-cursor",()=>new T2(o)),o.addCustom("block-menu",G=>new xR(G)),he.isMobile||o.addCustom("editor-tooltip",()=>new A0(o)),t!=null&&t.enableComments&&o.addCustom("editor-comments",G=>new Lw(G,new nZ(G))),o.addCustom("create-options",()=>new Jx(o,t)),o.addCustom("drop-target",()=>new of(o)),o.addCustom("list-to-mindmap",()=>new f0(o)),o.addCustom("list-to-mention",()=>new gX(o)),o.addCustom("mobile-helper",()=>new DX(o)),o.addCustom("code-caret",()=>new a$(o)),o.addCustom("image-paste-handler",()=>new cE(o)),(x=t.componentsOptions)!=null&&x.mention){const G=t.componentsOptions.mention;o.addCustom("mention",()=>new m4(o,G))}if(o.addCustom("heading-collapse",()=>new UE(o)),Ha.register(o),of.register(o),fs.register(o),os.register(o),o.addListener("clickLink",(G,q,rt)=>{var At;if((At=t==null?void 0:t.events)!=null&&At.onClickLink){t.events.onClickLink(G,q,rt);return}const at=rt.getAttribute("link");at&&(G.readonly||q.ctrlKey||q.metaKey)&&window.open(at,"_blank")}),(R=(v=t.componentsOptions)==null?void 0:v.remoteCarets)!=null&&R.onUserChanged){const G=(M=(L=t.componentsOptions)==null?void 0:L.remoteCarets)==null?void 0:M.onUserChanged;o.doc.getRemoteUsers().on("change",q=>{G(o,q)})}return(F=(U=t.componentsOptions)==null?void 0:U.templates)!=null&&F.templates.length&&(o.addListener("docChanged",()=>{Q0(o)}),o.addListener("resize",()=>{Q0(o,{reset:!0})}),setTimeout(()=>{Q0(o)},100)),o.doc.registerCallback({onError:async G=>{if(G.code==="ResetDoc"){QE.error(`reset doc: ${G.message}`);const q=await yu.load(r);o.doc.reset(q)}}}),o}function sJ(n){return n.toJSON!==void 0}async function lJ(n,t,e){var o,s,l,c,d,h;p(QE,n,"app does not exists");const r=sJ(t)?t:new q1(t,{serverUrl:e.serverUrl||""});e.lang&&D.setLang(e.lang),si.level=(o=e.logLevel)!=null?o:ws.DEBUG;const i=hu(n,r,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[MC,HC,jC,Hy],commandProviders:[new Zh],decorators:[new k0,new gp],embeds:[...qE,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[nk,g4,Fw,ok,...((l=e.components)==null?void 0:l.boxes)||[]],insertions:[p1],blockHooks:[new rE,...((c=e.components)==null?void 0:c.blockHooks)||[]],textRenders:[new Iw,new gC,...((d=e.components)==null?void 0:d.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[UC,sw,SC,Ch]});return i.editorCommandProviders.registerCommandProvider(new Ri(i)),i.input.addHandler(new w0),i.input.addHandler(new zC(i,{hideTitle:e.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new E0(i,(h=e.componentsOptions)==null?void 0:h.quickMenu)),i.input.addHandler(new uE(i)),i.input.addHandler(new pE(i)),i.input.addHandler(new D0),i.addCustom("block-menu",C=>new xR(C)),he.isMobile||i.addCustom("editor-tooltip",()=>new A0(i)),i.addCustom("image-paste-handler",()=>new cE(i)),e!=null&&e.enableComments&&i.addCustom("editor-comments",C=>new Lw(C,new rZ(C,r))),i.addCustom("heading-collapse",()=>new UE(i)),i.addListener("clickLink",(C,E,x)=>{var R;if((R=e==null?void 0:e.events)!=null&&R.onClickLink){e.events.onClickLink(C,E,x);return}const v=x.getAttribute("link");v&&(C.readonly||E.ctrlKey||E.metaKey)&&window.open(v,"_blank")}),Ha.register(i),i}function aJ(n,t,e){var h;const r=n.doc.externalDoc.client.auth,i=new k2({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 H4(l),d=n.addCustom("version-dialog",()=>new e4(i,c));return d.show(t),d}b.tippy=c6,b.AnchorBox=Q3,b.AuthError=Ih,b.AuthHeader=ya,b.AutoScroll=Ld,b.BaseURLHeader=Tu,b.BasicCommands=iF,b.BlockExclusiveHook=CR,b.BlockLockerHook=rE,b.BlockLockerPasteHandler=D0,b.BlockResizer=qu,b.BrBox=G3,b.CodeBlock=HC,b.CodeLineBlock=jC,b.CodeTextDecorator=k0,b.DefaultShortcuts=Ch,b.DocIdError=tU,b.DragDrop=Eb,b.DrawioEmbed=L4,b.EditorBlocks=wv,b.EditorBoxes=q3,b.EditorCommandProviders=NB,b.EditorComplexBlockPosition=Ur,b.EditorComplexSelectionRange=ui,b.EditorDecorators=t5,b.EditorEmbeds=Lv,b.EditorInsertions=J3,b.EditorSimpleBlockPosition=_e,b.EditorSimpleSelectionRange=Ge,b.EmbedBlock=Dv,b.EmbedBlockResizer=hf,b.EnforceWithDocumentTitleHandler=zC,b.EventCallbacks=ea,b.FILL_CHAR=v8,b.FileExtError=eU,b.GroupOrder=qy,b.HeadingBlockScrollListener=cX,b.ImageBox=X3,b.InlineBoxCommandProvider=sk,b.InputtingInsertion=Y3,b.LocalDoc=q1,b.LogLevel=ws,b.Logger=si,b.MIN_DISTANCE_THRESHOLD=pb,b.ManualCloseDialog=Ru,b.ManualMenu=rl,b.ManualToolbar=ku,b.MarkdownInputHandler=w0,b.MaxUserError=sp,b.Mindmap=u0,b.OnesEditorAutoSuggest=Op,b.OnesEditorCustomDataWrapper=Jx,b.OnesEditorExclusiveBlock=os,b.OnesEditorHoveringBlock=be,b.OnesEditorIcons=KU,b.OnesEditorQuickMenu=E0,b.OnesEditorToc=gf,b.OnesEditorTocProvider=fs,b.OnesEditorToolbar=Ha,b.OnesEditorTooltip=A0,b.OnesEditorVersionsDialog=e4,b.PermissionError=JM,b.Popup=Sa,b.RemoteCarets=T2,b.RemoteCaretsDecorator=gp,b.RemoteCaretsInsertion=p1,b.RemoteUsers=mu,b.RequestReloadError=Bu,b.RichText=dn,b.ShareDBDoc=yu,b.ShareDBDocVersionsProvider=H4,b.ShareDBServer=k2,b.SimpleCache=lb,b.StandardEmbedBlockCommands=wE,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=qg,b.TEXT_STYLE_COLOR_PREFIX=Wg,b.TableBlock=MC,b.TableBlockCommandProvider=Zh,b.TableShortcuts=UC,b.TextBlock=Mn,b.TextBox=z3,b.TextColorItem=KT,b.TextStyleShortcuts=SC,b.TocEmbed=d4,b.ZERO_WIDTH_SPACE_CHAR=Kc,b.abbreviation=Id,b.addAttribute=jd,b.addClass=z,b.addCommentToBlock=df,b.addDays=C9,b.addMetaToDoc=Ah,b.addMonths=p9,b.animateScrollTo=_s,b.applyPlaceholderToBlock=Gu,b.assert=p,b.autoShowHideTemplates=Q0,b.blockToDoc=z1,b.blockToHtml=A1,b.blockToMarkdown=x1,b.blockToText=oh,b.blocksToDoc=zD,b.clearAllSelection=uv,b.clientType=he,b.cloneBlock=zo,b.cloneChildContainer=I1,b.cloneDoc=D1,b.cloneText=U3,b.commentToShareDbComment=mp,b.compareElement=bd,b.comparePosition=Vg,b.complexBlockAdjustSelectionPos=Vd,b.complexBlockFindNearestChildBlock=Ov,b.complexBlockGeFirstSimpleChild=Hg,b.complexBlockGetAllChildContainers=xn,b.complexBlockGetBottomChildContainers=Uv,b.complexBlockGetLastSimpleChild=aa,b.complexBlockGetSelectedContainers=la,b.complexBlockGetTopChildContainers=Mv,b.containerToDoc=gB,b.continuousScroll=Ub,b.convertBlockFrom=Od,b.convertImageFileToPng=Nk,b.convertImageSrcToPng=IV,b.converterIntercept=R0,b.copyBlockAttributes=m5,b.copyResourcesFromDoc=W1,b.createBlockAnchor=Yi,b.createBlockCaretAnchor=Kv,b.createBlockContentElement=Ks,b.createBlockElement=ev,b.createBlockSimpleDocRange=th,b.createBlockSimpleRange=ve,b.createBoxContentElement=iv,b.createBoxElement=nv,b.createBoxOp=M3,b.createChildContainer=kv,b.createComplexBlockPosition=Ee,b.createComplexDocPos=V3,b.createComplexDocRange=y8,b.createContainer=P3,b.createContainerElement=Ng,b.createDeleteOps=L3,b.createEditor=hu,b.createEditorSelectionRange=We,b.createElement=B,b.createEmptyContainer=no,b.createEmptyDoc=eo,b.createEmptyTextBlockData=Zd,b.createExpandedRange=Ad,b.createIconButton=Ls,b.createImage=fg,b.createInsertOps=Qd,b.createInsertionContentElement=lv,b.createInsertionElement=ov,b.createLocalEditor=lJ,b.createOnesEditor=oJ,b.createRange=ab,b.createRichText=Xs,b.createRootContainer=yv,b.createSimpleBlockPosition=lt,b.createSimpleDocPos=K3,b.createTextBlockData=mi,b.createTextButton=cl,b.createTextOp=gr,b.createTextWithReplaceSoftReturn=s1,b.daysAfter=kg,b.deleteText=a1,b.diffDays=E9,b.disablePageScroll=Sb,b.docToHtml=c5,b.docToHtmlFragment=sh,b.docToMarkdown=u5,b.docToText=Qs,b.downloadImageToFile=Kk,b.downloadObjectToFile=$E,b.downloadSvgToString=b4,b.editLink=Pu,b.editorAddComment=mW,b.editorAddTextAttribute=y5,b.editorAutoInsertBlock=g5,b.editorBreakTextBlock=Ea,b.editorClearCompositionText=T1,b.editorClearSelectedContents=S1,b.editorCopyBlock=xh,b.editorDeleteBlock=R1,b.editorDeleteBlockText=y1,b.editorDeleteBlockWithoutChildren=ch,b.editorDeleteChildContainer=BD,b.editorDeleteChildContainers=p5,b.editorFocusToBlock=L1,b.editorFocusToEnd=HD,b.editorGetBlockData=jo,b.editorGetBlockText=bn,b.editorGetBlockTextEx=nh,b.editorGetBoxData=H3,b.editorHandleKeyboardEvent=AB,b.editorInsertBlock=Ca,b.editorInsertBoxToBlock=d5,b.editorInsertDoc=B5,b.editorInsertDocAt=_1,b.editorInsertText=B1,b.editorInsertTextToBlock=f5,b.editorInsertTextToBlockEx=v1,b.editorMergeTextBlock=C5,b.editorMoveDown=P5,b.editorMoveEnd=K1,b.editorMoveHome=q5,b.editorMoveLeft=U5,b.editorMoveLineEnd=nB,b.editorMoveLineHome=eB,b.editorMovePageDown=aB,b.editorMovePageUp=lB,b.editorMoveRight=O5,b.editorMoveUp=N5,b.editorMoveWordEnd=z5,b.editorMoveWordLeft=j5,b.editorRangeClearColor=R5,b.editorRangeGetColor=w5,b.editorRangeSetColor=k5,b.editorRemoveTextAttribute=RD,b.editorReplaceBlockText=fh,b.editorReplaceContainer=T5,b.editorRunOnce=X1,b.editorSelectAll=hB,b.editorSelectContainer=H1,b.editorSelectDown=F5,b.editorSelectEnd=V1,b.editorSelectHome=X5,b.editorSelectLeft=K5,b.editorSelectLineEnd=tB,b.editorSelectLineHome=J5,b.editorSelectPageDown=uB,b.editorSelectPageUp=cB,b.editorSelectRight=V5,b.editorSelectUp=$5,b.editorSelectWordEnd=W5,b.editorSelectWordLeft=G5,b.editorSetTextColor=Aa,b.editorShowFindDialog=xG,b.editorToDocx=iJ,b.editorUpdateBlockData=dh,b.editorUpdateCompositionText=h5,b.editorUpdateEmbedData=b5,b.enablePageScroll=Lb,b.escapeHtmlText=Bd,b.escapeRegExp=Lg,b.escapeSpace=t9,b.exclusiveBlock=tE,b.executeBlockCommand=Av,b.executeEmbedBlockCommand=Ev,b.executeRangeCommand=OB,b.fileToDataUrl=ia,b.findAfterOffsetNotType=h1,b.findAllText=u1,b.findEventTargetBlock=db,b.findInsertionById=sv,b.findNextOffset=z8,b.findNextVisibleSimpleBlock=$B,b.findPrevOffset=j8,b.findPrevOffsetNotType=d1,b.findPrevSimpleBlockBeforeChildContainer=_v,b.findPrevVisibleSimpleBlock=VB,b.findTarget=ra,b.findWordEnd=g1,b.findWordLeft=m1,b.format=Gc,b.formatBytes=Ob,b.formatDate=wg,b.fragmentToHtml=Ib,b.fromBase64=Hc,b.fromBase64ToBlob=vg,b.fromBase64ToUint8Array=f9,b.fromDocRange=Vo,b.fromNowString=Sg,b.genId=J,b.getAllChildBlocks=zg,b.getAllQuickMenuItems=wC,b.getAllSelectedBlocks=fi,b.getAttributesAt=da,b.getBlockBackground=tv,b.getBlockByIndex=zi,b.getBlockCaretRect=_r,b.getBlockClass=Zt,b.getBlockClassByType=Ns,b.getBlockClientRects=qi,b.getBlockCommandsWithHook=Ug,b.getBlockContent=Ot,b.getBlockId=st,b.getBlockIndex=bt,b.getBlockInfo=Ju,b.getBlockKind=Ir,b.getBlockMinWidth=dv,b.getBlockNearestRangeFromPoint=Fv,b.getBlockOptions=L9,b.getBlockPath=Ko,b.getBlockProperties=gv,b.getBlockRangeFromPoint=$d,b.getBlockStyles=S9,b.getBlockTextLength=dt,b.getBlockTools=ne,b.getBlockType=It,b.getBoxContent=Qc,b.getBoxId=rv,b.getBoxTypeFromElement=Xc,b.getChildBlockCount=Lr,b.getChildBlocks=Ce,b.getChildOffset=$o,b.getColorFromAttributes=Qg,b.getColorFromContent=Dd,b.getComplexBlockClass=qn,b.getContainerBlockPath=vv,b.getContainerBlocks=cv,b.getContainerBlocksElement=Fd,b.getContainerById=ci,b.getContainerId=ft,b.getContainerMinWidth=Fg,b.getContainerToolsElement=U9,b.getContainerWidth=Rv,b.getDistanceSquare=Vi,b.getElementOffset=Fc,b.getElementScale=ur,b.getEmbedType=un,b.getExistsBlockTools=_d,b.getExistsContainerById=Pd,b.getFileExt=zc,b.getFirstChildBlock=ke,b.getFirstClientRect=xd,b.getHeadingMenuOptions=vC,b.getHorizontalPadding=hg,b.getInsertionContent=Dg,b.getLastChildBlock=Ze,b.getLastClientRect=Is,b.getListAllNextBrothers=Pa,b.getLogger=I,b.getNextBlock=Gt,b.getNextValidOffset=Ws,b.getNextVisibleBlock=$s,b.getOffsetFromPoint=dg,b.getOffsetInfoAfter=ou,b.getOffsetInfoBefore=rh,b.getOpAt=d3,b.getOpLength=Hd,b.getParentBlock=nt,b.getParentBlockExcludeSelf=Fs,b.getParentBox=Ig,b.getParentContainer=it,b.getPrevBlock=me,b.getPrevValidOffset=Ho,b.getPrevVisibleBlock=Vs,b.getRangeCommands=MB,b.getReferenceClientRect=Ay,b.getRootBlock=Ud,b.getScrollContainer=cn,b.getSpecialBlockCommands=pv,b.getStandardEmbedBlockProperties=SE,b.getTextAfterOffset=$8,b.getTextAttributes=b1,b.getTextBeforeOffset=H8,b.getTextBlockChild=Nd,b.getTextBlockClass=Wb,b.getTextBlockContentChildTextLength=mr,b.getTextBlockContentChildType=xv,b.getTextBlockContentChildren=ai,b.getTextLength=fn,b.getTextOpLength=Gg,b.getTextWidth=Rd,b.getToolbar=i0,b.handleBlockElementUpdated=hv,b.hasAltOnly=s9,b.hasClass=Rt,b.hasCtrlOrCmd=Tb,b.hasCtrlOrCmdOnly=o9,b.hashCode=Hb,b.hideBlock=Zb,b.htmlToFragment=kd,b.i18n=D,b.injectDocToHtmlFragment=Eh,b.injectStyle=gb,b.insertEmptyBlock=_9,b.insertEmptyEmbedBlock=Og,b.insertText=to,b.intersectionCommands=G_,b.isBackspace=kb,b.isBlock=Ps,b.isBlockLocked=I0,b.isBlockLockedByOthers=nE,b.isBlockLockedBySelf=tf,b.isBlockTools=Yb,b.isBox=Md,b.isBoxOp=zs,b.isCJK=vb,b.isChildContainer=Mr,b.isChildNode=ee,b.isCodeBlock=vi,b.isCollapsedRange=T8,b.isComplexBlockPosition=sa,b.isComplexKindBlock=_t,b.isContainer=Wi,b.isContainerSelectedAllChildBlocks=fB,b.isControlEvent=Us,b.isDelete=a9,b.isDraggingFiles=wd,b.isElementVisible=pg,b.isEmbedBlock=Re,b.isEmptyContainer=Jc,b.isEmptyDoc=f1,b.isEmptyTextBlock=re,b.isEmptyTextBlockWithoutCompositionText=zu,b.isEnterOnly=yb,b.isEscape=xg,b.isExclusiveBlock=Zu,b.isFirefox=yd,b.isFirstChildBlockInComplexBlock=hI,b.isHighSurrogate=Q6,b.isInBlock=_g,b.isInBlockTools=Hs,b.isLetter=bb,b.isLowSurrogate=Y6,b.isMatchShortcut=li,b.isMoveForward=r9,b.isNavigationEvent=n9,b.isNavigationKey=Bb,b.isNodeRemoved=ub,b.isNumber=xb,b.isPrintableKey=Ag,b.isRootBlock=dr,b.isRootContainer=Qt,b.isSafari=$c,b.isSameDay=Rg,b.isSecureEnv=VC,b.isSelectBoxOnly=jy,b.isShiftEnter=l9,b.isShiftTab=u9,b.isShortcutEvent=i9,b.isSimpleBlock=w9,b.isSimpleBlockPosition=Or,b.isSimplePos=F3,b.isSimpleRange=Jd,b.isSpace=Td,b.isTab=c9,b.isTextBlockContentBoxChild=hr,b.isTextBlockContentChild=Yc,b.isTextBlockContentInsertionChild=Qi,b.isTextBlockContentTextChild=Zc,b.isTextKindBlock=et,b.isTextKindBlockType=Wc,b.isTitleBlock=Gi,b.isToday=Nb,b.isValidOffset=_n,b.isVisibleBlock=qc,b.isYesterday=Pb,b.loadJs=fb,b.loadJsPromise=Ds,b.lockers=Sr,b.mergeCommands=r0,b.mergeDocs=Ys,b.mergeOps=l1,b.mergeText=x8,b.multiSplitText=m3,b.overflowText=Fb,b.parseShortcut=Rb,b.patchNode=jc,b.pointInRect=Ms,b.rangeAddAttribute=nu,b.rangeGetTextColor=b3,b.rangeRemoveAttribute=fa,b.rangeSetTextColor=E3,b.rangeTransformText=p3,b.registerDragDrop=Cg,b.removeAttribute=Xg,b.removeClass=ot,b.removeLastBr=p8,b.removePlaceholderFromBlock=Hk,b.removeStyle=mb,b.replaceAll=A9,b.replaceAllCaseInsensitive=x9,b.replaceAllText=N3,b.replaceText=Yd,b.requestDownload=Sd,b.resetListStart=Ka,b.scrollable=Mb,b.selectFile=oa,b.selectedBlockToDoc=mh,b.selectionToDoc=gh,b.setAttributes=vd,b.setClipboardData=yg,b.setClipboardDataByEvent=g9,b.setColorToAttributes=A3,b.setDataset=mg,b.setDefaultCursor=Vc,b.setStyles=gg,b.shareDBCommentToDocObject=hp,b.shareDBDocCommentToComment=v2,b.shortcutToDisplayText=fr,b.showBlock=Jb,b.showDocVersions=aJ,b.splitText=In,b.splitToThree=qe,b.stringToDataUrl=Bg,b.stringToObjectUrl=Tg,b.subText=g3,b.textNodeOffsetFromPoint=cb,b.titleFromEditor=Fk,b.toBase64URL=ji,b.toMindmap=c0,b.toPlainText=ce,b.toPlainTextKeepLength=c1,b.trimChar=Eg,b.unexclusiveBlock=eE,b.unicodeLength=Z6,b.unicodeSubstr=J6,b.updateBlockSelection=fv,b.updateOpAttributes=O3,b.updateTextBlockContent=V8,b.updateUrl=bg;for(const n in ye)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>ye[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
958
|
+
\`\`\`\`\`\``}return""}const yY={embedType:"plantuml",convertFrom:vY,handleUpdateBlock:bY,createEmbedContent:xY,getBlockProperties:BY,convertTo:TY},Rlt="",kY="hr",RY={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},wY={dividingLine:{type:"Dividing-Line",abstract:"Dividing-Line"}},SY={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};D.mergeLang({"zh-CN":RY,"en-US":wY,"ja-JP":SY});function LY(n,t){const e=B("div",["editor-embed-container"],t);B("hr",["editor-embed-hr"],e)}function IY(n,t,e,r){return r==="html"?"<hr />":r==="markdown"?"---":"------------"}function DY(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:D.t("dividingLine.type"),icon:nT,order:500,group:"common",subText:Bn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:r}=t;return n.insertEmbed(e,r,kY,{})}}}function _Y(n,t,e){const{data:r}=e;if(!r||r.embedType!=="dividing-line"||!et(n,t))return null;const i={};return{blockData:{id:J(),type:"embed",embedType:"hr",embedData:i}}}function MY(){return{abstract:D.t("dividingLine.abstract")}}const UY={embedType:"hr",createEmbedContent:LY,convertTo:IY,getOptions:DY,convertFrom:_Y,getBlockProperties:MY},wlt="",Slt="",OY={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"}}},NY={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"}}},PY={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"}}};D.mergeLang({"zh-CN":OY,"en-US":NY,"ja-JP":PY});var Qr=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(Qr||{}),pf=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(pf||{});const U4=10*1024*1024,FY=["wav","mp3","aac","ogg","webm","flac"],KY=["ogg","mp4","webm"],VY=()=>{};function O4(n){var h,C,E,x,v,R;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:FY,s=(E=e==null?void 0:e.video)!=null?E:KY,l=(x=r==null?void 0:r.audio)!=null?x:U4,c=(v=r==null?void 0:r.video)!=null?v:U4,d=(R=i==null?void 0:i.onError)!=null?R:VY;return{allowedMedias:{audio:o,video:s},maxSize:{audio:l,video:c},callbacks:{onError:d}}}function $Y(n,t){const e=o=>o.map(s=>`.${s}`).join(","),{allowedMedias:r}=O4(n),i=r[t];return i?e(i):"*"}function HY(n,t,e){const{maxSize:r,callbacks:i,allowedMedias:o}=O4(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=zc(n.name);if(l&&!l.includes(rn.exports.lowerCase(c))){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 jY(n){return n===pf.Empty||n===pf.Error}const Qe=I("media");class zY extends ye.TypedEmitter{constructor(e){super();g(this,"mediaContainer",null);g(this,"media",null);g(this,"abstract",null);g(this,"handleMediaLoadError",(e,r)=>{if(!r.target||!(r.target instanceof Node)||!(r.target instanceof Element?r.target:r.target.parentElement))return;const o=nt(r.target);if(!o||!o.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",st(o))});g(this,"handleUploadFile",async e=>{p(Qe,this.abstract,"no abstract"),p(Qe,this.mediaContainer,"The media element not exist");const{editor:r}=this.options,i=nt(this.mediaContainer);p(Qe,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){Qe.error(s),this.emit("mediaError",r,"upload_error",o.id),this.renderRetry(e,s)}ot(i,"media-block-uploading")});g(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(Qe,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){p(Qe,this.abstract,"no abstract");const{editor:e,createMediaElement:r}=this.options,{mediaIcon:i,mediaName:o}=this.abstract;p(Qe,this.mediaContainer,"The media element not exist");const s=nt(this.mediaContainer);p(Qe,s,"The block element not exist");const l=e.getBlockData(s),c=l.embedData.src,d=B("div",["media-error","embed-selected-content","embed-hover-content"],null),h=B("span",["media-error-icon"],d);h.innerHTML=i;const C=B("div",[],d);C.innerHTML=D.t("media.load.failed",{name:o}),d.appendChild(C);const E=C.querySelector(".retry-upload");return p(Qe,E,"The element not exist"),e.domEvents.addEventListener(E,"click",(x,v)=>{const R=B("div",["media-element"],null),L=this.getResourceUrl(c),M=r(x,R,l,L);this.unbindMediaEvent(),this.media=M,this.bindMediaEvent(),this.updateMediaContent(R)}),this.setFullScreen(),d}renderRetry(e,r){var E,x;p(Qe,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=D.t("media.upload.failed",{name:s});(((E=r.response)==null?void 0:E.status)===420||((x=r.response)==null?void 0:x.status)===413)&&(h=D.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(Qe,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(l),this.setFullScreen()}renderProgress(e,r){p(Qe,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=nt(this.mediaContainer);p(Qe,l,"The element not exist"),z(l,"media-block-uploading");const c=B("div",["media-progress"],null);s(c,o,r),this.updateMediaContent(c)}this.setFullScreen()}renderMediaElement(e){p(Qe,this.mediaContainer,"The media element not exist");const r=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:i,updateMediaElement:o,editor:s}=this.options,l=this.getResourceUrl(e.embedData.src);if(r){const c=o(s,r,e,l);this.unbindMediaEvent(),this.media=c,this.bindMediaEvent()}else{const c=B("div",["media-element"],null),d=i(s,c,e,l);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent(),this.updateMediaContent(c)}}renderEmpty(e){p(Qe,this.abstract,"no abstract"),p(Qe,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){const{editor:r}=this.options;return r.doc.buildResourceUrl(e)}setFullScreen(){p(Qe,this.mediaContainer,"The media element not exist"),z(this.mediaContainer,"full-screen")}removeFullScreen(){p(Qe,this.mediaContainer,"The media element not exist"),ot(this.mediaContainer,"full-screen")}updateBlockAlign(e,r){const i=nt(r);p(Qe,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),jY(i)?i===pf.Empty&&this.renderEmpty(e):this.renderMediaElement(e)}setAbstract(e){this.abstract=e}}I("media-embed");const GY="left";class N4{constructor(){g(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=$Y(t,this.embedType);if(o=o!=null?o:await oa(s,{}),!o)return null;const{mediaType:l}=this.getAbstract();try{HY(o,t,l)}catch{return null}const c={id:J(),type:"embed",embedType:this.embedType,embedData:{src:pf.Empty}};l==="video"&&(c.align=GY);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 zY({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:Bn(`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=Ot(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"?``:s}}function P4(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 F4(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const WY=I("media-audio");class qY extends N4{constructor(){super(...arguments);g(this,"embedType",Qr.AUDIO);g(this,"updateProgressElement",F4);g(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:J2,mediaName:D.t(`media.${Qr.AUDIO}.menuItem`),menuItem:D.t(`media.${Qr.AUDIO}.menuItem`),order:800,mediaType:Qr.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${Qr.AUDIO}.abstract`)}`}}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .audio-container > audio");return p(WY,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",P4(e,r)}}const XY=new qY;I("video-resizer");function K4(n){return n&&Re(n)&&un(n)==="video"}const QY=50;class WE{constructor(t){g(this,"currentResizableElement",null);g(this,"resizing",!1);g(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&K4(e)&&this.disableBlockResize(e),t&&K4(t)&&this.editor.isBlockWritable(t))){const r=this.getVideoElement(t);if(!r)return;this.enableBlockResize(t,r)}});g(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,QY),i);this.currentResizableElement.style.width=`${o}px`,this.currentResizableElement.style.pointerEvents="none"});g(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,be.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Ot(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${st(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${st(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const r=this.editor.addCustom(`${st(t)}-resizer`,()=>new qu(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 YY=I("video");class ZY extends N4{constructor(){super(...arguments);g(this,"embedType",Qr.VIDEO);g(this,"updateProgressElement",F4);g(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 WE(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});g(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,P4(e,r),ia(i).then(s=>{const l=e.querySelector(".progress-video");l&&_g(e)&&(l.src=s)})})}getAbstract(){return{mediaName:D.t(`media.${Qr.VIDEO}.menuItem`),mediaIcon:tT,menuItem:D.t(`media.${Qr.VIDEO}.menuItem`),order:700,mediaType:Qr.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${Qr.VIDEO}.abstract`)}`}}handleMediaError(e,r,i){const o=e.addCustom("video-resizer",()=>new WE(e)),s=e.getBlockById(i);o.disableBlockResize(s)}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .video-container > video");p(YY,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 WE(e)).updateResizer(l)}),s}}const JY=new ZY,V4=[MC,HC,jC,Hy],qE=[L4,tQ,aY,CY,yY,IF,UY,JY,XY,Mj,d4,JW],$4=[nk,g4,Fw,ok];function tZ(n,t,e){var i,o,s,l;si.level=(i=e.logLevel)!=null?i:ws.DEBUG;const r=hu(n,t,{components:{blocks:[...V4,...((o=e==null?void 0:e.components)==null?void 0:o.blocks)||[]],embeds:[...qE,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[...$4,...((l=e.components)==null?void 0:l.boxes)||[]],textRenders:[new gC],options:{...e.componentsOptions}}});return r.readonly=!0,r.addCustom("heading-collapse",()=>new UE(r)),r.addCustom("editor-tooltip",()=>new A0(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 H4{constructor(t){this.createOptions=t,t.lang&&D.setLang(t.lang)}createHistoryEditor(t,e){return tZ(t,e,this.createOptions)}}I("create-editor");function j4(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=hu(t,e,{shortcuts:[Ch],components:{blocks:s,commandProviders:[new Zh],decorators:[new k0],embeds:l,boxes:c,options:o}});if(d.input.addHandler(new w0),d.input.addHandler(new uE(d)),d.input.addHandler(new pE(d)),d.input.addHandler(new fW(d)),d.input.addHandler(new D0),d.addCustom("image-paste-handler",()=>new cE(d)),(h=n.options.componentsOptions)!=null&&h.mention){const E=n.options.componentsOptions.mention;d.addCustom("mention",()=>new m4(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 eZ(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),r=new Set;e.forEach(i=>{const o=nt(i);o&&r.add(o)}),r.forEach(i=>{dW(n,i,t)})}class nZ{constructor(t){g(this,"listeners",new Set);g(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&&eZ(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 j4(this.editor,{root:t,childDoc:e,doc:this.doc})}allowEdit(t){return t.userId===this.doc.getUser().userId}}class rZ{constructor(t,e){g(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 hp(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 j4(this.editor,{root:t,childDoc:e,doc:this.localDoc})}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const iZ={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}"}},oZ={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}"}},sZ={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"}};D.mergeLang({"zh-CN":iZ,"en-US":oZ,"ja-JP":sZ});const lZ="UEsDBBQABgAIAAAAIQBk9WPugQEAACkGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0lMtqwzAQRfeF/oPRtsRKuiilxMmij2UbaArdKvI4EdULaZzH33fsJKYUJy5NsjHIM/feowHNcLw2OllCiMrZjA3SPkvASpcrO8/Yx/Sld8+SiMLmQjsLGdtAZOPR9dVwuvEQE1LbmLEFon/gPMoFGBFT58FSpXDBCKRjmHMv5JeYA7/t9++4dBbBYg8rDzYaPkEhSo3J85p+b0kC6MiSx21jlZUx4b1WUiDV+dLmv1J6u4SUlHVPXCgfb6iB8daEqnI4YKd7o9EElUMyEQFfhaEuvnIh57mTpSFletymhdMVhZLQ6Cs3H5yEGGnmRqcIxtMNIDVC2T1/G4csIzrzaTRXpJkE5+PgZJzGtPKDgAqaGR6chS3NDALRn38YjXUnRMSNhnh+gq1vdzwgkuASADvnToQVzN4vRvHDvBOkoNypmGk4P0Zj3QmBtIpg+z39VdQ2xyKps36AtNrCP669312Vuuf/9PKaRLI++X5QrcUc8pZsXi/60TcAAAD//wMAUEsDBBQABgAIAAAAIQAekRq37wAAAE4CAAALAAgCX3JlbHMvLnJlbHMgogQCKKAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJLBasMwDEDvg/2D0b1R2sEYo04vY9DbGNkHCFtJTBPb2GrX/v082NgCXelhR8vS05PQenOcRnXglF3wGpZVDYq9Cdb5XsNb+7x4AJWFvKUxeNZw4gyb5vZm/cojSSnKg4tZFYrPGgaR+IiYzcAT5SpE9uWnC2kiKc/UYySzo55xVdf3mH4zoJkx1dZqSFt7B6o9Rb6GHbrOGX4KZj+xlzMtkI/C3rJdxFTqk7gyjWop9SwabDAvJZyRYqwKGvC80ep6o7+nxYmFLAmhCYkv+3xmXBJa/ueK5hk/Nu8hWbRf4W8bnF1B8wEAAP//AwBQSwMEFAAGAAgAAAAhADPCW79BAQAA5wQAABwACAF3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJQxT8MwEIV3JP5D5B07LVAQatoFkDqwQJFYneSSWI3tyL6Q9t9zojRNRYkYPN6z7r1P57Pny62uo09wXlmTsAmPWQQms7kyZcLe189X9yzyKE0ua2sgYTvwbLm4vJi/Qi2RmnylGh+Ri/EJqxCbByF8VoGWntsGDJ0U1mmJVLpSNDLbyBLENI5nwg092OLEM1rlCXOrnPLXuwb+422LQmXwaLNWg8EzEQKpF8hQuhIwYd/lXpxwMmPiPMN1SAaPu5qG2EPs67H4u5DxhTW4lmk9GEMvjUFMQ0KYVqfgaMeOEL00BjEJCZG1Hq3+oLQegvOjKhSCHl2LWUiaipxcrczmSPNj23UdT6XKW55ZLQ7HLzan5KctgjPyT8TbkIgdpG+ASHc0WN+BODarm6BP6BfFQTkgiJPvafEFAAD//wMAUEsDBBQABgAIAAAAIQBOMo6QFgYAAKYkAAARAAAAd29yZC9kb2N1bWVudC54bWzUWttu40QYvkfiHSJfLRKtz4eYTVeOD7uVQKoo+wCuPUmstT3WeNI0XC0XC1wguOBiuWClLgjBE4AEiIdZ0T28BTM+JM6h7cTZkm0vEnv+mW+++eb7/0yc3r13lsSdU4DyCKY9TtwXuA5IAxhG6bDHPfzM2zO4To79NPRjmIIeNwU5d+/g/ffuTswQBuMEpLhDINLcnGRBjxthnJk8nwcjkPj5fhIFCOZwgPcDmPBwMIgCwE8gCnlJEIXiKkMwAHlO5rP99NTPuQouOGNDC5E/IYMpoMIHIx9hcDbHEDcGUfkub6wCSS2AyAolcRVK3hhK4ymrFSClFRBhtYKktkNaszitHZK0iqS3Q5JXkYx2SCt2SlYNDjOQkuAAosTH5BYN+cRHj8bZHgHOfBydRHGEpwRT0GoYP0oftWBERs0QEjncGEHnExiCWA5rFNjjxig1q/F7s/GUulmOr97qEYhl/eUQpyoOxcp5BGKiBUzzUZTNMjxpi0aCoxrk9KpFnCZx3W+SiYzpcll5ckop54As9Cv9k7hkfjWiKDDsCIWYjWChsDhnzSQhLpxP3EqahrgiYwGpAaQVAC0AjAW/xjAqDD6YZyjFiRhTo8Ypd4XiRHNhRcY6tkymAZCDzSDUmkc+TRoryobb2fY+guNsjhZth3Y4L0ITehzYAKuyfzMl8+3IHI/8jNSmJDAPhylE/klMGBEzd4gfO8UO0FeyrfStuARnHVoIuANyfDmB4ZS+ZySimJmP/EPiHEV2dE+3La5oJcUf01a9+iOtJjkqhZ/2OEEQJE1z5FmTAwb+OMY04nUVRRfryFGjqZjwCBVvx3gaE4bmqR/3uAfAp2cukeNpDJVdYj8d1h1AuvfwmEb5KszPkMqX6tqDKc7JoFGUEi7Az7GVR35z4MTEBy/Pv3rz0w+0CZeBZZwrp6ajxIXBlMwaMT2l6wh9lUHMRcnejpjSDYrJoND2GksMGquOY+iu7exIY/m2ayyzaKwaqi4YNNd3obFy2zVWGDTW+7Il296uaoX6LmisMugkKIpouJqwI5202+5FjUFjTfQ8S7OMHWms33aNdQaNJd3qqoq8q5pq3HaNDRaNNcFzRafLoLGtaF2JdlzReDFSaFw1NTTeRMf1XBVLNcSux+KHnXOVBddQLEm6DVxVSxf6nubdPNfFPLNhCCqWdRxBOHARIj3wNCNf1YbIT46xj3CVi6WxA5jmMAb7MRzeWUqQtQhuGi6Mf/H4xxGIY/hhh3xbjMMXj5998BFDrsiSZnuiYjPoZLiC7fV3rVM+zTFI9uEY72eI1KA4baPWnZZyiYYu2oLFlK6u2C3OzqtyLURaytXME8Zvv//+9fOr8y8unj1lWKjqeroraMpWvliMFAutmoq9WDp9aJohGzrLN7o2M7asLrVj6MMbM8/8gBgqQyAH6BRwB5RlZ8l/1HgFrSO0NH29Wws7e5jGUQoa+zvbLgwuQ26YiBGX2SOvn39z8eWT0ik3tbAzvIzMuiuXbkRndSfW+1rRlb7nKExng00SeDuXXcK1qwiWJi99hmme4uiaRfNkJ1wXt2u78+Dr35+8+vPXJTeMSNVGxDuPOsiMyILRYahR/qMoxxBNSREuTbdox+vy4UGNem06MPB+8/0/L7/9ZdluM+JvV6SX539c/P0dg7eFru3alrhUs1VH6kuqPD/gULUcRVAdd51fFiM35m21L3ueJNOJGlwFQ1FFxZ0beQ3Xcrs3WkDV1FjA4qfrx8RZR4QYOSlko3JX0nFS9ozi07juJ8xih2HdVjy65mcDGlmyljCbK5rbf/H109fPf7u6FjfA2R5Rq47sCZq2JL/ueo5o2VfK//8oXf0g8K4rvcf0c4DrGX25v3TElmzV1foiLe47tfrGZf16xWbiLMlTh/yTCmauWA4CfDST+jopimUNjz8nwQnxhSQp9LmgOSLXqqFUWZoNP/EpIoYZaVfKLigajvD89gRiDJP5fQwGjegI+CEg8+oCfSRmDiDEjdvhGBe31XQBjKle1cmE9imaQxjcR/SnOJOeho4iHBCWslYM4ut1F5flD3P8/B+MDv4DAAD//wMAUEsDBBQABgAIAAAAIQC29GeY0gYAAMkgAAAVAAAAd29yZC90aGVtZS90aGVtZTEueG1s7FlLixtHEL4H8h+Guct6zehhrDXSSPJr1zbetYOPvVJrpq2eadHd2rUwhmCfcgkEnJBDDLnlEEIMMcTkkh9jsEmcH5HqHkkzLfXEj12DCbuCVT++qv66qrq6NHPh4v2YOkeYC8KSjls9V3EdnIzYmCRhx719MCy1XEdIlIwRZQnuuAss3Is7n392AZ2XEY6xA/KJOI86biTl7Hy5LEYwjMQ5NsMJzE0Yj5GELg/LY46OQW9My7VKpVGOEUlcJ0ExqL0xmZARdg6USndnpXxA4V8ihRoYUb6vVGNDQmPH06r6EgsRUO4cIdpxYZ0xOz7A96XrUCQkTHTciv5zyzsXymshKgtkc3JD/beUWwqMpzUtx8PDtaDn+V6ju9avAVRu4wbNQWPQWOvTADQawU5TLqbOZi3wltgcKG1adPeb/XrVwOf017fwXV99DLwGpU1vCz8cBpkNc6C06W/h/V671zf1a1DabGzhm5Vu32saeA2KKEmmW+iK36gHq92uIRNGL1vhbd8bNmtLeIYq56IrlU9kUazF6B7jQwBo5yJJEkcuZniCRoALECWHnDi7JIwg8GYoYQKGK7XKsFKH/+rj6Zb2KDqPUU46HRqJrSHFxxEjTmay414FrW4O8urFi5ePnr989PvLx49fPvp1ufa23GWUhHm5Nz9988/TL52/f/vxzZNv7XiRx7/+5avXf/z5X+qlQeu7Z6+fP3v1/dd//fzEAu9ydJiHH5AYC+c6PnZusRg2aFkAH/L3kziIEMlLdJNQoAQpGQt6ICMDfX2BKLLgeti04x0O6cIGvDS/ZxDej/hcEgvwWhQbwD3GaI9x656uqbXyVpgnoX1xPs/jbiF0ZFs72PDyYD6DuCc2lUGEDZo3KbgchTjB0lFzbIqxRewuIYZd98iIM8Em0rlLnB4iVpMckEMjmjKhyyQGvyxsBMHfhm327jg9Rm3q+/jIRMLZQNSmElPDjJfQXKLYyhjFNI/cRTKykdxf8JFhcCHB0yGmzBmMsRA2mRt8YdC9BmnG7vY9uohNJJdkakPuIsbyyD6bBhGKZ1bOJIny2CtiCiGKnJtMWkkw84SoPvgBJYXuvkOw4e63n+3bkIbsAaJm5tx2JDAzz+OCThC2Ke/y2EixXU6s0dGbh0Zo72JM0TEaY+zcvmLDs5lh84z01QiyymVss81VZMaq6idYQK2kihuLY4kwQnYfh6yAz95iI/EsUBIjXqT5+tQMmQFcdbE1XuloaqRSwtWhtZO4IWJjf4Vab0bICCvVF/Z4XXDDf+9yxkDm3gfI4PeWgcT+zrY5QNRYIAuYAwRVhi3dgojh/kxEHSctNrfKTcxDm7mhvFH0xCR5awW0Ufv4H6/2gQrj1Q9PLdjTqXfswJNUOkXJZLO+KcJtVjUB42Py6Rc1fTRPbmK4RyzQs5rmrKb539c0Ref5rJI5q2TOKhm7yEeoZLLiRT8CWj3o0Vriwqc+E0LpvlxQvCt02SPg7I+HMKg7Wmj9kGkWQXO5nIELOdJthzP5BZHRfoRmsExVrxCKpepQODMmoHDSw1bdaoLO4z02Tker1dVzTRBAMhuHwms1DmWaTEcbzewB3lq97oX6QeuKgJJ9HxK5xUwSdQuJ5mrwLST0zk6FRdvCoqXUF7LQX0uvwOXkIPVI3PdSRhBuENJj5adUfuXdU/d0kTHNbdcs22srrqfjaYNELtxMErkwjODy2Bw+ZV+3M5ca9JQptmk0Wx/D1yqJbOQGmpg95xjOXN0HNSM067gT+MkEzXgG+oTKVIiGSccdyaWhPySzzLiQfSSiFKan0v3HRGLuUBJDrOfdQJOMW7XWVHv8RMm1K5+e5fRX3sl4MsEjWTCSdWEuVWKdPSFYddgcSO9H42PnkM75LQSG8ptVZcAxEXJtzTHhueDOrLiRrpZH0Xjfkh1RRGcRWt4o+WSewnV7TSe3D810c1dmf7mZw1A56cS37tuF1EQuaRZcIOrWtOePj3fJ51hled9glabuzVzXXuW6olvi5BdCjlq2mEFNMbZQy0ZNaqdYEOSWW4dm0R1x2rfBZtSqC2JVV+re1ottdngPIr8P1eqcSqGpwq8WjoLVK8k0E+jRVXa5L505Jx33QcXvekHND0qVlj8oeXWvUmr53Xqp6/v16sCvVvq92kMwioziqp+uPYQf+3SxfG+vx7fe3cerUvvciMVlpuvgshbW7+6rteJ39w4Byzxo1IbtervXKLXr3WHJ6/dapXbQ6JX6jaDZH/YDv9UePnSdIw32uvXAawxapUY1CEpeo6Lot9qlplerdb1mtzXwug+Xtoadr75X5tW8dv4FAAD//wMAUEsDBBQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAd29yZC9zZXR0aW5ncy54bWy0Vttu2zgQfV9g/8HQ8zq6WHZsoU4R3zYp4nZRebHPlETZRHgRSMqu8/U7pETLu3ELp0VeEmrOzJkh53DoDx+/MdrbY6mI4FMvvAm8Hua5KAjfTr2/N6v+2OspjXiBqOB46h2x8j7e/f7bh0OisNbgpnpAwVXC8qm307pKfF/lO8yQuhEV5gCWQjKk4VNufYbkc131c8EqpElGKNFHPwqCkdfSiKlXS560FH1GcimUKLUJSURZkhy3/1yEvCZvE7IQec0w1zajLzGFGgRXO1Ipx8Z+lg3AnSPZ/2gTe0ad3yEMrtjuQcjiFHFNeSagkiLHSkGDGHUFEt4ljl8RnXLfQO52i5YKwsPArs4rH76NIHpFMMrxt7dxjFsOHyLPeUjxNp7RiYd0BxuOfq6YMwKF30YxdHWoI+t2pOg1PW6gJ5JJJJsb1DaY5cnjlguJMgrlQKN70Kuerc78hS2bf3YJOe/gIr8IwXqHpMIyBzXDFAgCzzdABtXBaFiIz0KntZSi5sUDRmD7LrwSQrcwKFCUqUYa8iZbiRjc/amXU4x4Q1/gEtVUb1CWalGB0x7B1m+jNnu+QxLlwJZWKAcdzwXXUlDnV5i0c5gjEmTeRtipYla1wqvlEzqKWp8haTOxgIEjBofznym0FgWMFAiV5PoumgBbTTg8L+H/iQRMWEkKvDFNSfWR4hVsJiUv+J4Xn2qlCTDaWfQLFfyoAMxN5i8go82xwiuMdA3H9k7JbGdWlFRrAqKQj7wAWb1bMlKWWEICAkJbg5yIFAd7zo1S3ysvKOwfcIZbPNiATJ9nQmvBHo7VDs761zpp9e+fyxme50K5xVe4YifXYBEHw8WyqdSgHRJEo9FicAkJV9Eyvr+EjJfBfDW7hMxm0WB+ewmZx6NJNLmILMPJ+GIFCyhiPL+IfHc/q0kc39qe+KcTYYl5dv+SbmWuVY81EXPEMklQb20eZt94ZPJ5RrjDMwzzFJ8jaZ05sN9vAMUQpStosANsc1hSEFUtcGnXdI3ktuNtPeRFK8y8TycuM26x/BMGZ9WgB4mq5ro4lzCO20jC9RNhzq7qLHVRHF6AMwim8Je9tOfUHc8h0SA/O3aekJWx9cW8P/9shIeR0veKoKn3sjOmRvlUpka1eI2qqhF/tg2nHiXbnQ5NmIavAn7S2Y9sG7VYZLGowewHys1mwbtddLbI2c78Bs426Gyxs8Wdbehsw842craRse1g3ElK+DPcQ7c09lJQKg64eOjwVyb3SuUERJAeWdY9PjcNRomCwVDBO6WFdNgfFgvjpBD5o3ls48Y+nIwXy8mg0XY4tO+btrMDjvYrLmdI4aJRt/tpffcvAAAA//8DAFBLAwQUAAYACAAAACEAQMH/8TkBAAAjAwAAFAAAAHdvcmQvd2ViU2V0dGluZ3MueG1snNJfT8IwEADwdxO/w9J36CCykIVBYgzGF2OifoDS3aCx7S294sBP720CYnhhvvT//XLXdrbYOZt8QiCDvhCjYSoS8BpL49eFeH9bDqYioah8qSx6KMQeSCzmtzezJm9g9Qox8klKWPGUO12ITYx1LiXpDThFQ6zB82aFwanI07CWToWPbT3Q6GoVzcpYE/dynKaZODDhGgWrymh4QL114GMXLwNYFtHTxtR01JprtAZDWQfUQMT1OPvjOWX8iRndXUDO6ICEVRxyMYeMOorDR2k3cvYXmPQDxhdApmHXz5geDMmR544p+znZyTHlmfO/ZM4Agn7E5JgH7V1bkdP509pjUCvLEr9RwtecdHDbcrZt1w35+Jx/LdbROPMFSwz3ARuCINtlZS02L8+PPJF/vvb8GwAA//8DAFBLAwQUAAYACAAAACEAOdtFTLkFAAAnWgAAEgAAAHdvcmQvbnVtYmVyaW5nLnhtbOyczW7qRhiG95V6D8j7xP8/oEOOwECV6rQ60knV9WAGsGKPrbGB0FV7Ke266q430EvpDfQWOuOxzZ9DbIMw5MwmDuP5Xs/3zjfDk0nCh48vvtdaQhy5AeoK8r0ktCBygomLZl3hp6fRnSW0ohigCfACBLvCGkbCx4dvv/mw6qCFP4aYdGwRDRR1VqHTFeZxHHZEMXLm0AfRve86OIiCaXzvBL4YTKeuA8VVgCeiIslS8l2IAwdGEdGxAVqCSEjlnJdyahMMViSYCmqiMwc4hi8bDbmyiC62RetQSKkhRDJU5EMptbKUIdJRHQhptYTIqA6U9HpKBckZ9ZSUQyWznpJ6qGTVUzooJ/+wwIMQInJzGmAfxOQlnok+wM+L8I4IhyB2x67nxmuiKRmZDHDRc40RkahcwVcnlRVM0Q8m0FMnmUrQFRYYddL4uzyeDr3D4tNLFoHL5M9CBoGz8CGKk8xFDD3iRYCiuRvmK9yvq0ZuzjOR5bEklr6X9VuFcsnl8tr2NGBWbgTLDD/13/fYyI8rylKJGaESeUSZIew+MxuJT6pw8+Ba1myZK5fcQDIB5UDAcGDJDT/TsFIN0dmsUKrjllwamQ6bFarjboyVS+5j+4PZEohgNQk9G0e09rcyCmenle13OFiEGzX3NLXHzSa0ojxQQSst/+0lGZ02mC9zEJK9yXc6jzMUYDD2yIhIMbdIPbaSGaBfybTSS/ItfGnRjUB4IPwCxlGMgRP/uPBbO68eSQERDiIiHQwJ/GDayFCnN40h7mMInmkXqoIiKt9ZAo+0jJS+ItuKINI7/sKL3U9wCb2ndQizPkmrR1tZr9gPveyeatvSUJE0dsdb0hsuuWTPSsaSdZZZL0JhIz9vHC88D8Z5/BN8yW/9++sfefv3TtbqwWnaPfyM6cVFNB3a3BU0hdrQmQM0S3iQviZ9xbwzTi+jAMURNTFyXFJgP5PelCCjJLpHLNpvcxGRn8ApIG6wx4+Tr25uJWuNfskalCRfMX2mmKSx75J8ukv//F7VJEu7nEkbO2T9bTuU0+3477e/q/ohK8alDDmevnqO9P+snL5hXUf6bJM7Mf2/qqavyNJ1pK83UvyKfrEt83j6RiPFr7QvthkeT99spPhV9Uq2PquR4lfNxrY+cQfg6DOO0p1ch+4Uua1LumWw/KvTXbsvGX1LS+O3p+sMdJc+r/xkXRPblYEZznY7dnC2Oz19znbV0udsx9mOsx1nuwunX5HtlDpsp2rKSB5ItdlOaxu2aitWbms+Xfzk7kIndzXW9OXwjsMchzkOc4Xpc5hroPg5zHGYuwWYU2vBXNvWTcsasvyLYW6+HmN38sMRpDN7pqbpmpabm09a4l0cek5XsI2BNVRNu8Y0hl/itZeP55MbxZ8BBjMMwnnhPH8FJ3y5rZakS0N5dAZ2fl9nfrlBw/5Is4b9s7x5XDM4VrWI7hepRZImtSVJYlUFUQxidwnP9JPGLcPmvkHMsjMbdMs4um8QazmzQbcMrPsGXccSuyKk3TfoOpbYFUHvvkHXscRuB4vpLl4HiwdqXxqw/KufcQ7aQ0Oib/2ZrfmEvv8zTn6ayU8z+WkmP818M31+mtlA8fPTTH6aeQvYRjG3Mrbplq0aZttm+VfHNsM2FG3YTk9Dt6frDNhWY7FybOPYtsmeYxvHNo5tHNsaTZ9jWwPFfzvYRk+8K2ObOVBHqmFpLP/q2NYb9CRTVtL47el679jGIe317DmkNVD6HNI4pHFI45DWaPoc0o5DGv2te3VIG/ZNc9QbsPyrQxrZGwzLlL/Kf/vgZ2sc2zi2cWx7M32ObQ0UP8c2jm1Xgm0owTWUffIKbdphtywjNZVDBWHsDbQwLPmf3VfC2BtPYVj2x+RFYQefD7gJM4+EsY2uMEw7EsY2iMKw5JMEXwljC6swLJvrojBWkIVhGcYlYezKIPrhfwAAAP//AwBQSwMEFAAGAAgAAAAhAPiVyO/8DgAA85kAAA8AAAB3b3JkL3N0eWxlcy54bWzsXd9zo0YSfr+q+x8oPSUPG/+QLTtbcVJr2T67btdxVt5L3eMIRhZnYHSA1uv89TczDAjUDKKHjuu8m6RqLQH9MczXX890A5qffvkSR95nnmahSM5GBz/sjzye+CIIk4ez0af7qzenIy/LWRKwSCT8bPTMs9EvP//9bz89vc3y54hnngRIsrexfzZa5vnq7d5e5i95zLIfxIoncudCpDHL5df0YS9m6eN69cYX8Yrl4TyMwvx573B/fzIyMGkfFLFYhD6/EP465kmu7fdSHklEkWTLcJWVaE990J5EGqxS4fMskxcdRwVezMKkgjk4AkBx6KciE4v8B3kxpkUaSpof7OtPcbQBOMYBHAKAic+/4DBODcaetKzjhAEOZ1LhhEENx60xNYCM4yCOy3Zkz7G6oth/e/OQiJTNI4kkOfJkN3saWP0rW6v+6I/y8J+lwwbCv+ALto7yTH1N71Lz1XzTf65Ekmfe01uW+WF4L9slweNQnuf6XZKFI7mHsyx/l4WsvvPSbFP7l+rAVks/y2ubz8MgHO2pk2Z/yJ2fWXQ2Ojwqt0xVIxrbIpY8lNt48mZ6W2/M2eiPpdk0l7hnI5a+mb1Thnvm2oq/tSteVd+Ko7a6R+pJqmtWiFzu5Yv3wn/kwSyXO85G++pUcuOnm7s0FKkU8tnoxx/NxhmPw+swCHhSOzBZhgH/fcmTTxkPNtt/u9JiNBt8sU7k5/HJRFMWZcHlF5+vlLTl3oSp3rtVBpE6eh1uTq7N/1uCHZg+a7Nfcqbim3ewDaGbj4I4VBZZ7WrbMddb166PQp1o/FInOnqpEx2/1IkmL3Wik5c60elLnUjD/JknCpOAfymECE8DUHfhWNSIxrGIDY1j0RIaxyIVNI5FCWgci6OjcSx+jMaxuCkCJxe+zQtrzj62eHs37u4xwg1395Dghrt7BHDD3R3w3XB3x3c33N3h3A13d/R2w90drPG4xVTLu5EyS/LBKlsIkSci517OvwxHY4nE0kkfDZ4a9HhKcpEEMEVkMwPxYDSf6e+7PUSL1H08z1U25omFtwgf1inPBjecJ595JLN2jwWBxCMETHm+Ti094uLTKV/wlCc+p3RsOtAoTLiXrOM5gW+u2AMZFk8C4u4rEUmCQuXQbJ0vlUhCAqeOmZ+K4U0TjCw+vA+z4X2lQLzzdRRxIqxbGhfTWMNzAw0zPDXQMMMzAw0zPDGocUbVRQaNqKcMGlGHGTSifiv8k6rfDBpRvxk0on4zaMP77T7MIx3i67OOg/61u2kkVJl+cDtm4UPC5ARg+HBjaqbeHUvZQ8pWS0+VkNth69eMPc+5CJ69e4oxrUKimtdrF5nKqw6T9fAObaBRiavCI5JXhUcksApvuMQ+yGmymqBd0+Qzs/U8bxWtRuol2hmL1sWEdrjaWD7cwzYCuArTjEwG7bAEHnyrprOKTorIt2nl8IZtsIbLajsqkTbPQBK0MhL+I00Yvn5e8VSmZY+Dka5EFIknHtAhzvJUFL5Wl/yhpqSX5C/j1ZJloc6VGhD9h/ryBr/3ga0GX9BdxMKEhrfLNzELI49uBnF9/+G9dy9WKs1UHUMDeC7yXMRkmKYS+N3vfP49TQPfySQ4eSa62ndE5SENNg0JBpkCSQRESHKaGSYhyRiq8f7Jn+eCpQEN2l3Ki2dqck6EOGPxqph0EGhLxsUnGX8IZkMa718sDVVdiEpU9yRgtbJhtp7/h/vDQ92t8EgqQ7+uc11/1FNdbU0HN3ya0IAbPkXQbMrhQfkvwcU24IZfbAOO6mKnEcuy0HoL1RmP6nJLPOrrHZ78GTwRiXSxjug6sAQk68ESkKwLRbSOk4zyijUe4QVrPOrrJXQZjUdQktN4/0jDgIwMDUbFhAajokGDUXGgwUgJGP6ETg1s+GM6NbDhz+oUYERTgBoYlZ+RDv9Ed3lqYFR+psGo/EyDUfmZBqPys/GFxxcLOQmmG2JqkFQ+V4OkG2iSnMcrkbL0mQjyMuIPjKBAWqDdpWKhXrYQSfEQNwGkqlFHhJPtAo6K5N/5nKxpCouyXQQVURZFQhDV1jYDjrZsPru2y0y/czG4CXcR8/lSRAFPLddkt5X58mzFfFOmB7f7epU934cPy9ybLatqfx1msr/TskzYG2a7T9jW55PDDrMPPAjXcdlQ+DLFZNzfWHt0w7h856XDeDOTaFge97SE55zsttzMkhuWJz0t4TlPe1pqnTYsu/RwwdLHVkc46fKfKsezON9JlxdVxq2n7XKkyrLNBU+6vKghFe+d76u7BZCdfpqx2/cTj90eoyI7CkZOdpTeurJDdAnsI/8cqpEdEzT1+aqnJ0Dc15PoXpHzt7Uo6vaNG079X+q6kROnJONeK864/42rRpSx92PvcGOH6B137BC9A5AdolckspqjQpIdpXdsskP0DlJ2CHS0giMCLlpBe1y0gvYu0QqiuESrAbMAO0Tv6YAdAi1UCIEW6oCZgh0CJVRg7iRUiIIWKoRACxVCoIUKJ2A4oUJ7nFChvYtQIYqLUCEKWqgQAi1UCIEWKoRACxVCoIXqOLe3mjsJFaKghQoh0EKFEGih6vniAKFCe5xQob2LUCGKi1AhClqoEAItVAiBFiqEQAsVQqCFCiFQQgXmTkKFKGihQgi0UCEEWqjFq4buQoX2OKFCexehQhQXoUIUtFAhBFqoEAItVAiBFiqEQAsVQqCECsydhApR0EKFEGihQgi0UPXNwgFChfY4oUJ7F6FCFBehQhS0UCEEWqgQAi1UCIEWKoRACxVCoIQKzJ2EClHQQoUQaKFCiC7/NLcobY/ZH+CrntYn9vvfujKN+lh/lbsONe4PVbbKjtX/XYRzIR691hcPxzrf6AcSzqNQ6BK15bZ6HVc/EoG68fnrtPsNnzr6wB9dMu9C6HumAPyoryWoqRx1uXzdEiR5R12eXrcEs86jruhbtwTD4FFX0NW6LB9KkcMRMO4KMzXjA4t5V7SumcMu7orRNUPYw12RuWYIO7grHtcMjz0VnLetj3v206R6vhQgdLljDeHEjtDllpCrMhxDYfQlzY7Qlz07Ql8a7QgoPq0weGLtUGiG7VBuVEOZYal2F6odAUs1RHCiGsC4Uw2hnKmGUG5Uw8CIpRoiYKl2D852BCeqAYw71RDKmWoI5UY1HMqwVEMELNUQAUv1wAHZCuNONYRyphpCuVENJ3dYqiEClmqIgKUaIjhRDWDcqYZQzlRDKDeqQZaMphoiYKmGCFiqIYIT1QDGnWoI5Uw1hOqiWldRGlSjGK6Z4yZhNUPcgFwzxAXnmqFDtlSzdsyWagiO2RLkquQcly3VSbMj9GXPjtCXRjsCik8rDJ5YOxSaYTuUG9W4bKmNaneh2hGwVOOyJSvVuGypk2pcttRJNS5bslONy5baqMZlS21UuwdnO4IT1bhsqZNqXLbUSTUuW7JTjcuW2qjGZUttVOOypTaqBw7IVhh3qnHZUifVuGzJTjUuW2qjGpcttVGNy5baqMZlS1aqcdlSJ9W4bKmTaly2ZKcaly21UY3LltqoxmVLbVTjsiUr1bhsqZNqXLbUSTUuW/ogTUKCn4CaxSzNPbrfi7tm2TJnw3+c8FOS8kxEn3ng0V7qe9RV7j01lr9S2Hq1O3l8LvtM/QJ67XWloPgFWAOoD7wJqmWqlLFqiWeW7jKbdYPN7Vr9Oc1kTm2O2d8/Pz8cT43UVsXSZFnxZqk8Rv1a0dloPNGvJKkvH9dqDTS2zoVpvTbZM43Z0fyqweb+8wFo8mbBLN2eOZM99avqYXBBifqxxZbtysnK7eVppkuWFns37l8eYwRu75+Lo/3ji8tG/zxyvrqV59fb1BfJOc/0t03XzdXvlHG1qJoRvyh+/On956gCr/ehZWE4qcRyrTrv3+yaNxaGa92pV4Vr3eNnZ6P7MOaZd8ufvI8iZon3nemkzJvOvje9rv/1VfjYdIP6T2HodeV0aDkbqd+9N0xtFpYrb5TXF5Yb60hTWx/OxVsOrd5i4hiNtxz28JamlP9kB7L7TxlBvir/GZuJQ2NhQr1toP+Mrf5jHgqh8Z/x6/GfUpVfl/9QxJojq6+Y6EbjK0evx1e0Rv5ffSWcFhfk7DPlSDzEZ46tPmMeAKPxmePX4zNaK19DfBnoGcUKs22eYcY6Gs+YvB7P0Ir4yzMeTqyeYTIyGs84eT2eUc70vppxZqCHnFo9xBS3aDzk9PV4iFbGq4gdhyfq/3bPKDfeh2oV8gtDZiPp6ek+vmSO+eYnxy0VIrN0UPXbN3rhoG3HsqwvZHGKchJVlbnafcTe7lzVKTvarOuYnaWtotRp9VrjtrtaKNszjwonkh9uEuXET2aV96KlwRdWQMn9Ux5FH1hxtFjZD434QmlP7j3Y1780ubV/XiyaYLVPdXXdCrDXbEzxtdtPimUUw+K1D2slUZWQW7pbv4M0tKd7+rC/zmTXzNQB2+1rVPS2W2l2egfeJphtRcdWHdhiovFwazy0B7y/KnlIQouim43QQyJCTZ3wmyV0SGkNSWhRBbMROiYi1BTuvl1C/xw1FmUpG3lHROSZ6PLqyXup4hOSxKJOZCPxmIhEU9r6phRITlVRuLFRNSGiygT/v6gaQlVRSbFRdUJElSn+fJOhkZyyorRho+yUiDKTwH9d6nqZAkaj/tXBp17ibptHvbGNvX5Pv5xe7k+vzoujTEFpdR7U0nt9nFoI2qyb9oe6raE+rJhftlD32eapmCr532GrPwPbqjDgdOaybOBwalVSM5eeLasu8iPOCqHVjpZfF2Ek916eXE4u9YNl2heu9MY58x8fUrFOgn43mKciyUTE9O+BbFx8FsaztX4oy3h2/bBWl9aLsFbuHDFdT9QXwZM3n2a0weUmUWXJVpes7cKFFWuRrZ//EnVv0eagCgKJSCof0mHb+JD+DByQ1HVoWNwMCNVTiNuUbfYMZayshbWUGZvMTS8Pfjw1CaxhrjlMHk/G002YNbF32WzoujzaSH1A52weiCyfh9zupJZHJql6a3eNFtd5k/3jy+Mp1iMPLq4uLhzGrKoPVZF08/vy2/2nn87d7G7ru/qgBXtrbFJm1F2XZB0XH8Jo68kfve+msi5Ha2MAwnZPKZafsp//BwAA//8DAFBLAwQUAAYACAAAACEAzJJQVH0BAADxAgAAEQAIAWRvY1Byb3BzL2NvcmUueG1sIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAjJLLTsMwEEX3SPxD5H1qJ+WlKE3FQ6yoQKIViJ2xJ60hsS17IPTvcZI2JYgFO4/n+GRy7Xz+VVfRJzivjJ6RZMJIBFoYqfR6RlbL2/iCRB65lrwyGmZkC57Mi+OjXNhMGAcPzlhwqMBHwaR9JuyMbBBtRqkXG6i5nwRCh2ZpXM0xlG5NLRfvfA00ZeyM1oBccuS0FcZ2MJKdUopBaT9c1QmkoFBBDRo9TSYJPbAIrvZ/Hug6P8ha4dbCn+i+OdBfXg1g0zSTZtqhYf6EPi/uHrtfjZVusxJAilyKDBVWUOT0sAwr//H6BgL77aEIa+GAo3HFQglnvCkxui9LJSBaeXAdvSfa7N9h2xgnffCMqoBJ8MIpi+FG+6+MNgJdcY+LcMWlAnm1LS5Pz9OzTvOr0bIOPlX7NoqkI4Yy3wXdDwUyCgFlfZz7ztP0+mZ5S4qUpUnMTuIpW7I0O00zxl7auUbnD8J6N8A/jdOMnYyNe0EfzfiRFt8AAAD//wMAUEsDBBQABgAIAAAAIQAiURHx1QEAAN4DAAAQAAgBZG9jUHJvcHMvYXBwLnhtbCCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJxTwW7bMAy9D9g/GLo3crKh6AJFxZBi6GFDA8Rtz5xMJ8JsSZDYINnXj7YTT9l2mk/vkfTTE0mp+2PXFgeMyXq3EvNZKQp0xtfW7VbiufpycyeKROBqaL3DlThhEvf6/Tu1iT5gJIupYAmXVmJPFJZSJrPHDtKM044zjY8dENO4k75prMEHb946dCQXZXkr8UjoaqxvwiQoRsXlgf5XtPam95deqlNgPa0q7EILhJrOYFZ7Oio5xVXlCdrKdqjnJccnpjaww6TnSo5AvfpYJ724U3JEar2HCIa4h3p++0HJjKvPIbTWAHF39Tdrok++oeJpsFz0/yuZlyi+xhbNW7R00mwjp+qrdaOREbCxCLsIYX92NzG1NdDimhugG2gTKvk7oB4R+uFuwPb+DrQ8oCEfi2R/8ngXovgOCfu2rcQBogVHYiwbyYDbkCjqylLL2hMfYF6WY/uxNzmC68KBDB4YX7sbTkhPDd+N/mF2npsdPIxWMzu5s8sZf6iufRfAcX/lhLjBP9JzqPxDvxrnHl4Hs6m/WtpvA5h+OJ/KfP5ZRm05ijUPdJrJFFCPfIPY9vr8r9thfan5O9Fv1Mv4XHnbZiV/wwpdYrwI0zvSvwAAAP//AwBQSwMEFAAGAAgAAAAhAIg/pb/hAAAAVQEAABgAKABjdXN0b21YbWwvaXRlbVByb3BzMS54bWwgoiQAKKAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnJDBasMwEETvhf6D2bsiObFdEyyHuE4g19JCroq8tgWWZCS5tJT+e2V6So89LbPDzhu2OnzoKXlH55U1HNINgwSNtJ0yA4e31zMpIfFBmE5M1iAHY+FQPz5Und93IggfrMNLQJ3EhYrz0nL4ykvW5E87Rsr2nJLilDXkmKUNKTKWt8fnU8pY8Q1JRJsY4zmMIcx7Sr0cUQu/sTOaaPbWaRGidAO1fa8ktlYuGk2g25hA5RLx+qonqNc+v9cv2Pt7uVZbnPov5aZuk7KDE/P4CbSu6B/Uqu9eUf8AAAD//wMAUEsDBBQABgAIAAAAIQDBJ8sItgAAACEBAAATACgAY3VzdG9tWG1sL2l0ZW0xLnhtbCCiJAAooCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACskE0OgjAQRq9CegCKLlgQfmKiWzEhcV/KAE3aGdIOBm5v1egJXE7mfS/zTdlsziYP8MEQVuKQZiIJrHBQlhAqgSSauuyLjlavISSRxlD0lZiZl0LKoGdwKqS0AMbdSN4pjqOfJI2j0XAmvTpAlscsy2Vvemto8mqZd/GR/UfVgQXNMHS823i2PN1Ondl4vgyGY7P2LWjRGoR0CzYGXuBVuQhHViT37wtyUZfyV7h+AgAA//8DAFBLAwQUAAYACAAAACEAdD85esIAAAAoAQAAHgAIAWN1c3RvbVhtbC9fcmVscy9pdGVtMS54bWwucmVscyCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIzPsYrDMAwG4P3g3sFob5zcUMoRp0spdDtKDroaR0lMY8tYamnfvuamK3ToKIn/+1G7vYVFXTGzp2igqWpQGB0NPk4Gfvv9agOKxcbBLhTRwB0Ztt3nR3vExUoJ8ewTq6JENjCLpG+t2c0YLFeUMJbLSDlYKWOedLLubCfUX3W91vm/Ad2TqQ6DgXwYGlD9PeE7No2jd7gjdwkY5UWFdhcWCqew/GQqjaq3eUIx4AXD36qpigm6a/XTf90DAAD//wMAUEsDBBQABgAIAAAAIQDrgGBMUwMAAI8OAAASAAAAd29yZC9mb250VGFibGUueG1szJbPb9MwFMfvSPwPUU7jwJqkXZdV66Y2WzQk2IEVAUc3cVqL2I7itF3/AA6IE+LI38C4gwb/DNPYf8FznLRZm25LQbBGzY9n+5vnT57f8+7+KQ21MY4F4aytm5uGrmHmcZ+wQVt/0XMf27omEsR8FHKG2/oUC31/7+GD3Ukr4CwRGoxnokW9tj5MkqhVqwlviCkSmzzCDBoDHlOUwGM8qFEUvxlFjz1OI5SQPglJMq1ZhtHUM5n4Lio8CIiHD7g3opgl6fhajENQ5EwMSSRytcld1CY89qOYe1gImDMNlR5FhM1kzMaSECVezAUPkk2YTOZRKgXDTSO9o+FcYKuagLUk0PTwaTUNO9OowciiDvGr6TRnOsQv6KznTEFA4GoSW7kfYkrljKjXejJgPEb9EJTgG2mAWUuF5Rm8lZf0FrrvZfGqTVoMURjwEj62DHKRNkWIcYFNaB2jsK0bW8bST6/Jjt4QxQJLmbRj40CZA0RJOM2tPvbAr4SMsWqNSOIN88Yxion0WTUJMoCGkegb8Fb1q+vKYsJyzN+tLNasT26pX7d4qY6tDGZmMQt94J01BWIJSI9QLLRjPNGec4pYKRYLjqZRBzwN+Ftw1yjFktO6jiVOdasQgaVoWB17e04km9syEfsmIoqH61Yj4qCQ9GOygoSbEpBHAzhYlUiICRGiEomOdNY6TGegSDSkwdjuVosN9bxTkcQBZoNXJAsKFCbHYM19vvz87vLrj2wyS5RMiBcIabhmRyklu1lGCY0SvgakbgFS3XbcbcftLEIym7dAknQrQnqWZy/tNTrCKmwWWF18P/t1/uXq09urbx9WEetCXMl4knGVnisQqx5X6XqyiivM6jhu3dmy1kFmVkS2kHO0jSOM0qSsOSePygAuJqmVDJsZvWyF/oUs5eMAjcLkxoQB+w8eovKSorzaWTNjUO7juMytgJxif/m7HsrSYamMN88XrjOzzPPFzu2Zs2q+OCH0ZFSaLS7O3v88/3gvskU2j0K5tWzbzadfOVv8WbnVNrrcn96PsGc86cUj3JtGeK1lkFcL7SkZDJPVNSNrvw+x8H8rR7bRKPAq226oovBvthuHEkenmD4caWmUbDfukD5u3XhlN2LvNwAAAP//AwBQSwECLQAUAAYACAAAACEAZPVj7oEBAAApBgAAEwAAAAAAAAAAAAAAAAAAAAAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLAQItABQABgAIAAAAIQAekRq37wAAAE4CAAALAAAAAAAAAAAAAAAAALoDAABfcmVscy8ucmVsc1BLAQItABQABgAIAAAAIQAzwlu/QQEAAOcEAAAcAAAAAAAAAAAAAAAAANoGAAB3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAE4yjpAWBgAApiQAABEAAAAAAAAAAAAAAAAAXQkAAHdvcmQvZG9jdW1lbnQueG1sUEsBAi0AFAAGAAgAAAAhALb0Z5jSBgAAySAAABUAAAAAAAAAAAAAAAAAog8AAHdvcmQvdGhlbWUvdGhlbWUxLnhtbFBLAQItABQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAAAAAAAAAAAAAAKcWAAB3b3JkL3NldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQBAwf/xOQEAACMDAAAUAAAAAAAAAAAAAAAAAMsaAAB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQA520VMuQUAACdaAAASAAAAAAAAAAAAAAAAADYcAAB3b3JkL251bWJlcmluZy54bWxQSwECLQAUAAYACAAAACEA+JXI7/wOAADzmQAADwAAAAAAAAAAAAAAAAAfIgAAd29yZC9zdHlsZXMueG1sUEsBAi0AFAAGAAgAAAAhAMySUFR9AQAA8QIAABEAAAAAAAAAAAAAAAAASDEAAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhACJREfHVAQAA3gMAABAAAAAAAAAAAAAAAAAA/DMAAGRvY1Byb3BzL2FwcC54bWxQSwECLQAUAAYACAAAACEAiD+lv+EAAABVAQAAGAAAAAAAAAAAAAAAAAAHNwAAY3VzdG9tWG1sL2l0ZW1Qcm9wczEueG1sUEsBAi0AFAAGAAgAAAAhAMEnywi2AAAAIQEAABMAAAAAAAAAAAAAAAAARjgAAGN1c3RvbVhtbC9pdGVtMS54bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAABVOQAAY3VzdG9tWG1sL19yZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAOuAYExTAwAAjw4AABIAAAAAAAAAAAAAAAAAWzsAAHdvcmQvZm9udFRhYmxlLnhtbFBLBQYAAAAADwAPANQDAADePgAAAAA=",aZ=()=>vg(lZ);async function cZ(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 z4(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};const e=await ia(new File([t],"",{})),r=await cZ(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}}function uZ(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 fZ(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 G4(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let r;switch(e%3){case 0:r=pt.LevelFormat.DECIMAL;break;case 1:r=pt.LevelFormat.LOWER_LETTER;break;default:r=pt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:r,text:`%${e+1}. `,alignment:pt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(e+1)),hanging:pt.convertInchesToTwip(.2)}}}}})}function dZ(){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:pt.LevelFormat.BULLET,text:t,alignment:pt.AlignmentType.START,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(n+1)),hanging:pt.convertInchesToTwip(.2)}}}}})}function hZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:pt.LevelFormat.BULLET,text:"\u2611",alignment:pt.AlignmentType.START,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(n+1)),hanging:pt.convertInchesToTwip(.2)}}}}))}function mZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:pt.LevelFormat.BULLET,text:"\u2610",alignment:pt.AlignmentType.START,style:{paragraph:{indent:{left:pt.convertInchesToTwip(.3*(n+1)),hanging:pt.convertInchesToTwip(.2)}}}}))}var Cf=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))(Cf||{});const gZ=[{levels:G4(),reference:"number-numbering-reference"},{levels:dZ(),reference:"number-bullet-reference"},{levels:hZ(),reference:"checked-bullet-reference"},{levels:mZ(),reference:"unchecked-bullet-reference"}];function pZ(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 CZ(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 EZ(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 AZ=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function W4(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(AZ);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 on(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 q4(n,t,e){for(let r=0;r<=e;++r){const i=`${t}${r}`;if(on(n,i))return i}}function Z0(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function XE(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function X4(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function xZ(n){const t=on(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"&&Z0(n,"inline-style-font-size",s),o==="color"&&Z0(n,"inline-style-color",s),o==="background-color"&&Z0(n,"inline-style-background-color",s),o==="font-family"&&Z0(n,"inline-style-font-family",s)}}function bZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function vZ(n){const t=`${on(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function BZ(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 TZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function yZ(n){return on(n,"inline-style-font-family")}function kZ(n){const t=on(n,"inline-style-background-color");return W4(t)}function RZ(n){const t=on(n,"inline-style-color");return W4(t)}function wZ(n){xZ(n);const t=on(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!on(n,"style-code"),link:X4(on(n,"link")),size:vZ(n),text:t?TZ(n):BZ(n)||n.insert,bold:!!on(n,"style-bold"),underline:!!on(n,"style-underline"),italics:!!on(n,"style-italic"),strike:!!on(n,"style-strikethrough"),superScript:!!on(n,"style-super"),subScript:!!on(n,"style-sub"),math:on(n,"type")==="math"?on(n,"src"):void 0,mention:t,fontFamily:yZ(n),background:kZ(n),color:t?"338fe5":pZ(q4(n,"style-color-",6))||RZ(n),highlight:q4(n,"style-bg-color-",13)}}function SZ(){return[new pt.Paragraph({border:{top:{color:"auto",style:pt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new pt.Paragraph({spacing:{line:0}})]}function LZ(){return new pt.Paragraph({children:[new pt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function IZ(){return new pt.Paragraph({children:[new pt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function DZ(n,t){return new pt.Paragraph({children:[new pt.ExternalHyperlink({children:[new pt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function Q4(n){if(n.heading!=null)return`Heading${n.heading}`}function Y4(n){if(n.alignment!=null){if(n.alignment==="center")return pt.AlignmentType.CENTER;if(n.alignment==="right")return pt.AlignmentType.RIGHT;if(n.alignment==="left")return pt.AlignmentType.LEFT}}function _Z(n){if(n.indent)return{left:pt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:pt.convertInchesToTwip(.3*n.padding)}}function MZ(n){return{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function UZ(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function Z4(n,t){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 new pt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:pt.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?UZ(n.fontFamily):void 0,shading:n.background?MZ(n.background):void 0,color:n.color,highlight:CZ(n.highlight)})}function OZ(n,t){if(n.link)return new pt.ExternalHyperlink({children:[Z4(n,t)],link:n.link})}async function J4(n,t,e,r,i){const o=await i(n,t,e);if(o==null)return;const s=await z4({width:r||0,height:0,src:e},o);return new pt.ImageRun({data:o,transformation:{width:s.width||100,height:s.height||20}})}function NZ(n){if(n.heading||n.heading)return n.heading}function PZ(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function FZ(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function KZ(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(wZ(o))}return e}}function VZ(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 $Z(n,t){if(n.type==="embed"&&n.embedType&&XE(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 HZ(n){if(n.padding)return n.padding}function jZ(n){return!!(n.type==="embed"&&n.embedType&&XE(n.embedType)&&n.embedData&&n.embedData.src)}async function J0(n,t,e){return{quoted:!!n.quoted,heading:NZ(n),alignment:PZ(n),indent:FZ(n),padding:HZ(n),texts:await KZ(n,e),list:VZ(n),images:$Z(n,t),border:jZ(n)}}async function zZ(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 J0(l,e,r));i.push(s)}return i}const GZ=I("to-docx");function WZ(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 qZ(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 XZ(n){p(GZ,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=WZ(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=EZ(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 x=0;x<h;x++)E===0&&(C+=r?r[l+x]:80),!(E===0&&x===0)&&(i[s+E][l+x].from=[s,l]);i[s][l].width=C}}return qZ(n,t,e,i),i}async function QZ(n,t,e,r,i,o,s,l,c,d){async function h(x){if(l){const v=await l(i,o,x);if(v){await r.addDoc(n,v,d);return}}if(x.type==="text"||x.textOnly===!0){const v=await J0(x,s,c);await r.addTextBlock(v);return}if(x.type==="code"){const v=await zZ(x,e,s,c);await r.addCodeBlockObject(v);return}if(x.type==="list"&&x.textOnly!==!0){const v=await J0(x,s,c);await r.addListBlockObject(n,v);return}if(x.type==="embed"&&x.embedType){const v=x,R=v.embedData,L=v.embedType;if(XE(L)){const M=await J0(x,s,c);await r.addImagesBlockObject(x,M,d)}else x.embedType==="hr"?r.addSeparatorBlock():x.embedType==="video"?r.addVideoPlaceholder():x.embedType==="audio"?r.addAudioPlaceholder():x.embedType==="webpage"?r.addHyperlinkParagraph(X4(R.src),R.title):r.addOtherEmbedBlock(L,x.embedData);return}if(x.type==="table"){let v=[];if(x.colsWidth)v=x.colsWidth;else{const L=x.cols;v=new Array(L);for(let M=0;M<v.length;M++)v[M]=100;x.colsWidth=v}const R=XZ(x);await r.addTableMatrix(v,R,e),r.addEmptyParagraph()}}function C(x){const v=[];for(const{type:R,data:L}of x.embedData.exportSpec){if(R==="text"){const M={id:J(),text:[{insert:L}],type:"text"};v.push(M);continue}if(R==="image"){const M={id:J(),type:"embed",embedType:"image",align:"left",embedData:{src:L}};v.push(M);continue}if(R==="link"){const M={id:J(),type:"embed",embedType:"webpage",embedData:{src:L.url,title:L.title}};v.push(M);continue}}return v}function E(x){var v;return(v=x==null?void 0:x.embedData)!=null&&v.exportSpec?C(x):[x]}for(const x of t)for(const v of E(x))await h(v)}function YZ(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const ZZ=I("to-docx");class JZ{constructor(t,e,r,i,o,s){g(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 pt.Paragraph({heading:Q4(t),alignment:Y4(t),children:await this.paragraphsFromBlockTexts(t),indent:_Z(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new pt.Paragraph({text:`[${D.t("docx.imageExportFailed")}]`,shading:{type:pt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=bZ(this.defaultFontSize,t.heading),r=[];for(const i of t.texts){if(i.link){const o=OZ(i,e);o&&r.push(o);continue}if(i.box&&i.box.type&&i.box.type==="br"){r.push(new pt.TextRun({text:"",break:1}));continue}if(i.box&&i.box.type&&i.box.type==="image"){const o=await J4(this.appId,this.docId,i.box.src,i.box.width,this.readImageFunc);o&&r.push(o);continue}if(i.math){const o=await J4(this.appId,this.docId,i.math,0,this.readImageFunc);o&&r.push(o);continue}r.push(Z4(i,e))}return r}async addCodeBlockObject(t){for(const e of t)for(const r of e){const i={style:pt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new pt.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=G4([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]=Cf.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[i]=Cf.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[i]=Cf.UNCHECKED:this.state.listRefMap[i]=Cf.BULLET;const o=Q4(e);e.texts&&this.paragraphs.push(new pt.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 pt.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=await this.readImageFunc(this.appId,this.docId,c.src);if(d)return z4(c,d);i.push(c.src)}));fZ(o,r,t.embedData);const s=uZ(o,r),l={style:pt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new pt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:Y4(e)||pt.AlignmentType.CENTER,children:s.map(c=>this.imageDimWithBufferToImageRun(c)).flatMap((c,d,h)=>c==null?[]:h.length-1!==d?[c,new pt.TextRun({text:" "})]:c)})),i.forEach(c=>{this.addHyperlinkParagraph(c)})}addSeparatorBlock(){SZ().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new pt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(LZ())}addAudioPlaceholder(){this.paragraphs.push(IZ())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(DZ(t,e))}async addTableMatrix(t,e,r){const i=t.map(o=>o!==0?o*15:1500);this.paragraphs.push(new pt.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 pt.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:pt.WidthType.DXA,size:i.width*15},shading:i.color?{fill:i.color,type:pt.ShadingType.CLEAR,color:"auto"}:void 0}))}return r}async generateTableRows(t,e){const r=[];for(const i of t)r.push(new pt.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 addOtherEmbedBlock(){}}class tJ{constructor(t,e,r,i,o,s,l,c){g(this,"convertBlocks",async(t,e,r,i,o,s,l=720)=>{const c=new JZ(i,o,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await QZ(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 pt.ImportDotx,o=this.templateData?await i.extract(this.templateData):void 0,s=t.blocks.root;p(ZZ,s,"data must have blocks");const l=YZ(),c=await this.convertBlocks("blocks",s,t,e,r,l),d=this.backgroundImageOptions?{default:new pt.Header({children:[new pt.Paragraph({children:[new pt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new pt.Document({numbering:{config:[...gZ,...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 pt.Packer.toBlob(h)}}async function eJ(n,t,e,r){const i=n.doc.buildResourceUrl(r,{withToken:!0});let o=await Kk(i);if(!o)return;if(o.type.indexOf("/svg")!==-1){const l=await Nk(o);l&&(o=new File([l],o.name))}return await o.arrayBuffer()}async function nJ(n,t,e){const r=n.editorBlocks.getBlockClass(e.type);if(r.toStandardDoc)return r.toStandardDoc(n,e,t)}async function rJ(n,t){const e=t.attributes,r=n.editorBoxes.getBoxClass(e.type);if(r.toStandardText)return r.toStandardText(n,e)}async function iJ(n,t){let{template:e,download:r,backgroundImageOptions:i}=t!=null?t:{};e||(e=aZ());const o=n.doc.toJSON(),s=(C,E,x)=>eJ(n,C,E,x),l=async(C,E,x)=>nJ(n,o,x),c=async C=>rJ(n,C),h=await new tJ(e,o,md.default,s,void 0,l,c,i).convert("_appId","_docId");if(r){const C=URL.createObjectURL(h),E=document.createElement("a");E.setAttribute("download",`${Fk(n)}.docx`),E.setAttribute("href",`${C}`),E.click(),E.remove()}return h}const QE=I("create-editor");async function oJ(n,t){var s,l,c,d,h,C,E,x,v,R,L,M,U,F;p(QE,n,"app does not exists"),t.lang&&D.setLang(t.lang),si.level=(s=t.logLevel)!=null?s:ws.DEBUG;const e=t.onReauth?async()=>{var at;const G=t.user.userId,q=t.docId,rt=await((at=t.onReauth)==null?void 0:at.call(t,G,q,t.permission));return{userId:G,docId:q,permission:t.permission,appId:t.appId,token:rt,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},i=await yu.load(r),o=hu(n,i,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,components:{blocks:[...V4,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...qE,...((c=t.components)==null?void 0:c.embeds)||[]],boxes:[...$4,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Zh,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new k0,new gp],insertions:[p1],blockHooks:[new rE,new CR,...((C=t.components)==null?void 0:C.blockHooks)||[]],textRenders:[new Iw,new gC],options:{...t.componentsOptions}},shortcuts:[BW,d$,bj,UC,sw,CP,SC,oq,Ch,uP,...t.shortcuts||[]],colors:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"]});if(o.editorCommandProviders.registerCommandProvider(new Ri(o)),o.input.addHandler(new qq),o.input.addHandler(new w0),o.input.addHandler(new OF),o.input.addHandler(new pj),o.input.addHandler(new zC(o,{hideTitle:t.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),o.input.addHandler(new E0(o,(E=t.componentsOptions)==null?void 0:E.quickMenu)),o.input.addHandler(new uE(o)),o.input.addHandler(new pE(o)),o.input.addHandler(new D0),o.doc.registerCallback(new Xq(o)),o.addCustom("remote-cursor",()=>new T2(o)),o.addCustom("block-menu",G=>new xR(G)),he.isMobile||o.addCustom("editor-tooltip",()=>new A0(o)),t!=null&&t.enableComments&&o.addCustom("editor-comments",G=>new Lw(G,new nZ(G))),o.addCustom("create-options",()=>new Jx(o,t)),o.addCustom("drop-target",()=>new of(o)),o.addCustom("list-to-mindmap",()=>new f0(o)),o.addCustom("list-to-mention",()=>new gX(o)),o.addCustom("mobile-helper",()=>new DX(o)),o.addCustom("code-caret",()=>new a$(o)),o.addCustom("image-paste-handler",()=>new cE(o)),(x=t.componentsOptions)!=null&&x.mention){const G=t.componentsOptions.mention;o.addCustom("mention",()=>new m4(o,G))}if(o.addCustom("heading-collapse",()=>new UE(o)),Ha.register(o),of.register(o),fs.register(o),os.register(o),o.addListener("clickLink",(G,q,rt)=>{var At;if((At=t==null?void 0:t.events)!=null&&At.onClickLink){t.events.onClickLink(G,q,rt);return}const at=rt.getAttribute("link");at&&(G.readonly||q.ctrlKey||q.metaKey)&&window.open(at,"_blank")}),(R=(v=t.componentsOptions)==null?void 0:v.remoteCarets)!=null&&R.onUserChanged){const G=(M=(L=t.componentsOptions)==null?void 0:L.remoteCarets)==null?void 0:M.onUserChanged;o.doc.getRemoteUsers().on("change",q=>{G(o,q)})}return(F=(U=t.componentsOptions)==null?void 0:U.templates)!=null&&F.templates.length&&(o.addListener("docChanged",()=>{Q0(o)}),o.addListener("resize",()=>{Q0(o,{reset:!0})}),setTimeout(()=>{Q0(o)},100)),o.doc.registerCallback({onError:async G=>{if(G.code==="ResetDoc"){QE.error(`reset doc: ${G.message}`);const q=await yu.load(r);o.doc.reset(q)}}}),o}function sJ(n){return n.toJSON!==void 0}async function lJ(n,t,e){var o,s,l,c,d,h;p(QE,n,"app does not exists");const r=sJ(t)?t:new q1(t,{serverUrl:e.serverUrl||""});e.lang&&D.setLang(e.lang),si.level=(o=e.logLevel)!=null?o:ws.DEBUG;const i=hu(n,r,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[MC,HC,jC,Hy],commandProviders:[new Zh],decorators:[new k0,new gp],embeds:[...qE,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[nk,g4,Fw,ok,...((l=e.components)==null?void 0:l.boxes)||[]],insertions:[p1],blockHooks:[new rE,...((c=e.components)==null?void 0:c.blockHooks)||[]],textRenders:[new Iw,new gC,...((d=e.components)==null?void 0:d.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[UC,sw,SC,Ch]});return i.editorCommandProviders.registerCommandProvider(new Ri(i)),i.input.addHandler(new w0),i.input.addHandler(new zC(i,{hideTitle:e.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new E0(i,(h=e.componentsOptions)==null?void 0:h.quickMenu)),i.input.addHandler(new uE(i)),i.input.addHandler(new pE(i)),i.input.addHandler(new D0),i.addCustom("block-menu",C=>new xR(C)),he.isMobile||i.addCustom("editor-tooltip",()=>new A0(i)),i.addCustom("image-paste-handler",()=>new cE(i)),e!=null&&e.enableComments&&i.addCustom("editor-comments",C=>new Lw(C,new rZ(C,r))),i.addCustom("heading-collapse",()=>new UE(i)),i.addListener("clickLink",(C,E,x)=>{var R;if((R=e==null?void 0:e.events)!=null&&R.onClickLink){e.events.onClickLink(C,E,x);return}const v=x.getAttribute("link");v&&(C.readonly||E.ctrlKey||E.metaKey)&&window.open(v,"_blank")}),Ha.register(i),i}function aJ(n,t,e){var h;const r=n.doc.externalDoc.client.auth,i=new k2({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 H4(l),d=n.addCustom("version-dialog",()=>new e4(i,c));return d.show(t),d}b.tippy=c6,b.AnchorBox=Q3,b.AuthError=Ih,b.AuthHeader=ya,b.AutoScroll=Ld,b.BaseURLHeader=Tu,b.BasicCommands=iF,b.BlockExclusiveHook=CR,b.BlockLockerHook=rE,b.BlockLockerPasteHandler=D0,b.BlockResizer=qu,b.BrBox=G3,b.CodeBlock=HC,b.CodeLineBlock=jC,b.CodeTextDecorator=k0,b.DefaultShortcuts=Ch,b.DocIdError=tU,b.DragDrop=Eb,b.DrawioEmbed=L4,b.EditorBlocks=wv,b.EditorBoxes=q3,b.EditorCommandProviders=N5,b.EditorComplexBlockPosition=Ur,b.EditorComplexSelectionRange=ui,b.EditorDecorators=tB,b.EditorEmbeds=Lv,b.EditorInsertions=J3,b.EditorSimpleBlockPosition=_e,b.EditorSimpleSelectionRange=Ge,b.EmbedBlock=Dv,b.EmbedBlockResizer=hf,b.EnforceWithDocumentTitleHandler=zC,b.EventCallbacks=ea,b.FILL_CHAR=v8,b.FileExtError=eU,b.GroupOrder=qy,b.HeadingBlockScrollListener=cX,b.ImageBox=X3,b.InlineBoxCommandProvider=sk,b.InputtingInsertion=Y3,b.LocalDoc=q1,b.LogLevel=ws,b.Logger=si,b.MIN_DISTANCE_THRESHOLD=pb,b.ManualCloseDialog=Ru,b.ManualMenu=rl,b.ManualToolbar=ku,b.MarkdownInputHandler=w0,b.MaxUserError=sp,b.Mindmap=u0,b.OnesEditorAutoSuggest=Op,b.OnesEditorCustomDataWrapper=Jx,b.OnesEditorExclusiveBlock=os,b.OnesEditorHoveringBlock=be,b.OnesEditorIcons=KU,b.OnesEditorQuickMenu=E0,b.OnesEditorToc=gf,b.OnesEditorTocProvider=fs,b.OnesEditorToolbar=Ha,b.OnesEditorTooltip=A0,b.OnesEditorVersionsDialog=e4,b.PermissionError=JM,b.Popup=Sa,b.RemoteCarets=T2,b.RemoteCaretsDecorator=gp,b.RemoteCaretsInsertion=p1,b.RemoteUsers=mu,b.RequestReloadError=Bu,b.RichText=dn,b.ShareDBDoc=yu,b.ShareDBDocVersionsProvider=H4,b.ShareDBServer=k2,b.SimpleCache=lb,b.StandardEmbedBlockCommands=wE,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=qg,b.TEXT_STYLE_COLOR_PREFIX=Wg,b.TableBlock=MC,b.TableBlockCommandProvider=Zh,b.TableShortcuts=UC,b.TextBlock=Mn,b.TextBox=z3,b.TextColorItem=KT,b.TextStyleShortcuts=SC,b.TocEmbed=d4,b.ZERO_WIDTH_SPACE_CHAR=Kc,b.abbreviation=Id,b.addAttribute=jd,b.addClass=z,b.addCommentToBlock=df,b.addDays=C9,b.addMetaToDoc=Ah,b.addMonths=p9,b.animateScrollTo=_s,b.applyPlaceholderToBlock=Gu,b.assert=p,b.autoShowHideTemplates=Q0,b.blockToDoc=z1,b.blockToHtml=A1,b.blockToMarkdown=x1,b.blockToText=oh,b.blocksToDoc=zD,b.clearAllSelection=uv,b.clientType=he,b.cloneBlock=zo,b.cloneChildContainer=I1,b.cloneDoc=D1,b.cloneText=U3,b.commentToShareDbComment=mp,b.compareElement=bd,b.comparePosition=Vg,b.complexBlockAdjustSelectionPos=Vd,b.complexBlockFindNearestChildBlock=Ov,b.complexBlockGeFirstSimpleChild=Hg,b.complexBlockGetAllChildContainers=xn,b.complexBlockGetBottomChildContainers=Uv,b.complexBlockGetLastSimpleChild=aa,b.complexBlockGetSelectedContainers=la,b.complexBlockGetTopChildContainers=Mv,b.containerToDoc=g5,b.continuousScroll=Ub,b.convertBlockFrom=Od,b.convertImageFileToPng=Nk,b.convertImageSrcToPng=IV,b.converterIntercept=R0,b.copyBlockAttributes=mB,b.copyResourcesFromDoc=W1,b.createBlockAnchor=Yi,b.createBlockCaretAnchor=Kv,b.createBlockContentElement=Ks,b.createBlockElement=ev,b.createBlockSimpleDocRange=th,b.createBlockSimpleRange=ve,b.createBoxContentElement=iv,b.createBoxElement=nv,b.createBoxOp=M3,b.createChildContainer=kv,b.createComplexBlockPosition=Ee,b.createComplexDocPos=V3,b.createComplexDocRange=y8,b.createContainer=P3,b.createContainerElement=Ng,b.createDeleteOps=L3,b.createEditor=hu,b.createEditorSelectionRange=We,b.createElement=B,b.createEmptyContainer=no,b.createEmptyDoc=eo,b.createEmptyTextBlockData=Zd,b.createExpandedRange=Ad,b.createIconButton=Ls,b.createImage=fg,b.createInsertOps=Qd,b.createInsertionContentElement=lv,b.createInsertionElement=ov,b.createLocalEditor=lJ,b.createOnesEditor=oJ,b.createRange=ab,b.createRichText=Xs,b.createRootContainer=yv,b.createSimpleBlockPosition=lt,b.createSimpleDocPos=K3,b.createTextBlockData=mi,b.createTextButton=cl,b.createTextOp=gr,b.createTextWithReplaceSoftReturn=s1,b.daysAfter=kg,b.deleteText=a1,b.diffDays=E9,b.disablePageScroll=Sb,b.docToHtml=cB,b.docToHtmlFragment=sh,b.docToMarkdown=uB,b.docToText=Qs,b.downloadImageToFile=Kk,b.downloadObjectToFile=$E,b.downloadSvgToString=b4,b.editLink=Pu,b.editorAddComment=mW,b.editorAddTextAttribute=yB,b.editorAutoInsertBlock=gB,b.editorBreakTextBlock=Ea,b.editorClearCompositionText=T1,b.editorClearSelectedContents=S1,b.editorCopyBlock=xh,b.editorDeleteBlock=R1,b.editorDeleteBlockText=y1,b.editorDeleteBlockWithoutChildren=ch,b.editorDeleteChildContainer=BD,b.editorDeleteChildContainers=pB,b.editorFocusToBlock=L1,b.editorFocusToEnd=HD,b.editorGetBlockData=jo,b.editorGetBlockText=bn,b.editorGetBlockTextEx=nh,b.editorGetBoxData=H3,b.editorHandleKeyboardEvent=A5,b.editorInsertBlock=Ca,b.editorInsertBoxToBlock=dB,b.editorInsertDoc=BB,b.editorInsertDocAt=_1,b.editorInsertText=B1,b.editorInsertTextToBlock=fB,b.editorInsertTextToBlockEx=v1,b.editorMergeTextBlock=CB,b.editorMoveDown=PB,b.editorMoveEnd=K1,b.editorMoveHome=qB,b.editorMoveLeft=UB,b.editorMoveLineEnd=n5,b.editorMoveLineHome=e5,b.editorMovePageDown=a5,b.editorMovePageUp=l5,b.editorMoveRight=OB,b.editorMoveUp=NB,b.editorMoveWordEnd=zB,b.editorMoveWordLeft=jB,b.editorRangeClearColor=RB,b.editorRangeGetColor=wB,b.editorRangeSetColor=kB,b.editorRemoveTextAttribute=RD,b.editorReplaceBlockText=fh,b.editorReplaceContainer=TB,b.editorRunOnce=X1,b.editorSelectAll=h5,b.editorSelectContainer=H1,b.editorSelectDown=FB,b.editorSelectEnd=V1,b.editorSelectHome=XB,b.editorSelectLeft=KB,b.editorSelectLineEnd=t5,b.editorSelectLineHome=JB,b.editorSelectPageDown=u5,b.editorSelectPageUp=c5,b.editorSelectRight=VB,b.editorSelectUp=$B,b.editorSelectWordEnd=WB,b.editorSelectWordLeft=GB,b.editorSetTextColor=Aa,b.editorShowFindDialog=xG,b.editorToDocx=iJ,b.editorUpdateBlockData=dh,b.editorUpdateCompositionText=hB,b.editorUpdateEmbedData=bB,b.enablePageScroll=Lb,b.escapeHtmlText=Bd,b.escapeRegExp=Lg,b.escapeSpace=t9,b.exclusiveBlock=tE,b.executeBlockCommand=Av,b.executeEmbedBlockCommand=Ev,b.executeRangeCommand=O5,b.fileToDataUrl=ia,b.findAfterOffsetNotType=h1,b.findAllText=u1,b.findEventTargetBlock=db,b.findInsertionById=sv,b.findNextOffset=z8,b.findNextVisibleSimpleBlock=$5,b.findPrevOffset=j8,b.findPrevOffsetNotType=d1,b.findPrevSimpleBlockBeforeChildContainer=_v,b.findPrevVisibleSimpleBlock=V5,b.findTarget=ra,b.findWordEnd=g1,b.findWordLeft=m1,b.format=Gc,b.formatBytes=Ob,b.formatDate=wg,b.fragmentToHtml=Ib,b.fromBase64=Hc,b.fromBase64ToBlob=vg,b.fromBase64ToUint8Array=f9,b.fromDocRange=Vo,b.fromNowString=Sg,b.genId=J,b.getAllChildBlocks=zg,b.getAllQuickMenuItems=wC,b.getAllSelectedBlocks=fi,b.getAttributesAt=da,b.getBlockBackground=tv,b.getBlockByIndex=zi,b.getBlockCaretRect=_r,b.getBlockClass=Zt,b.getBlockClassByType=Ns,b.getBlockClientRects=qi,b.getBlockCommandsWithHook=Ug,b.getBlockContent=Ot,b.getBlockId=st,b.getBlockIndex=bt,b.getBlockInfo=Ju,b.getBlockKind=Ir,b.getBlockMinWidth=dv,b.getBlockNearestRangeFromPoint=Fv,b.getBlockOptions=L9,b.getBlockPath=Ko,b.getBlockProperties=gv,b.getBlockRangeFromPoint=$d,b.getBlockStyles=S9,b.getBlockTextLength=dt,b.getBlockTools=ne,b.getBlockType=It,b.getBoxContent=Qc,b.getBoxId=rv,b.getBoxTypeFromElement=Xc,b.getChildBlockCount=Lr,b.getChildBlocks=Ce,b.getChildOffset=$o,b.getColorFromAttributes=Qg,b.getColorFromContent=Dd,b.getComplexBlockClass=qn,b.getContainerBlockPath=vv,b.getContainerBlocks=cv,b.getContainerBlocksElement=Fd,b.getContainerById=ci,b.getContainerId=ft,b.getContainerMinWidth=Fg,b.getContainerToolsElement=U9,b.getContainerWidth=Rv,b.getDistanceSquare=Vi,b.getElementOffset=Fc,b.getElementScale=ur,b.getEmbedType=un,b.getExistsBlockTools=_d,b.getExistsContainerById=Pd,b.getFileExt=zc,b.getFirstChildBlock=ke,b.getFirstClientRect=xd,b.getHeadingMenuOptions=vC,b.getHorizontalPadding=hg,b.getInsertionContent=Dg,b.getLastChildBlock=Ze,b.getLastClientRect=Is,b.getListAllNextBrothers=Pa,b.getLogger=I,b.getNextBlock=Gt,b.getNextValidOffset=Ws,b.getNextVisibleBlock=$s,b.getOffsetFromPoint=dg,b.getOffsetInfoAfter=ou,b.getOffsetInfoBefore=rh,b.getOpAt=d3,b.getOpLength=Hd,b.getParentBlock=nt,b.getParentBlockExcludeSelf=Fs,b.getParentBox=Ig,b.getParentContainer=it,b.getPrevBlock=me,b.getPrevValidOffset=Ho,b.getPrevVisibleBlock=Vs,b.getRangeCommands=M5,b.getReferenceClientRect=Ay,b.getRootBlock=Ud,b.getScrollContainer=cn,b.getSpecialBlockCommands=pv,b.getStandardEmbedBlockProperties=SE,b.getTextAfterOffset=$8,b.getTextAttributes=b1,b.getTextBeforeOffset=H8,b.getTextBlockChild=Nd,b.getTextBlockClass=Wb,b.getTextBlockContentChildTextLength=mr,b.getTextBlockContentChildType=xv,b.getTextBlockContentChildren=ai,b.getTextLength=fn,b.getTextOpLength=Gg,b.getTextWidth=Rd,b.getToolbar=i0,b.handleBlockElementUpdated=hv,b.hasAltOnly=s9,b.hasClass=Rt,b.hasCtrlOrCmd=Tb,b.hasCtrlOrCmdOnly=o9,b.hashCode=Hb,b.hideBlock=Zb,b.htmlToFragment=kd,b.i18n=D,b.injectDocToHtmlFragment=Eh,b.injectStyle=gb,b.insertEmptyBlock=_9,b.insertEmptyEmbedBlock=Og,b.insertText=to,b.intersectionCommands=G_,b.isBackspace=kb,b.isBlock=Ps,b.isBlockLocked=I0,b.isBlockLockedByOthers=nE,b.isBlockLockedBySelf=tf,b.isBlockTools=Yb,b.isBox=Md,b.isBoxOp=zs,b.isCJK=vb,b.isChildContainer=Mr,b.isChildNode=ee,b.isCodeBlock=vi,b.isCollapsedRange=T8,b.isComplexBlockPosition=sa,b.isComplexKindBlock=_t,b.isContainer=Wi,b.isContainerSelectedAllChildBlocks=f5,b.isControlEvent=Us,b.isDelete=a9,b.isDraggingFiles=wd,b.isElementVisible=pg,b.isEmbedBlock=Re,b.isEmptyContainer=Jc,b.isEmptyDoc=f1,b.isEmptyTextBlock=re,b.isEmptyTextBlockWithoutCompositionText=zu,b.isEnterOnly=yb,b.isEscape=xg,b.isExclusiveBlock=Zu,b.isFirefox=yd,b.isFirstChildBlockInComplexBlock=hI,b.isHighSurrogate=Q6,b.isInBlock=_g,b.isInBlockTools=Hs,b.isLetter=bb,b.isLowSurrogate=Y6,b.isMatchShortcut=li,b.isMoveForward=r9,b.isNavigationEvent=n9,b.isNavigationKey=Bb,b.isNodeRemoved=ub,b.isNumber=xb,b.isPrintableKey=Ag,b.isRootBlock=dr,b.isRootContainer=Qt,b.isSafari=$c,b.isSameDay=Rg,b.isSecureEnv=VC,b.isSelectBoxOnly=jy,b.isShiftEnter=l9,b.isShiftTab=u9,b.isShortcutEvent=i9,b.isSimpleBlock=w9,b.isSimpleBlockPosition=Or,b.isSimplePos=F3,b.isSimpleRange=Jd,b.isSpace=Td,b.isTab=c9,b.isTextBlockContentBoxChild=hr,b.isTextBlockContentChild=Yc,b.isTextBlockContentInsertionChild=Qi,b.isTextBlockContentTextChild=Zc,b.isTextKindBlock=et,b.isTextKindBlockType=Wc,b.isTitleBlock=Gi,b.isToday=Nb,b.isValidOffset=_n,b.isVisibleBlock=qc,b.isYesterday=Pb,b.loadJs=fb,b.loadJsPromise=Ds,b.lockers=Sr,b.mergeCommands=r0,b.mergeDocs=Ys,b.mergeOps=l1,b.mergeText=x8,b.multiSplitText=m3,b.overflowText=Fb,b.parseShortcut=Rb,b.patchNode=jc,b.pointInRect=Ms,b.rangeAddAttribute=nu,b.rangeGetTextColor=b3,b.rangeRemoveAttribute=fa,b.rangeSetTextColor=E3,b.rangeTransformText=p3,b.registerDragDrop=Cg,b.removeAttribute=Xg,b.removeClass=ot,b.removeLastBr=p8,b.removePlaceholderFromBlock=Hk,b.removeStyle=mb,b.replaceAll=A9,b.replaceAllCaseInsensitive=x9,b.replaceAllText=N3,b.replaceText=Yd,b.requestDownload=Sd,b.resetListStart=Ka,b.scrollable=Mb,b.selectFile=oa,b.selectedBlockToDoc=mh,b.selectionToDoc=gh,b.setAttributes=vd,b.setClipboardData=yg,b.setClipboardDataByEvent=g9,b.setColorToAttributes=A3,b.setDataset=mg,b.setDefaultCursor=Vc,b.setStyles=gg,b.shareDBCommentToDocObject=hp,b.shareDBDocCommentToComment=v2,b.shortcutToDisplayText=fr,b.showBlock=Jb,b.showDocVersions=aJ,b.splitText=In,b.splitToThree=qe,b.stringToDataUrl=Bg,b.stringToObjectUrl=Tg,b.subText=g3,b.textNodeOffsetFromPoint=cb,b.titleFromEditor=Fk,b.toBase64URL=ji,b.toMindmap=c0,b.toPlainText=ce,b.toPlainTextKeepLength=c1,b.trimChar=Eg,b.unexclusiveBlock=eE,b.unicodeLength=Z6,b.unicodeSubstr=J6,b.updateBlockSelection=fv,b.updateOpAttributes=O3,b.updateTextBlockContent=V8,b.updateUrl=bg;for(const n in ye)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>ye[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|