@ones-editor/editor 0.0.3-beta.167 → 0.0.3-beta.168
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/@ones-editor/tsconfig.tsbuildinfo +1 -1
- package/dist/index.js +19 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ Available method signatures are:
|
|
|
24
24
|
`:""}const p6={boxType:"br",updateBoxContent:_I,convertTo:FI},C6=S("editor-boxes");class A6{constructor(t){m(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,o=this.boxes.get(e);g(C6,!o,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return g(C6,e,`unknown box type: ${t}`),e}createBox(t,e){const o=qC(e),r=ZC(o);return this.getBoxClass(e.type).updateBoxContent(this.editor,o,r,e),o}}function PI(n,t,e,o){const r=o,{width:i,height:s,src:l}=r,a=["editor-box-image"];r.link&&a.push("editor-box-image-link");const d=w("img",a,e);i&&(d.style.width=`${i}px`),s&&(d.style.height=`${s}px`),d.src=n.doc.buildResourceUrl(l)}const b6={boxType:"image",updateBoxContent:PI},NI="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9InJnYigxNzgsIDE4OCwgMjA1KSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0ibTE3IDE1IDEuNTUgMS41NWMtLjk2IDEuNjktMy4zMyAzLjA0LTUuNTUgMy4zN1YxMWgzVjloLTNWNy44MkMxNC4xNiA3LjQgMTUgNi4zIDE1IDVjMC0xLjY1LTEuMzUtMy0zLTNTOSAzLjM1IDkgNWMwIDEuMy44NCAyLjQgMiAyLjgyVjlIOHYyaDN2OC45MmMtMi4yMi0uMzMtNC41OS0xLjY4LTUuNTUtMy4zN0w3IDE1bC00LTN2M2MwIDMuODggNC45MiA3IDkgN3M5LTMuMTIgOS03di0zbC00IDN6TTEyIDRjLjU1IDAgMSAuNDUgMSAxcy0uNDUgMS0xIDEtMS0uNDUtMS0xIC40NS0xIDEtMXoiPjwvcGF0aD4KPC9zdmc+Cg==";function $I(n,t,e){W(e,"editor-box-anchor"),pm(NI,[],e)}const v6={boxType:"anchor",updateBoxContent:$I};function HI(n,t,e,o){w("span",[],e,o.text)}const y6={insertionType:"inputting",updateInsertionContent:HI},k6=S("editor-insertion");class w6{constructor(t){m(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,o=this.insertions.get(e);g(k6,!o,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return g(k6,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const o=QC(e.type,e.id),r=JC(o);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,o,r,e),o}}class jI{constructor(t){m(this,"cursors",new Map);m(this,"timer");this.editor=t,this.timer=this.startTimer()}add(t,e){this.cursors.set(t,e)}startTimer(){return setInterval(()=>{const t=Date.now();Array.from(this.cursors).forEach(([e,o])=>{if(t-o>3e3){const r=YC(this.editor,e);r&&et(r,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function UI(n,t,e,o){var l;const r=o;Date.now()-r.time<5*1e3&&(n.addCustom("active-cursors",d=>new jI(d)).add(r.id,r.time),W(t,"active")),w("span",[],e,"|").setAttribute("data-cursor-name",r.name),t.style.setProperty("--cursor-color",n.getColor((l=r.rainbowIndex)!=null?l:0))}const wg={insertionType:"remote-cursor",updateInsertionContent:UI};class B6{constructor(t){m(this,"decorators",[]);this.editor=t}registerDecorator(t){this.decorators.push(t)}decorateBlock(t,e){let o=e;return this.decorators.forEach(r=>{if(r.decorateBlock){const i=r.decorateBlock(this.editor,t,e);i&&(o=mt.default(i))}}),o}decorateText(t,e){let o=e;const r=new Map;return this.decorators.forEach(i=>{if(i.decorateText){const s=i.decorateText(this.editor,t,e);if(s){const{insertions:l,text:a}=s;l&&Array.from(l.entries()).forEach(([d,h])=>{const p=r.get(d);p?p.push(...h):r.set(d,h)}),a&&(o=mt.default(a))}}}),{insertions:r,text:o}}}const Bg=S("editor-input");class zI{constructor(t,e){m(this,"editor");m(this,"composing",!1);m(this,"callbacks");m(this,"inputElement");m(this,"handleDocumentClick",t=>{const e=this.editor.rootContainer,o=t.target;if(o&&e.contains(o)&&!Ls(o)){this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus();return}this.editor.emit("blur",this.editor),this.callbacks.onBlur()});m(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&this.editor.contains(t)&&!Ls(t)||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});m(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});m(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});m(this,"handleCompositionstart",t=>{!this.editor.isWritable()||(this.composing=!0,this.callbacks.onCompositionStart(t))});m(this,"handleCompositionend",t=>{this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});m(this,"handleInput",t=>{if(t instanceof InputEvent&&!!t.data){if(this.editor.readonly||!this.editor.isWritable()){this.inputElement.value="";return}this.composing?this.callbacks.onUpdateCompositionText(t,t.data,!1):(this.callbacks.onInsertText(t,t.data),this.inputElement.value="")}});m(this,"handleKeyDown",t=>{if(!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}!this.editor.isWritable()||setTimeout(()=>{this.composing||(this.inputElement.value="")})}});m(this,"handleCopy",t=>{this.callbacks.onCopy(t)});m(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onCut(t),Bg.debug("on cut")});m(this,"handlePaste",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)});m(this,"handlePasteText",(t,e)=>{this.callbacks.onPasteText(t,e)});this.editor=t,this.callbacks=e;const o=w("input",["editor-input"],t.contentElement);o.type="text",o.name="editor-input",o.onkeydown=this.handleKeyDown,o.oninput=this.handleInput,o.oncopy=this.handleCopy,o.onpaste=this.handlePaste,o.oncut=this.handleCut,o.addEventListener("compositionstart",this.handleCompositionstart),o.addEventListener("compositionend",this.handleCompositionend),this.inputElement=o,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,t.onpaste=null,t.oncut=null}getInput(){return this.inputElement}focus(){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),Ke.isMobileSafari?this.inputElement.focus():setTimeout(()=>{this.inputElement.focus()})}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,o,r,i){g(Bg,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,o,r,i)}defaultHandleKeydown(t,e){return g(Bg,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}}function E6(n){const t=n.rootElement,e=t.getBoundingClientRect(),o=ys(t),r=window.innerWidth,i=window.innerHeight,s=e.left<0?0:e.left,l=e.top<0?0:e.top,a=e.right>r?r:e.right,d=e.bottom>i?i:e.bottom,h=(s+a)/2,p=(l+d)/2,A=0-e.left+h,v=0-e.top+p,B=n.input.inputElement;B.style.left=`${A/o}px`,B.style.top=`${v/o}px`}const Eg=S("editor-caret");class VI{constructor(t){m(this,"editor");m(this,"caretElem");m(this,"handleReadOnlyChanged",()=>{this.update()});this.editor=t,this.caretElem=w("div",["editor-cursor"],this.editor.contentElement),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 je))return!1;const e=this.editor.getBlockById(t.blockId);return!!tt(this.editor,e)}update(){if(oC(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",E6(this.editor);return}const{range:e}=this.editor.selection;g(Eg,e.isCollapsed,"range is not collapsed");const o=e.start;g(Eg,o instanceof je,"only simple block position can has caret");const r=this.editor.getBlockById(o.blockId);g(Eg,tt(this.editor,r),"only text kind block can has caret");let i;const s=r.querySelector("span.inputting-insertion");s?(i=bs(s),i=new DOMRect(i.right,i.top,1,i.height)):i=zn(r,o);const l=this.editor.contentElement.getBoundingClientRect(),a=i.left-l.left,d=i.top-l.top;t.style.left=`${a}px`,t.style.top=`${d}px`,t.style.height=`${i.height}px`;const h=this.editor.input.inputElement;h.style.left=`${a}px`,h.style.top=`${d+i.height-24}px`,Ke.isMobileSafari&&(h.style.left=`${a-4}px`,h.style.height=`${i.height}px`);const A=oo(r,{horizontal:!0}).getBoundingClientRect(),v=A.left-l.left,B=v+A.width;a<v||a>B?(E6(this.editor),t.style.display="none"):t.style.display=""}}function WI(n){n4(n),n.selection.range.getSelectedBlocks().forEach(t=>o4(n,t.block,t.start,t.end))}const qI=S("editor-dom");function x6(n){return oo(n.rootContainer).clientHeight}function GI(n){return n.getFirstBlock().getBoundingClientRect().top}function ZI(n){return n.getLastBlock().getBoundingClientRect().bottom}function xg(n){const e=oo(n.rootContainer).getBoundingClientRect(),o=e.x<0?0:e.x,r=e.y<0?0:e.y,i=e.right>window.innerWidth?window.innerWidth:e.right,s=e.bottom>window.innerHeight?window.innerHeight:e.bottom;return new DOMRect(o,r,i-o,s-r)}function QI(n,t){const e=xg(n),o=n.getBlockById(t.blockId),i=To(n,o,t);return ks(e,i.x,i.y)&&ks(e,i.right,i.bottom)}function I6(n,t){const e=xg(n),o=t.getBoundingClientRect();return o.top>=e.top&&o.top<=e.bottom||o.bottom<=e.bottom&&o.bottom>=e.top}function YI(n,t){const e=xg(n),o=t.getBoundingClientRect();return ks(e,o.x,o.y)||ks(e,o.right,o.bottom)}function JI(n){if(!ym(n.rootContainer)){qI.warn("editorScrollIntoView: editor is not visible");return}const t=n.rootContainer.getBoundingClientRect();if(t.height<1&&t.width<1)return;const e=n.selection,o=e.range.focus;if(!o.isSimple()){const h=o,p=n.getContainerById(h.childContainerId);YI(n,p)||p.scrollIntoView();return}if(e.range.start.blockId===e.range.end.blockId){const h=n.getBlockById(e.range.start.blockId);if(Le(h)&&I6(n,h)||Lt(n,h)&&I6(n,h))return}const r=o,i=n.getBlockById(r.blockId);if(QI(n,r))return;const s=To(n,i,r),l=i.getBoundingClientRect(),a=le(i),d=w("div",["editor-block-anchor"],a);d.style.top=`${s.top-l.top}px`,km(d,{elementToScroll:oo(n.rootContainer)}),setTimeout(()=>{d.remove()},200)}function KI(n,t){if(t.isCollapsed())return!1;const e=Se(n.rootContainer),o=Ge(n.rootContainer),{start:r,end:i}=t;return r.blockId===it(e)&&r.offset===0&&i.blockId===it(o)&&i.offset===ut(n,o)}const T6=S("range-in-block");function D6(n,t){const e=t.getEditor(),o=e.getBlockById(t.start.blockId),r=e.getBlockById(t.end.blockId),i=o===n||Kt(n,o),s=r===n||Kt(n,r);return!!(i||s)}function S6(n,t){const e=n.doc.toJSON(),o=new Set(Object.values(e.blocks).map(s=>s.map(l=>l.id)).flat());let r,i=ce(t);if(i){for(;i&&!o.has(it(i));)i=ce(i);g(T6,i,"no prev block while deleting a block"),r=ye(n,i,ut(n,i))}else{const s=Zt(t);g(T6,s,"no prev and next block while deleting a block"),r=ye(n,s,0)}return r}const XI=S("block-to-html");function Ig(n,t,e,o){const r=Ms(n,t.type);if(r.convertTo)return r.convertTo(n,t,e,"html",o);if(r.blockKind!=="text")return`[${t.type}]`;g(XI,t.text,"no text");const i=re(t.text);return`<div>${lC(i)}</div>`}const L6=S("block-to-text");function tT(n,t,e){let o="";return t.forEach(r=>{if(g(L6,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){const i=r.attributes,s=n.editorBoxes.getBoxClass(i.type);if(s!=null&&s.convertTo){o+=s.convertTo(n,i,e,"text");return}if(r.attributes.text){o+=r.attributes.text;return}o+=`[${i.type}]`}o+=r.insert}),o}function Ah(n,t,e,o){const r=Ms(n,t.type);return r.convertTo?r.convertTo(n,t,e,"text",o):r.blockKind!=="text"?`[${t.type}]`:(g(L6,t.text,"no text"),tT(n,t.text,e))}function Tg(n,t,e,o){const r=Ms(n,t.type);return r.convertTo?r.convertTo(n,t,e,"markdown",o):Ah(n,t,e,o)}function bh(n,t){return t.blocks.root.map((r,i)=>Ig(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
|
|
25
25
|
`)}function M6(n,t){return`<!doctype html><html><head><meta charset="utf8" /></head><body>${bh(n,t)}</body></html>`}function La(n,t){return t.blocks.root.map((r,i)=>Ah(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
|
|
26
26
|
`)}function Ma(n,t){const e=t.blocks.root.map((r,i)=>Tg(n,r,t,[{containerId:"root",blockIndex:i}]));return e[e.length-1]=e[e.length-1].trimEnd(),e.join(`
|
|
27
|
-
`)}const eT=S("get-text-position");function Gl(n,t){const e=t!=null?t:n.selection.range.start;e instanceof je||g(eT,!1,`invalid insert pos type: ${typeof e}`);const{blockId:o}=e,r=n.getBlockById(o),i=bt(r),s=nt(r),l=at(s),{offset:a}=e;return{block:r,container:s,containerId:l,blockIndex:i,offset:a}}const Zl=S("insert-text");function Dg(n,t,e,o){var s;const r=n.doc.getBlockData(t,e);if(g(Zl,r,"no block data"),g(Zl,r.text,"no block text"),rn(r.text)===0)return g(Zl,o===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,r.id);if(o===0)return;const i=ze(r.text,o-1,1).middle;if(!((s=i[0].attributes)!=null&&s.box))return i[0].attributes}function nT(n,t,e){const o=nt(t),r=at(o),i=bt(t);return Dg(n,r,i,e)}function R6(n,t,e,o,r){const i=nt(t),s=at(i),l=bt(t),a=nT(n,t,e),d=ch(e,o,a!=null?a:null);return n.doc.localUpdateBlockText(s,l,d,r),mn(n,t)}function O6(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=ch(e," ",o);return n.doc.localUpdateBlockText(i,s,l),mn(n,t)}function oT(n,t){let e=0;if(t===0)return!1;for(let o=0;o<n.length;o++){const r=n[o];g(Zl,typeof r.insert=="string","invalid text op, no insert");const i=e+ah(r);if(i===t)return!1;if(i>t)return!0;e=i}return!1}function Sg(n,t,e,o,r){const i=n.doc.getBlockData(e,o);g(Zl,i,"no block data"),g(Zl,i.text,"no block text");const s=Dg(n,e,o,r);s&&Object.keys(s).includes("link")&&(oT(i.text,r)||delete s.link);const l=ch(r,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,o,l),mn(n,n.getBlockById(i.id))}function Lg(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:o,offset:r}=Gl(n);Sg(n,t,e,o,r)}const vh=S("update-composition-text");function _6(n){const t=n.selection.range.start;t instanceof je||g(vh,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,o=n.getBlockById(e);g(vh,tt(n,o),"not a text kind block");const r=nt(o),i=at(r),s=bt(o),l=n.doc.getBlockData(i,s);g(vh,l,"no block data in doc"),g(vh,l.text,"no text data in text block");const a=Rt(o);rh(n,Di(o),e,a,l.text)}function F6(n){_x(n)}function Ql(n,t,e,o,r,i){return n.doc.localInsertBlock(t,e,o,r,i),n.getBlockById(o.id)}const Ra=S("delete-block-text");function Mg(n,t,e,o,r){if(!n.isBlockWritable(t))return Ra.error("block is not writable"),0;g(Ra,tt(n,t),"block is not a text kind block");const i=nt(t),s=at(i),l=bt(t),a=n.doc.getBlockData(s,l);g(Ra,a,"no block data in doc"),g(Ra,a.text,"no text data in text block");let d=e;sn(t,e)||(d=Ri(t,d));let h=e+o;g(Ra,h<=ut(n,t),`invalid offset and count: ${e}, ${o}`),sn(t,h)||(h=Fs(t,h));const p=h-d,A=W4(d,p);return n.doc.localUpdateBlockText(s,l,A,r),p}const Rg=S("break-text-block");function P6(n,t){const o=n.getBlockData(t).quoted;return o?{quoted:o}:{}}function Yl(n,t,e,o){g(Rg,tt(n,t),`block is not a text kind block: ${Dt(t)}`),g(Rg,e>=0&&e<=ut(n,t),`invalid offset: ${e}`);const r=nt(t),i=at(r),s=bt(t),l=o!=null&&o.copyBlockAttributes?P6(n,t):{};if(!(o!=null&&o.forceInsertAfter)&&(e===0||e===ut(n,t))){const v=e===0?s:s+1,B={...sr(""),...l,...o==null?void 0:o.newBlockData},D=ye(n,t.id,0),T=Ql(n,i,v,B,D);return{block:t,newBlock:T}}g(Rg,sn(t,e),"not a valid offset");const a=mn(n,t),{right:d}=xn(a,e),h=rn(d);h>0&&Mg(n,t,e,h);const p={...sr(d),...l,...o==null?void 0:o.newBlockData},A=Ql(n,i,s+1,p,ye(n,p.id,0));return{block:t,newBlock:A}}const rT=S("prepare-insert-new-block");function iT(n,t,e){if(t&&e!==void 0&&e!==null){const d=n.getContainerById(t),h=ve(d);return g(rT,e>=0&&e<=h.length,`invalid blockIndex: ${e}`),{containerId:t,blockIndex:e}}const o=n.selection.range.start;if(!o.isSimple())return null;const r=n.getBlockById(o.blockId);if(t=at(nt(r)),e=bt(r),!tt(n,r))return{containerId:t,blockIndex:e+1};const s=o.offset;if(s===0||s===ut(n,r))return{containerId:t,blockIndex:s===0?e:e+1};const a=Yl(n,r,s).newBlock;return{containerId:t,blockIndex:bt(a)}}const sT=S("auto-insert-block");function N6(n,t,e,o,r,i){const s=iT(n,e,o);g(sT,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},a={anchor:l,focus:l};return Ql(n,s.containerId,s.blockIndex,t,r!=null?r:a,i)}const lT=S("delete-block");function yh(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(o=>{n.getChildContainerData(o).forEach(i=>{yh(n,i,e)})}))}function kh(n,t,e){const o=nt(t),r=at(o),i=bt(t),s=n.doc.getBlockData(r,i);return g(lT,s,"no block data in doc"),n.doc.localDeleteBlock(r,i,Ue(n,{anchor:e.start,focus:e.end})),s}function Og(n,t,e){return n.undoManager.runInGroup(()=>{const o=nt(t);Eo(o)===1&&n.insertTextBlock("",at(o),0);let r=e?Si(n,e):null;if(!r){const l=n.selection.range;D6(t,l)?r=S6(n,t):r=l}const i=kh(n,t,r),s=[];return yh(n,i,s),s.length>0&&n.doc.localDeleteChildContainers(s),i})}function cT(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(r=>{yh(n,r,e)}),n.doc.localDeleteChildContainers(e)}function $6(n,t){const e=[...t];t.forEach(o=>{n.doc.getContainerBlocks(o).forEach(i=>{yh(n,i,e)})}),n.doc.localDeleteChildContainers(e)}const _g=S("merge-text-block");function H6(n,t,e){g(_g,tt(n,t),"only text block can be merged"),g(_g,tt(n,e),"only text block can be merged");const o=_i(n,t),r=_i(n,e),i=o.text,s=r.text;g(_g,i&&s,"block data has no text");const l=nt(t),a=at(l),d=bt(t),h=ut(n,t),p=Sg(n,s,a,d,h),A=ye(n,t,rn(i));return Og(n,e,A),p}const lr=S("clear-selected-contents");function wh(n,t){g(lr,tt(n,t.block),"not a text kind block");const{start:e,end:o}=t;g(lr,e.isSimple(),"not a simple block position"),g(lr,o.isSimple(),"not a simple block position");const r=e.offset,i=o.offset;g(lr,r<=i,`invalid delete text offset: ${r}, ${i}`),r!==i&&n.deleteTextFromBlock(t.block,r,i-r)}function j6(n,t,e){const o=at(t),r=ve(t),i=e.focus?void 0:n.selection.range.toDocRange(),s=n.insertTextBlock("",o,0,{newRange:i});e.focus&&n.selection.selectBlock(s,0),r.reverse().forEach(l=>{n.deleteBlock(l)})}function aT(n,t){const{block:e,start:o,end:r}=t;if(tt(n,e)){wh(n,t);return}if(Le(e)||o.isSimple()){g(lr,r.isSimple(),"invalid range");const s=nt(e),l=bt(e),a=n.insertTextBlock("",at(s),l);n.selection.selectBlock(a,0),n.deleteBlock(e);return}g(lr,Lt(n,e),"invalid block kind"),g(lr,!o.isSimple()&&!r.isSimple(),"invalid range"),Os(n,e,o,r),n.selection.range.getSelectedContainers().forEach((s,l)=>{j6(n,s,{focus:l===0})})}function uT(n){if(!n.isWritable())return;const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(g(lr,e.length>0,"no selected block"),e.length===1){aT(n,e[0]);return}const o=e[0],r=o.block,i=nt(r);g(lr,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(tt(n,r)){wh(n,o);const h=ye(n,o.block,o.start.offset);if(e.slice(1,e.length-1).reverse().forEach(A=>n.deleteBlock(A.block)),tt(n,l)){wh(n,s),n.mergeTextBlock(r,l,{focus:!0}),n.selection.setRange(h);return}n.deleteBlock(l),n.selection.setRange(h);return}if(tt(n,l)){wh(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===Eo(i)){j6(n,i,{focus:!0});return}const a=ce(r),d=Zt(l);g(lr,a||d,"no prev or next block"),e.forEach(h=>n.deleteBlock(h.block))}function Fg(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),uT(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}const dT=S("core");function U6(n,t,e){const o=nt(t),r=at(o),i=bt(t);return n.doc.localUpdateBlockText(r,i,e),setTimeout(()=>{n.selection.updateSelection(null)}),mn(n,t)}function z6(n,t,e){if(!n.isBlockWritable(t)){dT.error("block is not writable");return}const o=n.getBlockText(t),r=ln.diff(o,e);U6(n,t,r)}function Bh(n,t,e){const o=mn(n,t),r=typeof e=="string"?Oi(e):e,i=ln.diff(o,r);return U6(n,t,i)}const Oa=S("update-block-data");function Eh(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=n.doc.getBlockData(i,s),a={insert:{},delete:[]},d=new Set(Object.keys(l)),h=new Set(Object.keys(e));return d.forEach(A=>{if(!h.has(A)){if(A==="id"||A==="type"||A==="text")return;Oa.debug(`delete key: ${A}`),a.delete.push(A)}}),Object.entries(e).forEach(([A,v])=>{g(Oa,A!=="id"&&A!=="type",`invalid block data delta, ${A}`);const B=l[A];if(v==null){B!=null&&(Oa.debug(`delete key: ${A}`),a.delete.push(A));return}B!==v&&(ua.default(B,v)||A==="text"&&ln.diff(B,v).length===0||(d.has(A)?(Oa.debug(`replace key: ${A}`),a.delete.push(A)):Oa.debug(`insert key: ${A}`),a.insert[A]=v))}),n.doc.localUpdateBlockData(i,s,a,o),_i(n,t)}function V6(n,t,e,o){const i={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,i,o)}function Pg(n,t,e){if(!Lt(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const r=jn(n,t).getChildContainers(n,t)[0],i=Se(r);Pg(n,i,e)}function $s(n){const t=[];let e={};return n.forEach(o=>{t.push(...o.blocks.root);const{root:r,...i}=o.blocks;e={...e,...i}}),{blocks:{...e,root:t},meta:{},comments:{}}}const _a=S("clone-block");function Fi(n,t,e,o){const r=n.getBlockClass(e.type);if(r.blockToDoc)return r.blockToDoc(t,e,(h,p)=>(g(_a,e!==p,"invalid child block"),Fi(n,h,e,o)));let i={};const s=new Map,l=mt.default(e);l.children&&(l.children=l.children.map(h=>{const p=K(),A=t.blocks[h];g(_a,Array.isArray(A),"invalid child blocks");const v=A.map(_=>Fi(n,t,_,o)),B=$s(v),{root:D,...T}=B.blocks;return i={...i,...T},i[p]=B.blocks.root,s.set(h,p),p}));const a=Array.from(s.entries()),d=h=>{for(const p of a){const[A,v]=p;{const B=`${A}/`;if(h.startsWith(B)){const D=h.substring(B.length),T=`${v}/${D}`;return _a.debug(`replace key: ${h} -> ${T}`),T}}{const B=`${A}_`;if(h.startsWith(B)){const D=h.substring(B.length),T=`${v}_${D}`;return _a.debug(`replace key: ${h} -> ${T}`),T}}}return h};return Array.from(Object.entries(l)).forEach(([h,p])=>{const A=d(h);A!==h&&delete l.key,l[A]=p}),l.id=K(),o&&(o.blockIdMap.set(e.id,l.id),s.forEach((h,p)=>o.containerIdMap.set(p,h))),{blocks:{root:[l],...i},meta:{},comments:{}}}function Ng(n,t,e,o){const r=t.blocks[e];g(_a,Array.isArray(r),"invalid child blocks");const i=r.map(l=>Fi(n,t,l,o));return $s(i)}function $g(n,t,e){const o=t.blocks.root.map(r=>Fi(n.editorBlocks,t,r,e));return mt.default($s(o))}const W6=S("insert-doc");function q6(n,t,e,o,r){if(Lt(n,t)){W6.warn("failed to insert doc into a complex block");return}const i=$g(n,o,r),s=nt(t),l=bt(t),a=at(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var M,H,z;Object.entries(i.blocks).forEach(([q,rt])=>{q!=="root"&&n.doc.localInsertChildContainer(q,rt)});const d=i.blocks.root;if(Le(t)){n.deleteBlock(t);let q;d.reverse().forEach(rt=>{const ft=n.insertBlock(a,l,rt);q||(q=ft)}),q&&n.selection.selectBlock(q,ut(n,q));return}if(g(W6,tt(n,t),"not a text block"),he(n,t)){const q=a==="root"&&n.getBlockByIndex(a,0)===t,rt=bt(t);let ft;d.forEach((Bt,jt)=>{const Ut=n.insertBlock(a,rt+jt,Bt);jt===d.length-1&&(ft=Ut)}),ft&&n.selection.selectBlock(ft,ut(n,ft)),q&&n.deleteBlock(t);return}if(d.length===1){const q=d[0];if(ya(n,q.type)){n.insertTextToBlock(t,e,(M=q.text)!=null?M:[]);return}n.breakTextBlock(t,e),n.insertBlock(a,l+1,q);return}const h=e===ut(n,t),p=e===0,A=d[0],v=d[d.length-1];let B;!h&&!p?B=n.breakTextBlock(t,e,{forceInsertAfter:!0}):B=t;const D=p?l:l+1;h?(B=n.insertBlock(a,l+1,v),n.selection.selectBlock(B,ut(n,B))):(n.selection.selectBlock(B,0),ya(n,v.type)?n.insertTextToBlock(B,0,(H=v.text)!=null?H:[]):n.insertBlock(a,D,v));const T=n.selection.range;let _=D;ya(n,A.type)?p?(n.insertBlock(a,D,A),_+=1):n.insertTextToBlock(t,e,(z=A.text)!=null?z:[]):(n.insertBlock(a,D,A),_+=1),d.slice(1,d.length-1).reverse().forEach(q=>{n.insertBlock(a,_,q)}),n.selection.setRange(T)}),n.doc.endBatchUpdate()}function Hg(n,t,e,o,r){const i=$g(n,o,r),s=at(t),l=[];return n.undoManager.runInGroup(()=>{Object.entries(i.blocks).forEach(([d,h])=>{d!=="root"&&n.doc.localInsertChildContainer(d,h)}),i.blocks.root.reverse().forEach(d=>{const h=n.insertBlock(s,e,d);l.push(h)})}),l}function G6(n,t,e){const o=Eo(t);Hg(n,t,o,e);for(let r=0;r<o;r++){const i=Se(t);n.deleteBlock(i)}}const Fa=S("add-text-attribute");function hT(n,t,e,o){const{start:r,end:i}=e;g(Fa,r.blockId===i.blockId&&r.blockId===it(t),"invalid range"),g(Fa,o,"invalid attribute name");const s=n.getBlockText(t),l=ql(r.offset,i.offset-r.offset,s,o,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function Z6(n,t,e,o,r){const{start:i,end:s}=e;g(Fa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(Fa,o,"invalid attribute name");const l=n.getBlockText(t),a=Ia(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function Jl(n,t,e,o,r){const{start:i,end:s}=e;g(Fa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range");const l=n.getBlockText(t),a=e6(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function Q6(n,t,e,o){const r=Lo(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:s,start:l,end:a}=i;if(!tt(n,s))return;if(he(n,s)){o(n,it(s),t,e);return}const d=Ue(n,{anchor:l,focus:a});t==="color"||t==="backgroundColor"?Jl(n,s,d,t,e):(Jl(n,s,d,"color",null),Jl(n,s,d,"backgroundColor",null))})})}function Y6(n,t,e){const o=Lo(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{o.forEach(r=>{const{block:i,start:s,end:l}=r;if(!tt(n,i))return;if(he(n,i)){(t==="clearColor"||t==="clearAll")&&e(n,it(i),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,it(i),"backgroundColor",null);return}const a=Ue(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Jl(n,i,a,"color",null),(t==="clearBackground"||t==="clearAll")&&Jl(n,i,a,"backgroundColor",null)})})}function jg(n,t){const e=Lo(n,{simpleBlockOnly:!0}).filter(s=>tt(n,s.block));if(e.length===0)return[null,null];const o=s=>{if(ut(n,s.block)===0)return t(n,it(s.block));const l=s.start,a=s.end,d=n.getBlockText(s.block);return r6(l.offset,a.offset-l.offset,d)};let[r,i]=o(e[0]);return r===null&&i===null?[r,i]:(e.forEach(s=>{const[l,a]=o(s);l===null||r===null?r=null:r=l===r?r:null,a===null||i===null?i=null:i=a===i?i:null}),[r,i])}const Vn=S("adjust-selection-pos");function J6(n){const t=[];for(;n;){const e=nt(n);if(t.unshift(e),Xt(e))return t;const o=ot(e);g(Vn,o,"child container has not parent container"),n=o}g(Vn,!1,"should not come here: getParentContainers")}function K6(n,t){for(;t;){const e=nt(t);if(e===n)return t;const o=ot(e);g(Vn,o,"could not find parent block for a child container"),t=o}g(Vn,!1,"no parent block in specified container")}function fT(n,t){const e=J6(n),o=J6(t);g(Vn,e.length>0&&o.length>0,"block has not parent container"),g(Vn,e[0]===o[0],"root container does not equal");let r=e[0];for(let l=1;l<e.length||o.length;l++)if(e[l]!==o[l]){r=e[l-1];break}const i=K6(r,n),s=K6(r,t);return{parentContainer:r,newBlock1:i,newBlock2:s}}function X6(n,t){let e=ot(t);for(g(Vn,e,"element is not in a block");e;){const o=nt(e);g(Vn,Do(o),"not a child container");const r=ot(o);if(g(Vn,r,"child container has not parent block"),r===n)return o;e=r}g(Vn,!1,"failed to find parent container in complex block")}function xh(n,t,e){const o=n.getBlockById(t.blockId),r=n.getBlockById(e.blockId);if(o===r)return t instanceof je&&e instanceof je?{anchor:t,focus:e}:t instanceof So&&e instanceof So?nh(n,o,t,e):null;const i=nt(o),s=nt(r);if(i===s)return t instanceof So&&(t=st(o,0,"home")),e instanceof So&&(e=st(r,ut(n,r),"end")),g(Vn,t instanceof je,"not valid position type"),g(Vn,e instanceof je,"not valid position type"),{anchor:t,focus:e};if(o.contains(s))return null;if(r.contains(i)){if(t instanceof je&&e instanceof So){const B=n.getContainerById(e.childContainerId);if(B===i)return{anchor:e,focus:e};const D=ot(i);if(D&&D===ot(B)){const T=fe(D,at(i)),_=fe(D,at(B));return nh(n,D,T,_)}}return null}const l=Hd(o,r)>0,{newBlock1:a,newBlock2:d}=fT(o,r);if(a===d){const B=a,D=X6(B,o),T=X6(B,r);return t=fe(a,at(D)),e=fe(a,at(T)),Vn.debug(`select in complex block: ${D.id}, ${T.id}`),nh(n,B,t,e)}let h=l?ut(n,a):0;a===o&&t instanceof je&&(h=t.offset);let A=l?0:ut(n,d);return d===r&&e instanceof je&&(A=e.offset),t=st(a,h,l?"end":"home"),e=st(d,A,l?"home":"end"),{anchor:t,focus:e}}const mT=S("move-complex-block-position");function gT(n,t,e){const o=n.getBlockById(t.blockId);g(mT,Lt(n,o),"is not a complex block");const r=jn(n,o),i=n.getContainerById(t.childContainerId),s=r.getNextContainer(n,o,i,e,{noWrap:!0});return s?fe(o,at(s)):null}const Pa=S("move-simple-block-position");function tA(n,t){const e=En(n,t,{visibleOnly:!0});g(Pa,e.length>0,"complex block has not any child container");const o=e[0];return Se(o)}function eA(n,t){const e=En(n,t,{visibleOnly:!0});g(Pa,e.length>0,"complex block has not any child container");const o=e[e.length-1];return Ge(o)}function nA(n,t,e){const o=e?tA(n,t):eA(n,t);return Lt(n,o)?nA(n,o,e):o}function pT(n,t){const e=n.getBlockById(t.blockId);return Lt(n,e)&&t.offset===0?tA(n,e):Ss(e)}function CT(n,t){const e=n.getBlockById(t.blockId);return Lt(n,e)&&t.offset===1?eA(n,e):Ds(e)}function Ug(n){return n==="ArrowLeft"||n==="ArrowUp"}function zg(n,t,e){const o=nt(t);if(Xt(o))return null;const r=ot(o);g(Pa,r,"child container has not parent block"),g(Pa,Lt(n,r),"is not a complex block");const i=jn(n,r).getNextContainer(n,r,o,e);return i?Ug(e)?Ge(i):Se(i):zg(n,r,e)}function AT(n,t,e){const o=nt(t);if(Xt(o))return null;const r=ot(o);if(g(Pa,r,"child container has not parent block"),Ug(e)){const l=ce(r);if(l)return l}else{const l=Zt(r);if(l)return l}const i=zg(n,r,e);if(i)return i;let s=r;for(;!Xt(nt(s));)s=ot(nt(s));return Ug(e)?ce(s):Zt(s)}function bT(n,t,e){return!Lt(n,t)||jn(n,t).enableKeyboardSelect?t:nA(n,t,e==="ArrowDown"||e==="ArrowRight")}function vT(n,t,e){const o=n.getBlockById(t.blockId),i=Qt(n,o).moveCaret(n,o,t,e);if(i)return i;let s=e==="ArrowDown"||e==="ArrowRight"?pT(n,t):CT(n,t);if(s||(s=zg(n,o,e),s||(s=AT(n,o,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!Xt(nt(o)))return null;const l=n.insertTextBlock("",at(n.rootContainer),Eo(n.rootContainer));return st(l,0,"home")}return null}if(s=bT(n,s,e),tt(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return Gx(n,s,o,t,l);if(e==="ArrowUp")return qx(n,s,o,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?st(s,ut(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?st(s,0,"home"):null}function yT(n,t,e){if(t==="ArrowLeft")return e.start;const o=e.end,r=n.getBlockById(o.blockId);if(tt(n,r))return o;const i=Zt(r);if(i)return st(i,0,"home");if(!Xt(nt(r))||n.readonly)return o;const s=n.insertTextBlock("",at(n.rootContainer),Eo(n.rootContainer));return st(s,0,"home")}function kT(n,t,e){const o=n.selection.range;let r;if(o instanceof Ze)e==="move"&&!o.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?r=yT(n,t,o):r=vT(n,o.getFocusedPos(),t);else if(r=gT(n,o.focus,t),e==="move"){const i=r!=null?r:o.focus,s=n.getContainerById(i.childContainerId);if(t==="ArrowLeft"||t==="ArrowUp"){const l=Ge(s);r=st(l,0,"home")}else{const l=Se(s);r=st(l,ut(n,l),"end")}}return r?e==="move"?{anchor:r,focus:r}:xh(n,o.anchor,r):null}function Pi(n,t,e){const o=kT(n,t,e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),(t==="ArrowLeft"||t==="ArrowRight")&&n.selection.updateLastCaretRect(),!0}function oA(n){return Pi(n,"ArrowLeft","move"),!0}function rA(n){return Pi(n,"ArrowRight","move"),!0}function iA(n){return Pi(n,"ArrowUp","move"),!0}function sA(n){if(Pi(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=nt(t);if(Xt(e)||Ge(e)!==t)return!0;const o=n.rootContainer;return n.insertTextBlock("",at(o),Eo(o)),!0}function lA(n){return Pi(n,"ArrowDown","select"),!0}function cA(n){return Pi(n,"ArrowLeft","select"),!0}function aA(n){return Pi(n,"ArrowRight","select"),!0}function uA(n){return Pi(n,"ArrowUp","select"),!0}const dA=S("word-offset");function Vg(n,t){const e=n.selection.range.focus;g(dA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"home");if(e.offset===0||!tt(n,o)){const s=ce(o);if(!s)return null;const l=st(s,ut(n,s),"end");if(t==="select"&&tt(n,s)){const a=yg(n,s,l.offset);return st(s,a,"normal")}return l}const r=yg(n,o,e.offset);return st(o,r,"normal")}function Wg(n,t){const e=n.selection.range.focus;g(dA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"end");if(e.offset===ut(n,o)||!tt(n,o)){const s=Zt(o);if(!s)return null;const l=st(s,0,"home");if(t==="select"&&tt(n,s)){const a=kg(n,s,l.offset);return st(s,a,"end")}return l}const r=kg(n,o,e.offset);return st(o,r,"normal")}function hA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Vg(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function fA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Wg(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function mA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Vg(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function gA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Wg(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}S("find-block");function qg(n,t){if(!Lt(n,t))return t;const o=jn(n,t).getChildContainers(n,t)[0],i=ve(o)[0];return qg(n,i)}function Gg(n,t){if(!Lt(n,t))return t;const e=jn(n,t).getChildContainers(n,t),o=e[e.length-1],r=ve(o),i=r[r.length-1];return Gg(n,i)}function pA(n){const t=Gg(n,Ge(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(e),!0}function CA(n){const t=qg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(e),!0}function AA(n){const t=qg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function Zg(n){const t=Gg(n,Ge(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const bA=S("line-offset");function vA(n){const t=n.selection.range.focus;g(bA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!tt(n,e))return st(e,0,"home");let r=H4(e,t).start;const{next:i}=Xd(e,r);return i&&io(i)&&va(i)==="br"&&(r+=1),st(e,r,"home")}function yA(n){const t=n.selection.range.focus;g(bA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===ut(n,e)||!tt(n,e))return st(e,ut(n,e),"end");const o=H4(e,t);return st(e,o.end,"end")}function kA(n){if(!n.selection.range.focus.isSimple())return!1;const e=vA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function wA(n){if(!n.selection.range.focus.isSimple())return!1;const e=yA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function BA(n){if(!n.selection.range.focus.isSimple())return!1;const e=vA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function EA(n){if(!n.selection.range.focus.isSimple())return!1;const e=yA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const xA=S("find-block-position");function wT(n,t,e,o){g(xA,Lt(n,t),"is not a complex block");const r=jn(n,t).getChildContainers(n,t);g(xA,r.length>0,"complex block has not any child container");const i=To(n,e,o),s=i.left+i.width/2,l=i.top+i.height/2,a=D4(n,t,s,l);return Qg(n,a,e,o)}function Qg(n,t,e,o){if(Lt(n,t))return wT(n,t,e,o);const r=it(t);let i=Number.MAX_SAFE_INTEGER;const s=To(n,e,o),l=s.left+s.width/2,a=s.top+s.height/2;let d=st(r,0,"home");const h=ut(n,t);for(let p=0;p<=h;p++){const A=st(r,p,"normal"),v=To(n,t,A),B=er(v,l,a);B<i&&(i=B,d=A)}return d}const IA=S("page-offset");function BT(n,t){const e=x6(n)*.9,r=t.getBoundingClientRect().bottom-e;if(r<GI(n))return n.getFirstBlock();const i=ce(t);if(!i)return n.getFirstBlock();let s=i;for(;s;){if(s.getBoundingClientRect().y<r)return s;s=ce(s)}return n.getFirstBlock()}function ET(n,t){const e=x6(n)*.9,o=t.getBoundingClientRect(),r=ZI(n),i=o.top+e;if(i>r)return n.getLastBlock();const s=Zt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>i)return l;l=Zt(l)}return n.getLastBlock()}function TA(n){const t=n.selection.range.focus;g(IA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=BT(n,e);let r;return o===n.getFirstBlock()?r=st(o,0,"home"):r=Qg(n,o,e,t),r}function DA(n){const t=n.selection.range.focus;g(IA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=ET(n,e);let r;return o===n.getLastBlock()?r=st(o,ut(n,o),"end"):r=Qg(n,o,e,t),r}function SA(n){if(!n.selection.range.focus.isSimple())return!1;const e=TA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function LA(n){if(!n.selection.range.focus.isSimple())return!1;const e=DA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function MA(n){if(!n.selection.range.focus.isSimple())return!1;const e=TA(n);if(!e)return!1;const o=xh(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}function RA(n){if(!n.selection.range.focus.isSimple())return!1;const e=DA(n);if(!e)return!1;const o=xh(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}const Na=S("select-all");function OA(n,t){const e=Se(n),o=Ge(n);return t.start.offset===0&&t.start.blockId===it(e)&&t.end.offset===ut(t.getEditor(),o)&&t.end.blockId===it(o)}function xT(n,t){const e=t.getEditor(),o=jn(e,n).getChildContainers(e,n),r=o[0],i=o[o.length-1],s=it(n);return t.start.blockId===s&&t.start.childContainerId===at(r)&&t.end.blockId===s&&t.end.childContainerId===at(i)}function IT(n,t){g(Na,t,"no parent block"),g(Na,Lt(n,t),"not a complex block");const e=jn(n,t).getChildContainers(n,t),o=e[0],r=e[e.length-1];n.selection.setRange(Ue(n,{anchor:fe(t,at(o)),focus:fe(t,at(r))}))}function _A(n,t){const e=nt(t);Yg(n,e)}function FA(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&tt(n,t)){const r=e.start,i=e.end,s=ut(n,t);if(r.offset>0||i.offset<s)return n.selection.selectBlock(t,0,s),!1}return W(n.rootContainer,"select-all"),_A(n,Se(n.rootContainer)),!1}return g(Na,!e.isSimple(),"invalid range type"),xT(t,e)?(_A(n,t),!1):(g(Na,t,"no parent block"),g(Na,Lt(n,t),"not a complex block"),IT(n,t),!0)}function Yg(n,t){const e=ve(t),o=e[0],r=e[e.length-1],i=st(o,0,"home"),s=st(r,ut(n,r),"end");n.selection.setSelection(i,s,{noScroll:!0})}function PA(n){Zg(n),n.focus()}const Jg=S("selected-block-to-doc");function NA(n,t,e){!t.children||t.children.forEach(o=>{const r=n.getChildContainerData(o);r.forEach(i=>{NA(n,i,e)}),e.blocks[o]=mt.default(r)})}function Ih(n,t){const e=Qt(n,t.block);if(e.selectionToDoc)return e.selectionToDoc(n,t);const o=mt.default(_i(n,t.block));if(tt(n,t.block)){const i=t.start,s=t.end;if(g(Jg,o.text,"no block text"),i.offset===s.offset)return{blocks:{root:[{...o,text:[]}]},meta:{},comments:{}};const{middle:l}=ze(o.text,i.offset,s.offset-i.offset);return{blocks:{root:[{...o,text:l}]},meta:{},comments:{}}}if(Le(t.block))return{blocks:{root:[o]},meta:{},comments:{}};g(Jg,Lt(n,t.block),"not complex block"),g(Jg,o.children,"no children");const r={blocks:{root:[o]},meta:{},comments:{}};return NA(n,o,r),r}function Kg(n,t){const e=st(t,0,"normal"),o=st(t,ut(n,t),"end");return Ih(n,{block:t,start:e,end:o})}const TT=S("block-to-doc");function DT(n,t){g(TT,t.length>0,"invalid params, no blocks");const e=t.map(o=>Kg(n,o));return $s(e)}function Th(n){const e=n.selection.range.getSelectedBlocks().map(o=>Ih(n,o));return $s(e)}function $A(n,t){const e=n.getContainerById(t),i=ve(e).map(s=>({start:st(s,0,"home"),end:st(s,ut(n,s),"end"),block:s})).map(s=>Ih(n,s));return $s(i)}const Dh=S("editor-selection");class ST{constructor(t){m(this,"editor");m(this,"caret");m(this,"_range");m(this,"lastCaretRect");m(this,"handleBlockDelete",(t,e,o,r)=>{if(o||r.child)return;const i=this.range;if(D6(e,i)){Dh.debug("adjust selection because remote deleted current block");const s=S6(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),o=it(e);this.caret=new VI(t);const r=st(o,0,"normal");this._range=Ue(t,{anchor:r,focus:r}),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,o){const r=st(t,e,"normal");let i;o&&(i=st(t,o,"normal")),this.setSelection(r,i)}setSelection(t,e,o){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const r=Ue(this.editor,{anchor:t,focus:e});if(this.range.isEqual(r))return this.range;const i=this._range;return this._range=r,this.selectionChanged(),this.updateFocusedBlock(i),xt(this.editor.rootContainer,"select-all")&&(!r.isSimple()||!KI(this.editor,r))&&et(this.editor.rootContainer,"select-all"),o!=null&&o.noScroll||this.scrollIntoView(),this.range}setRange(t,e){return this.setSelection(t.anchor,t.focus,e)}updateSelection(){this.caret.update(),WI(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(!$r(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=To(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){JI(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=ut(this.editor,e)||g(Dh,!1,"invalid block position, out of range");else{const o=t.childContainerId;!!this.editor.getContainerById(o)||g(Dh,!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 o;(this.range.isCollapsed()||!this.range.isSimple()||this.range.start.blockId===this.range.end.blockId)&&(o=this.editor.getBlockById(this.range.start.blockId));let r=!1;e&&xt(e,"focused")&&(et(e,"focused"),r=!0),this.removeAllBlockFocusedClass(),o&&this.setBlockFocused(o)&&(r=!0),r&&this.editor.emit("focusBlockChanged",this.editor,o!=null?o:null,e!=null?e:null)}verify(){this.verifyPos(this._range.start),this.verifyPos(this._range.end)}to(t){const e=Th(this.editor);return t==="text"?La(this.editor,e):t==="markdown"?Ma(this.editor,e):M6(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{et(t,"focused"),et(t,"child-focused")})}setBlockFocused(t){if(xt(t,"focused"))return!1;W(t,"focused");let e=nt(t);for(;Do(e);){const o=ot(e);g(Dh,o,"parent block not found"),W(o,"child-focused"),e=nt(o)}return!0}}function LT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,ut(n,e))}function MT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!tt(n,e))return;let o=Vg(n,"select"),r=Wg(n,"select");if(!o||!r)return;const i=t.blockId;o.blockId!==i&&(o=st(e,0,"home")),r.blockId!==i&&(r=st(e,ut(n,e),"end")),n.selection.setSelection(o,r)}class RT{constructor(t){m(this,"editor");m(this,"startPos",null);m(this,"lastCaretRect");m(this,"mouseDownEvent",null);m(this,"autoScroll",null);m(this,"handleMouseDown",(t,e)=>{var r;this.mouseDownEvent=t;const o=M4(this.editor,t.x,t.y);if(o){if(o instanceof or)return;if(!this.autoScroll&&e.autoScroll){const s=o.getSelectedBlocks(),l=oo(s[0].block);this.autoScroll=new Gd({scrollElement:l,edge:{top:50,bottom:50}})}const i=this.editor.selection.range;if(t.shiftKey&&i.isSimple()){const s=i.anchor;this.editor.selection.setSelection(s,o.focus),this.startPos=o.start}else this.editor.selection.setSelection(o.anchor,o.focus),this.startPos=o.start;this.editor.selection.updateLastCaretRect(),e.autoScroll&&((r=this.autoScroll)==null||r.active())}});m(this,"handleMouseMove",t=>{if(!this.startPos||!this.mouseDownEvent||Math.abs(this.mouseDownEvent.x-t.x)<3&&Math.abs(this.mouseDownEvent.y-t.y)<3)return;const e=oh(this.editor,t.x,t.y);if(!e)return;const o=xh(this.editor,this.startPos,e.end);if(!o)return;const{anchor:r,focus:i}=o;this.editor.selection.setSelection(r,i)});m(this,"handleMouseUp",t=>{var e;(e=this.autoScroll)==null||e.inactive(),this.startPos=null});this.editor=t,this.startPos=null,this.lastCaretRect=new DOMRect}isSelecting(){return this.startPos!==null}stopSelection(){this.startPos=null}handleDblClick(t){MT(this.editor)}handleTripleClick(t){LT(this.editor)}}function OT(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function _T(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const HA=S("delete-text");function jA(n,t,e,o){const r=o!=null?o:n.selection.range.start;r instanceof je||g(HA,!1,`invalid insert pos type: ${typeof r}`);const{blockId:i}=r,s=n.getBlockById(i);g(HA,tt(n,s),"block is not a text kind block");let{offset:l}=r;if(t==="backward"){if(l-e<0)return 0;if(!sn(s,l-e)){const a=Ri(s,l);e=l-a}}else if(t==="forward"&&l+e>ut(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function UA(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const FT=S("handle-backspace");function Xg(n,t){if(!he(n,t))return;const e=nt(t);Eo(e)!==1&&n.deleteBlock(t)}function PT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===0){if(UA(n,o))return;const r=ce(o);if(r){if(!n.isBlockWritable(r))return;if(tt(n,r))n.mergeTextBlock(r,o,{focus:!0});else if(Lt(n,r)){Xg(n,o);const i=Vl(n,r);i?n.selection.selectBlock(i,ut(n,i)):n.selection.selectBlock(r,0,ut(n,r))}else Xg(n,o),g(FT,Le(r),"prev block is not embed block"),n.selection.selectBlock(r,1)}else{const i=nt(o);if(Do(i)){const s=x4(n,i);if(s){if(!n.isBlockWritable(s))return;Xg(n,o),n.selection.selectBlock(s,ut(n,s))}}}}else jA(n,"backward",1,null),n.selection.updateLastCaretRect();else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function NT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===ut(n,o)){const r=Zt(o);if(r){if(!n.isBlockWritable(r))return;tt(n,r)?n.mergeTextBlock(o,r,{focus:!0}):he(n,o)?n.deleteBlock(o,ye(n,r,0)):n.deleteBlock(r)}}else jA(n,"forward",1,null);else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function $T(n){const{range:t}=n.selection,{start:e,end:o}=t,r=n.getBlockById(e.blockId),i=n.getBlockById(o.blockId);if(r!==i||!Lt(n,r))return!1;if($r(e))return!0;const s=Os(n,r,e,o),l=En(n,r);return s.length===l.length}function HT(n,t){if($T(n)){const o=n.getFocusedBlock(),r=bt(o),i=at(nt(o));n.insertTextBlock("",i,r+1);return}n.selection.range.isCollapsed()||n.clearSelectedContents();const e=n.getFocusedBlock();if(tt(n,e)){if(he(n,e)&&UA(n,e))return;const o=n.selection.range.start,r=n.breakTextBlock(e,o.offset,{copyBlockAttributes:!0});o.offset!==0?n.selection.selectBlock(r,0):n.selection.scrollIntoView()}else{const o=n.insertTextBlock();n.selection.selectBlock(o,0)}}function jT(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:o}=e;if(!tt(n,o))return!1;const r=e.end;return n.insertBoxToBlock(o,r.offset,{type:"br",id:K(),box:!0,created:Date.now()}),!0}const UT=S("input-handler-actions");function zT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(HT(n),!0))}function VT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(NT(n),!0))}function WT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(PT(n),!0))}function qT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(jT(n),!0))}function GT(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t,{toPlainText:!0})}).catch(t=>{UT.error(t)}),!0)}const Sh={ArrowDown:sA,ArrowUp:iA,ArrowLeft:oA,ArrowRight:rA,"Shift+ArrowDown":lA,"Shift+ArrowUp":uA,"Shift+ArrowLeft":cA,"Shift+ArrowRight":aA,"CtrlOrCmd+ArrowLeft":hA,"CtrlOrCmd+ArrowRight":fA,"CtrlOrCmd+Shift+ArrowLeft":mA,"CtrlOrCmd+Shift+ArrowRight":gA,"CtrlOrCmd+ArrowUp":CA,"CtrlOrCmd+ArrowDown":pA,"CtrlOrCmd+Shift+ArrowUp":AA,"CtrlOrCmd+Shift+ArrowDown":Zg,"CtrlOrCmd+A":FA,Home:BA,End:EA,"Shift+Home":kA,"Shift+End":wA,PageUp:SA,PageDown:LA,"Shift+PageUp":MA,"Shift+PageDown":RA,"CtrlOrCmd+Z":OT,"CtrlOrCmd+Shift+Z":_T,Enter:zT,Delete:VT,Backspace:WT,"Shift+Enter":qT,"CtrlOrCmd+Shift+V":GT};function zA(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function VA(n,t,e){if(t.type==="embed"){const i=t.embedData,s=i.src;if(s&&typeof s=="string"){const l=e.get(s);l&&(i.src=l)}return}const o=t.text;o&&o.forEach(i=>{if(i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"){const s=e.get(i.attributes.src);s&&(i.attributes.src=s)}});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{VA(n,l,e)})})}function WA(n,t,e){if(e.size===0)return;t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.replaceResources?i.replaceResources(r,e):VA(t,r,e)})}async function ZT(n,t){const e=t.filter(i=>i.indexOf(":")===-1),o=await n.doc.addResources(e),r=new Map;if(e.length!==o.length)return r;for(let i=0;i<e.length;i++)r.set(e[i],o[i]);return r}function QT(n,t){var i,s;const o=t.meta.serverId;if(!o||typeof o!="string")return!1;const r=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i);return!(!r||r.serverId!==o)}async function YT(n,t){const o=t.meta.resources;if(!o||Object.keys(o).length===0)return;let r=new Map;if(QT(n,t)){const s=Array.from(Object.keys(o));r=await ZT(n,s),WA(n,t,r)}const i=new Map;Object.entries(o).forEach(([s,l])=>{r.get(s)===void 0&&s!==l&&i.set(s,l)}),i.size!==0&&WA(n,t,i)}async function JT(n,t,e){await YT(n,t),n.undoManager.runInGroup(()=>{const{start:o,end:r}=n.selection.range,i=n.getBlockById(o.blockId);if(o.blockId===r.blockId&&Le(i)){const s=nt(i),l=n.getBlockIndex(i),[a]=n.insertDocAt(s,l+1,t,e);a&&n.selection.selectBlock(a,ut(n,a))}else{n.clearSelectedContents();const{block:s,offset:l}=Gl(n);n.insertDoc(s,l,t,e)}})}const KT=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function XT(n){let t;for(const e of KT)if(t=n[e],t)break;return t||null}function qA(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 o=t.text;o&&o.forEach(i=>{i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"&&e.add(i.attributes.src)});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{qA(n,l,e)})})}function tD(n,t){const e=new Set;return t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.getResources?i.getResources(r).forEach(s=>{e.add(s)}):qA(t,r,e)}),Array.from(e)}function Lh(n,t){return`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${Bs(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function Mh(n,t){var i,s,l;const e=(l=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i))!=null?l:{},o=tD(n,t),r={};o.forEach(a=>{const d=n.doc.buildResourceUrl(a,{withToken:!0});r[a]=d}),t.meta={...e,resources:r}}function eD(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let o=Th(n);const r=e==null?void 0:e(n,t,o);if(r===!0)return;typeof r=="object"&&r!==null&&(o=r),Mh(n,o);const i=bh(n,o),s=Ma(n,o),l=Lh(i,o);t.clipboardData.setData("text/html",l),t.clipboardData.setData("text/plain",s),t.clipboardData.setData("text/x-ones-editor-doc",JSON.stringify(o))}async function Rh(n,t){const e=Kg(n,t);Mh(n,e);const o=bh(n,e),r=Ma(n,e),i=Lh(o,e);return Mm([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:new Blob([i],{type:"text/html"})}])}class nD{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"onPasteText",async(t,e)=>{const o=new DataTransfer;o.setData("text/plain",t);const r=await this.editor.dataConverter.fromData(this.editor,o,e);r&&this.pasteDocs(r,null)});this.editor=t}onInsertText(t,e){if(!tt(this.editor,this.editor.getFocusedBlock()))return;const{containerId:o,blockIndex:r,offset:i}=Gl(this.editor);this.handleBeforeInsertText(o,r,i,e)||(this.defaultInsertText(this.editor,o,r,i,e),this.handleAfterInsertText(o,r,i,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 o=this.handlers[e];o.handleChanged&&o.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleRemoteChanged&&o.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:o,offset:r}=Gl(this.editor);for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,o,r)}}onUpdateCompositionText(t,e,o){this.editor.updateCompositionText(e,o),this.editor.selection.caret.update();const{containerId:r,blockIndex:i,offset:s}=Gl(this.editor);for(let l=0;l<this.handlers.length;l++){const a=this.handlers[l];a.handleUpdateCompositionText&&a.handleUpdateCompositionText(this.editor,r,i,s,o)}this.editor.selection.updateLastCaretRect()}onCopy(t){eD(this.editor,t,(e,o,r)=>{for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,o,r);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}onCut(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeCut&&r.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const o=this.editor.selection.focusedBlock;Le(o)&&this.editor.deleteBlock(o)}else Fg(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;this.editor.dataConverter.fromData(this.editor,t.clipboardData).then(async o=>{o&&this.pasteDocs(o,t)})}onFocus(){W(this.editor.rootElement,"active")}onBlur(){et(this.editor.rootElement,"active")}addHandler(t){this.handlers.push(t)}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,o,r))return!0}return!1}handleAfterInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,o,r))return!0}return!1}handleBeforeKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,o,r,i){Lg(this.editor,i)}defaultHandleKeydown(t,e){return zA(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforePasteDoc&&await r.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map};await JT(this.editor,t,e);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterPasteDoc&&await r.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePaste&&await i.handleBeforePaste(this.editor,e,t))return}const o=XT(t);if(!!o){await this.pasteDoc(o);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPaste&&await i.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}}function oD(n,t,e){const o=Or(t,e);return o.remove(),o}S("copy-dom-attributes");const GA=["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 rD(n,t){for(let l=0;l<GA.length;l++){const a=GA[l];t[a]=n[a]}const e=n.attributes,o=t.attributes,r=[],i=[];for(let l=0;l<e.length;l++){const a=e[l],d=o.getNamedItem(a.name);d?d.value!==a.value&&(d.value=a.value,i.push(a)):r.push(a)}const s=[];for(let l=0;l<o.length;l++){const a=o[l];e.getNamedItem(a.name)||s.push(a)}r.forEach(l=>{t.setAttribute(l.name,l.value)}),i.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function ZA(n){const t=Array.from(n.childNodes).filter(e=>!jC(e));return t.forEach(e=>{e.remove()}),t}function QA(n,t,e){var d;const o=n.getContainerById(t),r=Or(o,e),i=Di(r),s=n.doc.getBlockData(t,e),l=Qt(n,r);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,r,s))n.editorBlockRenders.updateBlock(n,i,r,s);else{const h=n.editorBlocks.createBlock(i,o,s),p=ZA(h);ZA(r),p.forEach(v=>{r.appendChild(v)});const A=Jd(h);if(A){const v=Jd(r);v&&v.remove(),r.appendChild(A)}rD(h,r)}i4(n,r,s),n.blockHooks.forEach(h=>{var p;(p=h.update)==null||p.call(h,n,i,o,r,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const iD=S("transform-selection");function YA(n,t,e,o){const{range:r}=n.selection,{anchor:i,focus:s}=r;if(i.blockId!==t&&s.blockId!==t)return r;g(iD,i.isSimple()&&s.isSimple(),"invalid text pos type");let l=i;if(i.blockId===t){const d=ln.transformCursor(i.offset,e,o);l=st(t,d,"normal")}let a=s;if(s.blockId===t){const d=ln.transformCursor(s.offset,e,o);a=st(t,d,"normal")}return Ue(n,{anchor:l,focus:a})}const sD=S("handle-block-text-changed");function lD(n,t,e,o,r){const i=n.getContainerById(t),s=Or(i,e),l=n.doc.getBlockData(t,e);if(g(sD,l.text,"no block text"),XC(n,s).setBlockText(n,s,l.text),!r){const a=YA(n,l.id,o,r);n.selection.setRange(a,{noScroll:!0})}}function cD(n,t){const e=mt.default(n);return t.delete.forEach(r=>{delete e[r]}),{...e,...t.insert}}function JA(n,t,e,o){const r=Qt(n,t);r.handleDeleteBlock&&r.handleDeleteBlock(n,t,e,o),n.emit("blockDeleted",n,t,e,o)}function aD(n,t,e,o){const r=n.getBlockByIndex(t,e);r.querySelectorAll('[data-type="editor-block"]').forEach(i=>{JA(n,i,o,{child:!0})}),JA(n,r,o,{child:!1})}const Ro=S("editor-doc");class uD extends fa{constructor(e,o,r){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=o,this.externalDoc.registerCallback(this),this.registerLocalEvents(r)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var o,r;return(r=(o=this.externalDoc).getVersionHelper)==null?void 0:r.call(o)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}getBlockData(e,o){return this.externalDoc.getBlockData(e,o)}verifyBlockWritable(e,o){const r=this.editor.getBlockByIndex(e,o);g(Ro,this.editor.isBlockWritable(r),`block is not writable, ${e}, ${o}`)}localUpdateBlockText(e,o,r,i){g(Ro,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const s=this.getBlockData(e,o),l=s.text;g(Ro,l,`no text, ${e}, ${o}`);const a=YA(this.editor,s.id,r,!0),d=ln.apply(l,r);this.localEvents.forEach(p=>p.onBeforeUpdateBlockText(e,s.id,l,d,a.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,o,r);return this.editor.selection.setRange(a,i),h}localUpdateBlockData(e,o,r,i){g(Ro,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,o);if(!this.editor.isBlockWritable(s)){const h=Array.from(r.delete).filter(A=>A!=="comments"),p=Object.keys(r.insert).filter(A=>A!=="comments");(h.length>0||p.length>0)&&g(Ro,!1,`block is not writable, comment supported only, ${JSON.stringify(r)}}`)}const l=mt.default(this.getBlockData(e,o)),a=mt.default(cD(l,r));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,a,i));const d=this.externalDoc.localUpdateBlockData(e,o,r,i);return this.editor.selection.setRange(Si(this.editor,i)),d}localInsertBlock(e,o,r,i,s){g(Ro,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(a=>a.onBeforeInsertBlock(e,o,r,i));const l=this.externalDoc.localInsertBlock(e,o,r,i);return this.editor.selection.setRange(Si(this.editor,i),s),l}localDeleteBlock(e,o,r){g(Ro,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const i=mt.default(this.getBlockData(e,o));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,o,i,r));const s=this.externalDoc.localDeleteBlock(e,o,r);return this.editor.selection.setRange(Si(this.editor,r)),s}localDeleteChildContainers(e){return g(Ro,!this.editor.readonly,"editor is readonly"),e.forEach(o=>{const r=mt.default(this.getContainerBlocks(o));this.localEvents.forEach(i=>i.onBeforeDeleteChildContainer(o,r))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainer(e,o){return g(Ro,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(r=>r.onBeforeInsertChildContainer(e,mt.default(o))),this.externalDoc.localInsertChildContainer(e,o)}onRequestReload(e){Ro.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)});const o=!1;this.editor.emit("docChanged",this.editor,o)}onUpdateBlockText(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,o,r,i)}),lD(this.editor,e,o,r,i),this.editor.emit("docChanged",this.editor,i)}onUpdateBlockData(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,i)}),QA(this.editor,e,o),this.editor.emit("docChanged",this.editor,i)}onInsertBlock(e,o,r,i){this.callbacks.forEach(l=>{var a;return(a=l.onInsertBlock)==null?void 0:a.call(l,e,o,r,i)});const s=this.editor.getContainerById(e);KE(this.editor,s,o,r),this.editor.emit("docChanged",this.editor,i)}onDeleteBlock(e,o,r){aD(this.editor,e,o,r),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,r)});const i=this.editor.getContainerById(e);oD(this.editor,i,o),this.editor.emit("docChanged",this.editor,r)}onInsertChildContainer(e,o,r){this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,e,o,r)})}onDeleteChildContainer(e,o){this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){this.callbacks.forEach(o=>{var r;return(r=o.onCustomMessage)==null?void 0:r.call(o,e)})}onStatusChanged(e){this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)})}onError(e){this.callbacks.forEach(o=>{var r;return(r=o.onError)==null?void 0:r.call(o,e)})}uploadResource(e,o){return this.externalDoc.uploadResource(e,o)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,o){return this.externalDoc.buildResourceUrl(e,o)}request(e,o){return this.externalDoc.request(e,o)}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,o,r;return(r=(o=(e=this.externalDoc).getServerMeta)==null?void 0:o.call(e))!=null?r:{}}reset(e){Ro.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function KA(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 tp=S("undo-action");class Kl{constructor(t,e,o){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=o}undo(t){return!1}redo(t){return!1}combinable(t){return g(tp,t,"no other action"),!1}combine(t){g(tp,!1,"no other")}setAfterRange(t){this.afterRange&&tp.warn("after range has already set"),this.afterRange=t}}const dD=S("block-action");class XA extends Kl{constructor(e,o,r,i,s){super(e,o,s);m(this,"blockData");m(this,"blockIndex");this.blockData=mt.default(i),this.blockIndex=r}deleteBlock(e,o){if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockData.id);return i?(g(dD,this.blockIndex===bt(i),"invalid block index"),kh(e,i,Si(e,o)),!0):!1}insertBlock(e,o){return Ql(e,this.containerId,this.blockIndex,mt.default(this.blockData),o),!0}}class hD extends XA{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class fD extends XA{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class mD extends Kl{constructor(e){super(e,at(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){KA(this.actions,e),this.afterRange=e.afterRange}undo(e){let o=!1;return this.actions.concat().reverse().forEach(r=>{r.undo(e)&&(o=!0)}),o}redo(e){let o=!1;return this.actions.forEach(r=>{r.redo(e)&&(o=!0)}),o}setAfterRange(e){this.afterRange=e;const o=this.actions[this.actions.length-1];!o||o instanceof Kl&&(o.afterRange||o.setAfterRange(e))}}const Hs=S("update-block-data-action");class Oh extends Kl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=r,g(Hs,this.blockId===i.id,"invalid block id"),g(Hs,this.blockId===s.id,"invalid block id"),this.beforeBlockData=mt.default(i),this.afterBlockData=mt.default(s),g(Hs,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Eh(e,o,Oh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Eh(e,o,Oh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const o=mt.default(e);return delete o.id,delete o.type,o}}const ep=S("update-block-text-action");class $a extends Kl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=r,this.beforeRichTextData=mt.default(i),this.afterRichTextData=mt.default(s),this.type=$a.calType(i,s)}static calType(e,o){g(ep,e,"no old data"),g(ep,o,"no new data");const i=ln.diff(e,o),s=new Set;let l=!1;const a=h=>pC(h)?`cjk_${h}`:mC(h)?"number":jd(h)?"space":gC(h)?"letter":"unknown";let d=!1;return i.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_${a(h.insert.substr(1))}`)):s.add(`insert_${a(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(Bh(e,r,this.beforeRichTextData),!0):!1}redo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(Bh(e,r,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof $a)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const o=e.beforeRange,r=o.anchor;if(!r.isSimple())return!1;const i=this.afterRange;if(!i)return!1;const s=i.anchor;return!(!s.isSimple()||s.blockId!==o.anchor.blockId||s.offset!==r.offset)}combine(e){g(ep,e instanceof $a,"invalid action type");const o=e;this.afterRichTextData=o.afterRichTextData,this.afterRange=e.afterRange}}class tb extends Kl{constructor(t,e,o){super(t,e,t.selection.range.toDocRange()),this.blocks=o}deleteChildContainer(t){return t.doc.localDeleteChildContainers([this.containerId]),!0}insertChildContainer(t){return t.doc.localInsertChildContainer(this.containerId,mt.default(this.blocks)),!0}}class gD extends tb{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class pD extends tb{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Oo=S("undo");class CD{constructor(t){m(this,"editor");m(this,"actions",[]);m(this,"undoCursor");m(this,"currentGroup",null);m(this,"groupCounter",0);m(this,"undoRedoing",!1);m(this,"handleSelectionChange",t=>{if(this.currentGroup){this.currentGroup.setAfterRange(t.selection.range.toDocRange());return}const e=this.actions[this.actions.length-1];!e||e.afterRange||e.setAfterRange(t.selection.range.toDocRange())});this.editor=t,this.undoCursor=-1,this.editor.addListener("selectionChanged",this.handleSelectionChange)}reset(){this.actions=[],this.undoCursor=-1}prepareSaveUndoState(){this.undoCursor!==-1&&(this.actions.splice(this.undoCursor),this.undoCursor=-1)}addAction(t){this.currentGroup?this.currentGroup.addAction(t):(KA(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(g(Oo,!this.currentGroup,"current group already exists"),this.currentGroup=new mD(this.editor),this.groupCounter=1):(g(Oo,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){g(Oo,this.currentGroup,"current group not exists"),g(Oo,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Oo.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 Oo.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(Si(this.editor,t.beforeRange))}catch(e){Oo.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(Si(this.editor,e)):Oo.warn("no after range")}catch(e){Oo.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,o,r,i){this.undoRedoing||(this.prepareSaveUndoState(),ln.diff(o,r).length!==0&&this.addAction(new $a(this.editor,t,e,o,r,i)))}onBeforeUpdateBlockData(t,e,o,r,i){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new Oh(this.editor,t,e,o,r,i);this.addAction(s)}onBeforeInsertBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),g(Oo,e>=0,"invalid block index"),g(Oo,o,"no block data"),this.addAction(new hD(this.editor,t,e,o,r)))}onBeforeDeleteBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new fD(this.editor,t,e,o,r)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new gD(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new pD(this.editor,t,e)))}}class AD{async fromData(t,e){const o=e.getData("text/x-ones-editor-doc");if(o)return{"text/x-ones-editor-doc":JSON.parse(o)}}}class bD{constructor(){m(this,"converters",[]);this.addConverter(new AD)}async fromData(t,e,o){let r={};for(const i of this.converters){const s=await i.fromData(t,e,o);s&&(r={...r,...s})}return r}addConverter(t){this.converters.push(t)}}class vD{constructor(t){m(this,"renders",[]);this.editor=t}registerRender(t){this.renders.push(t)}renderText(t,e){const o={classes:[],attributes:{},styles:{}};return this.renders.forEach(r=>{if(r.renderText){const i=r.renderText(this.editor,t,e);i.classes&&o.classes.push(...i.classes),i.attributes&&(o.attributes={...o.attributes,...i.attributes}),i.styles&&(o.styles={...o.styles,...i.styles})}}),o}renderBlock(t,e,o){const r={classes:[],attributes:{},styles:{}};return this.renders.forEach(i=>{if(i.renderBlock){const s=i.renderBlock(this.editor,e,o);s.classes&&r.classes.push(...s.classes),s.attributes&&(r.attributes={...r.attributes,...s.attributes}),s.styles&&(r.styles={...r.styles,...s.styles})}}),r}updateBlock(t,e,o,r){this.renders.forEach(i=>{var s;(s=i.updateBlock)==null||s.call(i,t,e,o,r)})}}class pe extends be.TypedEmitter{constructor(e){super();m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"filters",[]);m(this,"finders",[]);m(this,"handleDocumentMouseMove",e=>{if(this.hoveringBlock){for(const s of this.filters)if(s.isInBlock(this.hoveringBlock,e))return}const o=document.elementFromPoint(e.x,e.y);if(!o){this.setHoveringBlock(null,e,null);return}let r=ot(o);if((!r||!Kt(this.editor.rootContainer,r))&&(r=this.findBlockByFinders(e),!r)){this.setHoveringBlock(null,e,null);return}const i=this.getParentTextContentChild(r,o);this.setHoveringBlock(r,e,i)});this.editor=e,document.addEventListener("mousemove",this.handleDocumentMouseMove)}destroy(){document.removeEventListener("mousemove",this.handleDocumentMouseMove),this.filters.forEach(e=>e.destroy()),this.filters=[],this.finders.forEach(e=>e.destroy()),this.finders=[]}addFilter(e){this.filters.push(e)}addFinder(e){this.finders.push(e)}hoveringBlockId(){return this.hoveringBlock?it(this.hoveringBlock):""}findBlockByFinders(e){for(let o=0;o<this.finders.length;o++){const i=this.finders[o].findTargetBlock(this.editor,e);if(i)return i}return null}setHoveringBlock(e,o,r){if(this.hoveringBlock===e&&this.hoveringTextChild===r)return;if(this.hoveringBlock!==e){const s=this.hoveringBlock&&Kt(this.editor.rootContainer,this.hoveringBlock)?this.hoveringBlock:null;s&&et(s,"hover"),e&&W(e,"hover"),this.hoveringBlock=e,this.emit("change",this.hoveringBlock,s,o)}const i=this.hoveringTextChild;this.hoveringTextChild=r,this.emit("childChange",this.hoveringBlock,r,i,o)}static get(e){return e.addCustom("standard-hovering-block",()=>new pe(e))}getParentTextContentChild(e,o){if(!tt(this.editor,e))return null;const r=Rt(e);return o.parentElement===r?o:$m(o)}}const eb="style-color-",nb="style-bg-color-";class yD{renderText(t,e,o){const r=[],i={},s={};return Object.entries(o).forEach(([l,a])=>{a===!0?l.startsWith(eb)?i["data-style-color"]=l.substring(eb.length):l.startsWith(nb)?i["data-style-bg-color"]=l.substring(nb.length):l.startsWith("style")&&r.push(l):typeof a=="string"&&(l==="link"&&(r.push("link"),i.link=a),l==="inline-style-color"&&(s.color=a))}),{classes:r,attributes:i,styles:s}}renderBlock(t,e,o){var l,a;const r={};Object.entries(o).filter(d=>d[0].startsWith("style-")).forEach(([d,h])=>{r[`data-${d}`]=`${h}`});const s=[];return((a=(l=t.selection)==null?void 0:l.range)==null?void 0:a.start.blockId)===o.id&&s.push("focused"),typeof o.align=="string"&&o.align&&(r["data-style-align"]=o.align),o.heading&&(r["data-style-heading"]=String(o.heading)),o.quoted&&(r["data-style-quoted"]="true"),pe.get(t).hoveringBlockId()===o.id&&s.push("hover"),{attributes:r,classes:s}}updateBlock(t,e,o,r){var s,l;Array.from(o.attributes).forEach(a=>{a.name.startsWith("data-style-")&&o.removeAttribute(a.name)}),Object.entries(r).filter(a=>a[0].startsWith("style-")||a[0]==="align").forEach(([a,d])=>{a==="align"&&o.setAttribute(a.startsWith("style-")?`data-${a}`:`data-style-${a}`,`${d}`)}),((l=(s=t.selection)==null?void 0:s.range)==null?void 0:l.start.blockId)===r.id&&W(o,"focused"),pe.get(t).hoveringBlockId()===r.id&&W(o,"hover")}}function kD(n){n.editorBlocks.registerBlockClass(In),n.editorBlocks.registerBlockClass(E4),n.editorBoxes.registerBoxClass(g6),n.editorBoxes.registerBoxClass(p6),n.editorBoxes.registerBoxClass(b6),n.editorBoxes.registerBoxClass(v6),n.editorInsertions.registerInsertionClass(y6),n.editorBlockRenders.registerRender(new yD)}function wD(n,t){kD(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 ob=S("range-commands");function rb(n,t){n.forEach(e=>{e.source=t,e.children&&rb(e.children,t)})}function ib(n,t,e){const o=it(t);g(ob,o===e.start.blockId,"invalid start range"),g(ob,o===e.end.blockId,"invalid end range");const r=n.editorCommandProviders.getCommandProviders();let i=[];return r.forEach(s=>{const l=s.getAvailableCommands(n,t,e);rb(l,s.id),i.push(...l)}),r.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,i);l&&(i=l)}}),Lt(n,t)&&Os(n,t,e.start,e.end).forEach(l=>{ve(l).forEach(d=>{const h=ut(n,d),p=Ue(n,{anchor:st(d,0,"home"),focus:st(d,h,"end")}),A=ib(n,d,p);i.push(...A)})}),i}function sb(n){const t=n.getEditor(),e=n.getSelectedBlocks(),o=[];return e.forEach(r=>{const i=Ue(t,{anchor:r.start,focus:r.end});ib(t,r.block,i).forEach(l=>{o.push(l)})}),o}function lb(n,t,e,o,r,i){var h;const s=n.editorCommandProviders.getCommandProviders();for(let p=0;p<s.length;p++){const A=s[p];if(A.beforeExecuteCommand&&A.beforeExecuteCommand(n,t,e,o,r))return!1}const l=n.editorCommandProviders.getCommandProvider(o.source),a={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,o,r,{}))return i[it(t)]=a,!0;let d=!1;return Lt(n,t)&&Os(n,t,e.start,e.end).forEach(A=>{ve(A).forEach(B=>{const D=ut(n,B),T=Ue(n,{anchor:st(B,0,"home"),focus:st(B,D,"end")});lb(n,B,T,o,r,i)&&(d=!0)})}),s.forEach(p=>{p.afterExecuteCommand&&p.afterExecuteCommand(n,t,e,o,r,i)}),d}function cb(n,t,e){const o=n.getEditor(),r={},i=o.editorCommandProviders.getCommandProvider(t.source);return i.executeRangeCommand&&i.executeRangeCommand(o,n,t,e,r)||n.getSelectedBlocks().forEach(l=>{const a=Ue(o,{anchor:l.start,focus:l.end});lb(o,l.block,a,t,e,r)}),r}const BD=S("command-providers");class ab{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(o=>o.id===t);return g(BD,e,`no command provider, id=${t}`),e}getCommands(t){return sb(t)}executeCommand(t,e,o){return this.editor.undoManager.runInGroup(()=>cb(t,e,o))}getEmptyBlockTextAttributes(t,e){let o={};if(this.providers.forEach(r=>{var s;const i=(s=r.getEmptyBlockTextAttributes)==null?void 0:s.call(r,t,e);i&&(o={...o,...i})}),Object.keys(o).length!==0)return o}}function ED(n,t){const e=nt(t),o=at(e),r=bt(t);QA(n,o,r)}const xD=S("table-scroll");class ub{constructor(t,e,o,r,i){m(this,"handleEvent",t=>{this.handler(this.editor,t,this.data)});this.editor=t,this.dom=e,this.name=o,this.handler=r,this.data=i,e.addEventListener(o,this.handleEvent)}destroy(){this.dom.removeEventListener(this.name,this.handleEvent)}}class ID{constructor(t){m(this,"handlers",new Map);this.editor=t}destroy(){Array.from(this.handlers.entries()).forEach(([t,e])=>{e.forEach(o=>o.destroy()),this.handlers.delete(t)})}addEventListener(t,e,o,r){const i=this.handlers.get(t);if(i){if(i.find(s=>s.handler===o&&s.name===e)){xD.warn(`event has already registered: ${e}`);return}i.push(new ub(this.editor,t,e,o,r))}else{const s=new ub(this.editor,t,e,o,r);this.handlers.set(t,[s])}}removeEventListener(t,e,o){if(!t){for(const[i,s]of Array.from(this.handlers.entries()))for(let l=s.length-1;l>=0;l--){const a=s[l];if(e)e===a.name&&o===a.handler&&s.splice(l,1);else if(o===a.handler){s.splice(l,1),a.destroy(),s.length===0&&this.handlers.delete(i);continue}}return}const r=this.handlers.get(t);if(r){const i=r.findIndex(s=>s.handler===o&&s.name===e);if(i!==-1){const s=r[i];r.splice(i,1),s.destroy(),r.length===0&&this.handlers.delete(t)}}}removeAllListeners(t,e){const o=this.handlers.get(t);if(o)if(e)for(let r=0;r<o.length;r++){const i=o[r];i.name===e&&(o.splice(r,1),i.destroy())}else o.forEach(r=>{r.destroy()}),this.handlers.delete(t)}}const db=S("update-block-text");function TD(n,t){const e=n.getBoxById(t.id),o=ot(e);g(db,o,"no parent block"),g(db,tt(n,o),"not a text block");const r=n.getBlockText(o),i=s6(r,"id",t.id,t);z6(n,o,i)}function DD(n,t){for(const e of n.blockHooks)if(e.writable){const o=e.writable(n,t);if(typeof o=="boolean")return o}return!0}function SD(n){return n.readonly?!1:!Lo(n).find(o=>!n.isBlockWritable(o.block))}class LD{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 MD{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const o=this.shortcuts;for(const r of o){const i=Object.entries(r);for(const[s,l]of i)if(Rr(e,s)){const a=l(t,e);if(a!==void 0)return a}}}}const zr=S("editor");class RD extends be.TypedEmitter{constructor(e,o,r){var i,s,l,a,d,h,p;super();m(this,"parent");m(this,"rootElement");m(this,"contentElement");m(this,"rootContainerObject");m(this,"rootContainer");m(this,"input");m(this,"selection");m(this,"selectionHandler");m(this,"doc");m(this,"id");m(this,"clientId");m(this,"compositingText","");m(this,"undoManager");m(this,"shortcuts",new MD);m(this,"dataConverter",new bD);m(this,"editorBlocks",new y4(this));m(this,"editorBoxes",new A6(this));m(this,"editorInsertions",new w6(this));m(this,"editorEmbeds",new w4(this));m(this,"editorDecorators",new B6(this));m(this,"editorCommandProviders",new ab(this));m(this,"editorBlockRenders",new vD(this));m(this,"blockHooks",[]);m(this,"domEvents",new ID(this));m(this,"customs",new Map);m(this,"options");m(this,"inputHandlers",new nD(this));m(this,"settingsProvider");m(this,"_readonly",!1);zr.debug("create editor"),this.setMaxListeners(100),this.options={colors:(i=r==null?void 0:r.colors)!=null?i:["#9923E9","#4587C2","#8BDB7A","#FB28D3","#CBC619","#10FEEB","#812A1A","#8A3F25","#22D742","#A53E74","#555C87","#57E0AA"],componentsOptions:(l=(s=r==null?void 0:r.components)==null?void 0:s.options)!=null?l:{},scrollContainer:r==null?void 0:r.scrollContainer},this.settingsProvider=(a=r==null?void 0:r.settingsProvider)!=null?a:new LD(this),wD(this,r==null?void 0:r.components),this.blockHooks.push(...(h=(d=r==null?void 0:r.components)==null?void 0:d.blockHooks)!=null?h:[]),this.id=(p=r==null?void 0:r.id)!=null?p:K(),this.clientId=K(),this.undoManager=new CD(this),this.doc=new uD(this,o,this.undoManager),this.parent=e,this.rootElement=w("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=w("div",["editor-content"],this.rootElement),this.rootContainerObject=A4(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new zI(this,this.inputHandlers),this.selection=new ST(this),this.selectionHandler=new RT(this),r!=null&&r.shortcuts&&this.shortcuts.shortcuts.push(...r.shortcuts),Ke.isMobile&&W(this.rootElement,"mobile"),Ke.isSafari&&W(this.rootElement,"safari"),this._readonly&&W(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?W(this.rootElement,"readonly"):et(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:oo(this.rootContainer)}addCustom(e,o){const r=this.customs.get(e);if(r)return r;const i=o(this);return this.customs.set(e,i),i}getCustom(e){const o=this.customs.get(e);return g(zr,o,`${e} does not exists`),o}replaceCustom(e,o){const r=this.customs.get(e);return r&&r.destroy(),this.customs.set(e,o),o}findCustom(e){return this.customs.get(e)}findCustomByType(e){const o=this.customs.values();for(const r of o)if(r instanceof e)return r;return null}destroyCustom(e){const o=this.customs.get(e);o&&(this.customs.delete(e),o.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,o,r){return this.editorBlocks.createBlock(e,o,r)}createBox(e,o){return this.editorBoxes.createBox(e,o)}createInsertion(e,o){return this.editorInsertions.createInsertion(e,o)}destroy(){zr.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,o){Pg(this,e,o)}isWritable(){return SD(this)}isBlockWritable(e){return DD(this,e)}getChildContainerData(e){const o=this.doc.getContainerBlocks(e);return g(zr,o,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),g(zr,Array.isArray(o),`container data is not an array: ${JSON.stringify(o)}`),o}createChildContainer(e,o,r){return b4(this,e,o,r)}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 o=this.rootContainer.querySelector(`#${e}`);return o&&g(zr,xs(o),"not an valid block element"),o!=null?o:null}findBoxById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&g(zr,Nm(o),"not an valid box element"),o!=null?o:null}getBlockById(e){const o=this.findBlockById(e);return g(zr,o,`no block, id=${e}`),o}getBoxById(e){const o=this.findBoxById(e);return g(zr,o,`no box, id=${e}`),o}getBlockByIndex(e,o){const r=this.getContainerById(e);return Or(r,o)}getBlockIndex(e){if(typeof e=="string"){const o=this.getBlockById(e);return bt(o)}return bt(e)}getContainerById(e){return Nr(this,e)}getParentContainer(e){return nt(e)}reloadBlock(e){ED(this,e)}contains(e){const o=e instanceof Element?e:e.parentElement;return o?o.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,o,r,i,s){const l={blockId:r.id,offset:0},a={anchor:l,focus:l};return Ql(this,e,o,r,i!=null?i:a,s)}insertEmbed(e,o,r,i,s){const l={id:K(),type:"embed",embedType:r,embedData:i};return this.insertBlock(e,o,l,s)}deleteBlock(e,o){Og(this,e,o)}mergeTextBlock(e,o){return H6(this,e,o)}breakTextBlock(e,o,r){return Yl(this,e,o,r).newBlock}getTextPosition(){return Gl(this)}getBlockString(e,o){const r=this.getBlockText(e);return re(r,o)}getBlockData(e){return _i(this,e)}getBoxData(e){return f6(this,e)}getBlockText(e){return mn(this,e)}setBlockText(e,o){z6(this,e,o)}deleteTextFromBlock(e,o,r,i){return Mg(this,e,o,r,i)}insertTextToBlock(e,o,r,i){return R6(this,e,o,r,i)}insertBoxToBlock(e,o,r){return O6(this,e,o,r)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,o,r,i){q6(this,e,o,r,i)}insertDocAt(e,o,r,i){return Hg(this,e,o,r,i)}deleteChildContainers(e){$6(this,e)}replaceBlockText(e,o){return Bh(this,e,o)}updateBlockData(e,o,r){const i={...this.getBlockData(e),...o},{id:s,type:l,...a}=i;return Eh(this,e,a,(r!=null?r:this.selection.range).toDocRange())}updateEmbedData(e,o,r){return V6(this,e,o,r)}updateBoxData(e){TD(this,e)}getSelectedText(){const e=Th(this);return La(this,e)}clearSelectedContents(){Fg(this)}insertTextBlock(e,o,r,i){const s=sr(e!=null?e:"");return N6(this,s,o,r,i==null?void 0:i.newRange,i==null?void 0:i.insertBlockOptions)}updateCompositionText(e,o){if(e&&!o&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!o){F6(this);return}o?(this.compositingText="",Em()||Lg(this,e)):(this.compositingText=e,_6(this))}getColor(e){const o=this.options.colors;return o.length===0?"#FF1A75":o[e%o.length]}}function Ha(n,t,e){return new RD(n,t,e)}function OD(n){const t=(o,r)=>{const i=o.findIndex(l=>l.id===r.id);if(i===-1){o.push(r);return}const s=o[i];if(s.value!==r.value){o.splice(i,1);return}if(!!s.states){if(!r.states){s.states=[];return}s.states=fm.default(s.states,r.states)}},e=[];return n.forEach(o=>{o.forEach(r=>{t(e,r)})}),e}const _D=["#FBBFBD","#FFDDB6","#FFF897","#C5F0C1","#CEDDFE","#DCC9FC","#E5E6E8","#F76964","#FFA53D","#FFE928","#63D156","#A0BBFE","#C4A5FB","#BBBFC3"];class _h extends be.TypedEmitter{constructor(e){super();m(this,"users",new Map);m(this,"cursors",new Map);m(this,"addingUser",!1);m(this,"colors");this.colors=e&&e.length>0?e:_D}setCursor(e){this.addUser(e.user);const o=this.cursors.get(e.user.userId);if(o&&ua.default(o,e))return;this.cursors.set(e.user.userId,e);const r=new Set([e.range.anchor.blockId,e.range.focus.blockId]),i=new Set(r);o&&new Set([o.range.anchor.blockId,o.range.focus.blockId]).forEach(l=>{r.has(l)||i.add(l)}),this.emit("remote-carets-change",[...i])}addUsers(e){this.addingUser=!0,e.forEach(o=>this.addUser(o)),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 o;return(o=this.users.get(e))!=null?o:null}removeUser(e){this.users.delete(e),this.cursors.delete(e),this.emit("change",Array.from(this.users.values()))}updateUsers(e){this.users.clear(),this.addingUser=!0;try{e.forEach(o=>{this.addUser(o)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const o=new Map;return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e&&fh(r.range)).forEach(r=>{const i=r.range.focus.offset;let s=o.get(i);s||(s=[],o.set(i,s)),s.push(r)}),o}getCursors(e){return Array.from(this.cursors.values()).filter(o=>o.range.anchor.blockId===e||o.range.focus.blockId===e)}onUpdateBlockText(e,o,r){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(fh(l.range)){const{anchor:a,focus:d}=l.range;a.blockId===e.id&&(a.offset=ln.transformCursor(a.offset,o,r)),d.blockId===e.id&&(d.offset=ln.transformCursor(d.offset,o,r))}})}getFixedUserColor(e,o){let r=0;Array.from(e).forEach(s=>{r+=s.charCodeAt(0)});const i=r%this.colors.length;return this.colors[i]}destroy(){this.removeAllListeners()}}const Xe=S("local-doc");class np extends fa{constructor(e,o){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[sr("")]}},this.serviceUrl=(o==null?void 0:o.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`);const i=r[o];return g(Xe,i,`no block data: ${o}`),i}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(Xe,i.text,"no text for data");const s=ln.apply(i.text,r);return i.text=s,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockText)==null?void 0:a.call(l,e,o,r,!0)}),s}localUpdateBlockData(e,o,r){const i=this.getBlockData(e,o);return r.delete.forEach(s=>delete i[s]),Object.entries(r.insert).forEach(([s,l])=>{i[s]=l}),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,!0)}),i}localInsertBlock(e,o,r){const i=this.getContainerBlocks(e);return g(Xe,i,`no container data: ${e}`),g(Xe,o>=0&&o<=i.length,`invalid block index: ${o}, ${i.length}`),i.splice(o,0,r),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,o,r,!0)}),r}localDeleteBlock(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`),g(Xe,o>=0&&o<=r.length,`invalid block index: ${o}, ${r.length}`);const i=r[o];return r.splice(o,1),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,!0)}),i}localInsertChildContainer(e,o){this.doc.blocks[e]=o,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,e,o,!0)})}localDeleteChildContainers(e){Xe.debug(`delete child containers: ${e}`),e.forEach(o=>{g(Xe,this.doc.blocks[o],`no child container: ${o}`),delete this.doc.blocks[o]}),e.forEach(o=>{g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,o,!0)})})}uploadResource(e,o){g(Xe,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,o){g(Xe,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new _h}setDoc(e){this.doc=mt.default(e),this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,"change doc")})}destroy(){this.clearCallbacks()}}class FD{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function op(n,t,e){n.addCustom(t,()=>{var i;const o=(i=e())!=null?i:void 0;return new FD(o)})}const hb=S("find-block");function fb(n,t){const e=Ds(t);if(!e){if(ro(t))return null;const o=Is(t);return g(hb,o,"no parent block"),fb(n,o)}return Lt(n,e)?Vl(n,e,{visibleOnly:!0}):e}function mb(n,t){const e=Ss(t);if(!e){if(ro(t))return null;const o=Is(t);return g(hb,o,"no parent block"),mb(n,o)}return Lt(n,e)?eg(n,e,{visibleOnly:!0}):e}const PD=S("remote-cursor");class ND{constructor(){m(this,"remoteUsers",new _h)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const o=e;this.handleUpdateUsers(o.users)}else e.type==="caret"?this.handleUpdateCaret(e):PD.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 $D(n){const{blocks:t,meta:e,comments:o,...r}=n;return{rootBlocks:t,meta:e,comments:o,childBlocks:r}}function HD(n){const{blocks:t,meta:e,comments:o}=n,{root:r,...i}=t;return{blocks:r,meta:e,comments:o,...i}}function ja(n){const{childBlocks:t,meta:e,comments:o,rootBlocks:r}=$D(mt.default(n));return{blocks:{root:r,...t},meta:e,comments:o}}function Ni(n){return n==="root"?"blocks":n}function Xl(n){return n==="blocks"?"root":n}const jD={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new on.default(n)},apply(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},compose(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},diff(n,t){const e=new on.default(n),o=new on.default(t);return e.diff(o).ops},transform(n,t,e){const o=new on.default(n);return new on.default(t).transform(o,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 o=new on.default(t),r=this.transformCursor(n.index,o,e),i=this.transformCursor(n.index+n.length,o,e);return{...n,index:r,length:i-r}}}};var cr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},$i={},rp=Z5.default.EventEmitter;$i.EventEmitter=rp,$i.mixin=UD;function UD(n){for(var t in rp.prototype)n.prototype[t]=rp.prototype[t]}var gb=["info","warn","error"];function pb(){var n={};gb.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var zD=pb;pb.prototype.setMethods=function(n){n=n||{};var t=this;gb.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var VD=zD,WD=new VD,Cb=WD;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 Fh=js,Ua={},Ab=qD;function qD(n,t,e,o){var r=function(s,l,a,d){t(a,s,l,"left"),t(d,l,s,"right")},i=n.transformX=function(s,l){e(s),e(l);for(var a=[],d=0;d<l.length;d++){for(var h=l[d],p=[],A=0;A<s.length;){var v=[];if(r(s[A],h,p,v),A++,v.length===1)h=v[0];else if(v.length===0){for(var B=A;B<s.length;B++)o(p,s[B]);h=null;break}else{for(var D=i(s.slice(A),v),T=0;T<D[0].length;T++)o(p,D[0][T]);for(var _=0;_<D[1].length;_++)o(a,D[1][_]);h=null;break}}h!=null&&o(a,h),s=p}return[s,a]};n.transform=function(s,l,a){if(!(a==="left"||a==="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],a):a==="left"?i(s,l)[0]:i(l,s)[1]}}var bb={exports:{}},Hi=bb.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||""}},ip=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},sp=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")},Ph=function(n){for(var t=0;t<n.length;t++)sp(n[t])};Hi.apply=function(n,t){var e;Ph(t);for(var o=0;o<t.length;o++){var r=t[o];if(r.i!=null)n=ip(n,r.p,r.i);else{if(e=n.slice(r.p,r.p+r.d.length),r.d!==e)throw new Error("Delete component '"+r.d+"' does not match deleted text '"+e+"'");n=n.slice(0,r.p)+n.slice(r.p+r.d.length)}}return n};var Vr=Hi._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:ip(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:ip(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};Hi.compose=function(n,t){Ph(n),Ph(t);for(var e=n.slice(),o=0;o<t.length;o++)Vr(e,t[o]);return e},Hi.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=0),Vr(t,o)}return t};var lp=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};Hi.transformCursor=function(n,t,e){for(var o=e==="right",r=0;r<t.length;r++)n=lp(n,t[r],o);return n};var GD=Hi._tc=function(n,t,e,o){if(sp(t),sp(e),t.i!=null)Vr(n,{i:t.i,p:lp(t.p,e,o==="right")});else if(e.i!=null){var r=t.d;t.p<e.p&&(Vr(n,{d:r.slice(0,e.p-t.p),p:t.p}),r=r.slice(e.p-t.p)),r!==""&&Vr(n,{d:r,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)Vr(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)Vr(n,t);else{var i={d:"",p:t.p};t.p<e.p&&(i.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(i.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),a=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(a!==d)throw new Error("Delete ops delete different text in the same region of the document");i.d!==""&&(i.p=lp(i.p,e),Vr(n,i))}return n},ZD=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};Hi.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=ZD(n[t]);return n},Ab(Hi,GD,Ph,Vr);var Nh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},QD=function(n){return!!n&&n.constructor===Object},_o=function(n){return JSON.parse(JSON.stringify(n))},It={name:"json0",uri:"http://sharejs.org/types/JSONv0"},Wr={};It.registerSubtype=function(n){Wr[n.name]=n},It.create=function(n){return n===void 0?null:_o(n)},It.invertComponent=function(n){var t={p:n.p};return n.t&&Wr[n.t]&&(t.t=n.t,t.o=Wr[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},It.invert=function(n){for(var t=n.slice().reverse(),e=[],o=0;o<t.length;o++)e.push(It.invertComponent(t[o]));return e},It.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!Nh(n[t].p))throw new Error("Missing path")},It.checkList=function(n){if(!Nh(n))throw new Error("Referenced element not a list")},It.checkObj=function(n){if(!QD(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function za(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 Va(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}It.apply=function(n,t){It.checkValidOp(t),t=_o(t);for(var e={data:n},o=0;o<t.length;o++){var r=t[o];(r.si!=null||r.sd!=null)&&za(r);for(var i=null,s=e,l="data",a=0;a<r.p.length;a++){var d=r.p[a];if(i=s,s=s[l],l=d,i==null)throw new Error("Path invalid")}if(r.t&&r.o!==void 0&&Wr[r.t])s[l]=Wr[r.t].apply(s[l],r.o);else if(r.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=r.na}else if(r.li!==void 0&&r.ld!==void 0)It.checkList(s),s[l]=r.li;else if(r.li!==void 0)It.checkList(s),s.splice(l,0,r.li);else if(r.ld!==void 0)It.checkList(s),s.splice(l,1);else if(r.lm!==void 0){if(It.checkList(s),r.lm!=l){var h=s[l];s.splice(l,1),s.splice(r.lm,0,h)}}else if(r.oi!==void 0)It.checkObj(s),s[l]=r.oi;else if(r.od!==void 0)It.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},It.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},It.incrementalApply=function(n,t,e){for(var o=0;o<t.length;o++){var r=[t[o]];n=It.apply(n,r),e(r,n)}return n};var YD=It.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o]&&(!e||o!==n.length-1))return!1;return!0};It.append=function(n,t){if(t=_o(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)&&(za(t),za(e)),YD(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&Wr[t.t]){if(e.o=Wr[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var o=t.p,r=0;r<e.o.length-1;r++)t.o=[e.o.pop()],t.p=o.slice(),Va(t),n.push(t);Va(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)&&(Va(t),Va(e)),n.push(t)},It.compose=function(n,t){It.checkValidOp(n),It.checkValidOp(t);for(var e=_o(n),o=0;o<t.length;o++)It.append(e,t[o]);return e},It.normalize=function(n){var t=[];n=Nh(n)?n:[n];for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=[]),It.append(t,o)}return t},It.commonLengthForOps=function(n,t){var e=n.p.length,o=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&o++,e===0)return-1;if(o===0)return null;e--,o--;for(var r=0;r<e;r++){var i=n.p[r];if(r>=o||i!==t.p[r])return null}return e},It.canOpAffectPath=function(n,t){return It.commonLengthForOps({p:t},n)!=null},It.transformComponent=function(n,t,e,o){t=_o(t);var r=It.commonLengthForOps(e,t),i=It.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,i!=null&&l>s&&t.p[i]==e.p[i]){if(t.ld!==void 0){var a=_o(e);a.p=a.p.slice(s),t.ld=It.apply(_o(t.ld),[a])}else if(t.od!==void 0){var a=_o(e);a.p=a.p.slice(s),t.od=It.apply(_o(t.od),[a])}}if(r!=null){var d=s==l,a=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(za(t),a=_o(e),za(a)),a.t&&Wr[a.t]){if(t.t&&t.t===a.t){var h=Wr[t.t].transform(t.o,a.o,o);if(t.si!=null||t.sd!=null)for(var p=t.p,A=0;A<h.length;A++)t.o=[h[A]],t.p=p.slice(),Va(t),It.append(n,t);else(!Nh(h)||h.length>0)&&(t.o=h,It.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[r]===t.p[r])if(d){if(t.ld!==void 0)if(t.li!==void 0&&o==="left")t.ld=_o(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[r]===e.p[r]?o==="right"&&t.p[r]++:e.p[r]<=t.p[r]&&t.p[r]++,t.lm!==void 0&&d&&e.p[r]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[r]===t.p[r])return n;var p=e.p[r],v=t.p[r],B=t.lm;(p<B||p===B&&v<B)&&t.lm--}if(e.p[r]<t.p[r])t.p[r]--;else if(e.p[r]===t.p[r]){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 v=t.p[r],B=t.lm,D=e.p[r],T=e.lm;if(D!==T)if(v===D)if(o==="left")t.p[r]=T,v===B&&(t.lm=T);else return n;else v>D&&t.p[r]--,v>T?t.p[r]++:v===T&&D>T&&(t.p[r]++,v===B&&t.lm++),(B>D||B===D&&B>v)&&t.lm--,B>T?t.lm++:B===T&&(T>D&&B>v||T<D&&B<v?o==="right"&&t.lm++:B>v?t.lm++:B===D&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var v=e.p[r],B=e.lm;p=t.p[r],p>v&&t.p[r]--,p>B&&t.p[r]++}else{var v=e.p[r],B=e.lm;p=t.p[r],p===v?t.p[r]=B:(p>v&&t.p[r]--,(p>B||p===B&&v>B)&&t.p[r]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[r]===e.p[r])if(t.oi!==void 0&&d){if(o==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[r]===e.p[r])if(o==="left")It.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[r]==e.p[r]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return It.append(n,t),n},Ab(It,It.transformComponent,It.checkValidOp,It.append);var JD=bb.exports;It.registerSubtype(JD);var KD=It,XD={type:KD};(function(n){n.defaultType=XD.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)})(Ua);var Fo={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var o 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],o=1;o<arguments.length;o++){var r=arguments[o];e=e[r]||(o===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],o=arguments[arguments.length-1],r=1;r<arguments.length-1;r++){var i=arguments[r];e=e[i]||(e[i]=r===arguments.length-2?o():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],o=[e],r=1;r<arguments.length-1;r++){var i=arguments[r];if(!e.hasOwnProperty(i))break;e=e[i],o.push(e)}for(var r=o.length-1;r>=0;r--){var s=o[r],i=arguments[r+1],l=s[i];(r===o.length-1||!n.hasKeys(l))&&delete s[i]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,o){var r=!1;return e.forEach(function(i){i&&(i(o),r=!0)}),r},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];setTimeout(function(){e.apply(null,o)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(Fo);var vb=Array.isArray,yb=Object.keys,tS=Object.prototype.hasOwnProperty,eS=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var o=vb(t),r=vb(e),i,s,l;if(o&&r){if(s=t.length,s!=e.length)return!1;for(i=s;i--!==0;)if(!n(t[i],e[i]))return!1;return!0}if(o!=r)return!1;var a=t instanceof Date,d=e instanceof Date;if(a!=d)return!1;if(a&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,p=e instanceof RegExp;if(h!=p)return!1;if(h&&p)return t.toString()==e.toString();var A=yb(t);if(s=A.length,s!==yb(e).length)return!1;for(i=s;i--!==0;)if(!tS.call(e,A[i]))return!1;for(i=s;i--!==0;)if(l=A[i],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},kb=$i,nS=Cb,Wn=Fh,$h=Ua,Po=Fo,oS=Po.clone,rS=eS,Tn=Wn.CODES,iS=Ft;function Ft(n,t,e){kb.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}kb.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=$h.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new Wn(Tn.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 Wn(Tn.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 Wn(Tn.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 o=n.type===void 0?$h.defaultType:n.type;this._setType(o),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;Po.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===Tn.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 o=this.inflightFetch.shift();if(o&&e.push(o),e.length&&(o=function(r){Po.callEach(e,r)}),n)return this._emitResponseError(n,o);this.ingestSnapshot(t,o),this._emitNothingPending()},Ft.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var o=this.pendingFetch;this.pendingFetch=[],e.callback&&o.push(e.callback);var r;if(o.length&&(r=function(i){Po.callEach(o,i)}),n)return this._emitResponseError(n,r);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,r):r&&r(),this._emitNothingPending(),this._flushSubscribe()},Ft.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Tn.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=Hh(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var o=0;o<this.pendingOps.length;o++){var e=Hh(this.pendingOps[o],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}}},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);sS(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,o=e&&e.wantSubscribe===n;if(o){e.callback=lS([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;Po.nextTick(function(){n._handleSubscribe()})}}};function sS(n,t,e){if(t){var o=n.pop();n.push(function(r){o&&o(r),e&&e(r)})}else n.push(e)}function lS(n){return n=n.filter(Po.truthy),n.length?function(t){Po.callEach(n,t)}:null}Ft.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function cS(n){delete n.op,delete n.create,delete n.del}function Hh(n,t){if(n.del)return cS(t);if(t.del)return new Wn(Tn.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new Wn(Tn.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new Wn(Tn.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 o=n.type.transform(n.op,t.op,"left"),r=n.type.transform(t.op,n.op,"right");n.op=o,t.op=r}}}Ft.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new Wn(Tn.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===$h.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,o=0;o<n.op.length;o++){var r=n.op[o],i={op:[r]};this.emit("before op",i.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=Hh(this.applyStack[s],i);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,i.op)),this.emit("op",i.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 a=this.data;this._setType(null),this.emit("del",a,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 Wn(Tn.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>=Po.MAX_SAFE_INTEGER)return this.emit("error",new Wn(Tn.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 o=new Wn(Tn.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(o):this.emit("error",o)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(i){return this._hardRollback(i)}var r=this;Po.nextTick(function(){r.flush()})},Ft.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var o=this._tryCompose(n);if(o){o.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 o=this.pendingOps.splice(e),e=0;e<o.length;e++){var t=o[e],r=this._tryCompose(t);r?r.callbacks=r.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&&!rS(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 o={op:n},r=t&&t.source;this._submit(o,r,e)},Ft.prototype.create=function(n,t,e,o){if(typeof t=="function"?(o=t,e=null,t=null):typeof e=="function"&&(o=e,e=null),t||(t=$h.defaultType.uri),this.type){var r=new Wn(Tn.ERR_DOC_ALREADY_CREATED,"Document already exists");return o?o(r):this.emit("error",r)}var i={create:{type:t,data:n}},s=e&&e.source;this._submit(i,s,o)},Ft.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new Wn(Tn.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var o={del:!0},r=n&&n.source;this._submit(o,r,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:oS(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 nS.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 o=Hh(this.pendingOps[e],t);if(o)return this._hardRollback(o)}try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}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 o=!!t.length,r=0;r<t.length;r++)o=Po.callEach(t[r].callbacks,n)&&o;if(n&&!o)return e.emit("error",n)})},Ft.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=Po.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var Us={};Us.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 wb=$i,Bb=Us.ACTIONS,aS=Fo,uS=Dn;function Dn(n,t,e,o,r,i,s){wb.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=o,this.query=r,this.results=null,i&&i.results&&(this.results=i.results,delete i.results),this.extra=void 0,this.options=i,this.callback=s,this.ready=!1,this.sent=!1}wb.mixin(Dn),Dn.prototype.hasPending=function(){return!this.ready},Dn.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 o=this.results[e];t.push([o.id,o.version])}n.r=t}this.connection.send(n),this.sent=!0}},Dn.prototype.destroy=function(n){this.connection.canSend&&this.action===Bb.querySubscribe&&this.connection.send({a:Bb.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&aS.nextTick(n)},Dn.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},Dn.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},Dn.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},Dn.prototype._handleResponse=function(n,t,e){var o=this.callback;if(this.callback=null,n)return this._finishResponse(n,o);if(!t)return this._finishResponse(null,o);var r=this,i=1,s=function(h){if(h)return r._finishResponse(h,o);--i||r._finishResponse(null,o)};if(Array.isArray(t))i+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){i++;var a=t[l],d=this.connection.get(a.c||this.collection,l);d.ingestSnapshot(a,s)}s()},Dn.prototype._ingestSnapshots=function(n,t){for(var e=[],o=0;o<n.length;o++){var r=n[o],i=this.connection.get(r.c||this.collection,r.d);i.ingestSnapshot(r,t),e.push(i)}return e},Dn.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)},Dn.prototype._handleError=function(n){this.emit("error",n)},Dn.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 o=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(o)),this.emit("insert",o,e.index);break;case"remove":var i=e.howMany||1,r=this.results.splice(e.index,i);this.emit("remove",r,e.index);break;case"move":var i=e.howMany||1,s=this.results.splice(e.from,i);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)},Dn.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var Eb=$i,dS=Us.ACTIONS,hS=Fo,xb=ar;function ar(n,t){if(Eb.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={}}Eb.mixin(ar),ar.prototype.submit=function(n,t){this.value=n,this.send(t)},ar.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},ar.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()})},ar.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},ar.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},ar.prototype._message=function(){return{a:dS.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},ar.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},ar.prototype._callbackOrEmit=function(n,t){if(t)return hS.nextTick(t,n);n&&this.emit("error",n)};var fS=Fo,Ib=cp;function cp(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}cp.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},cp.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&fS.nextTick(n)};var ap={exports:{}};(function(n,t){(function(e,o){o(t)})(cr,function(e){function o(k,I){I=I|0;for(var L=Math.max(k.length-I,0),F=Array(L),U=0;U<L;U++)F[U]=k[I+U];return F}var r=function(k){var I=o(arguments,1);return function(){var L=o(arguments);return k.apply(null,I.concat(L))}},i=function(k){return function(){var I=o(arguments),L=I.pop();k.call(this,I,L)}};function s(k){var I=typeof k;return k!=null&&(I=="object"||I=="function")}var l=typeof setImmediate=="function"&&setImmediate,a=typeof process=="object"&&typeof process.nextTick=="function";function d(k){setTimeout(k,0)}function h(k){return function(I){var L=o(arguments,1);k(function(){I.apply(null,L)})}}var p;l?p=setImmediate:a?p=process.nextTick:p=d;var A=h(p);function v(k){return i(function(I,L){var F;try{F=k.apply(this,I)}catch(U){return L(U)}s(F)&&typeof F.then=="function"?F.then(function(U){B(L,null,U)},function(U){B(L,U.message?U:new Error(U))}):L(null,F)})}function B(k,I,L){try{k(I,L)}catch(F){A(D,F)}}function D(k){throw k}var T=typeof Symbol=="function";function _(k){return T&&k[Symbol.toStringTag]==="AsyncFunction"}function M(k){return _(k)?v(k):k}function H(k){return function(I){var L=o(arguments,1),F=i(function(U,j){var Z=this;return k(I,function(J,lt){M(J).apply(Z,U.concat(lt))},j)});return L.length?F.apply(this,L):F}}var z=typeof cr=="object"&&cr&&cr.Object===Object&&cr,q=typeof self=="object"&&self&&self.Object===Object&&self,rt=z||q||Function("return this")(),ft=rt.Symbol,Bt=Object.prototype,jt=Bt.hasOwnProperty,Ut=Bt.toString,ee=ft?ft.toStringTag:void 0;function Ye(k){var I=jt.call(k,ee),L=k[ee];try{k[ee]=void 0;var F=!0}catch{}var U=Ut.call(k);return F&&(I?k[ee]=L:delete k[ee]),U}var Wo=Object.prototype,Ne=Wo.toString;function Ln(k){return Ne.call(k)}var vr="[object Null]",bn="[object Undefined]",an=ft?ft.toStringTag:void 0;function yr(k){return k==null?k===void 0?bn:vr:an&&an in Object(k)?Ye(k):Ln(k)}var ei="[object AsyncFunction]",mo="[object Function]",t3="[object GeneratorFunction]",e3="[object Proxy]";function n3(k){if(!s(k))return!1;var I=yr(k);return I==mo||I==t3||I==ei||I==e3}var ns=9007199254740991;function ol(k){return typeof k=="number"&&k>-1&&k%1==0&&k<=ns}function rl(k){return k!=null&&ol(k.length)&&!n3(k)}var ni={};function Nt(){}function kr(k){return function(){if(k!==null){var I=k;k=null,I.apply(this,arguments)}}}var os=typeof Symbol=="function"&&Symbol.iterator,Pc=function(k){return os&&k[os]&&k[os]()};function s1(k,I){for(var L=-1,F=Array(k);++L<k;)F[L]=I(L);return F}function un(k){return k!=null&&typeof k=="object"}var il="[object Arguments]";function l1(k){return un(k)&&yr(k)==il}var go=Object.prototype,c1=go.hasOwnProperty,o3=go.propertyIsEnumerable,sl=l1(function(){return arguments}())?l1:function(k){return un(k)&&c1.call(k,"callee")&&!o3.call(k,"callee")},Ce=Array.isArray;function ll(){return!1}var cl=typeof e=="object"&&e&&!e.nodeType&&e,a1=cl&&!0&&n&&!n.nodeType&&n,al=a1&&a1.exports===cl,u1=al?rt.Buffer:void 0,ul=u1?u1.isBuffer:void 0,rs=ul||ll,Hu=9007199254740991,ju=/^(?:0|[1-9]\d*)$/;function Uu(k,I){var L=typeof k;return I=I==null?Hu:I,!!I&&(L=="number"||L!="symbol"&&ju.test(k))&&k>-1&&k%1==0&&k<I}var zu="[object Arguments]",Vu="[object Array]",Wu="[object Boolean]",qu="[object Date]",Gu="[object Error]",Zu="[object Function]",r3="[object Map]",i3="[object Number]",s3="[object Object]",d1="[object RegExp]",h1="[object Set]",l3="[object String]",c3="[object WeakMap]",a3="[object ArrayBuffer]",u3="[object DataView]",f1="[object Float32Array]",d3="[object Float64Array]",h3="[object Int8Array]",f3="[object Int16Array]",Qu="[object Int32Array]",m3="[object Uint8Array]",Yu="[object Uint8ClampedArray]",g3="[object Uint16Array]",p3="[object Uint32Array]",ie={};ie[f1]=ie[d3]=ie[h3]=ie[f3]=ie[Qu]=ie[m3]=ie[Yu]=ie[g3]=ie[p3]=!0,ie[zu]=ie[Vu]=ie[a3]=ie[Wu]=ie[u3]=ie[qu]=ie[Gu]=ie[Zu]=ie[r3]=ie[i3]=ie[s3]=ie[d1]=ie[h1]=ie[l3]=ie[c3]=!1;function C3(k){return un(k)&&ol(k.length)&&!!ie[yr(k)]}function A3(k){return function(I){return k(I)}}var m1=typeof e=="object"&&e&&!e.nodeType&&e,dl=m1&&!0&&n&&!n.nodeType&&n,b3=dl&&dl.exports===m1,Nc=b3&&z.process,g1=function(){try{var k=dl&&dl.require&&dl.require("util").types;return k||Nc&&Nc.binding&&Nc.binding("util")}catch{}}(),p1=g1&&g1.isTypedArray,v3=p1?A3(p1):C3,y3=Object.prototype,k3=y3.hasOwnProperty;function w3(k,I){var L=Ce(k),F=!L&&sl(k),U=!L&&!F&&rs(k),j=!L&&!F&&!U&&v3(k),Z=L||F||U||j,J=Z?s1(k.length,String):[],lt=J.length;for(var pt in k)(I||k3.call(k,pt))&&!(Z&&(pt=="length"||U&&(pt=="offset"||pt=="parent")||j&&(pt=="buffer"||pt=="byteLength"||pt=="byteOffset")||Uu(pt,lt)))&&J.push(pt);return J}var $c=Object.prototype;function B3(k){var I=k&&k.constructor,L=typeof I=="function"&&I.prototype||$c;return k===L}function Hc(k,I){return function(L){return k(I(L))}}var E3=Hc(Object.keys,Object),x3=Object.prototype,I3=x3.hasOwnProperty;function C1(k){if(!B3(k))return E3(k);var I=[];for(var L in Object(k))I3.call(k,L)&&L!="constructor"&&I.push(L);return I}function jc(k){return rl(k)?w3(k):C1(k)}function A1(k){var I=-1,L=k.length;return function(){return++I<L?{value:k[I],key:I}:null}}function T3(k){var I=-1;return function(){var F=k.next();return F.done?null:(I++,{value:F.value,key:I})}}function D3(k){var I=jc(k),L=-1,F=I.length;return function U(){var j=I[++L];return j==="__proto__"?U():L<F?{value:k[j],key:j}:null}}function S3(k){if(rl(k))return A1(k);var I=Pc(k);return I?T3(I):D3(k)}function po(k){return function(){if(k===null)throw new Error("Callback was already called.");var I=k;k=null,I.apply(this,arguments)}}function hl(k){return function(I,L,F){if(F=kr(F||Nt),k<=0||!I)return F(null);var U=S3(I),j=!1,Z=0,J=!1;function lt(ct,At){if(Z-=1,ct)j=!0,F(ct);else{if(At===ni||j&&Z<=0)return j=!0,F(null);J||pt()}}function pt(){for(J=!0;Z<k&&!j;){var ct=U();if(ct===null){j=!0,Z<=0&&F(null);return}Z+=1,L(ct.value,ct.key,po(lt))}J=!1}pt()}}function wr(k,I,L,F){hl(I)(k,M(L),F)}function $e(k,I){return function(L,F,U){return k(L,I,F,U)}}function Ju(k,I,L){L=kr(L||Nt);var F=0,U=0,j=k.length;j===0&&L(null);function Z(J,lt){J?L(J):(++U===j||lt===ni)&&L(null)}for(;F<j;F++)I(k[F],F,po(Z))}var L3=$e(wr,1/0),qo=function(k,I,L){var F=rl(k)?Ju:L3;F(k,M(I),L)};function Go(k){return function(I,L,F){return k(qo,I,M(L),F)}}function Ku(k,I,L,F){F=F||Nt,I=I||[];var U=[],j=0,Z=M(L);k(I,function(J,lt,pt){var ct=j++;Z(J,function(At,Gt){U[ct]=Gt,pt(At)})},function(J){F(J,U)})}var Uc=Go(Ku),Xu=H(Uc);function oi(k){return function(I,L,F,U){return k(hl(L),I,M(F),U)}}var Br=oi(Ku),td=$e(Br,1),ed=H(td);function is(k,I){for(var L=-1,F=k==null?0:k.length;++L<F&&I(k[L],L,k)!==!1;);return k}function nd(k){return function(I,L,F){for(var U=-1,j=Object(I),Z=F(I),J=Z.length;J--;){var lt=Z[k?J:++U];if(L(j[lt],lt,j)===!1)break}return I}}var ss=nd();function ls(k,I){return k&&ss(k,I,jc)}function b1(k,I,L,F){for(var U=k.length,j=L+(F?1:-1);F?j--:++j<U;)if(I(k[j],j,k))return j;return-1}function M3(k){return k!==k}function v1(k,I,L){for(var F=L-1,U=k.length;++F<U;)if(k[F]===I)return F;return-1}function fl(k,I,L){return I===I?v1(k,I,L):b1(k,M3,L)}var zc=function(k,I,L){typeof I=="function"&&(L=I,I=null),L=kr(L||Nt);var F=jc(k),U=F.length;if(!U)return L(null);I||(I=U);var j={},Z=0,J=!1,lt=Object.create(null),pt=[],ct=[],At={};ls(k,function(de,oe){if(!Ce(de)){Gt(oe,[de]),ct.push(oe);return}var ge=de.slice(0,de.length-1),Ao=ge.length;if(Ao===0){Gt(oe,de),ct.push(oe);return}At[oe]=Ao,is(ge,function(E){if(!k[E])throw new Error("async.auto task `"+oe+"` has a non-existent dependency `"+E+"` in "+ge.join(", "));en(E,function(){Ao--,Ao===0&&Gt(oe,de)})})}),t5(),Ie();function Gt(de,oe){pt.push(function(){Co(de,oe)})}function Ie(){if(pt.length===0&&Z===0)return L(null,j);for(;pt.length&&Z<I;){var de=pt.shift();de()}}function en(de,oe){var ge=lt[de];ge||(ge=lt[de]=[]),ge.push(oe)}function On(de){var oe=lt[de]||[];is(oe,function(ge){ge()}),Ie()}function Co(de,oe){if(!J){var ge=po(function(E,Ir){if(Z--,arguments.length>2&&(Ir=o(arguments,1)),E){var ds={};ls(j,function(_n,Pt){ds[Pt]=_n}),ds[de]=Ir,J=!0,lt=Object.create(null),L(E,ds)}else j[de]=Ir,On(de)});Z++;var Ao=M(oe[oe.length-1]);oe.length>1?Ao(j,ge):Ao(ge)}}function t5(){for(var de,oe=0;ct.length;)de=ct.pop(),oe++,is(e5(de),function(ge){--At[ge]===0&&ct.push(ge)});if(oe!==U)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function e5(de){var oe=[];return ls(k,function(ge,Ao){Ce(ge)&&fl(ge,de,0)>=0&&oe.push(Ao)}),oe}};function ri(k,I){for(var L=-1,F=k==null?0:k.length,U=Array(F);++L<F;)U[L]=I(k[L],L,k);return U}var R3="[object Symbol]";function O3(k){return typeof k=="symbol"||un(k)&&yr(k)==R3}var _3=1/0,od=ft?ft.prototype:void 0,y1=od?od.toString:void 0;function rd(k){if(typeof k=="string")return k;if(Ce(k))return ri(k,rd)+"";if(O3(k))return y1?y1.call(k):"";var I=k+"";return I=="0"&&1/k==-_3?"-0":I}function F3(k,I,L){var F=-1,U=k.length;I<0&&(I=-I>U?0:U+I),L=L>U?U:L,L<0&&(L+=U),U=I>L?0:L-I>>>0,I>>>=0;for(var j=Array(U);++F<U;)j[F]=k[F+I];return j}function P3(k,I,L){var F=k.length;return L=L===void 0?F:L,!I&&L>=F?k:F3(k,I,L)}function id(k,I){for(var L=k.length;L--&&fl(I,k[L],0)>-1;);return L}function N3(k,I){for(var L=-1,F=k.length;++L<F&&fl(I,k[L],0)>-1;);return L}function $3(k){return k.split("")}var H3="\\ud800-\\udfff",j3="\\u0300-\\u036f",U3="\\ufe20-\\ufe2f",se="\\u20d0-\\u20ff",ne=j3+U3+se,z3="\\ufe0e\\ufe0f",V3="\\u200d",W3=RegExp("["+V3+H3+ne+z3+"]");function q3(k){return W3.test(k)}var k1="\\ud800-\\udfff",G3="\\u0300-\\u036f",w1="\\ufe20-\\ufe2f",Z3="\\u20d0-\\u20ff",qe=G3+w1+Z3,sd="\\ufe0e\\ufe0f",ii="["+k1+"]",Vc="["+qe+"]",ml="\\ud83c[\\udffb-\\udfff]",Mn="(?:"+Vc+"|"+ml+")",ld="[^"+k1+"]",cd="(?:\\ud83c[\\udde6-\\uddff]){2}",ad="[\\ud800-\\udbff][\\udc00-\\udfff]",B1="\\u200d",ud=Mn+"?",dd="["+sd+"]?",vn="(?:"+B1+"(?:"+[ld,cd,ad].join("|")+")"+dd+ud+")*",Q3=dd+ud+vn,Rn="(?:"+[ld+Vc+"?",Vc,cd,ad,ii].join("|")+")",Y3=RegExp(ml+"(?="+ml+")|"+Rn+Q3,"g");function E1(k){return k.match(Y3)||[]}function Zo(k){return q3(k)?E1(k):$3(k)}function Wc(k){return k==null?"":rd(k)}var hd=/^\s+|\s+$/g;function ue(k,I,L){if(k=Wc(k),k&&(L||I===void 0))return k.replace(hd,"");if(!k||!(I=rd(I)))return k;var F=Zo(k),U=Zo(I),j=N3(F,U),Z=id(F,U)+1;return P3(F,j,Z).join("")}var Er=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,fd=/,/,J3=/(=.+)?(\s*)$/,md=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function K3(k){return k=k.toString().replace(md,""),k=k.match(Er)[2].replace(" ",""),k=k?k.split(fd):[],k=k.map(function(I){return ue(I.replace(J3,""))}),k}function x1(k,I){var L={};ls(k,function(F,U){var j,Z=_(F),J=!Z&&F.length===1||Z&&F.length===0;if(Ce(F))j=F.slice(0,-1),F=F[F.length-1],L[U]=j.concat(j.length>0?lt:F);else if(J)L[U]=F;else{if(j=K3(F),F.length===0&&!Z&&j.length===0)throw new Error("autoInject task functions require explicit parameters.");Z||j.pop(),L[U]=j.concat(lt)}function lt(pt,ct){var At=ri(j,function(Gt){return pt[Gt]});At.push(ct),M(F).apply(null,At)}}),zc(L,I)}function Yn(){this.head=this.tail=null,this.length=0}function gd(k,I){k.length=1,k.head=k.tail=I}Yn.prototype.removeLink=function(k){return k.prev?k.prev.next=k.next:this.head=k.next,k.next?k.next.prev=k.prev:this.tail=k.prev,k.prev=k.next=null,this.length-=1,k},Yn.prototype.empty=function(){for(;this.head;)this.shift();return this},Yn.prototype.insertAfter=function(k,I){I.prev=k,I.next=k.next,k.next?k.next.prev=I:this.tail=I,k.next=I,this.length+=1},Yn.prototype.insertBefore=function(k,I){I.prev=k.prev,I.next=k,k.prev?k.prev.next=I:this.head=I,k.prev=I,this.length+=1},Yn.prototype.unshift=function(k){this.head?this.insertBefore(this.head,k):gd(this,k)},Yn.prototype.push=function(k){this.tail?this.insertAfter(this.tail,k):gd(this,k)},Yn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},Yn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},Yn.prototype.toArray=function(){for(var k=Array(this.length),I=this.head,L=0;L<this.length;L++)k[L]=I.data,I=I.next;return k},Yn.prototype.remove=function(k){for(var I=this.head;I;){var L=I.next;k(I)&&this.removeLink(I),I=L}return this};function gl(k,I,L){if(I==null)I=1;else if(I===0)throw new Error("Concurrency must not be zero");var F=M(k),U=0,j=[],Z=!1;function J(At,Gt,Ie){if(Ie!=null&&typeof Ie!="function")throw new Error("task callback must be a function");if(ct.started=!0,Ce(At)||(At=[At]),At.length===0&&ct.idle())return A(function(){ct.drain()});for(var en=0,On=At.length;en<On;en++){var Co={data:At[en],callback:Ie||Nt};Gt?ct._tasks.unshift(Co):ct._tasks.push(Co)}Z||(Z=!0,A(function(){Z=!1,ct.process()}))}function lt(At){return function(Gt){U-=1;for(var Ie=0,en=At.length;Ie<en;Ie++){var On=At[Ie],Co=fl(j,On,0);Co===0?j.shift():Co>0&&j.splice(Co,1),On.callback.apply(On,arguments),Gt!=null&&ct.error(Gt,On.data)}U<=ct.concurrency-ct.buffer&&ct.unsaturated(),ct.idle()&&ct.drain(),ct.process()}}var pt=!1,ct={_tasks:new Yn,concurrency:I,payload:L,saturated:Nt,unsaturated:Nt,buffer:I/4,empty:Nt,drain:Nt,error:Nt,started:!1,paused:!1,push:function(At,Gt){J(At,!1,Gt)},kill:function(){ct.drain=Nt,ct._tasks.empty()},unshift:function(At,Gt){J(At,!0,Gt)},remove:function(At){ct._tasks.remove(At)},process:function(){if(!pt){for(pt=!0;!ct.paused&&U<ct.concurrency&&ct._tasks.length;){var At=[],Gt=[],Ie=ct._tasks.length;ct.payload&&(Ie=Math.min(Ie,ct.payload));for(var en=0;en<Ie;en++){var On=ct._tasks.shift();At.push(On),j.push(On),Gt.push(On.data)}U+=1,ct._tasks.length===0&&ct.empty(),U===ct.concurrency&&ct.saturated();var Co=po(lt(At));F(Gt,Co)}pt=!1}},length:function(){return ct._tasks.length},running:function(){return U},workersList:function(){return j},idle:function(){return ct._tasks.length+U===0},pause:function(){ct.paused=!0},resume:function(){ct.paused!==!1&&(ct.paused=!1,A(ct.process))}};return ct}function si(k,I){return gl(k,1,I)}var cs=$e(wr,1);function Qo(k,I,L,F){F=kr(F||Nt);var U=M(L);cs(k,function(j,Z,J){U(I,j,function(lt,pt){I=pt,J(lt)})},function(j){F(j,I)})}function qc(){var k=ri(arguments,M);return function(){var I=o(arguments),L=this,F=I[I.length-1];typeof F=="function"?I.pop():F=Nt,Qo(k,I,function(U,j,Z){j.apply(L,U.concat(function(J){var lt=o(arguments,1);Z(J,lt)}))},function(U,j){F.apply(L,[U].concat(j))})}}var Gc=function(){return qc.apply(null,o(arguments).reverse())},pd=Array.prototype.concat,pl=function(k,I,L,F){F=F||Nt;var U=M(L);Br(k,I,function(j,Z){U(j,function(J){return J?Z(J):Z(null,o(arguments,1))})},function(j,Z){for(var J=[],lt=0;lt<Z.length;lt++)Z[lt]&&(J=pd.apply(J,Z[lt]));return F(j,J)})},I1=$e(pl,1/0),Zc=$e(pl,1),Qc=function(){var k=o(arguments),I=[null].concat(k);return function(){var L=arguments[arguments.length-1];return L.apply(this,I)}};function Cl(k){return k}function li(k,I){return function(L,F,U,j){j=j||Nt;var Z=!1,J;L(F,function(lt,pt,ct){U(lt,function(At,Gt){At?ct(At):k(Gt)&&!J?(Z=!0,J=I(!0,lt),ct(null,ni)):ct()})},function(lt){lt?j(lt):j(null,Z?J:I(!1))})}}function dn(k,I){return I}var as=Go(li(Cl,dn)),Yo=oi(li(Cl,dn)),Al=$e(Yo,1);function Cd(k){return function(I){var L=o(arguments,1);L.push(function(F){var U=o(arguments,1);typeof console=="object"&&(F?console.error&&console.error(F):console[k]&&is(U,function(j){console[k](j)}))}),M(I).apply(null,L)}}var T1=Cd("dir");function D1(k,I,L){L=po(L||Nt);var F=M(k),U=M(I);function j(J){if(J)return L(J);var lt=o(arguments,1);lt.push(Z),U.apply(this,lt)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}Z(null,!0)}function Ad(k,I,L){L=po(L||Nt);var F=M(k),U=function(j){if(j)return L(j);var Z=o(arguments,1);if(I.apply(this,Z))return F(U);L.apply(null,[null].concat(Z))};F(U)}function S1(k,I,L){Ad(k,function(){return!I.apply(this,arguments)},L)}function L1(k,I,L){L=po(L||Nt);var F=M(I),U=M(k);function j(J){if(J)return L(J);U(Z)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}U(Z)}function ci(k){return function(I,L,F){return k(I,F)}}function Yc(k,I,L){qo(k,ci(M(I)),L)}function bl(k,I,L,F){hl(I)(k,ci(M(L)),F)}var ai=$e(bl,1);function Jc(k){return _(k)?k:i(function(I,L){var F=!0;I.push(function(){var U=arguments;F?A(function(){L.apply(null,U)}):L.apply(null,U)}),k.apply(this,I),F=!1})}function Jn(k){return!k}var ui=Go(li(Jn,Jn)),vl=oi(li(Jn,Jn)),Kc=$e(vl,1);function M1(k){return function(I){return I==null?void 0:I[k]}}function us(k,I,L,F){var U=new Array(I.length);k(I,function(j,Z,J){L(j,function(lt,pt){U[Z]=!!pt,J(lt)})},function(j){if(j)return F(j);for(var Z=[],J=0;J<I.length;J++)U[J]&&Z.push(I[J]);F(null,Z)})}function Kn(k,I,L,F){var U=[];k(I,function(j,Z,J){L(j,function(lt,pt){lt?J(lt):(pt&&U.push({index:Z,value:j}),J())})},function(j){j?F(j):F(null,ri(U.sort(function(Z,J){return Z.index-J.index}),M1("value")))})}function Xc(k,I,L,F){var U=rl(I)?us:Kn;U(k,I,M(L),F||Nt)}var ta=Go(Xc),yl=oi(Xc),ea=$e(yl,1);function R1(k,I){var L=po(I||Nt),F=M(Jc(k));function U(j){if(j)return L(j);F(U)}U()}var na=function(k,I,L,F){F=F||Nt;var U=M(L);Br(k,I,function(j,Z){U(j,function(J,lt){return J?Z(J):Z(null,{key:lt,val:j})})},function(j,Z){for(var J={},lt=Object.prototype.hasOwnProperty,pt=0;pt<Z.length;pt++)if(Z[pt]){var ct=Z[pt].key,At=Z[pt].val;lt.call(J,ct)?J[ct].push(At):J[ct]=[At]}return F(j,J)})},di=$e(na,1/0),N=$e(na,1),G=Cd("log");function V(k,I,L,F){F=kr(F||Nt);var U={},j=M(L);wr(k,I,function(Z,J,lt){j(Z,J,function(pt,ct){if(pt)return lt(pt);U[J]=ct,lt()})},function(Z){F(Z,U)})}var ht=$e(V,1/0),Et=$e(V,1);function Vt(k,I){return I in k}function we(k,I){var L=Object.create(null),F=Object.create(null);I=I||Cl;var U=M(k),j=i(function(J,lt){var pt=I.apply(null,J);Vt(L,pt)?A(function(){lt.apply(null,L[pt])}):Vt(F,pt)?F[pt].push(lt):(F[pt]=[lt],U.apply(null,J.concat(function(){var ct=o(arguments);L[pt]=ct;var At=F[pt];delete F[pt];for(var Gt=0,Ie=At.length;Gt<Ie;Gt++)At[Gt].apply(null,ct)})))});return j.memo=L,j.unmemoized=k,j}var qt;a?qt=process.nextTick:l?qt=setImmediate:qt=d;var oa=h(qt);function bd(k,I,L){L=L||Nt;var F=rl(I)?[]:{};k(I,function(U,j,Z){M(U)(function(J,lt){arguments.length>2&&(lt=o(arguments,1)),F[j]=lt,Z(J)})},function(U){L(U,F)})}function yn(k,I){bd(qo,k,I)}function kl(k,I,L){bd(hl(I),k,L)}var vd=function(k,I){var L=M(k);return gl(function(F,U){L(F[0],U)},I,1)},hi=function(k,I){var L=vd(k,I);return L.push=function(F,U,j){if(j==null&&(j=Nt),typeof j!="function")throw new Error("task callback must be a function");if(L.started=!0,Ce(F)||(F=[F]),F.length===0)return A(function(){L.drain()});U=U||0;for(var Z=L._tasks.head;Z&&U>=Z.priority;)Z=Z.next;for(var J=0,lt=F.length;J<lt;J++){var pt={data:F[J],priority:U,callback:j};Z?L._tasks.insertBefore(Z,pt):L._tasks.push(pt)}A(L.process)},delete L.unshift,L};function wl(k,I){if(I=kr(I||Nt),!Ce(k))return I(new TypeError("First argument to race must be an array of functions"));if(!k.length)return I();for(var L=0,F=k.length;L<F;L++)M(k[L])(I)}function fi(k,I,L,F){var U=o(k).reverse();Qo(U,I,L,F)}function Wt(k){var I=M(k);return i(function(F,U){return F.push(function(Z,J){if(Z)U(null,{error:Z});else{var lt;arguments.length<=2?lt=J:lt=o(arguments,1),U(null,{value:lt})}}),I.apply(this,F)})}function O1(k){var I;return Ce(k)?I=ri(k,Wt):(I={},ls(k,function(L,F){I[F]=Wt.call(this,L)})),I}function yd(k,I,L,F){Xc(k,I,function(U,j){L(U,function(Z,J){j(Z,!J)})},F)}var Bl=Go(yd),kd=oi(yd),_1=$e(kd,1);function F1(k){return function(){return k}}function mi(k,I,L){var F=5,U=0,j={times:F,intervalFunc:F1(U)};function Z(ct,At){if(typeof At=="object")ct.times=+At.times||F,ct.intervalFunc=typeof At.interval=="function"?At.interval:F1(+At.interval||U),ct.errorFilter=At.errorFilter;else if(typeof At=="number"||typeof At=="string")ct.times=+At||F;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof k=="function"?(L=I||Nt,I=k):(Z(j,k),L=L||Nt),typeof I!="function")throw new Error("Invalid arguments for async.retry");var J=M(I),lt=1;function pt(){J(function(ct){ct&<++<j.times&&(typeof j.errorFilter!="function"||j.errorFilter(ct))?setTimeout(pt,j.intervalFunc(lt)):L.apply(null,arguments)})}pt()}var Jo=function(k,I){I||(I=k,k=null);var L=M(I);return i(function(F,U){function j(Z){L.apply(null,F.concat(Z))}k?mi(k,j,U):mi(j,U)})};function El(k,I){bd(cs,k,I)}var xl=Go(li(Boolean,Cl)),xr=oi(li(Boolean,Cl)),Il=$e(xr,1);function wd(k,I,L){var F=M(I);Uc(k,function(j,Z){F(j,function(J,lt){if(J)return Z(J);Z(null,{value:j,criteria:lt})})},function(j,Z){if(j)return L(j);L(null,ri(Z.sort(U),M1("value")))});function U(j,Z){var J=j.criteria,lt=Z.criteria;return J<lt?-1:J>lt?1:0}}function Tl(k,I,L){var F=M(k);return i(function(U,j){var Z=!1,J;function lt(){var pt=k.name||"anonymous",ct=new Error('Callback function "'+pt+'" timed out.');ct.code="ETIMEDOUT",L&&(ct.info=L),Z=!0,j(ct)}U.push(function(){Z||(j.apply(null,arguments),clearTimeout(J))}),J=setTimeout(lt,I),F.apply(null,U)})}var P1=Math.ceil,Dl=Math.max;function gi(k,I,L,F){for(var U=-1,j=Dl(P1((I-k)/(L||1)),0),Z=Array(j);j--;)Z[F?j:++U]=k,k+=L;return Z}function pi(k,I,L,F){var U=M(L);Br(gi(0,k,1),I,U,F)}var N1=$e(pi,1/0),$1=$e(pi,1);function H1(k,I,L,F){arguments.length<=3&&(F=L,L=I,I=Ce(k)?[]:{}),F=kr(F||Nt);var U=M(L);qo(k,function(j,Z,J){U(I,j,Z,J)},function(j){F(j,I)})}function Sl(k,I){var L=null,F;I=I||Nt,ai(k,function(U,j){M(U)(function(Z,J){arguments.length>2?F=o(arguments,1):F=J,L=Z,j(!Z)})},function(){I(L,F)})}function Ll(k){return function(){return(k.unmemoized||k).apply(null,arguments)}}function Ml(k,I,L){L=po(L||Nt);var F=M(I);if(!k())return L(null);var U=function(j){if(j)return L(j);if(k())return F(U);var Z=o(arguments,1);L.apply(null,[null].concat(Z))};F(U)}function j1(k,I,L){Ml(function(){return!k.apply(this,arguments)},I,L)}var Bd=function(k,I){if(I=kr(I||Nt),!Ce(k))return I(new Error("First argument to waterfall must be an array of functions"));if(!k.length)return I();var L=0;function F(j){var Z=M(k[L++]);j.push(po(U)),Z.apply(null,j)}function U(j){if(j||L===k.length)return I.apply(null,arguments);F(o(arguments,1))}F([])},X3={apply:r,applyEach:Xu,applyEachSeries:ed,asyncify:v,auto:zc,autoInject:x1,cargo:si,compose:Gc,concat:I1,concatLimit:pl,concatSeries:Zc,constant:Qc,detect:as,detectLimit:Yo,detectSeries:Al,dir:T1,doDuring:D1,doUntil:S1,doWhilst:Ad,during:L1,each:Yc,eachLimit:bl,eachOf:qo,eachOfLimit:wr,eachOfSeries:cs,eachSeries:ai,ensureAsync:Jc,every:ui,everyLimit:vl,everySeries:Kc,filter:ta,filterLimit:yl,filterSeries:ea,forever:R1,groupBy:di,groupByLimit:na,groupBySeries:N,log:G,map:Uc,mapLimit:Br,mapSeries:td,mapValues:ht,mapValuesLimit:V,mapValuesSeries:Et,memoize:we,nextTick:oa,parallel:yn,parallelLimit:kl,priorityQueue:hi,queue:vd,race:wl,reduce:Qo,reduceRight:fi,reflect:Wt,reflectAll:O1,reject:Bl,rejectLimit:kd,rejectSeries:_1,retry:mi,retryable:Jo,seq:qc,series:El,setImmediate:A,some:xl,someLimit:xr,someSeries:Il,sortBy:wd,timeout:Tl,times:N1,timesLimit:pi,timesSeries:$1,transform:H1,tryEach:Sl,unmemoize:Ll,until:j1,waterfall:Bd,whilst:Ml,all:ui,allLimit:vl,allSeries:Kc,any:xl,anyLimit:xr,anySeries:Il,find:as,findLimit:Yo,findSeries:Al,forEach:Yc,forEachSeries:ai,forEachLimit:bl,forEachOf:qo,forEachOfSeries:cs,forEachOfLimit:wr,inject:Qo,foldl:Qo,foldr:fi,select:ta,selectLimit:yl,selectSeries:ea,wrapSync:v};e.default=X3,e.apply=r,e.applyEach=Xu,e.applyEachSeries=ed,e.asyncify=v,e.auto=zc,e.autoInject=x1,e.cargo=si,e.compose=Gc,e.concat=I1,e.concatLimit=pl,e.concatSeries=Zc,e.constant=Qc,e.detect=as,e.detectLimit=Yo,e.detectSeries=Al,e.dir=T1,e.doDuring=D1,e.doUntil=S1,e.doWhilst=Ad,e.during=L1,e.each=Yc,e.eachLimit=bl,e.eachOf=qo,e.eachOfLimit=wr,e.eachOfSeries=cs,e.eachSeries=ai,e.ensureAsync=Jc,e.every=ui,e.everyLimit=vl,e.everySeries=Kc,e.filter=ta,e.filterLimit=yl,e.filterSeries=ea,e.forever=R1,e.groupBy=di,e.groupByLimit=na,e.groupBySeries=N,e.log=G,e.map=Uc,e.mapLimit=Br,e.mapSeries=td,e.mapValues=ht,e.mapValuesLimit=V,e.mapValuesSeries=Et,e.memoize=we,e.nextTick=oa,e.parallel=yn,e.parallelLimit=kl,e.priorityQueue=hi,e.queue=vd,e.race=wl,e.reduce=Qo,e.reduceRight=fi,e.reflect=Wt,e.reflectAll=O1,e.reject=Bl,e.rejectLimit=kd,e.rejectSeries=_1,e.retry=mi,e.retryable=Jo,e.seq=qc,e.series=El,e.setImmediate=A,e.some=xl,e.someLimit=xr,e.someSeries=Il,e.sortBy=wd,e.timeout=Tl,e.times=N1,e.timesLimit=pi,e.timesSeries=$1,e.transform=H1,e.tryEach=Sl,e.unmemoize=Ll,e.until=j1,e.waterfall=Bd,e.whilst=Ml,e.all=ui,e.allLimit=vl,e.allSeries=Kc,e.any=xl,e.anyLimit=xr,e.anySeries=Il,e.find=as,e.findLimit=Yo,e.findSeries=Al,e.forEach=Yc,e.forEachSeries=ai,e.forEachLimit=bl,e.forEachOf=qo,e.forEachOfSeries=cs,e.forEachOfLimit=wr,e.inject=Qo,e.foldl=Qo,e.foldr=fi,e.select=ta,e.selectLimit=yl,e.selectSeries=ea,e.wrapSync=v,Object.defineProperty(e,"__esModule",{value:!0})})})(ap,ap.exports);var Tb={exports:{}},up=Tb.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),o=2;e===1/0;o*=2)e=Math.log(Math.pow(2,n/o))/Math.log(t)*o;for(var r=e-Math.floor(e),i="",o=0;o<Math.floor(e);o++){var s=Math.floor(Math.random()*t).toString(t);i=s+i}if(r){var l=Math.pow(t,r),s=Math.floor(Math.random()*l).toString(t);i=s+i}var a=parseInt(i,t);return a!==1/0&&a>=Math.pow(2,n)?up(n,t):i};up.rack=function(n,t,e){var o=function(i){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=up(n,t)}while(Object.hasOwnProperty.call(r,l));return r[l]=i,l},r=o.hats={};return o.get=function(i){return o.hats[i]},o.set=function(i,s){return o.hats[i]=s,o},o.bits=n||128,o.base=t||16,o};var Db=$i,mS=xb,gS=Ib,jh=Fo,dp=ap.exports,pS=Tb.exports,Sb=Us.ACTIONS,Lb=Me;function Me(n,t){if(Db.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}Db.mixin(Me),Me.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Me.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Me.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||pS();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Me.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(o){if(o)return t._callbackOrEmit(o,n);var r=Object.keys(t._remotePresenceInstances);dp.parallel([function(i){dp.each(e,function(s,l){t.localPresences[s].destroy(l)},i)},function(i){if(!t._wantsDestroy)return i();dp.each(r,function(s,l){t._remotePresenceInstances[s].destroy(l)},i)}],function(i){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(i,n)})})},Me.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?Sb.presenceSubscribe:Sb.presenceUnsubscribe,o=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[o]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,o,this)},Me.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Me.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Me.prototype._receiveUpdate=function(n,t){var e=jh.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var o=this,r=jh.digOrCreate(this._remotePresenceInstances,t.id,function(){return o._createRemotePresence(t.id)});r.receiveUpdate(t)},Me.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Me.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()}},Me.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Me.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Me.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 o=this;this.subscribe(function(r){o._callEachOrEmit(n,r)})},Me.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Me.prototype._callbackOrEmit=function(n,t){if(t)return jh.nextTick(t,n);n&&this.emit("error",n)},Me.prototype._createLocalPresence=function(n){return new mS(this,n)},Me.prototype._createRemotePresence=function(n){return new gS(this,n)},Me.prototype._callEachOrEmit=function(n,t){var e=jh.callEach(n,t);!e&&t&&this.emit("error",t)};var Wa=xb,Mb=Fh,CS=Fo,Rb=Mb.CODES,AS=No;function No(n,t){Wa.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()}No.prototype=Object.create(Wa.prototype),No.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:Rb.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,Wa.prototype.submit.call(this,n,t)},No.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),Wa.prototype.destroy.call(this,n)},No.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={})})}},No.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)},No.prototype._transformAgainstOp=function(n,t){var e=this,o=this._doc._dataStateVersion;this._pendingMessages.forEach(function(r){var i=e._docDataVersionByPresenceVersion[r.pv];if(!(i>=o))try{r.p=e._transformPresence(r.p,n,t),e._docDataVersionByPresenceVersion[r.pv]=o}catch(l){var s=e._getCallback(r.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(r){this.emit("error",r)}},No.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},No.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},No.prototype._message=function(){var n=Wa.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},No.prototype._transformPresence=function(n,t,e){var o=this._doc.type;if(!CS.supportsPresence(o))throw new Mb(Rb.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+o.name);return o.transformPresence(n,t,e)};var Ob={};(function(n){var t=Ua,e=Fh,o=Fo,r=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var a=l.create.type;if(typeof a!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[a];if(d==null||typeof d!="object")return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(r.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(r.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(r.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(r.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,a){if(typeof l!="object")return new e(r.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&a.v!=null&&l.v!==a.v)return new e(r.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(a.create){if(l.type)return new e(r.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=a.create,h=t.map[d.type];if(!h)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(A){return A}}else if(a.del)l.data=void 0,l.type=null,l.v++;else if("op"in a){var p=i(l,a.op);if(p)return p;l.v++}else l.v++};function i(l,a){if(!l.type)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(a===void 0)return new e(r.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,a)}catch(h){return new e(r.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,a,d){if(a.v!=null&&a.v!==d.v)return new e(r.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(a.create||"op"in a)return new e(r.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in a||a.create||a.del)||"op"in d&&a.create)return new e(r.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in a){if(!l)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{a.op=l.transform(a.op,d.op,"left")}catch(h){return h}}}a.v!=null&&a.v++},n.applyOps=function(l,a,d){d=d||{};for(var h=0;h<a.length;h++){var p=a[h];if(d._normalizeLegacyJson0Ops)try{s(l,p)}catch{return new e(r.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=p.v;var A=n.apply(l,p);if(A)return A}},n.transformPresence=function(l,a,d){var h=this.checkOp(a);if(h)return h;var p=l.t;if(typeof p=="string"&&(p=t.map[p]),!p)return{code:r.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!o.supportsPresence(p))return{code:r.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(a.create||a.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:p.transformPresence(l.p,a.op,d)}catch(A){return{code:r.ERR_PRESENCE_TRANSFORM_FAILED,message:A.message||A}}l.v++};function s(l,a){if(l.type===t.defaultType.uri){var d=a.op;if(!!d){var h=l.data;d.length>1&&(h=o.clone(h));for(var p=0;p<d.length;p++){var A=d[p];typeof A.lm=="string"&&(A.lm=+A.lm);for(var v=A.p,B=h,D=0;D<v.length;D++){var T=v[D];Object.prototype.toString.call(B)=="[object Array]"?v[D]=+T:B.constructor===Object&&(v[D]=T.toString()),B=B[T]}p<d.length-1&&(h=t.defaultType.apply(h,[A]))}}}}})(Ob);var qa=Ib,bS=Ob,vS=co;function co(n,t){qa.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()}co.prototype=Object.create(qa.prototype),co.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},co.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),qa.prototype.destroy.call(this,n)},co.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)},co.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))}})}},co.prototype._handleOp=function(n,t,e){var o=e===this.src;this._transformAgainstOp(n,o),this._cacheOp(n,o),this._setPendingPresence()},qa.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},qa.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},co.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)}},co.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++):bS.transformPresence(this._pending,t,e)}var o=this._pending.v>=this._doc.version;return o&&this._stopCachingOps(),o},co.prototype._startCachingOps=function(){this._opCache=[]},co.prototype._stopCachingOps=function(){this._opCache=null},co.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var _b=Lb,yS=AS,kS=vS;function tc(n,t,e){var o=tc.channel(t,e);_b.call(this,n,o),this.collection=t,this.id=e}var wS=tc;tc.prototype=Object.create(_b.prototype),tc.channel=function(n,t){return n+"."+t},tc.prototype._createLocalPresence=function(n){return new yS(this,n)},tc.prototype._createRemotePresence=function(n){return new kS(this,n)};var BS=ES;function ES(n,t,e,o,r){this.id=n,this.v=t,this.type=e,this.data=o,this.m=r}var xS=BS,Fb=$i,Pb=Ga;function Ga(n,t,e,o,r){if(Fb.EventEmitter.call(this),typeof r!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=o,this.collection=e,this.callback=r,this.sent=!1}Fb.mixin(Ga),Ga.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},Ga.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},Ga.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,o=new xS(this.id,t.v,t.type,t.data,e);this.callback(null,o)};var Nb=Pb,IS=Fo,TS=Us.ACTIONS,DS=hp;function hp(n,t,e,o,r,i){if(Nb.call(this,n,t,e,o,i),!IS.isValidVersion(r))throw new Error("Snapshot version must be a positive integer or null");this.version=r}hp.prototype=Object.create(Nb.prototype),hp.prototype._message=function(){return{a:TS.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var $b=Pb,SS=Fo,LS=Us.ACTIONS,MS=fp;function fp(n,t,e,o,r,i){if($b.call(this,n,t,e,o,i),!SS.isValidTimestamp(r))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=r}fp.prototype=Object.create($b.prototype),fp.prototype._message=function(){return{a:LS.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var RS=iS,OS=uS,_S=Lb,Hb=wS,FS=DS,PS=MS,jb=$i,ec=Fh,te=Us.ACTIONS,Ub=Ua,$o=Fo,Za=Cb,Qa=ec.CODES;function zb(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var NS=wt;function wt(n){jb.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=zb(n),this.bindToSocket(n)}jb.mixin(wt),wt.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=zb(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(o){try{var r=typeof o.data=="string"?JSON.parse(o.data):o.data}catch{Za.warn("Failed to parse message",o);return}e.debug&&Za.info("RECV",JSON.stringify(r));var i={data:r};if(e.emit("receive",i),!!i.data)try{e.handleMessage(i.data)}catch(s){$o.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(o){e.emit("connection error",o)},n.onclose=function(o){o==="closed"||o==="Closed"?e._setState("closed",o):o==="stopped"||o==="Stopped by server"?e._setState("stopped",o):e._setState("disconnected",o)}},wt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=Vb(n.error,n),delete n.error),n.a){case te.initLegacy:return this._handleLegacyInit(n);case te.handshake:return this._handleHandshake(t,n);case te.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case te.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case te.queryUnsubscribe:return;case te.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 te.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case te.bulkSubscribe:case te.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case te.snapshotFetch:case te.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case te.fetch:var o=this.getExisting(n.c,n.d);o&&o._handleFetch(t,n.data);return;case te.subscribe:case te.unsubscribe:var o=this.getExisting(n.c,n.d);o&&o._handleSubscribe(t,n.data);return;case te.op:var o=this.getExisting(n.c,n.d);o&&o._handleOp(t,n);return;case te.presence:return this._handlePresence(t,n);case te.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case te.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case te.presenceRequest:return this._handlePresenceRequest(t,n);case te.pingPong:return this._handlePingPong(t);default:Za.warn("Ignoring unrecognized message",n)}};function Vb(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}wt.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var o in t.data){var r=t.data[o],i=this.getExisting(t.c,o);i&&(n?i[e](n):r.error?i[e](Vb(r.error)):i[e](null,r))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var o=t.b[s],i=this.getExisting(t.c,o);i&&i[e](n)}else if(t.b)for(var o in t.b){var i=this.getExisting(t.c,o);i&&i[e](n)}else Za.error("Invalid bulk message",t)},wt.prototype._reset=function(){this.agent=null},wt.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 ec(Qa.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 o in this.queries){var r=this.queries[o];r._onConnectionStateChanged()}for(var i in this.collections){var s=this.collections[i];for(var o in s)s[o]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var o in this._snapshotRequests){var a=this._snapshotRequests[o];a._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},wt.prototype.startBulk=function(){this.bulk||(this.bulk={})},wt.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},wt.prototype._sendBulk=function(n,t,e){if(!!e){var o=[],r={},i=0,s;for(var l in e){var a=e[l];a==null?o.push(l):(r[l]=a,s=l,i++)}if(o.length===1){var l=o[0];this.send({a:n,c:t,d:l})}else o.length&&this.send({a:"b"+n,c:t,b:o});if(i===1){var d=r[s];this.send({a:n,c:t,d:s,v:d})}else i&&this.send({a:"b"+n,c:t,b:r})}},wt.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var o=this.bulk[t.collection]||(this.bulk[t.collection]={}),r=o[n]||(o[n]={}),i=r.hasOwnProperty(t.id);return r[t.id]=e,i}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},wt.prototype.sendFetch=function(n){return this._sendActions(te.fetch,n,n.version)},wt.prototype.sendSubscribe=function(n){return this._sendActions(te.subscribe,n,n.version)},wt.prototype.sendUnsubscribe=function(n){return this._sendActions(te.unsubscribe,n)},wt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:te.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)},wt.prototype.send=function(n){this.debug&&Za.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},wt.prototype.ping=function(){if(!this.canSend)throw new ec(Qa.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:te.pingPong};this.send(n)},wt.prototype.close=function(){this.socket.close()},wt.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},wt.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),o=e[t];return o||(o=e[t]=new RS(this,n,t),this.emit("doc",o)),o._wantsDestroy=!1,o},wt.prototype._destroyDoc=function(n){!n._wantsDestroy||($o.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},wt.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},wt.prototype._createQuery=function(n,t,e,o,r){var i=this.nextQueryId++,s=new OS(n,this,i,t,e,o,r);return this.queries[i]=s,s.send(),s},wt.prototype._destroyQuery=function(n){delete this.queries[n.id]},wt.prototype.createFetchQuery=function(n,t,e,o){return this._createQuery(te.queryFetch,n,t,e,o)},wt.prototype.createSubscribeQuery=function(n,t,e,o){return this._createQuery(te.querySubscribe,n,t,e,o)},wt.prototype.hasPending=function(){return!!(this._firstDoc(Uh)||this._firstQuery(Uh)||this._firstSnapshotRequest())};function Uh(n){return n.hasPending()}wt.prototype.hasWritePending=function(){return!!this._firstDoc($S)};function $S(n){return n.hasWritePending()}wt.prototype.whenNothingPending=function(n){var t=this._firstDoc(Uh);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(Uh);if(e){e.once("ready",this._nothingPendingRetry(n));return}var o=this._firstSnapshotRequest();if(o){o.once("ready",this._nothingPendingRetry(n));return}$o.nextTick(n)},wt.prototype._nothingPendingRetry=function(n){var t=this;return function(){$o.nextTick(function(){t.whenNothingPending(n)})}},wt.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var o in e){var r=e[o];if(n(r))return r}}},wt.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},wt.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},wt.prototype.fetchSnapshot=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new FS(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype.fetchSnapshotByTimestamp=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new PS(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},wt.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},wt.prototype._initializeHandshake=function(){this.send({a:te.handshake,id:this.id})},wt.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},wt.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},wt.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new ec(Qa.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(Ub.map[n.type]!==Ub.defaultType)return this.emit("error",new ec(Qa.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new ec(Qa.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},wt.prototype.getPresence=function(n){var t=this,e=$o.digOrCreate(this._presences,n,function(){return new _S(t,n)});return e._wantsDestroy=!1,e},wt.prototype.getDocPresence=function(n,t){var e=Hb.channel(n,t),o=this,r=$o.digOrCreate(this._presences,e,function(){return new Hb(o,n,t)});return r._wantsDestroy=!1,r},wt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var o={a:n,ch:e.channel,seq:t};return this.send(o),o.seq},wt.prototype._addPresence=function(n){$o.digOrCreate(this._presences,n.channel,function(){return n})},wt.prototype._handlePresenceSubscribe=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},wt.prototype._handlePresenceUnsubscribe=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},wt.prototype._handlePresence=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},wt.prototype._handlePresenceRequest=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var Wb=NS,HS=Ua;const zh={err:1001,msg:"user auth error",name:"AuthError"},jS={err:1002,msg:"you don't have required permission",name:"PermissionError"},mp={err:1003,msg:"Too many user connected",name:"MaxUserError"},Ya={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},US={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},zS={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},Ja="x-live-editor-token",Vh="x-live-editor-base-url",gn=S("auth-connection");function VS(n){try{n()}catch(t){gn.error(t)}}class WS{constructor(t,e){m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new q5.EventEmitter);m(this,"token",null);m(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 Bs(this.getBaseURL())}async auth(t){g(gn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,o=await window.fetch(e,{method:"GET",headers:{[Ja]:t.token,[Vh]:this.getBase64BaseURL()},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return this.token=t.token,await o.json()}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[Vh]:Bs(this.getBaseURL())}})}async init(t){const e=await this.auth(t);this.resourceToken=e.read,this.ws=new HB.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(Wb.prototype),g(gn,this.connection,"no this.connection"),this.ws,this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})};const o=this.connection.handleMessage.bind(this.connection);this.connection.handleMessage=r=>{var s;const i=r;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in i||i.a==="pong")this.handleMessage(i);else{Object.prototype.hasOwnProperty.call(i,"a")&&i.a!=="init"&&i.a!=="hs"&&(this.retryCount=0);try{o(i)}catch(l){if((l==null?void 0:l.type)==="writeConflict"){this.emitWriteConflictError(l,i);return}if((s=l==null?void 0:l.message)!=null&&s.startsWith("Cannot invert subtype")){this.emitWriteConflictError(l,i);return}throw l}}},Wb.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,gn.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const t=await this.reauthFunc();await this.auth(t),this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})}}}catch(t){gn.error(t),setTimeout(()=>this.handleAuthError(),0)}}else gn.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(zh.msg);t.code=zh.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Ya.msg);t.code=Ya.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 o=e.err;if(o===zh.err)gn.warn("auth error"),this.handleAuthError();else if(o===mp.err)gn.warn(mp.msg),this.emitMaxUsersError();else if(o===Ya.err){gn.warn(Ya.msg);try{this.emitRequestReloadError()}catch(r){gn.error(`error occurred while process reload error: ${JSON.stringify(r)}`)}finally{this.end(!1)}}else gn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return g(gn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(g(gn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){g(gn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){g(gn,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e;this.reauthFunc=void 0,this.events.removeAllListeners(),VS(()=>{var o;return(o=this.connection)==null?void 0:o.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}S("utils/file");function qS(){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}qS();async function GS(n){const e=n.size,o=Math.floor((e+102400-1)/102400),r=new jB.Hash;for(let s=0;s<o;s++){const l=s*102400;let a=l+102400;a>e&&(a=e);const h=await n.slice(l,a,n.type).arrayBuffer();r.update(new Uint8Array(h))}const i=r.digest();return Bs(i)}const ur=S("sharedb-doc/client");class ZS{constructor(t,e,o){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",K());m(this,"getDoc",async()=>{const t=o=>new Promise((r,i)=>{o.fetch(s=>{s?i(s):r()})});g(ur,!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),ur.debug(e),e});this.auth=t;const r=`${e}/${this.auth.appId}/${this.auth.docId}`;HS.register(_d.type),this.connection=new WS(r,o),this.reauthFunc=o}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return g(ur,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,o=>{(t==="error"||this.doc)&&e(o)})}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,o,r,i){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...i},data:{name:o,size:r}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const o=`${this.apiServer()}/resources`;let r=[];t.forEach(l=>{const a=l.split("|");r.push(...a)}),r=Array.from(new Set(r));const i=r.map(l=>this.getFileUrlByHash(o,l,"",0,{[Ja]:this.connection.token}));return await Promise.all(i)}async uploadFile(t,e,o,r,i){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=v=>{ur.info(`on progress: ${v.loaded}`);let B=v.loaded*100/s;B>100&&(B=100),r(B)},a=await GS(e),d=await this.getFileUrlByHash(t,a,e.name,e.size,o);if(d)return r(-1),d;let h=t;i!=null&&i.thumbnail&&(h+="/thumbnail");const p=new FormData;p.append("file-size",`${e.size}`),p.append("file-hash",a),p.append("file",e,e.name);const A=await this.request(h,{method:"post",data:p,withCredentials:!0,headers:{...o},onUploadProgress:l});return ur.info(A),r(100),Array.isArray(A.data)?A.data[0]:A.data}async uploadResource(t,e=()=>{},o){const i=`${this.apiServer()}/resources`;g(ur,this.connection.token,"no connection token");const s=await this.uploadFile(i,t,{[Ja]:this.connection.token},e,o);return g(ur,s,"no result"),s}async request(t,e){var i,s;let o=this.connection.token,r;for(let l=0;l<2;l++){const a=e||{};a.url=t,a.headers||(a.headers={}),g(ur,o,"no token"),a.headers={...a.headers,[Ja]:o,[Vh]:this.connection.getBase64BaseURL()};try{return await NB.default(t,a)}catch(d){if(r=d,((i=d==null?void 0:d.response)==null?void 0:i.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;o=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw g(ur,r,"no error"),r}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,r=(await this.request(e)).data.versions;return r.forEach(i=>{i.extra&&(i.extra=JSON.parse(i.extra))}),r}async getVersion(t){const o=`${this.apiServer()}/versions/${t}`,r=await this.request(o);return JSON.parse(r.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,o=await this.request(e);return JSON.parse(o.data.data)}async getVersionOps(t,e){let r=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(r+=`&from=${e}`);const i=await this.request(r),s=i.data.ops,l=$B.default(s,h=>!!h.create);let a=null;l!==-1&&(a=s[l],s.splice(0,l+1));let d;return a?(g(ur,a.create,"no createDoc.create"),d=a.create.data):d=JSON.parse(i.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:i.data.ops}}async updateVersionExtra(t,e,o){const i=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(i,{method:"post",data:{extra:JSON.stringify(o)}})}async revertVersion(t){const o=`${this.apiServer()}/versions/revert/${t}`;await this.request(o,{method:"post",data:{}})}async createVersion(t,e){const r=`${this.apiServer()}/versions`;return(await this.request(r,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const o=`${this.apiServer()}/resources/external/${Bs(t)}`;return(await this.request(o)).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 r=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const i=[];if(e!=null&&e.withToken&&i.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&i.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),i.length>0){const s=i.join("&");r+=`?${s}`}return r}}function QS(){return{blocks:[{id:K(),type:"text",text:[]}],comments:{},meta:{}}}const gp=S("block-ids");class YS{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((r,i)=>i-r);for(let r=0;r<e.length;r++){const i=e[r];if(i>=t){const s=this.ids.get(i);g(gp,s!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i+1,s)}}const o=K();this.ids.set(t,o)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((o,r)=>o-r);for(let o=0;o<e.length;o++){const r=e[o];if(r>t){const i=this.ids.get(r);g(gp,i!==void 0,"old id is not exists"),this.ids.delete(r),this.ids.set(r-1,i)}}}getId(t){let e=this.ids.get(t);return e||(e=K(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class JS{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new YS,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 o=0;o<e.length;o++){const r=e[o],i=r[1].getById(t);if(i)return{containerId:r[0],blockIndex:i[0]}}return g(gp,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class qb{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,o)=>{t[o]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const Wh=S("op-parse-handler");class KS{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const o={...t,containerId:(r=>r==="blocks"?"root":r)(t.containerId)};this.actions.push(o)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,o){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:o})}onDeleteBlockData(t,e,o){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:o})}onInsertBlockData(t,e,o,r){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:o,value:r})}onUpdateBlockText(t,e,o){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:o})}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,o=new Map,r=new JS,i=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of i)if(s.type==="deleteBlock"){const l=s,a=r.getBlockId(l.containerId,l.blockIndex);r.onDeleteBlock(l.containerId,l.blockIndex);const d=o.get(a);d&&(Wh.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),o.delete(a));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,a=`${l.containerId}-${l.blockIndex}`;if(e.has(a)){Wh.warn("delete block data after delete block, ignore it");continue}const d=r.getBlockId(l.containerId,l.blockIndex);let h=o.get(d);h||(h=new qb,o.set(d,h)),h.delete(l.key)}else g(Wh,!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,a=r.getBlockId(l.containerId,l.blockIndex);let d=o.get(a);d||(d=new qb,o.set(a,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(o.entries()).forEach(([s,l])=>{const{containerId:a,blockIndex:d}=r.getBlockIndexById(s);Wh.debug(`update block data: ${a}, ${d}, ${JSON.stringify(l.toDocBlockDelta())}`),this.outerHandler.onUpdateBlockData(a,d,l.toDocBlockDelta(),this.local)})}}const Re=S("op-parser");class Gb{}class pp{constructor(t){m(this,"key");this.key=t}}function XS(n,t,e){const o=t.concat(),r=o[0];if(typeof r!="number"||(o.shift(),o.length===1))return!1;const i=o[0];if(typeof i!="object"||!i.i||Object.keys(i).length!==1)return!1;for(let l=1;l<o.length;l++){const a=o[l];if(!Array.isArray(a)||a.length!==2||typeof a[0]!="string")return!1;const h=a[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=i.i;g(Re,s.id,"block id is required"),g(Re,s.type,"block type is required");for(let l=1;l<o.length;l++){const a=o[l],d=a[0],h=a[1];s[d]=h.i}return e.onInsertBlock(n,r,s),!0}function Cp(n,t,e,o){if(e==="upsert"&&XS(n,t,o))return;g(Re,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const r=t.concat(),i=r[0];r.shift();const s=[];for(;r.length>0;){const l=r[0];if(l==="text"){const a=r[1];if(g(Re,typeof a=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),g(Re,a.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),r.splice(0,2),e==="upsert"){const h=a.e;o.onUpdateBlockText(n,i,h)}g(Re,r.length===0,`invalid block ops.length !== 0, ${JSON.stringify(r)}`)}else if(Array.isArray(l)){g(Re,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const a=l[0];g(Re,typeof a=="string",`invalid block op: key ${JSON.stringify(a)}`);const d=l[1];if(a==="text"){if(g(Re,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&o.onInsertBlockData(n,i,a,d.i),d.r&&e==="remove"&&o.onDeleteBlockData(n,i,a),d.et==="rich-text"&&e==="upsert"){const p=d.e;o.onUpdateBlockText(n,i,p)}}else e==="remove"&&d.r&&s.push(new pp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i);r.shift()}else if(typeof l=="object"){const a=l;e==="remove"&&a.r&&s.push(new Gb),e==="upsert"&&a.i&&o.onInsertBlock(n,i,a.i),r.shift()}else{g(Re,typeof l=="string","data is not string"),g(Re,l!=="text","data !== 'text'"),g(Re,r.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(r)}`);const a=l,d=r[1];e==="remove"&&d.r&&s.push(new pp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i),r.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof Gb?o.onDeleteBlock(n,i):l instanceof pp?o.onDeleteBlockData(n,i,l.key):g(Re,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function tL(n,t,e){Re.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function eL(n,t,e){const o=n[1],r=n[2];g(Re,o,`invalid comment op, no commentId: ${JSON.stringify(n)}`),g(Re,r,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof r=="string"?Re.error(`unknown comment op, ${JSON.stringify(n)}`):r.i&&r.r?t==="upsert"&&e.onUpdateComment(o):r.i?t==="upsert"&&e.onCreateComment(o):r.r?t==="remove"&&e.onDeleteComment(o):Re.error(`unknown comment op, ${JSON.stringify(n)}`)}function Ap(n,t,e){const o=n[0];if(Array.isArray(o)){o.forEach(s=>{Ap(s,t,e)});return}const r=o;if(g(Re,typeof r=="string",`invalid container id: ${JSON.stringify(n)}`),r==="meta"){tL(n);return}if(r==="comments"){eL(n,t,e);return}const i=r;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{Cp(i,s,t,e)}):n.slice(1).forEach(s=>{Cp(i,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(i),s.i&&t==="upsert"&&e.onCreateContainer(i,s.i)}else g(Re,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),Cp(i,n.slice(1),t,e)}function Zb(n,t,e){const o=new KS(t,e);for(let r=0;r<2;r++){const i=r===0?"remove":"upsert",s=mt.default(n),l=s[0];Array.isArray(l)?s.forEach(a=>{Ap(a,i,o)}):Ap(s,i,o)}o.end()}const nL=S("sharedb-comments");function bp(n){const t=n.blocks;g(nL,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([o,r])=>{Array.isArray(r)&&(e.blocks[o]=r)}),mt.default(e)}function Qb(n){const{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}=n;return{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}}function vp(n,t){const e=HD(t),{comments:o,meta:r,blocks:i,...s}=e,l={...n,blocks:i,...s},a=mt.default(l);return delete a.children,a}const ae=S("sharedb-doc/doc-container"),Yb="ot-json1";_d.type.registerSubtype(jD.type),_d.type.name=Yb,_d.type.invert=null;class Ka extends fa{constructor(e,o,r=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new ND);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,e)})});m(this,"handleReset",async e=>{const o=new Error(`reset doc: ${e}`);o.code="ResetDoc",this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,o)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,o,r)=>{const i=[e,o,{i:r}];return this.submitOp(i)});m(this,"deleteObject",async(e,o)=>{const r=[e,o,{r:!0}];return this.submitOp(r)});m(this,"replaceObject",async(e,o,r)=>{const i=[e,o,{r:!0,i:r}];return this.submitOp(i)});m(this,"updateObject",async(e,o,r)=>{const i=this.data()[e][o],s=[e,o];return Object.entries(r).forEach(([l,a])=>{if(!ua.default(i[l],a))if(i[l]===void 0){if(a!=null){const d={i:a};s.push([l,d])}}else if(a==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:a};s.push([l,d])}}),Object.entries(i).forEach(([l,a])=>{if((r[l]===void 0||r[l]===null)&&a!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const o={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(o)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((o,r)=>{if(this.destroyed){ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},i=>{i?(ae.error(`invalid op, ${i.message}, ${JSON.stringify(e)}`),r(i),ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):o()}),this.doc.data||(ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((o,r)=>{this.doc.create(e,Yb,i=>{i?r(i):o()})}));m(this,"submitInsertChildContainer",async(e,o)=>{const r=[Ni(e),{i:o}];return this.submitOp(r)});m(this,"submitDeleteChildContainer",async e=>{const o=[Ni(e),{r:!0}];return this.submitOp(o)});m(this,"submitInsertBlock",async(e,o,r)=>{const i=[Ni(e),o,{i:r}];return this.submitOp(i)});m(this,"submitDeleteBlock",async(e,o)=>{const r=[Ni(e),o,{r:!0}];return this.submitOp(r)});m(this,"submitUpdateBlockData",async(e,o,r)=>{if(r.delete.length===0&&Object.keys(r.insert).length===0)return Promise.resolve();const i=[Ni(e),o],s=new Set(r.delete);Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a)){const h={r:!0,i:d};i.push([a,h])}});const l=new Set(Object.keys(r.insert));return r.delete.forEach(a=>{if(l.has(a))return;const d={r:!0};i.push([a,d])}),Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a))return;const h={i:d};i.push([a,h])}),this.submitOp(i)});m(this,"submitUpdateRichText",async(e,o,r)=>{const i=[Ni(e),o,"text",{e:r,et:"rich-text"}];return this.submitOp(i)});m(this,"handleOp",(e,o,r)=>{if(this.destroyed){ae.warn("handleOp: destroyed");return}Zb(e,this,!!o)});this.client=e,this.doc=o,this.doc.preventCompose=!0,this.disableLogout=r,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,g(ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const o=new ZS(e.auth,e.serverUrl,e.reauthFunc),r=await o.getDoc(),i=new Ka(o,r,e.disableLogout);if(r.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await i.createDoc(e.templateData||QS())}return await i.initPresence(),await i.subscribe(),i.initEvents(),i}catch(o){throw ae.error(o),ae.error(`failed to load doc: ${JSON.stringify(o)}`),o}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),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,o)=>{if(this.localPresence)e();else{const r=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);r.on("receive",(i,s)=>{this.onCustomMessage(s)}),r.subscribe(i=>{i?o(i):(this.localPresence=r.create(K()),e())})}})}subscribe(){return new Promise((e,o)=>{this.doc.subscribe(r=>{r?o(r):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return ja(this.data())}getContainerBlocks(e){const o=this.data();g(ae,o,"no doc data");const r=o[Ni(e)];return g(ae,r,`no container data: ${e}`),mt.default(r)}getBlockData(e,o){const r=this.data();g(ae,r,"no doc data");const i=r[Ni(e)];g(ae,i,`no container data: ${e}`);const s=i[o];return g(ae,s,`no block data: ${o}`),mt.default(s)}localInsertBlock(e,o,r){return this.submitInsertBlock(e,o,r),this.getBlockData(e,o)}localDeleteBlock(e,o){const r=this.getBlockData(e,o);return this.submitDeleteBlock(e,o),r}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(ae,i.text,"no block text");const s=mt.default(i.text);this.submitUpdateRichText(e,o,r);const l=ln.apply(s,r);return g(ae,l,"no block text"),l}localUpdateBlockData(e,o,r){const i=mt.default(this.getBlockData(e,o));return this.submitUpdateBlockData(e,o,r),i}localInsertChildContainer(e,o){this.submitInsertChildContainer(e,o)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(o=>{this.submitDeleteChildContainer(o)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(o=>Qb(o))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const o=this.data().comments[e];return bp(o)}localCreateComment(e,o){const r=vp(e,o),s=["comments",r.id,{i:r}];return this.submitOp(s)}localDeleteComment(e){const o=["comments",e,{r:!0}];return this.submitOp(o)}localUpdateComment(e,o){const r=vp(e,o),i=["comments",e.id,{r:!0,i:r}];return this.submitOp(i)}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,o,r){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var s;return(s=i.onDeleteBlock)==null?void 0:s.call(i,Xl(e),o,r)})}onInsertBlock(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Xl(e),o,r,i)})}onUpdateBlockData(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Xl(e),o,r,i)})}onUpdateBlockText(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Xl(e),o,r,i)})}onDeleteContainer(e,o){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,Xl(e),o)})}onCreateContainer(e,o,r){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,Xl(e),o,r)})}onDeleteComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteComment)==null?void 0:i.call(r,e,o)})}onCreateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onCreateComment)==null?void 0:i.call(r,e,o)})}onUpdateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onUpdateComment)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){const o=e;(o==null?void 0:o.type)==="custom"&&(o==null?void 0:o.clientId)!==this.client.clientId?this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,o.data)}):(o==null?void 0:o.type)==="onlineUsers"&&setTimeout(()=>{const r={type:"custom",data:e,clientId:"-"};this.onCustomMessage(r)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}async uploadResource(e,o){var i;return{resourceId:await this.client.uploadResource(e,(i=o==null?void 0:o.onProgress)!=null?i:()=>{})}}buildResourceUrl(e,o){return this.client.buildResourceUrl(e,o)}request(e,o){return this.client.request(e,o)}getUser(){const e=this.client.clientId,{permission:o,userId:r,displayName:i,avatarUrl:s}=this.client.auth;return{permission:o,clientId:e,userId:r,displayName:i,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const o=await this.client.getVersion(e);return ja(o)}async getLatestVersion(){const e=await this.client.getLatestVersion();return ja(e)}async getHistoryData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o),s=i.map(l=>({user:l.meta.createdBy,data:l}));return{doc:ja(r),historyData:s}}async getVersionData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o);return{doc:ja(r),versionData:i}}async updateVersionExtra(e,o,r){await this.client.updateVersionExtra(e,o,r)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,o){return this.client.createVersion(e,o)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,o){Zb(e.data.op,o,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}S("remote-cursor");class Jb{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",He.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const o=this.editor.findBlockById(e);o&&this.editor.reloadBlock(o)})});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 Kb=S("remote-cursor-decorator");class yp{decorateText(t,e,o){const r=t.doc.getRemoteUsers();if(!r)return{};const i=new Map,{containerId:s,blockIndex:l}=e[e.length-1];g(Kb,typeof s=="string","invalid path containerId"),g(Kb,typeof l=="number","invalid path blockIndex");const a=t.doc.getBlockData(s,l),d=rn(o);return r.getSimpleCursors(a.id).forEach((p,A)=>{A>d&&(A=d);const v=p.map(D=>({id:K(),type:"remote-cursor",name:D.user.displayName,time:D.time,rainbowIndex:D.user.rainbowIndex})),B=i.get(A);B?B.push(...v):i.set(A,v)}),{insertions:i}}}class Xb extends be.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,o){if(Xt(Nr(this.editor,t)))return;const r=this.editor.getBlockByIndex(t,e),i=ot(this.editor.getContainerById(t));i&&this.emit("change",this.editor,i,r,o)}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 oL(n,t){n.addCustom("child-block-tracker",()=>new Xb(n)).addListener("change",t)}function rL(n,t){n.addCustom("child-block-tracker",()=>new Xb(n)).removeListener("change",t)}const snt="",iL={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"}},sL={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},lL={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"}};R.mergeLang({"zh-CN":iL,"en-US":sL,"js-JP":lL});const lnt="";S("button");function ji(n,t,e,o,r){const i=w("button",["editor-button"],null);return i.setAttribute("data-button-id",n),r&&i.setAttribute(`data-editor-tooltip-${r}`,t),e?typeof e=="string"?e.startsWith("<")?i.innerHTML=e:i.innerText=e:i.appendChild(e):i.innerText=t,o&&(o.indexOf("checked")!==-1&&W(i,"checked"),o.indexOf("disabled")!==-1&&(i.disabled=!0)),i}function tv(n,t,e){e?n.setAttribute(`data-editor-tooltip-${e}`,t):n.innerText=t}const cnt="",nc=S("ui-command-bar-base"),cL={itemElementTag:"div",tippyArrow:!1},K2=class extends be.TypedEmitter{constructor(e,o,r){var i,s;super();m(this,"content");m(this,"items");m(this,"subBar",null);m(this,"parentItem",null);m(this,"closeable",null);m(this,"closeReason",null);m(this,"options");m(this,"id");m(this,"header",null);m(this,"footer",null);m(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing&&!Ls(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 o=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const o=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const o=this.getSelectedItem();o&&o.children&&this.showSubCommandBar(o.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const o=this.getSelectedItemIndex();if(o===-1)return;const r=this.items[o],i=this.getItemElementById(r.id);i&&this.emit("click",this,r,i)}}}});m(this,"handleDocumentMouseDown",e=>{if(e.target instanceof Element&&!this.isInCommandBar(e.target)){const o=this.listeners("closing");for(let r=0;r<o.length;r++)if(o[r](this,e)===!1)return;this.close("clickBackground")}});m(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),EC(this.id)});m(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&W(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&BC(this.id)});m(this,"lastEnterPauseTime",0);m(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});m(this,"handleItemMouseEnter",e=>{if(Date.now()-this.lastEnterPauseTime<100)return;const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.getItemById(r);if(this.selectItem(r),i.manualShowChildren)return;const s=i.childrenMenuId||"";this.showSubCommandBar(s)});m(this,"handleItemMouseLeave",e=>{var r,i;const o=this.getParentCommandItemElement(e.target);!o||((i=(r=this.subBar)==null?void 0:r.parentItem)==null?void 0:i.id)!==this.getItemElementId(o)&&(et(o,"selected"),this.emit("selectionChange",this,""))});m(this,"handleItemClick",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.items.find(s=>s.id===r);if(!!i&&!(i.states&&i.states.indexOf("disabled")!==-1)){if(i.children&&i.children.length>0&&i.manualShowChildren){this.showSubCommandBar(i.childrenMenuId);return}i.element||(this.emit("click",this,i,o),this.options.autoClose&&this.close("clickItem"))}});m(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const o=e.target;if(!o||!(o instanceof Node))return;const r=o instanceof HTMLElement?o:o.parentElement;if(!r)return;const i=oo(r);if(!Kt(this.content,i)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?i.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&i.scrollTop+i.clientHeight>=i.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(i=r==null?void 0:r.id)!=null?i:K(),this.options={...cL,...r},this.items=e,this.parentItem=(s=r==null?void 0:r.parentItem)!=null?s:null,this.closeable=o!=null?o: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,o){this.emit("click",this,e,o)}createPopperOptions(){var r,i;const e={modifiers:[]},o=this.options.overflowBoundary;return o&&((r=e==null?void 0:e.modifiers)==null||r.push({name:"flip",options:{boundary:o,fallbackPlacements:["top","bottom"]}})),this.options.padding&&((i=e==null?void 0:e.modifiers)==null||i.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 r;this.subBar&&e.findIndex(s=>{var l,a;return s.id===((a=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:a.id)})===-1&&((r=this.subBar)==null||r.destroy(),this.subBar=null),this.items=e;const o=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(o.children).forEach(i=>{this.content.appendChild(i)})}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 o=e-1;for(;;){const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o-=1,o<=0)return this.items.length-1}}getNextItemIndex(e){let o=e+1;for(;;){if(!this.items[o])return this.getNextItemIndex(-1);const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o+=1,o>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const o=this.getItemElementById(e.id);o&&et(o,"selected")}selectItem(e){const o=this.getSelectedItem();if(o){if(o.id===e)return;const i=o.id,s=this.getItemElementById(i);s&&et(s,"selected")}const r=this.getItemElementById(e);r?(W(r,"selected"),this.emit("selectionChange",this,r.getAttribute("data-id")||""),r.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const o=this.getSelectedItem();if(!o)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.id)===o.id){o.manualShowChildren&&this.subBar.close("switchItem");return}this.subBar.destroy(),this.subBar=null}if(!o.children)return;const r=this.getItemElementById(o.id);if(!r)return;const i=K2.createSubCommandBar(o,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=i,this.subBar.on("click",(a,d,h)=>{this.emit("click",a,d,h)}),this.subBar.on("close",()=>{var a;(a=this.subBar)==null||a.destroy(),this.subBar=null,et(r,"active")}),o.beforePopup&&o.beforePopup(i),this.subBar.manualShow(r,this.getSubBarOptions(o)),W(r,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const o=this.getCommandBarRoot();return o&&Kt(o,e)||Kt(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var i,s,l,a;let o=(i=this.options.itemElementTag)!=null?i:"div";e.element&&(o="div");const r=w(o,["command-item"],null);return r.setAttribute("data-id",e.id),e.type==="separator"?r.classList.add("separator"):e.type==="section"?(r.classList.add("section","text"),e.element&&(typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&r.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&r.classList.add("checked"),(a=e.states)!=null&&a.includes("disabled")&&r.classList.add("disabled"),r.onclick=this.handleItemClick,r.onmouseenter=this.handleItemMouseEnter,r.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element):r.classList.add("standard")),this.initItemElement(e,r),r}getItemById(e){const o=this.items.find(r=>r.id===e);return g(nc,o,`can not find command item for id: ${e}`),o}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const o=this.getItemElementId(e),r=this.items.find(i=>i.id===o);return g(nc,r,`can not find command item for id: ${o}`),r}return null}getItemElementId(e){const o=e.getAttribute("data-id");return g(nc,o,"no data-id attribute"),o}getItemElementById(e){const o=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return g(nc,o,`no exists command item, id=${e}`),o}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(xt(e,"command-item"))return e;const o=e.closest(".command-item");return o||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const o=w("div",["editor-command-bar-root"],null);if(this.options.header){const i=w("div",["editor-command-bar-header"],null);if(this.options.header instanceof Function){const s=this.options.header();s&&i.appendChild(s)}else i.appendChild(this.options.header);this.header=i,this.header&&o.appendChild(this.header)}const r=w("div",["editor-command-bar"],o);if(e.forEach(i=>{var l;const s=this.createCommandItem(i);r.appendChild(s),i.element&&i.setCloseable&&i.setCloseable((l=this.closeable)!=null?l:this)}),this.options.footer){const i=w("div",["menu-item","editor-command-bar","footer"],null);if(this.options.footer instanceof Function){const s=this.options.footer();s&&i.appendChild(s)}else i.appendChild(this.options.footer);this.footer=i,this.footer&&o.appendChild(this.footer)}return(this.options.header||this.options.footer)&&W(o,"scrollable-bar"),this.initCommandBarElement(r),o.addEventListener("wheel",this.handleWheel,{passive:!1}),o}getSubBarOptions(e){var o;return{placement:(o=e.childrenPlacement)!=null?o:"right-start"}}static registerManualCommandBar(e,o){this.commandBarCreators.set(e,o)}static createSubCommandBar(e,o,r){var l;g(nc,e.children&&e.children.length>0,"no item children");const i=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(i);return g(nc,s,`no creator for command type: ${i}`),s(e,o,r)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let Ui=K2;m(Ui,"commandBarCreators",new Map),S("ui-command-bar");class qh extends Ui{constructor(){super(...arguments);m(this,"tippyInstance",null)}manualShow(e,o){var r,i;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=UB.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(r=o==null?void 0:o.placement)!=null?r:"bottom-start",maxWidth:650,arrow:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:o==null?void 0:o.theme,getReferenceClientRect:o==null?void 0:o.getReferenceClientRect,offset:(i=o==null?void 0:o.offset)!=null?i:[0,0],popperOptions:this.createPopperOptions()}),o!=null&&o.point){const{x:s,y:l}=o.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(s,l,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 o;super.close(e),this.isVisible&&((o=this.tippyInstance)==null||o.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,o;return(o=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?o:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const ev=S("ui-base");class Xa extends qh{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${K()}`,name:"",element:t}];super(r,void 0,{disablePageScroll:!0})}initCommandBarElement(t){W(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];g(ev,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return g(ev,e,"no item element"),e}}const zi=S("filterable-list");function nv(n){var e,o;const t=w("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(w("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&W(t,"selected"),(o=n.states)!=null&&o.includes("disabled")&&W(t,"disabled"),t}function ov(n){const t=w("div",["list-root"],null);return n.forEach(e=>{t.appendChild(nv(e))}),n.length||t.appendChild(nv({id:"placeholder",states:["disabled"],name:R.t("search.emptyTips")})),t}function rv(n,t){let e=n;return t&&(e=n.map(o=>({...o,states:o.id===t?["selected"]:void 0}))),e}function aL(n,t){const e=w("div",["filterable-list"],null),o=w("div",["filter"],e),r=w("div",["filter-container"],o),i=w("input",["filter-input"],r);t&&t.placeholder&&(i.placeholder=t.placeholder);const s=w("div",["list"],e),l=ov(rv(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function iv(n,t,e){const o=n.querySelector(".list");g(zi,o,"no list root");const r=ov(rv(t,e)),i=o.querySelector(".list-root");if(g(zi,i,"no exists menu"),Ca(i,r),e){const s=o.querySelector(".list-item.selected");s&&(g(zi,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class uL{constructor(t,e){m(this,"root");m(this,"visibleItems");m(this,"selectedId");m(this,"filter","");m(this,"onSelected",null);m(this,"handleKeydown",t=>{this.processKeyDown(t)});m(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");g(zi,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});m(this,"handleClick",t=>{this.processClick(t)});var o;this.items=t,this.options=e,this.root=aL(t,e),this.bindEvents(),this.selectedId=(o=e==null?void 0:e.initialSelectedId)!=null?o:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");g(zi,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");g(zi,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,iv(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");g(zi,t,"no input"),t.focus()}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");g(zi,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),iv(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const o=e.closest(".list-item");if(!o)return;const r=(s=o.getAttribute("data-id"))!=null?s:"",i=(l=this.visibleItems.find(a=>a.id===r))!=null?l:null;this.onSelected&&this.onSelected(this,i)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let o=this.getSelectedIndex();o===-1?o=this.visibleItems.length-1:o>0&&(o-=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="ArrowDown"){let o=this.getSelectedIndex();o===-1?o=0:o<this.visibleItems.length-1&&(o+=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="Enter"){const o=(e=this.visibleItems.find(r=>r.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,o)}}}class dL extends uL{constructor(e,o,r){super(e,r);m(this,"popup");m(this,"onShow",null);m(this,"onHide",null);m(this,"custom",null);m(this,"handleShow",()=>{this.onShow&&this.onShow(this)});m(this,"handleHide",()=>{this.onHide&&this.onHide(this)});m(this,"handleShown",()=>{this.focus()});this.popup=new Xa(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close("cancelBar")}processClick(e){super.processClick(e);const o=e.target;!(o instanceof HTMLElement)||!o.closest(".list-item")||this.popup.close("clickItem")}}const ant="",unt="";function hL(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)}const sv=`<?xml version="1.0" ?>
|
|
27
|
+
`)}const eT=S("get-text-position");function Gl(n,t){const e=t!=null?t:n.selection.range.start;e instanceof je||g(eT,!1,`invalid insert pos type: ${typeof e}`);const{blockId:o}=e,r=n.getBlockById(o),i=bt(r),s=nt(r),l=at(s),{offset:a}=e;return{block:r,container:s,containerId:l,blockIndex:i,offset:a}}const Zl=S("insert-text");function Dg(n,t,e,o){var s;const r=n.doc.getBlockData(t,e);if(g(Zl,r,"no block data"),g(Zl,r.text,"no block text"),rn(r.text)===0)return g(Zl,o===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,r.id);if(o===0)return;const i=ze(r.text,o-1,1).middle;if(!((s=i[0].attributes)!=null&&s.box))return i[0].attributes}function nT(n,t,e){const o=nt(t),r=at(o),i=bt(t);return Dg(n,r,i,e)}function R6(n,t,e,o,r){const i=nt(t),s=at(i),l=bt(t),a=nT(n,t,e),d=ch(e,o,a!=null?a:null);return n.doc.localUpdateBlockText(s,l,d,r),mn(n,t)}function O6(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=ch(e," ",o);return n.doc.localUpdateBlockText(i,s,l),mn(n,t)}function oT(n,t){let e=0;if(t===0)return!1;for(let o=0;o<n.length;o++){const r=n[o];g(Zl,typeof r.insert=="string","invalid text op, no insert");const i=e+ah(r);if(i===t)return!1;if(i>t)return!0;e=i}return!1}function Sg(n,t,e,o,r){const i=n.doc.getBlockData(e,o);g(Zl,i,"no block data"),g(Zl,i.text,"no block text");const s=Dg(n,e,o,r);s&&Object.keys(s).includes("link")&&(oT(i.text,r)||delete s.link);const l=ch(r,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,o,l),mn(n,n.getBlockById(i.id))}function Lg(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:o,offset:r}=Gl(n);Sg(n,t,e,o,r)}const vh=S("update-composition-text");function _6(n){const t=n.selection.range.start;t instanceof je||g(vh,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,o=n.getBlockById(e);g(vh,tt(n,o),"not a text kind block");const r=nt(o),i=at(r),s=bt(o),l=n.doc.getBlockData(i,s);g(vh,l,"no block data in doc"),g(vh,l.text,"no text data in text block");const a=Rt(o);rh(n,Di(o),e,a,l.text)}function F6(n){_x(n)}function Ql(n,t,e,o,r,i){return n.doc.localInsertBlock(t,e,o,r,i),n.getBlockById(o.id)}const Ra=S("delete-block-text");function Mg(n,t,e,o,r){if(!n.isBlockWritable(t))return Ra.error("block is not writable"),0;g(Ra,tt(n,t),"block is not a text kind block");const i=nt(t),s=at(i),l=bt(t),a=n.doc.getBlockData(s,l);g(Ra,a,"no block data in doc"),g(Ra,a.text,"no text data in text block");let d=e;sn(t,e)||(d=Ri(t,d));let h=e+o;g(Ra,h<=ut(n,t),`invalid offset and count: ${e}, ${o}`),sn(t,h)||(h=Fs(t,h));const p=h-d,A=W4(d,p);return n.doc.localUpdateBlockText(s,l,A,r),p}const Rg=S("break-text-block");function P6(n,t){const o=n.getBlockData(t).quoted;return o?{quoted:o}:{}}function Yl(n,t,e,o){g(Rg,tt(n,t),`block is not a text kind block: ${Dt(t)}`),g(Rg,e>=0&&e<=ut(n,t),`invalid offset: ${e}`);const r=nt(t),i=at(r),s=bt(t),l=o!=null&&o.copyBlockAttributes?P6(n,t):{};if(!(o!=null&&o.forceInsertAfter)&&(e===0||e===ut(n,t))){const v=e===0?s:s+1,B={...sr(""),...l,...o==null?void 0:o.newBlockData},D=ye(n,t.id,0),T=Ql(n,i,v,B,D);return{block:t,newBlock:T}}g(Rg,sn(t,e),"not a valid offset");const a=mn(n,t),{right:d}=xn(a,e),h=rn(d);h>0&&Mg(n,t,e,h);const p={...sr(d),...l,...o==null?void 0:o.newBlockData},A=Ql(n,i,s+1,p,ye(n,p.id,0));return{block:t,newBlock:A}}const rT=S("prepare-insert-new-block");function iT(n,t,e){if(t&&e!==void 0&&e!==null){const d=n.getContainerById(t),h=ve(d);return g(rT,e>=0&&e<=h.length,`invalid blockIndex: ${e}`),{containerId:t,blockIndex:e}}const o=n.selection.range.start;if(!o.isSimple())return null;const r=n.getBlockById(o.blockId);if(t=at(nt(r)),e=bt(r),!tt(n,r))return{containerId:t,blockIndex:e+1};const s=o.offset;if(s===0||s===ut(n,r))return{containerId:t,blockIndex:s===0?e:e+1};const a=Yl(n,r,s).newBlock;return{containerId:t,blockIndex:bt(a)}}const sT=S("auto-insert-block");function N6(n,t,e,o,r,i){const s=iT(n,e,o);g(sT,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},a={anchor:l,focus:l};return Ql(n,s.containerId,s.blockIndex,t,r!=null?r:a,i)}const lT=S("delete-block");function yh(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(o=>{n.getChildContainerData(o).forEach(i=>{yh(n,i,e)})}))}function kh(n,t,e){const o=nt(t),r=at(o),i=bt(t),s=n.doc.getBlockData(r,i);return g(lT,s,"no block data in doc"),n.doc.localDeleteBlock(r,i,Ue(n,{anchor:e.start,focus:e.end})),s}function Og(n,t,e){return n.undoManager.runInGroup(()=>{const o=nt(t);Eo(o)===1&&n.insertTextBlock("",at(o),0);let r=e?Si(n,e):null;if(!r){const l=n.selection.range;D6(t,l)?r=S6(n,t):r=l}const i=kh(n,t,r),s=[];return yh(n,i,s),s.length>0&&n.doc.localDeleteChildContainers(s),i})}function cT(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(r=>{yh(n,r,e)}),n.doc.localDeleteChildContainers(e)}function $6(n,t){const e=[...t];t.forEach(o=>{n.doc.getContainerBlocks(o).forEach(i=>{yh(n,i,e)})}),n.doc.localDeleteChildContainers(e)}const _g=S("merge-text-block");function H6(n,t,e){g(_g,tt(n,t),"only text block can be merged"),g(_g,tt(n,e),"only text block can be merged");const o=_i(n,t),r=_i(n,e),i=o.text,s=r.text;g(_g,i&&s,"block data has no text");const l=nt(t),a=at(l),d=bt(t),h=ut(n,t),p=Sg(n,s,a,d,h),A=ye(n,t,rn(i));return Og(n,e,A),p}const lr=S("clear-selected-contents");function wh(n,t){g(lr,tt(n,t.block),"not a text kind block");const{start:e,end:o}=t;g(lr,e.isSimple(),"not a simple block position"),g(lr,o.isSimple(),"not a simple block position");const r=e.offset,i=o.offset;g(lr,r<=i,`invalid delete text offset: ${r}, ${i}`),r!==i&&n.deleteTextFromBlock(t.block,r,i-r)}function j6(n,t,e){const o=at(t),r=ve(t),i=e.focus?void 0:n.selection.range.toDocRange(),s=n.insertTextBlock("",o,0,{newRange:i});e.focus&&n.selection.selectBlock(s,0),r.reverse().forEach(l=>{n.deleteBlock(l)})}function aT(n,t){const{block:e,start:o,end:r}=t;if(tt(n,e)){wh(n,t);return}if(Le(e)||o.isSimple()){g(lr,r.isSimple(),"invalid range");const s=nt(e),l=bt(e),a=n.insertTextBlock("",at(s),l);n.selection.selectBlock(a,0),n.deleteBlock(e);return}g(lr,Lt(n,e),"invalid block kind"),g(lr,!o.isSimple()&&!r.isSimple(),"invalid range"),Os(n,e,o,r),n.selection.range.getSelectedContainers().forEach((s,l)=>{j6(n,s,{focus:l===0})})}function uT(n){if(!n.isWritable())return;const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(g(lr,e.length>0,"no selected block"),e.length===1){aT(n,e[0]);return}const o=e[0],r=o.block,i=nt(r);g(lr,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(tt(n,r)){wh(n,o);const h=ye(n,o.block,o.start.offset);if(e.slice(1,e.length-1).reverse().forEach(A=>n.deleteBlock(A.block)),tt(n,l)){wh(n,s),n.mergeTextBlock(r,l,{focus:!0}),n.selection.setRange(h);return}n.deleteBlock(l),n.selection.setRange(h);return}if(tt(n,l)){wh(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===Eo(i)){j6(n,i,{focus:!0});return}const a=ce(r),d=Zt(l);g(lr,a||d,"no prev or next block"),e.forEach(h=>n.deleteBlock(h.block))}function Fg(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),uT(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}const dT=S("core");function U6(n,t,e){const o=nt(t),r=at(o),i=bt(t);return n.doc.localUpdateBlockText(r,i,e),setTimeout(()=>{n.selection.updateSelection(null)}),mn(n,t)}function z6(n,t,e){if(!n.isBlockWritable(t)){dT.error("block is not writable");return}const o=n.getBlockText(t),r=ln.diff(o,e);U6(n,t,r)}function Bh(n,t,e){const o=mn(n,t),r=typeof e=="string"?Oi(e):e,i=ln.diff(o,r);return U6(n,t,i)}const Oa=S("update-block-data");function Eh(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=n.doc.getBlockData(i,s),a={insert:{},delete:[]},d=new Set(Object.keys(l)),h=new Set(Object.keys(e));return d.forEach(A=>{if(!h.has(A)){if(A==="id"||A==="type"||A==="text")return;Oa.debug(`delete key: ${A}`),a.delete.push(A)}}),Object.entries(e).forEach(([A,v])=>{g(Oa,A!=="id"&&A!=="type",`invalid block data delta, ${A}`);const B=l[A];if(v==null){B!=null&&(Oa.debug(`delete key: ${A}`),a.delete.push(A));return}B!==v&&(ua.default(B,v)||A==="text"&&ln.diff(B,v).length===0||(d.has(A)?(Oa.debug(`replace key: ${A}`),a.delete.push(A)):Oa.debug(`insert key: ${A}`),a.insert[A]=v))}),n.doc.localUpdateBlockData(i,s,a,o),_i(n,t)}function V6(n,t,e,o){const i={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,i,o)}function Pg(n,t,e){if(!Lt(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const r=jn(n,t).getChildContainers(n,t)[0],i=Se(r);Pg(n,i,e)}function $s(n){const t=[];let e={};return n.forEach(o=>{t.push(...o.blocks.root);const{root:r,...i}=o.blocks;e={...e,...i}}),{blocks:{...e,root:t},meta:{},comments:{}}}const _a=S("clone-block");function Fi(n,t,e,o){const r=n.getBlockClass(e.type);if(r.blockToDoc)return r.blockToDoc(t,e,(h,p)=>(g(_a,e!==p,"invalid child block"),Fi(n,h,e,o)));let i={};const s=new Map,l=mt.default(e);l.children&&(l.children=l.children.map(h=>{const p=K(),A=t.blocks[h];g(_a,Array.isArray(A),"invalid child blocks");const v=A.map(_=>Fi(n,t,_,o)),B=$s(v),{root:D,...T}=B.blocks;return i={...i,...T},i[p]=B.blocks.root,s.set(h,p),p}));const a=Array.from(s.entries()),d=h=>{for(const p of a){const[A,v]=p;{const B=`${A}/`;if(h.startsWith(B)){const D=h.substring(B.length),T=`${v}/${D}`;return _a.debug(`replace key: ${h} -> ${T}`),T}}{const B=`${A}_`;if(h.startsWith(B)){const D=h.substring(B.length),T=`${v}_${D}`;return _a.debug(`replace key: ${h} -> ${T}`),T}}}return h};return Array.from(Object.entries(l)).forEach(([h,p])=>{const A=d(h);A!==h&&delete l.key,l[A]=p}),l.id=K(),o&&(o.blockIdMap.set(e.id,l.id),s.forEach((h,p)=>o.containerIdMap.set(p,h))),{blocks:{root:[l],...i},meta:{},comments:{}}}function Ng(n,t,e,o){const r=t.blocks[e];g(_a,Array.isArray(r),"invalid child blocks");const i=r.map(l=>Fi(n,t,l,o));return $s(i)}function $g(n,t,e){const o=t.blocks.root.map(r=>Fi(n.editorBlocks,t,r,e));return mt.default($s(o))}const W6=S("insert-doc");function q6(n,t,e,o,r){if(Lt(n,t)){W6.warn("failed to insert doc into a complex block");return}const i=$g(n,o,r),s=nt(t),l=bt(t),a=at(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var M,H,z;Object.entries(i.blocks).forEach(([q,rt])=>{q!=="root"&&n.doc.localInsertChildContainer(q,rt)});const d=i.blocks.root;if(Le(t)){n.deleteBlock(t);let q;d.reverse().forEach(rt=>{const ft=n.insertBlock(a,l,rt);q||(q=ft)}),q&&n.selection.selectBlock(q,ut(n,q));return}if(g(W6,tt(n,t),"not a text block"),he(n,t)){const q=a==="root"&&n.getBlockByIndex(a,0)===t,rt=bt(t);let ft;d.forEach((Bt,jt)=>{const Ut=n.insertBlock(a,rt+jt,Bt);jt===d.length-1&&(ft=Ut)}),ft&&n.selection.selectBlock(ft,ut(n,ft)),q&&n.deleteBlock(t);return}if(d.length===1){const q=d[0];if(ya(n,q.type)){n.insertTextToBlock(t,e,(M=q.text)!=null?M:[]);return}n.breakTextBlock(t,e),n.insertBlock(a,l+1,q);return}const h=e===ut(n,t),p=e===0,A=d[0],v=d[d.length-1];let B;!h&&!p?B=n.breakTextBlock(t,e,{forceInsertAfter:!0}):B=t;const D=p?l:l+1;h?(B=n.insertBlock(a,l+1,v),n.selection.selectBlock(B,ut(n,B))):(n.selection.selectBlock(B,0),ya(n,v.type)?n.insertTextToBlock(B,0,(H=v.text)!=null?H:[]):n.insertBlock(a,D,v));const T=n.selection.range;let _=D;ya(n,A.type)?p?(n.insertBlock(a,D,A),_+=1):n.insertTextToBlock(t,e,(z=A.text)!=null?z:[]):(n.insertBlock(a,D,A),_+=1),d.slice(1,d.length-1).reverse().forEach(q=>{n.insertBlock(a,_,q)}),n.selection.setRange(T)}),n.doc.endBatchUpdate()}function Hg(n,t,e,o,r){const i=$g(n,o,r),s=at(t),l=[];return n.undoManager.runInGroup(()=>{Object.entries(i.blocks).forEach(([d,h])=>{d!=="root"&&n.doc.localInsertChildContainer(d,h)}),i.blocks.root.reverse().forEach(d=>{const h=n.insertBlock(s,e,d);l.push(h)})}),l}function G6(n,t,e){const o=Eo(t);Hg(n,t,o,e);for(let r=0;r<o;r++){const i=Se(t);n.deleteBlock(i)}}const Fa=S("add-text-attribute");function hT(n,t,e,o){const{start:r,end:i}=e;g(Fa,r.blockId===i.blockId&&r.blockId===it(t),"invalid range"),g(Fa,o,"invalid attribute name");const s=n.getBlockText(t),l=ql(r.offset,i.offset-r.offset,s,o,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function Z6(n,t,e,o,r){const{start:i,end:s}=e;g(Fa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(Fa,o,"invalid attribute name");const l=n.getBlockText(t),a=Ia(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function Jl(n,t,e,o,r){const{start:i,end:s}=e;g(Fa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range");const l=n.getBlockText(t),a=e6(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function Q6(n,t,e,o){const r=Lo(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:s,start:l,end:a}=i;if(!tt(n,s))return;if(he(n,s)){o(n,it(s),t,e);return}const d=Ue(n,{anchor:l,focus:a});t==="color"||t==="backgroundColor"?Jl(n,s,d,t,e):(Jl(n,s,d,"color",null),Jl(n,s,d,"backgroundColor",null))})})}function Y6(n,t,e){const o=Lo(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{o.forEach(r=>{const{block:i,start:s,end:l}=r;if(!tt(n,i))return;if(he(n,i)){(t==="clearColor"||t==="clearAll")&&e(n,it(i),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,it(i),"backgroundColor",null);return}const a=Ue(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Jl(n,i,a,"color",null),(t==="clearBackground"||t==="clearAll")&&Jl(n,i,a,"backgroundColor",null)})})}function jg(n,t){const e=Lo(n,{simpleBlockOnly:!0}).filter(s=>tt(n,s.block));if(e.length===0)return[null,null];const o=s=>{if(ut(n,s.block)===0)return t(n,it(s.block));const l=s.start,a=s.end,d=n.getBlockText(s.block);return r6(l.offset,a.offset-l.offset,d)};let[r,i]=o(e[0]);return r===null&&i===null?[r,i]:(e.forEach(s=>{const[l,a]=o(s);l===null||r===null?r=null:r=l===r?r:null,a===null||i===null?i=null:i=a===i?i:null}),[r,i])}const Vn=S("adjust-selection-pos");function J6(n){const t=[];for(;n;){const e=nt(n);if(t.unshift(e),Xt(e))return t;const o=ot(e);g(Vn,o,"child container has not parent container"),n=o}g(Vn,!1,"should not come here: getParentContainers")}function K6(n,t){for(;t;){const e=nt(t);if(e===n)return t;const o=ot(e);g(Vn,o,"could not find parent block for a child container"),t=o}g(Vn,!1,"no parent block in specified container")}function fT(n,t){const e=J6(n),o=J6(t);g(Vn,e.length>0&&o.length>0,"block has not parent container"),g(Vn,e[0]===o[0],"root container does not equal");let r=e[0];for(let l=1;l<e.length||o.length;l++)if(e[l]!==o[l]){r=e[l-1];break}const i=K6(r,n),s=K6(r,t);return{parentContainer:r,newBlock1:i,newBlock2:s}}function X6(n,t){let e=ot(t);for(g(Vn,e,"element is not in a block");e;){const o=nt(e);g(Vn,Do(o),"not a child container");const r=ot(o);if(g(Vn,r,"child container has not parent block"),r===n)return o;e=r}g(Vn,!1,"failed to find parent container in complex block")}function xh(n,t,e){const o=n.getBlockById(t.blockId),r=n.getBlockById(e.blockId);if(o===r)return t instanceof je&&e instanceof je?{anchor:t,focus:e}:t instanceof So&&e instanceof So?nh(n,o,t,e):null;const i=nt(o),s=nt(r);if(i===s)return t instanceof So&&(t=st(o,0,"home")),e instanceof So&&(e=st(r,ut(n,r),"end")),g(Vn,t instanceof je,"not valid position type"),g(Vn,e instanceof je,"not valid position type"),{anchor:t,focus:e};if(o.contains(s))return null;if(r.contains(i)){if(t instanceof je&&e instanceof So){const B=n.getContainerById(e.childContainerId);if(B===i)return{anchor:e,focus:e};const D=ot(i);if(D&&D===ot(B)){const T=fe(D,at(i)),_=fe(D,at(B));return nh(n,D,T,_)}}return null}const l=Hd(o,r)>0,{newBlock1:a,newBlock2:d}=fT(o,r);if(a===d){const B=a,D=X6(B,o),T=X6(B,r);return t=fe(a,at(D)),e=fe(a,at(T)),Vn.debug(`select in complex block: ${D.id}, ${T.id}`),nh(n,B,t,e)}let h=l?ut(n,a):0;a===o&&t instanceof je&&(h=t.offset);let A=l?0:ut(n,d);return d===r&&e instanceof je&&(A=e.offset),t=st(a,h,l?"end":"home"),e=st(d,A,l?"home":"end"),{anchor:t,focus:e}}const mT=S("move-complex-block-position");function gT(n,t,e){const o=n.getBlockById(t.blockId);g(mT,Lt(n,o),"is not a complex block");const r=jn(n,o),i=n.getContainerById(t.childContainerId),s=r.getNextContainer(n,o,i,e,{noWrap:!0});return s?fe(o,at(s)):null}const Pa=S("move-simple-block-position");function tA(n,t){const e=En(n,t,{visibleOnly:!0});g(Pa,e.length>0,"complex block has not any child container");const o=e[0];return Se(o)}function eA(n,t){const e=En(n,t,{visibleOnly:!0});g(Pa,e.length>0,"complex block has not any child container");const o=e[e.length-1];return Ge(o)}function nA(n,t,e){const o=e?tA(n,t):eA(n,t);return Lt(n,o)?nA(n,o,e):o}function pT(n,t){const e=n.getBlockById(t.blockId);return Lt(n,e)&&t.offset===0?tA(n,e):Ss(e)}function CT(n,t){const e=n.getBlockById(t.blockId);return Lt(n,e)&&t.offset===1?eA(n,e):Ds(e)}function Ug(n){return n==="ArrowLeft"||n==="ArrowUp"}function zg(n,t,e){const o=nt(t);if(Xt(o))return null;const r=ot(o);g(Pa,r,"child container has not parent block"),g(Pa,Lt(n,r),"is not a complex block");const i=jn(n,r).getNextContainer(n,r,o,e);return i?Ug(e)?Ge(i):Se(i):zg(n,r,e)}function AT(n,t,e){const o=nt(t);if(Xt(o))return null;const r=ot(o);if(g(Pa,r,"child container has not parent block"),Ug(e)){const l=ce(r);if(l)return l}else{const l=Zt(r);if(l)return l}const i=zg(n,r,e);if(i)return i;let s=r;for(;!Xt(nt(s));)s=ot(nt(s));return Ug(e)?ce(s):Zt(s)}function bT(n,t,e){return!Lt(n,t)||jn(n,t).enableKeyboardSelect?t:nA(n,t,e==="ArrowDown"||e==="ArrowRight")}function vT(n,t,e){const o=n.getBlockById(t.blockId),i=Qt(n,o).moveCaret(n,o,t,e);if(i)return i;let s=e==="ArrowDown"||e==="ArrowRight"?pT(n,t):CT(n,t);if(s||(s=zg(n,o,e),s||(s=AT(n,o,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!Xt(nt(o)))return null;const l=n.insertTextBlock("",at(n.rootContainer),Eo(n.rootContainer));return st(l,0,"home")}return null}if(s=bT(n,s,e),tt(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return Gx(n,s,o,t,l);if(e==="ArrowUp")return qx(n,s,o,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?st(s,ut(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?st(s,0,"home"):null}function yT(n,t,e){if(t==="ArrowLeft")return e.start;const o=e.end,r=n.getBlockById(o.blockId);if(tt(n,r))return o;const i=Zt(r);if(i)return st(i,0,"home");if(!Xt(nt(r))||n.readonly)return o;const s=n.insertTextBlock("",at(n.rootContainer),Eo(n.rootContainer));return st(s,0,"home")}function kT(n,t,e){const o=n.selection.range;let r;if(o instanceof Ze)e==="move"&&!o.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?r=yT(n,t,o):r=vT(n,o.getFocusedPos(),t);else if(r=gT(n,o.focus,t),e==="move"){const i=r!=null?r:o.focus,s=n.getContainerById(i.childContainerId);if(t==="ArrowLeft"||t==="ArrowUp"){const l=Ge(s);r=st(l,0,"home")}else{const l=Se(s);r=st(l,ut(n,l),"end")}}return r?e==="move"?{anchor:r,focus:r}:xh(n,o.anchor,r):null}function Pi(n,t,e){const o=kT(n,t,e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),(t==="ArrowLeft"||t==="ArrowRight")&&n.selection.updateLastCaretRect(),!0}function oA(n){return Pi(n,"ArrowLeft","move"),!0}function rA(n){return Pi(n,"ArrowRight","move"),!0}function iA(n){return Pi(n,"ArrowUp","move"),!0}function sA(n){if(Pi(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=nt(t);if(Xt(e)||Ge(e)!==t)return!0;const o=n.rootContainer;return n.insertTextBlock("",at(o),Eo(o)),!0}function lA(n){return Pi(n,"ArrowDown","select"),!0}function cA(n){return Pi(n,"ArrowLeft","select"),!0}function aA(n){return Pi(n,"ArrowRight","select"),!0}function uA(n){return Pi(n,"ArrowUp","select"),!0}const dA=S("word-offset");function Vg(n,t){const e=n.selection.range.focus;g(dA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"home");if(e.offset===0||!tt(n,o)){const s=ce(o);if(!s)return null;const l=st(s,ut(n,s),"end");if(t==="select"&&tt(n,s)){const a=yg(n,s,l.offset);return st(s,a,"normal")}return l}const r=yg(n,o,e.offset);return st(o,r,"normal")}function Wg(n,t){const e=n.selection.range.focus;g(dA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"end");if(e.offset===ut(n,o)||!tt(n,o)){const s=Zt(o);if(!s)return null;const l=st(s,0,"home");if(t==="select"&&tt(n,s)){const a=kg(n,s,l.offset);return st(s,a,"end")}return l}const r=kg(n,o,e.offset);return st(o,r,"normal")}function hA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Vg(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function fA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Wg(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function mA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Vg(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function gA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Wg(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}S("find-block");function qg(n,t){if(!Lt(n,t))return t;const o=jn(n,t).getChildContainers(n,t)[0],i=ve(o)[0];return qg(n,i)}function Gg(n,t){if(!Lt(n,t))return t;const e=jn(n,t).getChildContainers(n,t),o=e[e.length-1],r=ve(o),i=r[r.length-1];return Gg(n,i)}function pA(n){const t=Gg(n,Ge(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(e),!0}function CA(n){const t=qg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(e),!0}function AA(n){const t=qg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function Zg(n){const t=Gg(n,Ge(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const bA=S("line-offset");function vA(n){const t=n.selection.range.focus;g(bA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!tt(n,e))return st(e,0,"home");let r=H4(e,t).start;const{next:i}=Xd(e,r);return i&&io(i)&&va(i)==="br"&&(r+=1),st(e,r,"home")}function yA(n){const t=n.selection.range.focus;g(bA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===ut(n,e)||!tt(n,e))return st(e,ut(n,e),"end");const o=H4(e,t);return st(e,o.end,"end")}function kA(n){if(!n.selection.range.focus.isSimple())return!1;const e=vA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function wA(n){if(!n.selection.range.focus.isSimple())return!1;const e=yA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function BA(n){if(!n.selection.range.focus.isSimple())return!1;const e=vA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function EA(n){if(!n.selection.range.focus.isSimple())return!1;const e=yA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const xA=S("find-block-position");function wT(n,t,e,o){g(xA,Lt(n,t),"is not a complex block");const r=jn(n,t).getChildContainers(n,t);g(xA,r.length>0,"complex block has not any child container");const i=To(n,e,o),s=i.left+i.width/2,l=i.top+i.height/2,a=D4(n,t,s,l);return Qg(n,a,e,o)}function Qg(n,t,e,o){if(Lt(n,t))return wT(n,t,e,o);const r=it(t);let i=Number.MAX_SAFE_INTEGER;const s=To(n,e,o),l=s.left+s.width/2,a=s.top+s.height/2;let d=st(r,0,"home");const h=ut(n,t);for(let p=0;p<=h;p++){const A=st(r,p,"normal"),v=To(n,t,A),B=er(v,l,a);B<i&&(i=B,d=A)}return d}const IA=S("page-offset");function BT(n,t){const e=x6(n)*.9,r=t.getBoundingClientRect().bottom-e;if(r<GI(n))return n.getFirstBlock();const i=ce(t);if(!i)return n.getFirstBlock();let s=i;for(;s;){if(s.getBoundingClientRect().y<r)return s;s=ce(s)}return n.getFirstBlock()}function ET(n,t){const e=x6(n)*.9,o=t.getBoundingClientRect(),r=ZI(n),i=o.top+e;if(i>r)return n.getLastBlock();const s=Zt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>i)return l;l=Zt(l)}return n.getLastBlock()}function TA(n){const t=n.selection.range.focus;g(IA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=BT(n,e);let r;return o===n.getFirstBlock()?r=st(o,0,"home"):r=Qg(n,o,e,t),r}function DA(n){const t=n.selection.range.focus;g(IA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=ET(n,e);let r;return o===n.getLastBlock()?r=st(o,ut(n,o),"end"):r=Qg(n,o,e,t),r}function SA(n){if(!n.selection.range.focus.isSimple())return!1;const e=TA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function LA(n){if(!n.selection.range.focus.isSimple())return!1;const e=DA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function MA(n){if(!n.selection.range.focus.isSimple())return!1;const e=TA(n);if(!e)return!1;const o=xh(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}function RA(n){if(!n.selection.range.focus.isSimple())return!1;const e=DA(n);if(!e)return!1;const o=xh(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}const Na=S("select-all");function OA(n,t){const e=Se(n),o=Ge(n);return t.start.offset===0&&t.start.blockId===it(e)&&t.end.offset===ut(t.getEditor(),o)&&t.end.blockId===it(o)}function xT(n,t){const e=t.getEditor(),o=jn(e,n).getChildContainers(e,n),r=o[0],i=o[o.length-1],s=it(n);return t.start.blockId===s&&t.start.childContainerId===at(r)&&t.end.blockId===s&&t.end.childContainerId===at(i)}function IT(n,t){g(Na,t,"no parent block"),g(Na,Lt(n,t),"not a complex block");const e=jn(n,t).getChildContainers(n,t),o=e[0],r=e[e.length-1];n.selection.setRange(Ue(n,{anchor:fe(t,at(o)),focus:fe(t,at(r))}))}function _A(n,t){const e=nt(t);Yg(n,e)}function FA(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&tt(n,t)){const r=e.start,i=e.end,s=ut(n,t);if(r.offset>0||i.offset<s)return n.selection.selectBlock(t,0,s),!1}return W(n.rootContainer,"select-all"),_A(n,Se(n.rootContainer)),!1}return g(Na,!e.isSimple(),"invalid range type"),xT(t,e)?(_A(n,t),!1):(g(Na,t,"no parent block"),g(Na,Lt(n,t),"not a complex block"),IT(n,t),!0)}function Yg(n,t){const e=ve(t),o=e[0],r=e[e.length-1],i=st(o,0,"home"),s=st(r,ut(n,r),"end");n.selection.setSelection(i,s,{noScroll:!0})}function PA(n){Zg(n),n.focus()}const Jg=S("selected-block-to-doc");function NA(n,t,e){!t.children||t.children.forEach(o=>{const r=n.getChildContainerData(o);r.forEach(i=>{NA(n,i,e)}),e.blocks[o]=mt.default(r)})}function Ih(n,t){const e=Qt(n,t.block);if(e.selectionToDoc)return e.selectionToDoc(n,t);const o=mt.default(_i(n,t.block));if(tt(n,t.block)){const i=t.start,s=t.end;if(g(Jg,o.text,"no block text"),i.offset===s.offset)return{blocks:{root:[{...o,text:[]}]},meta:{},comments:{}};const{middle:l}=ze(o.text,i.offset,s.offset-i.offset);return{blocks:{root:[{...o,text:l}]},meta:{},comments:{}}}if(Le(t.block))return{blocks:{root:[o]},meta:{},comments:{}};g(Jg,Lt(n,t.block),"not complex block"),g(Jg,o.children,"no children");const r={blocks:{root:[o]},meta:{},comments:{}};return NA(n,o,r),r}function Kg(n,t){const e=st(t,0,"normal"),o=st(t,ut(n,t),"end");return Ih(n,{block:t,start:e,end:o})}const TT=S("block-to-doc");function DT(n,t){g(TT,t.length>0,"invalid params, no blocks");const e=t.map(o=>Kg(n,o));return $s(e)}function Th(n){const e=n.selection.range.getSelectedBlocks().map(o=>Ih(n,o));return $s(e)}function $A(n,t){const e=n.getContainerById(t),i=ve(e).map(s=>({start:st(s,0,"home"),end:st(s,ut(n,s),"end"),block:s})).map(s=>Ih(n,s));return $s(i)}const Dh=S("editor-selection");class ST{constructor(t){m(this,"editor");m(this,"caret");m(this,"_range");m(this,"lastCaretRect");m(this,"handleBlockDelete",(t,e,o,r)=>{if(o||r.child)return;const i=this.range;if(D6(e,i)){Dh.debug("adjust selection because remote deleted current block");const s=S6(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),o=it(e);this.caret=new VI(t);const r=st(o,0,"normal");this._range=Ue(t,{anchor:r,focus:r}),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,o){const r=st(t,e,"normal");let i;o&&(i=st(t,o,"normal")),this.setSelection(r,i)}setSelection(t,e,o){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const r=Ue(this.editor,{anchor:t,focus:e});if(this.range.isEqual(r))return this.range;const i=this._range;return this._range=r,this.selectionChanged(),this.updateFocusedBlock(i),xt(this.editor.rootContainer,"select-all")&&(!r.isSimple()||!KI(this.editor,r))&&et(this.editor.rootContainer,"select-all"),o!=null&&o.noScroll||this.scrollIntoView(),this.range}setRange(t,e){return this.setSelection(t.anchor,t.focus,e)}updateSelection(){this.caret.update(),WI(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(!$r(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=To(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){JI(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=ut(this.editor,e)||g(Dh,!1,"invalid block position, out of range");else{const o=t.childContainerId;!!this.editor.getContainerById(o)||g(Dh,!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 o;(this.range.isCollapsed()||!this.range.isSimple()||this.range.start.blockId===this.range.end.blockId)&&(o=this.editor.getBlockById(this.range.start.blockId));let r=!1;e&&xt(e,"focused")&&(et(e,"focused"),r=!0),this.removeAllBlockFocusedClass(),o&&this.setBlockFocused(o)&&(r=!0),r&&this.editor.emit("focusBlockChanged",this.editor,o!=null?o:null,e!=null?e:null)}verify(){this.verifyPos(this._range.start),this.verifyPos(this._range.end)}to(t){const e=Th(this.editor);return t==="text"?La(this.editor,e):t==="markdown"?Ma(this.editor,e):M6(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{et(t,"focused"),et(t,"child-focused")})}setBlockFocused(t){if(xt(t,"focused"))return!1;W(t,"focused");let e=nt(t);for(;Do(e);){const o=ot(e);g(Dh,o,"parent block not found"),W(o,"child-focused"),e=nt(o)}return!0}}function LT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,ut(n,e))}function MT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!tt(n,e))return;let o=Vg(n,"select"),r=Wg(n,"select");if(!o||!r)return;const i=t.blockId;o.blockId!==i&&(o=st(e,0,"home")),r.blockId!==i&&(r=st(e,ut(n,e),"end")),n.selection.setSelection(o,r)}class RT{constructor(t){m(this,"editor");m(this,"startPos",null);m(this,"lastCaretRect");m(this,"mouseDownEvent",null);m(this,"autoScroll",null);m(this,"handleMouseDown",(t,e)=>{var r;this.mouseDownEvent=t;const o=M4(this.editor,t.x,t.y);if(o){if(o instanceof or)return;if(!this.autoScroll&&e.autoScroll){const s=o.getSelectedBlocks(),l=oo(s[0].block);this.autoScroll=new Gd({scrollElement:l,edge:{top:50,bottom:50}})}const i=this.editor.selection.range;if(t.shiftKey&&i.isSimple()){const s=i.anchor;this.editor.selection.setSelection(s,o.focus),this.startPos=o.start}else this.editor.selection.setSelection(o.anchor,o.focus),this.startPos=o.start;this.editor.selection.updateLastCaretRect(),e.autoScroll&&((r=this.autoScroll)==null||r.active())}});m(this,"handleMouseMove",t=>{if(!this.startPos||!this.mouseDownEvent||Math.abs(this.mouseDownEvent.x-t.x)<3&&Math.abs(this.mouseDownEvent.y-t.y)<3)return;const e=oh(this.editor,t.x,t.y);if(!e)return;const o=xh(this.editor,this.startPos,e.end);if(!o)return;const{anchor:r,focus:i}=o;this.editor.selection.setSelection(r,i)});m(this,"handleMouseUp",t=>{var e;(e=this.autoScroll)==null||e.inactive(),this.startPos=null});this.editor=t,this.startPos=null,this.lastCaretRect=new DOMRect}isSelecting(){return this.startPos!==null}stopSelection(){this.startPos=null}handleDblClick(t){MT(this.editor)}handleTripleClick(t){LT(this.editor)}}function OT(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function _T(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const HA=S("delete-text");function jA(n,t,e,o){const r=o!=null?o:n.selection.range.start;r instanceof je||g(HA,!1,`invalid insert pos type: ${typeof r}`);const{blockId:i}=r,s=n.getBlockById(i);g(HA,tt(n,s),"block is not a text kind block");let{offset:l}=r;if(t==="backward"){if(l-e<0)return 0;if(!sn(s,l-e)){const a=Ri(s,l);e=l-a}}else if(t==="forward"&&l+e>ut(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function UA(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const FT=S("handle-backspace");function Xg(n,t){if(!he(n,t))return;const e=nt(t);Eo(e)!==1&&n.deleteBlock(t)}function PT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===0){if(UA(n,o))return;const r=ce(o);if(r){if(!n.isBlockWritable(r))return;if(tt(n,r))n.mergeTextBlock(r,o,{focus:!0});else if(Lt(n,r)){Xg(n,o);const i=Vl(n,r);i?n.selection.selectBlock(i,ut(n,i)):n.selection.selectBlock(r,0,ut(n,r))}else Xg(n,o),g(FT,Le(r),"prev block is not embed block"),n.selection.selectBlock(r,1)}else{const i=nt(o);if(Do(i)){const s=x4(n,i);if(s){if(!n.isBlockWritable(s))return;Xg(n,o),n.selection.selectBlock(s,ut(n,s))}}}}else jA(n,"backward",1,null),n.selection.updateLastCaretRect();else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function NT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===ut(n,o)){const r=Zt(o);if(r){if(!n.isBlockWritable(r))return;tt(n,r)?n.mergeTextBlock(o,r,{focus:!0}):he(n,o)?n.deleteBlock(o,ye(n,r,0)):n.deleteBlock(r)}}else jA(n,"forward",1,null);else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function $T(n){const{range:t}=n.selection,{start:e,end:o}=t,r=n.getBlockById(e.blockId),i=n.getBlockById(o.blockId);if(r!==i||!Lt(n,r))return!1;if($r(e))return!0;const s=Os(n,r,e,o),l=En(n,r);return s.length===l.length}function HT(n,t){if($T(n)){const o=n.getFocusedBlock(),r=bt(o),i=at(nt(o));n.insertTextBlock("",i,r+1);return}n.selection.range.isCollapsed()||n.clearSelectedContents();const e=n.getFocusedBlock();if(tt(n,e)){if(he(n,e)&&UA(n,e))return;const o=n.selection.range.start,r=n.breakTextBlock(e,o.offset,{copyBlockAttributes:!0});o.offset!==0?n.selection.selectBlock(r,0):n.selection.scrollIntoView()}else{const o=n.insertTextBlock();n.selection.selectBlock(o,0)}}function jT(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:o}=e;if(!tt(n,o))return!1;const r=e.end;return n.insertBoxToBlock(o,r.offset,{type:"br",id:K(),box:!0,created:Date.now()}),!0}const UT=S("input-handler-actions");function zT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(HT(n),!0))}function VT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(NT(n),!0))}function WT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(PT(n),!0))}function qT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(jT(n),!0))}function GT(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t,{toPlainText:!0})}).catch(t=>{UT.error(t)}),!0)}const Sh={ArrowDown:sA,ArrowUp:iA,ArrowLeft:oA,ArrowRight:rA,"Shift+ArrowDown":lA,"Shift+ArrowUp":uA,"Shift+ArrowLeft":cA,"Shift+ArrowRight":aA,"CtrlOrCmd+ArrowLeft":hA,"CtrlOrCmd+ArrowRight":fA,"CtrlOrCmd+Shift+ArrowLeft":mA,"CtrlOrCmd+Shift+ArrowRight":gA,"CtrlOrCmd+ArrowUp":CA,"CtrlOrCmd+ArrowDown":pA,"CtrlOrCmd+Shift+ArrowUp":AA,"CtrlOrCmd+Shift+ArrowDown":Zg,"CtrlOrCmd+A":FA,Home:BA,End:EA,"Shift+Home":kA,"Shift+End":wA,PageUp:SA,PageDown:LA,"Shift+PageUp":MA,"Shift+PageDown":RA,"CtrlOrCmd+Z":OT,"CtrlOrCmd+Shift+Z":_T,Enter:zT,Delete:VT,Backspace:WT,"Shift+Enter":qT,"CtrlOrCmd+Shift+V":GT};function zA(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function VA(n,t,e){if(t.type==="embed"){const i=t.embedData,s=i.src;if(s&&typeof s=="string"){const l=e.get(s);l&&(i.src=l)}return}const o=t.text;o&&o.forEach(i=>{if(i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"){const s=e.get(i.attributes.src);s&&(i.attributes.src=s)}});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{VA(n,l,e)})})}function WA(n,t,e){if(e.size===0)return;t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.replaceResources?i.replaceResources(r,e):VA(t,r,e)})}async function ZT(n,t){const e=t.filter(i=>i.indexOf(":")===-1),o=await n.doc.addResources(e),r=new Map;if(e.length!==o.length)return r;for(let i=0;i<e.length;i++)r.set(e[i],o[i]);return r}function QT(n,t){var i,s;const o=t.meta.serverId;if(!o||typeof o!="string")return!1;const r=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i);return!(!r||r.serverId!==o)}async function YT(n,t){const o=t.meta.resources;if(!o||Object.keys(o).length===0)return;let r=new Map;if(QT(n,t)){const s=Array.from(Object.keys(o));r=await ZT(n,s),WA(n,t,r)}const i=new Map;Object.entries(o).forEach(([s,l])=>{r.get(s)===void 0&&s!==l&&i.set(s,l)}),i.size!==0&&WA(n,t,i)}async function JT(n,t,e){await YT(n,t),n.undoManager.runInGroup(()=>{const{start:o,end:r}=n.selection.range,i=n.getBlockById(o.blockId);if(o.blockId===r.blockId&&Le(i)){const s=nt(i),l=n.getBlockIndex(i),[a]=n.insertDocAt(s,l+1,t,e);a&&n.selection.selectBlock(a,ut(n,a))}else{n.clearSelectedContents();const{block:s,offset:l}=Gl(n);n.insertDoc(s,l,t,e)}})}const KT=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function XT(n){let t;for(const e of KT)if(t=n[e],t)break;return t||null}function qA(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 o=t.text;o&&o.forEach(i=>{i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"&&e.add(i.attributes.src)});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{qA(n,l,e)})})}function tD(n,t){const e=new Set;return t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.getResources?i.getResources(r).forEach(s=>{e.add(s)}):qA(t,r,e)}),Array.from(e)}function Lh(n,t){return`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${Bs(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function Mh(n,t){var i,s,l;const e=(l=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i))!=null?l:{},o=tD(n,t),r={};o.forEach(a=>{const d=n.doc.buildResourceUrl(a,{withToken:!0});r[a]=d}),t.meta={...e,resources:r}}function eD(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let o=Th(n);const r=e==null?void 0:e(n,t,o);if(r===!0)return;typeof r=="object"&&r!==null&&(o=r),Mh(n,o);const i=bh(n,o),s=Ma(n,o),l=Lh(i,o);t.clipboardData.setData("text/html",l),t.clipboardData.setData("text/plain",s),t.clipboardData.setData("text/x-ones-editor-doc",JSON.stringify(o))}async function Rh(n,t){const e=Kg(n,t);Mh(n,e);const o=bh(n,e),r=Ma(n,e),i=Lh(o,e);return Mm([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:new Blob([i],{type:"text/html"})}])}class nD{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"onPasteText",async(t,e)=>{const o=new DataTransfer;o.setData("text/plain",t);const r=await this.editor.dataConverter.fromData(this.editor,o,e);r&&this.pasteDocs(r,null)});this.editor=t}onInsertText(t,e){if(!tt(this.editor,this.editor.getFocusedBlock()))return;const{containerId:o,blockIndex:r,offset:i}=Gl(this.editor);this.handleBeforeInsertText(o,r,i,e)||(this.defaultInsertText(this.editor,o,r,i,e),this.handleAfterInsertText(o,r,i,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 o=this.handlers[e];o.handleChanged&&o.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleRemoteChanged&&o.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:o,offset:r}=Gl(this.editor);for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,o,r)}}onUpdateCompositionText(t,e,o){this.editor.updateCompositionText(e,o),this.editor.selection.caret.update();const{containerId:r,blockIndex:i,offset:s}=Gl(this.editor);for(let l=0;l<this.handlers.length;l++){const a=this.handlers[l];a.handleUpdateCompositionText&&a.handleUpdateCompositionText(this.editor,r,i,s,o)}this.editor.selection.updateLastCaretRect()}onCopy(t){eD(this.editor,t,(e,o,r)=>{for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,o,r);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}onCut(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeCut&&r.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const o=this.editor.selection.focusedBlock;Le(o)&&this.editor.deleteBlock(o)}else Fg(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;this.editor.dataConverter.fromData(this.editor,t.clipboardData).then(async o=>{o&&this.pasteDocs(o,t)})}onFocus(){W(this.editor.rootElement,"active")}onBlur(){et(this.editor.rootElement,"active")}addHandler(t){this.handlers.push(t)}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,o,r))return!0}return!1}handleAfterInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,o,r))return!0}return!1}handleBeforeKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,o,r,i){Lg(this.editor,i)}defaultHandleKeydown(t,e){return zA(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforePasteDoc&&await r.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map};await JT(this.editor,t,e);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterPasteDoc&&await r.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePaste&&await i.handleBeforePaste(this.editor,e,t))return}const o=XT(t);if(!!o){await this.pasteDoc(o);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPaste&&await i.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}}function oD(n,t,e){const o=Or(t,e);return o.remove(),o}S("copy-dom-attributes");const GA=["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 rD(n,t){for(let l=0;l<GA.length;l++){const a=GA[l];t[a]=n[a]}const e=n.attributes,o=t.attributes,r=[],i=[];for(let l=0;l<e.length;l++){const a=e[l],d=o.getNamedItem(a.name);d?d.value!==a.value&&(d.value=a.value,i.push(a)):r.push(a)}const s=[];for(let l=0;l<o.length;l++){const a=o[l];e.getNamedItem(a.name)||s.push(a)}r.forEach(l=>{t.setAttribute(l.name,l.value)}),i.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function ZA(n){const t=Array.from(n.childNodes).filter(e=>!jC(e));return t.forEach(e=>{e.remove()}),t}function QA(n,t,e){var d;const o=n.getContainerById(t),r=Or(o,e),i=Di(r),s=n.doc.getBlockData(t,e),l=Qt(n,r);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,r,s))n.editorBlockRenders.updateBlock(n,i,r,s);else{const h=n.editorBlocks.createBlock(i,o,s),p=ZA(h);ZA(r),p.forEach(v=>{r.appendChild(v)});const A=Jd(h);if(A){const v=Jd(r);v&&v.remove(),r.appendChild(A)}rD(h,r)}i4(n,r,s),n.blockHooks.forEach(h=>{var p;(p=h.update)==null||p.call(h,n,i,o,r,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const iD=S("transform-selection");function YA(n,t,e,o){const{range:r}=n.selection,{anchor:i,focus:s}=r;if(i.blockId!==t&&s.blockId!==t)return r;g(iD,i.isSimple()&&s.isSimple(),"invalid text pos type");let l=i;if(i.blockId===t){const d=ln.transformCursor(i.offset,e,o);l=st(t,d,"normal")}let a=s;if(s.blockId===t){const d=ln.transformCursor(s.offset,e,o);a=st(t,d,"normal")}return Ue(n,{anchor:l,focus:a})}const sD=S("handle-block-text-changed");function lD(n,t,e,o,r){const i=n.getContainerById(t),s=Or(i,e),l=n.doc.getBlockData(t,e);if(g(sD,l.text,"no block text"),XC(n,s).setBlockText(n,s,l.text),!r){const a=YA(n,l.id,o,r);n.selection.setRange(a,{noScroll:!0})}}function cD(n,t){const e=mt.default(n);return t.delete.forEach(r=>{delete e[r]}),{...e,...t.insert}}function JA(n,t,e,o){const r=Qt(n,t);r.handleDeleteBlock&&r.handleDeleteBlock(n,t,e,o),n.emit("blockDeleted",n,t,e,o)}function aD(n,t,e,o){const r=n.getBlockByIndex(t,e);r.querySelectorAll('[data-type="editor-block"]').forEach(i=>{JA(n,i,o,{child:!0})}),JA(n,r,o,{child:!1})}const Ro=S("editor-doc");class uD extends fa{constructor(e,o,r){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=o,this.externalDoc.registerCallback(this),this.registerLocalEvents(r)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var o,r;return(r=(o=this.externalDoc).getVersionHelper)==null?void 0:r.call(o)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}getBlockData(e,o){return this.externalDoc.getBlockData(e,o)}verifyBlockWritable(e,o){const r=this.editor.getBlockByIndex(e,o);g(Ro,this.editor.isBlockWritable(r),`block is not writable, ${e}, ${o}`)}localUpdateBlockText(e,o,r,i){g(Ro,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const s=this.getBlockData(e,o),l=s.text;g(Ro,l,`no text, ${e}, ${o}`);const a=YA(this.editor,s.id,r,!0),d=ln.apply(l,r);this.localEvents.forEach(p=>p.onBeforeUpdateBlockText(e,s.id,l,d,a.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,o,r);return this.editor.selection.setRange(a,i),h}localUpdateBlockData(e,o,r,i){g(Ro,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,o);if(!this.editor.isBlockWritable(s)){const h=Array.from(r.delete).filter(A=>A!=="comments"),p=Object.keys(r.insert).filter(A=>A!=="comments");(h.length>0||p.length>0)&&g(Ro,!1,`block is not writable, comment supported only, ${JSON.stringify(r)}}`)}const l=mt.default(this.getBlockData(e,o)),a=mt.default(cD(l,r));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,a,i));const d=this.externalDoc.localUpdateBlockData(e,o,r,i);return this.editor.selection.setRange(Si(this.editor,i)),d}localInsertBlock(e,o,r,i,s){g(Ro,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(a=>a.onBeforeInsertBlock(e,o,r,i));const l=this.externalDoc.localInsertBlock(e,o,r,i);return this.editor.selection.setRange(Si(this.editor,i),s),l}localDeleteBlock(e,o,r){g(Ro,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const i=mt.default(this.getBlockData(e,o));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,o,i,r));const s=this.externalDoc.localDeleteBlock(e,o,r);return this.editor.selection.setRange(Si(this.editor,r)),s}localDeleteChildContainers(e){return g(Ro,!this.editor.readonly,"editor is readonly"),e.forEach(o=>{const r=mt.default(this.getContainerBlocks(o));this.localEvents.forEach(i=>i.onBeforeDeleteChildContainer(o,r))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainer(e,o){return g(Ro,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(r=>r.onBeforeInsertChildContainer(e,mt.default(o))),this.externalDoc.localInsertChildContainer(e,o)}onRequestReload(e){Ro.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)});const o=!1;this.editor.emit("docChanged",this.editor,o)}onUpdateBlockText(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,o,r,i)}),lD(this.editor,e,o,r,i),this.editor.emit("docChanged",this.editor,i)}onUpdateBlockData(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,i)}),QA(this.editor,e,o),this.editor.emit("docChanged",this.editor,i)}onInsertBlock(e,o,r,i){this.callbacks.forEach(l=>{var a;return(a=l.onInsertBlock)==null?void 0:a.call(l,e,o,r,i)});const s=this.editor.getContainerById(e);KE(this.editor,s,o,r),this.editor.emit("docChanged",this.editor,i)}onDeleteBlock(e,o,r){aD(this.editor,e,o,r),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,r)});const i=this.editor.getContainerById(e);oD(this.editor,i,o),this.editor.emit("docChanged",this.editor,r)}onInsertChildContainer(e,o,r){this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,e,o,r)})}onDeleteChildContainer(e,o){this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){this.callbacks.forEach(o=>{var r;return(r=o.onCustomMessage)==null?void 0:r.call(o,e)})}onStatusChanged(e){this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)})}onError(e){this.callbacks.forEach(o=>{var r;return(r=o.onError)==null?void 0:r.call(o,e)})}uploadResource(e,o){return this.externalDoc.uploadResource(e,o)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,o){return this.externalDoc.buildResourceUrl(e,o)}request(e,o){return this.externalDoc.request(e,o)}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,o,r;return(r=(o=(e=this.externalDoc).getServerMeta)==null?void 0:o.call(e))!=null?r:{}}reset(e){Ro.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function KA(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 tp=S("undo-action");class Kl{constructor(t,e,o){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=o}undo(t){return!1}redo(t){return!1}combinable(t){return g(tp,t,"no other action"),!1}combine(t){g(tp,!1,"no other")}setAfterRange(t){this.afterRange&&tp.warn("after range has already set"),this.afterRange=t}}const dD=S("block-action");class XA extends Kl{constructor(e,o,r,i,s){super(e,o,s);m(this,"blockData");m(this,"blockIndex");this.blockData=mt.default(i),this.blockIndex=r}deleteBlock(e,o){if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockData.id);return i?(g(dD,this.blockIndex===bt(i),"invalid block index"),kh(e,i,Si(e,o)),!0):!1}insertBlock(e,o){return Ql(e,this.containerId,this.blockIndex,mt.default(this.blockData),o),!0}}class hD extends XA{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class fD extends XA{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class mD extends Kl{constructor(e){super(e,at(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){KA(this.actions,e),this.afterRange=e.afterRange}undo(e){let o=!1;return this.actions.concat().reverse().forEach(r=>{r.undo(e)&&(o=!0)}),o}redo(e){let o=!1;return this.actions.forEach(r=>{r.redo(e)&&(o=!0)}),o}setAfterRange(e){this.afterRange=e;const o=this.actions[this.actions.length-1];!o||o instanceof Kl&&(o.afterRange||o.setAfterRange(e))}}const Hs=S("update-block-data-action");class Oh extends Kl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=r,g(Hs,this.blockId===i.id,"invalid block id"),g(Hs,this.blockId===s.id,"invalid block id"),this.beforeBlockData=mt.default(i),this.afterBlockData=mt.default(s),g(Hs,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Eh(e,o,Oh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Eh(e,o,Oh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const o=mt.default(e);return delete o.id,delete o.type,o}}const ep=S("update-block-text-action");class $a extends Kl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=r,this.beforeRichTextData=mt.default(i),this.afterRichTextData=mt.default(s),this.type=$a.calType(i,s)}static calType(e,o){g(ep,e,"no old data"),g(ep,o,"no new data");const i=ln.diff(e,o),s=new Set;let l=!1;const a=h=>pC(h)?`cjk_${h}`:mC(h)?"number":jd(h)?"space":gC(h)?"letter":"unknown";let d=!1;return i.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_${a(h.insert.substr(1))}`)):s.add(`insert_${a(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(Bh(e,r,this.beforeRichTextData),!0):!1}redo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(Bh(e,r,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof $a)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const o=e.beforeRange,r=o.anchor;if(!r.isSimple())return!1;const i=this.afterRange;if(!i)return!1;const s=i.anchor;return!(!s.isSimple()||s.blockId!==o.anchor.blockId||s.offset!==r.offset)}combine(e){g(ep,e instanceof $a,"invalid action type");const o=e;this.afterRichTextData=o.afterRichTextData,this.afterRange=e.afterRange}}class tb extends Kl{constructor(t,e,o){super(t,e,t.selection.range.toDocRange()),this.blocks=o}deleteChildContainer(t){return t.doc.localDeleteChildContainers([this.containerId]),!0}insertChildContainer(t){return t.doc.localInsertChildContainer(this.containerId,mt.default(this.blocks)),!0}}class gD extends tb{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class pD extends tb{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Oo=S("undo");class CD{constructor(t){m(this,"editor");m(this,"actions",[]);m(this,"undoCursor");m(this,"currentGroup",null);m(this,"groupCounter",0);m(this,"undoRedoing",!1);m(this,"handleSelectionChange",t=>{if(this.currentGroup){this.currentGroup.setAfterRange(t.selection.range.toDocRange());return}const e=this.actions[this.actions.length-1];!e||e.afterRange||e.setAfterRange(t.selection.range.toDocRange())});this.editor=t,this.undoCursor=-1,this.editor.addListener("selectionChanged",this.handleSelectionChange)}reset(){this.actions=[],this.undoCursor=-1}prepareSaveUndoState(){this.undoCursor!==-1&&(this.actions.splice(this.undoCursor),this.undoCursor=-1)}addAction(t){this.currentGroup?this.currentGroup.addAction(t):(KA(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(g(Oo,!this.currentGroup,"current group already exists"),this.currentGroup=new mD(this.editor),this.groupCounter=1):(g(Oo,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){g(Oo,this.currentGroup,"current group not exists"),g(Oo,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Oo.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 Oo.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(Si(this.editor,t.beforeRange))}catch(e){Oo.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(Si(this.editor,e)):Oo.warn("no after range")}catch(e){Oo.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,o,r,i){this.undoRedoing||(this.prepareSaveUndoState(),ln.diff(o,r).length!==0&&this.addAction(new $a(this.editor,t,e,o,r,i)))}onBeforeUpdateBlockData(t,e,o,r,i){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new Oh(this.editor,t,e,o,r,i);this.addAction(s)}onBeforeInsertBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),g(Oo,e>=0,"invalid block index"),g(Oo,o,"no block data"),this.addAction(new hD(this.editor,t,e,o,r)))}onBeforeDeleteBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new fD(this.editor,t,e,o,r)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new gD(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new pD(this.editor,t,e)))}}class AD{async fromData(t,e){const o=e.getData("text/x-ones-editor-doc");if(o)return{"text/x-ones-editor-doc":JSON.parse(o)}}}class bD{constructor(){m(this,"converters",[]);this.addConverter(new AD)}async fromData(t,e,o){let r={};for(const i of this.converters){const s=await i.fromData(t,e,o);s&&(r={...r,...s})}return r}addConverter(t){this.converters.push(t)}}class vD{constructor(t){m(this,"renders",[]);this.editor=t}registerRender(t){this.renders.push(t)}renderText(t,e){const o={classes:[],attributes:{},styles:{}};return this.renders.forEach(r=>{if(r.renderText){const i=r.renderText(this.editor,t,e);i.classes&&o.classes.push(...i.classes),i.attributes&&(o.attributes={...o.attributes,...i.attributes}),i.styles&&(o.styles={...o.styles,...i.styles})}}),o}renderBlock(t,e,o){const r={classes:[],attributes:{},styles:{}};return this.renders.forEach(i=>{if(i.renderBlock){const s=i.renderBlock(this.editor,e,o);s.classes&&r.classes.push(...s.classes),s.attributes&&(r.attributes={...r.attributes,...s.attributes}),s.styles&&(r.styles={...r.styles,...s.styles})}}),r}updateBlock(t,e,o,r){this.renders.forEach(i=>{var s;(s=i.updateBlock)==null||s.call(i,t,e,o,r)})}}class pe extends be.TypedEmitter{constructor(e){super();m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"filters",[]);m(this,"finders",[]);m(this,"handleDocumentMouseMove",e=>{if(this.hoveringBlock){for(const s of this.filters)if(s.isInBlock(this.hoveringBlock,e))return}const o=document.elementFromPoint(e.x,e.y);if(!o){this.setHoveringBlock(null,e,null);return}let r=ot(o);if((!r||!Kt(this.editor.rootContainer,r))&&(r=this.findBlockByFinders(e),!r)){this.setHoveringBlock(null,e,null);return}const i=this.getParentTextContentChild(r,o);this.setHoveringBlock(r,e,i)});this.editor=e,document.addEventListener("mousemove",this.handleDocumentMouseMove)}destroy(){document.removeEventListener("mousemove",this.handleDocumentMouseMove),this.filters.forEach(e=>e.destroy()),this.filters=[],this.finders.forEach(e=>e.destroy()),this.finders=[]}addFilter(e){this.filters.push(e)}addFinder(e){this.finders.push(e)}hoveringBlockId(){return this.hoveringBlock?it(this.hoveringBlock):""}findBlockByFinders(e){for(let o=0;o<this.finders.length;o++){const i=this.finders[o].findTargetBlock(this.editor,e);if(i)return i}return null}setHoveringBlock(e,o,r){if(this.hoveringBlock===e&&this.hoveringTextChild===r)return;if(this.hoveringBlock!==e){const s=this.hoveringBlock&&Kt(this.editor.rootContainer,this.hoveringBlock)?this.hoveringBlock:null;s&&et(s,"hover"),e&&W(e,"hover"),this.hoveringBlock=e,this.emit("change",this.hoveringBlock,s,o)}const i=this.hoveringTextChild;this.hoveringTextChild=r,this.emit("childChange",this.hoveringBlock,r,i,o)}static get(e){return e.addCustom("standard-hovering-block",()=>new pe(e))}getParentTextContentChild(e,o){if(!tt(this.editor,e))return null;const r=Rt(e);return o.parentElement===r?o:$m(o)}}const eb="style-color-",nb="style-bg-color-";class yD{renderText(t,e,o){const r=[],i={},s={};return Object.entries(o).forEach(([l,a])=>{a===!0?l.startsWith(eb)?i["data-style-color"]=l.substring(eb.length):l.startsWith(nb)?i["data-style-bg-color"]=l.substring(nb.length):l.startsWith("style")&&r.push(l):typeof a=="string"&&(l==="link"&&(r.push("link"),i.link=a),l==="inline-style-color"&&(s.color=a))}),{classes:r,attributes:i,styles:s}}renderBlock(t,e,o){var l,a;const r={};Object.entries(o).filter(d=>d[0].startsWith("style-")).forEach(([d,h])=>{r[`data-${d}`]=`${h}`});const s=[];return((a=(l=t.selection)==null?void 0:l.range)==null?void 0:a.start.blockId)===o.id&&s.push("focused"),typeof o.align=="string"&&o.align&&(r["data-style-align"]=o.align),o.heading&&(r["data-style-heading"]=String(o.heading)),o.quoted&&(r["data-style-quoted"]="true"),pe.get(t).hoveringBlockId()===o.id&&s.push("hover"),{attributes:r,classes:s}}updateBlock(t,e,o,r){var s,l;Array.from(o.attributes).forEach(a=>{a.name.startsWith("data-style-")&&o.removeAttribute(a.name)}),Object.entries(r).filter(a=>a[0].startsWith("style-")||a[0]==="align").forEach(([a,d])=>{a==="align"&&o.setAttribute(a.startsWith("style-")?`data-${a}`:`data-style-${a}`,`${d}`)}),((l=(s=t.selection)==null?void 0:s.range)==null?void 0:l.start.blockId)===r.id&&W(o,"focused"),pe.get(t).hoveringBlockId()===r.id&&W(o,"hover")}}function kD(n){n.editorBlocks.registerBlockClass(In),n.editorBlocks.registerBlockClass(E4),n.editorBoxes.registerBoxClass(g6),n.editorBoxes.registerBoxClass(p6),n.editorBoxes.registerBoxClass(b6),n.editorBoxes.registerBoxClass(v6),n.editorInsertions.registerInsertionClass(y6),n.editorBlockRenders.registerRender(new yD)}function wD(n,t){kD(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 ob=S("range-commands");function rb(n,t){n.forEach(e=>{e.source=t,e.children&&rb(e.children,t)})}function ib(n,t,e){const o=it(t);g(ob,o===e.start.blockId,"invalid start range"),g(ob,o===e.end.blockId,"invalid end range");const r=n.editorCommandProviders.getCommandProviders();let i=[];return r.forEach(s=>{const l=s.getAvailableCommands(n,t,e);rb(l,s.id),i.push(...l)}),r.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,i);l&&(i=l)}}),Lt(n,t)&&Os(n,t,e.start,e.end).forEach(l=>{ve(l).forEach(d=>{const h=ut(n,d),p=Ue(n,{anchor:st(d,0,"home"),focus:st(d,h,"end")}),A=ib(n,d,p);i.push(...A)})}),i}function sb(n){const t=n.getEditor(),e=n.getSelectedBlocks(),o=[];return e.forEach(r=>{const i=Ue(t,{anchor:r.start,focus:r.end});ib(t,r.block,i).forEach(l=>{o.push(l)})}),o}function lb(n,t,e,o,r,i){var h;const s=n.editorCommandProviders.getCommandProviders();for(let p=0;p<s.length;p++){const A=s[p];if(A.beforeExecuteCommand&&A.beforeExecuteCommand(n,t,e,o,r))return!1}const l=n.editorCommandProviders.getCommandProvider(o.source),a={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,o,r,{}))return i[it(t)]=a,!0;let d=!1;return Lt(n,t)&&Os(n,t,e.start,e.end).forEach(A=>{ve(A).forEach(B=>{const D=ut(n,B),T=Ue(n,{anchor:st(B,0,"home"),focus:st(B,D,"end")});lb(n,B,T,o,r,i)&&(d=!0)})}),s.forEach(p=>{p.afterExecuteCommand&&p.afterExecuteCommand(n,t,e,o,r,i)}),d}function cb(n,t,e){const o=n.getEditor(),r={},i=o.editorCommandProviders.getCommandProvider(t.source);return i.executeRangeCommand&&i.executeRangeCommand(o,n,t,e,r)||n.getSelectedBlocks().forEach(l=>{const a=Ue(o,{anchor:l.start,focus:l.end});lb(o,l.block,a,t,e,r)}),r}const BD=S("command-providers");class ab{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(o=>o.id===t);return g(BD,e,`no command provider, id=${t}`),e}getCommands(t){return sb(t)}executeCommand(t,e,o){return this.editor.undoManager.runInGroup(()=>cb(t,e,o))}getEmptyBlockTextAttributes(t,e){let o={};if(this.providers.forEach(r=>{var s;const i=(s=r.getEmptyBlockTextAttributes)==null?void 0:s.call(r,t,e);i&&(o={...o,...i})}),Object.keys(o).length!==0)return o}}function ED(n,t){const e=nt(t),o=at(e),r=bt(t);QA(n,o,r)}const xD=S("table-scroll");class ub{constructor(t,e,o,r,i){m(this,"handleEvent",t=>{this.handler(this.editor,t,this.data)});this.editor=t,this.dom=e,this.name=o,this.handler=r,this.data=i,e.addEventListener(o,this.handleEvent)}destroy(){this.dom.removeEventListener(this.name,this.handleEvent)}}class ID{constructor(t){m(this,"handlers",new Map);this.editor=t}destroy(){Array.from(this.handlers.entries()).forEach(([t,e])=>{e.forEach(o=>o.destroy()),this.handlers.delete(t)})}addEventListener(t,e,o,r){const i=this.handlers.get(t);if(i){if(i.find(s=>s.handler===o&&s.name===e)){xD.warn(`event has already registered: ${e}`);return}i.push(new ub(this.editor,t,e,o,r))}else{const s=new ub(this.editor,t,e,o,r);this.handlers.set(t,[s])}}removeEventListener(t,e,o){if(!t){for(const[i,s]of Array.from(this.handlers.entries()))for(let l=s.length-1;l>=0;l--){const a=s[l];if(e)e===a.name&&o===a.handler&&s.splice(l,1);else if(o===a.handler){s.splice(l,1),a.destroy(),s.length===0&&this.handlers.delete(i);continue}}return}const r=this.handlers.get(t);if(r){const i=r.findIndex(s=>s.handler===o&&s.name===e);if(i!==-1){const s=r[i];r.splice(i,1),s.destroy(),r.length===0&&this.handlers.delete(t)}}}removeAllListeners(t,e){const o=this.handlers.get(t);if(o)if(e)for(let r=0;r<o.length;r++){const i=o[r];i.name===e&&(o.splice(r,1),i.destroy())}else o.forEach(r=>{r.destroy()}),this.handlers.delete(t)}}const db=S("update-block-text");function TD(n,t){const e=n.getBoxById(t.id),o=ot(e);g(db,o,"no parent block"),g(db,tt(n,o),"not a text block");const r=n.getBlockText(o),i=s6(r,"id",t.id,t);z6(n,o,i)}function DD(n,t){for(const e of n.blockHooks)if(e.writable){const o=e.writable(n,t);if(typeof o=="boolean")return o}return!0}function SD(n){return n.readonly?!1:!Lo(n).find(o=>!n.isBlockWritable(o.block))}class LD{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 MD{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const o=this.shortcuts;for(const r of o){const i=Object.entries(r);for(const[s,l]of i)if(Rr(e,s)){const a=l(t,e);if(a!==void 0)return a}}}}const zr=S("editor");class RD extends be.TypedEmitter{constructor(e,o,r){var i,s,l,a,d,h,p;super();m(this,"parent");m(this,"rootElement");m(this,"contentElement");m(this,"rootContainerObject");m(this,"rootContainer");m(this,"input");m(this,"selection");m(this,"selectionHandler");m(this,"doc");m(this,"id");m(this,"clientId");m(this,"compositingText","");m(this,"undoManager");m(this,"shortcuts",new MD);m(this,"dataConverter",new bD);m(this,"editorBlocks",new y4(this));m(this,"editorBoxes",new A6(this));m(this,"editorInsertions",new w6(this));m(this,"editorEmbeds",new w4(this));m(this,"editorDecorators",new B6(this));m(this,"editorCommandProviders",new ab(this));m(this,"editorBlockRenders",new vD(this));m(this,"blockHooks",[]);m(this,"domEvents",new ID(this));m(this,"customs",new Map);m(this,"options");m(this,"inputHandlers",new nD(this));m(this,"settingsProvider");m(this,"_readonly",!1);zr.debug("create editor"),this.setMaxListeners(100),this.options={colors:(i=r==null?void 0:r.colors)!=null?i:["#9923E9","#4587C2","#8BDB7A","#FB28D3","#CBC619","#10FEEB","#812A1A","#8A3F25","#22D742","#A53E74","#555C87","#57E0AA"],componentsOptions:(l=(s=r==null?void 0:r.components)==null?void 0:s.options)!=null?l:{},scrollContainer:r==null?void 0:r.scrollContainer},this.settingsProvider=(a=r==null?void 0:r.settingsProvider)!=null?a:new LD(this),wD(this,r==null?void 0:r.components),this.blockHooks.push(...(h=(d=r==null?void 0:r.components)==null?void 0:d.blockHooks)!=null?h:[]),this.id=(p=r==null?void 0:r.id)!=null?p:K(),this.clientId=K(),this.undoManager=new CD(this),this.doc=new uD(this,o,this.undoManager),this.parent=e,this.rootElement=w("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=w("div",["editor-content"],this.rootElement),this.rootContainerObject=A4(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new zI(this,this.inputHandlers),this.selection=new ST(this),this.selectionHandler=new RT(this),r!=null&&r.shortcuts&&this.shortcuts.shortcuts.push(...r.shortcuts),Ke.isMobile&&W(this.rootElement,"mobile"),Ke.isSafari&&W(this.rootElement,"safari"),this._readonly&&W(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?W(this.rootElement,"readonly"):et(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:oo(this.rootContainer)}addCustom(e,o){const r=this.customs.get(e);if(r)return r;const i=o(this);return this.customs.set(e,i),i}getCustom(e){const o=this.customs.get(e);return g(zr,o,`${e} does not exists`),o}replaceCustom(e,o){const r=this.customs.get(e);return r&&r.destroy(),this.customs.set(e,o),o}findCustom(e){return this.customs.get(e)}findCustomByType(e){const o=this.customs.values();for(const r of o)if(r instanceof e)return r;return null}destroyCustom(e){const o=this.customs.get(e);o&&(this.customs.delete(e),o.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,o,r){return this.editorBlocks.createBlock(e,o,r)}createBox(e,o){return this.editorBoxes.createBox(e,o)}createInsertion(e,o){return this.editorInsertions.createInsertion(e,o)}destroy(){zr.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,o){Pg(this,e,o)}isWritable(){return SD(this)}isBlockWritable(e){return DD(this,e)}getChildContainerData(e){const o=this.doc.getContainerBlocks(e);return g(zr,o,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),g(zr,Array.isArray(o),`container data is not an array: ${JSON.stringify(o)}`),o}createChildContainer(e,o,r){return b4(this,e,o,r)}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 o=this.rootContainer.querySelector(`#${e}`);return o&&g(zr,xs(o),"not an valid block element"),o!=null?o:null}findBoxById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&g(zr,Nm(o),"not an valid box element"),o!=null?o:null}getBlockById(e){const o=this.findBlockById(e);return g(zr,o,`no block, id=${e}`),o}getBoxById(e){const o=this.findBoxById(e);return g(zr,o,`no box, id=${e}`),o}getBlockByIndex(e,o){const r=this.getContainerById(e);return Or(r,o)}getBlockIndex(e){if(typeof e=="string"){const o=this.getBlockById(e);return bt(o)}return bt(e)}getContainerById(e){return Nr(this,e)}getParentContainer(e){return nt(e)}reloadBlock(e){ED(this,e)}contains(e){const o=e instanceof Element?e:e.parentElement;return o?o.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,o,r,i,s){const l={blockId:r.id,offset:0},a={anchor:l,focus:l};return Ql(this,e,o,r,i!=null?i:a,s)}insertEmbed(e,o,r,i,s){const l={id:K(),type:"embed",embedType:r,embedData:i};return this.insertBlock(e,o,l,s)}deleteBlock(e,o){Og(this,e,o)}mergeTextBlock(e,o){return H6(this,e,o)}breakTextBlock(e,o,r){return Yl(this,e,o,r).newBlock}getTextPosition(){return Gl(this)}getBlockString(e,o){const r=this.getBlockText(e);return re(r,o)}getBlockData(e){return _i(this,e)}getBoxData(e){return f6(this,e)}getBlockText(e){return mn(this,e)}setBlockText(e,o){z6(this,e,o)}deleteTextFromBlock(e,o,r,i){return Mg(this,e,o,r,i)}insertTextToBlock(e,o,r,i){return R6(this,e,o,r,i)}insertBoxToBlock(e,o,r){return O6(this,e,o,r)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,o,r,i){q6(this,e,o,r,i)}insertDocAt(e,o,r,i){return Hg(this,e,o,r,i)}deleteChildContainers(e){$6(this,e)}replaceBlockText(e,o){return Bh(this,e,o)}updateBlockData(e,o,r){const i={...this.getBlockData(e),...o},{id:s,type:l,...a}=i;return Eh(this,e,a,(r!=null?r:this.selection.range).toDocRange())}updateEmbedData(e,o,r){return V6(this,e,o,r)}updateBoxData(e){TD(this,e)}getSelectedText(){const e=Th(this);return La(this,e)}clearSelectedContents(){Fg(this)}insertTextBlock(e,o,r,i){const s=sr(e!=null?e:"");return N6(this,s,o,r,i==null?void 0:i.newRange,i==null?void 0:i.insertBlockOptions)}updateCompositionText(e,o){if(e&&!o&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!o){F6(this);return}o?(this.compositingText="",Em()||Lg(this,e)):(this.compositingText=e,_6(this))}getColor(e){const o=this.options.colors;return o.length===0?"#FF1A75":o[e%o.length]}}function Ha(n,t,e){return new RD(n,t,e)}function OD(n){const t=(o,r)=>{const i=o.findIndex(l=>l.id===r.id);if(i===-1){o.push(r);return}const s=o[i];if(s.value!==r.value){o.splice(i,1);return}if(!!s.states){if(!r.states){s.states=[];return}s.states=fm.default(s.states,r.states)}},e=[];return n.forEach(o=>{o.forEach(r=>{t(e,r)})}),e}const _D=["#FBBFBD","#FFDDB6","#FFF897","#C5F0C1","#CEDDFE","#DCC9FC","#E5E6E8","#F76964","#FFA53D","#FFE928","#63D156","#A0BBFE","#C4A5FB","#BBBFC3"];class _h extends be.TypedEmitter{constructor(e){super();m(this,"users",new Map);m(this,"cursors",new Map);m(this,"addingUser",!1);m(this,"colors");this.colors=e&&e.length>0?e:_D}setCursor(e){this.addUser(e.user);const o=this.cursors.get(e.user.userId);if(o&&ua.default(o,e))return;this.cursors.set(e.user.userId,e);const r=new Set([e.range.anchor.blockId,e.range.focus.blockId]),i=new Set(r);o&&new Set([o.range.anchor.blockId,o.range.focus.blockId]).forEach(l=>{r.has(l)||i.add(l)}),this.emit("remote-carets-change",[...i])}addUsers(e){this.addingUser=!0,e.forEach(o=>this.addUser(o)),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 o;return(o=this.users.get(e))!=null?o:null}removeUser(e){this.users.delete(e),this.cursors.delete(e),this.emit("change",Array.from(this.users.values()))}updateUsers(e){this.users.clear(),this.addingUser=!0;try{e.forEach(o=>{this.addUser(o)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const o=new Map;return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e&&fh(r.range)).forEach(r=>{const i=r.range.focus.offset;let s=o.get(i);s||(s=[],o.set(i,s)),s.push(r)}),o}getCursors(e){return Array.from(this.cursors.values()).filter(o=>o.range.anchor.blockId===e||o.range.focus.blockId===e)}onUpdateBlockText(e,o,r){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(fh(l.range)){const{anchor:a,focus:d}=l.range;a.blockId===e.id&&(a.offset=ln.transformCursor(a.offset,o,r)),d.blockId===e.id&&(d.offset=ln.transformCursor(d.offset,o,r))}})}getFixedUserColor(e,o){let r=0;Array.from(e).forEach(s=>{r+=s.charCodeAt(0)});const i=r%this.colors.length;return this.colors[i]}destroy(){this.removeAllListeners()}}const Xe=S("local-doc");class np extends fa{constructor(e,o){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[sr("")]}},this.serviceUrl=(o==null?void 0:o.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`);const i=r[o];return g(Xe,i,`no block data: ${o}`),i}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(Xe,i.text,"no text for data");const s=ln.apply(i.text,r);return i.text=s,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockText)==null?void 0:a.call(l,e,o,r,!0)}),s}localUpdateBlockData(e,o,r){const i=this.getBlockData(e,o);return r.delete.forEach(s=>delete i[s]),Object.entries(r.insert).forEach(([s,l])=>{i[s]=l}),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,!0)}),i}localInsertBlock(e,o,r){const i=this.getContainerBlocks(e);return g(Xe,i,`no container data: ${e}`),g(Xe,o>=0&&o<=i.length,`invalid block index: ${o}, ${i.length}`),i.splice(o,0,r),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,o,r,!0)}),r}localDeleteBlock(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`),g(Xe,o>=0&&o<=r.length,`invalid block index: ${o}, ${r.length}`);const i=r[o];return r.splice(o,1),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,!0)}),i}localInsertChildContainer(e,o){this.doc.blocks[e]=o,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,e,o,!0)})}localDeleteChildContainers(e){Xe.debug(`delete child containers: ${e}`),e.forEach(o=>{g(Xe,this.doc.blocks[o],`no child container: ${o}`),delete this.doc.blocks[o]}),e.forEach(o=>{g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,o,!0)})})}uploadResource(e,o){g(Xe,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,o){g(Xe,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new _h}setDoc(e){this.doc=mt.default(e),this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,"change doc")})}destroy(){this.clearCallbacks()}}class FD{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function op(n,t,e){n.addCustom(t,()=>{var i;const o=(i=e())!=null?i:void 0;return new FD(o)})}const hb=S("find-block");function fb(n,t){const e=Ds(t);if(!e){if(ro(t))return null;const o=Is(t);return g(hb,o,"no parent block"),fb(n,o)}return Lt(n,e)?Vl(n,e,{visibleOnly:!0}):e}function mb(n,t){const e=Ss(t);if(!e){if(ro(t))return null;const o=Is(t);return g(hb,o,"no parent block"),mb(n,o)}return Lt(n,e)?eg(n,e,{visibleOnly:!0}):e}const PD=S("remote-cursor");class ND{constructor(){m(this,"remoteUsers",new _h)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const o=e;this.handleUpdateUsers(o.users)}else e.type==="caret"?this.handleUpdateCaret(e):PD.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 $D(n){const{blocks:t,meta:e,comments:o,...r}=n;return{rootBlocks:t,meta:e,comments:o,childBlocks:r}}function HD(n){const{blocks:t,meta:e,comments:o}=n,{root:r,...i}=t;return{blocks:r,meta:e,comments:o,...i}}function ja(n){const{childBlocks:t,meta:e,comments:o,rootBlocks:r}=$D(mt.default(n));return{blocks:{root:r,...t},meta:e,comments:o}}function Ni(n){return n==="root"?"blocks":n}function Xl(n){return n==="blocks"?"root":n}const jD={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new on.default(n)},apply(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},compose(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},diff(n,t){const e=new on.default(n),o=new on.default(t);return e.diff(o).ops},transform(n,t,e){const o=new on.default(n);return new on.default(t).transform(o,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 o=new on.default(t),r=this.transformCursor(n.index,o,e),i=this.transformCursor(n.index+n.length,o,e);return{...n,index:r,length:i-r}}}};var cr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},$i={},rp=Z5.default.EventEmitter;$i.EventEmitter=rp,$i.mixin=UD;function UD(n){for(var t in rp.prototype)n.prototype[t]=rp.prototype[t]}var gb=["info","warn","error"];function pb(){var n={};gb.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var zD=pb;pb.prototype.setMethods=function(n){n=n||{};var t=this;gb.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var VD=zD,WD=new VD,Cb=WD;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 Fh=js,Ua={},Ab=qD;function qD(n,t,e,o){var r=function(s,l,a,d){t(a,s,l,"left"),t(d,l,s,"right")},i=n.transformX=function(s,l){e(s),e(l);for(var a=[],d=0;d<l.length;d++){for(var h=l[d],p=[],A=0;A<s.length;){var v=[];if(r(s[A],h,p,v),A++,v.length===1)h=v[0];else if(v.length===0){for(var B=A;B<s.length;B++)o(p,s[B]);h=null;break}else{for(var D=i(s.slice(A),v),T=0;T<D[0].length;T++)o(p,D[0][T]);for(var _=0;_<D[1].length;_++)o(a,D[1][_]);h=null;break}}h!=null&&o(a,h),s=p}return[s,a]};n.transform=function(s,l,a){if(!(a==="left"||a==="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],a):a==="left"?i(s,l)[0]:i(l,s)[1]}}var bb={exports:{}},Hi=bb.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||""}},ip=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},sp=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")},Ph=function(n){for(var t=0;t<n.length;t++)sp(n[t])};Hi.apply=function(n,t){var e;Ph(t);for(var o=0;o<t.length;o++){var r=t[o];if(r.i!=null)n=ip(n,r.p,r.i);else{if(e=n.slice(r.p,r.p+r.d.length),r.d!==e)throw new Error("Delete component '"+r.d+"' does not match deleted text '"+e+"'");n=n.slice(0,r.p)+n.slice(r.p+r.d.length)}}return n};var Vr=Hi._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:ip(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:ip(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};Hi.compose=function(n,t){Ph(n),Ph(t);for(var e=n.slice(),o=0;o<t.length;o++)Vr(e,t[o]);return e},Hi.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=0),Vr(t,o)}return t};var lp=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};Hi.transformCursor=function(n,t,e){for(var o=e==="right",r=0;r<t.length;r++)n=lp(n,t[r],o);return n};var GD=Hi._tc=function(n,t,e,o){if(sp(t),sp(e),t.i!=null)Vr(n,{i:t.i,p:lp(t.p,e,o==="right")});else if(e.i!=null){var r=t.d;t.p<e.p&&(Vr(n,{d:r.slice(0,e.p-t.p),p:t.p}),r=r.slice(e.p-t.p)),r!==""&&Vr(n,{d:r,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)Vr(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)Vr(n,t);else{var i={d:"",p:t.p};t.p<e.p&&(i.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(i.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),a=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(a!==d)throw new Error("Delete ops delete different text in the same region of the document");i.d!==""&&(i.p=lp(i.p,e),Vr(n,i))}return n},ZD=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};Hi.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=ZD(n[t]);return n},Ab(Hi,GD,Ph,Vr);var Nh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},QD=function(n){return!!n&&n.constructor===Object},_o=function(n){return JSON.parse(JSON.stringify(n))},It={name:"json0",uri:"http://sharejs.org/types/JSONv0"},Wr={};It.registerSubtype=function(n){Wr[n.name]=n},It.create=function(n){return n===void 0?null:_o(n)},It.invertComponent=function(n){var t={p:n.p};return n.t&&Wr[n.t]&&(t.t=n.t,t.o=Wr[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},It.invert=function(n){for(var t=n.slice().reverse(),e=[],o=0;o<t.length;o++)e.push(It.invertComponent(t[o]));return e},It.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!Nh(n[t].p))throw new Error("Missing path")},It.checkList=function(n){if(!Nh(n))throw new Error("Referenced element not a list")},It.checkObj=function(n){if(!QD(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function za(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 Va(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}It.apply=function(n,t){It.checkValidOp(t),t=_o(t);for(var e={data:n},o=0;o<t.length;o++){var r=t[o];(r.si!=null||r.sd!=null)&&za(r);for(var i=null,s=e,l="data",a=0;a<r.p.length;a++){var d=r.p[a];if(i=s,s=s[l],l=d,i==null)throw new Error("Path invalid")}if(r.t&&r.o!==void 0&&Wr[r.t])s[l]=Wr[r.t].apply(s[l],r.o);else if(r.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=r.na}else if(r.li!==void 0&&r.ld!==void 0)It.checkList(s),s[l]=r.li;else if(r.li!==void 0)It.checkList(s),s.splice(l,0,r.li);else if(r.ld!==void 0)It.checkList(s),s.splice(l,1);else if(r.lm!==void 0){if(It.checkList(s),r.lm!=l){var h=s[l];s.splice(l,1),s.splice(r.lm,0,h)}}else if(r.oi!==void 0)It.checkObj(s),s[l]=r.oi;else if(r.od!==void 0)It.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},It.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},It.incrementalApply=function(n,t,e){for(var o=0;o<t.length;o++){var r=[t[o]];n=It.apply(n,r),e(r,n)}return n};var YD=It.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o]&&(!e||o!==n.length-1))return!1;return!0};It.append=function(n,t){if(t=_o(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)&&(za(t),za(e)),YD(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&Wr[t.t]){if(e.o=Wr[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var o=t.p,r=0;r<e.o.length-1;r++)t.o=[e.o.pop()],t.p=o.slice(),Va(t),n.push(t);Va(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)&&(Va(t),Va(e)),n.push(t)},It.compose=function(n,t){It.checkValidOp(n),It.checkValidOp(t);for(var e=_o(n),o=0;o<t.length;o++)It.append(e,t[o]);return e},It.normalize=function(n){var t=[];n=Nh(n)?n:[n];for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=[]),It.append(t,o)}return t},It.commonLengthForOps=function(n,t){var e=n.p.length,o=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&o++,e===0)return-1;if(o===0)return null;e--,o--;for(var r=0;r<e;r++){var i=n.p[r];if(r>=o||i!==t.p[r])return null}return e},It.canOpAffectPath=function(n,t){return It.commonLengthForOps({p:t},n)!=null},It.transformComponent=function(n,t,e,o){t=_o(t);var r=It.commonLengthForOps(e,t),i=It.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,i!=null&&l>s&&t.p[i]==e.p[i]){if(t.ld!==void 0){var a=_o(e);a.p=a.p.slice(s),t.ld=It.apply(_o(t.ld),[a])}else if(t.od!==void 0){var a=_o(e);a.p=a.p.slice(s),t.od=It.apply(_o(t.od),[a])}}if(r!=null){var d=s==l,a=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(za(t),a=_o(e),za(a)),a.t&&Wr[a.t]){if(t.t&&t.t===a.t){var h=Wr[t.t].transform(t.o,a.o,o);if(t.si!=null||t.sd!=null)for(var p=t.p,A=0;A<h.length;A++)t.o=[h[A]],t.p=p.slice(),Va(t),It.append(n,t);else(!Nh(h)||h.length>0)&&(t.o=h,It.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[r]===t.p[r])if(d){if(t.ld!==void 0)if(t.li!==void 0&&o==="left")t.ld=_o(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[r]===e.p[r]?o==="right"&&t.p[r]++:e.p[r]<=t.p[r]&&t.p[r]++,t.lm!==void 0&&d&&e.p[r]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[r]===t.p[r])return n;var p=e.p[r],v=t.p[r],B=t.lm;(p<B||p===B&&v<B)&&t.lm--}if(e.p[r]<t.p[r])t.p[r]--;else if(e.p[r]===t.p[r]){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 v=t.p[r],B=t.lm,D=e.p[r],T=e.lm;if(D!==T)if(v===D)if(o==="left")t.p[r]=T,v===B&&(t.lm=T);else return n;else v>D&&t.p[r]--,v>T?t.p[r]++:v===T&&D>T&&(t.p[r]++,v===B&&t.lm++),(B>D||B===D&&B>v)&&t.lm--,B>T?t.lm++:B===T&&(T>D&&B>v||T<D&&B<v?o==="right"&&t.lm++:B>v?t.lm++:B===D&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var v=e.p[r],B=e.lm;p=t.p[r],p>v&&t.p[r]--,p>B&&t.p[r]++}else{var v=e.p[r],B=e.lm;p=t.p[r],p===v?t.p[r]=B:(p>v&&t.p[r]--,(p>B||p===B&&v>B)&&t.p[r]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[r]===e.p[r])if(t.oi!==void 0&&d){if(o==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[r]===e.p[r])if(o==="left")It.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[r]==e.p[r]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return It.append(n,t),n},Ab(It,It.transformComponent,It.checkValidOp,It.append);var JD=bb.exports;It.registerSubtype(JD);var KD=It,XD={type:KD};(function(n){n.defaultType=XD.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)})(Ua);var Fo={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var o 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],o=1;o<arguments.length;o++){var r=arguments[o];e=e[r]||(o===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],o=arguments[arguments.length-1],r=1;r<arguments.length-1;r++){var i=arguments[r];e=e[i]||(e[i]=r===arguments.length-2?o():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],o=[e],r=1;r<arguments.length-1;r++){var i=arguments[r];if(!e.hasOwnProperty(i))break;e=e[i],o.push(e)}for(var r=o.length-1;r>=0;r--){var s=o[r],i=arguments[r+1],l=s[i];(r===o.length-1||!n.hasKeys(l))&&delete s[i]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,o){var r=!1;return e.forEach(function(i){i&&(i(o),r=!0)}),r},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];setTimeout(function(){e.apply(null,o)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(Fo);var vb=Array.isArray,yb=Object.keys,tS=Object.prototype.hasOwnProperty,eS=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var o=vb(t),r=vb(e),i,s,l;if(o&&r){if(s=t.length,s!=e.length)return!1;for(i=s;i--!==0;)if(!n(t[i],e[i]))return!1;return!0}if(o!=r)return!1;var a=t instanceof Date,d=e instanceof Date;if(a!=d)return!1;if(a&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,p=e instanceof RegExp;if(h!=p)return!1;if(h&&p)return t.toString()==e.toString();var A=yb(t);if(s=A.length,s!==yb(e).length)return!1;for(i=s;i--!==0;)if(!tS.call(e,A[i]))return!1;for(i=s;i--!==0;)if(l=A[i],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},kb=$i,nS=Cb,Wn=Fh,$h=Ua,Po=Fo,oS=Po.clone,rS=eS,Tn=Wn.CODES,iS=Ft;function Ft(n,t,e){kb.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}kb.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=$h.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new Wn(Tn.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 Wn(Tn.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 Wn(Tn.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 o=n.type===void 0?$h.defaultType:n.type;this._setType(o),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;Po.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===Tn.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 o=this.inflightFetch.shift();if(o&&e.push(o),e.length&&(o=function(r){Po.callEach(e,r)}),n)return this._emitResponseError(n,o);this.ingestSnapshot(t,o),this._emitNothingPending()},Ft.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var o=this.pendingFetch;this.pendingFetch=[],e.callback&&o.push(e.callback);var r;if(o.length&&(r=function(i){Po.callEach(o,i)}),n)return this._emitResponseError(n,r);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,r):r&&r(),this._emitNothingPending(),this._flushSubscribe()},Ft.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Tn.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=Hh(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var o=0;o<this.pendingOps.length;o++){var e=Hh(this.pendingOps[o],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}}},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);sS(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,o=e&&e.wantSubscribe===n;if(o){e.callback=lS([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;Po.nextTick(function(){n._handleSubscribe()})}}};function sS(n,t,e){if(t){var o=n.pop();n.push(function(r){o&&o(r),e&&e(r)})}else n.push(e)}function lS(n){return n=n.filter(Po.truthy),n.length?function(t){Po.callEach(n,t)}:null}Ft.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function cS(n){delete n.op,delete n.create,delete n.del}function Hh(n,t){if(n.del)return cS(t);if(t.del)return new Wn(Tn.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new Wn(Tn.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new Wn(Tn.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 o=n.type.transform(n.op,t.op,"left"),r=n.type.transform(t.op,n.op,"right");n.op=o,t.op=r}}}Ft.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new Wn(Tn.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===$h.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,o=0;o<n.op.length;o++){var r=n.op[o],i={op:[r]};this.emit("before op",i.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=Hh(this.applyStack[s],i);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,i.op)),this.emit("op",i.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 a=this.data;this._setType(null),this.emit("del",a,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 Wn(Tn.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>=Po.MAX_SAFE_INTEGER)return this.emit("error",new Wn(Tn.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 o=new Wn(Tn.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(o):this.emit("error",o)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(i){return this._hardRollback(i)}var r=this;Po.nextTick(function(){r.flush()})},Ft.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var o=this._tryCompose(n);if(o){o.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 o=this.pendingOps.splice(e),e=0;e<o.length;e++){var t=o[e],r=this._tryCompose(t);r?r.callbacks=r.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&&!rS(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 o={op:n},r=t&&t.source;this._submit(o,r,e)},Ft.prototype.create=function(n,t,e,o){if(typeof t=="function"?(o=t,e=null,t=null):typeof e=="function"&&(o=e,e=null),t||(t=$h.defaultType.uri),this.type){var r=new Wn(Tn.ERR_DOC_ALREADY_CREATED,"Document already exists");return o?o(r):this.emit("error",r)}var i={create:{type:t,data:n}},s=e&&e.source;this._submit(i,s,o)},Ft.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new Wn(Tn.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var o={del:!0},r=n&&n.source;this._submit(o,r,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:oS(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 nS.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 o=Hh(this.pendingOps[e],t);if(o)return this._hardRollback(o)}try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}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 o=!!t.length,r=0;r<t.length;r++)o=Po.callEach(t[r].callbacks,n)&&o;if(n&&!o)return e.emit("error",n)})},Ft.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=Po.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var Us={};Us.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 wb=$i,Bb=Us.ACTIONS,aS=Fo,uS=Dn;function Dn(n,t,e,o,r,i,s){wb.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=o,this.query=r,this.results=null,i&&i.results&&(this.results=i.results,delete i.results),this.extra=void 0,this.options=i,this.callback=s,this.ready=!1,this.sent=!1}wb.mixin(Dn),Dn.prototype.hasPending=function(){return!this.ready},Dn.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 o=this.results[e];t.push([o.id,o.version])}n.r=t}this.connection.send(n),this.sent=!0}},Dn.prototype.destroy=function(n){this.connection.canSend&&this.action===Bb.querySubscribe&&this.connection.send({a:Bb.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&aS.nextTick(n)},Dn.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},Dn.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},Dn.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},Dn.prototype._handleResponse=function(n,t,e){var o=this.callback;if(this.callback=null,n)return this._finishResponse(n,o);if(!t)return this._finishResponse(null,o);var r=this,i=1,s=function(h){if(h)return r._finishResponse(h,o);--i||r._finishResponse(null,o)};if(Array.isArray(t))i+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){i++;var a=t[l],d=this.connection.get(a.c||this.collection,l);d.ingestSnapshot(a,s)}s()},Dn.prototype._ingestSnapshots=function(n,t){for(var e=[],o=0;o<n.length;o++){var r=n[o],i=this.connection.get(r.c||this.collection,r.d);i.ingestSnapshot(r,t),e.push(i)}return e},Dn.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)},Dn.prototype._handleError=function(n){this.emit("error",n)},Dn.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 o=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(o)),this.emit("insert",o,e.index);break;case"remove":var i=e.howMany||1,r=this.results.splice(e.index,i);this.emit("remove",r,e.index);break;case"move":var i=e.howMany||1,s=this.results.splice(e.from,i);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)},Dn.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var Eb=$i,dS=Us.ACTIONS,hS=Fo,xb=ar;function ar(n,t){if(Eb.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={}}Eb.mixin(ar),ar.prototype.submit=function(n,t){this.value=n,this.send(t)},ar.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},ar.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()})},ar.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},ar.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},ar.prototype._message=function(){return{a:dS.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},ar.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},ar.prototype._callbackOrEmit=function(n,t){if(t)return hS.nextTick(t,n);n&&this.emit("error",n)};var fS=Fo,Ib=cp;function cp(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}cp.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},cp.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&fS.nextTick(n)};var ap={exports:{}};(function(n,t){(function(e,o){o(t)})(cr,function(e){function o(k,I){I=I|0;for(var L=Math.max(k.length-I,0),F=Array(L),U=0;U<L;U++)F[U]=k[I+U];return F}var r=function(k){var I=o(arguments,1);return function(){var L=o(arguments);return k.apply(null,I.concat(L))}},i=function(k){return function(){var I=o(arguments),L=I.pop();k.call(this,I,L)}};function s(k){var I=typeof k;return k!=null&&(I=="object"||I=="function")}var l=typeof setImmediate=="function"&&setImmediate,a=typeof process=="object"&&typeof process.nextTick=="function";function d(k){setTimeout(k,0)}function h(k){return function(I){var L=o(arguments,1);k(function(){I.apply(null,L)})}}var p;l?p=setImmediate:a?p=process.nextTick:p=d;var A=h(p);function v(k){return i(function(I,L){var F;try{F=k.apply(this,I)}catch(U){return L(U)}s(F)&&typeof F.then=="function"?F.then(function(U){B(L,null,U)},function(U){B(L,U.message?U:new Error(U))}):L(null,F)})}function B(k,I,L){try{k(I,L)}catch(F){A(D,F)}}function D(k){throw k}var T=typeof Symbol=="function";function _(k){return T&&k[Symbol.toStringTag]==="AsyncFunction"}function M(k){return _(k)?v(k):k}function H(k){return function(I){var L=o(arguments,1),F=i(function(U,j){var Z=this;return k(I,function(J,lt){M(J).apply(Z,U.concat(lt))},j)});return L.length?F.apply(this,L):F}}var z=typeof cr=="object"&&cr&&cr.Object===Object&&cr,q=typeof self=="object"&&self&&self.Object===Object&&self,rt=z||q||Function("return this")(),ft=rt.Symbol,Bt=Object.prototype,jt=Bt.hasOwnProperty,Ut=Bt.toString,ee=ft?ft.toStringTag:void 0;function Ye(k){var I=jt.call(k,ee),L=k[ee];try{k[ee]=void 0;var F=!0}catch{}var U=Ut.call(k);return F&&(I?k[ee]=L:delete k[ee]),U}var Wo=Object.prototype,Ne=Wo.toString;function Ln(k){return Ne.call(k)}var vr="[object Null]",bn="[object Undefined]",an=ft?ft.toStringTag:void 0;function yr(k){return k==null?k===void 0?bn:vr:an&&an in Object(k)?Ye(k):Ln(k)}var ei="[object AsyncFunction]",mo="[object Function]",t3="[object GeneratorFunction]",e3="[object Proxy]";function n3(k){if(!s(k))return!1;var I=yr(k);return I==mo||I==t3||I==ei||I==e3}var ns=9007199254740991;function ol(k){return typeof k=="number"&&k>-1&&k%1==0&&k<=ns}function rl(k){return k!=null&&ol(k.length)&&!n3(k)}var ni={};function Nt(){}function kr(k){return function(){if(k!==null){var I=k;k=null,I.apply(this,arguments)}}}var os=typeof Symbol=="function"&&Symbol.iterator,Pc=function(k){return os&&k[os]&&k[os]()};function s1(k,I){for(var L=-1,F=Array(k);++L<k;)F[L]=I(L);return F}function un(k){return k!=null&&typeof k=="object"}var il="[object Arguments]";function l1(k){return un(k)&&yr(k)==il}var go=Object.prototype,c1=go.hasOwnProperty,o3=go.propertyIsEnumerable,sl=l1(function(){return arguments}())?l1:function(k){return un(k)&&c1.call(k,"callee")&&!o3.call(k,"callee")},Ce=Array.isArray;function ll(){return!1}var cl=typeof e=="object"&&e&&!e.nodeType&&e,a1=cl&&!0&&n&&!n.nodeType&&n,al=a1&&a1.exports===cl,u1=al?rt.Buffer:void 0,ul=u1?u1.isBuffer:void 0,rs=ul||ll,Hu=9007199254740991,ju=/^(?:0|[1-9]\d*)$/;function Uu(k,I){var L=typeof k;return I=I==null?Hu:I,!!I&&(L=="number"||L!="symbol"&&ju.test(k))&&k>-1&&k%1==0&&k<I}var zu="[object Arguments]",Vu="[object Array]",Wu="[object Boolean]",qu="[object Date]",Gu="[object Error]",Zu="[object Function]",r3="[object Map]",i3="[object Number]",s3="[object Object]",d1="[object RegExp]",h1="[object Set]",l3="[object String]",c3="[object WeakMap]",a3="[object ArrayBuffer]",u3="[object DataView]",f1="[object Float32Array]",d3="[object Float64Array]",h3="[object Int8Array]",f3="[object Int16Array]",Qu="[object Int32Array]",m3="[object Uint8Array]",Yu="[object Uint8ClampedArray]",g3="[object Uint16Array]",p3="[object Uint32Array]",ie={};ie[f1]=ie[d3]=ie[h3]=ie[f3]=ie[Qu]=ie[m3]=ie[Yu]=ie[g3]=ie[p3]=!0,ie[zu]=ie[Vu]=ie[a3]=ie[Wu]=ie[u3]=ie[qu]=ie[Gu]=ie[Zu]=ie[r3]=ie[i3]=ie[s3]=ie[d1]=ie[h1]=ie[l3]=ie[c3]=!1;function C3(k){return un(k)&&ol(k.length)&&!!ie[yr(k)]}function A3(k){return function(I){return k(I)}}var m1=typeof e=="object"&&e&&!e.nodeType&&e,dl=m1&&!0&&n&&!n.nodeType&&n,b3=dl&&dl.exports===m1,Nc=b3&&z.process,g1=function(){try{var k=dl&&dl.require&&dl.require("util").types;return k||Nc&&Nc.binding&&Nc.binding("util")}catch{}}(),p1=g1&&g1.isTypedArray,v3=p1?A3(p1):C3,y3=Object.prototype,k3=y3.hasOwnProperty;function w3(k,I){var L=Ce(k),F=!L&&sl(k),U=!L&&!F&&rs(k),j=!L&&!F&&!U&&v3(k),Z=L||F||U||j,J=Z?s1(k.length,String):[],lt=J.length;for(var pt in k)(I||k3.call(k,pt))&&!(Z&&(pt=="length"||U&&(pt=="offset"||pt=="parent")||j&&(pt=="buffer"||pt=="byteLength"||pt=="byteOffset")||Uu(pt,lt)))&&J.push(pt);return J}var $c=Object.prototype;function B3(k){var I=k&&k.constructor,L=typeof I=="function"&&I.prototype||$c;return k===L}function Hc(k,I){return function(L){return k(I(L))}}var E3=Hc(Object.keys,Object),x3=Object.prototype,I3=x3.hasOwnProperty;function C1(k){if(!B3(k))return E3(k);var I=[];for(var L in Object(k))I3.call(k,L)&&L!="constructor"&&I.push(L);return I}function jc(k){return rl(k)?w3(k):C1(k)}function A1(k){var I=-1,L=k.length;return function(){return++I<L?{value:k[I],key:I}:null}}function T3(k){var I=-1;return function(){var F=k.next();return F.done?null:(I++,{value:F.value,key:I})}}function D3(k){var I=jc(k),L=-1,F=I.length;return function U(){var j=I[++L];return j==="__proto__"?U():L<F?{value:k[j],key:j}:null}}function S3(k){if(rl(k))return A1(k);var I=Pc(k);return I?T3(I):D3(k)}function po(k){return function(){if(k===null)throw new Error("Callback was already called.");var I=k;k=null,I.apply(this,arguments)}}function hl(k){return function(I,L,F){if(F=kr(F||Nt),k<=0||!I)return F(null);var U=S3(I),j=!1,Z=0,J=!1;function lt(ct,At){if(Z-=1,ct)j=!0,F(ct);else{if(At===ni||j&&Z<=0)return j=!0,F(null);J||pt()}}function pt(){for(J=!0;Z<k&&!j;){var ct=U();if(ct===null){j=!0,Z<=0&&F(null);return}Z+=1,L(ct.value,ct.key,po(lt))}J=!1}pt()}}function wr(k,I,L,F){hl(I)(k,M(L),F)}function $e(k,I){return function(L,F,U){return k(L,I,F,U)}}function Ju(k,I,L){L=kr(L||Nt);var F=0,U=0,j=k.length;j===0&&L(null);function Z(J,lt){J?L(J):(++U===j||lt===ni)&&L(null)}for(;F<j;F++)I(k[F],F,po(Z))}var L3=$e(wr,1/0),qo=function(k,I,L){var F=rl(k)?Ju:L3;F(k,M(I),L)};function Go(k){return function(I,L,F){return k(qo,I,M(L),F)}}function Ku(k,I,L,F){F=F||Nt,I=I||[];var U=[],j=0,Z=M(L);k(I,function(J,lt,pt){var ct=j++;Z(J,function(At,Gt){U[ct]=Gt,pt(At)})},function(J){F(J,U)})}var Uc=Go(Ku),Xu=H(Uc);function oi(k){return function(I,L,F,U){return k(hl(L),I,M(F),U)}}var Br=oi(Ku),td=$e(Br,1),ed=H(td);function is(k,I){for(var L=-1,F=k==null?0:k.length;++L<F&&I(k[L],L,k)!==!1;);return k}function nd(k){return function(I,L,F){for(var U=-1,j=Object(I),Z=F(I),J=Z.length;J--;){var lt=Z[k?J:++U];if(L(j[lt],lt,j)===!1)break}return I}}var ss=nd();function ls(k,I){return k&&ss(k,I,jc)}function b1(k,I,L,F){for(var U=k.length,j=L+(F?1:-1);F?j--:++j<U;)if(I(k[j],j,k))return j;return-1}function M3(k){return k!==k}function v1(k,I,L){for(var F=L-1,U=k.length;++F<U;)if(k[F]===I)return F;return-1}function fl(k,I,L){return I===I?v1(k,I,L):b1(k,M3,L)}var zc=function(k,I,L){typeof I=="function"&&(L=I,I=null),L=kr(L||Nt);var F=jc(k),U=F.length;if(!U)return L(null);I||(I=U);var j={},Z=0,J=!1,lt=Object.create(null),pt=[],ct=[],At={};ls(k,function(de,oe){if(!Ce(de)){Gt(oe,[de]),ct.push(oe);return}var ge=de.slice(0,de.length-1),Ao=ge.length;if(Ao===0){Gt(oe,de),ct.push(oe);return}At[oe]=Ao,is(ge,function(E){if(!k[E])throw new Error("async.auto task `"+oe+"` has a non-existent dependency `"+E+"` in "+ge.join(", "));en(E,function(){Ao--,Ao===0&&Gt(oe,de)})})}),t5(),Ie();function Gt(de,oe){pt.push(function(){Co(de,oe)})}function Ie(){if(pt.length===0&&Z===0)return L(null,j);for(;pt.length&&Z<I;){var de=pt.shift();de()}}function en(de,oe){var ge=lt[de];ge||(ge=lt[de]=[]),ge.push(oe)}function On(de){var oe=lt[de]||[];is(oe,function(ge){ge()}),Ie()}function Co(de,oe){if(!J){var ge=po(function(E,Ir){if(Z--,arguments.length>2&&(Ir=o(arguments,1)),E){var ds={};ls(j,function(_n,Pt){ds[Pt]=_n}),ds[de]=Ir,J=!0,lt=Object.create(null),L(E,ds)}else j[de]=Ir,On(de)});Z++;var Ao=M(oe[oe.length-1]);oe.length>1?Ao(j,ge):Ao(ge)}}function t5(){for(var de,oe=0;ct.length;)de=ct.pop(),oe++,is(e5(de),function(ge){--At[ge]===0&&ct.push(ge)});if(oe!==U)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function e5(de){var oe=[];return ls(k,function(ge,Ao){Ce(ge)&&fl(ge,de,0)>=0&&oe.push(Ao)}),oe}};function ri(k,I){for(var L=-1,F=k==null?0:k.length,U=Array(F);++L<F;)U[L]=I(k[L],L,k);return U}var R3="[object Symbol]";function O3(k){return typeof k=="symbol"||un(k)&&yr(k)==R3}var _3=1/0,od=ft?ft.prototype:void 0,y1=od?od.toString:void 0;function rd(k){if(typeof k=="string")return k;if(Ce(k))return ri(k,rd)+"";if(O3(k))return y1?y1.call(k):"";var I=k+"";return I=="0"&&1/k==-_3?"-0":I}function F3(k,I,L){var F=-1,U=k.length;I<0&&(I=-I>U?0:U+I),L=L>U?U:L,L<0&&(L+=U),U=I>L?0:L-I>>>0,I>>>=0;for(var j=Array(U);++F<U;)j[F]=k[F+I];return j}function P3(k,I,L){var F=k.length;return L=L===void 0?F:L,!I&&L>=F?k:F3(k,I,L)}function id(k,I){for(var L=k.length;L--&&fl(I,k[L],0)>-1;);return L}function N3(k,I){for(var L=-1,F=k.length;++L<F&&fl(I,k[L],0)>-1;);return L}function $3(k){return k.split("")}var H3="\\ud800-\\udfff",j3="\\u0300-\\u036f",U3="\\ufe20-\\ufe2f",se="\\u20d0-\\u20ff",ne=j3+U3+se,z3="\\ufe0e\\ufe0f",V3="\\u200d",W3=RegExp("["+V3+H3+ne+z3+"]");function q3(k){return W3.test(k)}var k1="\\ud800-\\udfff",G3="\\u0300-\\u036f",w1="\\ufe20-\\ufe2f",Z3="\\u20d0-\\u20ff",qe=G3+w1+Z3,sd="\\ufe0e\\ufe0f",ii="["+k1+"]",Vc="["+qe+"]",ml="\\ud83c[\\udffb-\\udfff]",Mn="(?:"+Vc+"|"+ml+")",ld="[^"+k1+"]",cd="(?:\\ud83c[\\udde6-\\uddff]){2}",ad="[\\ud800-\\udbff][\\udc00-\\udfff]",B1="\\u200d",ud=Mn+"?",dd="["+sd+"]?",vn="(?:"+B1+"(?:"+[ld,cd,ad].join("|")+")"+dd+ud+")*",Q3=dd+ud+vn,Rn="(?:"+[ld+Vc+"?",Vc,cd,ad,ii].join("|")+")",Y3=RegExp(ml+"(?="+ml+")|"+Rn+Q3,"g");function E1(k){return k.match(Y3)||[]}function Zo(k){return q3(k)?E1(k):$3(k)}function Wc(k){return k==null?"":rd(k)}var hd=/^\s+|\s+$/g;function ue(k,I,L){if(k=Wc(k),k&&(L||I===void 0))return k.replace(hd,"");if(!k||!(I=rd(I)))return k;var F=Zo(k),U=Zo(I),j=N3(F,U),Z=id(F,U)+1;return P3(F,j,Z).join("")}var Er=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,fd=/,/,J3=/(=.+)?(\s*)$/,md=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function K3(k){return k=k.toString().replace(md,""),k=k.match(Er)[2].replace(" ",""),k=k?k.split(fd):[],k=k.map(function(I){return ue(I.replace(J3,""))}),k}function x1(k,I){var L={};ls(k,function(F,U){var j,Z=_(F),J=!Z&&F.length===1||Z&&F.length===0;if(Ce(F))j=F.slice(0,-1),F=F[F.length-1],L[U]=j.concat(j.length>0?lt:F);else if(J)L[U]=F;else{if(j=K3(F),F.length===0&&!Z&&j.length===0)throw new Error("autoInject task functions require explicit parameters.");Z||j.pop(),L[U]=j.concat(lt)}function lt(pt,ct){var At=ri(j,function(Gt){return pt[Gt]});At.push(ct),M(F).apply(null,At)}}),zc(L,I)}function Yn(){this.head=this.tail=null,this.length=0}function gd(k,I){k.length=1,k.head=k.tail=I}Yn.prototype.removeLink=function(k){return k.prev?k.prev.next=k.next:this.head=k.next,k.next?k.next.prev=k.prev:this.tail=k.prev,k.prev=k.next=null,this.length-=1,k},Yn.prototype.empty=function(){for(;this.head;)this.shift();return this},Yn.prototype.insertAfter=function(k,I){I.prev=k,I.next=k.next,k.next?k.next.prev=I:this.tail=I,k.next=I,this.length+=1},Yn.prototype.insertBefore=function(k,I){I.prev=k.prev,I.next=k,k.prev?k.prev.next=I:this.head=I,k.prev=I,this.length+=1},Yn.prototype.unshift=function(k){this.head?this.insertBefore(this.head,k):gd(this,k)},Yn.prototype.push=function(k){this.tail?this.insertAfter(this.tail,k):gd(this,k)},Yn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},Yn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},Yn.prototype.toArray=function(){for(var k=Array(this.length),I=this.head,L=0;L<this.length;L++)k[L]=I.data,I=I.next;return k},Yn.prototype.remove=function(k){for(var I=this.head;I;){var L=I.next;k(I)&&this.removeLink(I),I=L}return this};function gl(k,I,L){if(I==null)I=1;else if(I===0)throw new Error("Concurrency must not be zero");var F=M(k),U=0,j=[],Z=!1;function J(At,Gt,Ie){if(Ie!=null&&typeof Ie!="function")throw new Error("task callback must be a function");if(ct.started=!0,Ce(At)||(At=[At]),At.length===0&&ct.idle())return A(function(){ct.drain()});for(var en=0,On=At.length;en<On;en++){var Co={data:At[en],callback:Ie||Nt};Gt?ct._tasks.unshift(Co):ct._tasks.push(Co)}Z||(Z=!0,A(function(){Z=!1,ct.process()}))}function lt(At){return function(Gt){U-=1;for(var Ie=0,en=At.length;Ie<en;Ie++){var On=At[Ie],Co=fl(j,On,0);Co===0?j.shift():Co>0&&j.splice(Co,1),On.callback.apply(On,arguments),Gt!=null&&ct.error(Gt,On.data)}U<=ct.concurrency-ct.buffer&&ct.unsaturated(),ct.idle()&&ct.drain(),ct.process()}}var pt=!1,ct={_tasks:new Yn,concurrency:I,payload:L,saturated:Nt,unsaturated:Nt,buffer:I/4,empty:Nt,drain:Nt,error:Nt,started:!1,paused:!1,push:function(At,Gt){J(At,!1,Gt)},kill:function(){ct.drain=Nt,ct._tasks.empty()},unshift:function(At,Gt){J(At,!0,Gt)},remove:function(At){ct._tasks.remove(At)},process:function(){if(!pt){for(pt=!0;!ct.paused&&U<ct.concurrency&&ct._tasks.length;){var At=[],Gt=[],Ie=ct._tasks.length;ct.payload&&(Ie=Math.min(Ie,ct.payload));for(var en=0;en<Ie;en++){var On=ct._tasks.shift();At.push(On),j.push(On),Gt.push(On.data)}U+=1,ct._tasks.length===0&&ct.empty(),U===ct.concurrency&&ct.saturated();var Co=po(lt(At));F(Gt,Co)}pt=!1}},length:function(){return ct._tasks.length},running:function(){return U},workersList:function(){return j},idle:function(){return ct._tasks.length+U===0},pause:function(){ct.paused=!0},resume:function(){ct.paused!==!1&&(ct.paused=!1,A(ct.process))}};return ct}function si(k,I){return gl(k,1,I)}var cs=$e(wr,1);function Qo(k,I,L,F){F=kr(F||Nt);var U=M(L);cs(k,function(j,Z,J){U(I,j,function(lt,pt){I=pt,J(lt)})},function(j){F(j,I)})}function qc(){var k=ri(arguments,M);return function(){var I=o(arguments),L=this,F=I[I.length-1];typeof F=="function"?I.pop():F=Nt,Qo(k,I,function(U,j,Z){j.apply(L,U.concat(function(J){var lt=o(arguments,1);Z(J,lt)}))},function(U,j){F.apply(L,[U].concat(j))})}}var Gc=function(){return qc.apply(null,o(arguments).reverse())},pd=Array.prototype.concat,pl=function(k,I,L,F){F=F||Nt;var U=M(L);Br(k,I,function(j,Z){U(j,function(J){return J?Z(J):Z(null,o(arguments,1))})},function(j,Z){for(var J=[],lt=0;lt<Z.length;lt++)Z[lt]&&(J=pd.apply(J,Z[lt]));return F(j,J)})},I1=$e(pl,1/0),Zc=$e(pl,1),Qc=function(){var k=o(arguments),I=[null].concat(k);return function(){var L=arguments[arguments.length-1];return L.apply(this,I)}};function Cl(k){return k}function li(k,I){return function(L,F,U,j){j=j||Nt;var Z=!1,J;L(F,function(lt,pt,ct){U(lt,function(At,Gt){At?ct(At):k(Gt)&&!J?(Z=!0,J=I(!0,lt),ct(null,ni)):ct()})},function(lt){lt?j(lt):j(null,Z?J:I(!1))})}}function dn(k,I){return I}var as=Go(li(Cl,dn)),Yo=oi(li(Cl,dn)),Al=$e(Yo,1);function Cd(k){return function(I){var L=o(arguments,1);L.push(function(F){var U=o(arguments,1);typeof console=="object"&&(F?console.error&&console.error(F):console[k]&&is(U,function(j){console[k](j)}))}),M(I).apply(null,L)}}var T1=Cd("dir");function D1(k,I,L){L=po(L||Nt);var F=M(k),U=M(I);function j(J){if(J)return L(J);var lt=o(arguments,1);lt.push(Z),U.apply(this,lt)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}Z(null,!0)}function Ad(k,I,L){L=po(L||Nt);var F=M(k),U=function(j){if(j)return L(j);var Z=o(arguments,1);if(I.apply(this,Z))return F(U);L.apply(null,[null].concat(Z))};F(U)}function S1(k,I,L){Ad(k,function(){return!I.apply(this,arguments)},L)}function L1(k,I,L){L=po(L||Nt);var F=M(I),U=M(k);function j(J){if(J)return L(J);U(Z)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}U(Z)}function ci(k){return function(I,L,F){return k(I,F)}}function Yc(k,I,L){qo(k,ci(M(I)),L)}function bl(k,I,L,F){hl(I)(k,ci(M(L)),F)}var ai=$e(bl,1);function Jc(k){return _(k)?k:i(function(I,L){var F=!0;I.push(function(){var U=arguments;F?A(function(){L.apply(null,U)}):L.apply(null,U)}),k.apply(this,I),F=!1})}function Jn(k){return!k}var ui=Go(li(Jn,Jn)),vl=oi(li(Jn,Jn)),Kc=$e(vl,1);function M1(k){return function(I){return I==null?void 0:I[k]}}function us(k,I,L,F){var U=new Array(I.length);k(I,function(j,Z,J){L(j,function(lt,pt){U[Z]=!!pt,J(lt)})},function(j){if(j)return F(j);for(var Z=[],J=0;J<I.length;J++)U[J]&&Z.push(I[J]);F(null,Z)})}function Kn(k,I,L,F){var U=[];k(I,function(j,Z,J){L(j,function(lt,pt){lt?J(lt):(pt&&U.push({index:Z,value:j}),J())})},function(j){j?F(j):F(null,ri(U.sort(function(Z,J){return Z.index-J.index}),M1("value")))})}function Xc(k,I,L,F){var U=rl(I)?us:Kn;U(k,I,M(L),F||Nt)}var ta=Go(Xc),yl=oi(Xc),ea=$e(yl,1);function R1(k,I){var L=po(I||Nt),F=M(Jc(k));function U(j){if(j)return L(j);F(U)}U()}var na=function(k,I,L,F){F=F||Nt;var U=M(L);Br(k,I,function(j,Z){U(j,function(J,lt){return J?Z(J):Z(null,{key:lt,val:j})})},function(j,Z){for(var J={},lt=Object.prototype.hasOwnProperty,pt=0;pt<Z.length;pt++)if(Z[pt]){var ct=Z[pt].key,At=Z[pt].val;lt.call(J,ct)?J[ct].push(At):J[ct]=[At]}return F(j,J)})},di=$e(na,1/0),N=$e(na,1),G=Cd("log");function V(k,I,L,F){F=kr(F||Nt);var U={},j=M(L);wr(k,I,function(Z,J,lt){j(Z,J,function(pt,ct){if(pt)return lt(pt);U[J]=ct,lt()})},function(Z){F(Z,U)})}var ht=$e(V,1/0),Et=$e(V,1);function Vt(k,I){return I in k}function we(k,I){var L=Object.create(null),F=Object.create(null);I=I||Cl;var U=M(k),j=i(function(J,lt){var pt=I.apply(null,J);Vt(L,pt)?A(function(){lt.apply(null,L[pt])}):Vt(F,pt)?F[pt].push(lt):(F[pt]=[lt],U.apply(null,J.concat(function(){var ct=o(arguments);L[pt]=ct;var At=F[pt];delete F[pt];for(var Gt=0,Ie=At.length;Gt<Ie;Gt++)At[Gt].apply(null,ct)})))});return j.memo=L,j.unmemoized=k,j}var qt;a?qt=process.nextTick:l?qt=setImmediate:qt=d;var oa=h(qt);function bd(k,I,L){L=L||Nt;var F=rl(I)?[]:{};k(I,function(U,j,Z){M(U)(function(J,lt){arguments.length>2&&(lt=o(arguments,1)),F[j]=lt,Z(J)})},function(U){L(U,F)})}function yn(k,I){bd(qo,k,I)}function kl(k,I,L){bd(hl(I),k,L)}var vd=function(k,I){var L=M(k);return gl(function(F,U){L(F[0],U)},I,1)},hi=function(k,I){var L=vd(k,I);return L.push=function(F,U,j){if(j==null&&(j=Nt),typeof j!="function")throw new Error("task callback must be a function");if(L.started=!0,Ce(F)||(F=[F]),F.length===0)return A(function(){L.drain()});U=U||0;for(var Z=L._tasks.head;Z&&U>=Z.priority;)Z=Z.next;for(var J=0,lt=F.length;J<lt;J++){var pt={data:F[J],priority:U,callback:j};Z?L._tasks.insertBefore(Z,pt):L._tasks.push(pt)}A(L.process)},delete L.unshift,L};function wl(k,I){if(I=kr(I||Nt),!Ce(k))return I(new TypeError("First argument to race must be an array of functions"));if(!k.length)return I();for(var L=0,F=k.length;L<F;L++)M(k[L])(I)}function fi(k,I,L,F){var U=o(k).reverse();Qo(U,I,L,F)}function Wt(k){var I=M(k);return i(function(F,U){return F.push(function(Z,J){if(Z)U(null,{error:Z});else{var lt;arguments.length<=2?lt=J:lt=o(arguments,1),U(null,{value:lt})}}),I.apply(this,F)})}function O1(k){var I;return Ce(k)?I=ri(k,Wt):(I={},ls(k,function(L,F){I[F]=Wt.call(this,L)})),I}function yd(k,I,L,F){Xc(k,I,function(U,j){L(U,function(Z,J){j(Z,!J)})},F)}var Bl=Go(yd),kd=oi(yd),_1=$e(kd,1);function F1(k){return function(){return k}}function mi(k,I,L){var F=5,U=0,j={times:F,intervalFunc:F1(U)};function Z(ct,At){if(typeof At=="object")ct.times=+At.times||F,ct.intervalFunc=typeof At.interval=="function"?At.interval:F1(+At.interval||U),ct.errorFilter=At.errorFilter;else if(typeof At=="number"||typeof At=="string")ct.times=+At||F;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof k=="function"?(L=I||Nt,I=k):(Z(j,k),L=L||Nt),typeof I!="function")throw new Error("Invalid arguments for async.retry");var J=M(I),lt=1;function pt(){J(function(ct){ct&<++<j.times&&(typeof j.errorFilter!="function"||j.errorFilter(ct))?setTimeout(pt,j.intervalFunc(lt)):L.apply(null,arguments)})}pt()}var Jo=function(k,I){I||(I=k,k=null);var L=M(I);return i(function(F,U){function j(Z){L.apply(null,F.concat(Z))}k?mi(k,j,U):mi(j,U)})};function El(k,I){bd(cs,k,I)}var xl=Go(li(Boolean,Cl)),xr=oi(li(Boolean,Cl)),Il=$e(xr,1);function wd(k,I,L){var F=M(I);Uc(k,function(j,Z){F(j,function(J,lt){if(J)return Z(J);Z(null,{value:j,criteria:lt})})},function(j,Z){if(j)return L(j);L(null,ri(Z.sort(U),M1("value")))});function U(j,Z){var J=j.criteria,lt=Z.criteria;return J<lt?-1:J>lt?1:0}}function Tl(k,I,L){var F=M(k);return i(function(U,j){var Z=!1,J;function lt(){var pt=k.name||"anonymous",ct=new Error('Callback function "'+pt+'" timed out.');ct.code="ETIMEDOUT",L&&(ct.info=L),Z=!0,j(ct)}U.push(function(){Z||(j.apply(null,arguments),clearTimeout(J))}),J=setTimeout(lt,I),F.apply(null,U)})}var P1=Math.ceil,Dl=Math.max;function gi(k,I,L,F){for(var U=-1,j=Dl(P1((I-k)/(L||1)),0),Z=Array(j);j--;)Z[F?j:++U]=k,k+=L;return Z}function pi(k,I,L,F){var U=M(L);Br(gi(0,k,1),I,U,F)}var N1=$e(pi,1/0),$1=$e(pi,1);function H1(k,I,L,F){arguments.length<=3&&(F=L,L=I,I=Ce(k)?[]:{}),F=kr(F||Nt);var U=M(L);qo(k,function(j,Z,J){U(I,j,Z,J)},function(j){F(j,I)})}function Sl(k,I){var L=null,F;I=I||Nt,ai(k,function(U,j){M(U)(function(Z,J){arguments.length>2?F=o(arguments,1):F=J,L=Z,j(!Z)})},function(){I(L,F)})}function Ll(k){return function(){return(k.unmemoized||k).apply(null,arguments)}}function Ml(k,I,L){L=po(L||Nt);var F=M(I);if(!k())return L(null);var U=function(j){if(j)return L(j);if(k())return F(U);var Z=o(arguments,1);L.apply(null,[null].concat(Z))};F(U)}function j1(k,I,L){Ml(function(){return!k.apply(this,arguments)},I,L)}var Bd=function(k,I){if(I=kr(I||Nt),!Ce(k))return I(new Error("First argument to waterfall must be an array of functions"));if(!k.length)return I();var L=0;function F(j){var Z=M(k[L++]);j.push(po(U)),Z.apply(null,j)}function U(j){if(j||L===k.length)return I.apply(null,arguments);F(o(arguments,1))}F([])},X3={apply:r,applyEach:Xu,applyEachSeries:ed,asyncify:v,auto:zc,autoInject:x1,cargo:si,compose:Gc,concat:I1,concatLimit:pl,concatSeries:Zc,constant:Qc,detect:as,detectLimit:Yo,detectSeries:Al,dir:T1,doDuring:D1,doUntil:S1,doWhilst:Ad,during:L1,each:Yc,eachLimit:bl,eachOf:qo,eachOfLimit:wr,eachOfSeries:cs,eachSeries:ai,ensureAsync:Jc,every:ui,everyLimit:vl,everySeries:Kc,filter:ta,filterLimit:yl,filterSeries:ea,forever:R1,groupBy:di,groupByLimit:na,groupBySeries:N,log:G,map:Uc,mapLimit:Br,mapSeries:td,mapValues:ht,mapValuesLimit:V,mapValuesSeries:Et,memoize:we,nextTick:oa,parallel:yn,parallelLimit:kl,priorityQueue:hi,queue:vd,race:wl,reduce:Qo,reduceRight:fi,reflect:Wt,reflectAll:O1,reject:Bl,rejectLimit:kd,rejectSeries:_1,retry:mi,retryable:Jo,seq:qc,series:El,setImmediate:A,some:xl,someLimit:xr,someSeries:Il,sortBy:wd,timeout:Tl,times:N1,timesLimit:pi,timesSeries:$1,transform:H1,tryEach:Sl,unmemoize:Ll,until:j1,waterfall:Bd,whilst:Ml,all:ui,allLimit:vl,allSeries:Kc,any:xl,anyLimit:xr,anySeries:Il,find:as,findLimit:Yo,findSeries:Al,forEach:Yc,forEachSeries:ai,forEachLimit:bl,forEachOf:qo,forEachOfSeries:cs,forEachOfLimit:wr,inject:Qo,foldl:Qo,foldr:fi,select:ta,selectLimit:yl,selectSeries:ea,wrapSync:v};e.default=X3,e.apply=r,e.applyEach=Xu,e.applyEachSeries=ed,e.asyncify=v,e.auto=zc,e.autoInject=x1,e.cargo=si,e.compose=Gc,e.concat=I1,e.concatLimit=pl,e.concatSeries=Zc,e.constant=Qc,e.detect=as,e.detectLimit=Yo,e.detectSeries=Al,e.dir=T1,e.doDuring=D1,e.doUntil=S1,e.doWhilst=Ad,e.during=L1,e.each=Yc,e.eachLimit=bl,e.eachOf=qo,e.eachOfLimit=wr,e.eachOfSeries=cs,e.eachSeries=ai,e.ensureAsync=Jc,e.every=ui,e.everyLimit=vl,e.everySeries=Kc,e.filter=ta,e.filterLimit=yl,e.filterSeries=ea,e.forever=R1,e.groupBy=di,e.groupByLimit=na,e.groupBySeries=N,e.log=G,e.map=Uc,e.mapLimit=Br,e.mapSeries=td,e.mapValues=ht,e.mapValuesLimit=V,e.mapValuesSeries=Et,e.memoize=we,e.nextTick=oa,e.parallel=yn,e.parallelLimit=kl,e.priorityQueue=hi,e.queue=vd,e.race=wl,e.reduce=Qo,e.reduceRight=fi,e.reflect=Wt,e.reflectAll=O1,e.reject=Bl,e.rejectLimit=kd,e.rejectSeries=_1,e.retry=mi,e.retryable=Jo,e.seq=qc,e.series=El,e.setImmediate=A,e.some=xl,e.someLimit=xr,e.someSeries=Il,e.sortBy=wd,e.timeout=Tl,e.times=N1,e.timesLimit=pi,e.timesSeries=$1,e.transform=H1,e.tryEach=Sl,e.unmemoize=Ll,e.until=j1,e.waterfall=Bd,e.whilst=Ml,e.all=ui,e.allLimit=vl,e.allSeries=Kc,e.any=xl,e.anyLimit=xr,e.anySeries=Il,e.find=as,e.findLimit=Yo,e.findSeries=Al,e.forEach=Yc,e.forEachSeries=ai,e.forEachLimit=bl,e.forEachOf=qo,e.forEachOfSeries=cs,e.forEachOfLimit=wr,e.inject=Qo,e.foldl=Qo,e.foldr=fi,e.select=ta,e.selectLimit=yl,e.selectSeries=ea,e.wrapSync=v,Object.defineProperty(e,"__esModule",{value:!0})})})(ap,ap.exports);var Tb={exports:{}},up=Tb.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),o=2;e===1/0;o*=2)e=Math.log(Math.pow(2,n/o))/Math.log(t)*o;for(var r=e-Math.floor(e),i="",o=0;o<Math.floor(e);o++){var s=Math.floor(Math.random()*t).toString(t);i=s+i}if(r){var l=Math.pow(t,r),s=Math.floor(Math.random()*l).toString(t);i=s+i}var a=parseInt(i,t);return a!==1/0&&a>=Math.pow(2,n)?up(n,t):i};up.rack=function(n,t,e){var o=function(i){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=up(n,t)}while(Object.hasOwnProperty.call(r,l));return r[l]=i,l},r=o.hats={};return o.get=function(i){return o.hats[i]},o.set=function(i,s){return o.hats[i]=s,o},o.bits=n||128,o.base=t||16,o};var Db=$i,mS=xb,gS=Ib,jh=Fo,dp=ap.exports,pS=Tb.exports,Sb=Us.ACTIONS,Lb=Me;function Me(n,t){if(Db.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}Db.mixin(Me),Me.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Me.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Me.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||pS();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Me.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(o){if(o)return t._callbackOrEmit(o,n);var r=Object.keys(t._remotePresenceInstances);dp.parallel([function(i){dp.each(e,function(s,l){t.localPresences[s].destroy(l)},i)},function(i){if(!t._wantsDestroy)return i();dp.each(r,function(s,l){t._remotePresenceInstances[s].destroy(l)},i)}],function(i){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(i,n)})})},Me.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?Sb.presenceSubscribe:Sb.presenceUnsubscribe,o=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[o]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,o,this)},Me.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Me.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Me.prototype._receiveUpdate=function(n,t){var e=jh.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var o=this,r=jh.digOrCreate(this._remotePresenceInstances,t.id,function(){return o._createRemotePresence(t.id)});r.receiveUpdate(t)},Me.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Me.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()}},Me.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Me.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Me.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 o=this;this.subscribe(function(r){o._callEachOrEmit(n,r)})},Me.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Me.prototype._callbackOrEmit=function(n,t){if(t)return jh.nextTick(t,n);n&&this.emit("error",n)},Me.prototype._createLocalPresence=function(n){return new mS(this,n)},Me.prototype._createRemotePresence=function(n){return new gS(this,n)},Me.prototype._callEachOrEmit=function(n,t){var e=jh.callEach(n,t);!e&&t&&this.emit("error",t)};var Wa=xb,Mb=Fh,CS=Fo,Rb=Mb.CODES,AS=No;function No(n,t){Wa.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()}No.prototype=Object.create(Wa.prototype),No.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:Rb.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,Wa.prototype.submit.call(this,n,t)},No.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),Wa.prototype.destroy.call(this,n)},No.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={})})}},No.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)},No.prototype._transformAgainstOp=function(n,t){var e=this,o=this._doc._dataStateVersion;this._pendingMessages.forEach(function(r){var i=e._docDataVersionByPresenceVersion[r.pv];if(!(i>=o))try{r.p=e._transformPresence(r.p,n,t),e._docDataVersionByPresenceVersion[r.pv]=o}catch(l){var s=e._getCallback(r.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(r){this.emit("error",r)}},No.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},No.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},No.prototype._message=function(){var n=Wa.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},No.prototype._transformPresence=function(n,t,e){var o=this._doc.type;if(!CS.supportsPresence(o))throw new Mb(Rb.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+o.name);return o.transformPresence(n,t,e)};var Ob={};(function(n){var t=Ua,e=Fh,o=Fo,r=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var a=l.create.type;if(typeof a!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[a];if(d==null||typeof d!="object")return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(r.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(r.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(r.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(r.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,a){if(typeof l!="object")return new e(r.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&a.v!=null&&l.v!==a.v)return new e(r.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(a.create){if(l.type)return new e(r.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=a.create,h=t.map[d.type];if(!h)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(A){return A}}else if(a.del)l.data=void 0,l.type=null,l.v++;else if("op"in a){var p=i(l,a.op);if(p)return p;l.v++}else l.v++};function i(l,a){if(!l.type)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(a===void 0)return new e(r.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,a)}catch(h){return new e(r.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,a,d){if(a.v!=null&&a.v!==d.v)return new e(r.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(a.create||"op"in a)return new e(r.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in a||a.create||a.del)||"op"in d&&a.create)return new e(r.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in a){if(!l)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{a.op=l.transform(a.op,d.op,"left")}catch(h){return h}}}a.v!=null&&a.v++},n.applyOps=function(l,a,d){d=d||{};for(var h=0;h<a.length;h++){var p=a[h];if(d._normalizeLegacyJson0Ops)try{s(l,p)}catch{return new e(r.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=p.v;var A=n.apply(l,p);if(A)return A}},n.transformPresence=function(l,a,d){var h=this.checkOp(a);if(h)return h;var p=l.t;if(typeof p=="string"&&(p=t.map[p]),!p)return{code:r.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!o.supportsPresence(p))return{code:r.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(a.create||a.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:p.transformPresence(l.p,a.op,d)}catch(A){return{code:r.ERR_PRESENCE_TRANSFORM_FAILED,message:A.message||A}}l.v++};function s(l,a){if(l.type===t.defaultType.uri){var d=a.op;if(!!d){var h=l.data;d.length>1&&(h=o.clone(h));for(var p=0;p<d.length;p++){var A=d[p];typeof A.lm=="string"&&(A.lm=+A.lm);for(var v=A.p,B=h,D=0;D<v.length;D++){var T=v[D];Object.prototype.toString.call(B)=="[object Array]"?v[D]=+T:B.constructor===Object&&(v[D]=T.toString()),B=B[T]}p<d.length-1&&(h=t.defaultType.apply(h,[A]))}}}}})(Ob);var qa=Ib,bS=Ob,vS=co;function co(n,t){qa.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()}co.prototype=Object.create(qa.prototype),co.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},co.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),qa.prototype.destroy.call(this,n)},co.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)},co.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))}})}},co.prototype._handleOp=function(n,t,e){var o=e===this.src;this._transformAgainstOp(n,o),this._cacheOp(n,o),this._setPendingPresence()},qa.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},qa.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},co.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)}},co.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++):bS.transformPresence(this._pending,t,e)}var o=this._pending.v>=this._doc.version;return o&&this._stopCachingOps(),o},co.prototype._startCachingOps=function(){this._opCache=[]},co.prototype._stopCachingOps=function(){this._opCache=null},co.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var _b=Lb,yS=AS,kS=vS;function tc(n,t,e){var o=tc.channel(t,e);_b.call(this,n,o),this.collection=t,this.id=e}var wS=tc;tc.prototype=Object.create(_b.prototype),tc.channel=function(n,t){return n+"."+t},tc.prototype._createLocalPresence=function(n){return new yS(this,n)},tc.prototype._createRemotePresence=function(n){return new kS(this,n)};var BS=ES;function ES(n,t,e,o,r){this.id=n,this.v=t,this.type=e,this.data=o,this.m=r}var xS=BS,Fb=$i,Pb=Ga;function Ga(n,t,e,o,r){if(Fb.EventEmitter.call(this),typeof r!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=o,this.collection=e,this.callback=r,this.sent=!1}Fb.mixin(Ga),Ga.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},Ga.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},Ga.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,o=new xS(this.id,t.v,t.type,t.data,e);this.callback(null,o)};var Nb=Pb,IS=Fo,TS=Us.ACTIONS,DS=hp;function hp(n,t,e,o,r,i){if(Nb.call(this,n,t,e,o,i),!IS.isValidVersion(r))throw new Error("Snapshot version must be a positive integer or null");this.version=r}hp.prototype=Object.create(Nb.prototype),hp.prototype._message=function(){return{a:TS.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var $b=Pb,SS=Fo,LS=Us.ACTIONS,MS=fp;function fp(n,t,e,o,r,i){if($b.call(this,n,t,e,o,i),!SS.isValidTimestamp(r))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=r}fp.prototype=Object.create($b.prototype),fp.prototype._message=function(){return{a:LS.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var RS=iS,OS=uS,_S=Lb,Hb=wS,FS=DS,PS=MS,jb=$i,ec=Fh,te=Us.ACTIONS,Ub=Ua,$o=Fo,Za=Cb,Qa=ec.CODES;function zb(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var NS=wt;function wt(n){jb.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=zb(n),this.bindToSocket(n)}jb.mixin(wt),wt.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=zb(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(o){try{var r=typeof o.data=="string"?JSON.parse(o.data):o.data}catch{Za.warn("Failed to parse message",o);return}e.debug&&Za.info("RECV",JSON.stringify(r));var i={data:r};if(e.emit("receive",i),!!i.data)try{e.handleMessage(i.data)}catch(s){$o.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(o){e.emit("connection error",o)},n.onclose=function(o){o==="closed"||o==="Closed"?e._setState("closed",o):o==="stopped"||o==="Stopped by server"?e._setState("stopped",o):e._setState("disconnected",o)}},wt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=Vb(n.error,n),delete n.error),n.a){case te.initLegacy:return this._handleLegacyInit(n);case te.handshake:return this._handleHandshake(t,n);case te.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case te.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case te.queryUnsubscribe:return;case te.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 te.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case te.bulkSubscribe:case te.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case te.snapshotFetch:case te.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case te.fetch:var o=this.getExisting(n.c,n.d);o&&o._handleFetch(t,n.data);return;case te.subscribe:case te.unsubscribe:var o=this.getExisting(n.c,n.d);o&&o._handleSubscribe(t,n.data);return;case te.op:var o=this.getExisting(n.c,n.d);o&&o._handleOp(t,n);return;case te.presence:return this._handlePresence(t,n);case te.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case te.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case te.presenceRequest:return this._handlePresenceRequest(t,n);case te.pingPong:return this._handlePingPong(t);default:Za.warn("Ignoring unrecognized message",n)}};function Vb(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}wt.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var o in t.data){var r=t.data[o],i=this.getExisting(t.c,o);i&&(n?i[e](n):r.error?i[e](Vb(r.error)):i[e](null,r))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var o=t.b[s],i=this.getExisting(t.c,o);i&&i[e](n)}else if(t.b)for(var o in t.b){var i=this.getExisting(t.c,o);i&&i[e](n)}else Za.error("Invalid bulk message",t)},wt.prototype._reset=function(){this.agent=null},wt.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 ec(Qa.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 o in this.queries){var r=this.queries[o];r._onConnectionStateChanged()}for(var i in this.collections){var s=this.collections[i];for(var o in s)s[o]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var o in this._snapshotRequests){var a=this._snapshotRequests[o];a._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},wt.prototype.startBulk=function(){this.bulk||(this.bulk={})},wt.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},wt.prototype._sendBulk=function(n,t,e){if(!!e){var o=[],r={},i=0,s;for(var l in e){var a=e[l];a==null?o.push(l):(r[l]=a,s=l,i++)}if(o.length===1){var l=o[0];this.send({a:n,c:t,d:l})}else o.length&&this.send({a:"b"+n,c:t,b:o});if(i===1){var d=r[s];this.send({a:n,c:t,d:s,v:d})}else i&&this.send({a:"b"+n,c:t,b:r})}},wt.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var o=this.bulk[t.collection]||(this.bulk[t.collection]={}),r=o[n]||(o[n]={}),i=r.hasOwnProperty(t.id);return r[t.id]=e,i}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},wt.prototype.sendFetch=function(n){return this._sendActions(te.fetch,n,n.version)},wt.prototype.sendSubscribe=function(n){return this._sendActions(te.subscribe,n,n.version)},wt.prototype.sendUnsubscribe=function(n){return this._sendActions(te.unsubscribe,n)},wt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:te.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)},wt.prototype.send=function(n){this.debug&&Za.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},wt.prototype.ping=function(){if(!this.canSend)throw new ec(Qa.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:te.pingPong};this.send(n)},wt.prototype.close=function(){this.socket.close()},wt.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},wt.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),o=e[t];return o||(o=e[t]=new RS(this,n,t),this.emit("doc",o)),o._wantsDestroy=!1,o},wt.prototype._destroyDoc=function(n){!n._wantsDestroy||($o.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},wt.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},wt.prototype._createQuery=function(n,t,e,o,r){var i=this.nextQueryId++,s=new OS(n,this,i,t,e,o,r);return this.queries[i]=s,s.send(),s},wt.prototype._destroyQuery=function(n){delete this.queries[n.id]},wt.prototype.createFetchQuery=function(n,t,e,o){return this._createQuery(te.queryFetch,n,t,e,o)},wt.prototype.createSubscribeQuery=function(n,t,e,o){return this._createQuery(te.querySubscribe,n,t,e,o)},wt.prototype.hasPending=function(){return!!(this._firstDoc(Uh)||this._firstQuery(Uh)||this._firstSnapshotRequest())};function Uh(n){return n.hasPending()}wt.prototype.hasWritePending=function(){return!!this._firstDoc($S)};function $S(n){return n.hasWritePending()}wt.prototype.whenNothingPending=function(n){var t=this._firstDoc(Uh);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(Uh);if(e){e.once("ready",this._nothingPendingRetry(n));return}var o=this._firstSnapshotRequest();if(o){o.once("ready",this._nothingPendingRetry(n));return}$o.nextTick(n)},wt.prototype._nothingPendingRetry=function(n){var t=this;return function(){$o.nextTick(function(){t.whenNothingPending(n)})}},wt.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var o in e){var r=e[o];if(n(r))return r}}},wt.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},wt.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},wt.prototype.fetchSnapshot=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new FS(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype.fetchSnapshotByTimestamp=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new PS(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},wt.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},wt.prototype._initializeHandshake=function(){this.send({a:te.handshake,id:this.id})},wt.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},wt.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},wt.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new ec(Qa.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(Ub.map[n.type]!==Ub.defaultType)return this.emit("error",new ec(Qa.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new ec(Qa.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},wt.prototype.getPresence=function(n){var t=this,e=$o.digOrCreate(this._presences,n,function(){return new _S(t,n)});return e._wantsDestroy=!1,e},wt.prototype.getDocPresence=function(n,t){var e=Hb.channel(n,t),o=this,r=$o.digOrCreate(this._presences,e,function(){return new Hb(o,n,t)});return r._wantsDestroy=!1,r},wt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var o={a:n,ch:e.channel,seq:t};return this.send(o),o.seq},wt.prototype._addPresence=function(n){$o.digOrCreate(this._presences,n.channel,function(){return n})},wt.prototype._handlePresenceSubscribe=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},wt.prototype._handlePresenceUnsubscribe=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},wt.prototype._handlePresence=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},wt.prototype._handlePresenceRequest=function(n,t){var e=$o.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var Wb=NS,HS=Ua;const zh={err:1001,msg:"user auth error",name:"AuthError"},jS={err:1002,msg:"you don't have required permission",name:"PermissionError"},mp={err:1003,msg:"Too many user connected",name:"MaxUserError"},Ya={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},US={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},zS={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},Ja="x-live-editor-token",Vh="x-live-editor-base-url",gn=S("auth-connection");function VS(n){try{n()}catch(t){gn.error(t)}}class WS{constructor(t,e){m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new q5.EventEmitter);m(this,"token",null);m(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 Bs(this.getBaseURL())}async auth(t){g(gn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,o=await window.fetch(e,{method:"GET",headers:{[Ja]:t.token,[Vh]:this.getBase64BaseURL()},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return this.token=t.token,await o.json()}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[Vh]:Bs(this.getBaseURL())}})}async init(t){const e=await this.auth(t);this.resourceToken=e.read,this.ws=new HB.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(Wb.prototype),g(gn,this.connection,"no this.connection"),this.ws,this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})};const o=this.connection.handleMessage.bind(this.connection);this.connection.handleMessage=r=>{var s;const i=r;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in i||i.a==="pong")this.handleMessage(i);else{Object.prototype.hasOwnProperty.call(i,"a")&&i.a!=="init"&&i.a!=="hs"&&(this.retryCount=0);try{o(i)}catch(l){if((l==null?void 0:l.type)==="writeConflict"){this.emitWriteConflictError(l,i);return}if((s=l==null?void 0:l.message)!=null&&s.startsWith("Cannot invert subtype")){this.emitWriteConflictError(l,i);return}throw l}}},Wb.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,gn.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const t=await this.reauthFunc();await this.auth(t),this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})}}}catch(t){gn.error(t),setTimeout(()=>this.handleAuthError(),0)}}else gn.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(zh.msg);t.code=zh.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Ya.msg);t.code=Ya.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 o=e.err;if(o===zh.err)gn.warn("auth error"),this.handleAuthError();else if(o===mp.err)gn.warn(mp.msg),this.emitMaxUsersError();else if(o===Ya.err){gn.warn(Ya.msg);try{this.emitRequestReloadError()}catch(r){gn.error(`error occurred while process reload error: ${JSON.stringify(r)}`)}finally{this.end(!1)}}else gn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return g(gn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(g(gn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){g(gn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){g(gn,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e;this.reauthFunc=void 0,this.events.removeAllListeners(),VS(()=>{var o;return(o=this.connection)==null?void 0:o.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}S("utils/file");function qS(){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}qS();async function GS(n){const e=n.size,o=Math.floor((e+102400-1)/102400),r=new jB.Hash;for(let s=0;s<o;s++){const l=s*102400;let a=l+102400;a>e&&(a=e);const h=await n.slice(l,a,n.type).arrayBuffer();r.update(new Uint8Array(h))}const i=r.digest();return Bs(i)}const ur=S("sharedb-doc/client");class ZS{constructor(t,e,o){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",K());m(this,"getDoc",async()=>{const t=o=>new Promise((r,i)=>{o.fetch(s=>{s?i(s):r()})});g(ur,!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),ur.debug(e),e});this.auth=t;const r=`${e}/${this.auth.appId}/${this.auth.docId}`;HS.register(_d.type),this.connection=new WS(r,o),this.reauthFunc=o}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return g(ur,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,o=>{(t==="error"||this.doc)&&e(o)})}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,o,r,i){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...i},data:{name:o,size:r}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const o=`${this.apiServer()}/resources`;let r=[];t.forEach(l=>{const a=l.split("|");r.push(...a)}),r=Array.from(new Set(r));const i=r.map(l=>this.getFileUrlByHash(o,l,"",0,{[Ja]:this.connection.token}));return await Promise.all(i)}async uploadFile(t,e,o,r,i){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=v=>{ur.info(`on progress: ${v.loaded}`);let B=v.loaded*100/s;B>100&&(B=100),r(B)},a=await GS(e),d=await this.getFileUrlByHash(t,a,e.name,e.size,o);if(d)return r(-1),d;let h=t;i!=null&&i.thumbnail&&(h+="/thumbnail");const p=new FormData;p.append("file-size",`${e.size}`),p.append("file-hash",a),p.append("file",e,e.name);const A=await this.request(h,{method:"post",data:p,withCredentials:!0,headers:{...o},onUploadProgress:l});return ur.info(A),r(100),Array.isArray(A.data)?A.data[0]:A.data}async uploadResource(t,e=()=>{},o){const i=`${this.apiServer()}/resources`;g(ur,this.connection.token,"no connection token");const s=await this.uploadFile(i,t,{[Ja]:this.connection.token},e,o);return g(ur,s,"no result"),s}async request(t,e){var i,s;let o=this.connection.token,r;for(let l=0;l<2;l++){const a=e||{};a.url=t,a.headers||(a.headers={}),g(ur,o,"no token"),a.headers={...a.headers,[Ja]:o,[Vh]:this.connection.getBase64BaseURL()};try{return await NB.default(t,a)}catch(d){if(r=d,((i=d==null?void 0:d.response)==null?void 0:i.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;o=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw g(ur,r,"no error"),r}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,r=(await this.request(e)).data.versions;return r.forEach(i=>{i.extra&&(i.extra=JSON.parse(i.extra))}),r}async getVersion(t){const o=`${this.apiServer()}/versions/${t}`,r=await this.request(o);return JSON.parse(r.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,o=await this.request(e);return JSON.parse(o.data.data)}async getVersionOps(t,e){let r=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(r+=`&from=${e}`);const i=await this.request(r),s=i.data.ops,l=$B.default(s,h=>!!h.create);let a=null;l!==-1&&(a=s[l],s.splice(0,l+1));let d;return a?(g(ur,a.create,"no createDoc.create"),d=a.create.data):d=JSON.parse(i.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:i.data.ops}}async updateVersionExtra(t,e,o){const i=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(i,{method:"post",data:{extra:JSON.stringify(o)}})}async revertVersion(t){const o=`${this.apiServer()}/versions/revert/${t}`;await this.request(o,{method:"post",data:{}})}async createVersion(t,e){const r=`${this.apiServer()}/versions`;return(await this.request(r,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const o=`${this.apiServer()}/resources/external/${Bs(t)}`;return(await this.request(o)).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 r=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const i=[];if(e!=null&&e.withToken&&i.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&i.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),i.length>0){const s=i.join("&");r+=`?${s}`}return r}}function QS(){return{blocks:[{id:K(),type:"text",text:[]}],comments:{},meta:{}}}const gp=S("block-ids");class YS{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((r,i)=>i-r);for(let r=0;r<e.length;r++){const i=e[r];if(i>=t){const s=this.ids.get(i);g(gp,s!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i+1,s)}}const o=K();this.ids.set(t,o)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((o,r)=>o-r);for(let o=0;o<e.length;o++){const r=e[o];if(r>t){const i=this.ids.get(r);g(gp,i!==void 0,"old id is not exists"),this.ids.delete(r),this.ids.set(r-1,i)}}}getId(t){let e=this.ids.get(t);return e||(e=K(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class JS{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new YS,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 o=0;o<e.length;o++){const r=e[o],i=r[1].getById(t);if(i)return{containerId:r[0],blockIndex:i[0]}}return g(gp,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class qb{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,o)=>{t[o]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const Wh=S("op-parse-handler");class KS{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const o={...t,containerId:(r=>r==="blocks"?"root":r)(t.containerId)};this.actions.push(o)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,o){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:o})}onDeleteBlockData(t,e,o){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:o})}onInsertBlockData(t,e,o,r){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:o,value:r})}onUpdateBlockText(t,e,o){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:o})}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,o=new Map,r=new JS,i=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of i)if(s.type==="deleteBlock"){const l=s,a=r.getBlockId(l.containerId,l.blockIndex);r.onDeleteBlock(l.containerId,l.blockIndex);const d=o.get(a);d&&(Wh.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),o.delete(a));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,a=`${l.containerId}-${l.blockIndex}`;if(e.has(a)){Wh.warn("delete block data after delete block, ignore it");continue}const d=r.getBlockId(l.containerId,l.blockIndex);let h=o.get(d);h||(h=new qb,o.set(d,h)),h.delete(l.key)}else g(Wh,!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,a=r.getBlockId(l.containerId,l.blockIndex);let d=o.get(a);d||(d=new qb,o.set(a,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(o.entries()).forEach(([s,l])=>{const{containerId:a,blockIndex:d}=r.getBlockIndexById(s);Wh.debug(`update block data: ${a}, ${d}, ${JSON.stringify(l.toDocBlockDelta())}`),this.outerHandler.onUpdateBlockData(a,d,l.toDocBlockDelta(),this.local)})}}const Re=S("op-parser");class Gb{}class pp{constructor(t){m(this,"key");this.key=t}}function XS(n,t,e){const o=t.concat(),r=o[0];if(typeof r!="number"||(o.shift(),o.length===1))return!1;const i=o[0];if(typeof i!="object"||!i.i||Object.keys(i).length!==1)return!1;for(let l=1;l<o.length;l++){const a=o[l];if(!Array.isArray(a)||a.length!==2||typeof a[0]!="string")return!1;const h=a[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=i.i;g(Re,s.id,"block id is required"),g(Re,s.type,"block type is required");for(let l=1;l<o.length;l++){const a=o[l],d=a[0],h=a[1];s[d]=h.i}return e.onInsertBlock(n,r,s),!0}function Cp(n,t,e,o){if(e==="upsert"&&XS(n,t,o))return;g(Re,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const r=t.concat(),i=r[0];r.shift();const s=[];for(;r.length>0;){const l=r[0];if(l==="text"){const a=r[1];if(g(Re,typeof a=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),g(Re,a.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),r.splice(0,2),e==="upsert"){const h=a.e;o.onUpdateBlockText(n,i,h)}g(Re,r.length===0,`invalid block ops.length !== 0, ${JSON.stringify(r)}`)}else if(Array.isArray(l)){g(Re,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const a=l[0];g(Re,typeof a=="string",`invalid block op: key ${JSON.stringify(a)}`);const d=l[1];if(a==="text"){if(g(Re,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&o.onInsertBlockData(n,i,a,d.i),d.r&&e==="remove"&&o.onDeleteBlockData(n,i,a),d.et==="rich-text"&&e==="upsert"){const p=d.e;o.onUpdateBlockText(n,i,p)}}else e==="remove"&&d.r&&s.push(new pp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i);r.shift()}else if(typeof l=="object"){const a=l;e==="remove"&&a.r&&s.push(new Gb),e==="upsert"&&a.i&&o.onInsertBlock(n,i,a.i),r.shift()}else{g(Re,typeof l=="string","data is not string"),g(Re,l!=="text","data !== 'text'"),g(Re,r.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(r)}`);const a=l,d=r[1];e==="remove"&&d.r&&s.push(new pp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i),r.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof Gb?o.onDeleteBlock(n,i):l instanceof pp?o.onDeleteBlockData(n,i,l.key):g(Re,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function tL(n,t,e){Re.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function eL(n,t,e){const o=n[1],r=n[2];g(Re,o,`invalid comment op, no commentId: ${JSON.stringify(n)}`),g(Re,r,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof r=="string"?Re.error(`unknown comment op, ${JSON.stringify(n)}`):r.i&&r.r?t==="upsert"&&e.onUpdateComment(o):r.i?t==="upsert"&&e.onCreateComment(o):r.r?t==="remove"&&e.onDeleteComment(o):Re.error(`unknown comment op, ${JSON.stringify(n)}`)}function Ap(n,t,e){const o=n[0];if(Array.isArray(o)){o.forEach(s=>{Ap(s,t,e)});return}const r=o;if(g(Re,typeof r=="string",`invalid container id: ${JSON.stringify(n)}`),r==="meta"){tL(n);return}if(r==="comments"){eL(n,t,e);return}const i=r;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{Cp(i,s,t,e)}):n.slice(1).forEach(s=>{Cp(i,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(i),s.i&&t==="upsert"&&e.onCreateContainer(i,s.i)}else g(Re,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),Cp(i,n.slice(1),t,e)}function Zb(n,t,e){const o=new KS(t,e);for(let r=0;r<2;r++){const i=r===0?"remove":"upsert",s=mt.default(n),l=s[0];Array.isArray(l)?s.forEach(a=>{Ap(a,i,o)}):Ap(s,i,o)}o.end()}const nL=S("sharedb-comments");function bp(n){const t=n.blocks;g(nL,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([o,r])=>{Array.isArray(r)&&(e.blocks[o]=r)}),mt.default(e)}function Qb(n){const{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}=n;return{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}}function vp(n,t){const e=HD(t),{comments:o,meta:r,blocks:i,...s}=e,l={...n,blocks:i,...s},a=mt.default(l);return delete a.children,a}const ae=S("sharedb-doc/doc-container"),Yb="ot-json1";_d.type.registerSubtype(jD.type),_d.type.name=Yb,_d.type.invert=null;class Ka extends fa{constructor(e,o,r=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new ND);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,e)})});m(this,"handleReset",async e=>{const o=new Error(`reset doc: ${e}`);o.code="ResetDoc",this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,o)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,o,r)=>{const i=[e,o,{i:r}];return this.submitOp(i)});m(this,"deleteObject",async(e,o)=>{const r=[e,o,{r:!0}];return this.submitOp(r)});m(this,"replaceObject",async(e,o,r)=>{const i=[e,o,{r:!0,i:r}];return this.submitOp(i)});m(this,"updateObject",async(e,o,r)=>{const i=this.data()[e][o],s=[e,o];return Object.entries(r).forEach(([l,a])=>{if(!ua.default(i[l],a))if(i[l]===void 0){if(a!=null){const d={i:a};s.push([l,d])}}else if(a==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:a};s.push([l,d])}}),Object.entries(i).forEach(([l,a])=>{if((r[l]===void 0||r[l]===null)&&a!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const o={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(o)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((o,r)=>{if(this.destroyed){ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},i=>{i?(ae.error(`invalid op, ${i.message}, ${JSON.stringify(e)}`),r(i),ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):o()}),this.doc.data||(ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((o,r)=>{this.doc.create(e,Yb,i=>{i?r(i):o()})}));m(this,"submitInsertChildContainer",async(e,o)=>{const r=[Ni(e),{i:o}];return this.submitOp(r)});m(this,"submitDeleteChildContainer",async e=>{const o=[Ni(e),{r:!0}];return this.submitOp(o)});m(this,"submitInsertBlock",async(e,o,r)=>{const i=[Ni(e),o,{i:r}];return this.submitOp(i)});m(this,"submitDeleteBlock",async(e,o)=>{const r=[Ni(e),o,{r:!0}];return this.submitOp(r)});m(this,"submitUpdateBlockData",async(e,o,r)=>{if(r.delete.length===0&&Object.keys(r.insert).length===0)return Promise.resolve();const i=[Ni(e),o],s=new Set(r.delete);Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a)){const h={r:!0,i:d};i.push([a,h])}});const l=new Set(Object.keys(r.insert));return r.delete.forEach(a=>{if(l.has(a))return;const d={r:!0};i.push([a,d])}),Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a))return;const h={i:d};i.push([a,h])}),this.submitOp(i)});m(this,"submitUpdateRichText",async(e,o,r)=>{const i=[Ni(e),o,"text",{e:r,et:"rich-text"}];return this.submitOp(i)});m(this,"handleOp",(e,o,r)=>{if(this.destroyed){ae.warn("handleOp: destroyed");return}Zb(e,this,!!o)});this.client=e,this.doc=o,this.doc.preventCompose=!0,this.disableLogout=r,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,g(ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const o=new ZS(e.auth,e.serverUrl,e.reauthFunc),r=await o.getDoc(),i=new Ka(o,r,e.disableLogout);if(r.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await i.createDoc(e.templateData||QS())}return await i.initPresence(),await i.subscribe(),i.initEvents(),i}catch(o){throw ae.error(o),ae.error(`failed to load doc: ${JSON.stringify(o)}`),o}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),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,o)=>{if(this.localPresence)e();else{const r=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);r.on("receive",(i,s)=>{this.onCustomMessage(s)}),r.subscribe(i=>{i?o(i):(this.localPresence=r.create(K()),e())})}})}subscribe(){return new Promise((e,o)=>{this.doc.subscribe(r=>{r?o(r):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return ja(this.data())}getContainerBlocks(e){const o=this.data();g(ae,o,"no doc data");const r=o[Ni(e)];return g(ae,r,`no container data: ${e}`),mt.default(r)}getBlockData(e,o){const r=this.data();g(ae,r,"no doc data");const i=r[Ni(e)];g(ae,i,`no container data: ${e}`);const s=i[o];return g(ae,s,`no block data: ${o}`),mt.default(s)}localInsertBlock(e,o,r){return this.submitInsertBlock(e,o,r),this.getBlockData(e,o)}localDeleteBlock(e,o){const r=this.getBlockData(e,o);return this.submitDeleteBlock(e,o),r}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(ae,i.text,"no block text");const s=mt.default(i.text);this.submitUpdateRichText(e,o,r);const l=ln.apply(s,r);return g(ae,l,"no block text"),l}localUpdateBlockData(e,o,r){const i=mt.default(this.getBlockData(e,o));return this.submitUpdateBlockData(e,o,r),i}localInsertChildContainer(e,o){this.submitInsertChildContainer(e,o)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(o=>{this.submitDeleteChildContainer(o)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(o=>Qb(o))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const o=this.data().comments[e];return bp(o)}localCreateComment(e,o){const r=vp(e,o),s=["comments",r.id,{i:r}];return this.submitOp(s)}localDeleteComment(e){const o=["comments",e,{r:!0}];return this.submitOp(o)}localUpdateComment(e,o){const r=vp(e,o),i=["comments",e.id,{r:!0,i:r}];return this.submitOp(i)}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,o,r){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var s;return(s=i.onDeleteBlock)==null?void 0:s.call(i,Xl(e),o,r)})}onInsertBlock(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Xl(e),o,r,i)})}onUpdateBlockData(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Xl(e),o,r,i)})}onUpdateBlockText(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Xl(e),o,r,i)})}onDeleteContainer(e,o){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,Xl(e),o)})}onCreateContainer(e,o,r){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,Xl(e),o,r)})}onDeleteComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteComment)==null?void 0:i.call(r,e,o)})}onCreateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onCreateComment)==null?void 0:i.call(r,e,o)})}onUpdateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onUpdateComment)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){const o=e;(o==null?void 0:o.type)==="custom"&&(o==null?void 0:o.clientId)!==this.client.clientId?this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,o.data)}):(o==null?void 0:o.type)==="onlineUsers"&&setTimeout(()=>{const r={type:"custom",data:e,clientId:"-"};this.onCustomMessage(r)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}async uploadResource(e,o){var i;return{resourceId:await this.client.uploadResource(e,(i=o==null?void 0:o.onProgress)!=null?i:()=>{})}}buildResourceUrl(e,o){return this.client.buildResourceUrl(e,o)}request(e,o){return this.client.request(e,o)}getUser(){const e=this.client.clientId,{permission:o,userId:r,displayName:i,avatarUrl:s}=this.client.auth;return{permission:o,clientId:e,userId:r,displayName:i,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const o=await this.client.getVersion(e);return ja(o)}async getLatestVersion(){const e=await this.client.getLatestVersion();return ja(e)}async getHistoryData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o),s=i.map(l=>({user:l.meta.createdBy,data:l}));return{doc:ja(r),historyData:s}}async getVersionData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o);return{doc:ja(r),versionData:i}}async updateVersionExtra(e,o,r){await this.client.updateVersionExtra(e,o,r)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,o){return this.client.createVersion(e,o)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,o){Zb(e.data.op,o,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}S("remote-cursor");class Jb{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",He.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const o=this.editor.findBlockById(e);o&&this.editor.reloadBlock(o)})});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 Kb=S("remote-cursor-decorator");class yp{decorateText(t,e,o){const r=t.doc.getRemoteUsers();if(!r)return{};const i=new Map,{containerId:s,blockIndex:l}=e[e.length-1];g(Kb,typeof s=="string","invalid path containerId"),g(Kb,typeof l=="number","invalid path blockIndex");const a=t.doc.getBlockData(s,l),d=rn(o);return r.getSimpleCursors(a.id).forEach((p,A)=>{A>d&&(A=d);const v=p.map(D=>({id:K(),type:"remote-cursor",name:D.user.displayName,time:D.time,rainbowIndex:D.user.rainbowIndex})),B=i.get(A);B?B.push(...v):i.set(A,v)}),{insertions:i}}}class Xb extends be.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,o){if(Xt(Nr(this.editor,t)))return;const r=this.editor.getBlockByIndex(t,e),i=ot(this.editor.getContainerById(t));i&&this.emit("change",this.editor,i,r,o)}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 oL(n,t){n.addCustom("child-block-tracker",()=>new Xb(n)).addListener("change",t)}function rL(n,t){n.addCustom("child-block-tracker",()=>new Xb(n)).removeListener("change",t)}const snt="",iL={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"}},sL={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},lL={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"}};R.mergeLang({"zh-CN":iL,"en-US":sL,"js-JP":lL});const lnt="";S("button");function ji(n,t,e,o,r){const i=w("button",["editor-button"],null);return i.setAttribute("data-button-id",n),r&&i.setAttribute(`data-editor-tooltip-${r}`,t),e?typeof e=="string"?e.startsWith("<")?i.innerHTML=e:i.innerText=e:i.appendChild(e):i.innerText=t,o&&(o.indexOf("checked")!==-1&&W(i,"checked"),o.indexOf("disabled")!==-1&&(i.disabled=!0)),i}function tv(n,t,e){e?n.setAttribute(`data-editor-tooltip-${e}`,t):n.innerText=t}const cnt="",nc=S("ui-command-bar-base"),cL={itemElementTag:"div",tippyArrow:!1},K2=class extends be.TypedEmitter{constructor(e,o,r){var i,s;super();m(this,"content");m(this,"items");m(this,"subBar",null);m(this,"parentItem",null);m(this,"closeable",null);m(this,"closeReason",null);m(this,"options");m(this,"id");m(this,"header",null);m(this,"footer",null);m(this,"handleDocumentKeydown",e=>{if(console.log(e,"handleDocumentKeydown"),console.log(this,"handleDocumentKeydown"),!!this.isVisible&&!e.isComposing&&!Ls(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 o=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const o=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const o=this.getSelectedItem();o&&o.children&&this.showSubCommandBar(o.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const o=this.getSelectedItemIndex();if(o===-1)return;const r=this.items[o],i=this.getItemElementById(r.id);i&&this.emit("click",this,r,i)}}}});m(this,"handleDocumentMouseDown",e=>{if(e.target instanceof Element&&!this.isInCommandBar(e.target)){const o=this.listeners("closing");for(let r=0;r<o.length;r++)if(o[r](this,e)===!1)return;this.close("clickBackground")}});m(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),EC(this.id)});m(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&W(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&BC(this.id)});m(this,"lastEnterPauseTime",0);m(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});m(this,"handleItemMouseEnter",e=>{if(Date.now()-this.lastEnterPauseTime<100)return;const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.getItemById(r);if(this.selectItem(r),i.manualShowChildren)return;const s=i.childrenMenuId||"";this.showSubCommandBar(s)});m(this,"handleItemMouseLeave",e=>{var r,i;const o=this.getParentCommandItemElement(e.target);!o||((i=(r=this.subBar)==null?void 0:r.parentItem)==null?void 0:i.id)!==this.getItemElementId(o)&&(et(o,"selected"),this.emit("selectionChange",this,""))});m(this,"handleItemClick",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.items.find(s=>s.id===r);if(!!i&&!(i.states&&i.states.indexOf("disabled")!==-1)){if(i.children&&i.children.length>0&&i.manualShowChildren){this.showSubCommandBar(i.childrenMenuId);return}i.element||(this.emit("click",this,i,o),this.options.autoClose&&this.close("clickItem"))}});m(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const o=e.target;if(!o||!(o instanceof Node))return;const r=o instanceof HTMLElement?o:o.parentElement;if(!r)return;const i=oo(r);if(!Kt(this.content,i)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?i.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&i.scrollTop+i.clientHeight>=i.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(i=r==null?void 0:r.id)!=null?i:K(),this.options={...cL,...r},this.items=e,this.parentItem=(s=r==null?void 0:r.parentItem)!=null?s:null,this.closeable=o!=null?o: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,o){this.emit("click",this,e,o)}createPopperOptions(){var r,i;const e={modifiers:[]},o=this.options.overflowBoundary;return o&&((r=e==null?void 0:e.modifiers)==null||r.push({name:"flip",options:{boundary:o,fallbackPlacements:["top","bottom"]}})),this.options.padding&&((i=e==null?void 0:e.modifiers)==null||i.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 r;this.subBar&&e.findIndex(s=>{var l,a;return s.id===((a=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:a.id)})===-1&&((r=this.subBar)==null||r.destroy(),this.subBar=null),this.items=e;const o=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(o.children).forEach(i=>{this.content.appendChild(i)})}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 o=e-1;for(;;){const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o-=1,o<=0)return this.items.length-1}}getNextItemIndex(e){let o=e+1;for(;;){if(!this.items[o])return this.getNextItemIndex(-1);const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o+=1,o>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const o=this.getItemElementById(e.id);o&&et(o,"selected")}selectItem(e){const o=this.getSelectedItem();if(o){if(o.id===e)return;const i=o.id,s=this.getItemElementById(i);s&&et(s,"selected")}const r=this.getItemElementById(e);r?(W(r,"selected"),this.emit("selectionChange",this,r.getAttribute("data-id")||""),r.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const o=this.getSelectedItem();if(!o)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.id)===o.id){o.manualShowChildren&&this.subBar.close("switchItem");return}this.subBar.destroy(),this.subBar=null}if(!o.children)return;const r=this.getItemElementById(o.id);if(!r)return;const i=K2.createSubCommandBar(o,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=i,this.subBar.on("click",(a,d,h)=>{this.emit("click",a,d,h)}),this.subBar.on("close",()=>{var a;(a=this.subBar)==null||a.destroy(),this.subBar=null,et(r,"active")}),o.beforePopup&&o.beforePopup(i),this.subBar.manualShow(r,this.getSubBarOptions(o)),W(r,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const o=this.getCommandBarRoot();return o&&Kt(o,e)||Kt(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var i,s,l,a;let o=(i=this.options.itemElementTag)!=null?i:"div";e.element&&(o="div");const r=w(o,["command-item"],null);return r.setAttribute("data-id",e.id),e.type==="separator"?r.classList.add("separator"):e.type==="section"?(r.classList.add("section","text"),e.element&&(typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&r.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&r.classList.add("checked"),(a=e.states)!=null&&a.includes("disabled")&&r.classList.add("disabled"),r.onclick=this.handleItemClick,r.onmouseenter=this.handleItemMouseEnter,r.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element):r.classList.add("standard")),this.initItemElement(e,r),r}getItemById(e){const o=this.items.find(r=>r.id===e);return g(nc,o,`can not find command item for id: ${e}`),o}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const o=this.getItemElementId(e),r=this.items.find(i=>i.id===o);return g(nc,r,`can not find command item for id: ${o}`),r}return null}getItemElementId(e){const o=e.getAttribute("data-id");return g(nc,o,"no data-id attribute"),o}getItemElementById(e){const o=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return g(nc,o,`no exists command item, id=${e}`),o}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(xt(e,"command-item"))return e;const o=e.closest(".command-item");return o||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const o=w("div",["editor-command-bar-root"],null);if(this.options.header){const i=w("div",["editor-command-bar-header"],null);if(this.options.header instanceof Function){const s=this.options.header();s&&i.appendChild(s)}else i.appendChild(this.options.header);this.header=i,this.header&&o.appendChild(this.header)}const r=w("div",["editor-command-bar"],o);if(e.forEach(i=>{var l;const s=this.createCommandItem(i);r.appendChild(s),i.element&&i.setCloseable&&i.setCloseable((l=this.closeable)!=null?l:this)}),this.options.footer){const i=w("div",["menu-item","editor-command-bar","footer"],null);if(this.options.footer instanceof Function){const s=this.options.footer();s&&i.appendChild(s)}else i.appendChild(this.options.footer);this.footer=i,this.footer&&o.appendChild(this.footer)}return(this.options.header||this.options.footer)&&W(o,"scrollable-bar"),this.initCommandBarElement(r),o.addEventListener("wheel",this.handleWheel,{passive:!1}),o}getSubBarOptions(e){var o;return{placement:(o=e.childrenPlacement)!=null?o:"right-start"}}static registerManualCommandBar(e,o){this.commandBarCreators.set(e,o)}static createSubCommandBar(e,o,r){var l;g(nc,e.children&&e.children.length>0,"no item children");const i=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(i);return g(nc,s,`no creator for command type: ${i}`),s(e,o,r)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let Ui=K2;m(Ui,"commandBarCreators",new Map),S("ui-command-bar");class qh extends Ui{constructor(){super(...arguments);m(this,"tippyInstance",null)}manualShow(e,o){var r,i;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=UB.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(r=o==null?void 0:o.placement)!=null?r:"bottom-start",maxWidth:650,arrow:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:o==null?void 0:o.theme,getReferenceClientRect:o==null?void 0:o.getReferenceClientRect,offset:(i=o==null?void 0:o.offset)!=null?i:[0,0],popperOptions:this.createPopperOptions()}),o!=null&&o.point){const{x:s,y:l}=o.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(s,l,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 o;super.close(e),this.isVisible&&((o=this.tippyInstance)==null||o.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,o;return(o=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?o:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const ev=S("ui-base");class Xa extends qh{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${K()}`,name:"",element:t}];super(r,void 0,{disablePageScroll:!0})}initCommandBarElement(t){W(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];g(ev,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return g(ev,e,"no item element"),e}}const zi=S("filterable-list");function nv(n){var e,o;const t=w("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(w("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&W(t,"selected"),(o=n.states)!=null&&o.includes("disabled")&&W(t,"disabled"),t}function ov(n){const t=w("div",["list-root"],null);return n.forEach(e=>{t.appendChild(nv(e))}),n.length||t.appendChild(nv({id:"placeholder",states:["disabled"],name:R.t("search.emptyTips")})),t}function rv(n,t){let e=n;return t&&(e=n.map(o=>({...o,states:o.id===t?["selected"]:void 0}))),e}function aL(n,t){const e=w("div",["filterable-list"],null),o=w("div",["filter"],e),r=w("div",["filter-container"],o),i=w("input",["filter-input"],r);t&&t.placeholder&&(i.placeholder=t.placeholder);const s=w("div",["list"],e),l=ov(rv(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function iv(n,t,e){const o=n.querySelector(".list");g(zi,o,"no list root");const r=ov(rv(t,e)),i=o.querySelector(".list-root");if(g(zi,i,"no exists menu"),Ca(i,r),e){const s=o.querySelector(".list-item.selected");s&&(g(zi,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class uL{constructor(t,e){m(this,"root");m(this,"visibleItems");m(this,"selectedId");m(this,"filter","");m(this,"onSelected",null);m(this,"handleKeydown",t=>{this.processKeyDown(t)});m(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");g(zi,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});m(this,"handleClick",t=>{this.processClick(t)});var o;this.items=t,this.options=e,this.root=aL(t,e),this.bindEvents(),this.selectedId=(o=e==null?void 0:e.initialSelectedId)!=null?o:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");g(zi,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");g(zi,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,iv(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");g(zi,t,"no input"),t.focus()}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");g(zi,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),iv(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const o=e.closest(".list-item");if(!o)return;const r=(s=o.getAttribute("data-id"))!=null?s:"",i=(l=this.visibleItems.find(a=>a.id===r))!=null?l:null;this.onSelected&&this.onSelected(this,i)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let o=this.getSelectedIndex();o===-1?o=this.visibleItems.length-1:o>0&&(o-=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="ArrowDown"){let o=this.getSelectedIndex();o===-1?o=0:o<this.visibleItems.length-1&&(o+=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="Enter"){const o=(e=this.visibleItems.find(r=>r.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,o)}}}class dL extends uL{constructor(e,o,r){super(e,r);m(this,"popup");m(this,"onShow",null);m(this,"onHide",null);m(this,"custom",null);m(this,"handleShow",()=>{this.onShow&&this.onShow(this)});m(this,"handleHide",()=>{this.onHide&&this.onHide(this)});m(this,"handleShown",()=>{this.focus()});this.popup=new Xa(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close("cancelBar")}processClick(e){super.processClick(e);const o=e.target;!(o instanceof HTMLElement)||!o.closest(".list-item")||this.popup.close("clickItem")}}const ant="",unt="";function hL(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)}const sv=`<?xml version="1.0" ?>
|
|
28
28
|
<svg
|
|
29
29
|
fill="currentColor"
|
|
30
30
|
xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
@@ -417,12 +417,12 @@ ${s}
|
|
|
417
417
|
<p>${l}</p>`}const Df={blockType:"code",blockKind:"complex",createBlockContent:cN,getBlockTextLength:aN,getRangeFromPoint:uN,moveCaret:dN,getCaretRect:hN,updateSelection:fN,clearSelection:mN,getChildContainers:gN,getNextContainer:pN,getSelectedContainers:CN,convertFrom:OP,handleBlockElementUpdated:AN,getOptions:vN,getBlockProperties:yN,convertTo:kN},U0={...In,blockType:"code-line"};class wN{constructor(t){m(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!yc(this.editor,e))return;const o=e,r=t.range.focus.offset,i=R4(this.editor,o,r,"code-caret");i.scrollIntoView({block:"nearest"}),setTimeout(()=>{i.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function y7(n,t){const e=n.split(`
|
|
418
418
|
`).map(s=>({id:K(),type:"text",text:Oi(s)})),o=K();return{blocks:{root:[{children:[o],type:"code",id:K(),...t}],[o]:e},meta:{},comments:{}}}class BN{handleBeforeCopy(t,e,o){const r=t.getFocusedBlock();if(!yc(t,r))return;const i=_0(r),s=t.getBlockData(i),{language:l,nowrap:a}=s;if(t.selection.range.isCollapsed()){const h=t.getBlockString(r);return y7(h,{language:l,nowrap:a})}const d=t.getSelectedText();return y7(d,{language:l,nowrap:a})}}function EN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!yc(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{Lo(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function xN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!yc(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{Lo(n).forEach(r=>{const i=re(n.getBlockText(r.block));for(let s=0;s<e.length;s++){const l=e[s];if(i.startsWith(l)){n.deleteTextFromBlock(r.block,0,l.length);break}}})}),!0}function IN(n){const t=n.getFocusedBlock(),e=nt(t);if(Xt(e))return;const o=ot(e);if(!o||Dt(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!OA(e,r))return Yg(n,e),!0}const TN={Tab:EN,"Shift+Tab":xN,"CtrlOrCmd+A":IN},yu=S("code-text-decorate");class Sf{decorateText(t,e,o){var v;if(g(yu,e.length>0,"invalid path"),e.length===1)return{};const r=e[e.length-2];if(t.doc.getBlockData(r.containerId,r.blockIndex).type!=="code")return{};const s=o;if(s.length===0)return{};const l=re(s),a=t.doc.getBlockData(r.containerId,r.blockIndex),d=da.default.tokenize(l,(v=da.default.languages[a.language])!=null?v:da.default.languages.plain),h=(B,D)=>{if(g(yu,B,"no token"),typeof B=="string")return[{insert:B,attributes:mt.default(D)}];g(yu,B instanceof da.default.Token,"invalid token type");const T=B.content,_=mt.default(D);return _[`style-code-${B.type}`]=!0,typeof T=="string"?[{insert:T,attributes:_}]:Array.isArray(T)?T.map(z=>h(z,_)).flat():(g(yu,T instanceof da.default.Token,"invalid token"),h(T,_))},A=d.map(B=>h(B,{})).flat();return g(yu,rn(A)===rn(s),"failed to highlight code, text length mismatch"),{text:A}}}const DN={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"}},SN={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},LN={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"}};R.mergeLang({"zh-CN":DN,"en-US":SN,"ja-JP":LN});const MN=S("image-data"),k7=1e3,z0=400,RN=10;function kc(n){return n.src.startsWith("empty:")||!n.src}function ON(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function w7(n){return`${Fd.default(n)}_width`}function B7(n){return`${Fd.default(n)}_height`}function E7(n){return`${n}_flex`}function x7(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function ku(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const t=100,o=n.map(r=>{const i=r.height==="auto"?r.width/t:r.height/t;return r.width/i}).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.height==="auto"?r.width/t:r.height/t,s=r.width/i;r.flex=s/o})}function wc(n){const t=(r,i)=>{r||(r=`empty:${i}`);const s=w7(r),l=B7(r),a=E7(i);let d=n[s],h=n[l],p=n[a];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof p=="string"&&(p=Number.parseInt(p,10)),d&&h?{src:r,width:d,height:h,flex:p,virtualSize:!1}:d&&!h?{src:r,width:d,height:"auto",flex:p,virtualSize:!1}:(d=k7,h=z0,{src:r,width:d,height:h,flex:p,virtualSize:!0})};let e=[];const o=n.src;return Array.isArray(o)?e=o.map(t):typeof o=="string"&&(e=o.split("|").map(t)),ku(e),e}function Uo(n){const t=n.embedData;return wc(n.embedData).length>1?100:t.widthPercent}function _N(n,t,e,o){const r=wc(t.embedData);if(r.length>1||o)return"100%";const i=Uo(t),s=n.rootContainer.getBoundingClientRect().width;if(i){const l=x7(e);return`${Math.min(s*i/100,l)}px`}return r[0].width?`${r[0].width}px`:"auto"}function cn(n,t){const o={src:n.map(r=>r.src).join("|"),widthPercent:t};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,a=w7(l);o[a]=r.width;const d=B7(l);r.height!=="auto"&&(o[d]=r.height)}g(MN,r.flex,"no image flex");const s=E7(i);o[s]=r.flex}),o}function FN(n,t,e,o){const r=wc(t.embedData),i=r.length===1?n.rootContainer:e;if(r.length===1&&o)return`${z0}px`;if(r.some(h=>h.height==="auto"))return"auto";const s=Uo(t);if(!s)return"";let l=i.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(i).paddingLeft)+Number.parseFloat(window.getComputedStyle(i).paddingRight),i===n.rootContainer&&i!==e&&(l=Math.min(l,x7(e))),r.length===1){const h=r[0];return h.virtualSize?"":`${h.height/(h.width/l)}px`}l-=(r.length-1)*RN;const a=r.reduce((h,p)=>h+p.flex,0);let d=0;for(const h of r){const A=l*h.flex/a/h.width*h.height;d=Math.max(A,d)}return`${d}px`}function PN(n){return n.reduce((e,o)=>e+o.flex,0)}function NN(n,t){w("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function V0(n){return le(n).querySelector(".block-resizer")}function $N(n){const t=V0(n);t&&et(t,"active")}function I7(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}function HN(n,t,e,o){const r=V0(n);if(r)return W(r,"active"),I7(n,t,r),r;const i=le(n),s=w("div",["block-resizer"],i);return I7(n,t,s),e.resize.forEach(l=>{NN(s,l)}),s.addEventListener("mousedown",o),W(s,"active"),s}function W0(n,t){const e=V0(n);if(!e||!Kt(n,t))return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}const Lnt="",jN=S("block-resizer");class wu extends be.TypedEmitter{constructor(e,o){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,pa(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:a,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(a+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=r);const p=d>a?d-a:0,A=h>l?h-l:0,v=new DOMRect(a,l,p,A);this.emit("resizing",this,v);const B=this.getResizableElement();B&&W0(this.block,B)});m(this,"handleMouseUp",e=>{if(e.button!==0)return;pa(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||W0(this.block,o)});this.editor=e,this.options=o}enableResize(e,o){this.block=e,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||($N(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&W0(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Rt(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(g(jN,Kt(this.block,e),"not a block child element"),HN(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 UN=S("image-dom");function T7(n){return n.querySelector(".uploading-progress-mask")}function zN(n){const t=T7(n);if(t)return t;const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e);return w("div",["uploading-progress-bar-value"],o),o}function VN(n){const e=zN(n).querySelector(".uploading-progress-bar-value");return g(UN,e,"no progress value"),e}function D7(n,t){const e=VN(n);e.style.width=`${t}%`}function WN(n){var t;(t=T7(n))==null||t.remove()}function Bu(n,t,e,o){const r=e!=null?e:n.findBlockById(t.id);if(!r)return;const i=o||nt(r),s=!!r.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=_N(n,t,i,s),a=FN(n,t,i,s),d=Rt(r);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=r.querySelector(".images");!h||(h.style.height=a||"none")}function qN(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function GN(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=qN(t.headers).toLocaleLowerCase();let r="";if(o){const s=mm.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}function Ki(n,t){const e=typeof t=="string"?t:it(t);return n.getCustom(`image-${e}`)}function Lf(n,t){if(!t||!(t instanceof Node))return null;const e=ot(t);return e?Ki(n,e):null}function Qr(n){return Array.from(n.querySelectorAll(".image-container"))}const q0=S("table-resize-drag-drop");class ZN{constructor(t,e,o,r){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=t,this.elem=e,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=Ki(this.editor,i).getImages(),a=this.data.splitterIndex;g(q0,a>=0&&a<l.length-1,`invalid splitter index: ${a}`);const h=Qr(i).map(p=>p.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,o){if(!this.editor.isWritable())return;const r=this.data.block;Ki(this.editor,r).setResizing(!0)}onDragging(t,e,o,r,i){const s=this.data.block,l=Ki(this.editor,s),a=mt.default(l.getImages()),d=this.data.splitterIndex;g(q0,d>=0&&d<a.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],p=this.initWidths[d+1];if(h+p<100)return;let A=r;h+A<50&&(A=50-h),p-A<50&&(A=p-50);const D=[...this.initWidths];D[d]+=A,D[d+1]-=A;const T=Qr(s);g(q0,T.length===a.length,"invalid image data");const _=D.reduce((z,q)=>z+q,0);for(let z=0;z<a.length;z++){const q=D[z]/_;a[z].flex=q,T[z].style.flexGrow=`${q}`}const M=mt.default(this.editor.getBlockData(s)),H=cn(a,Uo(M));M.embedData=H,Bu(this.editor,M,s,null)}onDragEnd(t,e,o,r,i){const s=this.data.block,l=Ki(this.editor,s),d=Qr(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function S7(n){var t;return!n||!(n instanceof HTMLElement)?null:xt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function QN(n,t){var s;const e=S7(t.target);if(!e)return;const o=ot(e);if(!o)return;Ki(n,o).setSelectedIndex(-1),n.selection.selectBlock(o,0);const r=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(r)||typeof r!="number")return;const i={block:o,splitterIndex:r};wm(new ZN(n,e,i,t))}function YN(n,t){t.preventDefault(),t.stopPropagation();const e=S7(t.target);if(!e)return;const o=ot(e);!o||Ki(n,o).resetFlex()}function JN(n,t,e,o){const r=w("div",["image-splitter"],e);w("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",QN),n.domEvents.addEventListener(r,"dblclick",YN)}const KN=S("image-item");function L7(n){return!n||!(n instanceof Node)?null:ot(n)}function M7(n){const t=L7(n);return t?Qr(t):[]}function G0(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 Eu(n){const t=G0(n);return t?M7(n).indexOf(t):-1}async function XN(n,t){const e=Lf(n,t.target);if(!e)return;const o=Eu(t.target);if(o===-1)return;const r=t.target;if(!(r instanceof HTMLImageElement))return;const i=e.getImages()[o];if(kc(i)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),i.height==="auto"&&e.fixImageSize(o,r),i.virtualSize&&e.fixImageSize(o,r),!i||!ON(i)||i.downloading))return;i.downloading=!0;const s=await GN(i.src);s?e.replaceImage(o,s):KN.warn(`failed to download image: ${i.src}`)}function t$(n,t,e){if(t.querySelector(".load-error"))return;const r=e.src.startsWith("http:")||e.src.startsWith("https:"),i=w("div",["load-error"],t),s=w("div",["error-icon"],i);s.innerHTML=dv;const l=w("div",["error-message"],i);r?(l.innerHTML=R.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=R.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&r$(a,d.target)}))}function Z0(n,t){setTimeout(()=>{if(Kt(n.rootContainer,t)){const e=n.getBlockData(t);Bu(n,e,null,null)}})}function e$(n,t){const e=Lf(n,t.target);if(!e)return;const o=Eu(t.target);if(o===-1)return;const r=e.getImages()[o];if(!r)return;const i=G0(t.target);if(!i)return;W(i,"error","error-load");const s=ot(i);s&&Z0(n,s),i.innerHTML="",t$(n,i,r)}function n$(n,t,e){if(t.querySelector(".upload-error"))return;const r=w("div",["upload-error"],t),i=w("div",["error-icon"],r);i.innerHTML=dv;const s=w("div",["error-message"],r);s.innerHTML=R.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,a)=>{if(a.preventDefault(),!a.target||!(a.target instanceof Element)||a.target.tagName!=="A")return;const d=Lf(l,a.target),h=Eu(a.target);!d||h===-1||d.replaceImage(h,e)})}function R7(n,t,e,o,r){const i=Qr(t)[e];!i||(W(i,"error","error-upload"),Z0(n,t),i.innerHTML="",n$(n,i,r))}function O7(n,t,e,o,r,i,s){const l=w("div",["image-container"],e);if(l.setAttribute("data-src",o.src),s.length>1&&(l.style.flexShrink=`${o.flex}`,l.style.flexGrow=`${o.flex}`),i===r&&W(l,"active"),kc(o)){W(l,"empty");const d=w("div",["upload-image-icon"],l);return d.innerHTML=IL,l}const a=w("img",["editor-image"],l);if(a.src=n.doc.buildResourceUrl(o.src),n.domEvents.addEventListener(a,"load",XN),n.domEvents.addEventListener(a,"error",e$),o.src.startsWith("https:")||o.src.startsWith("http:")){const d=w("div",["image-warning"],l);d.innerHTML=uv,d.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("image.load.remote.tooltip"))}return l}function o$(n,t,e,o,r){const i=w("div",["images"],e);return o.forEach((s,l)=>{l>0&&JN(n,t,i,l-1),O7(n,t,i,s,l,r,o)}),o.length>1&&W(t,"multi"),i}function _7(n,t,e,o,r,i){const l=Array.from(t.querySelectorAll(".image-container"))[o];if(!l)return;const a=O7(n,t,null,e,o,r,i);l.insertAdjacentElement("beforebegin",a),l.remove(),Z0(n,t)}function xu(n,t){return Qr(n)[t]}function r$(n,t){const e=L7(t);if(!e)return;const o=Eu(t);if(o===-1)return;const r=Lf(n,t);if(!r)return;const i=r.getImages()[o];_7(n,e,i,o,r.getSelectedIndex(),r.getImages())}function zo(n){return Dt(n)==="embed"&&Un(n)==="image"}async function F7(n){return new Promise((t,e)=>{const o=new Image;o.onload=()=>{t({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=e,o.src=n})}async function i$(n){const t=await Ul(n);return F7(t)}function P7(n){var o;let t="image/*";const e=(o=n.getComponentOptions("image"))==null?void 0:o.allowedMedias;return e&&(t=e.map(r=>`.${r}`).join(",")),t}function N7(n,t){var s;const{maxSize:e,allowedMedias:o,callbacks:r}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}const i=Aa(t.name);if(o&&!o.includes(i)){const l=new Error(`media file is not allowed: ${i}`);throw l.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}}function $7(n){return n.startsWith("image/")}const H7=S("image-object");class xe{constructor(t,e){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(t,e)=>{const o=Eu(e.target);if(o===-1)return;const r=this.images[o];kc(r)||this.setSelectedIndex(o)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||nt(e)===t&&Bu(this.editor,this.blockData,e,null)});m(this,"handleResizing",(t,e)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;this.autoFix||this.setAutoFix(!0);const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const a=l*100/i;this.blockData.embedData.widthPercent=a,Bu(this.editor,this.blockData,o,null)});m(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=cn(this.images,Uo(this.blockData));this.editor.updateEmbedData(e,o),this.blockResizer.enableResize(e)});m(this,"fixImageSizes",He.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=cn(this.images,Uo(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new wu(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=wc(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,o){const r=o$(this.editor,e,o,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Do(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new ResizeObserver(s),this.parentContainerResizerObserver.observe(t)}const i=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&i()&&W(r,"empty"),Bu(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 Uo(this.blockData)}isEmpty(){return this.images.length===1&&kc(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 r=xu(e,this.selectedIndex);r&&et(r,"active")}this.selectedIndex=t;const o=xu(e,t);o&&W(o,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=xu(e,t);if(xt(o,"error"))return;const r=P7(this.editor),i=await zl(r);await this.replaceImage(t,i)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=xu(t,0);!this.isEmpty()&&this.images.length===1&&!xt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const o=this.images[t];kc(o)||(o.height==="auto"&&(o.height=e.height),o.width=e.naturalWidth,o.height=e.naturalHeight,o.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 o=mt.default(this.images);if(o.splice(t,1),o.length===0)return this.editor.deleteBlock(e),!0;o[0].flex=NaN,ku(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=cn(o,Uo(this.blockData));return this.editor.updateEmbedData(e,r),!0}async replaceImage(t,e){const o=this.editor.findBlockById(this.blockData.id);if(!o)return!1;try{const i=await Ul(e),s=this.images[t];if(s.virtualSize){const{width:a,height:d}=await F7(i);s.width=a,s.height=d,s.virtualSize=!1;const h=cn(this.images,Uo(this.blockData));this.editor.updateEmbedData(o,h)}const l={...s,src:i};_7(this.editor,o,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return R7(this.editor,o,t,i,e),!1}const r=xu(o,t);if(!r)return!1;W(r,"uploading"),D7(r,0),W(o,"media-block-uploading");try{const i=await this.editor.doc.uploadResource(e,{onProgress:a=>{D7(r,a)}});et(r,"uploading"),this.images[t].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;et(s,"media-block-uploading");const l=cn(this.images,Uo(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){H7.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(et(r,"uploading"),WN(r),R7(this.editor,s,t,i,e),et(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;g(H7,t.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=t[r];const o=cn(this.images,Uo(this.blockData));this.editor.updateEmbedData(e,o)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=mt.default(this.images);e[0].flex=NaN,ku(e);const o=cn(e,Uo(this.blockData));this.editor.updateEmbedData(t,o)}setData(t){this.blockData=t,this.images=wc(t.embedData)}static create(t,e){const o=t.addCustom(`image-${e.id}`,()=>new xe(t,e));return o.setData(e),o}static getImageObject(t,e){let o;return typeof e=="string"?o=e:o=it(e),t.getCustom(`image-${o}`)}}const Mnt="",Rnt="";function Mf(n){const t=le(n);let e=t.querySelector(":scope > .block-helper");return e||(e=w("div",["block-helper"],t),w("span",["helper-sizer"],e,"A")),e}function Q0(n,t,e){const o=Mf(n),i=Array.from(o.children).find(s=>{var a;return Number.parseInt((a=s.getAttribute("data-index"))!=null?a:"0",10)>e});o.insertBefore(t,i!=null?i:null)}const j7=40,s$=20;class l${findTargetBlock(t,e){const o=e.target;if(o&&o instanceof Element){const a=ot(o);if(a&&Kt(t.rootContainer,a))return a}let r=e.clientX,i=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;r<s&&s-r<j7&&(r+=j7);let l=document.elementFromPoint(r,i);if(l){const a=ot(l);if(a&&Kt(t.rootContainer,a))return a}if(i-=s$,l=document.elementFromPoint(r,i),l){const a=ot(l);if(a&&Kt(t.rootContainer,a))return a}return null}destroy(){}}class c$ extends Cf{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(e){this.currentBlock=e}}function a$(n,t,e){const o=Wm(n,t);if(!o)return[];const r=[];return Object.values(o).forEach(i=>{e!=null&&e.has(i.group)||r.push(...i.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:i.group})))}),r}function Y0(n,t,e={withPlainText:!1}){const o=D0(n,e),r=i=>{i.forEach(s=>{s.source=t,s.children&&r(s.children)})};return r(o),o}function u$(n,t,e,o=!1){var d,h;const r=nt(t);let s=bt(t);he(n,t)||o||(s+=1);const l=at(r),a=e;return a.commandProvider?a.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:l,blockIndex:s}):(h=(d=a.blockOptions)==null?void 0:d.handleInsertEmptyBlock)==null?void 0:h.call(d,n,{containerId:l,blockIndex:s,item:e})}function d$(n,t){const e=Io(n,t),o=n.getBlockData(t);return!(e!=="text"||o.heading)}class U7{constructor(t,e,o){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"createHeadingItemElement",(t,e,o)=>{var i;const r=B0();this.createItem("text",nu,e,d$(this.editor,t)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,o?o===Number(s.value):!1)})});m(this,"createListItemElement",(t,e,o)=>{const{checkbox:r,ordered:i}=o,l=Dt(t)==="list",a=l&&i===!1&&!r,d=l&&i,h=l&&!!r;this.createItem("unordered-list",Cv,e,a),this.createItem("ordered-list",Av,e,d),this.createItem("check-list",gv,e,h)});m(this,"handleClick",(t,e)=>{var l,a;if(!e.target||!(e.target instanceof Node))return;const o=e.target instanceof Element?e.target:e.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&gf(t,this.block,null),i.startsWith(s)){const d=Number.parseInt(i.substring(s.length),10);d&&gf(t,this.block,d)}if(i==="blockquote"&&y0(t,this.block),i.startsWith("align")){const d=i.replace(/^align-/,"");T9(t,this.block,d)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&w0(t,this.block,i),(a=(l=this.options).onAfterStyleItemClick)==null||a.call(l)});this.editor=t,this.block=e,this.options=o,this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const o=w("div",["text-styles"],null),r=w("div",["text-style-section"],o),i=t.getBlockData(e);if(!this.options.fromEmbed){const l=i.heading,a=i.quoted;this.createHeadingItemElement(e,r,l),this.createListItemElement(e,r,i),this.createItem("blockquote",pv,r,!!a)}const s=i.align||"left";return this.createItem("align-left",tu,r,s==="left"),this.createItem("align-center",Lp,r,s==="center"),this.createItem("align-right",Sp,r,s==="right"),o}createItem(t,e,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=Hl(e,i,o);s.id=t}}function z7(){return{source:"separator",type:"separator",id:`section-${K()}`,name:""}}const V7={copy:VL,cut:WL,delete:qL,"lock-block":GL,"unlock-block":ZL,comment:eu},h$=["image","video"];function f$(n,t,e){const o=[],r=tt(n,t),i=Le(t)&&h$.includes(Un(t));if(r?o.push(new U7(n,t,e)):i&&o.push(new U7(n,t,{...e,fromEmbed:!0})),!he(n,t)){(r||i)&&o.push(z7());const s=a$(n,t,new Set(["hovering-toolbar"]));s.sort((l,a)=>{var d,h;return((d=l.order)!=null?d:0)-((h=a.order)!=null?h:0)}),s.forEach(l=>{l.id in V7&&(l.icon=V7[l.id])}),o.push(...s)}return he(n,t)?o.push(...Y0(n,"insert-block")):o.push(z7(),{id:"insert-block-before",icon:QL,name:R.t("blockMenu.command.insertAbove"),children:Y0(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:YL,name:R.t("blockMenu.command.insertAfter"),children:Y0(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),o}function m$(n,t,e){if(e.source==="block-command"){const o=e.blockMenuItemCustomData;d4(n,t,o,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&u$(n,t,e,e.source==="insert-block-before")}const g$=S("exclusive-block");function J0(n,t,e,o){var l;W(t,"block-exclusive");const r=Qt(n,t),i=(l=r.getBlockProperties)==null?void 0:l.call(r,n,t),{abstract:s}=i||{};t.setAttribute("data-user-name",o),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",R.t("exclusive.tips",{editor:o,embedType:s||R.t("exclusive.fallbackAbstract")}))}function W7(n){et(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function p$(n,t,e,o,r){g$.debug(`block ${it(t)} ${e?"exclusive":"unexclusive"}, ${o}, ${r}`),e?J0(n,t,o,r):W7(t)}function Rf(n){return n.classList.contains("block-exclusive")}function q7(n,t){t.blockIds.forEach(e=>{const o=n.findBlockById(e);o&&p$(n,o,t.exclusive,t.userId,t.displayName)})}class Xi{constructor(t){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",t=>{const e=new Set(t.map(r=>r.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([r,i])=>{if(!e.has(i.userId)){this.remoteExclusiveBlockIds.delete(r);const s={...i,exclusive:!1};q7(this.editor,s)}});const o=Array.from(this.exclusiveBlockIds).map(r=>this.editor.findBlockById(r)).filter(r=>!!r);o.length>0&&this.broadcastExclusiveBlockMessage(o,!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;q7(this.editor,e),e.blockIds.forEach(o=>{e.exclusive?this.remoteExclusiveBlockIds.set(o,e):this.remoteExclusiveBlockIds.delete(o)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const o=this.editor.doc.getUser(),r={type:"exclusiveBlock",userId:o.userId,displayName:o.displayName,blockIds:t.map(i=>it(i)),exclusive:e};this.editor.doc.broadcastMessage(r)}exclusiveBlock(t){this.exclusiveBlockIds.has(it(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(it(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(it(t))||(this.exclusiveBlockIds.delete(it(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 Xi(t))}static register(t){return this.get(t)}}function K0(n,t){Xi.get(n).exclusiveBlock(t)}function X0(n,t){Xi.get(n).unexclusiveBlock(t)}class G7{writable(t,e){if(Rf(e))return!1}create(t,e,o,r,i){const s=Xi.get(t).getExclusiveMessage(i.id);s&&J0(t,r,s.userId,s.displayName)}update(t,e,o,r,i){const s=Xi.get(t).getExclusiveMessage(i.id);s?J0(t,r,s.userId,s.displayName):W7(r)}}const Ont="",C$={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},A$={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},b$={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"}};R.mergeLang({"zh-CN":C$,"en-US":A$,"ja-JP":b$});function Iu(n,t){return n.getBlockData(t).lock}function Of(n,t){return!!Iu(n,t)}function Tu(n,t){const e=Iu(n,t);return e?e.userId===n.doc.getUser().userId:!1}function t2(n,t){const e=Iu(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function v$(n,t){if(n.readonly||!n.isBlockWritable(t)||Of(n,t)&&!Tu(n,t))return;const e=n.doc.getUser(),o={userId:e.userId,displayName:e.displayName,locked:Date.now()},i={...n.getBlockData(t),lock:o};n.updateBlockData(t,i)}function y$(n,t){if(!Tu(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const k$=10,w$=80;class e2{constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=t.getBlockById(r.blockId);r.type==="lock"?v$(t,i):r.type==="unlock"&&y$(t,i)})}create(t,e,o,r,i){const s=i.lock;s&&(s.userId!==t.doc.getUser().userId?W(r,"locked-by-others"):W(r,"locked-by-self"))}update(t,e,o,r,i){const s=i.lock;if(s)if(s.userId!==t.doc.getUser().userId){W(r,"locked-by-others");const l=t.selection.focusedBlock;(l===r||Kt(r,l))&&(tt(t,r)||Dt(r)==="code")&&t.insertTextBlock("",at(o),bt(r)+1)}else W(r,"locked-by-self");else et(r,"locked-by-others"),et(r,"locked-by-self")}writable(t,e){if(t2(t,e))return!1;if(ro(e))return;let o=Is(e);for(;o;){if(t2(t,o))return!1;o=Is(o)}}commands(t,e){const o=Of(t,e),r=Tu(t,e),i=Rf(e),s={blockId:it(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(o)if(r)l.id="unlock-block",l.name=R.t("locker.unlock"),s.type="unlock";else{const a=Iu(t,e);let d=(a==null?void 0:a.displayName)||"";const h=OC(d,k$,w$);(h==null?void 0:h.length)!==d.length&&(l.ellipsisTooltip=a==null?void 0:a.displayName,d=h||""),l.name=R.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else i?(l.name=R.t("locker.lock"),l.states=["disabled"]):l.name=R.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const _nt="",B$={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},E$={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},x$={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};R.mergeLang({"zh-CN":B$,"en-US":E$,"ja-JP":x$});class _f{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.lock})}),!1}}const I$=S("standard-block-actions");class T${constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{const i=t.getBlockById(r);if(o.id==="delete"){t.deleteBlock(i);return}o.id==="copy"&&Rh(t,i),o.id==="cut"&&(Rh(t,i),t.deleteBlock(i))}catch(i){I$.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(t,e){const o=Of(t,e),r=o&&Tu(t,e),i=it(e),s=j0(),l=Rf(e),a={id:"copy",name:R.t("blockMenu.command.copy"),data:i,order:1,states:s?[]:["disabled"],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:Bo("CtrlOrCmd+C"),operation:R.t("copyCutProperty.copy")})},d={id:"cut",name:R.t("blockMenu.command.cut"),data:i,order:2,states:o&&!r||!s||l?["disabled"]:[],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:Bo("CtrlOrCmd+X"),operation:R.t("copyCutProperty.cut")})},h={id:"delete",name:R.t("blockMenu.command.delete"),data:i,order:3,states:o&&!r||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[a,d,h],executeCommand:this.executeCommand}}}const Z7=S("block-menu");class D${constructor(t){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{g(Z7,this.currentBlock,"no target block before show block menu");const t=f$(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{Fp(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(t,e)=>{g(Z7,this.commandBlock,"no command block before show block menu"),m$(this.editor,this.commandBlock,e),e.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new zs([],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 T$)}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 S$=1e3;async function L$(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),o=t.getBoundingClientRect();return o.width>e||o.height>=S$?"":(await Q5.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const M$=S("drag-preview-image");class R${constructor(t){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(t,e)=>{const o=t.target;g(M$,o instanceof Element,`Invalid Drag target:${o}`);const{x:r,y:i}=t;this.startPosition={x:r,y:i};const s=w("div",["drag-image-container"],this.editor.rootContainer),l=w("img",["drag-image"],s),a=w("span",["drag-loading"],s);a.innerHTML=tM;const{x:d,width:h,height:p,y:A}=o.getBoundingClientRect(),v=this.editor.rootContainer.getBoundingClientRect(),B=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${A+p}px`,s.style.width=`${Math.min(v.width/2,B.width)}px`,this.dragContainer=s;const T=await L$(this.editor,e);T?l.src=T:W(s,"drag-placeholder"),Am(s,{status:"loaded"})});m(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const Q7="drag-preview-element";function O$(n){if(xt(n,Q7))return n;const t=n.querySelector(`.${Q7}`);return t||(Le(n)?Rt(n):n)}const Ff=S("block-menu-drag-handler");function n2(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 _${constructor(t,e){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(g(Ff,e,"no dragged block"),!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:o,y:r}=t;this.oldPos={x:o,y:r},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",t=>{var s,l;const e=oo(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Gd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const o=this.button.blockMenu.currentBlock;g(Ff,o,"no dragged block"),(l=(s=Qt(this.editor,o)).notify)==null||l.call(s,this.editor,"beginDrag");const r=n2(t,"dragstart");H$(this.editor,r,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const i=O$(o);this.dragPreview.handleDragStart(t,i),this.autoScroll.active(),W(o,"dragging"),W(this.editor.contentElement,"dragging")});m(this,"handleDrag",t=>{const{target:e,x:o,y:r}=t;if(this.oldPos.x===o&&this.oldPos.y===r)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:o,y:r},g(Ff,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const i=n2(t,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",t=>{var r;const e=this.button.blockMenu.currentBlock;g(Ff,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(r=this.autoScroll)==null||r.inactive(),et(e,"dragging"),et(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const o=n2(t,"drop");this.editor.contentElement.dispatchEvent(o)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new R$(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class Du{constructor(t){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=it(t),W(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&et(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new Du(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class Y7{constructor(t){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(t,e,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=Vm(t);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),Q0(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{Du.get(this.editor).highlightBlock(o)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",t=>{Rt(t).setAttribute("data-content-placeholder",R.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;const e=he(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new c$(t),this.blockMenu=new D$(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new _$(this.editor,this);const e=pe.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new l$),Du.register(this.editor)}destroy(){pe.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=w("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,R.t("blockMenu.button.tips")),t.innerHTML=bv,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=XL,this.buttonElement.setAttribute(e,R.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=bv,this.buttonElement.setAttribute(e,R.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),he(this.editor,t)?this.setButtonType("insert"):this.setButtonType("move")}}const F$={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
|
|
419
419
|
\u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},P$={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
|
|
420
|
-
Click to open the menu`,insertTips:"Click to add block"}}},N$={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:"\u30B3\u30D4\u30FC",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"}}};R.mergeLang({"zh-CN":F$,"en-US":P$,"ja-JP":N$});const Fnt="";class $${constructor(){m(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function Pf(n){return n.addCustom("drag-data",()=>new $$)}function o2(n,t){if(!t)return null;const e=Pf(n).getData();return!e||e.editorId!==n.id?null:e}function J7(n,t){const e=o2(n,t);return e?n.findBlockById(e.blockId):null}function H$(n,t,e){if(!t.dataTransfer)return;const r=nt(e),i=at(r),s=it(e),l={type:"block",editorId:n.id,containerId:i,blockId:s};Pf(n).setData(l)}function j$(n,t,e,o,r){if(!t.dataTransfer)return;const s=nt(e),l=at(s),a=it(e),d={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:a,data:r};Pf(n).setData(d)}function U$(n){Pf(n).clearData()}const z$=S("drop-indicator"),Nf=2;class V${constructor(t){m(this,"indicator");m(this,"target",null);this.editor=t,this.indicator=w("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const o=this.getIndicatorRect(t,e),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.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 s=Ds(t);if(!s){g(z$,Do(nt(t)),"block does not in a child container");const d=t.getBoundingClientRect();return new DOMRect(d.x,d.y,d.width,Nf)}const l=s.getBoundingClientRect(),a=t.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+a.top)/2,l.width,Nf)}const o=Ss(t);if(!o){const s=t.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,Nf)}const r=t.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,Nf)}}const W$=S("find-drop-target");function q$(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(_r(e)&&Do(e))return e;const o=e.firstElementChild;return o&&_r(o)&&Do(o)?o:null}function G$(n,t){const s=t,l=n;for(let a=0;a<2;a++){const d=l+a*50;for(let h=0;h<5;h++){const p=s+h*8,A=document.elementFromPoint(d,p);if(A){const D=ot(A);if(D)return D}if(h===0)continue;const v=s-h*8,B=document.elementFromPoint(d,v);if(B){const D=ot(B);if(D)return D}}}return null}function Z$(n,t,e){const o=document.elementFromPoint(t,e);if(o){const h=ot(o);if(h&&!Lt(n,h))return h}const r=new Set,i=q$(t,e);if(i){const h=i.getBoundingClientRect();e<h.top+h.height/2?r.add(Se(i)):r.add(Ge(i))}const s=G$(t,e);s&&r.add(s);const l=Array.from(r),a=h=>{for(let p=0;p<l.length;p++){const A=l[p];if(h!==A&&Kt(h,A))return!0}return!1},d=l.filter(h=>!a(h));return d.length>0?d[0]:null}function r2(n,t){if(n.readonly)return!1;const e=nt(t);if(Xt(e))return!0;const o=ot(e);return g(W$,o,"no parent block"),n.isBlockWritable(o)?r2(n,o):!1}const Q$=S("drop-target");function Y$(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")),g(Q$,e,`unSupport file type ${t.type}`),e}async function K7(n,t,e,o){var i,s;let r=o;for(const l of t){const a=Y$(n,l);a.getOptions&&await((s=(i=a.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(i,n,{containerId:e,blockIndex:r,data:{file:l}}))&&(r+=1)}}class J${constructor(t){m(this,"handleDrop",(t,e,o,r)=>{if(Array.isArray(e)){const i=e;if(i.length>0){const s=at(o);return K7(t,i,s,r),!0}}return!1});this.editor=t}}class Su{constructor(t){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=i=>{var d,h;const s=o2(this.editor,i.dataTransfer),l=J7(this.editor,i.dataTransfer),a=this.findTargetBlock(l,i.x,i.y);if(a&&Kt(this.editor.rootContainer,a)){const p=this.findInsertPos(l,a,i.x,i.y,(h=s!=null?s:(d=i.dataTransfer)==null?void 0:d.items)!=null?h:null);if(p)return this.indicator.show(a,p),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(t,i);return}const r=e(t);o(t,r),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:r}});m(this,"handleDrop",t=>{var i,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=o2(this.editor,t.dataTransfer),o=Array.from((s=(i=t.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!e&&o.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:a}=r,d=J7(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Qt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:o,a,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus();return}if(d){const p=Qt(this.editor,d);if(p.handleDrop&&p.handleDrop(this.editor,d,e!=null?e:o,a,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus();return}}if(typeof a=="string"){const p=nt(l);let A=bt(l);a==="after"&&(A+=1),t.preventDefault();for(let v=0;v<this.handlers.length;v++)if(this.handlers[v].handleDrop(this.editor,d!=null?d:o,p,A)){this.editor.focus();return}if(d){const v=this.editor.getBlockData(d),B=Fi(this.editor.editorBlocks,this.editor.doc.toJSON(),v),[D]=this.editor.insertDocAt(p,A,B);this.editor.selection.selectBlock(D,0),Du.get(this.editor).highlightBlock(D),this.editor.deleteBlock(d),this.editor.focus()}}}),U$(this.editor)}});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new V$(this.editor),this.handlers.push(new J$(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 Su(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||Ss(e)===t&&t||!r2(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Ds(e)===t&&t||!r2(this.editor,e)||Xt(nt(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!Kt(t,e)}findTargetBlock(t,e,o){let r=Z$(this.editor,e,o);if(!r||!Kt(this.editor.rootContainer,r))return null;const i=nt(r),s=ot(i);return s&&Dt(s)==="code"&&(r=s),this.canDrop(t,r)?r:null}findInsertPos(t,e,o,r,i){let s=e;for(;s;){const a=Qt(this.editor,s);if(a.handleDropOver){const d=a.handleDropOver(this.editor,s,i,o,r);if(d)return d;if(d===!1)return null}s=Is(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<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 r<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<r&&this.canInsertAfter(t,e)?"after":""}}function X7(n,t,e){const o=xe.getImageObject(n,t),r=mt.default(o.getImages());if(r.length===1){n.deleteBlock(t);return}if(e===-1||e>=r.length)return;const i=PN(r);if(r.splice(e,1),r.length===1){const l=r[0],a=100*(l.flex/i);l.flex=1;const d=cn([l],a);n.updateEmbedData(t,d);return}r[0].flex=NaN,ku(r);const s=cn(r,o.getWidthPercent());n.updateEmbedData(t,s)}function K$(n,t,e,o){if(t.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=xe.getImageObject(n,e),s=mt.default(i.getImages()),l=[],a=[];t.forEach(p=>{$7(p.type)&&s.length+l.length<6?l.push(p):a.push(p)}),l.forEach(p=>{try{N7(n,p)}catch{return}const A={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,A);const v=cn(s,i.getWidthPercent());n.updateEmbedData(e,v),i.replaceImage(r,p),r+=1});const d=n.getBlockIndex(e)+1,h=at(nt(e));return K7(n,a,h,d),!0}function X$(n,t,e,o,r){var s,l,a;if(Wd(e))return K$(n,e,t,o);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const i=e.data;if(r.isSourceBlock){const d=r.targetBlock,h=nt(d);let p=bt(d);o==="after"&&(p+=1);const v=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),B=cn([i.image],v),D={id:K(),type:"embed",embedType:"image",embedData:B},T=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;T&&(D.align=T),n.insertBlock(at(h),p,D),X7(n,t,i.index),(a=n.findCustom("drag-handler"))==null||a.handleDragEnd()}else{if(typeof o=="string")return;const d=t;let h=o.data;const p=xe.getImageObject(n,d),A=mt.default(p.getImages());h>A.length&&(h=A.length),n.undoManager.runInGroup(()=>{var B,D;p.setAutoFix(!0);const v=n.getBlockById(e.blockId);if(v===d){const T=i.index,_=h,M=i.image;if(T===_||_===T+1)return;let H=_;T<_?(A.splice(_,0,M),A.splice(T,1),H-=1):(A.splice(T,1),A.splice(_,0,M));const z=cn(A,p.getWidthPercent());n.updateEmbedData(d,z),p.setSelectedIndex(H),(B=n.findCustom("drag-handler"))==null||B.handleDragEnd()}else{A.splice(h,0,i.image),A[0].flex=NaN,ku(A);const T=cn(A,p.getWidthPercent());n.updateEmbedData(d,T),X7(n,v,i.index),(D=n.findCustom("drag-handler"))==null||D.handleDragEnd(),p.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const tH=2;function $f(n,t,e){const o=Qr(t);if(e<=0){const s=o[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===o.length){const s=o[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const r=o[e-1].getBoundingClientRect(),i=o[e].getBoundingClientRect();return new DOMRect((i.left+r.right)/2-1,r.top,tH,r.height)}function eH(n,t,e,o,r){for(let i=0;i<e.length;i++){const l=e[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:$f(n,t,i),data:i}:{rect:$f(n,t,i+1),data:i+1}}return o>e[e.length-1].getBoundingClientRect().right?{rect:$f(n,t,e.length),data:e.length}:{rect:$f(n,t,e.length),data:0}}function nH(n,t,e,o,r){const i=Qr(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>$7(s.type))||i.length>=6)return}else{if((e==null?void 0:e.type)==="block"||i.length>=6&&(e==null?void 0:e.blockId)!==it(t))return;const s=it(t);if(i.length===1&&s===(e==null?void 0:e.blockId))return}return eH(n,t,i,o)}async function oH(n){return await Q5.default.toSvg(n)}function i2(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 rH{constructor(t){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement))return;const o=ot(e);if(!o||!zo(o)||!this.editor.isBlockWritable(o)||this.editor.readonly)return;const r=xe.getImageObject(this.editor,o);if(this.imageContainer=G0(t.target),!this.imageContainer)return;const s=M7(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=r.getImages()[s];if(!l)return;const{x:a,y:d}=t;this.startPosition={x:a,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},p=i2(t,"dragstart");j$(this.editor,p,o,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});m(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=ot(this.imageContainer);if(!e)return;const{x:o,y:r}=t,{width:i,height:s}=t.target.getBoundingClientRect(),l=le(e),a=w("div",["drag-container"],l);a.style.left=`${o-i/4}px`,a.style.top=`${r-s/4}px`,a.style.width=`${Math.max(i/2,16)}px`,a.style.height=`${s/2}px`,this.dragContainer=a;const d=w("img",["drag-target"],a),p=await oH(this.imageContainer);p&&(d.src=p),W(this.editor.contentElement,"dragging");const A=oo(e);this.autoScroll=new Gd({scrollElement:A,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active()});m(this,"handleDrag",t=>{var i;const{x:e,y:o}=t;if(((i=this.startPosition)==null?void 0:i.x)===e&&this.startPosition.y===o)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:a,y:d}=this.startPosition,h=s-a,p=l-d;this.dragContainer.style.transform=`translate(${h}px, ${p}px)`,this.dragContainer.style.opacity="0.5"}const r=i2(t,"dragover");this.editor.contentElement.dispatchEvent(r)});m(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(),et(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const o=i2(t,"drop");this.editor.contentElement.dispatchEvent(o)}});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 iH{constructor(t){m(this,"handleFocusBlockChanged",(t,e,o)=>{const i=this.editor.getFocusedBlock();if(i&&zo(i)){const s=xe.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&zo(o)&&xe.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class sH{constructor(t){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(t,e)=>{e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t))});this.editor=t,pe.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){pe.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){zo(t)&&xe.getImageObject(this.editor,t).disableResizer()}enable(t){if(zo(t)){const e=xe.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const lH={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"}},cH={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"}},aH={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"}};R.mergeLang({"zh-CN":lH,"en-US":cH,"ja-JP":aH});function uH(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=xn(i,o),l=re(s);let a=o;if(l.endsWith("![]()"))a-=5;else if(l.endsWith("![]"))a-=3;else return!1;const d=o;return zl("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a);let p=e+1;re(n.getBlockText(r)).trim()?(Yl(n,r,a,{forceInsertAfter:!0}),a===0&&(n.deleteBlock(r),p--)):(n.deleteBlock(r),p--),qm(n,"image",t,p,{file:h})})}),!0}class dH{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&uH(t,e,o,r))}}function hH(n){const t=n.getFocusedBlock(),e=Ss(t);if(e&&zo(e)){n.selection.selectBlock(e,0);const o=xe.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function fH(n){const t=n.getFocusedBlock(),e=Ds(t);if(e&&zo(e)){n.selection.selectBlock(e,0);const o=xe.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function mH(n){const e=n.getFocusedBlock();if(e&&zo(e)){const o=xe.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(r.length-1),!0;if(i>0)return o.setSelectedIndex(i-1),!0}}}function gH(n){const e=n.getFocusedBlock();if(e&&zo(e)){const o=xe.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(0),!0;if(i<r.length-1)return o.setSelectedIndex(i+1),!0}}}function s2(n){const e=n.getFocusedBlock();if(e&&zo(e)){const o=xe.getImageObject(n,e);if(o.getImages().length>0){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}const pH={ArrowLeft:mH,ArrowRight:gH,ArrowUp:fH,ArrowDown:hH,Delete:s2,Backspace:s2},CH=S("copy-image");function AH(n,t,e,o){const r=e.getImages()[o],i=e.getImages().length===1?e.getWidthPercent():r.flex*100,s=cn([r],i),l={id:K(),type:"embed",embedType:"image",embedData:s},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(l.align=a.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const p=h.getContext("2d");if(!p)return;const A={},v={};try{p.drawImage(t,0,0,h.width,h.height);const z=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),q=Dm(z),rt=new File([q],`${Date.now()}.png`,{type:"image/png"});A["image/png"]=rt}catch(H){CH.error(H)}Mh(n,d);const D=`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`,T=Lh(D,d),_=Ma(n,d);A["text/plain"]=new Blob([_],{type:"text/plain"}),v["text/plain"]=_;const M=new Blob([T],{type:"text/html"});return A["text/html"]=M,v["text/html"]=T,[A,v]}function bH(n,t,e,o,r){const i=AH(n,t,e,o);if(!i)return;const[s,l]=i;if(s){const a=Object.entries(s).map(([d,h])=>({type:d,data:h}));return Mm(a).then(d=>{if(!d&&r){const h=r.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function t8(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const r=n.getFocusedBlock();if(r&&zo(r)){const i=xe.getImageObject(n,r);if(i.getImages().length>0){const l=i.getSelectedIndex();if(l!==-1){const d=Qr(r)[l].querySelector("img");if(d)return bH(n,d,i,l,t)}}}}class vH{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,o){if(t8(t,e))return!0}handleBeforeCut(t,e){if(t8(t,e))return s2(t),!0}destroy(){}}class l2{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,o){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{if(i.type==="embed"&&i.embedType==="image"){const s=i.embedData;if(Array.isArray(s.src))return;if(s.src.startsWith("https:")||s.src.startsWith("http:")){const l=o.blockIdMap.get(i.id);l&&Ki(t,l).setAutoFix(!0)}}})}),!1}destroy(){}}const yH=S("image-embed");function kH(n,t,e,o,r,i){xe.create(n,e).createContent(r,i,t),n.addCustom("image-select-handler",()=>new iH(n)),n.addCustom("image-copy-handler",()=>new vH(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new rH(n));const l=n.addCustom("image-resizer",()=>new sH(n)),a=e.embedData;kc(a)?l.disable(i):l.currentResizer===i&&l.enable(i)})}function wH(n,t,e,o){const r=t.embedData,i=wc(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`})`).join(`
|
|
420
|
+
Click to open the menu`,insertTips:"Click to add block"}}},N$={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:"\u30B3\u30D4\u30FC",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"}}};R.mergeLang({"zh-CN":F$,"en-US":P$,"ja-JP":N$});const Fnt="";class $${constructor(){m(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function Pf(n){return n.addCustom("drag-data",()=>new $$)}function o2(n,t){if(!t)return null;const e=Pf(n).getData();return!e||e.editorId!==n.id?null:e}function J7(n,t){const e=o2(n,t);return e?n.findBlockById(e.blockId):null}function H$(n,t,e){if(!t.dataTransfer)return;const r=nt(e),i=at(r),s=it(e),l={type:"block",editorId:n.id,containerId:i,blockId:s};Pf(n).setData(l)}function j$(n,t,e,o,r){if(!t.dataTransfer)return;const s=nt(e),l=at(s),a=it(e),d={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:a,data:r};Pf(n).setData(d)}function U$(n){Pf(n).clearData()}const z$=S("drop-indicator"),Nf=2;class V${constructor(t){m(this,"indicator");m(this,"target",null);this.editor=t,this.indicator=w("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const o=this.getIndicatorRect(t,e),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.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 s=Ds(t);if(!s){g(z$,Do(nt(t)),"block does not in a child container");const d=t.getBoundingClientRect();return new DOMRect(d.x,d.y,d.width,Nf)}const l=s.getBoundingClientRect(),a=t.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+a.top)/2,l.width,Nf)}const o=Ss(t);if(!o){const s=t.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,Nf)}const r=t.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,Nf)}}const W$=S("find-drop-target");function q$(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(_r(e)&&Do(e))return e;const o=e.firstElementChild;return o&&_r(o)&&Do(o)?o:null}function G$(n,t){const s=t,l=n;for(let a=0;a<2;a++){const d=l+a*50;for(let h=0;h<5;h++){const p=s+h*8,A=document.elementFromPoint(d,p);if(A){const D=ot(A);if(D)return D}if(h===0)continue;const v=s-h*8,B=document.elementFromPoint(d,v);if(B){const D=ot(B);if(D)return D}}}return null}function Z$(n,t,e){const o=document.elementFromPoint(t,e);if(o){const h=ot(o);if(h&&!Lt(n,h))return h}const r=new Set,i=q$(t,e);if(i){const h=i.getBoundingClientRect();e<h.top+h.height/2?r.add(Se(i)):r.add(Ge(i))}const s=G$(t,e);s&&r.add(s);const l=Array.from(r),a=h=>{for(let p=0;p<l.length;p++){const A=l[p];if(h!==A&&Kt(h,A))return!0}return!1},d=l.filter(h=>!a(h));return d.length>0?d[0]:null}function r2(n,t){if(n.readonly)return!1;const e=nt(t);if(Xt(e))return!0;const o=ot(e);return g(W$,o,"no parent block"),n.isBlockWritable(o)?r2(n,o):!1}const Q$=S("drop-target");function Y$(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")),g(Q$,e,`unSupport file type ${t.type}`),e}async function K7(n,t,e,o){var i,s;let r=o;for(const l of t){const a=Y$(n,l);a.getOptions&&await((s=(i=a.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(i,n,{containerId:e,blockIndex:r,data:{file:l}}))&&(r+=1)}}class J${constructor(t){m(this,"handleDrop",(t,e,o,r)=>{if(Array.isArray(e)){const i=e;if(i.length>0){const s=at(o);return K7(t,i,s,r),!0}}return!1});this.editor=t}}class Su{constructor(t){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=i=>{var d,h;const s=o2(this.editor,i.dataTransfer),l=J7(this.editor,i.dataTransfer),a=this.findTargetBlock(l,i.x,i.y);if(a&&Kt(this.editor.rootContainer,a)){const p=this.findInsertPos(l,a,i.x,i.y,(h=s!=null?s:(d=i.dataTransfer)==null?void 0:d.items)!=null?h:null);if(p)return this.indicator.show(a,p),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(t,i);return}const r=e(t);o(t,r),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:r}});m(this,"handleDrop",t=>{var i,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=o2(this.editor,t.dataTransfer),o=Array.from((s=(i=t.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!e&&o.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:a}=r,d=J7(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Qt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:o,a,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus();return}if(d){const p=Qt(this.editor,d);if(p.handleDrop&&p.handleDrop(this.editor,d,e!=null?e:o,a,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus();return}}if(typeof a=="string"){const p=nt(l);let A=bt(l);a==="after"&&(A+=1),t.preventDefault();for(let v=0;v<this.handlers.length;v++)if(this.handlers[v].handleDrop(this.editor,d!=null?d:o,p,A)){this.editor.focus();return}if(d){const v=this.editor.getBlockData(d),B=Fi(this.editor.editorBlocks,this.editor.doc.toJSON(),v),[D]=this.editor.insertDocAt(p,A,B);this.editor.selection.selectBlock(D,0),Du.get(this.editor).highlightBlock(D),this.editor.deleteBlock(d),this.editor.focus()}}}),U$(this.editor)}});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new V$(this.editor),this.handlers.push(new J$(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 Su(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||Ss(e)===t&&t||!r2(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Ds(e)===t&&t||!r2(this.editor,e)||Xt(nt(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!Kt(t,e)}findTargetBlock(t,e,o){let r=Z$(this.editor,e,o);if(!r||!Kt(this.editor.rootContainer,r))return null;const i=nt(r),s=ot(i);return s&&Dt(s)==="code"&&(r=s),this.canDrop(t,r)?r:null}findInsertPos(t,e,o,r,i){let s=e;for(;s;){const a=Qt(this.editor,s);if(a.handleDropOver){const d=a.handleDropOver(this.editor,s,i,o,r);if(d)return d;if(d===!1)return null}s=Is(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<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 r<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<r&&this.canInsertAfter(t,e)?"after":""}}function X7(n,t,e){const o=xe.getImageObject(n,t),r=mt.default(o.getImages());if(r.length===1){n.deleteBlock(t);return}if(e===-1||e>=r.length)return;const i=PN(r);if(r.splice(e,1),r.length===1){const l=r[0],a=100*(l.flex/i);l.flex=1;const d=cn([l],a);n.updateEmbedData(t,d);return}r[0].flex=NaN,ku(r);const s=cn(r,o.getWidthPercent());n.updateEmbedData(t,s)}function K$(n,t,e,o){if(t.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=xe.getImageObject(n,e),s=mt.default(i.getImages()),l=[],a=[];t.forEach(p=>{$7(p.type)&&s.length+l.length<6?l.push(p):a.push(p)}),l.forEach(p=>{try{N7(n,p)}catch{return}const A={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,A);const v=cn(s,i.getWidthPercent());n.updateEmbedData(e,v),i.replaceImage(r,p),r+=1});const d=n.getBlockIndex(e)+1,h=at(nt(e));return K7(n,a,h,d),!0}function X$(n,t,e,o,r){var s,l,a;if(Wd(e))return K$(n,e,t,o);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const i=e.data;if(r.isSourceBlock){const d=r.targetBlock,h=nt(d);let p=bt(d);o==="after"&&(p+=1);const v=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),B=cn([i.image],v),D={id:K(),type:"embed",embedType:"image",embedData:B},T=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;T&&(D.align=T),n.insertBlock(at(h),p,D),X7(n,t,i.index),(a=n.findCustom("drag-handler"))==null||a.handleDragEnd()}else{if(typeof o=="string")return;const d=t;let h=o.data;const p=xe.getImageObject(n,d),A=mt.default(p.getImages());h>A.length&&(h=A.length),n.undoManager.runInGroup(()=>{var B,D;p.setAutoFix(!0);const v=n.getBlockById(e.blockId);if(v===d){const T=i.index,_=h,M=i.image;if(T===_||_===T+1)return;let H=_;T<_?(A.splice(_,0,M),A.splice(T,1),H-=1):(A.splice(T,1),A.splice(_,0,M));const z=cn(A,p.getWidthPercent());n.updateEmbedData(d,z),p.setSelectedIndex(H),(B=n.findCustom("drag-handler"))==null||B.handleDragEnd()}else{A.splice(h,0,i.image),A[0].flex=NaN,ku(A);const T=cn(A,p.getWidthPercent());n.updateEmbedData(d,T),X7(n,v,i.index),(D=n.findCustom("drag-handler"))==null||D.handleDragEnd(),p.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const tH=2;function $f(n,t,e){const o=Qr(t);if(e<=0){const s=o[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===o.length){const s=o[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const r=o[e-1].getBoundingClientRect(),i=o[e].getBoundingClientRect();return new DOMRect((i.left+r.right)/2-1,r.top,tH,r.height)}function eH(n,t,e,o,r){for(let i=0;i<e.length;i++){const l=e[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:$f(n,t,i),data:i}:{rect:$f(n,t,i+1),data:i+1}}return o>e[e.length-1].getBoundingClientRect().right?{rect:$f(n,t,e.length),data:e.length}:{rect:$f(n,t,e.length),data:0}}function nH(n,t,e,o,r){const i=Qr(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>$7(s.type))||i.length>=6)return}else{if((e==null?void 0:e.type)==="block"||i.length>=6&&(e==null?void 0:e.blockId)!==it(t))return;const s=it(t);if(i.length===1&&s===(e==null?void 0:e.blockId))return}return eH(n,t,i,o)}async function oH(n){return await Q5.default.toSvg(n)}function i2(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 rH{constructor(t){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement))return;const o=ot(e);if(!o||!zo(o)||!this.editor.isBlockWritable(o)||this.editor.readonly)return;const r=xe.getImageObject(this.editor,o);if(this.imageContainer=G0(t.target),!this.imageContainer)return;const s=M7(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=r.getImages()[s];if(!l)return;const{x:a,y:d}=t;this.startPosition={x:a,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},p=i2(t,"dragstart");j$(this.editor,p,o,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});m(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=ot(this.imageContainer);if(!e)return;const{x:o,y:r}=t,{width:i,height:s}=t.target.getBoundingClientRect(),l=le(e),a=w("div",["drag-container"],l);a.style.left=`${o-i/4}px`,a.style.top=`${r-s/4}px`,a.style.width=`${Math.max(i/2,16)}px`,a.style.height=`${s/2}px`,this.dragContainer=a;const d=w("img",["drag-target"],a),p=await oH(this.imageContainer);p&&(d.src=p),W(this.editor.contentElement,"dragging");const A=oo(e);this.autoScroll=new Gd({scrollElement:A,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active()});m(this,"handleDrag",t=>{var i;const{x:e,y:o}=t;if(((i=this.startPosition)==null?void 0:i.x)===e&&this.startPosition.y===o)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:a,y:d}=this.startPosition,h=s-a,p=l-d;this.dragContainer.style.transform=`translate(${h}px, ${p}px)`,this.dragContainer.style.opacity="0.5"}const r=i2(t,"dragover");this.editor.contentElement.dispatchEvent(r)});m(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(),et(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const o=i2(t,"drop");this.editor.contentElement.dispatchEvent(o)}});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 iH{constructor(t){m(this,"handleFocusBlockChanged",(t,e,o)=>{const i=this.editor.getFocusedBlock();if(i&&zo(i)){const s=xe.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&zo(o)&&xe.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class sH{constructor(t){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(t,e)=>{e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t))});this.editor=t,pe.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){pe.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){zo(t)&&xe.getImageObject(this.editor,t).disableResizer()}enable(t){if(zo(t)){const e=xe.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const lH={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"}},cH={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"}},aH={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"}};R.mergeLang({"zh-CN":lH,"en-US":cH,"ja-JP":aH});function uH(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=xn(i,o),l=re(s);let a=o;if(l.endsWith("![]()"))a-=5;else if(l.endsWith("![]"))a-=3;else return!1;const d=o;return zl("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a);let p=e+1;re(n.getBlockText(r)).trim()?(Yl(n,r,a,{forceInsertAfter:!0}),a===0&&(n.deleteBlock(r),p--)):(n.deleteBlock(r),p--),qm(n,"image",t,p,{file:h})})}),!0}class dH{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&uH(t,e,o,r))}}function hH(n){const t=n.getFocusedBlock(),e=Ss(t);if(e&&zo(e)){n.selection.selectBlock(e,0);const o=xe.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function fH(n){const t=n.getFocusedBlock(),e=Ds(t);if(e&&zo(e)){n.selection.selectBlock(e,0);const o=xe.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function mH(n){const e=n.getFocusedBlock();if(e&&zo(e)){const o=xe.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(r.length-1),!0;if(i>0)return o.setSelectedIndex(i-1),!0}}}function gH(n){const e=n.getFocusedBlock();if(e&&zo(e)){const o=xe.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(0),!0;if(i<r.length-1)return o.setSelectedIndex(i+1),!0}}}function s2(n){const e=n.getFocusedBlock();if(e&&zo(e)){const o=xe.getImageObject(n,e);if(o.getImages().length>0){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}const pH={ArrowLeft:mH,ArrowRight:gH,ArrowUp:fH,ArrowDown:hH,Delete:s2,Backspace:s2},CH=S("copy-image");function AH(n,t,e,o){const r=e.getImages()[o],i=e.getImages().length===1?e.getWidthPercent():r.flex*100,s=cn([r],i),l={id:K(),type:"embed",embedType:"image",embedData:s},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(l.align=a.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const p=h.getContext("2d");if(!p)return;const A={},v={};try{p.drawImage(t,0,0,h.width,h.height);const z=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),q=Dm(z),rt=new File([q],`${Date.now()}.png`,{type:"image/png"});A["image/png"]=rt}catch(H){CH.error(H)}Mh(n,d);const D=`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`,T=Lh(D,d),_=Ma(n,d);A["text/plain"]=new Blob([_],{type:"text/plain"}),v["text/plain"]=_;const M=new Blob([T],{type:"text/html"});return A["text/html"]=M,v["text/html"]=T,[A,v]}function bH(n,t,e,o,r){const i=AH(n,t,e,o);if(!i)return;const[s,l]=i;if(s){const a=Object.entries(s).map(([d,h])=>({type:d,data:h}));return Mm(a).then(d=>{if(!d&&r){const h=r.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function ty(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const r=n.getFocusedBlock();if(r&&zo(r)){const i=xe.getImageObject(n,r);if(i.getImages().length>0){const l=i.getSelectedIndex();if(l!==-1){const d=Qr(r)[l].querySelector("img");if(d)return bH(n,d,i,l,t)}}}}class vH{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,o){if(ty(t,e))return!0}handleBeforeCut(t,e){if(ty(t,e))return s2(t),!0}destroy(){}}class l2{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,o){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{if(i.type==="embed"&&i.embedType==="image"){const s=i.embedData;if(Array.isArray(s.src))return;if(s.src.startsWith("https:")||s.src.startsWith("http:")){const l=o.blockIdMap.get(i.id);l&&Ki(t,l).setAutoFix(!0)}}})}),!1}destroy(){}}const yH=S("image-embed");function kH(n,t,e,o,r,i){xe.create(n,e).createContent(r,i,t),n.addCustom("image-select-handler",()=>new iH(n)),n.addCustom("image-copy-handler",()=>new vH(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new rH(n));const l=n.addCustom("image-resizer",()=>new sH(n)),a=e.embedData;kc(a)?l.disable(i):l.currentResizer===i&&l.enable(i)})}function wH(n,t,e,o){const r=t.embedData,i=wc(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`})`).join(`
|
|
421
421
|
`)}
|
|
422
422
|
`:i.map(s=>n.doc.buildResourceUrl(s.src,{withToken:!0})).join(`
|
|
423
|
-
`)}class BH{constructor(){m(this,"group","image");m(this,"commands",[])}executeCommand(t,e,o){if(o.id==="replace-image"){const{block:r,image:i}=o.data;xe.getImageObject(t,r).replaceImage(0,i)}}}function EH(){return{blockCommands:{image:new BH},abstract:`${R.t("image.abstract")}`}}function xH(){return{name:"Image",insertEmbedCommandItems:[{id:"insert-image",name:R.t("image.abstract"),icon:EL,group:"common",subText:"/image",order:100}],handleInsertEmptyEmbed:async(n,t)=>{var v;let e;(v=t.data)!=null&&v.file&&(e=t.data.file);const o=P7(n);if(e=e!=null?e:await zl(o),!e)return null;try{N7(n,e)}catch{return null}let r={width:k7,height:z0};try{r=await i$(e)}catch(B){yH.error(B)}const i=n.rootContainer.clientWidth,s=r.width<i?Math.min(100,r.width/i*100):100,l={src:"",width:r.width,height:r.height,flex:1,virtualSize:!1},a=cn([l],s),d={id:K(),type:"embed",embedType:"image",embedData:a},h=n.options.componentsOptions.image;h!=null&&h.defaultAlign&&(d.align=h.defaultAlign);const p=n.insertBlock(t.containerId,t.blockIndex,d);return xe.getImageObject(n,p).replaceImage(0,e),p}}}function IH(n,t,e){var h;const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="image"||!tt(n,t))return null;const i=r.match(/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/),s=(h=i==null?void 0:i.groups)==null?void 0:h.filename;if(!s)return null;const l={src:s},a={id:K(),type:"embed",embedType:"image",embedData:l};xe.create(n,a).setAutoFix(!0);const d=n.options.componentsOptions.image.defaultAlign;return d&&(a.align=d),{blockData:a}}function TH(n,t){const e=it(t);n.destroyCustom(`image-${e}`)}const e8={embedType:"image",createEmbedContent:kH,convertTo:wH,convertFrom:IH,getBlockProperties:EH,getOptions:xH,handleDrop:X$,handleDropOver:nH,handleDeleteBlock:TH};class DH{constructor(t,e){m(this,"toolbar");m(this,"anchor",null);m(this,"item");m(this,"docs",null);m(this,"checkedId");m(this,"handlePasteSpecial",(t,e)=>{!e.data||(this.checkedId===e.id?this.checkedId=void 0:this.checkedId=e.id,this.onPasteSpecial(e.data),setTimeout(()=>{this.docs&&this.show(this.docs),this.editor.focus()}))});m(this,"handleClose",()=>{this.editor.focus()});m(this,"handleSelectionChange",()=>{this.hide()});this.editor=t,this.onPasteSpecial=e,this.item={id:"paste-special",name:"",icon:xL,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",childrenOffset:[-4,4],children:[]},this.toolbar=new ou([this.item],void 0,{id:"paste-special-button",tooltipId:this.editor.clientId,refuseOverflow:!0}),this.toolbar.addListener("click",this.handlePasteSpecial),this.toolbar.addListener("close",this.handleClose),this.editor.addListener("selectionChanged",this.handleSelectionChange)}show(t){this.docs=t;const e=this.editor,o=e.selection.range;if(!o.isCollapsed())return;const r=e.getBlockById(o.start.blockId);if(!tt(e,r))return;const i=Ti(e,r,o)[0];if(!i)return;this.anchor&&this.anchor.remove(),this.anchor=Li(e,r,"paste-special-button-anchor",i);const s=this.getCommandItems(t);this.item.children=s,this.toolbar.manualShow(this.anchor)}hide(){this.toolbar.close("selectionChange")}clearCheckedState(){this.checkedId=void 0}destroy(){this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange)}getCommandItems(t){const e=i=>({id:i,states:this.checkedId===i?["checked"]:void 0,name:R.t("pasteSpecial.originFormats"),data:t[i]}),o=[];let r=!0;return t["text/x-ones-editor-doc"]?o.push(e("text/x-ones-editor-doc")):t["text/office-html"]?o.push(e("text/office-html")):t["text/html"]?o.push(e("text/html")):t["text/plain"]&&(o.push(e("text/plain")),r=!1),t["text/plain"]&&(r&&o.push({id:"text/plain",states:this.checkedId==="text/plain"?["checked"]:void 0,name:R.t("pasteSpecial.plainText"),data:t["text/plain"]}),o.push({id:"text/markdown",states:this.checkedId==="text/markdown"?["checked"]:void 0,name:R.t("pasteSpecial.markdown"),data:t["text/markdown"]})),o}}const SH=S("paste-special");class c2{constructor(t){m(this,"button");m(this,"lastUndoAction",null);m(this,"event",null);m(this,"handlePasteSpecial",t=>{this.editor.undoManager.runInGroup(()=>{this.editor.undoManager.undoTo(this.lastUndoAction),this.editor.pasteDoc(t)})});this.editor=t,this.button=new DH(t,this.handlePasteSpecial)}destroy(){this.event=null,this.button.destroy()}handleChanged(t,e){this.event=null,this.button.hide()}async handleBeforePaste(t,e){return SH.debug("before paste"),this.lastUndoAction=t.undoManager.lastAction(),!1}async handleAfterPaste(t,e,o){if(Object.keys(o).length<=1)return!1;const r=t.selection.range;if(r.isCollapsed()){const i=t.getBlockById(r.start.blockId);if(!tt(t,i))return!1;this.button.clearCheckedState(),this.button.show(o),this.event=e}return!1}}const LH={pasteSpecial:{originFormats:"\u4FDD\u6301\u539F\u6837\u5F0F",plainText:"\u7C98\u8D34\u7EAF\u6587\u672C",markdown:"\u7C98\u8D34\u4E3A Markdown"}},MH={pasteSpecial:{originFormats:"Keep origin formats",plainText:"Paste as plain text",markdown:"Paste as markdown"}},RH={pasteSpecial:{originFormats:"\u5143\u306E\u30B9\u30BF\u30A4\u30EB\u3092\u7DAD\u6301\u3059\u308B",plainText:"\u30D7\u30EC\u30FC\u30F3\u30C6\u30AD\u30B9\u30C8\u3092\u8CBC\u308A\u4ED8\u3051\u308B",markdown:"Markdown \u3068\u3057\u3066\u8CBC\u308A\u4ED8\u3051"}};R.mergeLang({"zh-CN":LH,"en-US":MH,"ja-JP":RH});const Pnt="",OH=S("html-to-doc");function _H(n){const t="ones-editor-doc::",e="::ones-editor-doc";let o=n.indexOf(t);if(o!==-1){o+=t.length;const r=n.indexOf(e,o);if(r!==-1){const i=n.substr(o,r-o);try{const s=Ud(i);return JSON.parse(s)}catch(s){OH.error(`invalid doc data: ${s}, ${i}`)}}}return null}const n8="latex-b172fea480b",FH=n=>({name:"latex-block",level:"block",start(t){var e,o;return(o=(e=t.match(/\$\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$\$([^\$]+)\$\$/.exec(t);return o?{type:"latex-block",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${n8}" block>${t.formula}</span>`:n.render(t.formula,!0)}}),PH=n=>({name:"latex",level:"inline",start(t){var e,o;return(o=(e=t.match(/\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$([^\$]+)\$/.exec(t);return o?{type:"latex",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${n8}">${t.formula}</span>`:n.render(t.formula,!1)}});var NH=(n={})=>(n.lazy&&n.env!=="test"&&new IntersectionObserver((t,e)=>{for(const o of t){if(!o.isIntersecting)continue;const r=o.target;e.unobserve(r),Promise.resolve(n.render(r.innerText,r.hasAttribute("block"))).then(i=>{r.innerHTML=i}),r.classList.add("latex-rendered")}},{threshold:1}),{extensions:[FH(n),PH(n)]});function Bc(n){const t=n.type;if(t==="link")return!!n.tokens.some(Bc);switch(t){case"code":case"table":case"hr":case"blockquote":case"list":case"list_item":case"image":case"paragraph":return!0;default:return!1}}function $H(n){return!Bc(n)}function HH(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=Bc(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===Bc(i)?e.push(i):(t.push(e),e=[i],o=Bc(i))}return t.push(e),t}function jH(n,t,e){const o=n.href;let r=e.tokensToText(n.tokens,t,e);return r.length===0&&(r=Oi(o,t)),r=uh(r,"link",o),r}let Lu;function a2(n){Lu||(Lu=document.createElement("textarea")),Lu.innerHTML=n;const t=Lu.childNodes.length===0?"":Lu.childNodes[0].nodeValue;return t!=null?t:""}function UH(n,t){const e=a2(n.text);return[lo(e,{...t,"style-code":!0})]}function zH(n,t,e){const r=n.tokens;return r?e.tokensToText(r,t,e):ag(a2(n.text),t)}const VH=S("token-to-text");function u2(n,t,e){return n.map(r=>r.type==="text"?zH(r,t,e):r.type==="strong"?e.tokensToText(r.tokens,{...t,"style-bold":!0},e):r.type==="em"?e.tokensToText(r.tokens,{...t,"style-italic":!0},e):r.type==="del"?e.tokensToText(r.tokens,{...t,"style-strikethrough":!0},e):r.type==="link"?jH(r,t,e):r.type==="codespan"?UH(r,t):r.type==="br"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"br"}}]:r.type==="escape"?ag(a2(r.text),t):r.type==="latex"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"math",tex:r.formula}}]:(VH.warn(`unknown token in text: ${JSON.stringify(r)}`),[])).flat()}function WH(n,t){const e=u2(n.tokens,{},t);return[{id:K(),type:"text",text:e,heading:n.depth}]}function qH(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function GH(n,t){const{text:e,children:o}=t.tokensToTextWithChildren([n],t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function ZH(n,t){const e=typeof n.start=="number"?n.start:1,o=n.ordered,r=K(),i=[];return n.items.forEach((l,a)=>{const d={...t,listLevel:t.listLevel+1},{text:h,children:p}=t.tokensToTextWithChildren(l.tokens,d);let A;typeof l.checked=="boolean"&&(A=l.checked?"checked":"unchecked");const v={id:K(),type:"list",groupId:r,ordered:o,checkbox:A,start:e+a,text:h,level:t.listLevel};i.push(v),i.push(...p)}),i}function QH(n,t){const e=t.tokensToBlocks(n.tokens,t);return e.forEach(o=>{o.quoted=!0}),e}const o8=100,YH=20,JH=600;function KH(n,t){const e=t.text;if(e){const o=re(e);return Math.min(Vd(o,n)+YH,JH)}return o8}function r8(n,t){let e=o8;return t.forEach(o=>{e=Math.max(e,KH(n,o))}),e}function XH(n,t){var l,a;const e=n.header.length,o=n.rows.length+1,r=[],i=Array(e).fill(100);for(let d=0;d<o;d++){let h;d===0?h=n.header:h=n.rows[d-1];for(let p=0;p<e;p++){const A=h[p],v=(l=A==null?void 0:A.tokens)!=null?l:[],B=K();r.push(B);let D;if(v.length===0)D=[hh()];else if(Bc(v[0]))D=t.tokensToBlocks(A.tokens,t),D.length===0&&D.push(hh());else{const{text:T,children:_}=t.tokensToTextWithChildren(A.tokens,t);D=[{id:K(),type:"text",text:T},..._]}t.doc.blocks[B]=D,i[p]=Math.max(i[p],r8((a=t.font)!=null?a:"",D))}}return[{id:K(),type:"table",cols:e,rows:o,colsWidth:i,children:r}]}function tj(n){return[{id:K(),type:"embed",embedType:"hr",embedData:{}}]}function ej(n,t){var a;const e=n.text;if(!e)return[];try{const d=n.text,h=Ud(d),p=JSON.parse(h);if(p){const{root:A,...v}=p.blocks;return t.doc.blocks={...t.doc.blocks,...v},A}}catch{}const o=(a=n.lang)!=null?a:"Plain Text";if(o==="mermaid")return[{id:K(),type:"embed",embedType:"mermaid",embedData:{mermaidText:e}}];if(o==="plantuml")return[{id:K(),type:"embed",embedType:"plantuml",embedData:{plantumlText:e}}];if(o==="flow"||o==="flowchart")return[{id:K(),type:"embed",embedType:"flowchart",embedData:{flowchartText:e}}];const i=e.split(`
|
|
424
|
-
`).map(d=>({id:K(),type:"text",text:Oi(d)})),s=t.doc,l=K();return s.blocks[l]=i,[{id:K(),type:"code",language:o,children:[l]}]}function nj(n){return[{id:K(),type:"embed",embedType:"image",embedData:{src:n.href,title:n.title}}]}function oj(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function rj(n){const t=n.formula;return t?[{id:K(),type:"embed",embedType:"math",embedData:{mathjaxText:t}}]:[]}const
|
|
425
|
-
`).length/2)-1;return r>0?new Array(r).fill("").map(()=>({type:"text",id:K(),text:[]})):[]}if(n.type==="html"){const o=(e=t.htmlToDoc)==null?void 0:e.call(t,n.text);if(!o)return
|
|
423
|
+
`)}class BH{constructor(){m(this,"group","image");m(this,"commands",[])}executeCommand(t,e,o){if(o.id==="replace-image"){const{block:r,image:i}=o.data;xe.getImageObject(t,r).replaceImage(0,i)}}}function EH(){return{blockCommands:{image:new BH},abstract:`${R.t("image.abstract")}`}}function xH(){return{name:"Image",insertEmbedCommandItems:[{id:"insert-image",name:R.t("image.abstract"),icon:EL,group:"common",subText:"/image",order:100}],handleInsertEmptyEmbed:async(n,t)=>{var v;let e;(v=t.data)!=null&&v.file&&(e=t.data.file);const o=P7(n);if(e=e!=null?e:await zl(o),!e)return null;try{N7(n,e)}catch{return null}let r={width:k7,height:z0};try{r=await i$(e)}catch(B){yH.error(B)}const i=n.rootContainer.clientWidth,s=r.width<i?Math.min(100,r.width/i*100):100,l={src:"",width:r.width,height:r.height,flex:1,virtualSize:!1},a=cn([l],s),d={id:K(),type:"embed",embedType:"image",embedData:a},h=n.options.componentsOptions.image;h!=null&&h.defaultAlign&&(d.align=h.defaultAlign);const p=n.insertBlock(t.containerId,t.blockIndex,d);return xe.getImageObject(n,p).replaceImage(0,e),p}}}function IH(n,t,e){var h;const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="image"||!tt(n,t))return null;const i=r.match(/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/),s=(h=i==null?void 0:i.groups)==null?void 0:h.filename;if(!s)return null;const l={src:s},a={id:K(),type:"embed",embedType:"image",embedData:l};xe.create(n,a).setAutoFix(!0);const d=n.options.componentsOptions.image.defaultAlign;return d&&(a.align=d),{blockData:a}}function TH(n,t){const e=it(t);n.destroyCustom(`image-${e}`)}const ey={embedType:"image",createEmbedContent:kH,convertTo:wH,convertFrom:IH,getBlockProperties:EH,getOptions:xH,handleDrop:X$,handleDropOver:nH,handleDeleteBlock:TH};class DH{constructor(t,e){m(this,"toolbar");m(this,"anchor",null);m(this,"item");m(this,"docs",null);m(this,"checkedId");m(this,"handlePasteSpecial",(t,e)=>{!e.data||(this.checkedId===e.id?this.checkedId=void 0:this.checkedId=e.id,this.onPasteSpecial(e.data),setTimeout(()=>{this.docs&&this.show(this.docs),this.editor.focus()}))});m(this,"handleClose",()=>{this.editor.focus()});m(this,"handleSelectionChange",()=>{this.hide()});this.editor=t,this.onPasteSpecial=e,this.item={id:"paste-special",name:"",icon:xL,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",childrenOffset:[-4,4],children:[]},this.toolbar=new ou([this.item],void 0,{id:"paste-special-button",tooltipId:this.editor.clientId,refuseOverflow:!0}),this.toolbar.addListener("click",this.handlePasteSpecial),this.toolbar.addListener("close",this.handleClose),this.editor.addListener("selectionChanged",this.handleSelectionChange)}show(t){this.docs=t;const e=this.editor,o=e.selection.range;if(!o.isCollapsed())return;const r=e.getBlockById(o.start.blockId);if(!tt(e,r))return;const i=Ti(e,r,o)[0];if(!i)return;this.anchor&&this.anchor.remove(),this.anchor=Li(e,r,"paste-special-button-anchor",i);const s=this.getCommandItems(t);this.item.children=s,this.toolbar.manualShow(this.anchor)}hide(){this.toolbar.close("selectionChange")}clearCheckedState(){this.checkedId=void 0}destroy(){this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange)}getCommandItems(t){const e=i=>({id:i,states:this.checkedId===i?["checked"]:void 0,name:R.t("pasteSpecial.originFormats"),data:t[i]}),o=[];let r=!0;return t["text/x-ones-editor-doc"]?o.push(e("text/x-ones-editor-doc")):t["text/office-html"]?o.push(e("text/office-html")):t["text/html"]?o.push(e("text/html")):t["text/plain"]&&(o.push(e("text/plain")),r=!1),t["text/plain"]&&(r&&o.push({id:"text/plain",states:this.checkedId==="text/plain"?["checked"]:void 0,name:R.t("pasteSpecial.plainText"),data:t["text/plain"]}),o.push({id:"text/markdown",states:this.checkedId==="text/markdown"?["checked"]:void 0,name:R.t("pasteSpecial.markdown"),data:t["text/markdown"]})),o}}const SH=S("paste-special");class c2{constructor(t){m(this,"button");m(this,"lastUndoAction",null);m(this,"event",null);m(this,"handlePasteSpecial",t=>{this.editor.undoManager.runInGroup(()=>{this.editor.undoManager.undoTo(this.lastUndoAction),this.editor.pasteDoc(t)})});this.editor=t,this.button=new DH(t,this.handlePasteSpecial)}destroy(){this.event=null,this.button.destroy()}handleChanged(t,e){this.event=null,this.button.hide()}async handleBeforePaste(t,e){return SH.debug("before paste"),this.lastUndoAction=t.undoManager.lastAction(),!1}async handleAfterPaste(t,e,o){if(Object.keys(o).length<=1)return!1;const r=t.selection.range;if(r.isCollapsed()){const i=t.getBlockById(r.start.blockId);if(!tt(t,i))return!1;this.button.clearCheckedState(),this.button.show(o),this.event=e}return!1}}const LH={pasteSpecial:{originFormats:"\u4FDD\u6301\u539F\u6837\u5F0F",plainText:"\u7C98\u8D34\u7EAF\u6587\u672C",markdown:"\u7C98\u8D34\u4E3A Markdown"}},MH={pasteSpecial:{originFormats:"Keep origin formats",plainText:"Paste as plain text",markdown:"Paste as markdown"}},RH={pasteSpecial:{originFormats:"\u5143\u306E\u30B9\u30BF\u30A4\u30EB\u3092\u7DAD\u6301\u3059\u308B",plainText:"\u30D7\u30EC\u30FC\u30F3\u30C6\u30AD\u30B9\u30C8\u3092\u8CBC\u308A\u4ED8\u3051\u308B",markdown:"Markdown \u3068\u3057\u3066\u8CBC\u308A\u4ED8\u3051"}};R.mergeLang({"zh-CN":LH,"en-US":MH,"ja-JP":RH});const Pnt="",OH=S("html-to-doc");function _H(n){const t="ones-editor-doc::",e="::ones-editor-doc";let o=n.indexOf(t);if(o!==-1){o+=t.length;const r=n.indexOf(e,o);if(r!==-1){const i=n.substr(o,r-o);try{const s=Ud(i);return JSON.parse(s)}catch(s){OH.error(`invalid doc data: ${s}, ${i}`)}}}return null}const ny="latex-b172fea480b",FH=n=>({name:"latex-block",level:"block",start(t){var e,o;return(o=(e=t.match(/\$\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$\$([^\$]+)\$\$/.exec(t);return o?{type:"latex-block",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${ny}" block>${t.formula}</span>`:n.render(t.formula,!0)}}),PH=n=>({name:"latex",level:"inline",start(t){var e,o;return(o=(e=t.match(/\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$([^\$]+)\$/.exec(t);return o?{type:"latex",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${ny}">${t.formula}</span>`:n.render(t.formula,!1)}});var NH=(n={})=>(n.lazy&&n.env!=="test"&&new IntersectionObserver((t,e)=>{for(const o of t){if(!o.isIntersecting)continue;const r=o.target;e.unobserve(r),Promise.resolve(n.render(r.innerText,r.hasAttribute("block"))).then(i=>{r.innerHTML=i}),r.classList.add("latex-rendered")}},{threshold:1}),{extensions:[FH(n),PH(n)]});function Bc(n){const t=n.type;if(t==="link")return!!n.tokens.some(Bc);switch(t){case"code":case"table":case"hr":case"blockquote":case"list":case"list_item":case"image":case"paragraph":return!0;default:return!1}}function $H(n){return!Bc(n)}function HH(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=Bc(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===Bc(i)?e.push(i):(t.push(e),e=[i],o=Bc(i))}return t.push(e),t}function jH(n,t,e){const o=n.href;let r=e.tokensToText(n.tokens,t,e);return r.length===0&&(r=Oi(o,t)),r=uh(r,"link",o),r}let Lu;function a2(n){Lu||(Lu=document.createElement("textarea")),Lu.innerHTML=n;const t=Lu.childNodes.length===0?"":Lu.childNodes[0].nodeValue;return t!=null?t:""}function UH(n,t){const e=a2(n.text);return[lo(e,{...t,"style-code":!0})]}function zH(n,t,e){const r=n.tokens;return r?e.tokensToText(r,t,e):ag(a2(n.text),t)}const VH=S("token-to-text");function u2(n,t,e){return n.map(r=>r.type==="text"?zH(r,t,e):r.type==="strong"?e.tokensToText(r.tokens,{...t,"style-bold":!0},e):r.type==="em"?e.tokensToText(r.tokens,{...t,"style-italic":!0},e):r.type==="del"?e.tokensToText(r.tokens,{...t,"style-strikethrough":!0},e):r.type==="link"?jH(r,t,e):r.type==="codespan"?UH(r,t):r.type==="br"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"br"}}]:r.type==="escape"?ag(a2(r.text),t):r.type==="latex"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"math",tex:r.formula}}]:(VH.warn(`unknown token in text: ${JSON.stringify(r)}`),[])).flat()}function WH(n,t){const e=u2(n.tokens,{},t);return[{id:K(),type:"text",text:e,heading:n.depth}]}function qH(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function GH(n,t){const{text:e,children:o}=t.tokensToTextWithChildren([n],t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function ZH(n,t){const e=typeof n.start=="number"?n.start:1,o=n.ordered,r=K(),i=[];return n.items.forEach((l,a)=>{const d={...t,listLevel:t.listLevel+1},{text:h,children:p}=t.tokensToTextWithChildren(l.tokens,d);let A;typeof l.checked=="boolean"&&(A=l.checked?"checked":"unchecked");const v={id:K(),type:"list",groupId:r,ordered:o,checkbox:A,start:e+a,text:h,level:t.listLevel};i.push(v),i.push(...p)}),i}function QH(n,t){const e=t.tokensToBlocks(n.tokens,t);return e.forEach(o=>{o.quoted=!0}),e}const oy=100,YH=20,JH=600;function KH(n,t){const e=t.text;if(e){const o=re(e);return Math.min(Vd(o,n)+YH,JH)}return oy}function ry(n,t){let e=oy;return t.forEach(o=>{e=Math.max(e,KH(n,o))}),e}function XH(n,t){var l,a;const e=n.header.length,o=n.rows.length+1,r=[],i=Array(e).fill(100);for(let d=0;d<o;d++){let h;d===0?h=n.header:h=n.rows[d-1];for(let p=0;p<e;p++){const A=h[p],v=(l=A==null?void 0:A.tokens)!=null?l:[],B=K();r.push(B);let D;if(v.length===0)D=[hh()];else if(Bc(v[0]))D=t.tokensToBlocks(A.tokens,t),D.length===0&&D.push(hh());else{const{text:T,children:_}=t.tokensToTextWithChildren(A.tokens,t);D=[{id:K(),type:"text",text:T},..._]}t.doc.blocks[B]=D,i[p]=Math.max(i[p],ry((a=t.font)!=null?a:"",D))}}return[{id:K(),type:"table",cols:e,rows:o,colsWidth:i,children:r}]}function tj(n){return[{id:K(),type:"embed",embedType:"hr",embedData:{}}]}function ej(n,t){var a;const e=n.text;if(!e)return[];try{const d=n.text,h=Ud(d),p=JSON.parse(h);if(p){const{root:A,...v}=p.blocks;return t.doc.blocks={...t.doc.blocks,...v},A}}catch{}const o=(a=n.lang)!=null?a:"Plain Text";if(o==="mermaid")return[{id:K(),type:"embed",embedType:"mermaid",embedData:{mermaidText:e}}];if(o==="plantuml")return[{id:K(),type:"embed",embedType:"plantuml",embedData:{plantumlText:e}}];if(o==="flow"||o==="flowchart")return[{id:K(),type:"embed",embedType:"flowchart",embedData:{flowchartText:e}}];const i=e.split(`
|
|
424
|
+
`).map(d=>({id:K(),type:"text",text:Oi(d)})),s=t.doc,l=K();return s.blocks[l]=i,[{id:K(),type:"code",language:o,children:[l]}]}function nj(n){return[{id:K(),type:"embed",embedType:"image",embedData:{src:n.href,title:n.title}}]}function oj(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function rj(n){const t=n.formula;return t?[{id:K(),type:"embed",embedType:"math",embedData:{mathjaxText:t}}]:[]}const iy=S("markdown-to-doc");function ij(n,t){var e;if(n.type==="heading")return WH(n,t);if(n.type==="paragraph")return qH(n,t);if(n.type==="list")return ZH(n,t);if(n.type==="blockquote")return QH(n,t);if(n.type==="table")return XH(n,t);if(n.type==="hr")return tj();if(n.type==="code")return ej(n,t);if(n.type==="image")return nj(n);if(n.type==="link")return oj(n,t);if(n.type==="latex-block")return rj(n);if(n.type==="text")return GH(n,t);if(n.type==="space"){const o=n.raw.replaceAll(" ",""),r=Math.floor(o.split(`
|
|
425
|
+
`).length/2)-1;return r>0?new Array(r).fill("").map(()=>({type:"text",id:K(),text:[]})):[]}if(n.type==="html"){const o=(e=t.htmlToDoc)==null?void 0:e.call(t,n.text);if(!o)return iy.warn(`failed to convert html to doc: ${JSON.stringify(n)}`),[];const{root:r,...i}=o.blocks;return t.doc.blocks={...t.doc.blocks,...i},r}return iy.warn(`unknown block token: ${JSON.stringify(n)}`),[]}function d2(n,t){const e=[];return n.forEach(o=>{const r=ij(o,t);e.push(...r)}),e}S("markdown-to-doc");function sj(n,t){const e={text:[],children:[]};return HH(n).forEach((r,i)=>{const s=r[0];if(i===0&&$H(s)){e.text=u2(r,{},t);return}e.children.push(...d2(r,t))}),e}const lj={render:(n,t)=>""};G5.marked.use(NH(lj));function sy(n,t){const o=new G5.marked.Lexer().lex(n),r={blocks:{root:[]},meta:{},comments:{}},i={font:t==null?void 0:t.font,doc:r,tokensToText:u2,tokensToBlocks:d2,tokensToTextWithChildren:sj,htmlToDoc:t==null?void 0:t.htmlToDoc,listLevel:1},s=d2(o,i);return s.length===0?null:(r.blocks.root.push(...s),r)}function cj(n){if(n.nodeName!=="DIV")return!1;const t=n;return Array.from(t.childNodes).every(e=>e.nodeName==="SPAN"||e instanceof Text)?!!t.querySelector(":scope > .hljs-function, :scope > .hljs-params, :scope > .hljs-string, :scope > .hljs-keyword, :scope > .hljs-attr"):!1}function ly(n){if(cj(n)){const t=n,e=t.parentNode,o=document.createElement("pre");Array.from(t.childNodes).forEach(r=>o.appendChild(r)),e==null||e.insertBefore(o,t);return}n.childNodes.forEach(t=>ly(t))}function Hf(n){var t;if(n instanceof HTMLBRElement){const e=document.createTextNode(`
|
|
426
426
|
`);(t=n.parentNode)==null||t.insertBefore(e,n),n.remove();return}n.childNodes.forEach(Hf)}function aj(n){n.addRule("preOnlyBlockToCode",{filter:t=>t.nodeName!=="PRE"?!1:Array.from(t.childNodes).every(e=>e.nodeName==="SPAN"||e instanceof Text||e.nodeName==="BR"),replacement:(t,e,o)=>{var r;return Hf(e),`
|
|
427
427
|
|
|
428
428
|
`+o.fence+`
|
|
@@ -466,20 +466,20 @@ ${s}
|
|
|
466
466
|
|
|
467
467
|
> ${o}
|
|
468
468
|
|
|
469
|
-
`}})}class pj{constructor(t){m(this,"_grid",[]);m(this,"_needFixSpanData",!1);Array.from(t.rows).forEach((e,o)=>{Array.from(e.cells).forEach(r=>{this._addCell(o,r)})})}_addCell(t,e){const o=this._getNextColIndex(t),r=e.colSpan,i=e.rowSpan;for(let s=0;s<i;s++)for(let l=0;l<r;l++){const a=t+s,d=o+l;if(this._getCell({row:a,col:d})){this._needFixSpanData=!0,console.warn(`invalid table data, cell data already exists, ${a}, ${d}`);continue}this._setCell({row:a,col:d},{cell:e,virtual:!(l===0&&s===0)})}}_getNextColIndex(t){const e=this._grid[t];if(!e)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r])o+=1;else return o;return o}_setCell(t,e){if(!(e.cell.colSpan===0||e.cell.rowSpan===0)){for(;this._grid.length<=t.row;)this._grid.push([]);for(let o=0;o<this._grid.length;o++){const r=this._grid[o];for(;r.length<=t.col;)r.push(null)}this._grid[t.row][t.col]=e}}_getCell(t){var o;const e=this._grid[t.row];return e&&(o=e[t.col])!=null?o:null}get rowCount(){return this._grid.length}get colCount(){return this._grid[0].length}getCellData(t){const e=this._getCell(t);return e||null}getCellSpan(t){const e=this._getCell(t);if(!e)return{colSpan:1,rowSpan:1};if(e.virtual)return{colSpan:1,rowSpan:1};const o=()=>{let l=t.col+1;for(;;){const a=this._getCell({row:t.row,col:l});if(!a||a.cell!==e.cell)return l-t.col;l+=1}},r=()=>{let l=t.row+1;for(;;){const a=this._getCell({row:l,col:t.col});if(!a||a.cell!==e.cell)return l-t.row;l+=1}},i=o(),s=r();return i!==e.cell.colSpan&&console.warn(`invalid colSpan: ${i} -> ${e.cell.colSpan}`),s!==e.cell.rowSpan&&console.warn(`invalid rowSpan: ${s} -> ${e.cell.rowSpan}`),{colSpan:i,rowSpan:s}}getColumnWidth(t){const r=Array(this.rowCount).fill(0).map((s,l)=>{const a=this.getCellData({row:l,col:t});if(a&&!a.virtual){const d=a.cell.getAttribute("width")||a.cell.style.width;if(d){if(d.endsWith("%")){const p=d.substr(0,d.length-1),A=Number.parseInt(p,10);if(A>0&&A<=100)return Math.floor(720*A/100)}const h=Number.parseInt(d,10);if(h)return h}return a.cell.getBoundingClientRect().width}return 1e9}),i=Math.min(...r);return i===1e9||Number.isNaN(i)||i<30?0:i}}function Cj(n){return new pj(n)}function c8(n,t){var a;const e=Cj(n),o=[],r={},i=e.rowCount,s=e.colCount,l=Array(s).fill(100);for(let d=0;d<i;d++)for(let h=0;h<s;h++){let p;const A=e.getCellData({row:d,col:h});if(A&&A.virtual)continue;A&&!A.virtual&&(p=t.htmlToBlocks(A.cell.innerHTML,t)),(!p||p.length===0)&&(p=[{id:K(),type:"text",text:[]}]);const v=K();o.push(v);const{colSpan:B,rowSpan:D}=e.getCellSpan({row:d,col:h});D>1&&(r[`${v}_rowSpan`]=D),B>1&&(r[`${v}_colSpan`]=B),t.doc.blocks[v]=p,A&&!A.virtual&&(l[h]=Math.max(l[h],r8((a=t.font)!=null?a:"",p)))}for(let d=0;d<e.colCount;d++)l[d]=e.getColumnWidth(d)||l[d];return o.length===0?[]:[{cols:e.colCount,rows:e.rowCount,id:K(),type:"table",children:o,...r,colsWidth:l}]}function a8(n,t){var e;if(n.tagName==="TABLE"){const o={blocks:{root:[]},meta:{},comments:{}},r=c8(n,{doc:o,...t});if(r.length===0||((e=r[0].children)==null?void 0:e.length)===0)return;o.blocks.root=r;const i=JSON.stringify(o),s=Bs(i),l=document.createElement("div");l.classList.add("highlight-text-wizdoc");const a=document.createElement("pre");l.appendChild(a),a.innerText=s,n.insertAdjacentElement("beforebegin",l),n.remove();return}Array.from(n.children).forEach(o=>a8(o,t))}function u8(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(u8)}function d8(n){if(n instanceof HTMLElement){if(n.style.display==="none"){n.remove();return}if(n.style.visibility==="hidden"){n.remove();return}}Array.from(n.children).forEach(d8)}function Aj(n,t){const e=zd(n);return e.querySelectorAll("td.js-line-number").forEach(r=>r.remove()),e.querySelectorAll("div.copy-button").forEach(r=>r.remove()),e.querySelectorAll("div.code-copy-button").forEach(r=>r.remove()),e.querySelectorAll("noscript").forEach(r=>r.remove()),Array.from(e.children).forEach(d8),Array.from(e.children).forEach(r=>a8(r,t)),Array.from(e.children).forEach(u8),l8(e),xC(e)}const Yr=new qB.default;Yr.use(aj),Yr.use(uj),Yr.use(dj),Yr.use(hj),Yr.use(fj),Yr.use(mj),Yr.use(gj),Yr.use(MB.gfm);function bj(n,t){const e=h8(n,t);if(!e)return[];const{root:o,...r}=e.blocks;return t.doc.blocks={...t.doc.blocks,...r},o}function h8(n,t){const e=Yr.turndown(n);return s8(e,{htmlToDoc:o=>f8(o,t)})}function f8(n,t){const e=Aj(n,{font:t==null?void 0:t.font,htmlToBlocks:bj});return h8(e)}function m8(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function jf(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP","FONT","BR"].indexOf(n.tagName)!==-1}function vj(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function g8(n){return n.replace(/\r\n\s*/g,"").replace(/\n\s*/g,"").replace(/\r\s*/g,"")}function yj(n){if(!n.tagName)return!1;if(n.tagName.toLocaleLowerCase()==="img")return!0;const t=n.querySelectorAll("img");for(let e=0;e<t.length;e+=1){const o=t[e];if(!o.src||o.getAttribute("width")==="0"||o.getAttribute("height")==="0")return!1}return t.length}function kj(n){return(n.tagName.toLocaleLowerCase()==="img"?[n]:Array.from(n.querySelectorAll("img"))).map(r=>({id:K(),type:"embed",embedType:"image",embedData:{src:r.src,width:r.width,height:r.height}}))}function p8(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(o=>o.startsWith("level"))!==-1}function wj(n){var e;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let o=0;o<t.length;o++){const r=t[o];if(r.startsWith("mso-list:"))return r}return""}function C8(n){var e,o;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let r=0;r<t.length;r++){const i=t[r];if(i.startsWith("level")){const s=(o=Number.parseInt(i.substring(5),10))!=null?o:void 0;if(s)return s}}return 1}function Bj(n,t){n.setAttribute("data-group-id",t)}function Ej(n){const t={},e=r=>{Array.from(Object.keys(t)).forEach(i=>{Number.parseInt(i,10)>r&&delete t[i]})};let o="";Array.from(n.children).forEach(r=>{if(p8(r)){const i=wj(r);o!==i&&(e(0),o=i);const s=C8(r);e(s);let l=t[`${s}`];l||(l=K(),t[`${s}`]=l),Bj(r,l)}})}function A8(n){if(!p8(n))return{};const t=C8(n),e=n.getAttribute("data-group-id")||K();return{start:1,level:t,groupId:e,ordered:!0,type:"list"}}const xj=S("office-list");function b8(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function Ij(n,t){g(xj,b8(n),"not list group element");let e=!1,o=1;const r=K();n instanceof HTMLOListElement&&(e=!0,o=n.start);const i=n,s=[];let l;return Array.from(i.children).forEach(a=>{if(a instanceof HTMLLIElement){const h=A8(a),p=t.textElementToBlocks(a,t);l||(l=h.level);const A=p[0];s.push({...A,type:"list",ordered:e,level:l,groupId:r,start:o}),o+=1,s.push(...p.slice(1));return}const d=t.blockElementToBlocks(a,t);s.push(...d)}),s}function v8(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return c8(n,t);if(b8(n))return[...Ij(n,t)];if(yj(n))return[...kj(n)];if(vj(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(o=>{const r=v8(o,t);e.push(...r)}),e}function y8(n,t){const e=[];return n.forEach(o=>{var r;if(o instanceof Element)if(jf(o)){const i=document.createElement("p");i.appendChild(o);const s=t.blockElementToBlocks(i,t);e.push(...s)}else{const i=t.blockElementToBlocks(o,t);e.push(...i)}else if(o instanceof Text){const i=sr(g8((r=o.textContent)!=null?r:""));e.push(i)}}),e}function k8(n){const t=Array.from(n.children);for(let e=0;e<t.length;e++){const o=t[e];if(!jf(o))continue;let r=e+1;for(;r<t.length&&jf(t[r]);)r+=1;const i=document.createElement("p");o.insertAdjacentElement("beforebegin",i);for(let s=e;s<r;s++)i.appendChild(t[s]);e=r-1}}function Tj(n,t){const e=zd(n);return k8(e),y8(Array.from(e.childNodes),t)}function Dj(n){if(!(n instanceof HTMLElement))return{};const t={};if(n.style.textAlign==="right"?t.align="right":n.style.textAlign==="center"&&(t.align="center"),n.style.marginLeft){const e=Math.ceil(Number.parseInt(n.style.marginLeft,10)/20);e>=1&&e<=12&&(t.padding=e)}return t}function Sj(n,t){return t&&Object.keys(t).length>0?{insert:n,attributes:t}:{insert:n}}function Lj(n,t){if(n.nodeName==="B")return{...t,"style-bold":!0};if(n.nodeName==="I")return{...t,"style-italic":!0};if(n.nodeName==="U")return{...t,"style-underline":!0};if(n.nodeName==="S"||n.nodeName==="DEL")return{...t,"style-strikethrough":!0};if(n.nodeName==="SUB")return{...t,"style-sub":!0};if(n.nodeName==="SUP")return{...t,"style-super":!0};if(n.nodeName==="BR")return{...t,created:Date.now(),id:K(),box:!0,type:"br"};if(n.nodeName==="A"&&n.href){const o=n.href;if(o.startsWith("http:")||o.startsWith("https:"))return{...t,link:n.href}}const e={...t};return n instanceof HTMLSpanElement?(n.style.backgroundColor&&(e["inline-style-background-color"]=n.style.backgroundColor),n.style.color&&(e["inline-style-color"]=n.style.color),n.style.fontSize&&(e["inline-style-font-size"]=n.style.fontSize),n.style.fontFamily&&(e["inline-style-font-family"]=n.style.fontFamily),e):t}function w8(n,t,e){var r;if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const o=Lj(n,t);if(n instanceof Text&&n.nodeValue||n.nodeName==="BR"){const i=g8((r=n.nodeValue)!=null?r:" ");i&&e.push(Sj(i,o));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(i=>{w8(i,o,e)})}function B8(n){return n instanceof Element?jf(n):!0}function h2(n){return!B8(n)}function Mj(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=h2(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===h2(i)?e.push(i):(t.push(e),e=[i],o=h2(i))}return t.push(e),t}function Rj(n,t){const e={};if(n.tagName.startsWith("H")){const i=Number.parseInt(n.tagName.substr(1),10);i>=1&&i<=8&&(e.heading=i)}const o=Mj(Array.from(n.childNodes)),r=[];return o.forEach((i,s)=>{if(B8(i[0])){const l=[],a={};Array.from(n.childNodes).forEach(h=>{w8(h,a,l)});let d={};s===0&&(d=A8(n)),r.push({id:K(),type:"text",text:l,...d,...e,...Dj(n)})}i.forEach(l=>{const a=t.blockElementToBlocks(l,t);r.push(...a)})}),r}function Oj(n,t){const e=zd(n);Ej(e),k8(e);const o={blocks:{root:[]},meta:{},comments:{}},r={font:t==null?void 0:t.font,doc:o,blockElementToBlocks:v8,textElementToBlocks:Rj,htmlToBlocks:Tj},i=y8(Array.from(e.children),r);if(i.length!==0)return o.blocks.root=i,o}const _j=S("html-to-doc");function E8(n,t){if(!n)return null;const e=_H(n);if(e)return e;if(m8(n)){const o=Oj(n,t);if(o)return o}try{return f8(n,t)}catch(o){_j.error(o)}return null}class Fj{async fromData(t,e){const o={},r=e.getData("text/html");if(r){const i=E8(r,{font:t.rootContainer});i&&(m8(r)?o["text/office-html"]=i:o["text/html"]=i)}return o}}class Pj{async fromData(t,e){const o=e.getData("text/plain");if(!o)return;const r=s8(o,{font:t.rootContainer,htmlToDoc:E8});if(!!r)return{"text/markdown":r}}}function Nj(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function $j(n){const t=[],e=n.split(/https|http|ftp/)[0],o=n.substring(e.length).trim();if(e&&e.length){const i=lo(e,null);t.push(i,lo(" ",null))}const r=lo(o,{link:o});return t.push(r,lo(" ",null)),t}class Hj{async fromData(t,e,o){const{toPlainText:r=!1}=o||{},i={},s=e.getData("text/plain");if(s){const d={blocks:{root:s.replace(/\r\n/g,`
|
|
469
|
+
`}})}class pj{constructor(t){m(this,"_grid",[]);m(this,"_needFixSpanData",!1);Array.from(t.rows).forEach((e,o)=>{Array.from(e.cells).forEach(r=>{this._addCell(o,r)})})}_addCell(t,e){const o=this._getNextColIndex(t),r=e.colSpan,i=e.rowSpan;for(let s=0;s<i;s++)for(let l=0;l<r;l++){const a=t+s,d=o+l;if(this._getCell({row:a,col:d})){this._needFixSpanData=!0,console.warn(`invalid table data, cell data already exists, ${a}, ${d}`);continue}this._setCell({row:a,col:d},{cell:e,virtual:!(l===0&&s===0)})}}_getNextColIndex(t){const e=this._grid[t];if(!e)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r])o+=1;else return o;return o}_setCell(t,e){if(!(e.cell.colSpan===0||e.cell.rowSpan===0)){for(;this._grid.length<=t.row;)this._grid.push([]);for(let o=0;o<this._grid.length;o++){const r=this._grid[o];for(;r.length<=t.col;)r.push(null)}this._grid[t.row][t.col]=e}}_getCell(t){var o;const e=this._grid[t.row];return e&&(o=e[t.col])!=null?o:null}get rowCount(){return this._grid.length}get colCount(){return this._grid[0].length}getCellData(t){const e=this._getCell(t);return e||null}getCellSpan(t){const e=this._getCell(t);if(!e)return{colSpan:1,rowSpan:1};if(e.virtual)return{colSpan:1,rowSpan:1};const o=()=>{let l=t.col+1;for(;;){const a=this._getCell({row:t.row,col:l});if(!a||a.cell!==e.cell)return l-t.col;l+=1}},r=()=>{let l=t.row+1;for(;;){const a=this._getCell({row:l,col:t.col});if(!a||a.cell!==e.cell)return l-t.row;l+=1}},i=o(),s=r();return i!==e.cell.colSpan&&console.warn(`invalid colSpan: ${i} -> ${e.cell.colSpan}`),s!==e.cell.rowSpan&&console.warn(`invalid rowSpan: ${s} -> ${e.cell.rowSpan}`),{colSpan:i,rowSpan:s}}getColumnWidth(t){const r=Array(this.rowCount).fill(0).map((s,l)=>{const a=this.getCellData({row:l,col:t});if(a&&!a.virtual){const d=a.cell.getAttribute("width")||a.cell.style.width;if(d){if(d.endsWith("%")){const p=d.substr(0,d.length-1),A=Number.parseInt(p,10);if(A>0&&A<=100)return Math.floor(720*A/100)}const h=Number.parseInt(d,10);if(h)return h}return a.cell.getBoundingClientRect().width}return 1e9}),i=Math.min(...r);return i===1e9||Number.isNaN(i)||i<30?0:i}}function Cj(n){return new pj(n)}function cy(n,t){var a;const e=Cj(n),o=[],r={},i=e.rowCount,s=e.colCount,l=Array(s).fill(100);for(let d=0;d<i;d++)for(let h=0;h<s;h++){let p;const A=e.getCellData({row:d,col:h});if(A&&A.virtual)continue;A&&!A.virtual&&(p=t.htmlToBlocks(A.cell.innerHTML,t)),(!p||p.length===0)&&(p=[{id:K(),type:"text",text:[]}]);const v=K();o.push(v);const{colSpan:B,rowSpan:D}=e.getCellSpan({row:d,col:h});D>1&&(r[`${v}_rowSpan`]=D),B>1&&(r[`${v}_colSpan`]=B),t.doc.blocks[v]=p,A&&!A.virtual&&(l[h]=Math.max(l[h],ry((a=t.font)!=null?a:"",p)))}for(let d=0;d<e.colCount;d++)l[d]=e.getColumnWidth(d)||l[d];return o.length===0?[]:[{cols:e.colCount,rows:e.rowCount,id:K(),type:"table",children:o,...r,colsWidth:l}]}function ay(n,t){var e;if(n.tagName==="TABLE"){const o={blocks:{root:[]},meta:{},comments:{}},r=cy(n,{doc:o,...t});if(r.length===0||((e=r[0].children)==null?void 0:e.length)===0)return;o.blocks.root=r;const i=JSON.stringify(o),s=Bs(i),l=document.createElement("div");l.classList.add("highlight-text-wizdoc");const a=document.createElement("pre");l.appendChild(a),a.innerText=s,n.insertAdjacentElement("beforebegin",l),n.remove();return}Array.from(n.children).forEach(o=>ay(o,t))}function uy(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(uy)}function dy(n){if(n instanceof HTMLElement){if(n.style.display==="none"){n.remove();return}if(n.style.visibility==="hidden"){n.remove();return}}Array.from(n.children).forEach(dy)}function Aj(n,t){const e=zd(n);return e.querySelectorAll("td.js-line-number").forEach(r=>r.remove()),e.querySelectorAll("div.copy-button").forEach(r=>r.remove()),e.querySelectorAll("div.code-copy-button").forEach(r=>r.remove()),e.querySelectorAll("noscript").forEach(r=>r.remove()),Array.from(e.children).forEach(dy),Array.from(e.children).forEach(r=>ay(r,t)),Array.from(e.children).forEach(uy),ly(e),xC(e)}const Yr=new qB.default;Yr.use(aj),Yr.use(uj),Yr.use(dj),Yr.use(hj),Yr.use(fj),Yr.use(mj),Yr.use(gj),Yr.use(MB.gfm);function bj(n,t){const e=hy(n,t);if(!e)return[];const{root:o,...r}=e.blocks;return t.doc.blocks={...t.doc.blocks,...r},o}function hy(n,t){const e=Yr.turndown(n);return sy(e,{htmlToDoc:o=>fy(o,t)})}function fy(n,t){const e=Aj(n,{font:t==null?void 0:t.font,htmlToBlocks:bj});return hy(e)}function my(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function jf(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP","FONT","BR"].indexOf(n.tagName)!==-1}function vj(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function gy(n){return n.replace(/\r\n\s*/g,"").replace(/\n\s*/g,"").replace(/\r\s*/g,"")}function yj(n){if(!n.tagName)return!1;if(n.tagName.toLocaleLowerCase()==="img")return!0;const t=n.querySelectorAll("img");for(let e=0;e<t.length;e+=1){const o=t[e];if(!o.src||o.getAttribute("width")==="0"||o.getAttribute("height")==="0")return!1}return t.length}function kj(n){return(n.tagName.toLocaleLowerCase()==="img"?[n]:Array.from(n.querySelectorAll("img"))).map(r=>({id:K(),type:"embed",embedType:"image",embedData:{src:r.src,width:r.width,height:r.height}}))}function py(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(o=>o.startsWith("level"))!==-1}function wj(n){var e;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let o=0;o<t.length;o++){const r=t[o];if(r.startsWith("mso-list:"))return r}return""}function Cy(n){var e,o;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let r=0;r<t.length;r++){const i=t[r];if(i.startsWith("level")){const s=(o=Number.parseInt(i.substring(5),10))!=null?o:void 0;if(s)return s}}return 1}function Bj(n,t){n.setAttribute("data-group-id",t)}function Ej(n){const t={},e=r=>{Array.from(Object.keys(t)).forEach(i=>{Number.parseInt(i,10)>r&&delete t[i]})};let o="";Array.from(n.children).forEach(r=>{if(py(r)){const i=wj(r);o!==i&&(e(0),o=i);const s=Cy(r);e(s);let l=t[`${s}`];l||(l=K(),t[`${s}`]=l),Bj(r,l)}})}function Ay(n){if(!py(n))return{};const t=Cy(n),e=n.getAttribute("data-group-id")||K();return{start:1,level:t,groupId:e,ordered:!0,type:"list"}}const xj=S("office-list");function by(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function Ij(n,t){g(xj,by(n),"not list group element");let e=!1,o=1;const r=K();n instanceof HTMLOListElement&&(e=!0,o=n.start);const i=n,s=[];let l;return Array.from(i.children).forEach(a=>{if(a instanceof HTMLLIElement){const h=Ay(a),p=t.textElementToBlocks(a,t);l||(l=h.level);const A=p[0];s.push({...A,type:"list",ordered:e,level:l,groupId:r,start:o}),o+=1,s.push(...p.slice(1));return}const d=t.blockElementToBlocks(a,t);s.push(...d)}),s}function vy(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return cy(n,t);if(by(n))return[...Ij(n,t)];if(yj(n))return[...kj(n)];if(vj(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(o=>{const r=vy(o,t);e.push(...r)}),e}function yy(n,t){const e=[];return n.forEach(o=>{var r;if(o instanceof Element)if(jf(o)){const i=document.createElement("p");i.appendChild(o);const s=t.blockElementToBlocks(i,t);e.push(...s)}else{const i=t.blockElementToBlocks(o,t);e.push(...i)}else if(o instanceof Text){const i=sr(gy((r=o.textContent)!=null?r:""));e.push(i)}}),e}function ky(n){const t=Array.from(n.children);for(let e=0;e<t.length;e++){const o=t[e];if(!jf(o))continue;let r=e+1;for(;r<t.length&&jf(t[r]);)r+=1;const i=document.createElement("p");o.insertAdjacentElement("beforebegin",i);for(let s=e;s<r;s++)i.appendChild(t[s]);e=r-1}}function Tj(n,t){const e=zd(n);return ky(e),yy(Array.from(e.childNodes),t)}function Dj(n){if(!(n instanceof HTMLElement))return{};const t={};if(n.style.textAlign==="right"?t.align="right":n.style.textAlign==="center"&&(t.align="center"),n.style.marginLeft){const e=Math.ceil(Number.parseInt(n.style.marginLeft,10)/20);e>=1&&e<=12&&(t.padding=e)}return t}function Sj(n,t){return t&&Object.keys(t).length>0?{insert:n,attributes:t}:{insert:n}}function Lj(n,t){if(n.nodeName==="B")return{...t,"style-bold":!0};if(n.nodeName==="I")return{...t,"style-italic":!0};if(n.nodeName==="U")return{...t,"style-underline":!0};if(n.nodeName==="S"||n.nodeName==="DEL")return{...t,"style-strikethrough":!0};if(n.nodeName==="SUB")return{...t,"style-sub":!0};if(n.nodeName==="SUP")return{...t,"style-super":!0};if(n.nodeName==="BR")return{...t,created:Date.now(),id:K(),box:!0,type:"br"};if(n.nodeName==="A"&&n.href){const o=n.href;if(o.startsWith("http:")||o.startsWith("https:"))return{...t,link:n.href}}const e={...t};return n instanceof HTMLSpanElement?(n.style.backgroundColor&&(e["inline-style-background-color"]=n.style.backgroundColor),n.style.color&&(e["inline-style-color"]=n.style.color),n.style.fontSize&&(e["inline-style-font-size"]=n.style.fontSize),n.style.fontFamily&&(e["inline-style-font-family"]=n.style.fontFamily),e):t}function wy(n,t,e){var r;if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const o=Lj(n,t);if(n instanceof Text&&n.nodeValue||n.nodeName==="BR"){const i=gy((r=n.nodeValue)!=null?r:" ");i&&e.push(Sj(i,o));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(i=>{wy(i,o,e)})}function By(n){return n instanceof Element?jf(n):!0}function h2(n){return!By(n)}function Mj(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=h2(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===h2(i)?e.push(i):(t.push(e),e=[i],o=h2(i))}return t.push(e),t}function Rj(n,t){const e={};if(n.tagName.startsWith("H")){const i=Number.parseInt(n.tagName.substr(1),10);i>=1&&i<=8&&(e.heading=i)}const o=Mj(Array.from(n.childNodes)),r=[];return o.forEach((i,s)=>{if(By(i[0])){const l=[],a={};Array.from(n.childNodes).forEach(h=>{wy(h,a,l)});let d={};s===0&&(d=Ay(n)),r.push({id:K(),type:"text",text:l,...d,...e,...Dj(n)})}i.forEach(l=>{const a=t.blockElementToBlocks(l,t);r.push(...a)})}),r}function Oj(n,t){const e=zd(n);Ej(e),ky(e);const o={blocks:{root:[]},meta:{},comments:{}},r={font:t==null?void 0:t.font,doc:o,blockElementToBlocks:vy,textElementToBlocks:Rj,htmlToBlocks:Tj},i=yy(Array.from(e.children),r);if(i.length!==0)return o.blocks.root=i,o}const _j=S("html-to-doc");function Ey(n,t){if(!n)return null;const e=_H(n);if(e)return e;if(my(n)){const o=Oj(n,t);if(o)return o}try{return fy(n,t)}catch(o){_j.error(o)}return null}class Fj{async fromData(t,e){const o={},r=e.getData("text/html");if(r){const i=Ey(r,{font:t.rootContainer});i&&(my(r)?o["text/office-html"]=i:o["text/html"]=i)}return o}}class Pj{async fromData(t,e){const o=e.getData("text/plain");if(!o)return;const r=sy(o,{font:t.rootContainer,htmlToDoc:Ey});if(!!r)return{"text/markdown":r}}}function Nj(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function $j(n){const t=[],e=n.split(/https|http|ftp/)[0],o=n.substring(e.length).trim();if(e&&e.length){const i=lo(e,null);t.push(i,lo(" ",null))}const r=lo(o,{link:o});return t.push(r,lo(" ",null)),t}class Hj{async fromData(t,e,o){const{toPlainText:r=!1}=o||{},i={},s=e.getData("text/plain");if(s){const d={blocks:{root:s.replace(/\r\n/g,`
|
|
470
470
|
`).replace(/\r/g,`
|
|
471
471
|
`).split(`
|
|
472
|
-
`).map(h=>{const p={id:K(),type:"text"};if(Nj(h)&&!r)return p.text=$j(h),p;const A=h?[lo(h,null)]:[];return p.text=A,p})},meta:{},comments:{}};i["text/plain"]=d}return i}}function jj(n){const t=[];for(let e=0;e<n.length;e++){const o=n[e];o.type.toLocaleLowerCase().startsWith("image/")&&t.push(o)}return t}class f2{constructor(t){t.dataConverter.addConverter(new Fj),t.dataConverter.addConverter(new Hj),t.dataConverter.addConverter(new Pj)}async handleBeforePaste(t,e,o){if(!e)return!1;const r=e.clipboardData;if(r){if(r.getData("text/html").indexOf("<ones-editor-doc")>0)return!1;const s=jj(r.files);if(s.length>0&&!o["text/office-html"])return await this.handleInsertImages(t,s),!0}return!1}async handleInsertImages(t,e){const{start:o,end:r}=t.selection.range,i=t.selection.focusedBlock;let s=nt(i),a=bt(i);const d=ot(s);if(d&&Dt(d)==="code")return;if(o.blockId===r.blockId&&Le(i))a+=1;else{t.clearSelectedContents();const{blockId:p}=t.selection.range.start,A=t.getBlockById(p);a=bt(A),s=nt(A),he(t,A)||(a+=1),Xt(s)&&a===0&&(a+=1)}const h=at(s);for(let p=0;p<e.length;p++){const A=e[p],v=await qm(t,"image",h,a+p,{file:A});v&&u4(t,v,"image",{id:"replace-image",name:"Replace image",data:{block:v,image:A}})}}}class Uj extends be.TypedEmitter{constructor(t){super(),this.editor=t}onUpdateBlockText(t,e,o){const r=this.editor.getCustom("find-dialog");if(!r||!r.isVisible())return;const i=Or(Nr(this.editor,t),e);!tt(this.editor,i)||!o.some(l=>l.insert||l.delete)||this.emit("onDocChanged",i)}onInsertBlock(t,e,o,r){Or(Nr(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,o){const r=Or(Nr(this.editor,t),e);this.emit("onDocDeleted",r)}}function x8(n){return Ke.isSafari&&!!n&&Date.now()-n<100}const I8=S("highlight-data");class Uf{constructor(t){m(this,"data",new Map);this.editor=t}add(t,e,o){const r={id:K(),blockId:it(t),oldText:this.editor.getBlockText(t),start:e,end:o};return this.data.set(r.id,r),r}get(t){const e=this.data.get(t);return g(I8,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new Uf(t))}}function zj(n,t,e,o,r){const s=Uf.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function zf(n,t){const e=t.getAttribute("data-highlight-id");return g(I8,e,"invalid highlight elem, no id"),Uf.getData(n).get(e)}const Ec=S("highligh-dom");function Vj(n){return xt(n,"editor-highlight")}function pr(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function Wj(n,t){g(Ec,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function qj(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function Vf(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function Gj(n){Vf(n).forEach(t=>{t.remove()})}function Jr(n){return pr(n).length}function Zj(n,t){g(Ec,t>=0,`invalid highlight index: ${t}`);const e=pr(n);return e.length===0?null:(g(Ec,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function Qj(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const a=w("div",l,n);a.style.top=`${o}px`,a.style.left=`${e}px`,a.style.width=`${r}px`,a.style.height=`${i}px`}function T8(n,t,e,o,r){g(Ec,o>0,`invalid end: ${o}`);const i=le(t),s=t.getBoundingClientRect(),l=Ti(n,t,ye(n,t,e,o)),d=w("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(h=>{Qj(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),zj(n,t,e,o,d)}function Yj(n,t,e,o){return T8(n,t,e,o,"find")}function D8(n,t,e,o){return T8(n,t,e,o,"replace")}function Wf(n,t){pr(n).forEach(s=>{xt(s,"active")&&et(s,"active")}),W(t,"active"),g(Ec,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const o=t.firstChild;let i=o.getBoundingClientRect().y;i===0&&(i=o.getBoundingClientRect().y),km(o,{elementToScroll:n.scrollContainer})}function Mu(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function S8(n){return g(Ec,n,"no highlight elem"),xt(n,"editor-highlight-readonly")}const xc=S("highligh-text");function L8(n){qj(n).forEach(e=>{e.remove()})}function qf(n,t){pr(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||L8(n)}function M8(n,t,e){Wj(n,t).forEach(r=>{r.remove()}),e!=null&&e.keepReplaceResult||L8(n)}function Ru(n){const t=Mu(n);if(!t)return-1;const o=pr(n).indexOf(t);return g(xc,o!==-1,`invalid highlight index: ${o}`),o}function Jj(n){const t=pr(n);if(t.length===0)return 0;const e=Mu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return Wf(n,r),o}function Kj(n){const t=pr(n);if(t.length===0)return 0;const e=Mu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return Wf(n,r),o}function m2(n,t){const e=pr(n);e.length>0&&t<e.length&&Wf(n,e[t])}function Xj(n,t,e){const o=Mu(n);if(!o)return!1;const r=ot(o);if(g(xc,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=Jr(n);let s=Ru(n);if(!S8(o)&&n.isBlockWritable(r)){const d=zf(n,o),h=n.getBlockText(r),{start:p,end:A}=zf(n,o),[v,B]=ln.transformOffset(d.oldText,h,[p,A]),D=P4(h,v,B-v);if(re(D).toLowerCase()!==t.toLowerCase())return!1;const T=dh(h,v,B,e);n.setBlockText(r,T),Gj(r),g2(n,r,t),e&&D8(n,r,v,v+e.length)}const l=Jr(n);s>=l?s=0:l>i&&(s+=1);const a=Zj(n,s);return a&&Wf(n,a),!0}function tU(n,t,e,o){if(!tt(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);g(xc,r,"no block text");const i={count:0},s=l6(r,e,o,i);return re(r)===re(s)?0:(n.setBlockText(t,s),i.count)}function eU(n,t,e){if(g(xc,Vj(t),"not a highlight elem"),S8(t))return;g(xc,e>0,"invalid highlight length");const o=zf(n,t),r=ot(t);g(xc,r,"no parent block"),D8(n,r,o.start,o.start+e)}function nU(n,t){pr(n).forEach(o=>{eU(n,o,t)})}function oU(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return ve(i).forEach(a=>{Lt(n,a)?En(n,a).forEach(h=>{s+=o(h)}):s+=tU(n,a,t,e)}),s},r=o(n.rootContainer);return e.length>0&&nU(n,e.length),r}function rU(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=Vf(e);for(let l=0;l<r.length;l++){const a=r[l],{end:d}=zf(n,a);if(d>=o)return a}const i=og(n,{simpleBlockOnly:!0}),s=i.indexOf(e);if(s===-1)return null;for(let l=s+1;l<i.length;l++){const a=i[l],d=Vf(a);if(d.length>0)return d[0]}return null}function iU(n){const t=pr(n),e=rU(n);return e?t.indexOf(e):0}function g2(n,t,e){if(!!e&&tt(n,t)){const o=n.getBlockText(t),r=Cg(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{Yj(n,t,i,s)})}}function R8(n,t){if(qf(n),!t)return;og(n,{simpleBlockOnly:!0}).forEach(o=>{g2(n,o,t)})}class sU{constructor(t){m(this,"dialog",null);m(this,"root");m(this,"oldText","");m(this,"_compositionEndTime",0);m(this,"components");m(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});m(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});m(this,"handleDocChanged",t=>{setTimeout(()=>{M8(this.editor,t),g2(this.editor,t,this.components.findInput.value);const e=Jr(this.editor);t.querySelectorAll(".editor-highlight").length===e&&m2(this.editor,0);const o=Ru(this.editor);this.updateSearchStatus(o,e)})});m(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),qf(this.editor,{keepReplaceResult:!0}),R8(this.editor,this.components.findInput.value);const e=Jr(this.editor),o=Ru(this.editor);this.updateSearchStatus(o,e),m2(this.editor,o)})});m(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!Vf(t).length){clearTimeout(e);return}M8(this.editor,t);const r=Jr(this.editor),i=Ru(this.editor);this.updateSearchStatus(i,r)})});m(this,"handleInput",t=>{if(t.isComposing||x8(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});m(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});m(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!Mu(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(Xj(this.editor,t,o)){const i=Ru(this.editor),s=Jr(this.editor);this.updateSearchStatus(i,s)}this.findNext({keepSearchResult:!0})});m(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;if(t===e)return;oU(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))});m(this,"doSearch",He.default(this.doSearchNow,300));this.editor=t;const e=w("div",["editor-find-dialog"],null),o=w("div",["editor-find-content"],e),r=w("div",["editor-find-dialog-row"],o),i=Hl(sv,["editor-find-dialog-button-close"],e),s=w("label",["editor-find-dialog-label"],r,R.t("find.findLabel"));s.htmlFor="";const l=w("div",["editor-find-dialog-input-container"],r),a=w("input",["editor-find-dialog-input"],l);a.type="text",a.placeholder=R.t("find.findPlaceholder");const d=w("div",["editor-find-dialog-status"],l),h=Hl(fL,["editor-find-dialog-icon-button"],d),p=w("div",["editor-find-dialog-curr"],d,"0/0"),A=Hl(mL,["editor-find-dialog-icon-button"],d);let v;R.t("find.moreButton")?v=w("button",["editor-find-dialog-button"],r,R.t("find.moreButton")):v=Hl(lv,["editor-find-dialog-icon-button-border"],r);const B=w("div",["editor-find-dialog-row"],o),D=w("label",["editor-find-dialog-label"],B,R.t("find.replaceLabel"));D.htmlFor="";const T=w("div",["editor-find-dialog-input-container"],B),_=w("input",["editor-find-dialog-input"],T);_.type="text",_.placeholder=R.t("find.replacePlaceholder");const M=w("div",["editor-find-dialog-row"],o);w("div",["editor-find-dialog-space"],M);const H=w("button",["editor-find-dialog-button"],M,R.t("find.findButton")),z=w("button",["editor-find-dialog-button"],M,R.t("find.replaceButton")),q=w("button",["editor-find-dialog-button"],M,R.t("find.replaceAllButton"));v.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},a.onkeydown=ft=>{if(ft.isComposing||x8(this._compositionEndTime)){this.doSearch.cancel();return}vC(ft)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):Im(ft)&&this.hide()},a.oninput=this.handleInput,a.onpaste=this.handleFindChanged,a.oncut=this.handleFindChanged,a.addEventListener("compositionend",this.handleCompositionEnd),a.maxLength=50,H.onclick=this.handleFind,z.onclick=this.handleReplace,q.onclick=this.handleReplaceAll,_.maxLength=50,A.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:a,findPrev:h,findCurrent:p,findNext:A,replaceInput:_,findButton:H,replaceButton:z,replaceAllButton:q,closeButton:i,showReplaceButton:v,rowReplace:B,rowActions:M,statusContainer:d},this.root=e;const rt=new Uj(t);t.doc.registerCallback(rt),rt.addListener("onDocChanged",this.handleDocChanged),rt.addListener("onDocInserted",this.handleDocInserted),rt.addListener("onDocDeleted",this.handleDocDeleted)}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,R8(this.editor,e);const o=Jr(this.editor),r=iU(this.editor);t.gotoFirstSearchResult&&m2(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=Jr(this.editor),e=Jj(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=Jr(this.editor),e=Kj(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0/0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1}/${e}`;const o=this.editor.readonly;this.components.replaceAllButton.disabled=o,this.components.replaceButton.disabled=o,this.components.findButton.disabled=!1}}clearFind(t){qf(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const o=this.editor.readonly;this.components.replaceButton.disabled=o,this.components.replaceAllButton.disabled=o,this.components.replaceInput.disabled=o,this.dialog||(this.dialog=new ru(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var p,A,v,B;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((A=(p=this.dialog)==null?void 0:p.tippyInstance)==null?void 0:A.popper))return l(i,(B=(v=this.dialog)==null?void 0:v.tippyInstance)==null?void 0:B.popper);const a=i.getBoundingClientRect(),d=a.top<0?12:a.top+12,h=a.right-this.root.clientWidth-12;return new DOMRect(h,d,0,0)};this.dialog.show(i,{getReferenceClientRect:s}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close("cancelBar"),qf(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const lU={find:{findLabel:"\u67E5\u627E:",replaceLabel:"\u66FF\u6362:",findButton:"\u67E5\u627E",replaceButton:"\u66FF\u6362",replaceAllButton:"\u5168\u90E8\u66FF\u6362",moreButton:"",findPlaceholder:"\u5728\u6587\u6863\u5185\u67E5\u627E",replacePlaceholder:"\u66FF\u6362\u4E3A"}},cU={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},aU={find:{findLabel:"\u691C\u7D22\uFF1A",replaceLabel:"\u7F6E\u63DB\uFF1A",findButton:"\u691C\u7D22",replaceButton:"\u7F6E\u63DB",replaceAllButton:"\u3059\u3079\u3066\u3092\u7F6E\u63DB",moreButton:"",findPlaceholder:"\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u691C\u7D22",replacePlaceholder:"\u306B\u7F6E\u63DB"}};R.mergeLang({"zh-CN":lU,"en-US":cU,"ja-JP":aU});function O8(n){return n.addCustom("find-dialog",()=>new sU(n)).show(),!0}const _8={"CtrlOrCmd+F":O8},Nnt="";function uU(n){O8(n)}function p2(n,t){return t.map(e=>{var i,s;const o=Qt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return Le(e)||Lt(n,e)?r!=null&&r.abstract?`[${r.abstract}]`:"":(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function Gf(n){const{editor:t,commentGroupId:e,abstract:o="text"}=n,r=K(),i=t.doc.getUser(),s=Date.now(),l=e!=null?e:r;return{id:r,groupId:l,userId:i.userId,displayName:i.displayName,avatarUrl:i.avatarUrl,abstract:o,created:s,modified:s}}function F8(n,t,e){const o=e.id,i=n.getBlockData(t).comments;let s;i?s=[...i,o]:s=[o];const l={comments:s};n.updateBlockData(t,l)}function C2(n,t,e){const o=p2(n,[t]),r=Gf({editor:n,abstract:o});F8(n,t,r);const i=jr();return e.localCreateComment(r,i),r}const dU=S("standard-block-actions");class hU{constructor(t,e){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);C2(t,i,this.provider)}catch(i){dU.error(`failed to execute block command: ${JSON.stringify(i)}`)}});this.provider=t,this.editorComments=e}commands(t,e){const o=it(e);return{group:"block-comment-actions",commands:[{id:"comment",name:R.t("comment.quickMenuCommand"),data:o,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class fU{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.comments,r.text&&r.text.forEach(i=>{if(i.attributes){const s=i.attributes;Object.keys(s).forEach(l=>{l.startsWith("comment-")&&delete s[l]})}})})}),!1}}var Yt=(n=>(n.SwitchUp="switch-up",n.SwitchDown="switch-down",n.CommentItemReply="comment-item-reply",n.CommentItemMore="comment-item-more",n.CommentItemOk="comment-item-ok",n.CommentItemCancel="comment-item-cancel",n.CommentItemDelete="comment-item-delete",n.CommentItemEdit="comment-item-edit",n.QuickReply="quick-reply",n.QuickReplyOk="quick-reply-ok",n.QuickReplyCancel="quick-reply-cancel",n))(Yt||{});const A2="group-item-action",P8="last-comment-item",Kr="disabled",N8=500;function Js(n){return n.id!==n.groupId}function $8(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function mU(n){const t=n.closest(".comment-item-root");return t?t.id:null}function Xr(n,t){n.setAttribute(A2,t)}function gU(n){return n.closest(`[${A2}]`)}function pU(n){var t;return(t=n.getAttribute(A2))!=null?t:""}function CU(n){return xt(n,Kr)}function H8(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return null;const o=e.closest('[data-type="editor-block"]');return o?o.id:null}function j8(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const U8=S("doc-comments");function z8(n,t,e,o){if(t.comments){const i=t.comments;Array.isArray(i)&&i.forEach(s=>{o.has(s)||(o.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([a,d])=>{if(a.startsWith(l)){const h=d;o.has(h)||(o.add(h),e.push(h))}})}});const r=t.children;!r||r.forEach(i=>{n.blocks[i].forEach(l=>{z8(n,l,e,o)})})}function AU(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{z8(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function bU(n){const t=new Map;n.forEach(r=>{if(Js(r)){const i=t.get(r.groupId);i?i.push(r):t.set(r.groupId,[r])}});const e=[];return n.forEach(r=>{var i;if(!Js(r)){const s=(i=t.get(r.id))!=null?i:[];t.delete(r.id);const l={...r,children:s};e.push(l)}}),Array.from(t.values()).forEach(r=>{const i=r[0],s=r.slice(1),l={...i,children:s};e.push(l)}),e}function ts(n,t){const e=n.doc.toJSON(),o=AU(e);return bU(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const a=o.get(s.groupId),d=o.get(l.groupId);return g(U8,a!==void 0,`comment not exists in doc, ${s.groupId}`),g(U8,d!==void 0,`comment not exists in doc, ${l.groupId}`),a-d})}function b2(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function vU(n,t){return ts(n,t).map(b2).reduce((r,i)=>i.length+r,0)}function v2(n,t){const e=[],o=n.getBlockById(t.blockId);if(tt(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),a=n.getBlockText(l),d=Ta(a,s);d&&Object.entries(d).forEach(([h,p])=>{h.startsWith("comment-")&&e.push(p)})}const r=o.attributes;for(let i=0;i<r.length;i++){const s=r[i];s.name.startsWith("comment-")&&e.push(s.value)}return e}function V8(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return v2(n,t.start);const{start:e,end:o}=t,r=v2(n,e),i=v2(n,o);return fm.default(r,i)}const yU=S("active-comments");function W8(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{et(o,"active")})}function q8(n,t){const e=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)e&&j8(e).forEach(r=>W8(n,r));else{const o=t.toLocaleLowerCase();if(e){const i=j8(e);if(i.length===1&&i[0]===o)return;i.forEach(s=>W8(n,s))}const r=n.rootContainer.querySelectorAll(`span.text.comment[comment-${o}],[data-type=editor-block].comment[comment-${o}]`);if(r){r.forEach(s=>{W(s,"active")});const i=r[0];if(xs(i))n.selection.selectBlock(i,0);else if(V8(n).indexOf(t)===-1){const l=ot(i);g(yU,l,"block not found");const a=Mi(l,i);n.selection.selectBlock(l,a.start)}n.focus()}}}const $nt="";S("comment-editor");const{t:kU}=R,y2="comment-editor-readonly",Ou="comment-editor-editing";class k2{constructor(t,e,o){m(this,"root");m(this,"components");m(this,"handleEditorBlur",()=>{this.inactiveEditor()});m(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});m(this,"activeEditor",()=>{xt(this.root,Ou)||W(this.root,Ou)});m(this,"inactiveEditor",()=>{et(this.root,Ou)});m(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=at(t.rootContainer),o=await zl("image/*",{}),r={src:"",widthPercent:50},i={id:K(),type:"embed",embedType:"image",embedData:r},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(i.align=s.defaultAlign);const l=t.getFocusedBlock(),a=t.getBlockIndex(l),d=t.insertBlock(e,a+1,i);xe.getImageObject(t,d).replaceImage(0,o)});m(this,"handleReadonlyChange",t=>{t.readonly?(et(this.root,Ou),W(this.root,y2)):(W(this.root,Ou),et(this.root,y2))});m(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});m(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});m(this,"isEmpty",()=>Ag(this.getDoc()));m(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,PA(t),this.activeEditor()});m(this,"clear",()=>{const t=jr();this.setDoc(t)});m(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});m(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:o}}=this;o.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=o,this.root=w("div",["comment-editor",y2],null),this.components=this.createEditor()}createEditor(){const t=w("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new np(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=Qs(this.root,"comment-editor-img",kU("comment.image"),BL,void 0,o.clientId);return i.classList.add("comment-editor-img"),i.onclick=this.handleInsertImg,{editor:r,insertImgButton:i}}get editor(){return this.components.editor}}class wU{constructor(t){m(this,"handleBeforeKeyDown",(t,e)=>{if(Rr(e,"Enter")){const{quickReply:o,updateLastCommentItem:r}=this.groupItem;return o.getReplyEditor().isEmpty()?(o.hideReplyEditor(),!0):(o.reply(),r(),!0)}return!1});this.groupItem=t}}class BU{constructor(t,e,o){m(this,"handleBeforeKeyDown",(t,e)=>{if(Rr(e,"Enter")){const{quickReply:o}=this.groupItem,{comment:r,getCommentEditor:i}=this.commentItem,s=i();if(s.isEmpty())this.commentsProvider.localDeleteComment(r.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(r,l),s.readonly()}return o.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=o}}const EU=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
472
|
+
`).map(h=>{const p={id:K(),type:"text"};if(Nj(h)&&!r)return p.text=$j(h),p;const A=h?[lo(h,null)]:[];return p.text=A,p})},meta:{},comments:{}};i["text/plain"]=d}return i}}function jj(n){const t=[];for(let e=0;e<n.length;e++){const o=n[e];o.type.toLocaleLowerCase().startsWith("image/")&&t.push(o)}return t}class f2{constructor(t){t.dataConverter.addConverter(new Fj),t.dataConverter.addConverter(new Hj),t.dataConverter.addConverter(new Pj)}async handleBeforePaste(t,e,o){if(!e)return!1;const r=e.clipboardData;if(r){if(r.getData("text/html").indexOf("<ones-editor-doc")>0)return!1;const s=jj(r.files);if(s.length>0&&!o["text/office-html"])return await this.handleInsertImages(t,s),!0}return!1}async handleInsertImages(t,e){const{start:o,end:r}=t.selection.range,i=t.selection.focusedBlock;let s=nt(i),a=bt(i);const d=ot(s);if(d&&Dt(d)==="code")return;if(o.blockId===r.blockId&&Le(i))a+=1;else{t.clearSelectedContents();const{blockId:p}=t.selection.range.start,A=t.getBlockById(p);a=bt(A),s=nt(A),he(t,A)||(a+=1),Xt(s)&&a===0&&(a+=1)}const h=at(s);for(let p=0;p<e.length;p++){const A=e[p],v=await qm(t,"image",h,a+p,{file:A});v&&u4(t,v,"image",{id:"replace-image",name:"Replace image",data:{block:v,image:A}})}}}class Uj extends be.TypedEmitter{constructor(t){super(),this.editor=t}onUpdateBlockText(t,e,o){const r=this.editor.getCustom("find-dialog");if(!r||!r.isVisible())return;const i=Or(Nr(this.editor,t),e);!tt(this.editor,i)||!o.some(l=>l.insert||l.delete)||this.emit("onDocChanged",i)}onInsertBlock(t,e,o,r){Or(Nr(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,o){const r=Or(Nr(this.editor,t),e);this.emit("onDocDeleted",r)}}function xy(n){return Ke.isSafari&&!!n&&Date.now()-n<100}const Iy=S("highlight-data");class Uf{constructor(t){m(this,"data",new Map);this.editor=t}add(t,e,o){const r={id:K(),blockId:it(t),oldText:this.editor.getBlockText(t),start:e,end:o};return this.data.set(r.id,r),r}get(t){const e=this.data.get(t);return g(Iy,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new Uf(t))}}function zj(n,t,e,o,r){const s=Uf.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function zf(n,t){const e=t.getAttribute("data-highlight-id");return g(Iy,e,"invalid highlight elem, no id"),Uf.getData(n).get(e)}const Ec=S("highligh-dom");function Vj(n){return xt(n,"editor-highlight")}function pr(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function Wj(n,t){g(Ec,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function qj(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function Vf(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function Gj(n){Vf(n).forEach(t=>{t.remove()})}function Jr(n){return pr(n).length}function Zj(n,t){g(Ec,t>=0,`invalid highlight index: ${t}`);const e=pr(n);return e.length===0?null:(g(Ec,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function Qj(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const a=w("div",l,n);a.style.top=`${o}px`,a.style.left=`${e}px`,a.style.width=`${r}px`,a.style.height=`${i}px`}function Ty(n,t,e,o,r){g(Ec,o>0,`invalid end: ${o}`);const i=le(t),s=t.getBoundingClientRect(),l=Ti(n,t,ye(n,t,e,o)),d=w("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(h=>{Qj(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),zj(n,t,e,o,d)}function Yj(n,t,e,o){return Ty(n,t,e,o,"find")}function Dy(n,t,e,o){return Ty(n,t,e,o,"replace")}function Wf(n,t){pr(n).forEach(s=>{xt(s,"active")&&et(s,"active")}),W(t,"active"),g(Ec,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const o=t.firstChild;let i=o.getBoundingClientRect().y;i===0&&(i=o.getBoundingClientRect().y),km(o,{elementToScroll:n.scrollContainer})}function Mu(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function Sy(n){return g(Ec,n,"no highlight elem"),xt(n,"editor-highlight-readonly")}const xc=S("highligh-text");function Ly(n){qj(n).forEach(e=>{e.remove()})}function qf(n,t){pr(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||Ly(n)}function My(n,t,e){Wj(n,t).forEach(r=>{r.remove()}),e!=null&&e.keepReplaceResult||Ly(n)}function Ru(n){const t=Mu(n);if(!t)return-1;const o=pr(n).indexOf(t);return g(xc,o!==-1,`invalid highlight index: ${o}`),o}function Jj(n){const t=pr(n);if(t.length===0)return 0;const e=Mu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return Wf(n,r),o}function Kj(n){const t=pr(n);if(t.length===0)return 0;const e=Mu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return Wf(n,r),o}function m2(n,t){const e=pr(n);e.length>0&&t<e.length&&Wf(n,e[t])}function Xj(n,t,e){const o=Mu(n);if(!o)return!1;const r=ot(o);if(g(xc,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=Jr(n);let s=Ru(n);if(!Sy(o)&&n.isBlockWritable(r)){const d=zf(n,o),h=n.getBlockText(r),{start:p,end:A}=zf(n,o),[v,B]=ln.transformOffset(d.oldText,h,[p,A]),D=P4(h,v,B-v);if(re(D).toLowerCase()!==t.toLowerCase())return!1;const T=dh(h,v,B,e);n.setBlockText(r,T),Gj(r),g2(n,r,t),e&&Dy(n,r,v,v+e.length)}const l=Jr(n);s>=l?s=0:l>i&&(s+=1);const a=Zj(n,s);return a&&Wf(n,a),!0}function tU(n,t,e,o){if(!tt(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);g(xc,r,"no block text");const i={count:0},s=l6(r,e,o,i);return re(r)===re(s)?0:(n.setBlockText(t,s),i.count)}function eU(n,t,e){if(g(xc,Vj(t),"not a highlight elem"),Sy(t))return;g(xc,e>0,"invalid highlight length");const o=zf(n,t),r=ot(t);g(xc,r,"no parent block"),Dy(n,r,o.start,o.start+e)}function nU(n,t){pr(n).forEach(o=>{eU(n,o,t)})}function oU(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return ve(i).forEach(a=>{Lt(n,a)?En(n,a).forEach(h=>{s+=o(h)}):s+=tU(n,a,t,e)}),s},r=o(n.rootContainer);return e.length>0&&nU(n,e.length),r}function rU(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=Vf(e);for(let l=0;l<r.length;l++){const a=r[l],{end:d}=zf(n,a);if(d>=o)return a}const i=og(n,{simpleBlockOnly:!0}),s=i.indexOf(e);if(s===-1)return null;for(let l=s+1;l<i.length;l++){const a=i[l],d=Vf(a);if(d.length>0)return d[0]}return null}function iU(n){const t=pr(n),e=rU(n);return e?t.indexOf(e):0}function g2(n,t,e){if(!!e&&tt(n,t)){const o=n.getBlockText(t),r=Cg(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{Yj(n,t,i,s)})}}function Ry(n,t){if(qf(n),!t)return;og(n,{simpleBlockOnly:!0}).forEach(o=>{g2(n,o,t)})}class sU{constructor(t){m(this,"dialog",null);m(this,"root");m(this,"oldText","");m(this,"_compositionEndTime",0);m(this,"components");m(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});m(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});m(this,"handleDocChanged",t=>{setTimeout(()=>{My(this.editor,t),g2(this.editor,t,this.components.findInput.value);const e=Jr(this.editor);t.querySelectorAll(".editor-highlight").length===e&&m2(this.editor,0);const o=Ru(this.editor);this.updateSearchStatus(o,e)})});m(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),qf(this.editor,{keepReplaceResult:!0}),Ry(this.editor,this.components.findInput.value);const e=Jr(this.editor),o=Ru(this.editor);this.updateSearchStatus(o,e),m2(this.editor,o)})});m(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!Vf(t).length){clearTimeout(e);return}My(this.editor,t);const r=Jr(this.editor),i=Ru(this.editor);this.updateSearchStatus(i,r)})});m(this,"handleInput",t=>{if(t.isComposing||xy(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});m(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});m(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!Mu(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(Xj(this.editor,t,o)){const i=Ru(this.editor),s=Jr(this.editor);this.updateSearchStatus(i,s)}this.findNext({keepSearchResult:!0})});m(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;if(t===e)return;oU(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))});m(this,"doSearch",He.default(this.doSearchNow,300));this.editor=t;const e=w("div",["editor-find-dialog"],null),o=w("div",["editor-find-content"],e),r=w("div",["editor-find-dialog-row"],o),i=Hl(sv,["editor-find-dialog-button-close"],e),s=w("label",["editor-find-dialog-label"],r,R.t("find.findLabel"));s.htmlFor="";const l=w("div",["editor-find-dialog-input-container"],r),a=w("input",["editor-find-dialog-input"],l);a.type="text",a.placeholder=R.t("find.findPlaceholder");const d=w("div",["editor-find-dialog-status"],l),h=Hl(fL,["editor-find-dialog-icon-button"],d),p=w("div",["editor-find-dialog-curr"],d,"0/0"),A=Hl(mL,["editor-find-dialog-icon-button"],d);let v;R.t("find.moreButton")?v=w("button",["editor-find-dialog-button"],r,R.t("find.moreButton")):v=Hl(lv,["editor-find-dialog-icon-button-border"],r);const B=w("div",["editor-find-dialog-row"],o),D=w("label",["editor-find-dialog-label"],B,R.t("find.replaceLabel"));D.htmlFor="";const T=w("div",["editor-find-dialog-input-container"],B),_=w("input",["editor-find-dialog-input"],T);_.type="text",_.placeholder=R.t("find.replacePlaceholder");const M=w("div",["editor-find-dialog-row"],o);w("div",["editor-find-dialog-space"],M);const H=w("button",["editor-find-dialog-button"],M,R.t("find.findButton")),z=w("button",["editor-find-dialog-button"],M,R.t("find.replaceButton")),q=w("button",["editor-find-dialog-button"],M,R.t("find.replaceAllButton"));v.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},a.onkeydown=ft=>{if(ft.isComposing||xy(this._compositionEndTime)){this.doSearch.cancel();return}vC(ft)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):Im(ft)&&this.hide()},a.oninput=this.handleInput,a.onpaste=this.handleFindChanged,a.oncut=this.handleFindChanged,a.addEventListener("compositionend",this.handleCompositionEnd),a.maxLength=50,H.onclick=this.handleFind,z.onclick=this.handleReplace,q.onclick=this.handleReplaceAll,_.maxLength=50,A.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:a,findPrev:h,findCurrent:p,findNext:A,replaceInput:_,findButton:H,replaceButton:z,replaceAllButton:q,closeButton:i,showReplaceButton:v,rowReplace:B,rowActions:M,statusContainer:d},this.root=e;const rt=new Uj(t);t.doc.registerCallback(rt),rt.addListener("onDocChanged",this.handleDocChanged),rt.addListener("onDocInserted",this.handleDocInserted),rt.addListener("onDocDeleted",this.handleDocDeleted)}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,Ry(this.editor,e);const o=Jr(this.editor),r=iU(this.editor);t.gotoFirstSearchResult&&m2(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=Jr(this.editor),e=Jj(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=Jr(this.editor),e=Kj(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0/0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1}/${e}`;const o=this.editor.readonly;this.components.replaceAllButton.disabled=o,this.components.replaceButton.disabled=o,this.components.findButton.disabled=!1}}clearFind(t){qf(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const o=this.editor.readonly;this.components.replaceButton.disabled=o,this.components.replaceAllButton.disabled=o,this.components.replaceInput.disabled=o,this.dialog||(this.dialog=new ru(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var p,A,v,B;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((A=(p=this.dialog)==null?void 0:p.tippyInstance)==null?void 0:A.popper))return l(i,(B=(v=this.dialog)==null?void 0:v.tippyInstance)==null?void 0:B.popper);const a=i.getBoundingClientRect(),d=a.top<0?12:a.top+12,h=a.right-this.root.clientWidth-12;return new DOMRect(h,d,0,0)};this.dialog.show(i,{getReferenceClientRect:s}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close("cancelBar"),qf(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const lU={find:{findLabel:"\u67E5\u627E:",replaceLabel:"\u66FF\u6362:",findButton:"\u67E5\u627E",replaceButton:"\u66FF\u6362",replaceAllButton:"\u5168\u90E8\u66FF\u6362",moreButton:"",findPlaceholder:"\u5728\u6587\u6863\u5185\u67E5\u627E",replacePlaceholder:"\u66FF\u6362\u4E3A"}},cU={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},aU={find:{findLabel:"\u691C\u7D22\uFF1A",replaceLabel:"\u7F6E\u63DB\uFF1A",findButton:"\u691C\u7D22",replaceButton:"\u7F6E\u63DB",replaceAllButton:"\u3059\u3079\u3066\u3092\u7F6E\u63DB",moreButton:"",findPlaceholder:"\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u691C\u7D22",replacePlaceholder:"\u306B\u7F6E\u63DB"}};R.mergeLang({"zh-CN":lU,"en-US":cU,"ja-JP":aU});function Oy(n){return n.addCustom("find-dialog",()=>new sU(n)).show(),!0}const _y={"CtrlOrCmd+F":Oy},Nnt="";function uU(n){Oy(n)}function p2(n,t){return t.map(e=>{var i,s;const o=Qt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return Le(e)||Lt(n,e)?r!=null&&r.abstract?`[${r.abstract}]`:"":(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function Gf(n){const{editor:t,commentGroupId:e,abstract:o="text"}=n,r=K(),i=t.doc.getUser(),s=Date.now(),l=e!=null?e:r;return{id:r,groupId:l,userId:i.userId,displayName:i.displayName,avatarUrl:i.avatarUrl,abstract:o,created:s,modified:s}}function Fy(n,t,e){const o=e.id,i=n.getBlockData(t).comments;let s;i?s=[...i,o]:s=[o];const l={comments:s};n.updateBlockData(t,l)}function C2(n,t,e){const o=p2(n,[t]),r=Gf({editor:n,abstract:o});Fy(n,t,r);const i=jr();return e.localCreateComment(r,i),r}const dU=S("standard-block-actions");class hU{constructor(t,e){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);C2(t,i,this.provider)}catch(i){dU.error(`failed to execute block command: ${JSON.stringify(i)}`)}});this.provider=t,this.editorComments=e}commands(t,e){const o=it(e);return{group:"block-comment-actions",commands:[{id:"comment",name:R.t("comment.quickMenuCommand"),data:o,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class fU{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.comments,r.text&&r.text.forEach(i=>{if(i.attributes){const s=i.attributes;Object.keys(s).forEach(l=>{l.startsWith("comment-")&&delete s[l]})}})})}),!1}}var Yt=(n=>(n.SwitchUp="switch-up",n.SwitchDown="switch-down",n.CommentItemReply="comment-item-reply",n.CommentItemMore="comment-item-more",n.CommentItemOk="comment-item-ok",n.CommentItemCancel="comment-item-cancel",n.CommentItemDelete="comment-item-delete",n.CommentItemEdit="comment-item-edit",n.QuickReply="quick-reply",n.QuickReplyOk="quick-reply-ok",n.QuickReplyCancel="quick-reply-cancel",n))(Yt||{});const A2="group-item-action",Py="last-comment-item",Kr="disabled",Ny=500;function Js(n){return n.id!==n.groupId}function $y(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function mU(n){const t=n.closest(".comment-item-root");return t?t.id:null}function Xr(n,t){n.setAttribute(A2,t)}function gU(n){return n.closest(`[${A2}]`)}function pU(n){var t;return(t=n.getAttribute(A2))!=null?t:""}function CU(n){return xt(n,Kr)}function Hy(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return null;const o=e.closest('[data-type="editor-block"]');return o?o.id:null}function jy(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const Uy=S("doc-comments");function zy(n,t,e,o){if(t.comments){const i=t.comments;Array.isArray(i)&&i.forEach(s=>{o.has(s)||(o.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([a,d])=>{if(a.startsWith(l)){const h=d;o.has(h)||(o.add(h),e.push(h))}})}});const r=t.children;!r||r.forEach(i=>{n.blocks[i].forEach(l=>{zy(n,l,e,o)})})}function AU(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{zy(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function bU(n){const t=new Map;n.forEach(r=>{if(Js(r)){const i=t.get(r.groupId);i?i.push(r):t.set(r.groupId,[r])}});const e=[];return n.forEach(r=>{var i;if(!Js(r)){const s=(i=t.get(r.id))!=null?i:[];t.delete(r.id);const l={...r,children:s};e.push(l)}}),Array.from(t.values()).forEach(r=>{const i=r[0],s=r.slice(1),l={...i,children:s};e.push(l)}),e}function ts(n,t){const e=n.doc.toJSON(),o=AU(e);return bU(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const a=o.get(s.groupId),d=o.get(l.groupId);return g(Uy,a!==void 0,`comment not exists in doc, ${s.groupId}`),g(Uy,d!==void 0,`comment not exists in doc, ${l.groupId}`),a-d})}function b2(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function vU(n,t){return ts(n,t).map(b2).reduce((r,i)=>i.length+r,0)}function v2(n,t){const e=[],o=n.getBlockById(t.blockId);if(tt(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),a=n.getBlockText(l),d=Ta(a,s);d&&Object.entries(d).forEach(([h,p])=>{h.startsWith("comment-")&&e.push(p)})}const r=o.attributes;for(let i=0;i<r.length;i++){const s=r[i];s.name.startsWith("comment-")&&e.push(s.value)}return e}function Vy(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return v2(n,t.start);const{start:e,end:o}=t,r=v2(n,e),i=v2(n,o);return fm.default(r,i)}const yU=S("active-comments");function Wy(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{et(o,"active")})}function qy(n,t){const e=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)e&&jy(e).forEach(r=>Wy(n,r));else{const o=t.toLocaleLowerCase();if(e){const i=jy(e);if(i.length===1&&i[0]===o)return;i.forEach(s=>Wy(n,s))}const r=n.rootContainer.querySelectorAll(`span.text.comment[comment-${o}],[data-type=editor-block].comment[comment-${o}]`);if(r){r.forEach(s=>{W(s,"active")});const i=r[0];if(xs(i))n.selection.selectBlock(i,0);else if(Vy(n).indexOf(t)===-1){const l=ot(i);g(yU,l,"block not found");const a=Mi(l,i);n.selection.selectBlock(l,a.start)}n.focus()}}}const $nt="";S("comment-editor");const{t:kU}=R,y2="comment-editor-readonly",Ou="comment-editor-editing";class k2{constructor(t,e,o){m(this,"root");m(this,"components");m(this,"handleEditorBlur",()=>{this.inactiveEditor()});m(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});m(this,"activeEditor",()=>{xt(this.root,Ou)||W(this.root,Ou)});m(this,"inactiveEditor",()=>{et(this.root,Ou)});m(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=at(t.rootContainer),o=await zl("image/*",{}),r={src:"",widthPercent:50},i={id:K(),type:"embed",embedType:"image",embedData:r},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(i.align=s.defaultAlign);const l=t.getFocusedBlock(),a=t.getBlockIndex(l),d=t.insertBlock(e,a+1,i);xe.getImageObject(t,d).replaceImage(0,o)});m(this,"handleReadonlyChange",t=>{t.readonly?(et(this.root,Ou),W(this.root,y2)):(W(this.root,Ou),et(this.root,y2))});m(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});m(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});m(this,"isEmpty",()=>Ag(this.getDoc()));m(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,PA(t),this.activeEditor()});m(this,"clear",()=>{const t=jr();this.setDoc(t)});m(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});m(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:o}}=this;o.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=o,this.root=w("div",["comment-editor",y2],null),this.components=this.createEditor()}createEditor(){const t=w("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new np(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=Qs(this.root,"comment-editor-img",kU("comment.image"),BL,void 0,o.clientId);return i.classList.add("comment-editor-img"),i.onclick=this.handleInsertImg,{editor:r,insertImgButton:i}}get editor(){return this.components.editor}}class wU{constructor(t){m(this,"handleBeforeKeyDown",(t,e)=>{if(Rr(e,"Enter")){const{quickReply:o,updateLastCommentItem:r}=this.groupItem;return o.getReplyEditor().isEmpty()?(o.hideReplyEditor(),!0):(o.reply(),r(),!0)}return!1});this.groupItem=t}}class BU{constructor(t,e,o){m(this,"handleBeforeKeyDown",(t,e)=>{if(Rr(e,"Enter")){const{quickReply:o}=this.groupItem,{comment:r,getCommentEditor:i}=this.commentItem,s=i();if(s.isEmpty())this.commentsProvider.localDeleteComment(r.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(r,l),s.readonly()}return o.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=o}}const EU=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
473
473
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.65499 6.6665C3.09433 6.6665 2.66699 7.1275 2.66699 7.67617C2.66699 8.2255 3.02633 8.64284 3.65499 8.6645C4.23833 8.6645 4.66399 8.26917 4.66399 7.67617C4.66399 7.1275 4.23899 6.6665 3.65499 6.6665ZM12.9883 6.6665C12.4277 6.6665 12.0003 7.1275 12.0003 7.67617C12.0003 8.2255 12.3597 8.64284 12.9883 8.6645C13.5717 8.6645 13.9973 8.26917 13.9973 7.67617C13.9973 7.1275 13.5723 6.6665 12.9883 6.6665ZM8.32166 6.6665C7.76099 6.6665 7.33399 7.1275 7.33399 7.67617C7.33399 8.2255 7.69299 8.64284 8.32166 8.6645C8.90499 8.6645 9.33066 8.26917 9.33066 7.67617C9.33066 7.1275 8.90566 6.6665 8.32166 6.6665Z" fill="currentColor"></path>
|
|
474
474
|
</svg>`,xU=`<svg
|
|
475
475
|
fill="currentColor"
|
|
476
476
|
width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
477
477
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.63999 19.5893C8.82172 19.5893 8.9891 19.5427 9.14214 19.4494C9.29518 19.3561 9.48169 19.2115 9.70168 19.0154L12.0403 16.9422H16.2512C16.9255 16.9422 17.497 16.8191 17.9657 16.5728C18.4343 16.3265 18.7906 15.969 19.0345 15.5003C19.2784 15.0317 19.4004 14.4626 19.4004 13.793V8.55629C19.4004 7.88675 19.2784 7.31765 19.0345 6.84897C18.7906 6.38029 18.4343 6.02161 17.9657 5.77293C17.497 5.52424 16.9255 5.3999 16.2512 5.3999H7.5496C6.88007 5.3999 6.31096 5.52305 5.84228 5.76934C5.37361 6.01564 5.01612 6.37432 4.76983 6.84538C4.52354 7.31645 4.40039 7.88675 4.40039 8.55629V13.793C4.40039 14.4626 4.52354 15.0329 4.76983 15.5039C5.01612 15.975 5.37241 16.3325 5.8387 16.5764C6.30498 16.8203 6.86811 16.9422 7.52808 16.9422H7.82937V18.6639C7.82937 18.9461 7.89991 19.1708 8.04099 19.3382C8.18207 19.5056 8.38174 19.5893 8.63999 19.5893ZM8.94845 18.1976V16.2536C8.94845 16.0623 8.90541 15.9248 8.81933 15.8411C8.73325 15.7574 8.59695 15.7155 8.41043 15.7155H7.5783C6.91832 15.7155 6.42932 15.5505 6.11129 15.2206C5.79326 14.8906 5.63425 14.4076 5.63425 13.7715V8.57781C5.63425 7.94175 5.79326 7.45992 6.11129 7.13233C6.42932 6.80473 6.91832 6.64094 7.5783 6.64094H16.2225C16.8825 6.64094 17.3715 6.80473 17.6895 7.13233C18.0075 7.45992 18.1665 7.94175 18.1665 8.57781V13.7715C18.1665 14.4076 18.0075 14.8906 17.6895 15.2206C17.3715 15.5505 16.8825 15.7155 16.2225 15.7155H11.9757C11.7749 15.7155 11.6146 15.7383 11.4951 15.7837C11.3755 15.8291 11.2464 15.9212 11.1077 16.0599L8.94845 18.1976ZM15.584 9.23419C15.5027 9.3131 15.4047 9.35256 15.2899 9.35256H8.42478C8.31479 9.35256 8.22033 9.3131 8.14142 9.23419C8.06251 9.15528 8.02306 9.05844 8.02306 8.94366C8.02306 8.83367 8.06251 8.73802 8.14142 8.65672C8.22033 8.57542 8.31479 8.53477 8.42478 8.53477H15.2899C15.4047 8.53477 15.5027 8.57542 15.584 8.65672C15.6653 8.73802 15.706 8.83367 15.706 8.94366C15.706 9.05844 15.6653 9.15528 15.584 9.23419ZM15.2899 11.5333C15.4047 11.5333 15.5027 11.4939 15.584 11.415C15.6653 11.3361 15.706 11.2392 15.706 11.1244C15.706 11.0097 15.6653 10.9116 15.584 10.8303C15.5027 10.749 15.4047 10.7084 15.2899 10.7084H8.42478C8.31479 10.7084 8.22033 10.749 8.14142 10.8303C8.06251 10.9116 8.02306 11.0097 8.02306 11.1244C8.02306 11.2392 8.06251 11.3361 8.14142 11.415C8.22033 11.4939 8.31479 11.5333 8.42478 11.5333H15.2899ZM13.1845 13.5957C13.1056 13.6747 13.0111 13.7141 12.9011 13.7141H8.42478C8.31479 13.7141 8.22033 13.6747 8.14142 13.5957C8.06251 13.5168 8.02306 13.4224 8.02306 13.3124C8.02306 13.1928 8.06251 13.0924 8.14142 13.0111C8.22033 12.9298 8.31479 12.8891 8.42478 12.8891H12.9011C13.0111 12.8891 13.1056 12.9298 13.1845 13.0111C13.2634 13.0924 13.3028 13.1928 13.3028 13.3124C13.3028 13.4224 13.2634 13.5168 13.1845 13.5957Z"></path>
|
|
478
|
-
</svg>`,Hnt="";S("comment-item");const{t:Ic}=R,
|
|
478
|
+
</svg>`,Hnt="";S("comment-item");const{t:Ic}=R,Gy="comment-item-editing",Zy="active";class Qy{constructor(t){m(this,"root");m(this,"moreMenu");m(this,"components");m(this,"createRoot",()=>{const t=w("div",["comment-item-root"],null);return t.id=this.comment.id,t});m(this,"createAvatar",(t,e)=>{if(e.avatarUrl){const o=w("img",["item-head-avatar"],t);o.src=e.avatarUrl}else{const o=Qd(e.displayName);t.style.setProperty("--comment-avatar-color",o),w("span",["item-head-avatar","item-head-avatar-string"],t,Zd(e.displayName,1))}});m(this,"handleMore",()=>{const{moreButton:t}=this.components;!t||this.moreMenu.manualShow(t,{placement:"bottom-start"})});m(this,"handleMoreMenuItemShow",()=>{const{headTools:t}=this.components;t.classList.add(Zy)});m(this,"handleMoreMenuItemClose",()=>{const{headTools:t}=this.components;t.classList.remove(Zy)});m(this,"handleMoreMenuItemClick",(t,e)=>{const o=this.options.groupList.groupItemHandlers,{id:r}=e;r==="edit"&&o.handleCommentItemEdit(this),r==="delete"&&o.handleCommentItemDelete(this)});m(this,"handleEditorReadonlyChange",t=>{const{components:{actions:e},root:o}=this;t.readonly?(o.classList.remove(Gy),e.classList.add("hidden")):(o.classList.add(Gy),e.classList.remove("hidden"))});m(this,"handleFocus",()=>{const{components:{commentEditor:t,okButton:e}}=this;t.isEmpty()?W(e,Kr):et(e,Kr)});m(this,"handleDocChanged",()=>{const{commentEditor:t,okButton:e}=this.components;t.isEmpty()?W(e,Kr):et(e,Kr)});m(this,"getCommentEditor",()=>this.components.commentEditor);m(this,"handleReadonlyChanged",t=>{t.readonly?W(this.root,"readonly"):et(this.root,"readonly")});this.options=t,this.root=this.createRoot(),this.components=this.createItem(),this.moreMenu=this.createMoreMenu(),t.mainEditor.on("readonlyChanged",this.handleReadonlyChanged)}get commentOptions(){return this.options.mainEditor.getComponentOptions("comment")}get comment(){return this.options.comment}get doc(){const{comment:t,commentsProvider:e}=this.options;return e.getCommentDoc(t.id)}createMoreMenu(){const t=new zs([{id:"edit",name:Ic("comment.edit")},{id:"delete",name:Ic("comment.delete")}]);return t.on("click",this.handleMoreMenuItemClick),t.on("close",this.handleMoreMenuItemClose),t.on("show",this.handleMoreMenuItemShow),t}createItem(){var z,q;const{comment:t,commentsProvider:e,mainEditor:o,groupItem:r}=this.options,i=!((z=this.commentOptions)!=null&&z.disableReply)&&!o.readonly,l=!((q=this.commentOptions)!=null&&q.disableEdit)&&!o.readonly&&e.allowEdit(t)&&i,a=w("div",["item-head"],this.root);this.createAvatar(a,t);const d=w("span",["item-head-username"],a);d.innerText=t.displayName;const h=w("span",["item-head-modified"],a),p=new Date(t.modified);h.innerText=Fm(p);const A=w("div",["item-head-tools"],a);let v=null;i&&(v=Qs(A,Yt.CommentItemReply,Ic("comment.reply"),xU,void 0,o.clientId),Xr(v,Yt.CommentItemReply));let B=null;l&&(B=Qs(A,Yt.CommentItemMore,Ic("comment.more"),EU,void 0,o.clientId),Xr(B,Yt.CommentItemMore),B.onclick=this.handleMore);const D=w("div",["item-editor"],this.root),T=new k2(o,e,this.doc);T.editor.addListener("readonlyChanged",this.handleEditorReadonlyChange),T.editor.addListener("docChanged",this.handleDocChanged),T.editor.addListener("focus",this.handleFocus),T.editor.input.addHandler(new BU(e,r,this)),D.append(T.root);const _=w("div",["item-actions","hidden"],this.root),M=ji(Yt.CommentItemCancel,Ic("common.cancel"));Xr(M,Yt.CommentItemCancel);const H=ji(Yt.CommentItemOk,Ic("comment.send"));return Xr(H,Yt.CommentItemOk),_.append(M,H),{head:a,replyButton:v,moreButton:B,commentEditor:T,okButton:H,cancelButton:M,actions:_,headTools:A}}reloadDoc(){const{components:{commentEditor:t}}=this;t.setDoc(this.doc)}edit(){const{components:{commentEditor:t}}=this;t.edit()}destroy(){const{replyButton:t,moreButton:e,commentEditor:o,okButton:r,cancelButton:i}=this.components;e&&(e.onclick=null),t&&(t.onclick=null),r.onclick=null,i.onclick=null,o.destroy(),this.moreMenu.removeAllListeners(),this.moreMenu.destroy(),this.root.remove(),this.options.mainEditor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const jnt="";class Yy{constructor(t,e,o){m(this,"root");m(this,"components");m(this,"createAvatar",(t,e)=>{if(e.avatarUrl){const o=w("img",["item-head-avatar"],t);o.src=e.avatarUrl}else{const o=Qd(e.displayName);t.style.setProperty("--comment-avatar-color",o),w("span",["item-head-avatar","item-head-avatar-string"],t,Zd(e.displayName,1))}});m(this,"reloadDoc",()=>{const{mobileCommentEditor:t}=this.components;t.setDoc(this.doc)});this.editor=t,this.commentsProvider=e,this.comment=o,this.root=w("div",["mobile-comment-item"],null),this.components=this.createItem()}get doc(){const{comment:t,commentsProvider:e}=this;return e.getCommentDoc(t.id)}createItem(){const{comment:t,editor:e,commentsProvider:o}=this,r=w("div",["item-head"],this.root);this.createAvatar(r,t);const i=w("span",["item-head-username"],r);i.innerText=t.displayName;const s=w("span",["item-head-modified"],r),l=new Date(t.modified);s.innerText=Fm(l);const a=w("div",["item-editor"],this.root),d=new k2(e,o,this.doc);return a.append(d.root),{mobileCommentEditor:d}}destroy(){this.root.remove(),this.components.mobileCommentEditor.destroy()}}const Unt="";class IU{constructor(t,e){m(this,"root");m(this,"countElement");m(this,"updateCount",t=>{this.countElement.textContent=`${t}`});this.root=w("div",["mini-comment-item"],e),this.root.id=t,this.countElement=w("span",["mini-comment-item-count"],this.root)}}class _u extends be.TypedEmitter{constructor(e,o,r,i,s){super();m(this,"_items");this.editor=e,this.commentsProvider=o,this.container=r,this.options=s,this._items=this.createList(i)}get items(){return this._items}createList(e){return e.map(r=>{const i=this.createItem(r,"init");return this.container.appendChild(i.root),i})}reloadList(e){this.container.innerHTML="",this.createList(e)}insertItem(e){const o=this.findInsertPos(e);if(o===-1)return null;const r=this.createItem(e,"insert");if(o===this.items.length)this.container.appendChild(r.root);else{const i=this.items[o];this.container.insertBefore(r.root,i.root)}return this.items.splice(o,0,r),r}deleteItem(e){const o=this.findItemIndex(e);if(o!==-1){const r=this.items[o];return this.items.splice(o,1),r.destroy(),!0}return!1}findItemIndex(e){return this.items.findIndex(o=>o.comment.id===e)}findItem(e){const o=this.findItemIndex(e);return o===-1?null:this.items[o]}destroy(){this._items.forEach(e=>e.destroy()),this._items=[]}}class TU extends _u{constructor(t){const{editor:e,comments:o,commentsProvider:r,parent:i}=t;super(e,r,i,o,t)}createItem(t){const{editor:e,commentsProvider:o,groupList:r,groupItem:i}=this.options;return new Qy({mainEditor:e,commentsProvider:o,comment:t,groupList:r,groupItem:i})}findInsertPos(){return this.items.length}destroy(){this.items.forEach(t=>{t.destroy()})}}const DU=`<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
479
479
|
<path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
480
480
|
</svg>`,SU=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
|
|
481
481
|
<path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
482
|
-
</svg>`,znt="",Zf="reply-editor-editing",{t:w2}=R;class LU{constructor(t,e,o,r){m(this,"root");m(this,"components");m(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&W(e,Kr)});m(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();Ag(o)?W(e,Kr):et(e,Kr)});m(this,"getReplyEditor",()=>this.components.replyEditor);m(this,"showReplyEditor",()=>{xt(this.root,Zf)||(W(this.root,Zf),this.components.replyEditor.edit())});m(this,"hideReplyEditor",()=>{!xt(this.root,Zf)||et(this.root,Zf)});m(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=Gf({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});m(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});m(this,"hide",()=>{xt(this.root,"hidden")||W(this.root,"hidden")});m(this,"show",()=>{et(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=w("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=Qs(this.root,Yt.QuickReply,w2("comment.placeholder"));Xr(e,Yt.QuickReply),e.classList.add("quick-reply-button");const o=w("div",["quick-reply-editor"],this.root),r=jr(),i=new k2(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new wU(this.groupItem)),o.append(i.root);const s=w("div",["reply-editor-actions"],o),l=ji(Yt.QuickReplyCancel,w2("common.cancel"));Xr(l,Yt.QuickReplyCancel);const a=ji(Yt.QuickReplyOk,w2("comment.send"));return Xr(a,Yt.QuickReplyOk),W(a,Kr),s.append(l,a),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:a}}}const ti=S("comment-group-item");class MU extends be.TypedEmitter{constructor(e,o,r,i){super();m(this,"root");m(this,"header");m(this,"mainItem");m(this,"childrenList");m(this,"resizeObserver");m(this,"quickReply");m(this,"createRoot",()=>w("div",["comment-group-item-root"],null));m(this,"createChildrenList",()=>{const e=w("div",["comment-children-list-container"],this.root);return new TU({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});m(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));g(ti,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{et(r,P8)});const o=e.at(-1);W(o,P8)});m(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');g(ti,e,"switchUpButton not exist"),g(ti,o,"switchDownButton not exist"),et(o,"disabled"),et(e,"disabled"),this.root.previousElementSibling===null&&W(e,"disabled"),this.root.nextElementSibling===null&&W(o,"disabled")});m(this,"handleReadonlyChanged",e=>{e.readonly?W(this.root,"readonly"):et(this.root,"readonly")});m(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,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 ResizeObserver(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return $8(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new LU(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=w("div",["comment-item-head"],this.root),r=w("span",["item-head-quote"],o);r.innerText=e.abstract;const i=w("span",["item-head-switch"],o),s=Qs(i,Yt.SwitchUp,"up",DU),l=Qs(i,Yt.SwitchDown,"down",SU);return Xr(s,Yt.SwitchUp),Xr(l,Yt.SwitchDown),o}createItem(){const e=w("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new Q8({mainEditor:o,commentsProvider:r,comment:i,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(o=>o.comment.id===e):null}handleCreateComment(e){return g(ti,Js(e),"invalid comment, not a child comment"),g(ti,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){g(ti,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){ti.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(ti,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(ti,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 RU=S("arrange=items"),J8=20;function K8(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function X8(n,t){return Number.parseInt(t.root.style.top,10)}function ty(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,a=K8(n,l.groupId);if(s.root.setAttribute("data-target-top",a.toString()),i===r){if(o!==void 0){const p=t[0];p.root.style.top=`${o}px`}else s.root.style.top=`${a}px`;continue}const d=t[i-1],h=X8(n,d)+d.root.getBoundingClientRect().height;h>a?s.root.style.top=`${h+J8}px`:s.root.style.top=`${a}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,a=K8(n,l.groupId);s.root.setAttribute("data-target-top",a.toString());const d=s.root.getBoundingClientRect(),h=a+d.height,p=t[i+1];g(RU,p,"no next item");const A=X8(n,p);A<h?s.root.style.top=`${A-d.height-J8}px`:s.root.style.top=`${a}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const Qf=S("comment-group-item-handler");class OU{constructor(t,e){m(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});m(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});m(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});m(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});m(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});m(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);g(Qf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),a={type:"mention",id:K(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,a)});m(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});m(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);g(Qf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),a=l.getDoc();this.commentsProvider.localUpdateComment(i,a),l.readonly(),r.show()});m(this,"handleCommentItemCancel",(t,e)=>{var a,d;const o=t.findCommentItem(e);g(Qf,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);let i=!1;if((a=r.blocks)!=null&&a.length||(i=!0),((d=r.blocks)==null?void 0:d.length)===1){const h=r.blocks[0];i=!!h.text&&rn(h.text)===0}if(i){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:s}=t,l=o.getCommentEditor();l.setDoc(o.doc),l.readonly(),s.show()});m(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});m(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});m(this,"execute",(t,e,o,r)=>{const i=gU(t);if(!i||CU(i))return;const s=pU(i);switch(s){case Yt.SwitchUp:this.handleSwitchUp(r);break;case Yt.SwitchDown:this.handleSwitchDown(r);break;case Yt.CommentItemReply:this.handleCommentItemReply(e,o);break;case Yt.CommentItemMore:this.handleCommentItemMore(e);break;case Yt.CommentItemOk:this.handleCommentItemOk(e,o);break;case Yt.CommentItemCancel:this.handleCommentItemCancel(e,o);break;case Yt.CommentItemDelete:break;case Yt.CommentItemEdit:break;case Yt.QuickReply:this.handleQuickReply(e);break;case Yt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Yt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;Qf.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const Yf=S("comment-group-list");class _U extends _u{constructor(e,o,r){super(e,o,r,ts(e,o),{});m(this,"groupItemHandlers");m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=mU(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items.at(i),r,i)}});m(this,"handleSelectionChanged",()=>{var o;const e=V8(this.editor);if(e.length>0){if(((o=this.activeItem)==null?void 0:o.comment.id)&&e.includes(this.activeItem.comment.id))return;const r=e[0],i=this.items.findIndex(s=>s.comment.groupId===r);this.setActiveItem(i),this.emit("selectionOnComment")}else this.setActiveItem(-1)});m(this,"handleEditorResize",()=>{this.updateItemsLayout()});m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"handleItemResize",()=>{this.updateItemsLayout()});m(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&ty(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});m(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;g(Yf,e,"invalid activeItem"),e.updateSwitchButton()});m(this,"updateComments",He.default(()=>{const e=ts(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(s=>s.groupId===i.comment.groupId)===-1&&(this.deleteItem(i.comment.id),o=!0)}o&&(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(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new OU(this,o)}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()}updateItemsLayout(){ty(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new MU(this.editor,this.commentsProvider,e,this);return o==="insert"&&(W(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{et(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=ts(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e,o){const r=super.insertItem(e);return r?(o!=null&&o.active&&this.setActiveItem(this.items.indexOf(r)),this.updateItemsLayout(),r.addListener("resize",this.handleItemResize),r):null}setActiveItem(e){if(g(Yf,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const o=this.container.querySelector(".comment-group-item-root.active");if(o&&et(o,"active"),e!==-1){const r=this.items[e];W(r.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(Js(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);g(Yf,!r,"comment group item has already exists");const i={children:[],...e};g(Yf,i.children,"not a comment group");const s=this.insertItem(i,{active:o});!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?(this.deleteItem(r.comment.id),this.updateItemsLayout()):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&(this.deleteItem(r.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const FU="comment-mini";S("comment-list");class PU extends be.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"groupsContainer");m(this,"list");m(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});m(this,"updateCommentCount",()=>{var o,r;const e=vU(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});m(this,"handleActiveItemChanged",()=>{var o;const e=this.list.activeItem;q8(this.editor,(o=e==null?void 0:e.comment.id)!=null?o:"")});m(this,"handleItemLayoutUpdated",()=>{var o,r;const e=xt(this.root,FU);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=w("div",["editor-web-comment-root"],null),this.groupsContainer=w("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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new _U(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(et(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){W(this.root,"hidden")}}class NU extends _u{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new Y8(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const Jf=S("mobile-comment-group-item"),$U=20;class HU extends be.TypedEmitter{constructor(e,o,r){super();m(this,"root");m(this,"childrenList");m(this,"mainItem");m(this,"scroller");m(this,"createRoot",()=>w("div",["mobile-group-item-root"],null));m(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new Y8(o,r,i);return e.append(s.root),s});m(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=w("div",["mobile-comment-children-list-container"],e);return new NU({editor:o,commentsProvider:r,comments:i.children,parent:s})});m(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=$U}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,N8)}});m(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=w("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=w("div",["mobile-group-item"],this.root),s=w("div",["mobile-group-item-space"],null),l=w("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const a=w("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(a),this.childrenList=this.createChildrenList(a),i.append(s,l,a),this.scroller=new Y5.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return $8(this.root,".mobile-group-item")}handleUpdateChildComment(e){g(Jf,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){Jf.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(Jf,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(Jf,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 B2=S("mobile-group-list");class jU extends _u{constructor(e,o,r,i){super(e,o,r,ts(e,o),{});m(this,"scroller");m(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});m(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,N8),!0):!1});m(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});m(this,"handleReachBottom",()=>{this.emit("onReachBottom")});m(this,"handleReachTop",()=>{this.emit("onReachTop")});m(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);g(B2,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),q8(this.editor,r.comment.id)});m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"updateComments",He.default(()=>{const e=ts(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new Y5.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new HU(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=ts(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(Js(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);g(B2,!r,"comment group item has already exists");const i={children:[],...e};g(B2,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const UU=S("mobile-comment-list"),{t:ey}=R;class zU extends be.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"list");m(this,"mask");m(this,"pullInfoContainer");m(this,"handleRootClick",e=>{const o=e.target;g(UU,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});m(this,"hidePullInfo",He.default(()=>{et(this.pullInfoContainer,"active")},1e3*3));m(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});m(this,"handleReachTop",()=>{this.showPullInfo("top")});m(this,"show",e=>{var o;et(this.root,"hidden"),W(document.documentElement,"disabled-scroll"),(o=this.commentOptions)==null||o.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});m(this,"hide",()=>{W(this.root,"hidden"),et(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=w("div",["editor-mobile-comments-root"],null),this.mask=w("div",["mobile-comment-mask"],this.root);const r=w("div",["mobile-comment-groups-container"],this.root),i=w("div",["mobile-comment-groups-scroll-container"],r);this.list=new jU(this.editor,this.commentsProvider,i,r),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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=w("div",["mobile-comment-pull-info-container"],this.root);return w("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=ey(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,W(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function ny(n,t){const e=ts(n,t),o=new Map;for(const r of e){const i=H8(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);b2(r).forEach(a=>{s==null||s.commentIds.add(a.id)})}else{const s=b2(r),l=new Set(s.map(a=>a.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const VU=S("mini-group-item");class WU{constructor(t,e){m(this,"root");m(this,"blockId");m(this,"comment");m(this,"miniCommentItem");m(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=w("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new IU(this.comment.id,this.root),this.blockId=this.getBlockId(),this.alignToBlock(),this.updateCommentItemCount()}getBlockId(){return H8(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId(),e=this.editor.getBlockById(t);g(VU,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),r=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-o.top+r;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class qU extends _u{constructor(e,o,r){super(e,o,r,ny(e,o),{});m(this,"fixListOps",He.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));m(this,"handleDocChanged",He.default(()=>{this.updateMiniCommentsGroup()},100));m(this,"updateMiniCommentsGroup",()=>{const e=ny(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new WU(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const GU=S("mini-comments-list");class ZU extends be.TypedEmitter{constructor(e,o){super();m(this,"list");m(this,"root");m(this,"createList",()=>{const e=w("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new qU(this.editor,this.commentsProvider,e)});m(this,"handleListContainerClick",(e,o)=>{const r=o.target;g(GU,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=w("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){et(this.root,"hidden")}hide(){W(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function oy(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=ye(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;Z6(n,o,r,i,s)}function QU(n,t,e){const o=Lo(n).map(s=>s.block),r=p2(n,o),i=Gf({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{Lo(n,{simpleBlockOnly:!0}).forEach(a=>{!tt(n,a.block)||oy(n,a,i)});const l=jr();e.localCreateComment(i,l)}),i}class YU{constructor(t,e){m(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(tt(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=it(e),s=Dt(e),l=Io(t,e);return[{id:"add-comment",name:R.t("comment.command"),blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:eu}]}return[]}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=QU(t,e,this.provider);return i["add-comment"]=s,!0}return!1}}class ry{constructor(t,e){m(this,"commentList",null);m(this,"mobileCommentList",null);m(this,"miniCommentList");m(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});m(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});m(this,"handleCommentListClose",()=>{this.showComment("mini")});m(this,"handleOnSelectComment",()=>{this.showComment("web")});m(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new YU(e,this)),t.blockHooks.push(new hU(this.provider,this)),this.isMobile?(this.mobileCommentList=new zU(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new PU(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new ZU(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new fU)}get commentProvider(){return this.provider}get isMobile(){return Ke.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}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 Vnt="",JU={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\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"}},KU={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add Annotations or @ others",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"}},XU={comment:{count:"\u30B3\u30E1\u30F3\u30C8 ({num})",hide:"\u30B3\u30E1\u30F3\u30C8\u3092\u975E\u8868\u793A",show:"\u30B3\u30E1\u30F3\u30C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u8A8D",placeholder:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\u30E1\u30F3\u30B7\u30E7\u30F3(@)",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u30B3\u30E1\u30F3\u30C8\u3092",command:"\u30B3\u30E1\u30F3\u30C8\u3092",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};R.mergeLang({"zh-CN":JU,"en-US":KU,"ja-JP":XU});class iy{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;et(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(W(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class tz{constructor(t){m(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});m(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});m(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();If(t,e,R.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function ez(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&tt(n,t)){const s=mg(i,`comment-${e.toLocaleLowerCase()}`,e);ua.default(i,s)||n.setBlockText(t,s)}}const nz=S("editor-comment");function oz(n){const t=n.getCustom("editor-comments");if(g(nz,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Di(s);if(l.length>=2){const{containerId:a}=l.at(-1),d=ot(Nr(n,a));if(d&&Dt(d)==="code"){C2(n,d,t.commentProvider);return}}C2(n,s,t.commentProvider);return}const e=Lo(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=p2(n,o),i=Gf({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{tt(n,l.block)?oy(n,l,i):F8(n,l.block,i)});const s=jr();t.commentProvider.localCreateComment(i,s)})}const E2=S("text-styles");function rz(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function iz(n,t,e,o,r){g(E2,e.isSimple(),"invalid range");const{start:i,end:s}=e;g(E2,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(E2,o.startsWith("style-"),"invalid style");let a=n.getBlockText(t);return o==="style-sub"?a=ql(i.offset,s.offset-i.offset,a,"style-super",r,{ignoreValue:!0}):o==="style-super"&&(a=ql(i.offset,s.offset-i.offset,a,"style-sub",r,{ignoreValue:!0})),r===!1||r===void 0||r===null?a=ql(i.offset,s.offset-i.offset,a,o,void 0,{ignoreValue:!0}):a=Ia(i.offset,s.offset-i.offset,a,o,r),n.setBlockText(t,a),a}const sz=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
482
|
+
</svg>`,znt="",Zf="reply-editor-editing",{t:w2}=R;class LU{constructor(t,e,o,r){m(this,"root");m(this,"components");m(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&W(e,Kr)});m(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();Ag(o)?W(e,Kr):et(e,Kr)});m(this,"getReplyEditor",()=>this.components.replyEditor);m(this,"showReplyEditor",()=>{xt(this.root,Zf)||(W(this.root,Zf),this.components.replyEditor.edit())});m(this,"hideReplyEditor",()=>{!xt(this.root,Zf)||et(this.root,Zf)});m(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=Gf({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});m(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});m(this,"hide",()=>{xt(this.root,"hidden")||W(this.root,"hidden")});m(this,"show",()=>{et(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=w("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=Qs(this.root,Yt.QuickReply,w2("comment.placeholder"));Xr(e,Yt.QuickReply),e.classList.add("quick-reply-button");const o=w("div",["quick-reply-editor"],this.root),r=jr(),i=new k2(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new wU(this.groupItem)),o.append(i.root);const s=w("div",["reply-editor-actions"],o),l=ji(Yt.QuickReplyCancel,w2("common.cancel"));Xr(l,Yt.QuickReplyCancel);const a=ji(Yt.QuickReplyOk,w2("comment.send"));return Xr(a,Yt.QuickReplyOk),W(a,Kr),s.append(l,a),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:a}}}const ti=S("comment-group-item");class MU extends be.TypedEmitter{constructor(e,o,r,i){super();m(this,"root");m(this,"header");m(this,"mainItem");m(this,"childrenList");m(this,"resizeObserver");m(this,"quickReply");m(this,"createRoot",()=>w("div",["comment-group-item-root"],null));m(this,"createChildrenList",()=>{const e=w("div",["comment-children-list-container"],this.root);return new TU({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});m(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));g(ti,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{et(r,Py)});const o=e.at(-1);W(o,Py)});m(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');g(ti,e,"switchUpButton not exist"),g(ti,o,"switchDownButton not exist"),et(o,"disabled"),et(e,"disabled"),this.root.previousElementSibling===null&&W(e,"disabled"),this.root.nextElementSibling===null&&W(o,"disabled")});m(this,"handleReadonlyChanged",e=>{e.readonly?W(this.root,"readonly"):et(this.root,"readonly")});m(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,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 ResizeObserver(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return $y(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new LU(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=w("div",["comment-item-head"],this.root),r=w("span",["item-head-quote"],o);r.innerText=e.abstract;const i=w("span",["item-head-switch"],o),s=Qs(i,Yt.SwitchUp,"up",DU),l=Qs(i,Yt.SwitchDown,"down",SU);return Xr(s,Yt.SwitchUp),Xr(l,Yt.SwitchDown),o}createItem(){const e=w("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new Qy({mainEditor:o,commentsProvider:r,comment:i,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(o=>o.comment.id===e):null}handleCreateComment(e){return g(ti,Js(e),"invalid comment, not a child comment"),g(ti,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){g(ti,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){ti.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(ti,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(ti,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 RU=S("arrange=items"),Jy=20;function Ky(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function Xy(n,t){return Number.parseInt(t.root.style.top,10)}function t8(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,a=Ky(n,l.groupId);if(s.root.setAttribute("data-target-top",a.toString()),i===r){if(o!==void 0){const p=t[0];p.root.style.top=`${o}px`}else s.root.style.top=`${a}px`;continue}const d=t[i-1],h=Xy(n,d)+d.root.getBoundingClientRect().height;h>a?s.root.style.top=`${h+Jy}px`:s.root.style.top=`${a}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,a=Ky(n,l.groupId);s.root.setAttribute("data-target-top",a.toString());const d=s.root.getBoundingClientRect(),h=a+d.height,p=t[i+1];g(RU,p,"no next item");const A=Xy(n,p);A<h?s.root.style.top=`${A-d.height-Jy}px`:s.root.style.top=`${a}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const Qf=S("comment-group-item-handler");class OU{constructor(t,e){m(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});m(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});m(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});m(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});m(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});m(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);g(Qf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),a={type:"mention",id:K(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,a)});m(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});m(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);g(Qf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),a=l.getDoc();this.commentsProvider.localUpdateComment(i,a),l.readonly(),r.show()});m(this,"handleCommentItemCancel",(t,e)=>{var a,d;const o=t.findCommentItem(e);g(Qf,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);let i=!1;if((a=r.blocks)!=null&&a.length||(i=!0),((d=r.blocks)==null?void 0:d.length)===1){const h=r.blocks[0];i=!!h.text&&rn(h.text)===0}if(i){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:s}=t,l=o.getCommentEditor();l.setDoc(o.doc),l.readonly(),s.show()});m(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});m(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});m(this,"execute",(t,e,o,r)=>{const i=gU(t);if(!i||CU(i))return;const s=pU(i);switch(s){case Yt.SwitchUp:this.handleSwitchUp(r);break;case Yt.SwitchDown:this.handleSwitchDown(r);break;case Yt.CommentItemReply:this.handleCommentItemReply(e,o);break;case Yt.CommentItemMore:this.handleCommentItemMore(e);break;case Yt.CommentItemOk:this.handleCommentItemOk(e,o);break;case Yt.CommentItemCancel:this.handleCommentItemCancel(e,o);break;case Yt.CommentItemDelete:break;case Yt.CommentItemEdit:break;case Yt.QuickReply:this.handleQuickReply(e);break;case Yt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Yt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;Qf.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const Yf=S("comment-group-list");class _U extends _u{constructor(e,o,r){super(e,o,r,ts(e,o),{});m(this,"groupItemHandlers");m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=mU(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items.at(i),r,i)}});m(this,"handleSelectionChanged",()=>{var o;const e=Vy(this.editor);if(e.length>0){if(((o=this.activeItem)==null?void 0:o.comment.id)&&e.includes(this.activeItem.comment.id))return;const r=e[0],i=this.items.findIndex(s=>s.comment.groupId===r);this.setActiveItem(i),this.emit("selectionOnComment")}else this.setActiveItem(-1)});m(this,"handleEditorResize",()=>{this.updateItemsLayout()});m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"handleItemResize",()=>{this.updateItemsLayout()});m(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&t8(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});m(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;g(Yf,e,"invalid activeItem"),e.updateSwitchButton()});m(this,"updateComments",He.default(()=>{const e=ts(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(s=>s.groupId===i.comment.groupId)===-1&&(this.deleteItem(i.comment.id),o=!0)}o&&(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(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new OU(this,o)}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()}updateItemsLayout(){t8(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new MU(this.editor,this.commentsProvider,e,this);return o==="insert"&&(W(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{et(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=ts(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e,o){const r=super.insertItem(e);return r?(o!=null&&o.active&&this.setActiveItem(this.items.indexOf(r)),this.updateItemsLayout(),r.addListener("resize",this.handleItemResize),r):null}setActiveItem(e){if(g(Yf,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const o=this.container.querySelector(".comment-group-item-root.active");if(o&&et(o,"active"),e!==-1){const r=this.items[e];W(r.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(Js(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);g(Yf,!r,"comment group item has already exists");const i={children:[],...e};g(Yf,i.children,"not a comment group");const s=this.insertItem(i,{active:o});!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?(this.deleteItem(r.comment.id),this.updateItemsLayout()):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&(this.deleteItem(r.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const FU="comment-mini";S("comment-list");class PU extends be.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"groupsContainer");m(this,"list");m(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});m(this,"updateCommentCount",()=>{var o,r;const e=vU(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});m(this,"handleActiveItemChanged",()=>{var o;const e=this.list.activeItem;qy(this.editor,(o=e==null?void 0:e.comment.id)!=null?o:"")});m(this,"handleItemLayoutUpdated",()=>{var o,r;const e=xt(this.root,FU);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=w("div",["editor-web-comment-root"],null),this.groupsContainer=w("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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new _U(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(et(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){W(this.root,"hidden")}}class NU extends _u{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new Yy(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const Jf=S("mobile-comment-group-item"),$U=20;class HU extends be.TypedEmitter{constructor(e,o,r){super();m(this,"root");m(this,"childrenList");m(this,"mainItem");m(this,"scroller");m(this,"createRoot",()=>w("div",["mobile-group-item-root"],null));m(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new Yy(o,r,i);return e.append(s.root),s});m(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=w("div",["mobile-comment-children-list-container"],e);return new NU({editor:o,commentsProvider:r,comments:i.children,parent:s})});m(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=$U}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,Ny)}});m(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=w("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=w("div",["mobile-group-item"],this.root),s=w("div",["mobile-group-item-space"],null),l=w("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const a=w("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(a),this.childrenList=this.createChildrenList(a),i.append(s,l,a),this.scroller=new Y5.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return $y(this.root,".mobile-group-item")}handleUpdateChildComment(e){g(Jf,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){Jf.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(Jf,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(Jf,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 B2=S("mobile-group-list");class jU extends _u{constructor(e,o,r,i){super(e,o,r,ts(e,o),{});m(this,"scroller");m(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});m(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,Ny),!0):!1});m(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});m(this,"handleReachBottom",()=>{this.emit("onReachBottom")});m(this,"handleReachTop",()=>{this.emit("onReachTop")});m(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);g(B2,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),qy(this.editor,r.comment.id)});m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"updateComments",He.default(()=>{const e=ts(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new Y5.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new HU(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=ts(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(Js(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);g(B2,!r,"comment group item has already exists");const i={children:[],...e};g(B2,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const UU=S("mobile-comment-list"),{t:e8}=R;class zU extends be.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"list");m(this,"mask");m(this,"pullInfoContainer");m(this,"handleRootClick",e=>{const o=e.target;g(UU,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});m(this,"hidePullInfo",He.default(()=>{et(this.pullInfoContainer,"active")},1e3*3));m(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});m(this,"handleReachTop",()=>{this.showPullInfo("top")});m(this,"show",e=>{var o;et(this.root,"hidden"),W(document.documentElement,"disabled-scroll"),(o=this.commentOptions)==null||o.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});m(this,"hide",()=>{W(this.root,"hidden"),et(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=w("div",["editor-mobile-comments-root"],null),this.mask=w("div",["mobile-comment-mask"],this.root);const r=w("div",["mobile-comment-groups-container"],this.root),i=w("div",["mobile-comment-groups-scroll-container"],r);this.list=new jU(this.editor,this.commentsProvider,i,r),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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=w("div",["mobile-comment-pull-info-container"],this.root);return w("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=e8(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,W(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function n8(n,t){const e=ts(n,t),o=new Map;for(const r of e){const i=Hy(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);b2(r).forEach(a=>{s==null||s.commentIds.add(a.id)})}else{const s=b2(r),l=new Set(s.map(a=>a.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const VU=S("mini-group-item");class WU{constructor(t,e){m(this,"root");m(this,"blockId");m(this,"comment");m(this,"miniCommentItem");m(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=w("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new IU(this.comment.id,this.root),this.blockId=this.getBlockId(),this.alignToBlock(),this.updateCommentItemCount()}getBlockId(){return Hy(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId(),e=this.editor.getBlockById(t);g(VU,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),r=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-o.top+r;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class qU extends _u{constructor(e,o,r){super(e,o,r,n8(e,o),{});m(this,"fixListOps",He.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));m(this,"handleDocChanged",He.default(()=>{this.updateMiniCommentsGroup()},100));m(this,"updateMiniCommentsGroup",()=>{const e=n8(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new WU(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const GU=S("mini-comments-list");class ZU extends be.TypedEmitter{constructor(e,o){super();m(this,"list");m(this,"root");m(this,"createList",()=>{const e=w("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new qU(this.editor,this.commentsProvider,e)});m(this,"handleListContainerClick",(e,o)=>{const r=o.target;g(GU,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=w("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){et(this.root,"hidden")}hide(){W(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function o8(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=ye(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;Z6(n,o,r,i,s)}function QU(n,t,e){const o=Lo(n).map(s=>s.block),r=p2(n,o),i=Gf({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{Lo(n,{simpleBlockOnly:!0}).forEach(a=>{!tt(n,a.block)||o8(n,a,i)});const l=jr();e.localCreateComment(i,l)}),i}class YU{constructor(t,e){m(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(tt(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=it(e),s=Dt(e),l=Io(t,e);return[{id:"add-comment",name:R.t("comment.command"),blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:eu}]}return[]}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=QU(t,e,this.provider);return i["add-comment"]=s,!0}return!1}}class r8{constructor(t,e){m(this,"commentList",null);m(this,"mobileCommentList",null);m(this,"miniCommentList");m(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});m(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});m(this,"handleCommentListClose",()=>{this.showComment("mini")});m(this,"handleOnSelectComment",()=>{this.showComment("web")});m(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new YU(e,this)),t.blockHooks.push(new hU(this.provider,this)),this.isMobile?(this.mobileCommentList=new zU(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new PU(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new ZU(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new fU)}get commentProvider(){return this.provider}get isMobile(){return Ke.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}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 Vnt="",JU={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\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"}},KU={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add Annotations or @ others",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"}},XU={comment:{count:"\u30B3\u30E1\u30F3\u30C8 ({num})",hide:"\u30B3\u30E1\u30F3\u30C8\u3092\u975E\u8868\u793A",show:"\u30B3\u30E1\u30F3\u30C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u8A8D",placeholder:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\u30E1\u30F3\u30B7\u30E7\u30F3(@)",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u30B3\u30E1\u30F3\u30C8\u3092",command:"\u30B3\u30E1\u30F3\u30C8\u3092",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};R.mergeLang({"zh-CN":JU,"en-US":KU,"ja-JP":XU});class i8{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;et(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(W(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class tz{constructor(t){m(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});m(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});m(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();If(t,e,R.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function ez(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&tt(n,t)){const s=mg(i,`comment-${e.toLocaleLowerCase()}`,e);ua.default(i,s)||n.setBlockText(t,s)}}const nz=S("editor-comment");function oz(n){const t=n.getCustom("editor-comments");if(g(nz,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Di(s);if(l.length>=2){const{containerId:a}=l.at(-1),d=ot(Nr(n,a));if(d&&Dt(d)==="code"){C2(n,d,t.commentProvider);return}}C2(n,s,t.commentProvider);return}const e=Lo(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=p2(n,o),i=Gf({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{tt(n,l.block)?o8(n,l,i):Fy(n,l.block,i)});const s=jr();t.commentProvider.localCreateComment(i,s)})}const E2=S("text-styles");function rz(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function iz(n,t,e,o,r){g(E2,e.isSimple(),"invalid range");const{start:i,end:s}=e;g(E2,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(E2,o.startsWith("style-"),"invalid style");let a=n.getBlockText(t);return o==="style-sub"?a=ql(i.offset,s.offset-i.offset,a,"style-super",r,{ignoreValue:!0}):o==="style-super"&&(a=ql(i.offset,s.offset-i.offset,a,"style-sub",r,{ignoreValue:!0})),r===!1||r===void 0||r===null?a=ql(i.offset,s.offset-i.offset,a,o,void 0,{ignoreValue:!0}):a=Ia(i.offset,s.offset-i.offset,a,o,r),n.setBlockText(t,a),a}const sz=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
483
483
|
<line x1="3.5" y1="0.5" x2="3.5" y2="15.5" stroke="currentColor"/>
|
|
484
484
|
<path d="M4 8L7.5 8C9.433 8 11 6.433 11 4.5V4.5C11 2.567 9.433 1 7.5 1L4 1" stroke="currentColor"/>
|
|
485
485
|
<path d="M4 15L9.5 15C11.433 15 13 13.433 13 11.5V11.5C13 9.567 11.433 8 9.5 8L4 8" stroke="currentColor"/>
|
|
@@ -506,7 +506,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
506
506
|
<path d="M1.00098 12.9985L10.9995 2.99998" stroke="currentColor"/>
|
|
507
507
|
<path d="M11.9113 6.16809L13.7433 3.79209C13.946 3.52009 14.0473 3.26142 14.0473 3.01609V2.90409C14.0473 2.71209 13.994 2.56009 13.8873 2.44809C13.786 2.33609 13.6473 2.28009 13.4713 2.28009C13.2953 2.28009 13.1567 2.33876 13.0553 2.45609C12.954 2.57342 12.9033 2.73609 12.9033 2.94409V3.07209H11.8873V2.88009C11.8873 2.59209 11.9513 2.33609 12.0793 2.11209C12.2127 1.88809 12.402 1.71209 12.6473 1.58409C12.8927 1.45609 13.1807 1.39209 13.5113 1.39209C13.8313 1.39209 14.1113 1.45876 14.3513 1.59209C14.5967 1.72542 14.7833 1.90409 14.9113 2.12809C15.0447 2.35209 15.1113 2.60009 15.1113 2.87209V3.00809C15.1113 3.24809 15.0687 3.46942 14.9833 3.67209C14.898 3.87476 14.7727 4.08276 14.6073 4.29609L13.2313 6.08009H15.1113V7.00009H11.9113V6.16809Z" fill="currentColor"/>
|
|
508
508
|
</svg>
|
|
509
|
-
`,Ks=S("text-commands");function
|
|
509
|
+
`,Ks=S("text-commands");function s8(n){const t={id:"more",name:R.t("commands.more"),icon:lv,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[R.t("commands.bold"),Bo("CtrlOrCmd+B"),sz],"style-italic":[R.t("commands.italic"),Bo("CtrlOrCmd+I"),lz],"style-underline":[R.t("commands.underline"),Bo("CtrlOrCmd+U"),cz],"style-strikethrough":[R.t("commands.strikethrough"),Bo("CtrlOrCmd+D"),az],"style-code":[R.t("commands.code"),void 0,uz]},o={"style-super":[R.t("commands.superscript"),void 0,hz],"style-sub":[R.t("commands.subscript"),void 0,dz]};if(rn(n)===0){const l=Object.entries(e).map(([a,[d,h,p]])=>({id:a,name:d,icon:p,desc:h}));return t.children=Object.entries(o).map(([a,[d,h,p]])=>({id:a,name:d,icon:p,desc:h})),l.concat(t)}const r=rz(n);function i([l,[a,d,h]]){const p=r.get(l);return p!==void 0?{id:l,name:a,value:p,states:p===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:a,icon:h,desc:d}}const s=Object.entries(e).map(i);return t.children=Object.entries(o).map(i),s.concat(t)}function fz(n,t){const e=it(t),o=Dt(t),r=Io(n,t);return s8([]).map(i=>({blockId:e,blockType:o,blockKind:r,...i,groupIndex:500}))}function mz(n,t,e){g(Ks,e.isSimple(),"nor a simple range");const{start:o,end:r}=e;g(Ks,o.isSimple(),"is not a simple block position"),g(Ks,r.isSimple(),"is not a simple block position"),g(Ks,tt(n,t),"invalid block type, not a text kind block");const i=it(t);g(Ks,o.blockId===i&&r.blockId===i,"invalid range");const s=n.getBlockText(t);let l=[];o.offset===r.offset?o.offset!==0&&(l=ze(s,o.offset-1,1).middle):l=ze(s,o.offset,r.offset-o.offset).middle;const a=Dt(t),d=Io(n,t);return s8(l).map((h,p)=>({blockId:i,blockType:a,blockKind:d,...h,groupIndex:500,order:p*100}))}function gz(n,t,e,o,r,i){if(!tt(n,t))return!1;if(!o.startsWith("style-"))return Ks.warn(`unknown command: ${o}`),!1;const s=r==null?void 0:r.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return Ks.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const a=iz(n,t,e,o,s);return n.focus(),i.result=a,!0}const pz=S("text-command-provider");class Cr{constructor(t){m(this,"id","TextCommandProvider");m(this,"emptyTextBlockAttributes",new Map);m(this,"colorItem");m(this,"updateButtonColor",()=>{const t=jg(this.editor,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(t)});m(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")Q6(this.editor,t,e,this.setEmptyTextBlockColor);else{const o=["clearAll","clearColor","clearBackground"];Y6(this.editor,o[e],this.setEmptyTextBlockColor)}this.editor.focus()});m(this,"handleBeforePopupPalette",()=>{const t=jg(this.editor,this.getEmptyTextBlockColor);this.colorItem.updatePaletteColor(t)});m(this,"getEmptyTextBlockColor",(t,e)=>{const o=this.getEmptyBlockTextAttributes(t,e);return gg(o)});m(this,"setEmptyTextBlockColor",(t,e,o,r)=>{var s;const i=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};n6(i,o,r),this.emptyTextBlockAttributes.set(e,i)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new pM(t)),this.colorItem.addListener("onClick",this.handleChangeColor),this.colorItem.addListener("beforePopup",this.handleBeforePopupPalette)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,o){if(!tt(t,e))return[];let r;ut(t,e)===0?r=this.getCommandsOnEmptyText(t,e).map(Cr.toTextCommand):r=mz(t,e,o).map(Cr.toTextCommand),this.updateButtonColor();const s={...this.colorItem,blockId:it(e),blockKind:Io(t,e),blockType:Dt(e),groupIndex:500,order:350};return r.push(s),r}executeCommand(t,e,o,r,i,s){if(!tt(t,e))return!1;let l=i.value;l===void 0&&(l=!r.value);const a=Cr.fromTextCommandId(r.id);if(a.startsWith("style-")){if(a==="style-font")return this.handleChangeColor(i.type,l),!0;if(ut(t,e)===0)return this.executeCommandOnEmptyText(e,r,{value:l})}return gz(t,e,o,a,{value:l},s)}executeCommandOnEmptyText(t,e,o){let r=this.emptyTextBlockAttributes.get(it(t));r||(r={},this.emptyTextBlockAttributes.set(it(t),r));const i=Cr.fromTextCommandId(e.id),s=o.value;return s==null||s===!1?(delete r[i],!0):(r[i]=o.value,!0)}getCommandsOnEmptyText(t,e){const o=fz(t,e);return this.setCommandsStates(o,e)}setCommandsStates(t,e){var i;const o=it(e),r=(i=this.emptyTextBlockAttributes.get(o))!=null?i:{};return t.map(s=>{const l=r[s.id],a=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:a}})}getEmptyBlockTextAttributes(t,e){var r;const o=mt.default((r=this.emptyTextBlockAttributes.get(e))!=null?r:{});if(Array.from(Object.entries(o)).forEach(([i,s])=>{s||delete o[i]}),Object.keys(o).length!==0)return o}static toTextCommand(t){return t.children&&(t.children=t.children.map(Cr.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return g(pz,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(Cr.toTextCommand)}static fromTextCommands(t){return t.map(Cr.fromTextCommand)}}function l8(n){const t=n.getCustom("toolbar-handler");t.disableTextToolbar(),t.hide(),setTimeout(()=>{t.enableTextToolbar()},300)}function Cz(n){n.undoManager.canUndo()&&l8(n)}function Az(n){n.undoManager.canRedo()&&l8(n)}const bz={"CtrlOrCmd+Z":Cz,"CtrlOrCmd+Shift+Z":Az},vz={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"}},yz={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},kz={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"}};R.mergeLang({"zh-CN":vz,"en-US":yz,"ja-JP":kz});var c8=(n=>(n.Card="card",n.Preview="preview",n))(c8||{});const wz=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
|
|
510
510
|
<g clip-path="url(#clip0)">
|
|
511
511
|
<path d="M6.01 10.4886C5.85 10.4886 5.7 10.4286 5.58 10.3086L3.98 8.71859C3.35 8.07859 3 7.23859 3 6.34859C3 5.45859 3.35 4.60859 3.98 3.97859C5.29 2.66859 7.41 2.66859 8.72 3.97859L10.31 5.56859C10.55 5.80859 10.55 6.18859 10.31 6.42859C10.07 6.66859 9.69 6.66859 9.45 6.42859L7.86 4.83859C7.03 4.00859 5.68 4.00859 4.85 4.83859C4.45 5.23859 4.23 5.77859 4.23 6.34859C4.23 6.91859 4.45 7.44859 4.85 7.85859L6.44 9.44859C6.68 9.68859 6.68 10.0686 6.44 10.3086C6.32 10.4286 6.16 10.4886 6.01 10.4886ZM11.65 14.9986C10.79 14.9986 9.93 14.6686 9.28 14.0186L7.4 12.1386C7.16 11.8986 7.16 11.5186 7.4 11.2786C7.64 11.0386 8.02 11.0386 8.26 11.2786L10.14 13.1586C10.97 13.9886 12.32 13.9886 13.15 13.1586C13.55 12.7586 13.77 12.2186 13.77 11.6486C13.77 11.0786 13.55 10.5486 13.15 10.1386L11.28 8.25859C11.04 8.01859 11.04 7.63859 11.28 7.39859C11.52 7.15859 11.9 7.15859 12.14 7.39859L14.02 9.27859C14.65 9.90859 15 10.7486 15 11.6486C15 12.5386 14.65 13.3886 14.02 14.0186C13.37 14.6686 12.51 14.9986 11.65 14.9986Z" fill="#5587F0"/>
|
|
512
512
|
<path d="M10.88 10.8604C10.67 11.0704 10.32 11.0704 10.1 10.8604L7.64004 8.40039C7.43004 8.19039 7.43004 7.84039 7.64004 7.62039C7.85004 7.41039 8.20004 7.41039 8.42004 7.62039L10.88 10.0804C11.1 10.3004 11.1 10.6404 10.88 10.8604Z" fill="#5587F0"/>
|
|
@@ -521,18 +521,18 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
521
521
|
<path d="M4.015 5.4597L8.00002 9.44472L11.9835 5.4597" stroke="#606060"/>
|
|
522
522
|
<path d="M7.99994 9.44471L8 0" stroke="#606060"/>
|
|
523
523
|
</svg>
|
|
524
|
-
`,
|
|
524
|
+
`,a8=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
525
525
|
<rect x="0.5" y="5.5" width="5" height="5" rx="1" stroke="currentColor"/>
|
|
526
526
|
<path d="M0 2.5L16 2.5" stroke="currentColor"/>
|
|
527
527
|
<path d="M0 13.5L16 13.5" stroke="currentColor"/>
|
|
528
528
|
<path d="M8 8L16 8" stroke="currentColor"/>
|
|
529
529
|
</svg>
|
|
530
|
-
`,
|
|
530
|
+
`,u8=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
531
531
|
<rect x="0.5" y="5.5" width="15" height="5" rx="1" stroke="currentColor"/>
|
|
532
532
|
<path d="M0 2.5L16 2.5" stroke="currentColor"/>
|
|
533
533
|
<path d="M0 13.5L16 13.5" stroke="currentColor"/>
|
|
534
534
|
</svg>
|
|
535
|
-
`,Wnt="";S("file-box");function
|
|
535
|
+
`,Wnt="";S("file-box");function d8(n,t){const e=n.getBoxData(t),o=n.doc.buildResourceUrl(e.src,{downloadFileName:e.fileName});qd(o,e.fileName)}class Bz{constructor(t){m(this,"group","file-box-commands");m(this,"_commands",[{id:"download",name:"Download",icon:x2},{id:"sep",name:"",type:"separator"},{id:"to-link",name:"To link",icon:a8,states:["checked"]},{id:"to-card",name:"To card",icon:u8}]);this.editor=t}get commands(){return this.editor.readonly?this._commands.filter(t=>t.id!=="to-link"&&t.id!=="to-card"):this._commands}executeCommand(t,e,o,r){if(r.id==="to-card"){const i=nt(e),s=at(i),l=bt(e)+1,a=t.getBoxData(o),d=Mi(e,o);t.undoManager.runInGroup(()=>{const h={src:a.src,previewType:c8.Card,fileName:a.fileName,fileSize:a.fileSize,fileType:a.fileType};d.start===0?ut(t,e)===1?(t.deleteBlock(e),t.insertEmbed(s,l-1,"office",h)):(t.deleteTextFromBlock(e,d.start,1),t.insertEmbed(s,l-1,"office",h)):d.start===ut(t,e)-1?(t.deleteTextFromBlock(e,d.start,1),t.insertEmbed(s,l,"office",h)):(t.deleteTextFromBlock(e,d.start,1),Yl(t,e,d.start,{forceInsertAfter:!0}),t.insertEmbed(s,l,"office",h))})}else r.id==="download"&&d8(t,o)}}function Ez(n,t,e,o){const r=o,i=w("a",["file-container"],e),s=w("span",["file-icon"],i);s.innerHTML=wz,w("span",["file-name"],i,r.fileName),i.setAttribute("data-file-id",r.id),i.setAttribute("data-file-src",r.src)}function xz(n,t,e){const o=n.options.componentsOptions.file;if(o!=null&&o.onClick){o.onClick(n,t,e);return}d8(n,t)}function Iz(n,t){return{boxCommands:{"hovering-toolbar":new Bz(n)},abstract:R.t("file.abstract")}}function Tz(n,t,e,o){const r=t;return o==="html"?r.src?`<a href="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" >${r.fileName}</a>`:`[${r.fileName}]`:o==="markdown"?r.src?`})`:`[${r.fileName}]`:r.fileName}async function Dz(n,t){const e=t,{fileName:o,src:r}=e,{onGetFileDownloadUrl:i}=n.getComponentOptions("file")||{},s=i?await i(n,e):void 0;return[{insert:o,attributes:{link:s||r}}]}const h8={boxType:"file",updateBoxContent:Ez,handleClickBox:xz,getBoxProperties:Iz,convertTo:Tz,toStandardText:Dz},Sz={embedProperties:{edit:"\u7F16\u8F91",addComment:"\u6DFB\u52A0\u6279\u6CE8"}},Lz={embedProperties:{edit:"Edit",addComment:"Add annotation"}},Mz={embedProperties:{edit:"\u7DE8\u96C6",addComment:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0"}};R.mergeLang({"zh-CN":Sz,"en-US":Lz,"ja-JP":Mz});const f8=S("embed-block-properties");function Kf(n,t){var e;for(const o of n.blockHooks){const r=(e=o.commands)==null?void 0:e.call(o,n,t);if(!!r&&r.group==="block-comment-actions")return r.executeCommand(n,t,r.commands[0]),!0}return!1}class I2{constructor(t,e,o){m(this,"group","hovering-toolbar");m(this,"_commands",[{id:"edit",name:R.t("embedProperties.edit"),icon:Mp},{id:"add-comment",name:R.t("embedProperties.addComment"),icon:eu}]);this.editor=t,this.block=e,this.properties=o}get commands(){var r,i,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"])});const o=(r=this.properties)!=null&&r.presetIds?t.filter(l=>{var a,d;return(d=(a=this.properties)==null?void 0:a.presetIds)==null?void 0:d.includes(l.id)}):[...t];return(s=(i=this.properties)==null?void 0:i.extCommands)!=null&&s.length&&(o.push({id:K(),type:"separator",name:""}),o.push(...this.properties.extCommands)),o}executeCommand(t,e,o){var r,i;if(!((i=(r=this.properties)==null?void 0:r.handleExecuteCommand)!=null&&i.call(r,t,e,o))){if(o.id==="add-comment"){Kf(t,e)||f8.error("failed to add comment to block");return}f8.error(`unknown command: ${JSON.stringify(o)}`)}}}function T2(n,t,e){return{blockCommands:{"hovering-toolbar":new I2(n,t,e)}}}class Fu{constructor(t){m(this,"blockResizer");m(this,"handleResizing",(t,e)=>{var r,i;const o=t.getBlock();if(o){if(((i=(r=Qt(this.editor,o)).notify)==null?void 0:i.call(r,this.editor,"resize",{block:o,rect:e}))===!0)return;const s=Math.max(e.height,100),d={...this.editor.getBlockData(o).embedData,height:s};this.editor.updateEmbedData(o,d)}});m(this,"handleHoveringBlockChange",(t,e)=>{e&&Le(e)&&xt(e,"resizable")&&this.disableResizer(),t&&Le(t)&&xt(t,"resizable")&&this.editor.isBlockWritable(t)&&this.tryEnableResizer(t)});this.editor=t,pe.get(t).addListener("change",this.handleHoveringBlockChange),this.blockResizer=new wu(this.editor,{resize:["bottom"]}),this.blockResizer.addListener("resizing",this.handleResizing)}destroy(){pe.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 Fu(t))}static register(t,e){return W(e,"resizable"),t.addCustom("EmbedBlockResizer",()=>new Fu(t))}}const Rz=`<svg width="48" height="48" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
536
536
|
<path d="M12 1C13.5 2.5 14 3 16 5V15.6087C16 15.7914 15.9638 15.9723 15.8934 16.1411C15.8231 16.3099 15.7199 16.4633 15.5899 16.5925C15.4599 16.7217 15.3056 16.8242 15.1358 16.8941C14.9659 16.964 14.7838 17 14.6 17H3.4C3.21615 17 3.0341 16.964 2.86424 16.8941C2.69439 16.8242 2.54005 16.7217 2.41005 16.5925C2.28005 16.4633 2.17693 16.3099 2.10657 16.1411C2.03621 15.9723 2 15.7914 2 15.6087V2.3913C2 2.2086 2.03621 2.02768 2.10657 1.85888C2.17693 1.69007 2.28005 1.5367 2.41005 1.4075C2.54005 1.27831 2.69439 1.17583 2.86424 1.10591C3.0341 1.03599 3.21615 1 3.4 1H12Z" fill="#FFBE5A"/>
|
|
537
537
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 7.5V11.1H8.7C9.69411 11.1 10.5 10.2941 10.5 9.3C10.5 8.30589 9.69411 7.5 8.7 7.5H7.5ZM7 6C6.44772 6 6 6.44771 6 7V11.6C6 12.1523 6.44772 12.6 7 12.6H8.7C10.5225 12.6 12 11.1225 12 9.3C12 7.47746 10.5225 6 8.7 6H7Z" fill="white"/>
|
|
538
538
|
<path d="M12 1L14 3L16 5H13.3333C12.9797 5 12.6406 4.84675 12.3905 4.57397C12.1405 4.30119 12 3.93122 12 3.54546V1Z" fill="#FFD89C"/>
|
|
@@ -554,7 +554,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
554
554
|
<path d="M12 1L14 3L16 5H13.3333C12.9797 5 12.6406 4.84675 12.3905 4.57397C12.1405 4.30119 12 3.93122 12 3.54546V1Z" fill="#99B7F6"/>
|
|
555
555
|
<rect x="10.2002" y="6.59961" width="0.9" height="4.8" rx="0.45" transform="rotate(90 10.2002 6.59961)" fill="white"/>
|
|
556
556
|
<rect x="12.6001" y="10.8008" width="0.899998" height="7.2" rx="0.449999" transform="rotate(90 12.6001 10.8008)" fill="white"/>
|
|
557
|
-
</svg>`,
|
|
557
|
+
</svg>`,m8=`<svg width="48" height="48" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
558
558
|
<path d="M12 1C13.5 2.5 14 3 16 5V15.6087C16 15.7914 15.9638 15.9723 15.8934 16.1411C15.8231 16.3099 15.7199 16.4633 15.5899 16.5925C15.4599 16.7217 15.3056 16.8242 15.1358 16.8941C14.9659 16.964 14.7838 17 14.6 17H3.4C3.21615 17 3.0341 16.964 2.86424 16.8941C2.69439 16.8242 2.54005 16.7217 2.41005 16.5925C2.28005 16.4633 2.17693 16.3099 2.10657 16.1411C2.03621 15.9723 2 15.7914 2 15.6087V2.3913C2 2.2086 2.03621 2.02768 2.10657 1.85888C2.17693 1.69007 2.28005 1.5367 2.41005 1.4075C2.54005 1.27831 2.69439 1.17583 2.86424 1.10591C3.0341 1.03599 3.21615 1 3.4 1H12Z" fill="#F0DC5A"/>
|
|
559
559
|
<path d="M12 1L14 3L16 5H13.3333C12.9797 5 12.6406 4.84675 12.3905 4.57397C12.1405 4.30119 12 3.93122 12 3.54546V1Z" fill="#F8EEAD"/>
|
|
560
560
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.1998 3H5.9998V3.9H4.7998V4.8H5.9998V5.69999H7.1998V4.79999H5.9998V3.9H7.1998V3ZM5.9998 5.70001H4.7998V6.60001H5.9998V7.5H4.7998V8.4H5.9998V9.3L4.7998 9.29999V11.8C4.7998 12.0761 5.02366 12.3 5.2998 12.3H6.6998C6.97595 12.3 7.1998 12.0761 7.1998 11.8V9.3V8.4L5.9998 8.4V7.5L7.1998 7.5V6.6H5.9998V5.70001ZM5.3998 11.4V10.8H6.5998V11.4H5.3998Z" fill="white"/>
|
|
@@ -585,17 +585,17 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
585
585
|
<rect width="6" height="7" fill="white" transform="translate(6 6)"/>
|
|
586
586
|
</clipPath>
|
|
587
587
|
</defs>
|
|
588
|
-
</svg>`,
|
|
588
|
+
</svg>`,g8={dwg:[],rvt:[],skp:[],img:["image/png","image/jpg","image/jpeg","image/bmp","image/ico","image/icon","image/gif"],txt:["text/plain"],zip:["application/zip","application/x-rar-compressed","application/x-7z-compressed","application/x-tar","application/x-bzip2","application/java-archive"],ppt:["application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"],excel:["application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],word:["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"]},D2={dwg:Rz,rvt:Oz,skp:_z,img:Fz,txt:Pz,zip:m8,rar:m8,ppt:Nz,excel:$z,pdf:Hz,word:jz};function p8(n,t){const e=Object.keys(g8);for(let r=0;r<e.length;r+=1){const i=e[r];if(g8[i].includes(t))return D2[i]}const o=Aa(n.toLowerCase());return D2[o]?D2[o]:Uz}async function zz(n,t,e){var D;const{fileName:o,fileType:r,fileSize:i}=e,s=w("div",["card-root"],t),l=w("div",["file-icon"],s),{renderFileCardIcon:a}=((D=n.options.componentsOptions)==null?void 0:D.file)||{};if(!a)l.innerHTML=p8(o,r);else{const T=a&&await a(n,e);T?l.append(T):l.innerHTML=p8(o,r)}const d=w("div",["file-details"],s),h=Aa(o),p=o.length-h.length-3,A=w("div",["file-name"],d);p>0?(w("span",["file-name-pre"],A,o.slice(0,p)),w("span",[],A,o.slice(p))):A.textContent=o,w("div",["file-size"],d,LC(i));const v=w("div",["file-actions"],s),B=w("button",["download"],v);return B.innerHTML=x2,{card:s,downloadButton:B}}const qnt="";function C8(n,t){const o=n.getBlockData(t).embedData,r=n.options.componentsOptions.file;if(r!=null&&r.onDownloadFile){r.onDownloadFile(n,o);return}const i=n.doc.buildResourceUrl(o.src,{downloadFileName:o.fileName});qd(i,o.fileName)}async function Vz(n,t,e){const{embedData:o}=e,r=o,{card:i,downloadButton:s}=await zz(n,t,r);n.domEvents.addEventListener(s,"click",(l,a)=>{if(!a.target)return;const d=ot(a.target);!d||C8(l,d)}),n.domEvents.addEventListener(i,"click",(l,a)=>{if(!a.target)return;const d=ot(a.target);if(!d||jl(a,"button"))return;const h=l.options.componentsOptions.file;if(h!=null&&h.onClick){h.onClick(l,d,a);return}const A=l.getBlockData(d).embedData,v=l.doc.buildResourceUrl(A.src,{downloadFileName:A.fileName});qd(v,A.fileName)})}class Wz{constructor(t){m(this,"group","hovering-toolbar");m(this,"_commands",[{id:"download",name:R.t("file.commands.download"),icon:x2},{id:"add-comment",name:R.t("file.commands.comment"),icon:eu},{id:"sep",name:"",type:"separator"},{id:"to-link",name:R.t("file.commands.toLink"),icon:a8},{id:"to-card",name:R.t("file.commands.toCard"),icon:u8,states:["checked"]}]);this.editor=t}get commands(){return this.editor.readonly?[]:this._commands}executeCommand(t,e,o){if(o.id==="to-link"){const r=nt(e),i=at(r),s=bt(e),l=t.getBlockData(e),{embedData:a}=l,d=a,h={id:K(),box:!0,type:"file",created:Date.now(),src:d.src,fileName:d.fileName,fileSize:d.fileSize,fileType:d.fileType};t.undoManager.runInGroup(()=>{t.deleteBlock(e);const p=[Q4(h)];t.insertTextBlock(p,i,s)})}else o.id==="download"?C8(t,e):o.id==="add-comment"&&Kf(t,e)}}function qz(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o;return{blockCommands:{"hovering-toolbar":new Wz(n)},abstract:r.fileName}}function Gz(n,t,e,o){const{embedData:r}=t,i=r;return o==="html"?i.src?`<p><a href="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" >${i.fileName}</a></p>`:`<p>[${i.fileName}]</p>`:o==="markdown"?i.src?`[${i.fileName}](${n.doc.buildResourceUrl(i.src,{withToken:!0})})
|
|
589
589
|
`:`[${i.fileName}]
|
|
590
590
|
`:i.src?`[${i.fileName}](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:`[${i.fileName}]`}async function Zz(n,t,e,o){const{onGetFileDownloadUrl:r}=n.getComponentOptions("file")||{},i=t.embedData,s=r?await r(n,i):void 0;return{blocks:{root:[{type:"embed",id:K(),embedType:"webpage",embedData:{src:s||i.src,title:i.fileName}}]},meta:{},comments:{}}}const Qz={embedType:"office",createEmbedContent:Vz,getBlockProperties:qz,convertTo:Gz,toStandardDoc:Zz},Yz={file:{abstract:"\u9644\u4EF6",commands:{download:"\u4E0B\u8F7D",toLink:"\u8F6C\u4E3A\u6807\u9898",toCard:"\u8F6C\u4E3A\u5361\u7247",comment:"\u6279\u6CE8"}}},Jz={file:{abstract:"Attachment",commands:{download:"Download",toLink:"To Link",toCard:"To Card",comment:"Annotation"}}},Kz={file:{abstract:"\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB",commands:{download:"\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9",toLink:"\u30BF\u30A4\u30C8\u30EB\u306B\u5909\u63DB",toCard:"\u30AB\u30FC\u30C9\u306B\u5909\u63DB",comment:"\u30B3\u30E1\u30F3\u30C8"}}};R.mergeLang({"zh-CN":Yz,"en-US":Jz,"ja-JP":Kz});function Xz(n){const t=/(\s|^)(http|https):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?$/;return t.test(n)?n.search(t):-1}function tV(n){const t=n.selection.range;if(!t.isCollapsed()||!t.isSimple())return;const{start:e}=t,o=n.getBlockById(e.blockId);if(!tt(n,o))return;const r=n.getBlockText(o),s=pg(r).slice(0,e.offset),l=Xz(s);if(l===-1)return;const a=s.slice(l),d=s.length;let h=Ia(l,d-l,r,"link",a);return h=Hr(h,d," ",null),n.setBlockText(o,h),n.selection.selectBlock(o,d+1),!0}const eV={Space:tV},Gnt="",nV={version:{latest:"\u6700\u65B0\u7248\u672C",insert:"{name} \u6DFB\u52A0",delete:"{name} \u5220\u9664",goBack:"\u8FD4\u56DE",revertVersion:"\u8FD8\u539F\u5185\u5BB9",play:"\u64AD\u653E\u5386\u53F2\u64CD\u4F5C",versionList:"\u5386\u53F2\u7248\u672C ({count})",unknown:"\u672A\u77E5\u7248\u672C",restoreFrom:"\u56DE\u6EDA\u81EA\u7248\u672C\u300C{from}\u300D",restoreInfo:"\u56DE\u6EDA\u7684\u7248\u672C\u6682\u4E0D\u652F\u6301\u4E0E\u4E0A\u4E00\u7248\u672C\u5BF9\u6BD4",versionInfoLeft:'<span class="text-1">\u5F53\u524D\u7248\u672C: </span><span class="name">{versionName}</span><span class="text-2"> \u4E0E</span>',versionInfoRight:'<span class="text-3">\u5BF9\u6BD4</span>',noSelectedVersion:"\u672A\u9009\u62E9\u7248\u672C",noMemoedVersion:"\u6682\u65E0\u5DF2\u5907\u6CE8\u7684\u5386\u53F2\u7248\u672C",noFilterVersion:"\u6682\u65E0\u5339\u914D\u7ED3\u679C",memo:"\u5907\u6CE8",revert:"\u56DE\u6EDA",filter:{all:"\u5168\u90E8",memoed:"\u5DF2\u5907\u6CE8",allVersions:"\u5168\u90E8\u5386\u53F2\u7248\u672C",memoVersions:"\u5DF2\u5907\u6CE8\u7684\u5386\u53F2\u7248\u672C"},textarea:{placeholder:"\u8BF7\u8F93\u5165\u7248\u672C\u5907\u6CE8"},tooltip:{help:`1. \u56DE\u6EDA\u7248\u672C\u4E0D\u652F\u6301\u4E0E\u56DE\u6EDA\u524D\u7248\u672C\u8FDB\u884C\u5BF9\u6BD4\uFF1B
|
|
591
591
|
2. \u82E5\u4E24\u4E2A\u7248\u672C\u4E4B\u95F4\u5B58\u5728\u56DE\u6EDA\u7248\u672C\uFF0C\u5219\u4E0D\u652F\u6301\u5BF9\u6BD4\u3002`,user:"\u7248\u672C\u53D1\u5E03\u8005\uFF1A{name}",auth:"\u6682\u65E0\u9875\u9762\u7F16\u8F91\u6743\u9650\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"},dropdownHeader:"\u4EC5\u5C55\u793A\u53EF\u4E0E\u5F53\u524D\u7248\u672C\u8FDB\u884C\u5BF9\u6BD4\u7684\u5386\u53F2\u7248\u672C",dropdown:{header:"\u6240\u6709\u53EF\u5BF9\u6BD4\u7684\u7248\u672C"},noVersions:"\u6682\u65E0\u53EF\u5BF9\u6BD4\u7684\u7248\u672C",lastVersion:"\u4E0A\u4E00\u7248\u672C",filterMemoed:"\u7B5B\u9009\u5DF2\u5907\u6CE8\u7684\u7248\u672C"}},oV={version:{latest:"Latest",insert:"Added by {name}",delete:"Deleted by {name}",goBack:"Back",revertVersion:"Revert",play:"Play",versionList:"Historical versions ({count})",unknown:"Unknown version",restoreFrom:"Rolled back from version {from}",restoreInfo:"The rolled back version does not currently support comparison with the previous version.",versionInfoLeft:'<span class="text-1">Current version: </span><span class="name">{versionName}</span><span class="text-2"> Compare with</span>',versionInfoRight:'<span class="text-3"></span>',noSelectedVersion:"Not selected",noMemoedVersion:"No historical commented versions",noFilterVersion:"No result",memo:"Comment",revert:"Roll back",filter:{all:"All",memoed:"Commented",allVersions:"All historical versions",memoVersions:"Historical versions with comments"},textarea:{placeholder:"Enter comment"},tooltip:{help:`1. A rolled back version can't be compared with versions before it.
|
|
592
592
|
2. Versions can't be compared if there are rolled back versions between them.`,user:"Released by {name}",auth:"No edit permission for this page. Contact the admin."},dropdownHeader:"The list below only contains historical versions that can be compared with the current version",dropdown:{header:"All historical versions that can be compared"},noVersions:"No comparable versions available",lastVersion:"Previous version",filterMemoed:"Filter versions with comments"}},rV={version:{latest:"\u6700\u65B0",insert:"{name}\u304C\u8FFD\u52A0\u3057\u307E\u3057\u305F",delete:"{name}\u304C\u524A\u9664\u3057\u307E\u3057\u305F",goBack:"\u623B\u308B",revertVersion:"\u5185\u5BB9\u3092\u5FA9\u5143",play:"\u5C65\u6B74\u3092\u518D\u751F",versionList:"\u30D0\u30FC\u30B8\u30E7\u30F3\u5C65\u6B74 {count}",unknown:"\u672A\u77E5\u306E\u30D0\u30FC\u30B8\u30E7\u30F3",restoreFrom:"\u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\uFF1A{from}",restoreInfo:"\u5C65\u6B74\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u4EE5\u524D\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u307E\u305B\u3093\u3002",versionInfoLeft:'<span class="text-1">\u73FE\u5728\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\uFF1A</span><span class="name">{versionName}</span><span class="text-2"> \u3068</span>',versionInfoRight:'<span class="text-3">\u3092\u6BD4\u8F03\u3059\u308B</span>',noSelectedVersion:"\u672A\u9078\u629E",noMemoedVersion:"\u5099\u8003\u306E\u3042\u308B\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u3042\u308A\u307E\u305B\u3093",noFilterVersion:"\u4E00\u81F4\u3057\u305F\u7D50\u679C\u306F\u3042\u308A\u307E\u305B\u3093",memo:"\u5099\u8003",revert:"\u5FA9\u5143",filter:{all:"\u3059\u3079\u3066",memoed:"\u5099\u8003\u3042\u308A",allVersions:"\u3059\u3079\u3066",memoVersions:"\u5099\u8003\u3042\u308A"},textarea:{placeholder:"\u8AAC\u660E\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},tooltip:{help:`1. \u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u305D\u308C\u4EE5\u524D\u306E\u53E4\u3044\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u307E\u305B\u3093\u3002
|
|
593
|
-
2. \u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306E\u9593\u306B\u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\u304C\u3042\u308B\u5834\u5408\u3001\u3053\u306E\u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u6BD4\u8F03\u3067\u304D\u306A\u3044\u3053\u3068\u306B\u306A\u308A\u307E\u3059\u3002`,user:"\u30D0\u30FC\u30B8\u30E7\u30F3\u4F5C\u6210\u8005\uFF1A{name}",auth:"\u3053\u306E\u30B9\u30DA\u30FC\u30B9\u3092\u7DE8\u96C6\u3059\u308B\u6A29\u9650\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7BA1\u7406\u8005\u306B\u3054\u9023\u7D61\u304F\u3060\u3055\u3044\u3002"},dropdownHeader:"\u73FE\u5728\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u308B\u30D0\u30FC\u30B8\u30E7\u30F3\u3060\u3051\u8868\u793A\u3055\u308C\u307E\u3059",dropdown:{header:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3"},noVersions:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u3042\u308A\u307E\u305B\u3093",lastVersion:"\u524D\u306E\u30D0\u30FC\u30B8\u30E7\u30F3",filterMemoed:"\u5099\u8003\u3042\u308A"}};R.mergeLang({"zh-CN":nV,"en-US":oV,"ja-JP":rV});var Ay=(n=>(n.NEW="history-new",n.NEW_CHILD="history-new-child",n.DELETED="history-deleted",n.UPDATED="history-updated",n.HISTORY="history",n))(Ay||{});const Tc="--op-color",Dc="--op-selected-color",Znt="";class iV{constructor(t){m(this,"root");this.content=t;const e=w("div",["editor-dialog-root"],null);e.append(t),this.root=e}show(t=document.body){t.append(this.root)}hide(){this.root.remove()}destroy(){}}function Xs(n){var e;let t;if(n.version!==-1){const o=new Date((e=n.created)!=null?e:n.version);t=_m(o,"YYYY-MM-DD hh:mm")}else t=R.t("version.latest");return t}function Xf(n){return n.source&&typeof n.source=="object"&&!!n.source.restore}const Qnt="";class sV{constructor(t,e){m(this,"textArea");m(this,"warning");m(this,"end",!1);m(this,"root");m(this,"handleBlur",()=>{var t,e;this.end||(e=(t=this.options)==null?void 0:t.onend)==null||e.call(t,this.textArea.value,!1)});m(this,"handleKeyDown",t=>{var e,o,r,i;t.isComposing||(t.key==="Enter"||t.key==="Tab"?(t.preventDefault(),(o=(e=this.options)==null?void 0:e.onend)==null||o.call(e,this.textArea.value,!1),this.end=!0):t.key==="Escape"&&(t.preventDefault(),(i=(r=this.options)==null?void 0:r.onend)==null||i.call(r,this.textArea.value,!0),this.end=!0))});m(this,"handleInput",t=>{const e=t.target,{value:o}=e;o.length>this.maxLength-10?this.warning.innerText=`${o.length}/${this.maxLength}`:this.warning.innerText="",this.autoSize()});var o,r;this.maxLength=t,this.options=e,this.root=w("div",["size-limit-textarea",...(o=e==null?void 0:e.classes)!=null?o:[]],null),this.textArea=w("textarea",["size-limit-textarea-input"],this.root),this.warning=w("div",["size-limit-textarea-warning"],this.root),this.textArea.addEventListener("input",this.handleInput),this.textArea.addEventListener("blur",this.handleBlur),this.textArea.addEventListener("keydown",this.handleKeyDown),this.textArea.maxLength=t,this.textArea.placeholder=(r=e==null?void 0:e.placeholder)!=null?r:""}destroy(){this.textArea.removeEventListener("input",this.handleInput),this.textArea.removeEventListener("blur",this.handleBlur),this.textArea.removeEventListener("keydown",this.handleKeyDown)}setValue(t){this.textArea.value=t,this.autoSize()}autoSize(){const t=Math.max(this.textArea.scrollHeight,60);this.textArea.style.height="auto",this.textArea.style.height=`${t}px`}resetSize(){this.textArea.style.height="auto";const t=Math.max(this.textArea.scrollHeight,60);this.textArea.style.height=`${t}px`}focus(){this.textArea.focus(),this.end=!1}}const Ynt="",{t:Qn}=R,by=S("version-list");class lV{constructor(t){m(this,"versionsList");m(this,"versionsListHeader");m(this,"versionFilterToolbar");m(this,"memoInput",null);m(this,"selectedVersion",0);m(this,"handleClickVersionItem",t=>{const e=t.target,o=e.closest(".version-item");if(!this.isVersionElement(o))return;const r=xt(o,"active");if(r&&e.closest(".version-item-memo")&&this.options.enableEdit){this.editItemMemo(o);return}const i=this.getVersionFromElement(o);if(this.setActiveItem(o),e.closest(".add-memo-button")&&this.options.enableEdit){this.handleAddMemo(i,o);return}if(e.closest(".revert-button")&&this.options.enableEdit){this.handleRevert(i,o);return}if(r)return;const{onSelectVersion:s}=this.options;s(i)});m(this,"handleEndEditItemMemo",(t,e)=>{var r,i;const o=(r=this.memoInput)==null?void 0:r.root.closest(".version-item");if(this.isVersionElement(o)&&(et(o,"editing"),!e)){const s=this.getVersionFromElement(o),l=t.replace(/[\n\r]+/g," ");if(((i=s.extra)==null?void 0:i.memo)!==l){s.extra={memo:l},this.options.versionHelper.updateVersionExtra(s.version,s.tagId,s.extra).then(()=>{var d,h;(h=(d=this.options).onMemoChanged)==null||h.call(d,s)});const a=o.querySelector(".version-item-memo");g(by,a,"no memo element"),a.textContent=l}}setTimeout(()=>{var s;(s=this.memoInput)==null||s.root.remove()})});m(this,"handleRevert",(t,e)=>{const{onRevert:o}=this.options;o(t)});m(this,"handleFilterClick",(t,e)=>{let o=this.options.versions;e.id==="memoed"&&(o=o.filter(i=>{var s;return!!((s=i.extra)!=null&&s.memo)}));const r=this.createVersionItems(o,e.id);this.versionsList.innerHTML="",this.versionsList.append(r),this.versionFilterToolbar.updateItems(this.getFilterItems(e.id)),this.updateHeaderCount(o.length)});var d,h;this.options=t;const{versions:e}=t,o=w("div",["version-list-header"],null),r=Qn("version.versionList",{count:`${e.length}`});w("span",["version-count"],o,r);const i=w("div",["version-list-filter"],o);this.versionFilterToolbar=new rM(i,this.getFilterItems("all"),{tooltipId:"version-viewer"}),this.versionFilterToolbar.addListener("click",this.handleFilterClick),this.selectedVersion=t.selectedVersion||((d=e[0])==null?void 0:d.version)||-1;const s=w("div",["version-list-content"],null),l=this.createVersionItems(e,"all");s.append(l),this.versionsList=s,this.versionsListHeader=o,s.onclick=this.handleClickVersionItem;const a=this.activeVersion;a&&((h=this.options)==null||h.onSelectVersion(a))}getFilterItems(t){return[{id:"filter",name:Qn(t==="all"?"version.filter.all":"version.filter.memoed"),dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",children:[{id:"all",states:t==="all"?["checked"]:[],name:Qn("version.filter.allVersions")},{id:"memoed",states:t==="memoed"?["checked"]:[],name:Qn("version.filter.memoVersions")}]}]}createVersionItems(t,e){const o=document.createDocumentFragment();if(t.length===0){const i=w("div",["version-list-empty"],o);return i.textContent=Qn("version.noMemoedVersion"),o}const r=(i,s,l,a=!1)=>{var T,_;const d=w("div",["version-item"],o);d.versionData=i,s&&W(d,"child"),i.version===this.selectedVersion&&W(d,"active");const h=w("div",["version-item-title"],d);w("div",["version-item-date"],h,Xs(i)),a&&w("div",["version-item-latest"],h,Qn("version.latest")),w("div",["spacer"],h);const p=w("div",["version-actions"],h),A=w("button",["add-memo-button"],p);if(A.textContent=Qn("version.memo"),this.options.enableEdit||(W(A,"disabled"),A.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth"))),!a){const M=w("button",["revert-button"],p);M.textContent=Qn("version.revert"),this.options.enableEdit||(W(M,"disabled"),M.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth")))}let v="";if(typeof i.source=="object"&&((T=i.source)==null?void 0:T.restore)){const M=i.source.restore,H=l.find(q=>q.version==M),z=H?Xs(H):Qn("version.unknown");v=Qn("version.restoreFrom",{from:z})}w("div",["version-item-restore-from"],d,v),w("div",["version-item-memo"],d,((_=i.extra)==null?void 0:_.memo)||"");const B=w("ul",["version-item-authors"],d),D=M=>{const H=w("li",["version-item-author"],B),z=w("span",["version-item-author-mark"],H);z.style.background=this.options.getMarkColor(M),w("span",["version-item-author-name"],H,M.displayName).setAttribute("data-editor-tooltip-common",R.t("version.tooltip.user",{name:M.displayName}))};if(this.options.useCreatedBy)if(i.createdBy){const M=i.createdBy;D(M)}else i.authors&&i.authors.length>0&&i.authors.forEach(M=>{D(M)});else if(i.authors&&i.authors.length>0)i.authors.forEach(M=>{D(M)});else if(i.createdBy){const M=i.createdBy;D(M)}};return t.forEach((i,s)=>{r(i,!1,t,s===0),i.minorVersions&&i.minorVersions.length>0&&i.minorVersions.forEach(l=>{r(l,!0,t,!1)})}),o}isVersionElement(t){return t?xt(t,"version-item"):!1}getVersionFromElement(t){return t.versionData}get activeVersion(){return this.options.versions.find(t=>t.version===this.selectedVersion)}setActiveItem(t){if(xt(t,"active"))return;const e=this.versionsList.querySelector(".version-item.active");e&&et(e,"active"),W(t,"active"),this.selectedVersion=this.getVersionFromElement(t).version}handleAddMemo(t,e){this.editItemMemo(e)}editItemMemo(t){var o;this.memoInput||(this.memoInput=new sV(256,{onend:this.handleEndEditItemMemo,classes:["memo-input"],placeholder:Qn("version.textarea.placeholder")}));const e=t.querySelector(".version-item-restore-from");g(by,e,"no title element"),e.insertAdjacentElement("afterend",this.memoInput.root),W(t,"editing"),this.memoInput.setValue(((o=t.versionData.extra)==null?void 0:o.memo)||""),this.memoInput.resetSize(),this.memoInput.focus()}updateHeaderCount(t){const e=this.versionsListHeader.querySelector(".version-count");e&&(e.textContent=Qn("version.versionList",{count:`${t.toString()}`}))}getVersionItemByVersionNum(t){const e=Array.from(this.versionsList.children).find(o=>o.versionData.version===t);return this.isVersionElement(e)?e:null}selectVersionByVersionNum(t){const e=this.getVersionItemByVersionNum(t);return e?(this.setActiveItem(e),this.getVersionFromElement(e)):null}render(t){t.innerHTML="",t.append(this.versionsListHeader,this.versionsList)}destroy(){this.versionsList.onclick=null,this.versionFilterToolbar.destroy()}}class cV{constructor(t,e){this.doc=t,this.user=e}onDeleteBlock(t,e){this.doc.onDeleteBlock(t,e,this.user)}onInsertBlock(t,e,o){this.doc.onInsertBlock(t,e,o,this.user)}onUpdateBlockText(t,e,o){this.doc.onUpdateBlockText(t,e,o,this.user)}onUpdateBlockData(t,e,o){this.doc.onUpdateBlockData(t,e,o,this.user)}onCreateContainer(t,e){this.doc.onCreateContainer(t,e,this.user)}onCreateComment(){}onDeleteComment(){}onDeleteContainer(){}onUpdateComment(){}}async function aV(n,t,e){for(const o of e){const r=new cV(n,o.user);t.parseHistoryData(o,r)}}const An=S("split-text-actions");function vy(n){return n.length>2?!1:n.length===1?n[0].insert!==void 0:(g(An,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].insert!==void 0)}function yy(n){return n.length>2?!1:n.length===1?n[0].delete!==void 0:(g(An,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].delete!==void 0)}function ky(n){return n.length>2?!1:n.length===1?n[0].insert===void 0&&n[0].delete===void 0&&n[0].attributes!==void 0:(g(An,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].attributes!==void 0)}function uV(n){const t=[],e=mt.default(n);if(e.length===0)return[];if(e.length===1)return[n];if(e.length===2&&(yy(n)||vy(n)||ky(n)))return[n];const o=(i,s)=>i>0?[{retain:i},s]:[s];let r=0;for(;e.length>0;){const i=e[0];if(i.retain!==void 0&&i.attributes===void 0){g(An,i.retain>0,`invalid text op: ${JSON.stringify(i)}`),g(An,e.length>1,`invalid text op: ${JSON.stringify(i)}`);const s=e[1];g(An,s.delete||s.insert!==void 0||s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=i.retain,t.push(o(r,s)),s.delete!==void 0?r-=s.delete:s.insert!==void 0?r+=s.insert.length:(g(An,s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),g(An,s.retain!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=s.retain),e.splice(0,2)}else g(An,i.delete||i.insert!==void 0||i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),t.push(o(r,i)),e.shift(),i.retain!==void 0&&(g(An,i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),r+=i.retain),i.insert&&(r+=i.insert.length)}return t}function wy(n){if(g(An,n.length===1||n.length===2,`not a single action op: ${JSON.stringify(n)}`),n.length===1)return 0;const t=n[0].retain;return g(An,typeof t=="number"&&t>0,`invalid retain: ${JSON.stringify(n)}`),t}let By=0;function dV(n,t,e){const o=By;By+=1;const r=re(n);return{insert:" ",attributes:{box:!0,id:K(),type:"history-deleted-box",user:e,created:Date.now(),text:r,deletedOffset:t,deletedOrder:o}}}function hV(n,t,e){const o=wy(t),r=t.length===1?t[0].delete:t[1].delete;g(An,typeof r=="number",`not a delete op: ${JSON.stringify(t)}`);const{left:i,middle:s,right:l}=ze(n,o,r),a=dV(s,o,e);return[...i,a,...l]}function fV(n,t,e){const o=wy(t),r=t.length===1?t[0].insert:t[1].insert;g(An,typeof r=="string",`invalid insert op: ${JSON.stringify(t)}`);const i=t.length===1?t[0].attributes:t[1].attributes,l=uh([{insert:r,attributes:i}],"insertedBy",e);return Hr(n,o,l,null)}function mV(n,t,e){const o=uV(t);let r=n;for(const i of o)yy(i)?r=hV(r,i,e):vy(i)?r=fV(r,i,e):(g(An,ky(i),`unknown op: ${JSON.stringify(i)}`),r=ln.apply(r,i));return r}const gV=S("history-update-block-text");function Ey(n){const t=[],e=[];let o=0;return n.forEach(r=>{var i;if((i=r.attributes)!=null&&i.box){const s=r.attributes;if(s.type==="history-deleted-box"){t.push({boxData:s,offset:o});return}}e.push(r),o+=ah(r)}),t.sort((r,i)=>i.offset-r.offset),{deletedBoxes:t,newText:e}}function pV(n,t,e){let o=n;return t.forEach(r=>{const i=ln.transformCursor(r.offset,e,!1);o=Hr(o,i,[{insert:" ",attributes:r.boxData}],null)}),o}function CV(n){n.sort((t,e)=>t.boxData.deletedOffset!==e.boxData.deletedOffset?t.boxData.deletedOffset-e.boxData.deletedOffset:t.boxData.deletedOrder-e.boxData.deletedOrder)}function AV(n){if(n.length<=1)return n;const t=n[0].offset;n.forEach(e=>{g(gV,e.offset===t,`invalid boxes group, ${JSON.stringify(n)}`)}),CV(n);for(let e=n.length-1;e>=1;e--){const o=n[e],r=n[e-1];o.boxData.user.userId===r.boxData.user.userId&&(r.boxData.text+=o.boxData.text,n.splice(e,1))}return n}function bV(n){let{newText:t,deletedBoxes:e}=Ey(n);const o=new Map;return e.forEach(i=>{let s=o.get(i.offset);s||(s=[],o.set(i.offset,s)),s.push(i),s.sort((l,a)=>l.boxData.deletedOffset-a.boxData.deletedOffset)}),Array.from(o.values()).sort((i,s)=>s[0].offset-i[0].offset).forEach(i=>{const s=i[0].offset;AV(i).reverse().forEach(l=>{t=Hr(t,s,[{insert:" ",attributes:l.boxData}],null)})}),t}function vV(n,t,e){let{newText:o,deletedBoxes:r}=Ey(n);return o=mV(o,t,e),o=pV(o,r,t),o=bV(o),o}const Ar=S("history-doc");function br(n){g(Ar,!1,"no local actions for history doc")}class yV extends fa{constructor(t,e){super(),this.externalDoc=t,this.docObject=e}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.docObject)}getContainerBlocks(t){return this.docObject.blocks[t]}getBlockData(t,e){const o=this.getContainerBlocks(t);g(Ar,o,`no container data: ${t}`);const r=o[e];return g(Ar,r,`no block data: ${e}`),r}localUpdateBlockText(){br()}localUpdateBlockData(){br()}localInsertBlock(){br()}localDeleteBlock(){br()}localInsertChildContainer(){br()}localDeleteChildContainers(){br()}uploadResource(){br()}async addResources(t){br()}getServerMeta(){var t,e,o;return(o=(e=(t=this.externalDoc).getServerMeta)==null?void 0:e.call(t))!=null?o:{}}buildResourceUrl(t){return this.externalDoc.buildResourceUrl(t)}request(){br()}broadcastMessage(){br()}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new _h}destroy(){this.clearCallbacks()}transformBlockIndex(t,e,o){const r=this.docObject.blocks[t];g(Ar,r,`no container blocks: ${t}`);let i=0;for(let s=0;s<r.length;s++)if(!r[s].deletedBy){if(i===e)return s;i++}return o&&g(Ar,!1,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),g(Ar,i===e,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),r.length}onDeleteBlock(t,e,o){const r=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t][r];g(Ar,!s.deleted,`block has already deleted: ${t}/${e}`),s.deletedBy=o,this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockData)==null?void 0:a.call(l,t,r,{insert:{},delete:[]},!0)})}onInsertBlock(t,e,o,r){const i=this.transformBlockIndex(t,e,!1),s=this.docObject.blocks[t],l=mt.default(o);l.insertedBy=r,s.splice(i,0,l),this.callbacks.forEach(a=>{var d;return(d=a.onInsertBlock)==null?void 0:d.call(a,t,i,l,!0)})}onUpdateBlockText(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),l=this.docObject.blocks[t][i];g(Ar,!l.deleted,`block has already deleted: ${t}/${e}`);const a=l.text;g(Ar,a,`no text for block: ${JSON.stringify(l)}`);const d=vV(a,o,r);l.text=d,this.callbacks.forEach(h=>{var p;return(p=h.onUpdateBlockText)==null?void 0:p.call(h,t,i,o,!0)})}onUpdateBlockData(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t],l=s[i];g(Ar,!l.deleted,`block has already deleted: ${t}/${e}`);const a=mt.default(l);a.updatedBy=r,o.delete.forEach(d=>delete a[d]),Object.entries(o.insert).forEach(([d,h])=>{a[d]=h}),s[i]=a,this.callbacks.forEach(d=>{var h;return(h=d.onUpdateBlockData)==null?void 0:h.call(d,t,i,o,!0)})}onCreateContainer(t,e,o){this.docObject.blocks[t]=mt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,t,e,!0)})}}const{t:xy}=R;function Sc(n,t){return t==="insert"?xy("version.insert",{name:n.displayName}):xy("version.delete",{name:n.displayName})}function tl(n,t){const{userId:e}=t;return["flag","selection"].reduce((r,i)=>{const s=n.getRemoteUsers().getFixedUserColor(e,i);return r[i]=s,r},{})}class kV{renderText(t,e,o){if(!o.box&&o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,o.insertedBy);return{classes:["history-inserted-text"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Sc(r,"insert")},styles:{[Tc]:i,[Dc]:s}}}return{}}renderBlock(t,e,o){if(o.deletedBy){const r=o.deletedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-deleted-block"],attributes:{"history-deleted-by":r.displayName,"data-op-description":Sc(r,"delete")},styles:{[Tc]:i,[Dc]:s}}}if(o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-inserted-block"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Sc(r,"insert")},styles:{[Tc]:i,[Dc]:s}}}return{}}updateBlock(t,e,o,r){if(r.deletedBy){const i=r.deletedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-deleted-block"),bm(o,{"history-inserted-by":i.displayName,"data-op-description":Sc(i,"delete")}),vm(o,{[Tc]:s,[Dc]:l});return}if(r.insertedBy){const i=r.insertedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-inserted-block"),bm(o,{"history-inserted-by":i.displayName,"data-op-description":Sc(i,"insert")}),vm(o,{[Tc]:s,[Dc]:l})}}}const Iy=S("history-deleted-box");function wV(n,t,e,o){const r=o;g(Iy,r.text,`no text for text box data: ${JSON.stringify(o)}`),g(Iy,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`);const i=w("span",["history-deleted-box"],e,r.text),s=r.user,{flag:l,selection:a}=tl(n.doc,s);i.setAttribute("history-deleted-by",s.displayName),i.setAttribute("data-op-description",Sc(s,"delete")),i.style.setProperty(Tc,l),i.style.setProperty(Dc,a)}function BV(n,t,e,o){return t.text}const EV={boxType:"history-deleted-box",updateBoxContent:wV,convertTo:BV},Jnt="",xV=S("versions-dropdown"),Ty=(n,t)=>{if(!t)return n;let e="";const o=t.length,r=t.toLocaleLowerCase();let i=0;for(i=0;i<=n.length-o;i){let s=n.substring(i,i+o);if(s.toLocaleLowerCase()===r){i+=o;const l=n.charAt(i);let a=!1;s.endsWith(" ")&&(a=!0,s=s.trimEnd()),e+=`<span class="highlight">${s}${l===" "||a?" ":""}</span>`}else e+=n.charAt(i),i++}return i<n.length&&(e+=n.substring(i)),e};class IV{constructor(t,e){m(this,"dropdown");m(this,"versions",[]);m(this,"currentVersion",null);m(this,"compareWithVersion",null);m(this,"filterMemoed",!1);m(this,"keywords","");m(this,"createFilterMemoedFilterItem",t=>{const e=w("div",["filter-memoed-version-item"],null);t&&w("div",["filter-item-info"],e,R.t("version.dropdown.header"));const o=w("div",["filter-item-input-container"],e),r=w("input",["filter-item-input"],o);r.id="filter-item-input",r.type="checkbox";const i=w("label",["filter-item-label"],o,R.t("version.filterMemoed"));return i.htmlFor=r.id,r.onchange=this.handleInputChange,r.checked=this.filterMemoed,e});m(this,"filterItems",(t,e)=>{var i,s;if(this.keywords=e,!e)return!0;if(t.id==="section")return!1;const o=e.toLocaleLowerCase();if(t.name.toLocaleLowerCase().indexOf(o)!==-1)return!0;const r=t.data;return!!(r&&((i=r.extra)==null?void 0:i.memo)&&((s=r.extra)==null?void 0:s.memo.toLocaleLowerCase().indexOf(o))!==-1)});m(this,"handleClose",()=>{});m(this,"handleClear",()=>{this.options.onCompareWithVersion(null)});m(this,"handleClickItem",t=>{const e=t.data,o=Xs(e);this.dropdown.setText(o),this.options.onCompareWithVersion(e)});m(this,"handleInputChange",t=>{const e=t.target;this.filterMemoed=e.checked,this.resetItems()});this.options=e,this.dropdown=new Rp(t,{placeholder:R.t("version.noSelectedVersion"),emptyPlaceholder:R.t("version.noFilterVersion"),popupId:"versions-dropdown-popup",header:this.createHeader(),filter:this.filterItems,onClose:this.handleClose,onClickItem:this.handleClickItem,onClear:this.handleClear,highlight:!0})}createHeader(){const t=w("div",["versions-dropdown-header"],null),e=w("span",["versions-dropdown-header-info"],t);e.innerHTML=R.t("version.dropdownHeader");const o=w("span",["versions-dropdown-header-icon"],t);return o.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.help")),o.setAttribute("data-editor-tooltip-placement","right"),o.innerHTML=fv,o.onclick=this.options.onHelp,t}setVersions(t){this.versions=t}setCurrentVersion(t,e){this.dropdown.setText(""),this.dropdown.setLabels([]),e&&(this.dropdown.setText(Xs(e)),(e.version===-1||e.version===this.versions[0].version)&&this.dropdown.setLabels([R.t("version.latest")])),this.currentVersion=t,this.compareWithVersion=e!=null?e:null,this.resetItems()}resetItems(){var A;if(this.versions.length===0)return;const t=this.currentVersion;if(!t)return;const e=t.version===-1?0:this.versions.findIndex(v=>v.version===t.version);g(xV,e!==-1,"version not found");const o=this.versions[0],r=v=>{var H;const B=v.data,D=w("div",["version-item-container"],null),T=w("div",["version-item-line1"],D),_=v.value==="last-version"?R.t("version.lastVersion"):Xs(B),M=w("div",["version-item-name"],T);if(this.keywords?M.innerHTML=Ty(_,this.keywords):M.innerText=_,B.version===o.version&&w("div",["version-item-latest"],T,R.t("version.latest")),(H=B.extra)!=null&&H.memo){const z=w("div",["version-item-line2"],D),q=w("div",["version-item-memo"],z,B.extra.memo);this.keywords?q.innerHTML=Ty(B.extra.memo,this.keywords):q.innerText=B.extra.memo,q.setAttribute("data-editor-tooltip-common",B.extra.memo),q.setAttribute("data-editor-tooltip-placement","bottom")}return D.onclick=()=>{this.handleClickItem(v),this.dropdown.close()},D},i=[],s=this.versions[e+1],l=s&&!Xf(t);if(l){const v={id:"section",value:"last-version",name:"Last version",data:s,element:r};i.push(v)}let a=e;for(let v=e-1;v>=0;v-=1){const B=this.versions[v];if(Xf(B))break;a=v}let d=e;if(!Xf(t))for(let v=e+1;v<this.versions.length;v+=1){const B=this.versions[v];if(d=v,Xf(B))break}let h=!1;const p=[];for(let v=a;v<=d;v+=1){const B=this.versions[v];if(B.version!==t.version&&B.version!==(s==null?void 0:s.version)&&(!this.filterMemoed||((A=B.extra)==null?void 0:A.memo))){h=!0;let D=Xs(B),T=`${B.version}`;v===e+1&&(D="Previous version",T="prev-version");const _={id:T,name:D,data:B,element:r};p.push(_)}}if((l||h||this.filterMemoed)&&i.push({id:"section",name:"",element:this.createFilterMemoedFilterItem(i.length>0&&l),states:["disabled"]}),i.push(...p),!h){const v={id:"section",name:"No versions",states:["disabled"],element:w("span",["version-item-empty"],null,R.t("version.noVersions"))};i.push(v)}this.dropdown.updateItems(i)}}class TV{constructor(t,e){m(this,"left");m(this,"right");m(this,"dropdown");const o=w("div",["version-info-container"],t);this.left=w("div",["version-info-left"],o),this.dropdown=new IV(o,e),this.right=w("div",["version-info-right"],o)}setVersion(t,e,o){const r=`<span class="version-item-latest">${R.t("version.latest")}</span>`,i=`${Xs(t)}${o?r:""}`;this.left.innerHTML=R.t("version.versionInfoLeft",{versionName:i}),this.right.innerHTML=R.t("version.versionInfoRight",{versionName:i}),this.dropdown.setCurrentVersion(t,e)}}const es=S("version-dialog");class Dy{constructor(t,e){m(this,"dialog",null);m(this,"oldViewer",null);m(this,"versionOptions");m(this,"versionList",null);m(this,"provider");m(this,"versions",[]);m(this,"components");m(this,"handleRevert",async t=>{var o,r,i;g(es,this.versionList,"The versionList did not render");const e=t!=null?t:(o=this.versionList)==null?void 0:o.activeVersion;g(es,e,`The version: ${e} is invalid`),!(((r=this.versionOptions)==null?void 0:r.onBeforeRevert)&&await this.versionOptions.onBeforeRevert(e))&&(await this.versionHelper.revertVersion(e.version),(i=this.dialog)==null||i.hide())});m(this,"handleSelectVersion",t=>{g(es,t,`The version: ${t} is invalid`),this.viewVersion(t)});m(this,"handleCompareWithVersion",t=>{var o;const e=(o=this.versionList)==null?void 0:o.activeVersion;g(es,e,"no active version"),this.viewVersion(e,t!=null?t:void 0)});m(this,"handleHelp",()=>{var t,e;(e=(t=this.versionOptions)==null?void 0:t.onHelp)==null||e.call(t)});m(this,"viewVersion",async(t,e)=>{var h,p;const o=this.versions[0].version===t.version;if(this.components.infoHeader.setVersion(t,e,o),this.oldViewer&&(this.oldViewer.destroy(),this.oldViewer=null),!this.versionList)return;(h=this.versionOptions)!=null&&h.onWillChangeVersion&&this.versionOptions.onWillChangeVersion(this,t);const r=e==null?void 0:e.version;let i,s;if(r){const A=Math.min(t.version,r),v=Math.max(t.version,r),B=await this.versionHelper.getHistoryData(v,A);i=B.doc,s=B.historyData}else i=await this.versionHelper.getVersion(t.version),s=[];const{editorContainer:l}=this.components;l.innerHTML="";const a=new yV(this.doc,i),d=this.provider.createHistoryEditor(l,a);d.editorBlockRenders.registerRender(new kV),d.editorBoxes.registerBoxClass(EV),W(d.rootElement,Ay.HISTORY);try{await aV(a,this.versionHelper,s)}finally{this.oldViewer=d}(p=this.versionOptions)!=null&&p.onVersionChanged&&this.versionOptions.onVersionChanged(this,d,t)});m(this,"onMemoChanged",t=>{var e,o;(o=(e=this.versionOptions)==null?void 0:e.onMemoChanged)==null||o.call(e,t),this.components.infoHeader.dropdown.resetItems(),this.components.infoHeader.dropdown.setVersions(this.versions)});this.doc=t,this.provider=e;const o=w("div",["version-dialog"],null),r=w("div",["version-viewer"],o),i=new TV(r,{onCompareWithVersion:this.handleCompareWithVersion,onHelp:this.handleHelp}),s=w("div",["version-dialog-editor"],r),l=w("div",["version-list-root"],o);this.components={root:o,editorContainer:s,listContainer:l,infoHeader:i}}get versionHelper(){g(es,this.doc.getVersionHelper,"Can not get getVersionHelper from doc");const t=this.doc.getVersionHelper();return g(es,t,"current doc does not support version"),t}get editor(){return this.oldViewer}renderContent(t){var r,i;const{listContainer:e}=this.components;e.innerHTML="";const o=new lV({enableEdit:((r=this.versionOptions)==null?void 0:r.enableEdit)||!1,versions:t,versionHelper:this.versionHelper,useCreatedBy:(i=this.versionOptions)==null?void 0:i.useCreatedBy,onSelectVersion:this.handleSelectVersion,onRevert:this.handleRevert,onMemoChanged:this.onMemoChanged,getMarkColor:s=>{const{flag:l}=tl(this.doc,s);return l}});o.render(e),this.versionList=o}initViewVersion(){var t;if(g(es,this.versionList,"no versionList"),(t=this.versionOptions)!=null&&t.initSelectedVersion){const{initSelectedVersion:e}=this.versionOptions,o=this.versionList.selectVersionByVersionNum(e);g(es,o,`version ${e} not found`),this.viewVersion(o)}else{const e=this.versionList.activeVersion;e&&this.viewVersion(e)}}async show(t){if(this.versionOptions={...this.versionOptions,...t},this.versions=await this.versionHelper.getVersions(),this.versionOptions.onVersionsLoaded&&this.versionOptions.onVersionsLoaded(this,this.versions),this.components.infoHeader.dropdown.setVersions(this.versions),this.renderContent(this.versions),this.initViewVersion(),!this.dialog){const{root:e}=this.components;this.dialog=new iV(e)}this.dialog.show(t.container)}destroy(){var t,e;(t=this.dialog)==null||t.destroy(),(e=this.versionList)==null||e.destroy()}}const DV={expandCollapseButton:{tips:"\u5C55\u5F00 / \u6536\u8D77"}},SV={expandCollapseButton:{tips:"Expand / Collapse"}},LV={expandCollapseButton:{tips:"\u5C55\u958B / \u7E2E\u5C0F"}};R.mergeLang({"zh-CN":DV,"en-US":SV,"ja-JP":LV});const Knt="",MV=S("heading-collapse");function S2(n){var e;const t=Number.parseInt((e=n.getAttribute("data-style-heading"))!=null?e:"",10);return g(MV,t,"not a heading block"),t}function fo(n){return!!n.getAttribute("data-style-heading")}function RV(n){return!xt(n,"heading-collapsed")}function el(n){return xt(n,"heading-collapsed")}function Sy(n){if(ce(n))return!1;const e=nt(n);return Xt(e)}const OV=S("heading-collapse");function L2(n){g(OV,fo(n),"not a heading block");const t=[],e=S2(n);let o=Zt(n);for(;o&&!(fo(o)&&S2(o)<=e);)t.push(o),o=Zt(o);return t}function Ly(n,t){if(!ro(t))return;n.selection.selectBlock(t,0),L2(t).forEach(o=>{UC(o)}),W(t,"heading-collapsed")}function Lc(n,t){L2(t).forEach(o=>{zC(o)}),et(t,"heading-collapsed")}function _V(n,t){RV(t)?Ly(n,t):Lc(n,t)}const FV=[kp,wp,Bp,Ep,xp,Ip,Tp,Dp];function PV(n){const t=w("button",["heading-collapse-button"],null);return t.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("expandCollapseButton.tips")),t.innerHTML=Gh,t}function My(n){return Mf(n).querySelector("button.heading-collapse-button")}function Ry(n,t){My(t)||Sy(t)||!ro(t)||Q0(t,PV(n),-1)}function NV(n){var t;(t=My(n))==null||t.remove()}function Oy(n,t){Mf(t).querySelector("button.heading-collapse-button")||Ry(n,t)}function $V(n){const t=S2(n),e=w("button",["heading-marker"],null);return e.innerHTML=FV[t-1],e}function _y(n){return Mf(n).querySelector("button.heading-marker")}function M2(n){_y(n)||Sy(n)||!ro(n)||Q0(n,$V(n),1)}function Fy(n){const t=_y(n);t==null||t.remove()}function Py(n){Fy(n),fo(n)&&M2(n)}class HV{handleDrop(t,e,o,r){if(Wd(e)||!fo(e)||!el(e))return;const i=L2(e);i.unshift(e);const s=i.reverse();let l=null;return t.doc.beginBatchUpdate(),s.forEach((a,d,h)=>{const p=t.getBlockData(a),A=Fi(t.editorBlocks,t.doc.toJSON(),p),v=t.insertDocAt(o,r,A)[0];d===h.length-1&&(l=v)}),t.doc.endBatchUpdate(),t.doc.beginBatchUpdate(),s.forEach(a=>{t.deleteBlock(a)}),t.doc.endBatchUpdate(),l&&Ly(t,l),!0}}const jV=S("heading-collapse");class R2{constructor(t){m(this,"handleLoad",()=>{this.showCollapseButtons()});m(this,"handleHoverBlock",(t,e)=>{e&&(et(e,"hovering-heading"),fo(e)&&Xt(nt(e))&&(M2(e),el(e)||NV(e))),t&&fo(t)&&Xt(nt(t))&&(W(t,"hovering-heading"),this.editor.readonly||Fy(t),Ry(this.editor,t))});m(this,"handleClick",(t,e)=>{const o=jl(e,"button.heading-collapse-button");if(!o)return;const r=ot(o);!r||(g(jV,fo(r),"not a heading block"),_V(this.editor,r),Oy(this.editor,r))});this.editor=t,t.addListener("load",this.handleLoad),t.addListener("click",this.handleClick),pe.get(t).addListener("change",this.handleHoverBlock),this.showCollapseButtons(),setTimeout(()=>{var o;(o=Su.find(t))==null||o.addHandler(new HV)})}showCollapseButtons(){const t=ve(this.editor.rootContainer).filter(fo);t.length!==0&&(t[0]===Se(this.editor.rootContainer)&&t.splice(0,1),t.forEach(M2))}destroy(){this.editor.removeListener("load",this.handleLoad),this.editor.removeListener("click",this.handleClick)}}function t1(n){const t=n.selection.range;if(t.isCollapsed()||t.start.blockId===t.end.blockId)return;const e=n.getBlockById(t.start.blockId),o=n.getBlockById(t.end.blockId);el(e)&&Lc(n,e),el(o)&&Lc(n,o)}function UV(n){t1(n);const t=n.getFocusedBlock();!fo(t)||el(t)&&Lc(n,t)}function zV(n){t1(n);const t=n.getFocusedBlock();if(!fo(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===ut(n,t)&&el(t)&&Lc(n,t)}function VV(n){t1(n);const t=n.getFocusedBlock();if(!fo(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===0&&el(t)&&Lc(n,t)}class WV{handleBeforeKeyDown(t,e){return xm(e.key)&&t1(t),e.key==="Enter"?(UV(t),!1):e.key==="Delete"?(zV(t),!1):(e.key==="Backspace"&&VV(t),!1)}}class qV{constructor(t){this.editor=t}onInsertBlock(t,e,o,r){this.updateBlockIfNeeded(o.id)}onUpdateBlockData(t,e,o,r){const i=this.editor.doc.getBlockData(t,e);this.updateBlockIfNeeded(i.id,o)}updateBlockIfNeeded(t,e){setTimeout(()=>{const o=this.editor.findBlockById(t);if(!!o){if(!fo(o)){e&&e.delete.includes("heading")&&Py(o);return}xt(o,"hovering-heading")&&Oy(this.editor,o),Py(o)}},100)}}function GV(n){return!!n.heading}function Ny(n){var e;const t=n.heading;return(e=Number.parseInt(`${t}`,10))!=null?e:1}function $y(n,t,e){var i;const o=Ms(n,t.type);let r="";if(o.convertTo){const s=jr();r=o.convertTo(n,t,s,"text",[{containerId:"root",blockIndex:0}]),r=r.replace(/\n/g,"").trim()}else r=re((i=t.text)!=null?i:[]);return{parentNode:e,children:[],text:r,level:Ny(t),block:t}}class Pu{constructor(t){m(this,"nodes",[]);this.editor=t}appendBlock(t){const e=this.findParent(Ny(t),this.nodes);e?e.children.push($y(this.editor,t,e)):this.nodes.push($y(this.editor,t,null))}findParent(t,e){const o=e[e.length-1];if(!o||t<=1)return null;if(o.level===t-1)return o;const r=this.findParent(t,o.children);return r||(o.level<t?o:null)}static buildToc(t,e){const o=new Pu(t),r=e.blocks.root;for(let i=0;i<r.length;i++){const s=r[i];GV(s)&&o.appendBlock(s)}return o}}class nl extends be.TypedEmitter{constructor(e){super();m(this,"toc");m(this,"updateToc",He.default(()=>{this.updateTocNow()},500));this.editor=e,e.doc.registerCallback(this),this.updateToc(),this.toc=new Pu(this.editor)}destroy(){this.editor.doc.unregisterCallback(this)}isHeadingBlock(e){return!!e.heading}onInsertBlock(e,o,r,i){e==="root"&&this.isHeadingBlock(r)&&this.updateToc()}onDeleteBlock(e,o,r){e==="root"&&this.updateToc()}onUpdateBlockText(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}onUpdateBlockData(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}static register(e){return e.addCustom("editor-toc",()=>new nl(e))}static get(e){return e.getCustom("editor-toc")}updateTocNow(){this.toc=Pu.buildToc(this.editor,this.editor.doc.toJSON()),this.emit("change",this.editor,this.toc)}}const Xnt="";function ZV(n){return n.nodes.length===0?!0:n.nodes.length>1?!1:n.nodes[0].children.length===0}function Hy(n,t){t.forEach(e=>{const o=w("div",["toc-node"],n),r=w("div",["toc-title"],o);if(w("span",["toc-text"],r,e.text).setAttribute("data-block-id",e.block.id),e.children.length>0){const s=w("div",["toc-children"],o);Hy(s,e.children)}})}function QV(n,t){const e=jl(t,".toc-text");if(!e)return;const o=e.getAttribute("data-block-id");if(!o)return;const r=n.findBlockById(o);!r||(t.preventDefault(),t.stopPropagation(),n.selection.selectBlock(r,0))}function jy(n,t,e){if(et(t,"loading"),t.innerHTML="",ZV(e)){w("div",["toc-empty-message"],t,R.t("toc.empty"));return}if(e.nodes.length>=1){const[o,...r]=e.nodes,i=[...o.children,...r];Hy(t,i)}op(n,"toc-click-handler",()=>{n.addListener("click",QV)})}class YV{constructor(t){m(this,"handleUpdateToc",(t,e)=>{Array.from(t.rootContainer.querySelectorAll('.embed-block[data-type="editor-block"][data-embed-type="toc"]')).forEach(r=>{const i=r.querySelector(".editor-toc-container");i&&jy(t,i,e)})});this.editor=t,nl.register(t).addListener("change",this.handleUpdateToc)}destroy(){nl.register(this.editor).removeListener("change",this.handleUpdateToc)}get toc(){return nl.register(this.editor).toc}}function JV(n,t){const e=w("div",["editor-toc-container"],t),r=n.addCustom("init-editor-toc",()=>new YV(n)).toc;r.nodes.length===0?W(e,"loading"):jy(n,e,r)}function KV(n,t,e,o){return o==="markdown"?"[toc]":""}function XV(n,t,e){const{data:o}=e;if(!o||o.embedType!=="toc"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"toc",embedData:r}}}const Uy={embedType:"toc",createEmbedContent:JV,convertTo:KV,convertFrom:XV},tW={toc:{empty:"No Toc"}},eW={toc:{empty:"No Toc"}},nW={toc:{empty:"No Toc"}};R.mergeLang({"zh-CN":tW,"en-US":eW,"ja-JP":nW});function oW(n){return!!n.getAttribute("data-style-heading")}function O2(n,t){return oW(t)&&ut(n,t)>0}function rW(n){const t=oo(n.rootElement);let e=0,o=0,r=0;if(t===document.documentElement){const i=n.rootContainer.getBoundingClientRect();e=i.left+i.width/2,o=10,r=t.offsetHeight}else{const i=t.getBoundingClientRect();e=i.left+i.width/2,o=i.top+10,r=i.bottom}for(;o<r;){const i=document.elementsFromPoint(e,o);for(let s=0;s<i.length;s++){const l=ot(i[s]);if(l&&n.rootContainer.contains(l))return l}o+=10}return null}function _2(n,t){let e=t;for(;e&&!O2(n,e);)e=Zt(e);return e}function zy(n){if(ce(n))return!1;const e=nt(n);return Xt(e)}function e1(n,t){let e=t;for(;e&&!O2(n,e);)e=ce(e),e&&zy(e)&&(e=null);return e}const iW=.3;class sW extends be.TypedEmitter{constructor(e){super();m(this,"scrollContainer");m(this,"scrollEventTarget");m(this,"scrollStatus",{curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null});m(this,"handleScroll",He.default(()=>{const e={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null};let o=rW(this.editor);if(o&&(o=Vm(o)),!o||!this.scrollContainer){this.setStatus(e);return}if(zy(o)&&(o=Zt(o)),!o){this.setStatus(e);return}if(O2(this.editor,o)){e.curHeadingBlock=o,e.previousHeadingBlock=e1(this.editor,o),e.nextHeadingBlock=_2(this.editor,o),this.setStatus(e);return}const r=this.scrollContainer.getBoundingClientRect(),i=_2(this.editor,o);if(i){const l=i.getBoundingClientRect();if(l.top>r.top&&l.top<r.top+r.height*iW){e.curHeadingBlock=i,e.previousHeadingBlock=e1(this.editor,i),e.nextHeadingBlock=_2(this.editor,i),this.setStatus(e);return}e.nextHeadingBlock=i}const s=e1(this.editor,o);s&&(e.curHeadingBlock=s,e.previousHeadingBlock=e1(this.editor,s)),this.setStatus(e)},200));this.editor=e,setTimeout(()=>{this.start()},50)}setStatus(e){this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock&&this.scrollStatus.nextHeadingBlock===e.nextHeadingBlock&&this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock||(this.scrollStatus=e,this.emit("change",this.editor,e))}start(){this.stop(),this.scrollContainer=oo(this.editor.rootElement),this.scrollEventTarget=this.scrollContainer===document.documentElement?document:this.scrollContainer,this.scrollEventTarget.addEventListener("scroll",this.handleScroll),this.handleScroll()}stop(){this.scrollEventTarget&&this.scrollEventTarget.removeEventListener("scroll",this.handleScroll)}destroy(){this.stop(),this.scrollEventTarget=void 0}}class F2{constructor(t,e){m(this,"suggest");m(this,"onClose",()=>{this.editor.focus()});m(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!ro(i)){const s=ot(nt(i));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e,o)=>{const r=e.data,i={id:K(),type:"mention",box:!0,created:Date.now(),iconUrl:r.avatarUrl,text:r.displayName,mentionId:r.userId},s=this.editor.selection.range;if(!s.isCollapsed()||!s.isSimple())return;const l=s.focus,a=this.editor.getBlockById(l.blockId);this.editor.insertBoxToBlock(a,l.offset,i)});m(this,"queryItems",async(t,e)=>(await this.options.queryUsers(this.editor,e)).map(i=>{const s=Qd(i.displayName);return{id:i.userId,name:i.displayName,icon:i.avatarUrl?`<img src="${i.avatarUrl}" class="mention-user-avatar">`:`<span style="background: ${s}" class="mention-user-avatar-string">${Zd(i.displayName,1)}</span>`,element:i.element,data:i,subText:i.email}}));this.editor=t,this.options=e,this.suggest=new Np(t,{id:"editor-mention",trigger:["@"],autoDeleteTrigger:!0,showLoading:!0,enableFirstBlock:e.enableFirstBlock,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,onClose:this.onClose})}destroy(){}}S("mathjax-box");function lW(n,t,e,o){const r=o,i=w("a",["mention-container"],e);w("span",["mention-name"],i,`@${r.text}`),i.setAttribute("data-mention-id",r.mentionId)}function cW(n,t,e){}function aW(n,t,e,o){return`@${t.text}`}function uW(){return{abstract:R.t("mention.abstract")}}const P2={boxType:"mention",updateBoxContent:lW,handleClickBox:cW,convertTo:aW,getBoxProperties:uW};function dW(n){const t=w("div",["mention-button-wrap"],null),e=ji("mention-button",R.t("list.mention.tooltip"),JL,[],n.clientId);return t.appendChild(e),t}class hW{constructor(t){m(this,"mentionButton");m(this,"handleHoveringBlock",t=>{var e;!this.editor.isWritable()||(t&&this.shouldBlockShowMention(t)?le(t).appendChild(this.mentionButton):(e=this.mentionButton)==null||e.remove())});m(this,"handleMouseDown",(t,e)=>{e.preventDefault(),e.stopPropagation();const o=ot(this.mentionButton);if(!o||!tt(t,o))return;const r=t.selection.range.focus;if(!r.isSimple())return;let i;t.selection.focusedBlock!==o?i=ut(t,o):i=r.offset,setTimeout(()=>{const s=t.insertTextToBlock(o,i,"@");i+=1;const l=re(xn(s,i).left);this.editor.selection.selectBlock(o,i),this.editor.focus(),t.getCustom("mention").suggest.popup(o,i,l,"@")})});m(this,"destroy",()=>{pe.get(this.editor).removeListener("change",this.handleHoveringBlock)});this.editor=t,this.mentionButton=dW(t),pe.get(this.editor).addListener("change",this.handleHoveringBlock),t.domEvents.addEventListener(this.mentionButton,"mousedown",this.handleMouseDown)}shouldBlockShowMention(t){if(!tt(this.editor,t)||!Ht(t))return!1;const e=Zn(t);return!(e==="ordered"||e==="unordered")}}const tot="",fW={mention:{abstract:"\u6210\u5458"}},mW={mention:{abstract:"Member"}},gW={mention:{abstract:"\u30E1\u30F3\u30D0\u30FC"}};R.mergeLang({"zh-CN":fW,"en-US":mW,"ja-JP":gW});const pW={templates:{title:"\u9009\u62E9\u6A21\u677F\uFF0C\u5FEB\u901F\u521B\u5EFA",create:"\u65B0\u5EFA\u6A21\u677F",choose:"\u5168\u90E8\u6A21\u677F",customizedMark:"\u81EA\u5B9A\u4E49"}},CW={templates:{title:"Choose a template",create:"New template",choose:"All templates",customizedMark:"Custom"}},AW={templates:{title:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u9078\u629E",create:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u65B0\u898F\u4F5C\u6210",choose:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u4E00\u89A7",customizedMark:"\u30AB\u30B9\u30BF\u30E0"}};R.mergeLang({"zh-CN":pW,"en-US":CW,"ja-JP":AW});const eot="",bW="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjEyMCIgaGVpZ2h0PSIxMjAiIHZpZXdCb3g9IjAgMCAxMjAgMTIwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cmVjdCB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTQ4IDU5QzQ4IDU0LjU4MTcgNTEuNTgxNyA1MSA1NiA1MUg5M0M5OC41MjI4IDUxIDEwMyA1NS40NzcyIDEwMyA2MVY4OEMxMDMgOTEuODY2IDk5Ljg2NiA5NSA5NiA5NUg1NkM1MS41ODE3IDk1IDQ4IDkxLjQxODMgNDggODdWNTlaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGQ9Ik0xOCA2NEMxOCA2Mi4zNDMxIDE5LjM0MzEgNjEgMjEgNjFINTZDNjAuNDE4MyA2MSA2NCA2NC41ODE3IDY0IDY5VjgzQzY0IDg1LjIwOTEgNjIuMjA5MSA4NyA2MCA4N0gyNkMyMS41ODE3IDg3IDE4IDgzLjQxODMgMTggNzlWNjRaIiBmaWxsPSIjRUFFNEY2Ii8+CjxyZWN0IHg9IjI0IiB5PSIzMSIgd2lkdGg9IjY1IiBoZWlnaHQ9IjUwIiByeD0iNSIgZmlsbD0iIzk5QzdGMiIvPgo8cmVjdCB4PSIzMy41IiB5PSI0MyIgd2lkdGg9IjQ2IiBoZWlnaHQ9IjUiIHJ4PSIyLjUiIGZpbGw9IndoaXRlIi8+CjxyZWN0IHg9IjMzLjUiIHk9IjU0IiB3aWR0aD0iNDYiIGhlaWdodD0iNSIgcng9IjIuNSIgZmlsbD0id2hpdGUiLz4KPHJlY3QgeD0iMjQiIHk9IjMxIiB3aWR0aD0iNjUiIGhlaWdodD0iNTAiIHJ4PSI1IiBzdHJva2U9IiNGOEY4RjgiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01MCA4NS4yNjhDNTMuODI2MyA4My4wNTg5IDU1LjEzNzMgNzguMTY2MiA1Mi45MjgyIDc0LjMzOThMNjMuMzIwNSA2OC4zMzk4QzY4Ljg0MzMgNzcuOTA1NyA2NS41NjU4IDkwLjEzNzUgNTYgOTUuNjYwNEM0Ni40MzQxIDEwMS4xODMgMzQuMjAyMyA5Ny45MDU3IDI4LjY3OTQgODguMzM5OEwzOS4wNzE3IDgyLjMzOThDNDEuMjgwOSA4Ni4xNjYyIDQ2LjE3MzYgODcuNDc3MiA1MCA4NS4yNjhaIiBmaWxsPSIjQUI5M0RDIi8+CjxyZWN0IHg9IjU5IiB5PSI2NSIgd2lkdGg9IjQyIiBoZWlnaHQ9IjI4IiByeD0iNSIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTYzIDg4VjczLjA4MDhDNjMgNzEuNzA5NiA2My4zNjE0IDcwLjY4NjcgNjQuMDg0MSA3MC4wMTJDNjQuODI4NyA2OS4zMzczIDY1Ljg1OCA2OSA2Ny4xNzIgNjlIOTIuODYwOUM5NS42MjAzIDY5IDk3IDcwLjM2MDMgOTcgNzMuMDgwOFY4OEg5My41MTc5TDg3LjM3NDkgODAuNjIyQzg3LjA5MDIgODAuMzE3MyA4Ni43NjE3IDgwLjA4ODggODYuMzg5NCA3OS45MzY0Qzg2LjAxNzEgNzkuNzg0MSA4NS42NDQ4IDc5LjcwNzkgODUuMjcyNSA3OS43MDc5Qzg0LjkwMDIgNzkuNzA3OSA4NC41Mjc5IDc5Ljc4NDEgODQuMTU1NiA3OS45MzY0QzgzLjgwNTIgODAuMDg4OCA4My40NTQ4IDgwLjMxNzMgODMuMTA0MyA4MC42MjJMNzYuNzMxNCA4Ni4yMzcxTDc0LjIwMTkgODMuOTUxOUM3My42MzI1IDgzLjQyOTYgNzMuMDA4NCA4My4xNjg0IDcyLjMyOTUgODMuMTY4NEM3MS42NTA2IDgzLjE2ODQgNzEuMDM3NCA4My40Mjk2IDcwLjQ4OTkgODMuOTUxOUw2Ni40NDkzIDg4SDYzWk03NC40NjQ3IDgwLjYyMkM3NS4zNjI2IDgwLjYyMiA3Ni4xNDAxIDgwLjI5NTUgNzYuNzk3MSA3OS42NDI2Qzc3LjQ3NiA3OC45ODk3IDc3LjgxNTUgNzguMjE3MSA3Ny44MTU1IDc3LjMyNDdDNzcuODE1NSA3Ni40MTA3IDc3LjQ3NiA3NS42MzggNzYuNzk3MSA3NS4wMDY5Qzc2LjE0MDEgNzQuMzU0IDc1LjM2MjYgNzQuMDE2NiA3NC40NjQ3IDczLjk5NDhDNzMuNTQ0OSA3My45NTEzIDcyLjc1NjUgNzQuMjY2OSA3Mi4wOTk1IDc0Ljk0MTZDNzEuNDQyNSA3NS42MTYzIDcxLjExNCA3Ni40MTA3IDcxLjExNCA3Ny4zMjQ3QzcxLjExNCA3OC4yMTcxIDcxLjQ0MjUgNzguOTg5NyA3Mi4wOTk1IDc5LjY0MjZDNzIuNzU2NSA4MC4yOTU1IDczLjU0NDkgODAuNjIyIDc0LjQ2NDcgODAuNjIyWiIgZmlsbD0iI0Y3RDA3RiIvPgo8Y2lyY2xlIGN4PSI5NSIgY3k9IjQyIiByPSIyIiBzdHJva2U9IiM1MEMzOTgiIHN0cm9rZS13aWR0aD0iMiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTk0Ljc1MDEgMjQuNDY4N0wxMDAuNzgxIDI3LjkxNDlMOTQuNzE5IDMxLjQxNDlMOTQuNzUwMSAyNC40Njg3WiIgc3Ryb2tlPSIjNUNBNUVBIiBzdHJva2Utd2lkdGg9IjEuOCIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwNSAzOEMxMDUgMzguNTUyMyAxMDUuNDQ4IDM5IDEwNiAzOUMxMDYuNTUyIDM5IDEwNyAzOC41NTIzIDEwNyAzOFYzNkgxMDlDMTA5LjU1MiAzNiAxMTAgMzUuNTUyMyAxMTAgMzVDMTEwIDM0LjQ0NzcgMTA5LjU1MiAzNCAxMDkgMzRIMTA3VjMyQzEwNyAzMS40NDc3IDEwNi41NTIgMzEgMTA2IDMxQzEwNS40NDggMzEgMTA1IDMxLjQ0NzcgMTA1IDMyVjM0SDEwM0MxMDIuNDQ4IDM0IDEwMiAzNC40NDc3IDEwMiAzNUMxMDIgMzUuNTUyMyAxMDIuNDQ4IDM2IDEwMyAzNkgxMDVWMzhaIiBmaWxsPSIjQUI5M0RDIi8+Cjwvc3ZnPgo=",vW="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgdmlld0JveD0iMCAwIDM3MiAyNzkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8xMjU2XzM3MTY4KSI+CjxyZWN0IHdpZHRoPSIzNzIiIGhlaWdodD0iMjc5IiBmaWxsPSJ3aGl0ZSIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIzOS41NzQ3IiB3aWR0aD0iMTE4LjcyMyIgaGVpZ2h0PSIxNS44Mjk4IiByeD0iNy45MTQ4OSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI3MS4yMzM5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI5MS4wMjE1IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIxMTAuODA5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSI0MC41NjM4IiB5PSIxMzUuNTQzIiB3aWR0aD0iMjkwLjg3MiIgaGVpZ2h0PSIxMDAuOTE1IiByeD0iMi45NjgwOSIgc3Ryb2tlPSIjRUFGM0ZDIiBzdHJva2Utd2lkdGg9IjEuOTc4NzIiLz4KPHBhdGggZD0iTTM5LjU3NDUgMTM4LjUxMUMzOS41NzQ1IDEzNi4zMjUgNDEuMzQ2MyAxMzQuNTUzIDQzLjUzMTkgMTM0LjU1M0gzMjguNDY4QzMzMC42NTQgMTM0LjU1MyAzMzIuNDI2IDEzNi4zMjUgMzMyLjQyNiAxMzguNTExVjE1Mi4zNjJIMzkuNTc0NVYxMzguNTExWiIgZmlsbD0iI0Q2RTlGQSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTg3LjA2MzcgMTY5LjE4MUM4Ny4wNjM3IDE2Ny41NDIgODguMzkyNiAxNjYuMjEzIDkwLjAzMTggMTY2LjIxM0gzMTcuNTg1QzMxOS4yMjQgMTY2LjIxMyAzMjAuNTUzIDE2Ny41NDIgMzIwLjU1MyAxNjkuMTgxQzMyMC41NTMgMTcwLjgyIDMxOS4yMjQgMTcyLjE0OSAzMTcuNTg1IDE3Mi4xNDlIOTAuMDMxOEM4OC4zOTI2IDE3Mi4xNDkgODcuMDYzNyAxNzAuODIgODcuMDYzNyAxNjkuMTgxWk0xMDQuODcyIDE5Mi45MjZDMTA0Ljg3MiAxOTEuMjg2IDEwNi4yMDEgMTg5Ljk1NyAxMDcuODQgMTg5Ljk1N0gzMTcuNTg1QzMxOS4yMjQgMTg5Ljk1NyAzMjAuNTUzIDE5MS4yODYgMzIwLjU1MyAxOTIuOTI2QzMyMC41NTMgMTk0LjU2NSAzMTkuMjI0IDE5NS44OTQgMzE3LjU4NSAxOTUuODk0SDEwNy44NEMxMDYuMjAxIDE5NS44OTQgMTA0Ljg3MiAxOTQuNTY1IDEwNC44NzIgMTkyLjkyNlpNMTA3Ljg0IDIxMy43MDJDMTA2LjIwMSAyMTMuNzAyIDEwNC44NzIgMjE1LjAzMSAxMDQuODcyIDIxNi42N0MxMDQuODcyIDIxOC4zMDkgMTA2LjIwMSAyMTkuNjM4IDEwNy44NCAyMTkuNjM4SDMxNy41ODVDMzE5LjIyNCAyMTkuNjM4IDMyMC41NTMgMjE4LjMwOSAzMjAuNTUzIDIxNi42N0MzMjAuNTUzIDIxNS4wMzEgMzE5LjIyNCAyMTMuNzAyIDMxNy41ODUgMjEzLjcwMkgxMDcuODRaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNTEuNDQ2OCAxNjkuMTgxQzUxLjQ0NjggMTY3LjU0MiA1Mi43NzU2IDE2Ni4yMTMgNTQuNDE0OSAxNjYuMjEzSDYwLjM1MUM2MS45OTAzIDE2Ni4yMTMgNjMuMzE5MSAxNjcuNTQyIDYzLjMxOTEgMTY5LjE4MUM2My4zMTkxIDE3MC44MiA2MS45OTAzIDE3Mi4xNDkgNjAuMzUxIDE3Mi4xNDlINTQuNDE0OUM1Mi43NzU2IDE3Mi4xNDkgNTEuNDQ2OCAxNzAuODIgNTEuNDQ2OCAxNjkuMTgxWk01MS40NDY4IDE5Mi45MjZDNTEuNDQ2OCAxOTEuMjg2IDUyLjc3NTcgMTg5Ljk1NyA1NC40MTQ5IDE4OS45NTdINjAuMzUxMUM2MS45OTAzIDE4OS45NTcgNjMuMzE5MSAxOTEuMjg2IDYzLjMxOTEgMTkyLjkyNkM2My4zMTkxIDE5NC41NjUgNjEuOTkwMyAxOTUuODk0IDYwLjM1MTEgMTk1Ljg5NEg1NC40MTQ5QzUyLjc3NTcgMTk1Ljg5NCA1MS40NDY4IDE5NC41NjUgNTEuNDQ2OCAxOTIuOTI2Wk01NC40MTQ5IDIxMy43MDJDNTIuNzc1NyAyMTMuNzAyIDUxLjQ0NjggMjE1LjAzMSA1MS40NDY4IDIxNi42N0M1MS40NDY4IDIxOC4zMDkgNTIuNzc1NyAyMTkuNjM4IDU0LjQxNDkgMjE5LjYzOEg2MC4zNTExQzYxLjk5MDMgMjE5LjYzOCA2My4zMTkxIDIxOC4zMDkgNjMuMzE5MSAyMTYuNjdDNjMuMzE5MSAyMTUuMDMxIDYxLjk5MDMgMjEzLjcwMiA2MC4zNTExIDIxMy43MDJINTQuNDE0OVoiIGZpbGw9IiM5OUM3RjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02OS4yNTU0IDE2OS4xODFDNjkuMjU1NCAxNjcuNTQyIDcwLjU4NDMgMTY2LjIxMyA3Mi4yMjM1IDE2Ni4yMTNINzguMTU5N0M3OS43OTg5IDE2Ni4yMTMgODEuMTI3OCAxNjcuNTQyIDgxLjEyNzggMTY5LjE4MUM4MS4xMjc4IDE3MC44MiA3OS43OTg5IDE3Mi4xNDkgNzguMTU5NyAxNzIuMTQ5SDcyLjIyMzVDNzAuNTg0MyAxNzIuMTQ5IDY5LjI1NTQgMTcwLjgyIDY5LjI1NTQgMTY5LjE4MVpNNjkuMjU1NCAxOTIuOTI2QzY5LjI1NTQgMTkxLjI4NiA3MC41ODQyIDE4OS45NTcgNzIuMjIzNSAxODkuOTU3SDc4LjE1OTZDNzkuNzk4OSAxODkuOTU3IDgxLjEyNzcgMTkxLjI4NiA4MS4xMjc3IDE5Mi45MjZDODEuMTI3NyAxOTQuNTY1IDc5Ljc5ODkgMTk1Ljg5NCA3OC4xNTk2IDE5NS44OTRINzIuMjIzNUM3MC41ODQyIDE5NS44OTQgNjkuMjU1NCAxOTQuNTY1IDY5LjI1NTQgMTkyLjkyNlpNNzIuMjIzNSAyMTMuNzAyQzcwLjU4NDIgMjEzLjcwMiA2OS4yNTU0IDIxNS4wMzEgNjkuMjU1NCAyMTYuNjdDNjkuMjU1NCAyMTguMzA5IDcwLjU4NDIgMjE5LjYzOCA3Mi4yMjM1IDIxOS42MzhINzguMTU5NkM3OS43OTg5IDIxOS42MzggODEuMTI3NyAyMTguMzA5IDgxLjEyNzcgMjE2LjY3QzgxLjEyNzcgMjE1LjAzMSA3OS43OTg5IDIxMy43MDIgNzguMTU5NiAyMTMuNzAySDcyLjIyMzVaIiBmaWxsPSIjRjdEMDdGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNOTAuMDMxOCAxODkuOTU4Qzg4LjM5MjYgMTg5Ljk1OCA4Ny4wNjM3IDE5MS4yODYgODcuMDYzNyAxOTIuOTI2Qzg3LjA2MzcgMTk0LjU2NSA4OC4zOTI2IDE5NS44OTQgOTAuMDMxOCAxOTUuODk0SDk1Ljk2OEM5Ny42MDcyIDE5NS44OTQgOTguOTM2MSAxOTQuNTY1IDk4LjkzNjEgMTkyLjkyNkM5OC45MzYxIDE5MS4yODYgOTcuNjA3MiAxODkuOTU4IDk1Ljk2OCAxODkuOTU4SDkwLjAzMThaTTkwLjAzMTkgMjEzLjcwMkM4OC4zOTI3IDIxMy43MDIgODcuMDYzOCAyMTUuMDMxIDg3LjA2MzggMjE2LjY3Qzg3LjA2MzggMjE4LjMwOSA4OC4zOTI3IDIxOS42MzggOTAuMDMxOSAyMTkuNjM4SDk1Ljk2ODFDOTcuNjA3MyAyMTkuNjM4IDk4LjkzNjIgMjE4LjMwOSA5OC45MzYyIDIxNi42N0M5OC45MzYyIDIxNS4wMzEgOTcuNjA3MyAyMTMuNzAyIDk1Ljk2ODEgMjEzLjcwMkg5MC4wMzE5WiIgZmlsbD0iIzkxRDlCRSIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEyNTZfMzcxNjgiPgo8cmVjdCB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",Vy=S("templates");function N2(n){const t=n.rootElement.querySelector(":scope .editor-templates");if(!t)return null;const e=t.querySelector(":scope .editor-templates-cards");return g(Vy,e,"no card container"),{root:t,cardContainer:e}}function yW(n){const t=N2(n);if(t)return t.cardContainer.innerHTML="",t;const e=w("div",["editor-templates"],n.rootElement);w("div",["editor-templates-title"],e,R.t("templates.title"));const o=w("div",["editor-templates-cards"],e);return{root:e,cardContainer:o}}function Wy(n,t,e,o,r){var p;const i=(p=n.options.componentsOptions)==null?void 0:p.templates,s=w("div",["editor-template-card",...o],null),l=w("div",["editor-template-thumb-container"],s),a=w("img",["editor-template-thumb"],l);a.src=t,a.style.display="none",a.onerror=()=>{var v;const A=(v=i==null?void 0:i.placeHolderImageSrc)!=null?v:vW;a.src!==A&&(a.src=A)},a.onload=()=>{a.style.display=""};const d=w("div",["editor-template-name"],s),h=w("span",[],d,e);return i!=null&&i.showTemplateTitleAttr&&h.setAttribute("title",e),s.onclick=()=>r(s),s}function kW(n,t){return t.thumbnailUrl?t.thumbnailUrl:n.doc.buildResourceUrl("thumbnail.png")}function wW(n,t){const e=kW(n,t);return Wy(n,e,t.name,[],async()=>{var r,i;const o=(r=n.options.componentsOptions)==null?void 0:r.templates;(i=o==null?void 0:o.onApplyTemplate)==null||i.call(o,n,t)})}function BW(n,t){return Wy(n,t,R.t("templates.choose"),["more"],()=>{var o,r;const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onChooseTemplate)==null||r.call(e,n)})}function EW(n,t){var p,A;const e=(p=n.options.componentsOptions)==null?void 0:p.templates;if(!e)return;const r=Ge(n.rootContainer).getBoundingClientRect().width;let i=1;const s=bW,l=N2(n);if(l){if(t!=null&&t.reset){const v=Array.from(l.cardContainer.children),B=l.cardContainer.firstElementChild;if(g(Vy,B,"no first card"),xt(B,"new")||xt(B,"more"))return;const D=window.getComputedStyle(B),T=parseFloat(D.marginLeft),_=parseFloat(D.marginRight),M=B.getBoundingClientRect().width+T+_;i=Math.floor(r/M);const z=Math.max(1,i-1-1),q=v.length-1;v.forEach((rt,ft)=>{ft>z&&ft<q?rt.style.display="none":(ft>=q&&xt(rt,"more"),rt.style.display="")})}return}const a=e.templates,{cardContainer:d}=yW(n);a.forEach((v,B)=>{const D=wW(n,v);if(B>0&&B>=i&&(D.style.display="none"),d.appendChild(D),B===0){const T=window.getComputedStyle(D),_=parseFloat(T.marginLeft),M=parseFloat(T.marginRight),H=D.getBoundingClientRect().width+_+M;i=Math.floor(r/H)-1}});const h=BW(n,s);d.appendChild(h),(A=e==null?void 0:e.onTemplateChooserStatusChanged)==null||A.call(e,n,d,"visible")}const qy=He.default(EW,50);function xW(n){var o,r;const t=N2(n);if(!t)return;t.root.remove();const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onTemplateChooserStatusChanged)==null||r.call(e,n,null,"hide")}function IW(n){const t=n.blocks.root;if(t.length===0)return!0;if(t.length>5)return!1;const e=[...t];e[0].type==="text"&&e[0].heading&&e.splice(0,1);const o=r=>{var i;return r.type!=="text"&&r.type!=="list"?!1:r.text?((i=r.text)==null?void 0:i.length)===0:!0};return e.every(r=>o(r))}function n1(n,t){IW(n.doc.toJSON())?qy(n,t):(qy.cancel(),xW(n))}const TW=800;class DW{constructor(t){m(this,"longPressTimeout",0);m(this,"handleSelectionChange",()=>{});m(this,"handleLongPress",t=>{const e=t.touches[0],o=oh(this.editor,e.clientX,e.clientY);!o||console.log(o)});m(this,"handleTouchStart",t=>{t.touches.length===1&&(this.longPressTimeout=window.setTimeout(()=>{this.handleLongPress(t)},TW))});m(this,"handleTouchEnd",t=>{this.longPressTimeout&&(window.clearTimeout(this.longPressTimeout),this.longPressTimeout=0)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange),document.addEventListener("touchstart",this.handleTouchStart),document.addEventListener("touchend",this.handleTouchEnd)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange),document.removeEventListener("touchstart",this.handleTouchStart),document.removeEventListener("touchend",this.handleTouchEnd)}}const SW=`<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
593
|
+
2. \u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306E\u9593\u306B\u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\u304C\u3042\u308B\u5834\u5408\u3001\u3053\u306E\u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u6BD4\u8F03\u3067\u304D\u306A\u3044\u3053\u3068\u306B\u306A\u308A\u307E\u3059\u3002`,user:"\u30D0\u30FC\u30B8\u30E7\u30F3\u4F5C\u6210\u8005\uFF1A{name}",auth:"\u3053\u306E\u30B9\u30DA\u30FC\u30B9\u3092\u7DE8\u96C6\u3059\u308B\u6A29\u9650\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7BA1\u7406\u8005\u306B\u3054\u9023\u7D61\u304F\u3060\u3055\u3044\u3002"},dropdownHeader:"\u73FE\u5728\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u308B\u30D0\u30FC\u30B8\u30E7\u30F3\u3060\u3051\u8868\u793A\u3055\u308C\u307E\u3059",dropdown:{header:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3"},noVersions:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u3042\u308A\u307E\u305B\u3093",lastVersion:"\u524D\u306E\u30D0\u30FC\u30B8\u30E7\u30F3",filterMemoed:"\u5099\u8003\u3042\u308A"}};R.mergeLang({"zh-CN":nV,"en-US":oV,"ja-JP":rV});var A8=(n=>(n.NEW="history-new",n.NEW_CHILD="history-new-child",n.DELETED="history-deleted",n.UPDATED="history-updated",n.HISTORY="history",n))(A8||{});const Tc="--op-color",Dc="--op-selected-color",Znt="";class iV{constructor(t){m(this,"root");this.content=t;const e=w("div",["editor-dialog-root"],null);e.append(t),this.root=e}show(t=document.body){t.append(this.root)}hide(){this.root.remove()}destroy(){}}function Xs(n){var e;let t;if(n.version!==-1){const o=new Date((e=n.created)!=null?e:n.version);t=_m(o,"YYYY-MM-DD hh:mm")}else t=R.t("version.latest");return t}function Xf(n){return n.source&&typeof n.source=="object"&&!!n.source.restore}const Qnt="";class sV{constructor(t,e){m(this,"textArea");m(this,"warning");m(this,"end",!1);m(this,"root");m(this,"handleBlur",()=>{var t,e;this.end||(e=(t=this.options)==null?void 0:t.onend)==null||e.call(t,this.textArea.value,!1)});m(this,"handleKeyDown",t=>{var e,o,r,i;t.isComposing||(t.key==="Enter"||t.key==="Tab"?(t.preventDefault(),(o=(e=this.options)==null?void 0:e.onend)==null||o.call(e,this.textArea.value,!1),this.end=!0):t.key==="Escape"&&(t.preventDefault(),(i=(r=this.options)==null?void 0:r.onend)==null||i.call(r,this.textArea.value,!0),this.end=!0))});m(this,"handleInput",t=>{const e=t.target,{value:o}=e;o.length>this.maxLength-10?this.warning.innerText=`${o.length}/${this.maxLength}`:this.warning.innerText="",this.autoSize()});var o,r;this.maxLength=t,this.options=e,this.root=w("div",["size-limit-textarea",...(o=e==null?void 0:e.classes)!=null?o:[]],null),this.textArea=w("textarea",["size-limit-textarea-input"],this.root),this.warning=w("div",["size-limit-textarea-warning"],this.root),this.textArea.addEventListener("input",this.handleInput),this.textArea.addEventListener("blur",this.handleBlur),this.textArea.addEventListener("keydown",this.handleKeyDown),this.textArea.maxLength=t,this.textArea.placeholder=(r=e==null?void 0:e.placeholder)!=null?r:""}destroy(){this.textArea.removeEventListener("input",this.handleInput),this.textArea.removeEventListener("blur",this.handleBlur),this.textArea.removeEventListener("keydown",this.handleKeyDown)}setValue(t){this.textArea.value=t,this.autoSize()}autoSize(){const t=Math.max(this.textArea.scrollHeight,60);this.textArea.style.height="auto",this.textArea.style.height=`${t}px`}resetSize(){this.textArea.style.height="auto";const t=Math.max(this.textArea.scrollHeight,60);this.textArea.style.height=`${t}px`}focus(){this.textArea.focus(),this.end=!1}}const Ynt="",{t:Qn}=R,b8=S("version-list");class lV{constructor(t){m(this,"versionsList");m(this,"versionsListHeader");m(this,"versionFilterToolbar");m(this,"memoInput",null);m(this,"selectedVersion",0);m(this,"handleClickVersionItem",t=>{const e=t.target,o=e.closest(".version-item");if(!this.isVersionElement(o))return;const r=xt(o,"active");if(r&&e.closest(".version-item-memo")&&this.options.enableEdit){this.editItemMemo(o);return}const i=this.getVersionFromElement(o);if(this.setActiveItem(o),e.closest(".add-memo-button")&&this.options.enableEdit){this.handleAddMemo(i,o);return}if(e.closest(".revert-button")&&this.options.enableEdit){this.handleRevert(i,o);return}if(r)return;const{onSelectVersion:s}=this.options;s(i)});m(this,"handleEndEditItemMemo",(t,e)=>{var r,i;const o=(r=this.memoInput)==null?void 0:r.root.closest(".version-item");if(this.isVersionElement(o)&&(et(o,"editing"),!e)){const s=this.getVersionFromElement(o),l=t.replace(/[\n\r]+/g," ");if(((i=s.extra)==null?void 0:i.memo)!==l){s.extra={memo:l},this.options.versionHelper.updateVersionExtra(s.version,s.tagId,s.extra).then(()=>{var d,h;(h=(d=this.options).onMemoChanged)==null||h.call(d,s)});const a=o.querySelector(".version-item-memo");g(b8,a,"no memo element"),a.textContent=l}}setTimeout(()=>{var s;(s=this.memoInput)==null||s.root.remove()})});m(this,"handleRevert",(t,e)=>{const{onRevert:o}=this.options;o(t)});m(this,"handleFilterClick",(t,e)=>{let o=this.options.versions;e.id==="memoed"&&(o=o.filter(i=>{var s;return!!((s=i.extra)!=null&&s.memo)}));const r=this.createVersionItems(o,e.id);this.versionsList.innerHTML="",this.versionsList.append(r),this.versionFilterToolbar.updateItems(this.getFilterItems(e.id)),this.updateHeaderCount(o.length)});var d,h;this.options=t;const{versions:e}=t,o=w("div",["version-list-header"],null),r=Qn("version.versionList",{count:`${e.length}`});w("span",["version-count"],o,r);const i=w("div",["version-list-filter"],o);this.versionFilterToolbar=new rM(i,this.getFilterItems("all"),{tooltipId:"version-viewer"}),this.versionFilterToolbar.addListener("click",this.handleFilterClick),this.selectedVersion=t.selectedVersion||((d=e[0])==null?void 0:d.version)||-1;const s=w("div",["version-list-content"],null),l=this.createVersionItems(e,"all");s.append(l),this.versionsList=s,this.versionsListHeader=o,s.onclick=this.handleClickVersionItem;const a=this.activeVersion;a&&((h=this.options)==null||h.onSelectVersion(a))}getFilterItems(t){return[{id:"filter",name:Qn(t==="all"?"version.filter.all":"version.filter.memoed"),dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",children:[{id:"all",states:t==="all"?["checked"]:[],name:Qn("version.filter.allVersions")},{id:"memoed",states:t==="memoed"?["checked"]:[],name:Qn("version.filter.memoVersions")}]}]}createVersionItems(t,e){const o=document.createDocumentFragment();if(t.length===0){const i=w("div",["version-list-empty"],o);return i.textContent=Qn("version.noMemoedVersion"),o}const r=(i,s,l,a=!1)=>{var T,_;const d=w("div",["version-item"],o);d.versionData=i,s&&W(d,"child"),i.version===this.selectedVersion&&W(d,"active");const h=w("div",["version-item-title"],d);w("div",["version-item-date"],h,Xs(i)),a&&w("div",["version-item-latest"],h,Qn("version.latest")),w("div",["spacer"],h);const p=w("div",["version-actions"],h),A=w("button",["add-memo-button"],p);if(A.textContent=Qn("version.memo"),this.options.enableEdit||(W(A,"disabled"),A.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth"))),!a){const M=w("button",["revert-button"],p);M.textContent=Qn("version.revert"),this.options.enableEdit||(W(M,"disabled"),M.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth")))}let v="";if(typeof i.source=="object"&&((T=i.source)==null?void 0:T.restore)){const M=i.source.restore,H=l.find(q=>q.version==M),z=H?Xs(H):Qn("version.unknown");v=Qn("version.restoreFrom",{from:z})}w("div",["version-item-restore-from"],d,v),w("div",["version-item-memo"],d,((_=i.extra)==null?void 0:_.memo)||"");const B=w("ul",["version-item-authors"],d),D=M=>{const H=w("li",["version-item-author"],B),z=w("span",["version-item-author-mark"],H);z.style.background=this.options.getMarkColor(M),w("span",["version-item-author-name"],H,M.displayName).setAttribute("data-editor-tooltip-common",R.t("version.tooltip.user",{name:M.displayName}))};if(this.options.useCreatedBy)if(i.createdBy){const M=i.createdBy;D(M)}else i.authors&&i.authors.length>0&&i.authors.forEach(M=>{D(M)});else if(i.authors&&i.authors.length>0)i.authors.forEach(M=>{D(M)});else if(i.createdBy){const M=i.createdBy;D(M)}};return t.forEach((i,s)=>{r(i,!1,t,s===0),i.minorVersions&&i.minorVersions.length>0&&i.minorVersions.forEach(l=>{r(l,!0,t,!1)})}),o}isVersionElement(t){return t?xt(t,"version-item"):!1}getVersionFromElement(t){return t.versionData}get activeVersion(){return this.options.versions.find(t=>t.version===this.selectedVersion)}setActiveItem(t){if(xt(t,"active"))return;const e=this.versionsList.querySelector(".version-item.active");e&&et(e,"active"),W(t,"active"),this.selectedVersion=this.getVersionFromElement(t).version}handleAddMemo(t,e){this.editItemMemo(e)}editItemMemo(t){var o;this.memoInput||(this.memoInput=new sV(256,{onend:this.handleEndEditItemMemo,classes:["memo-input"],placeholder:Qn("version.textarea.placeholder")}));const e=t.querySelector(".version-item-restore-from");g(b8,e,"no title element"),e.insertAdjacentElement("afterend",this.memoInput.root),W(t,"editing"),this.memoInput.setValue(((o=t.versionData.extra)==null?void 0:o.memo)||""),this.memoInput.resetSize(),this.memoInput.focus()}updateHeaderCount(t){const e=this.versionsListHeader.querySelector(".version-count");e&&(e.textContent=Qn("version.versionList",{count:`${t.toString()}`}))}getVersionItemByVersionNum(t){const e=Array.from(this.versionsList.children).find(o=>o.versionData.version===t);return this.isVersionElement(e)?e:null}selectVersionByVersionNum(t){const e=this.getVersionItemByVersionNum(t);return e?(this.setActiveItem(e),this.getVersionFromElement(e)):null}render(t){t.innerHTML="",t.append(this.versionsListHeader,this.versionsList)}destroy(){this.versionsList.onclick=null,this.versionFilterToolbar.destroy()}}class cV{constructor(t,e){this.doc=t,this.user=e}onDeleteBlock(t,e){this.doc.onDeleteBlock(t,e,this.user)}onInsertBlock(t,e,o){this.doc.onInsertBlock(t,e,o,this.user)}onUpdateBlockText(t,e,o){this.doc.onUpdateBlockText(t,e,o,this.user)}onUpdateBlockData(t,e,o){this.doc.onUpdateBlockData(t,e,o,this.user)}onCreateContainer(t,e){this.doc.onCreateContainer(t,e,this.user)}onCreateComment(){}onDeleteComment(){}onDeleteContainer(){}onUpdateComment(){}}async function aV(n,t,e){for(const o of e){const r=new cV(n,o.user);t.parseHistoryData(o,r)}}const An=S("split-text-actions");function v8(n){return n.length>2?!1:n.length===1?n[0].insert!==void 0:(g(An,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].insert!==void 0)}function y8(n){return n.length>2?!1:n.length===1?n[0].delete!==void 0:(g(An,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].delete!==void 0)}function k8(n){return n.length>2?!1:n.length===1?n[0].insert===void 0&&n[0].delete===void 0&&n[0].attributes!==void 0:(g(An,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].attributes!==void 0)}function uV(n){const t=[],e=mt.default(n);if(e.length===0)return[];if(e.length===1)return[n];if(e.length===2&&(y8(n)||v8(n)||k8(n)))return[n];const o=(i,s)=>i>0?[{retain:i},s]:[s];let r=0;for(;e.length>0;){const i=e[0];if(i.retain!==void 0&&i.attributes===void 0){g(An,i.retain>0,`invalid text op: ${JSON.stringify(i)}`),g(An,e.length>1,`invalid text op: ${JSON.stringify(i)}`);const s=e[1];g(An,s.delete||s.insert!==void 0||s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=i.retain,t.push(o(r,s)),s.delete!==void 0?r-=s.delete:s.insert!==void 0?r+=s.insert.length:(g(An,s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),g(An,s.retain!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=s.retain),e.splice(0,2)}else g(An,i.delete||i.insert!==void 0||i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),t.push(o(r,i)),e.shift(),i.retain!==void 0&&(g(An,i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),r+=i.retain),i.insert&&(r+=i.insert.length)}return t}function w8(n){if(g(An,n.length===1||n.length===2,`not a single action op: ${JSON.stringify(n)}`),n.length===1)return 0;const t=n[0].retain;return g(An,typeof t=="number"&&t>0,`invalid retain: ${JSON.stringify(n)}`),t}let B8=0;function dV(n,t,e){const o=B8;B8+=1;const r=re(n);return{insert:" ",attributes:{box:!0,id:K(),type:"history-deleted-box",user:e,created:Date.now(),text:r,deletedOffset:t,deletedOrder:o}}}function hV(n,t,e){const o=w8(t),r=t.length===1?t[0].delete:t[1].delete;g(An,typeof r=="number",`not a delete op: ${JSON.stringify(t)}`);const{left:i,middle:s,right:l}=ze(n,o,r),a=dV(s,o,e);return[...i,a,...l]}function fV(n,t,e){const o=w8(t),r=t.length===1?t[0].insert:t[1].insert;g(An,typeof r=="string",`invalid insert op: ${JSON.stringify(t)}`);const i=t.length===1?t[0].attributes:t[1].attributes,l=uh([{insert:r,attributes:i}],"insertedBy",e);return Hr(n,o,l,null)}function mV(n,t,e){const o=uV(t);let r=n;for(const i of o)y8(i)?r=hV(r,i,e):v8(i)?r=fV(r,i,e):(g(An,k8(i),`unknown op: ${JSON.stringify(i)}`),r=ln.apply(r,i));return r}const gV=S("history-update-block-text");function E8(n){const t=[],e=[];let o=0;return n.forEach(r=>{var i;if((i=r.attributes)!=null&&i.box){const s=r.attributes;if(s.type==="history-deleted-box"){t.push({boxData:s,offset:o});return}}e.push(r),o+=ah(r)}),t.sort((r,i)=>i.offset-r.offset),{deletedBoxes:t,newText:e}}function pV(n,t,e){let o=n;return t.forEach(r=>{const i=ln.transformCursor(r.offset,e,!1);o=Hr(o,i,[{insert:" ",attributes:r.boxData}],null)}),o}function CV(n){n.sort((t,e)=>t.boxData.deletedOffset!==e.boxData.deletedOffset?t.boxData.deletedOffset-e.boxData.deletedOffset:t.boxData.deletedOrder-e.boxData.deletedOrder)}function AV(n){if(n.length<=1)return n;const t=n[0].offset;n.forEach(e=>{g(gV,e.offset===t,`invalid boxes group, ${JSON.stringify(n)}`)}),CV(n);for(let e=n.length-1;e>=1;e--){const o=n[e],r=n[e-1];o.boxData.user.userId===r.boxData.user.userId&&(r.boxData.text+=o.boxData.text,n.splice(e,1))}return n}function bV(n){let{newText:t,deletedBoxes:e}=E8(n);const o=new Map;return e.forEach(i=>{let s=o.get(i.offset);s||(s=[],o.set(i.offset,s)),s.push(i),s.sort((l,a)=>l.boxData.deletedOffset-a.boxData.deletedOffset)}),Array.from(o.values()).sort((i,s)=>s[0].offset-i[0].offset).forEach(i=>{const s=i[0].offset;AV(i).reverse().forEach(l=>{t=Hr(t,s,[{insert:" ",attributes:l.boxData}],null)})}),t}function vV(n,t,e){let{newText:o,deletedBoxes:r}=E8(n);return o=mV(o,t,e),o=pV(o,r,t),o=bV(o),o}const Ar=S("history-doc");function br(n){g(Ar,!1,"no local actions for history doc")}class yV extends fa{constructor(t,e){super(),this.externalDoc=t,this.docObject=e}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.docObject)}getContainerBlocks(t){return this.docObject.blocks[t]}getBlockData(t,e){const o=this.getContainerBlocks(t);g(Ar,o,`no container data: ${t}`);const r=o[e];return g(Ar,r,`no block data: ${e}`),r}localUpdateBlockText(){br()}localUpdateBlockData(){br()}localInsertBlock(){br()}localDeleteBlock(){br()}localInsertChildContainer(){br()}localDeleteChildContainers(){br()}uploadResource(){br()}async addResources(t){br()}getServerMeta(){var t,e,o;return(o=(e=(t=this.externalDoc).getServerMeta)==null?void 0:e.call(t))!=null?o:{}}buildResourceUrl(t){return this.externalDoc.buildResourceUrl(t)}request(){br()}broadcastMessage(){br()}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new _h}destroy(){this.clearCallbacks()}transformBlockIndex(t,e,o){const r=this.docObject.blocks[t];g(Ar,r,`no container blocks: ${t}`);let i=0;for(let s=0;s<r.length;s++)if(!r[s].deletedBy){if(i===e)return s;i++}return o&&g(Ar,!1,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),g(Ar,i===e,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),r.length}onDeleteBlock(t,e,o){const r=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t][r];g(Ar,!s.deleted,`block has already deleted: ${t}/${e}`),s.deletedBy=o,this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockData)==null?void 0:a.call(l,t,r,{insert:{},delete:[]},!0)})}onInsertBlock(t,e,o,r){const i=this.transformBlockIndex(t,e,!1),s=this.docObject.blocks[t],l=mt.default(o);l.insertedBy=r,s.splice(i,0,l),this.callbacks.forEach(a=>{var d;return(d=a.onInsertBlock)==null?void 0:d.call(a,t,i,l,!0)})}onUpdateBlockText(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),l=this.docObject.blocks[t][i];g(Ar,!l.deleted,`block has already deleted: ${t}/${e}`);const a=l.text;g(Ar,a,`no text for block: ${JSON.stringify(l)}`);const d=vV(a,o,r);l.text=d,this.callbacks.forEach(h=>{var p;return(p=h.onUpdateBlockText)==null?void 0:p.call(h,t,i,o,!0)})}onUpdateBlockData(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t],l=s[i];g(Ar,!l.deleted,`block has already deleted: ${t}/${e}`);const a=mt.default(l);a.updatedBy=r,o.delete.forEach(d=>delete a[d]),Object.entries(o.insert).forEach(([d,h])=>{a[d]=h}),s[i]=a,this.callbacks.forEach(d=>{var h;return(h=d.onUpdateBlockData)==null?void 0:h.call(d,t,i,o,!0)})}onCreateContainer(t,e,o){this.docObject.blocks[t]=mt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,t,e,!0)})}}const{t:x8}=R;function Sc(n,t){return t==="insert"?x8("version.insert",{name:n.displayName}):x8("version.delete",{name:n.displayName})}function tl(n,t){const{userId:e}=t;return["flag","selection"].reduce((r,i)=>{const s=n.getRemoteUsers().getFixedUserColor(e,i);return r[i]=s,r},{})}class kV{renderText(t,e,o){if(!o.box&&o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,o.insertedBy);return{classes:["history-inserted-text"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Sc(r,"insert")},styles:{[Tc]:i,[Dc]:s}}}return{}}renderBlock(t,e,o){if(o.deletedBy){const r=o.deletedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-deleted-block"],attributes:{"history-deleted-by":r.displayName,"data-op-description":Sc(r,"delete")},styles:{[Tc]:i,[Dc]:s}}}if(o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-inserted-block"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Sc(r,"insert")},styles:{[Tc]:i,[Dc]:s}}}return{}}updateBlock(t,e,o,r){if(r.deletedBy){const i=r.deletedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-deleted-block"),bm(o,{"history-inserted-by":i.displayName,"data-op-description":Sc(i,"delete")}),vm(o,{[Tc]:s,[Dc]:l});return}if(r.insertedBy){const i=r.insertedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-inserted-block"),bm(o,{"history-inserted-by":i.displayName,"data-op-description":Sc(i,"insert")}),vm(o,{[Tc]:s,[Dc]:l})}}}const I8=S("history-deleted-box");function wV(n,t,e,o){const r=o;g(I8,r.text,`no text for text box data: ${JSON.stringify(o)}`),g(I8,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`);const i=w("span",["history-deleted-box"],e,r.text),s=r.user,{flag:l,selection:a}=tl(n.doc,s);i.setAttribute("history-deleted-by",s.displayName),i.setAttribute("data-op-description",Sc(s,"delete")),i.style.setProperty(Tc,l),i.style.setProperty(Dc,a)}function BV(n,t,e,o){return t.text}const EV={boxType:"history-deleted-box",updateBoxContent:wV,convertTo:BV},Jnt="",xV=S("versions-dropdown"),T8=(n,t)=>{if(!t)return n;let e="";const o=t.length,r=t.toLocaleLowerCase();let i=0;for(i=0;i<=n.length-o;i){let s=n.substring(i,i+o);if(s.toLocaleLowerCase()===r){i+=o;const l=n.charAt(i);let a=!1;s.endsWith(" ")&&(a=!0,s=s.trimEnd()),e+=`<span class="highlight">${s}${l===" "||a?" ":""}</span>`}else e+=n.charAt(i),i++}return i<n.length&&(e+=n.substring(i)),e};class IV{constructor(t,e){m(this,"dropdown");m(this,"versions",[]);m(this,"currentVersion",null);m(this,"compareWithVersion",null);m(this,"filterMemoed",!1);m(this,"keywords","");m(this,"createFilterMemoedFilterItem",t=>{const e=w("div",["filter-memoed-version-item"],null);t&&w("div",["filter-item-info"],e,R.t("version.dropdown.header"));const o=w("div",["filter-item-input-container"],e),r=w("input",["filter-item-input"],o);r.id="filter-item-input",r.type="checkbox";const i=w("label",["filter-item-label"],o,R.t("version.filterMemoed"));return i.htmlFor=r.id,r.onchange=this.handleInputChange,r.checked=this.filterMemoed,e});m(this,"filterItems",(t,e)=>{var i,s;if(this.keywords=e,!e)return!0;if(t.id==="section")return!1;const o=e.toLocaleLowerCase();if(t.name.toLocaleLowerCase().indexOf(o)!==-1)return!0;const r=t.data;return!!(r&&((i=r.extra)==null?void 0:i.memo)&&((s=r.extra)==null?void 0:s.memo.toLocaleLowerCase().indexOf(o))!==-1)});m(this,"handleClose",()=>{});m(this,"handleClear",()=>{this.options.onCompareWithVersion(null)});m(this,"handleClickItem",t=>{const e=t.data,o=Xs(e);this.dropdown.setText(o),this.options.onCompareWithVersion(e)});m(this,"handleInputChange",t=>{const e=t.target;this.filterMemoed=e.checked,this.resetItems()});this.options=e,this.dropdown=new Rp(t,{placeholder:R.t("version.noSelectedVersion"),emptyPlaceholder:R.t("version.noFilterVersion"),popupId:"versions-dropdown-popup",header:this.createHeader(),filter:this.filterItems,onClose:this.handleClose,onClickItem:this.handleClickItem,onClear:this.handleClear,highlight:!0})}createHeader(){const t=w("div",["versions-dropdown-header"],null),e=w("span",["versions-dropdown-header-info"],t);e.innerHTML=R.t("version.dropdownHeader");const o=w("span",["versions-dropdown-header-icon"],t);return o.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.help")),o.setAttribute("data-editor-tooltip-placement","right"),o.innerHTML=fv,o.onclick=this.options.onHelp,t}setVersions(t){this.versions=t}setCurrentVersion(t,e){this.dropdown.setText(""),this.dropdown.setLabels([]),e&&(this.dropdown.setText(Xs(e)),(e.version===-1||e.version===this.versions[0].version)&&this.dropdown.setLabels([R.t("version.latest")])),this.currentVersion=t,this.compareWithVersion=e!=null?e:null,this.resetItems()}resetItems(){var A;if(this.versions.length===0)return;const t=this.currentVersion;if(!t)return;const e=t.version===-1?0:this.versions.findIndex(v=>v.version===t.version);g(xV,e!==-1,"version not found");const o=this.versions[0],r=v=>{var H;const B=v.data,D=w("div",["version-item-container"],null),T=w("div",["version-item-line1"],D),_=v.value==="last-version"?R.t("version.lastVersion"):Xs(B),M=w("div",["version-item-name"],T);if(this.keywords?M.innerHTML=T8(_,this.keywords):M.innerText=_,B.version===o.version&&w("div",["version-item-latest"],T,R.t("version.latest")),(H=B.extra)!=null&&H.memo){const z=w("div",["version-item-line2"],D),q=w("div",["version-item-memo"],z,B.extra.memo);this.keywords?q.innerHTML=T8(B.extra.memo,this.keywords):q.innerText=B.extra.memo,q.setAttribute("data-editor-tooltip-common",B.extra.memo),q.setAttribute("data-editor-tooltip-placement","bottom")}return D.onclick=()=>{this.handleClickItem(v),this.dropdown.close()},D},i=[],s=this.versions[e+1],l=s&&!Xf(t);if(l){const v={id:"section",value:"last-version",name:"Last version",data:s,element:r};i.push(v)}let a=e;for(let v=e-1;v>=0;v-=1){const B=this.versions[v];if(Xf(B))break;a=v}let d=e;if(!Xf(t))for(let v=e+1;v<this.versions.length;v+=1){const B=this.versions[v];if(d=v,Xf(B))break}let h=!1;const p=[];for(let v=a;v<=d;v+=1){const B=this.versions[v];if(B.version!==t.version&&B.version!==(s==null?void 0:s.version)&&(!this.filterMemoed||((A=B.extra)==null?void 0:A.memo))){h=!0;let D=Xs(B),T=`${B.version}`;v===e+1&&(D="Previous version",T="prev-version");const _={id:T,name:D,data:B,element:r};p.push(_)}}if((l||h||this.filterMemoed)&&i.push({id:"section",name:"",element:this.createFilterMemoedFilterItem(i.length>0&&l),states:["disabled"]}),i.push(...p),!h){const v={id:"section",name:"No versions",states:["disabled"],element:w("span",["version-item-empty"],null,R.t("version.noVersions"))};i.push(v)}this.dropdown.updateItems(i)}}class TV{constructor(t,e){m(this,"left");m(this,"right");m(this,"dropdown");const o=w("div",["version-info-container"],t);this.left=w("div",["version-info-left"],o),this.dropdown=new IV(o,e),this.right=w("div",["version-info-right"],o)}setVersion(t,e,o){const r=`<span class="version-item-latest">${R.t("version.latest")}</span>`,i=`${Xs(t)}${o?r:""}`;this.left.innerHTML=R.t("version.versionInfoLeft",{versionName:i}),this.right.innerHTML=R.t("version.versionInfoRight",{versionName:i}),this.dropdown.setCurrentVersion(t,e)}}const es=S("version-dialog");class D8{constructor(t,e){m(this,"dialog",null);m(this,"oldViewer",null);m(this,"versionOptions");m(this,"versionList",null);m(this,"provider");m(this,"versions",[]);m(this,"components");m(this,"handleRevert",async t=>{var o,r,i;g(es,this.versionList,"The versionList did not render");const e=t!=null?t:(o=this.versionList)==null?void 0:o.activeVersion;g(es,e,`The version: ${e} is invalid`),!(((r=this.versionOptions)==null?void 0:r.onBeforeRevert)&&await this.versionOptions.onBeforeRevert(e))&&(await this.versionHelper.revertVersion(e.version),(i=this.dialog)==null||i.hide())});m(this,"handleSelectVersion",t=>{g(es,t,`The version: ${t} is invalid`),this.viewVersion(t)});m(this,"handleCompareWithVersion",t=>{var o;const e=(o=this.versionList)==null?void 0:o.activeVersion;g(es,e,"no active version"),this.viewVersion(e,t!=null?t:void 0)});m(this,"handleHelp",()=>{var t,e;(e=(t=this.versionOptions)==null?void 0:t.onHelp)==null||e.call(t)});m(this,"viewVersion",async(t,e)=>{var h,p;const o=this.versions[0].version===t.version;if(this.components.infoHeader.setVersion(t,e,o),this.oldViewer&&(this.oldViewer.destroy(),this.oldViewer=null),!this.versionList)return;(h=this.versionOptions)!=null&&h.onWillChangeVersion&&this.versionOptions.onWillChangeVersion(this,t);const r=e==null?void 0:e.version;let i,s;if(r){const A=Math.min(t.version,r),v=Math.max(t.version,r),B=await this.versionHelper.getHistoryData(v,A);i=B.doc,s=B.historyData}else i=await this.versionHelper.getVersion(t.version),s=[];const{editorContainer:l}=this.components;l.innerHTML="";const a=new yV(this.doc,i),d=this.provider.createHistoryEditor(l,a);d.editorBlockRenders.registerRender(new kV),d.editorBoxes.registerBoxClass(EV),W(d.rootElement,A8.HISTORY);try{await aV(a,this.versionHelper,s)}finally{this.oldViewer=d}(p=this.versionOptions)!=null&&p.onVersionChanged&&this.versionOptions.onVersionChanged(this,d,t)});m(this,"onMemoChanged",t=>{var e,o;(o=(e=this.versionOptions)==null?void 0:e.onMemoChanged)==null||o.call(e,t),this.components.infoHeader.dropdown.resetItems(),this.components.infoHeader.dropdown.setVersions(this.versions)});this.doc=t,this.provider=e;const o=w("div",["version-dialog"],null),r=w("div",["version-viewer"],o),i=new TV(r,{onCompareWithVersion:this.handleCompareWithVersion,onHelp:this.handleHelp}),s=w("div",["version-dialog-editor"],r),l=w("div",["version-list-root"],o);this.components={root:o,editorContainer:s,listContainer:l,infoHeader:i}}get versionHelper(){g(es,this.doc.getVersionHelper,"Can not get getVersionHelper from doc");const t=this.doc.getVersionHelper();return g(es,t,"current doc does not support version"),t}get editor(){return this.oldViewer}renderContent(t){var r,i;const{listContainer:e}=this.components;e.innerHTML="";const o=new lV({enableEdit:((r=this.versionOptions)==null?void 0:r.enableEdit)||!1,versions:t,versionHelper:this.versionHelper,useCreatedBy:(i=this.versionOptions)==null?void 0:i.useCreatedBy,onSelectVersion:this.handleSelectVersion,onRevert:this.handleRevert,onMemoChanged:this.onMemoChanged,getMarkColor:s=>{const{flag:l}=tl(this.doc,s);return l}});o.render(e),this.versionList=o}initViewVersion(){var t;if(g(es,this.versionList,"no versionList"),(t=this.versionOptions)!=null&&t.initSelectedVersion){const{initSelectedVersion:e}=this.versionOptions,o=this.versionList.selectVersionByVersionNum(e);g(es,o,`version ${e} not found`),this.viewVersion(o)}else{const e=this.versionList.activeVersion;e&&this.viewVersion(e)}}async show(t){if(this.versionOptions={...this.versionOptions,...t},this.versions=await this.versionHelper.getVersions(),this.versionOptions.onVersionsLoaded&&this.versionOptions.onVersionsLoaded(this,this.versions),this.components.infoHeader.dropdown.setVersions(this.versions),this.renderContent(this.versions),this.initViewVersion(),!this.dialog){const{root:e}=this.components;this.dialog=new iV(e)}this.dialog.show(t.container)}destroy(){var t,e;(t=this.dialog)==null||t.destroy(),(e=this.versionList)==null||e.destroy()}}const DV={expandCollapseButton:{tips:"\u5C55\u5F00 / \u6536\u8D77"}},SV={expandCollapseButton:{tips:"Expand / Collapse"}},LV={expandCollapseButton:{tips:"\u5C55\u958B / \u7E2E\u5C0F"}};R.mergeLang({"zh-CN":DV,"en-US":SV,"ja-JP":LV});const Knt="",MV=S("heading-collapse");function S2(n){var e;const t=Number.parseInt((e=n.getAttribute("data-style-heading"))!=null?e:"",10);return g(MV,t,"not a heading block"),t}function fo(n){return!!n.getAttribute("data-style-heading")}function RV(n){return!xt(n,"heading-collapsed")}function el(n){return xt(n,"heading-collapsed")}function S8(n){if(ce(n))return!1;const e=nt(n);return Xt(e)}const OV=S("heading-collapse");function L2(n){g(OV,fo(n),"not a heading block");const t=[],e=S2(n);let o=Zt(n);for(;o&&!(fo(o)&&S2(o)<=e);)t.push(o),o=Zt(o);return t}function L8(n,t){if(!ro(t))return;n.selection.selectBlock(t,0),L2(t).forEach(o=>{UC(o)}),W(t,"heading-collapsed")}function Lc(n,t){L2(t).forEach(o=>{zC(o)}),et(t,"heading-collapsed")}function _V(n,t){RV(t)?L8(n,t):Lc(n,t)}const FV=[kp,wp,Bp,Ep,xp,Ip,Tp,Dp];function PV(n){const t=w("button",["heading-collapse-button"],null);return t.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("expandCollapseButton.tips")),t.innerHTML=Gh,t}function M8(n){return Mf(n).querySelector("button.heading-collapse-button")}function R8(n,t){M8(t)||S8(t)||!ro(t)||Q0(t,PV(n),-1)}function NV(n){var t;(t=M8(n))==null||t.remove()}function O8(n,t){Mf(t).querySelector("button.heading-collapse-button")||R8(n,t)}function $V(n){const t=S2(n),e=w("button",["heading-marker"],null);return e.innerHTML=FV[t-1],e}function _8(n){return Mf(n).querySelector("button.heading-marker")}function M2(n){_8(n)||S8(n)||!ro(n)||Q0(n,$V(n),1)}function F8(n){const t=_8(n);t==null||t.remove()}function P8(n){F8(n),fo(n)&&M2(n)}class HV{handleDrop(t,e,o,r){if(Wd(e)||!fo(e)||!el(e))return;const i=L2(e);i.unshift(e);const s=i.reverse();let l=null;return t.doc.beginBatchUpdate(),s.forEach((a,d,h)=>{const p=t.getBlockData(a),A=Fi(t.editorBlocks,t.doc.toJSON(),p),v=t.insertDocAt(o,r,A)[0];d===h.length-1&&(l=v)}),t.doc.endBatchUpdate(),t.doc.beginBatchUpdate(),s.forEach(a=>{t.deleteBlock(a)}),t.doc.endBatchUpdate(),l&&L8(t,l),!0}}const jV=S("heading-collapse");class R2{constructor(t){m(this,"handleLoad",()=>{this.showCollapseButtons()});m(this,"handleHoverBlock",(t,e)=>{e&&(et(e,"hovering-heading"),fo(e)&&Xt(nt(e))&&(M2(e),el(e)||NV(e))),t&&fo(t)&&Xt(nt(t))&&(W(t,"hovering-heading"),this.editor.readonly||F8(t),R8(this.editor,t))});m(this,"handleClick",(t,e)=>{const o=jl(e,"button.heading-collapse-button");if(!o)return;const r=ot(o);!r||(g(jV,fo(r),"not a heading block"),_V(this.editor,r),O8(this.editor,r))});this.editor=t,t.addListener("load",this.handleLoad),t.addListener("click",this.handleClick),pe.get(t).addListener("change",this.handleHoverBlock),this.showCollapseButtons(),setTimeout(()=>{var o;(o=Su.find(t))==null||o.addHandler(new HV)})}showCollapseButtons(){const t=ve(this.editor.rootContainer).filter(fo);t.length!==0&&(t[0]===Se(this.editor.rootContainer)&&t.splice(0,1),t.forEach(M2))}destroy(){this.editor.removeListener("load",this.handleLoad),this.editor.removeListener("click",this.handleClick)}}function t1(n){const t=n.selection.range;if(t.isCollapsed()||t.start.blockId===t.end.blockId)return;const e=n.getBlockById(t.start.blockId),o=n.getBlockById(t.end.blockId);el(e)&&Lc(n,e),el(o)&&Lc(n,o)}function UV(n){t1(n);const t=n.getFocusedBlock();!fo(t)||el(t)&&Lc(n,t)}function zV(n){t1(n);const t=n.getFocusedBlock();if(!fo(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===ut(n,t)&&el(t)&&Lc(n,t)}function VV(n){t1(n);const t=n.getFocusedBlock();if(!fo(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===0&&el(t)&&Lc(n,t)}class WV{handleBeforeKeyDown(t,e){return xm(e.key)&&t1(t),e.key==="Enter"?(UV(t),!1):e.key==="Delete"?(zV(t),!1):(e.key==="Backspace"&&VV(t),!1)}}class qV{constructor(t){this.editor=t}onInsertBlock(t,e,o,r){this.updateBlockIfNeeded(o.id)}onUpdateBlockData(t,e,o,r){const i=this.editor.doc.getBlockData(t,e);this.updateBlockIfNeeded(i.id,o)}updateBlockIfNeeded(t,e){setTimeout(()=>{const o=this.editor.findBlockById(t);if(!!o){if(!fo(o)){e&&e.delete.includes("heading")&&P8(o);return}xt(o,"hovering-heading")&&O8(this.editor,o),P8(o)}},100)}}function GV(n){return!!n.heading}function N8(n){var e;const t=n.heading;return(e=Number.parseInt(`${t}`,10))!=null?e:1}function $8(n,t,e){var i;const o=Ms(n,t.type);let r="";if(o.convertTo){const s=jr();r=o.convertTo(n,t,s,"text",[{containerId:"root",blockIndex:0}]),r=r.replace(/\n/g,"").trim()}else r=re((i=t.text)!=null?i:[]);return{parentNode:e,children:[],text:r,level:N8(t),block:t}}class Pu{constructor(t){m(this,"nodes",[]);this.editor=t}appendBlock(t){const e=this.findParent(N8(t),this.nodes);e?e.children.push($8(this.editor,t,e)):this.nodes.push($8(this.editor,t,null))}findParent(t,e){const o=e[e.length-1];if(!o||t<=1)return null;if(o.level===t-1)return o;const r=this.findParent(t,o.children);return r||(o.level<t?o:null)}static buildToc(t,e){const o=new Pu(t),r=e.blocks.root;for(let i=0;i<r.length;i++){const s=r[i];GV(s)&&o.appendBlock(s)}return o}}class nl extends be.TypedEmitter{constructor(e){super();m(this,"toc");m(this,"updateToc",He.default(()=>{this.updateTocNow()},500));this.editor=e,e.doc.registerCallback(this),this.updateToc(),this.toc=new Pu(this.editor)}destroy(){this.editor.doc.unregisterCallback(this)}isHeadingBlock(e){return!!e.heading}onInsertBlock(e,o,r,i){e==="root"&&this.isHeadingBlock(r)&&this.updateToc()}onDeleteBlock(e,o,r){e==="root"&&this.updateToc()}onUpdateBlockText(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}onUpdateBlockData(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}static register(e){return e.addCustom("editor-toc",()=>new nl(e))}static get(e){return e.getCustom("editor-toc")}updateTocNow(){this.toc=Pu.buildToc(this.editor,this.editor.doc.toJSON()),this.emit("change",this.editor,this.toc)}}const Xnt="";function ZV(n){return n.nodes.length===0?!0:n.nodes.length>1?!1:n.nodes[0].children.length===0}function H8(n,t){t.forEach(e=>{const o=w("div",["toc-node"],n),r=w("div",["toc-title"],o);if(w("span",["toc-text"],r,e.text).setAttribute("data-block-id",e.block.id),e.children.length>0){const s=w("div",["toc-children"],o);H8(s,e.children)}})}function QV(n,t){const e=jl(t,".toc-text");if(!e)return;const o=e.getAttribute("data-block-id");if(!o)return;const r=n.findBlockById(o);!r||(t.preventDefault(),t.stopPropagation(),n.selection.selectBlock(r,0))}function j8(n,t,e){if(et(t,"loading"),t.innerHTML="",ZV(e)){w("div",["toc-empty-message"],t,R.t("toc.empty"));return}if(e.nodes.length>=1){const[o,...r]=e.nodes,i=[...o.children,...r];H8(t,i)}op(n,"toc-click-handler",()=>{n.addListener("click",QV)})}class YV{constructor(t){m(this,"handleUpdateToc",(t,e)=>{Array.from(t.rootContainer.querySelectorAll('.embed-block[data-type="editor-block"][data-embed-type="toc"]')).forEach(r=>{const i=r.querySelector(".editor-toc-container");i&&j8(t,i,e)})});this.editor=t,nl.register(t).addListener("change",this.handleUpdateToc)}destroy(){nl.register(this.editor).removeListener("change",this.handleUpdateToc)}get toc(){return nl.register(this.editor).toc}}function JV(n,t){const e=w("div",["editor-toc-container"],t),r=n.addCustom("init-editor-toc",()=>new YV(n)).toc;r.nodes.length===0?W(e,"loading"):j8(n,e,r)}function KV(n,t,e,o){return o==="markdown"?"[toc]":""}function XV(n,t,e){const{data:o}=e;if(!o||o.embedType!=="toc"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"toc",embedData:r}}}const U8={embedType:"toc",createEmbedContent:JV,convertTo:KV,convertFrom:XV},tW={toc:{empty:"No Toc"}},eW={toc:{empty:"No Toc"}},nW={toc:{empty:"No Toc"}};R.mergeLang({"zh-CN":tW,"en-US":eW,"ja-JP":nW});function oW(n){return!!n.getAttribute("data-style-heading")}function O2(n,t){return oW(t)&&ut(n,t)>0}function rW(n){const t=oo(n.rootElement);let e=0,o=0,r=0;if(t===document.documentElement){const i=n.rootContainer.getBoundingClientRect();e=i.left+i.width/2,o=10,r=t.offsetHeight}else{const i=t.getBoundingClientRect();e=i.left+i.width/2,o=i.top+10,r=i.bottom}for(;o<r;){const i=document.elementsFromPoint(e,o);for(let s=0;s<i.length;s++){const l=ot(i[s]);if(l&&n.rootContainer.contains(l))return l}o+=10}return null}function _2(n,t){let e=t;for(;e&&!O2(n,e);)e=Zt(e);return e}function z8(n){if(ce(n))return!1;const e=nt(n);return Xt(e)}function e1(n,t){let e=t;for(;e&&!O2(n,e);)e=ce(e),e&&z8(e)&&(e=null);return e}const iW=.3;class sW extends be.TypedEmitter{constructor(e){super();m(this,"scrollContainer");m(this,"scrollEventTarget");m(this,"scrollStatus",{curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null});m(this,"handleScroll",He.default(()=>{const e={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null};let o=rW(this.editor);if(o&&(o=Vm(o)),!o||!this.scrollContainer){this.setStatus(e);return}if(z8(o)&&(o=Zt(o)),!o){this.setStatus(e);return}if(O2(this.editor,o)){e.curHeadingBlock=o,e.previousHeadingBlock=e1(this.editor,o),e.nextHeadingBlock=_2(this.editor,o),this.setStatus(e);return}const r=this.scrollContainer.getBoundingClientRect(),i=_2(this.editor,o);if(i){const l=i.getBoundingClientRect();if(l.top>r.top&&l.top<r.top+r.height*iW){e.curHeadingBlock=i,e.previousHeadingBlock=e1(this.editor,i),e.nextHeadingBlock=_2(this.editor,i),this.setStatus(e);return}e.nextHeadingBlock=i}const s=e1(this.editor,o);s&&(e.curHeadingBlock=s,e.previousHeadingBlock=e1(this.editor,s)),this.setStatus(e)},200));this.editor=e,setTimeout(()=>{this.start()},50)}setStatus(e){this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock&&this.scrollStatus.nextHeadingBlock===e.nextHeadingBlock&&this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock||(this.scrollStatus=e,this.emit("change",this.editor,e))}start(){this.stop(),this.scrollContainer=oo(this.editor.rootElement),this.scrollEventTarget=this.scrollContainer===document.documentElement?document:this.scrollContainer,this.scrollEventTarget.addEventListener("scroll",this.handleScroll),this.handleScroll()}stop(){this.scrollEventTarget&&this.scrollEventTarget.removeEventListener("scroll",this.handleScroll)}destroy(){this.stop(),this.scrollEventTarget=void 0}}class F2{constructor(t,e){m(this,"suggest");m(this,"onClose",()=>{this.editor.focus()});m(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!ro(i)){const s=ot(nt(i));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e,o)=>{const r=e.data,i={id:K(),type:"mention",box:!0,created:Date.now(),iconUrl:r.avatarUrl,text:r.displayName,mentionId:r.userId},s=this.editor.selection.range;if(!s.isCollapsed()||!s.isSimple())return;const l=s.focus,a=this.editor.getBlockById(l.blockId);this.editor.insertBoxToBlock(a,l.offset,i)});m(this,"queryItems",async(t,e)=>(await this.options.queryUsers(this.editor,e)).map(i=>{const s=Qd(i.displayName);return{id:i.userId,name:i.displayName,icon:i.avatarUrl?`<img src="${i.avatarUrl}" class="mention-user-avatar">`:`<span style="background: ${s}" class="mention-user-avatar-string">${Zd(i.displayName,1)}</span>`,element:i.element,data:i,subText:i.email}}));this.editor=t,this.options=e,this.suggest=new Np(t,{id:"editor-mention",trigger:["@"],autoDeleteTrigger:!0,showLoading:!0,enableFirstBlock:e.enableFirstBlock,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,onClose:this.onClose})}destroy(){}}S("mathjax-box");function lW(n,t,e,o){const r=o,i=w("a",["mention-container"],e);w("span",["mention-name"],i,`@${r.text}`),i.setAttribute("data-mention-id",r.mentionId)}function cW(n,t,e){}function aW(n,t,e,o){return`@${t.text}`}function uW(){return{abstract:R.t("mention.abstract")}}const P2={boxType:"mention",updateBoxContent:lW,handleClickBox:cW,convertTo:aW,getBoxProperties:uW};function dW(n){const t=w("div",["mention-button-wrap"],null),e=ji("mention-button",R.t("list.mention.tooltip"),JL,[],n.clientId);return t.appendChild(e),t}class hW{constructor(t){m(this,"mentionButton");m(this,"handleHoveringBlock",t=>{var e;!this.editor.isWritable()||(t&&this.shouldBlockShowMention(t)?le(t).appendChild(this.mentionButton):(e=this.mentionButton)==null||e.remove())});m(this,"handleMouseDown",(t,e)=>{e.preventDefault(),e.stopPropagation();const o=ot(this.mentionButton);if(!o||!tt(t,o))return;const r=t.selection.range.focus;if(!r.isSimple())return;let i;t.selection.focusedBlock!==o?i=ut(t,o):i=r.offset,setTimeout(()=>{const s=t.insertTextToBlock(o,i,"@");i+=1;const l=re(xn(s,i).left);this.editor.selection.selectBlock(o,i),this.editor.focus(),t.getCustom("mention").suggest.popup(o,i,l,"@")})});m(this,"destroy",()=>{pe.get(this.editor).removeListener("change",this.handleHoveringBlock)});this.editor=t,this.mentionButton=dW(t),pe.get(this.editor).addListener("change",this.handleHoveringBlock),t.domEvents.addEventListener(this.mentionButton,"mousedown",this.handleMouseDown)}shouldBlockShowMention(t){if(!tt(this.editor,t)||!Ht(t))return!1;const e=Zn(t);return!(e==="ordered"||e==="unordered")}}const tot="",fW={mention:{abstract:"\u6210\u5458"}},mW={mention:{abstract:"Member"}},gW={mention:{abstract:"\u30E1\u30F3\u30D0\u30FC"}};R.mergeLang({"zh-CN":fW,"en-US":mW,"ja-JP":gW});const pW={templates:{title:"\u9009\u62E9\u6A21\u677F\uFF0C\u5FEB\u901F\u521B\u5EFA",create:"\u65B0\u5EFA\u6A21\u677F",choose:"\u5168\u90E8\u6A21\u677F",customizedMark:"\u81EA\u5B9A\u4E49"}},CW={templates:{title:"Choose a template",create:"New template",choose:"All templates",customizedMark:"Custom"}},AW={templates:{title:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u9078\u629E",create:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u65B0\u898F\u4F5C\u6210",choose:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u4E00\u89A7",customizedMark:"\u30AB\u30B9\u30BF\u30E0"}};R.mergeLang({"zh-CN":pW,"en-US":CW,"ja-JP":AW});const eot="",bW="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjEyMCIgaGVpZ2h0PSIxMjAiIHZpZXdCb3g9IjAgMCAxMjAgMTIwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cmVjdCB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTQ4IDU5QzQ4IDU0LjU4MTcgNTEuNTgxNyA1MSA1NiA1MUg5M0M5OC41MjI4IDUxIDEwMyA1NS40NzcyIDEwMyA2MVY4OEMxMDMgOTEuODY2IDk5Ljg2NiA5NSA5NiA5NUg1NkM1MS41ODE3IDk1IDQ4IDkxLjQxODMgNDggODdWNTlaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGQ9Ik0xOCA2NEMxOCA2Mi4zNDMxIDE5LjM0MzEgNjEgMjEgNjFINTZDNjAuNDE4MyA2MSA2NCA2NC41ODE3IDY0IDY5VjgzQzY0IDg1LjIwOTEgNjIuMjA5MSA4NyA2MCA4N0gyNkMyMS41ODE3IDg3IDE4IDgzLjQxODMgMTggNzlWNjRaIiBmaWxsPSIjRUFFNEY2Ii8+CjxyZWN0IHg9IjI0IiB5PSIzMSIgd2lkdGg9IjY1IiBoZWlnaHQ9IjUwIiByeD0iNSIgZmlsbD0iIzk5QzdGMiIvPgo8cmVjdCB4PSIzMy41IiB5PSI0MyIgd2lkdGg9IjQ2IiBoZWlnaHQ9IjUiIHJ4PSIyLjUiIGZpbGw9IndoaXRlIi8+CjxyZWN0IHg9IjMzLjUiIHk9IjU0IiB3aWR0aD0iNDYiIGhlaWdodD0iNSIgcng9IjIuNSIgZmlsbD0id2hpdGUiLz4KPHJlY3QgeD0iMjQiIHk9IjMxIiB3aWR0aD0iNjUiIGhlaWdodD0iNTAiIHJ4PSI1IiBzdHJva2U9IiNGOEY4RjgiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01MCA4NS4yNjhDNTMuODI2MyA4My4wNTg5IDU1LjEzNzMgNzguMTY2MiA1Mi45MjgyIDc0LjMzOThMNjMuMzIwNSA2OC4zMzk4QzY4Ljg0MzMgNzcuOTA1NyA2NS41NjU4IDkwLjEzNzUgNTYgOTUuNjYwNEM0Ni40MzQxIDEwMS4xODMgMzQuMjAyMyA5Ny45MDU3IDI4LjY3OTQgODguMzM5OEwzOS4wNzE3IDgyLjMzOThDNDEuMjgwOSA4Ni4xNjYyIDQ2LjE3MzYgODcuNDc3MiA1MCA4NS4yNjhaIiBmaWxsPSIjQUI5M0RDIi8+CjxyZWN0IHg9IjU5IiB5PSI2NSIgd2lkdGg9IjQyIiBoZWlnaHQ9IjI4IiByeD0iNSIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTYzIDg4VjczLjA4MDhDNjMgNzEuNzA5NiA2My4zNjE0IDcwLjY4NjcgNjQuMDg0MSA3MC4wMTJDNjQuODI4NyA2OS4zMzczIDY1Ljg1OCA2OSA2Ny4xNzIgNjlIOTIuODYwOUM5NS42MjAzIDY5IDk3IDcwLjM2MDMgOTcgNzMuMDgwOFY4OEg5My41MTc5TDg3LjM3NDkgODAuNjIyQzg3LjA5MDIgODAuMzE3MyA4Ni43NjE3IDgwLjA4ODggODYuMzg5NCA3OS45MzY0Qzg2LjAxNzEgNzkuNzg0MSA4NS42NDQ4IDc5LjcwNzkgODUuMjcyNSA3OS43MDc5Qzg0LjkwMDIgNzkuNzA3OSA4NC41Mjc5IDc5Ljc4NDEgODQuMTU1NiA3OS45MzY0QzgzLjgwNTIgODAuMDg4OCA4My40NTQ4IDgwLjMxNzMgODMuMTA0MyA4MC42MjJMNzYuNzMxNCA4Ni4yMzcxTDc0LjIwMTkgODMuOTUxOUM3My42MzI1IDgzLjQyOTYgNzMuMDA4NCA4My4xNjg0IDcyLjMyOTUgODMuMTY4NEM3MS42NTA2IDgzLjE2ODQgNzEuMDM3NCA4My40Mjk2IDcwLjQ4OTkgODMuOTUxOUw2Ni40NDkzIDg4SDYzWk03NC40NjQ3IDgwLjYyMkM3NS4zNjI2IDgwLjYyMiA3Ni4xNDAxIDgwLjI5NTUgNzYuNzk3MSA3OS42NDI2Qzc3LjQ3NiA3OC45ODk3IDc3LjgxNTUgNzguMjE3MSA3Ny44MTU1IDc3LjMyNDdDNzcuODE1NSA3Ni40MTA3IDc3LjQ3NiA3NS42MzggNzYuNzk3MSA3NS4wMDY5Qzc2LjE0MDEgNzQuMzU0IDc1LjM2MjYgNzQuMDE2NiA3NC40NjQ3IDczLjk5NDhDNzMuNTQ0OSA3My45NTEzIDcyLjc1NjUgNzQuMjY2OSA3Mi4wOTk1IDc0Ljk0MTZDNzEuNDQyNSA3NS42MTYzIDcxLjExNCA3Ni40MTA3IDcxLjExNCA3Ny4zMjQ3QzcxLjExNCA3OC4yMTcxIDcxLjQ0MjUgNzguOTg5NyA3Mi4wOTk1IDc5LjY0MjZDNzIuNzU2NSA4MC4yOTU1IDczLjU0NDkgODAuNjIyIDc0LjQ2NDcgODAuNjIyWiIgZmlsbD0iI0Y3RDA3RiIvPgo8Y2lyY2xlIGN4PSI5NSIgY3k9IjQyIiByPSIyIiBzdHJva2U9IiM1MEMzOTgiIHN0cm9rZS13aWR0aD0iMiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTk0Ljc1MDEgMjQuNDY4N0wxMDAuNzgxIDI3LjkxNDlMOTQuNzE5IDMxLjQxNDlMOTQuNzUwMSAyNC40Njg3WiIgc3Ryb2tlPSIjNUNBNUVBIiBzdHJva2Utd2lkdGg9IjEuOCIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwNSAzOEMxMDUgMzguNTUyMyAxMDUuNDQ4IDM5IDEwNiAzOUMxMDYuNTUyIDM5IDEwNyAzOC41NTIzIDEwNyAzOFYzNkgxMDlDMTA5LjU1MiAzNiAxMTAgMzUuNTUyMyAxMTAgMzVDMTEwIDM0LjQ0NzcgMTA5LjU1MiAzNCAxMDkgMzRIMTA3VjMyQzEwNyAzMS40NDc3IDEwNi41NTIgMzEgMTA2IDMxQzEwNS40NDggMzEgMTA1IDMxLjQ0NzcgMTA1IDMyVjM0SDEwM0MxMDIuNDQ4IDM0IDEwMiAzNC40NDc3IDEwMiAzNUMxMDIgMzUuNTUyMyAxMDIuNDQ4IDM2IDEwMyAzNkgxMDVWMzhaIiBmaWxsPSIjQUI5M0RDIi8+Cjwvc3ZnPgo=",vW="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgdmlld0JveD0iMCAwIDM3MiAyNzkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8xMjU2XzM3MTY4KSI+CjxyZWN0IHdpZHRoPSIzNzIiIGhlaWdodD0iMjc5IiBmaWxsPSJ3aGl0ZSIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIzOS41NzQ3IiB3aWR0aD0iMTE4LjcyMyIgaGVpZ2h0PSIxNS44Mjk4IiByeD0iNy45MTQ4OSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI3MS4yMzM5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI5MS4wMjE1IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIxMTAuODA5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSI0MC41NjM4IiB5PSIxMzUuNTQzIiB3aWR0aD0iMjkwLjg3MiIgaGVpZ2h0PSIxMDAuOTE1IiByeD0iMi45NjgwOSIgc3Ryb2tlPSIjRUFGM0ZDIiBzdHJva2Utd2lkdGg9IjEuOTc4NzIiLz4KPHBhdGggZD0iTTM5LjU3NDUgMTM4LjUxMUMzOS41NzQ1IDEzNi4zMjUgNDEuMzQ2MyAxMzQuNTUzIDQzLjUzMTkgMTM0LjU1M0gzMjguNDY4QzMzMC42NTQgMTM0LjU1MyAzMzIuNDI2IDEzNi4zMjUgMzMyLjQyNiAxMzguNTExVjE1Mi4zNjJIMzkuNTc0NVYxMzguNTExWiIgZmlsbD0iI0Q2RTlGQSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTg3LjA2MzcgMTY5LjE4MUM4Ny4wNjM3IDE2Ny41NDIgODguMzkyNiAxNjYuMjEzIDkwLjAzMTggMTY2LjIxM0gzMTcuNTg1QzMxOS4yMjQgMTY2LjIxMyAzMjAuNTUzIDE2Ny41NDIgMzIwLjU1MyAxNjkuMTgxQzMyMC41NTMgMTcwLjgyIDMxOS4yMjQgMTcyLjE0OSAzMTcuNTg1IDE3Mi4xNDlIOTAuMDMxOEM4OC4zOTI2IDE3Mi4xNDkgODcuMDYzNyAxNzAuODIgODcuMDYzNyAxNjkuMTgxWk0xMDQuODcyIDE5Mi45MjZDMTA0Ljg3MiAxOTEuMjg2IDEwNi4yMDEgMTg5Ljk1NyAxMDcuODQgMTg5Ljk1N0gzMTcuNTg1QzMxOS4yMjQgMTg5Ljk1NyAzMjAuNTUzIDE5MS4yODYgMzIwLjU1MyAxOTIuOTI2QzMyMC41NTMgMTk0LjU2NSAzMTkuMjI0IDE5NS44OTQgMzE3LjU4NSAxOTUuODk0SDEwNy44NEMxMDYuMjAxIDE5NS44OTQgMTA0Ljg3MiAxOTQuNTY1IDEwNC44NzIgMTkyLjkyNlpNMTA3Ljg0IDIxMy43MDJDMTA2LjIwMSAyMTMuNzAyIDEwNC44NzIgMjE1LjAzMSAxMDQuODcyIDIxNi42N0MxMDQuODcyIDIxOC4zMDkgMTA2LjIwMSAyMTkuNjM4IDEwNy44NCAyMTkuNjM4SDMxNy41ODVDMzE5LjIyNCAyMTkuNjM4IDMyMC41NTMgMjE4LjMwOSAzMjAuNTUzIDIxNi42N0MzMjAuNTUzIDIxNS4wMzEgMzE5LjIyNCAyMTMuNzAyIDMxNy41ODUgMjEzLjcwMkgxMDcuODRaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNTEuNDQ2OCAxNjkuMTgxQzUxLjQ0NjggMTY3LjU0MiA1Mi43NzU2IDE2Ni4yMTMgNTQuNDE0OSAxNjYuMjEzSDYwLjM1MUM2MS45OTAzIDE2Ni4yMTMgNjMuMzE5MSAxNjcuNTQyIDYzLjMxOTEgMTY5LjE4MUM2My4zMTkxIDE3MC44MiA2MS45OTAzIDE3Mi4xNDkgNjAuMzUxIDE3Mi4xNDlINTQuNDE0OUM1Mi43NzU2IDE3Mi4xNDkgNTEuNDQ2OCAxNzAuODIgNTEuNDQ2OCAxNjkuMTgxWk01MS40NDY4IDE5Mi45MjZDNTEuNDQ2OCAxOTEuMjg2IDUyLjc3NTcgMTg5Ljk1NyA1NC40MTQ5IDE4OS45NTdINjAuMzUxMUM2MS45OTAzIDE4OS45NTcgNjMuMzE5MSAxOTEuMjg2IDYzLjMxOTEgMTkyLjkyNkM2My4zMTkxIDE5NC41NjUgNjEuOTkwMyAxOTUuODk0IDYwLjM1MTEgMTk1Ljg5NEg1NC40MTQ5QzUyLjc3NTcgMTk1Ljg5NCA1MS40NDY4IDE5NC41NjUgNTEuNDQ2OCAxOTIuOTI2Wk01NC40MTQ5IDIxMy43MDJDNTIuNzc1NyAyMTMuNzAyIDUxLjQ0NjggMjE1LjAzMSA1MS40NDY4IDIxNi42N0M1MS40NDY4IDIxOC4zMDkgNTIuNzc1NyAyMTkuNjM4IDU0LjQxNDkgMjE5LjYzOEg2MC4zNTExQzYxLjk5MDMgMjE5LjYzOCA2My4zMTkxIDIxOC4zMDkgNjMuMzE5MSAyMTYuNjdDNjMuMzE5MSAyMTUuMDMxIDYxLjk5MDMgMjEzLjcwMiA2MC4zNTExIDIxMy43MDJINTQuNDE0OVoiIGZpbGw9IiM5OUM3RjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02OS4yNTU0IDE2OS4xODFDNjkuMjU1NCAxNjcuNTQyIDcwLjU4NDMgMTY2LjIxMyA3Mi4yMjM1IDE2Ni4yMTNINzguMTU5N0M3OS43OTg5IDE2Ni4yMTMgODEuMTI3OCAxNjcuNTQyIDgxLjEyNzggMTY5LjE4MUM4MS4xMjc4IDE3MC44MiA3OS43OTg5IDE3Mi4xNDkgNzguMTU5NyAxNzIuMTQ5SDcyLjIyMzVDNzAuNTg0MyAxNzIuMTQ5IDY5LjI1NTQgMTcwLjgyIDY5LjI1NTQgMTY5LjE4MVpNNjkuMjU1NCAxOTIuOTI2QzY5LjI1NTQgMTkxLjI4NiA3MC41ODQyIDE4OS45NTcgNzIuMjIzNSAxODkuOTU3SDc4LjE1OTZDNzkuNzk4OSAxODkuOTU3IDgxLjEyNzcgMTkxLjI4NiA4MS4xMjc3IDE5Mi45MjZDODEuMTI3NyAxOTQuNTY1IDc5Ljc5ODkgMTk1Ljg5NCA3OC4xNTk2IDE5NS44OTRINzIuMjIzNUM3MC41ODQyIDE5NS44OTQgNjkuMjU1NCAxOTQuNTY1IDY5LjI1NTQgMTkyLjkyNlpNNzIuMjIzNSAyMTMuNzAyQzcwLjU4NDIgMjEzLjcwMiA2OS4yNTU0IDIxNS4wMzEgNjkuMjU1NCAyMTYuNjdDNjkuMjU1NCAyMTguMzA5IDcwLjU4NDIgMjE5LjYzOCA3Mi4yMjM1IDIxOS42MzhINzguMTU5NkM3OS43OTg5IDIxOS42MzggODEuMTI3NyAyMTguMzA5IDgxLjEyNzcgMjE2LjY3QzgxLjEyNzcgMjE1LjAzMSA3OS43OTg5IDIxMy43MDIgNzguMTU5NiAyMTMuNzAySDcyLjIyMzVaIiBmaWxsPSIjRjdEMDdGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNOTAuMDMxOCAxODkuOTU4Qzg4LjM5MjYgMTg5Ljk1OCA4Ny4wNjM3IDE5MS4yODYgODcuMDYzNyAxOTIuOTI2Qzg3LjA2MzcgMTk0LjU2NSA4OC4zOTI2IDE5NS44OTQgOTAuMDMxOCAxOTUuODk0SDk1Ljk2OEM5Ny42MDcyIDE5NS44OTQgOTguOTM2MSAxOTQuNTY1IDk4LjkzNjEgMTkyLjkyNkM5OC45MzYxIDE5MS4yODYgOTcuNjA3MiAxODkuOTU4IDk1Ljk2OCAxODkuOTU4SDkwLjAzMThaTTkwLjAzMTkgMjEzLjcwMkM4OC4zOTI3IDIxMy43MDIgODcuMDYzOCAyMTUuMDMxIDg3LjA2MzggMjE2LjY3Qzg3LjA2MzggMjE4LjMwOSA4OC4zOTI3IDIxOS42MzggOTAuMDMxOSAyMTkuNjM4SDk1Ljk2ODFDOTcuNjA3MyAyMTkuNjM4IDk4LjkzNjIgMjE4LjMwOSA5OC45MzYyIDIxNi42N0M5OC45MzYyIDIxNS4wMzEgOTcuNjA3MyAyMTMuNzAyIDk1Ljk2ODEgMjEzLjcwMkg5MC4wMzE5WiIgZmlsbD0iIzkxRDlCRSIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEyNTZfMzcxNjgiPgo8cmVjdCB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",V8=S("templates");function N2(n){const t=n.rootElement.querySelector(":scope .editor-templates");if(!t)return null;const e=t.querySelector(":scope .editor-templates-cards");return g(V8,e,"no card container"),{root:t,cardContainer:e}}function yW(n){const t=N2(n);if(t)return t.cardContainer.innerHTML="",t;const e=w("div",["editor-templates"],n.rootElement);w("div",["editor-templates-title"],e,R.t("templates.title"));const o=w("div",["editor-templates-cards"],e);return{root:e,cardContainer:o}}function W8(n,t,e,o,r){var p;const i=(p=n.options.componentsOptions)==null?void 0:p.templates,s=w("div",["editor-template-card",...o],null),l=w("div",["editor-template-thumb-container"],s),a=w("img",["editor-template-thumb"],l);a.src=t,a.style.display="none",a.onerror=()=>{var v;const A=(v=i==null?void 0:i.placeHolderImageSrc)!=null?v:vW;a.src!==A&&(a.src=A)},a.onload=()=>{a.style.display=""};const d=w("div",["editor-template-name"],s),h=w("span",[],d,e);return i!=null&&i.showTemplateTitleAttr&&h.setAttribute("title",e),s.onclick=()=>r(s),s}function kW(n,t){return t.thumbnailUrl?t.thumbnailUrl:n.doc.buildResourceUrl("thumbnail.png")}function wW(n,t){const e=kW(n,t);return W8(n,e,t.name,[],async()=>{var r,i;const o=(r=n.options.componentsOptions)==null?void 0:r.templates;(i=o==null?void 0:o.onApplyTemplate)==null||i.call(o,n,t)})}function BW(n,t){return W8(n,t,R.t("templates.choose"),["more"],()=>{var o,r;const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onChooseTemplate)==null||r.call(e,n)})}function EW(n,t){var p,A;const e=(p=n.options.componentsOptions)==null?void 0:p.templates;if(!e)return;const r=Ge(n.rootContainer).getBoundingClientRect().width;let i=1;const s=bW,l=N2(n);if(l){if(t!=null&&t.reset){const v=Array.from(l.cardContainer.children),B=l.cardContainer.firstElementChild;if(g(V8,B,"no first card"),xt(B,"new")||xt(B,"more"))return;const D=window.getComputedStyle(B),T=parseFloat(D.marginLeft),_=parseFloat(D.marginRight),M=B.getBoundingClientRect().width+T+_;i=Math.floor(r/M);const z=Math.max(1,i-1-1),q=v.length-1;v.forEach((rt,ft)=>{ft>z&&ft<q?rt.style.display="none":(ft>=q&&xt(rt,"more"),rt.style.display="")})}return}const a=e.templates,{cardContainer:d}=yW(n);a.forEach((v,B)=>{const D=wW(n,v);if(B>0&&B>=i&&(D.style.display="none"),d.appendChild(D),B===0){const T=window.getComputedStyle(D),_=parseFloat(T.marginLeft),M=parseFloat(T.marginRight),H=D.getBoundingClientRect().width+_+M;i=Math.floor(r/H)-1}});const h=BW(n,s);d.appendChild(h),(A=e==null?void 0:e.onTemplateChooserStatusChanged)==null||A.call(e,n,d,"visible")}const q8=He.default(EW,50);function xW(n){var o,r;const t=N2(n);if(!t)return;t.root.remove();const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onTemplateChooserStatusChanged)==null||r.call(e,n,null,"hide")}function IW(n){const t=n.blocks.root;if(t.length===0)return!0;if(t.length>5)return!1;const e=[...t];e[0].type==="text"&&e[0].heading&&e.splice(0,1);const o=r=>{var i;return r.type!=="text"&&r.type!=="list"?!1:r.text?((i=r.text)==null?void 0:i.length)===0:!0};return e.every(r=>o(r))}function n1(n,t){IW(n.doc.toJSON())?q8(n,t):(q8.cancel(),xW(n))}const TW=800;class DW{constructor(t){m(this,"longPressTimeout",0);m(this,"handleSelectionChange",()=>{});m(this,"handleLongPress",t=>{const e=t.touches[0],o=oh(this.editor,e.clientX,e.clientY);!o||console.log(o)});m(this,"handleTouchStart",t=>{t.touches.length===1&&(this.longPressTimeout=window.setTimeout(()=>{this.handleLongPress(t)},TW))});m(this,"handleTouchEnd",t=>{this.longPressTimeout&&(window.clearTimeout(this.longPressTimeout),this.longPressTimeout=0)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange),document.addEventListener("touchstart",this.handleTouchStart),document.addEventListener("touchend",this.handleTouchEnd)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange),document.removeEventListener("touchstart",this.handleTouchStart),document.removeEventListener("touchend",this.handleTouchEnd)}}const SW=`<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
594
594
|
<g>
|
|
595
595
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 7.61719C11.4477 7.61719 11 7.16947 11 6.61719V3.61719C11 3.0649 11.4477 2.61719 12 2.61719C12.5523 2.61719 13 3.0649 13 3.61719V6.61719C13 7.16947 12.5523 7.61719 12 7.61719ZM4.92893 5.54612C5.31946 5.15559 5.95262 5.1556 6.34315 5.54612L8.46447 7.66744C8.85499 8.05796 8.85499 8.69113 8.46447 9.08165C8.07394 9.47218 7.44078 9.47218 7.05025 9.08165L4.92893 6.96033C4.53841 6.56981 4.53841 5.93664 4.92893 5.54612ZM15.5355 9.08165C15.145 8.69113 15.145 8.05796 15.5355 7.66744L17.6569 5.54612C18.0474 5.1556 18.6805 5.1556 19.0711 5.54612C19.4616 5.93664 19.4616 6.56981 19.0711 6.96033L16.9497 9.08165C16.5592 9.47218 15.9261 9.47218 15.5355 9.08165ZM2 12.6172C2 12.0649 2.44772 11.6172 3 11.6172L6 11.6172C6.55229 11.6172 7 12.0649 7 12.6172C7 13.1695 6.55228 13.6172 6 13.6172L3 13.6172C2.44772 13.6172 2 13.1695 2 12.6172ZM17 12.6172C17 12.0649 17.4477 11.6172 18 11.6172L21 11.6172C21.5523 11.6172 22 12.0649 22 12.6172C22 13.1695 21.5523 13.6172 21 13.6172L18 13.6172C17.4477 13.6172 17 13.1695 17 12.6172ZM15.5355 16.1527C15.9261 15.7622 16.5592 15.7622 16.9497 16.1527L19.0711 18.274C19.4616 18.6646 19.4616 19.2977 19.0711 19.6883C18.6805 20.0788 18.0474 20.0788 17.6569 19.6883L15.5355 17.5669C15.145 17.1764 15.145 16.5432 15.5355 16.1527ZM4.92893 19.6883C4.53841 19.2977 4.53841 18.6646 4.92893 18.274L7.05025 16.1527C7.44078 15.7622 8.07394 15.7622 8.46447 16.1527C8.85499 16.5432 8.85499 17.1764 8.46447 17.5669L6.34315 19.6883C5.95262 20.0788 5.31946 20.0788 4.92893 19.6883ZM12 22.6172C11.4477 22.6172 11 22.1695 11 21.6172V18.6172C11 18.0649 11.4477 17.6172 12 17.6172C12.5523 17.6172 13 18.0649 13 18.6172V21.6172C13 22.1695 12.5523 22.6172 12 22.6172Z" fill="#5587F0"/>
|
|
596
596
|
<animateTransform attributeType="xml" attributeName="transform" type="rotate" values="0 12 12.5;360 12 12.5" dur="2s" repeatCount="indefinite" />
|
|
597
597
|
</g>
|
|
598
|
-
</svg>`,$2=S("webpage");class LW{constructor(t,e){m(this,"currentSrc","");m(this,"loading",null);m(this,"handleMaskMouseMove",(t,e)=>{if(!window.isDragging){if(e.target&&e.target instanceof Element){const o=e.target.closest("webpage-mask");o&&(o.style.display="none")}t.domEvents.addEventListener(document,"mousemove",this.handleDocumentMouseMove)}});m(this,"handleDocumentMouseMove",(t,e)=>{if(!e.target||!(e.target instanceof Element))return;const o=this.editor.findBlockById(this.blockData.id);if(o){const r=this.getExistsMask(o);if(r){if(Kt(o,e.target)){r.style.display="none";return}r.style.display=""}}});this.editor=t,this.blockData=e}create(t,e,o,r){const i=e.src,s=w("div",["editor-embed"],null),l=w("iframe",["editor-preview-iframe"],s);this.loading=this.createLoading(s);const a=()=>{g($2,this.loading,"not created"),this.loading.hide(),this.currentSrc=i};t.domEvents.addEventListener(l,"load",a),l.src=i,this.loading.show(),o.append(s),this.createMask(t,r)}update(t,e,o){if(g($2,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");g($2,r,"no exists iframe"),this.loading.show(),r.src=o.src,this.createMask(t,e)}createLoading(t){const e=w("div",["editor-preview-iframe-loading"],null),o=w("span",[],e);return o.innerHTML=SW,{show(){t.append(e)},hide(){const r=t.querySelector(":scope > .editor-preview-iframe-loading");!r||r.remove()}}}getExistsMask(t){return le(t).querySelector(".webpage-mask")}createMask(t,e){const o=le(e);let r=this.getExistsMask(e);if(r){r.style.display="";return}r=w("div",["webpage-mask"],o),t.domEvents.addEventListener(r,"mousemove",this.handleMaskMouseMove)}destroy(){const t=this.editor.findBlockById(this.blockData.id);if(t){const e=this.getExistsMask(t);e&&(this.editor.domEvents.removeEventListener(e,"mousemove",this.handleMaskMouseMove),this.editor.domEvents.removeEventListener(document,"mousemove",this.handleDocumentMouseMove))}}}function Gy(n){return n&&Le(n)&&Un(n)==="webpage"}const MW=1e3,RW=100;class OW{constructor(t){m(this,"currentBlockElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&Gy(e)&&this.disableBlockResize(e),t&&Gy(t)&&this.enableBlockResize(t))});m(this,"handleResizing",(t,e)=>{this.resizing=!0;const o=t.getBlock();if(!o)return;const r=Math.max(Math.min(e.height,MW),RW);o.style.height=`${r}px`,W(o,"resizing")});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;et(e,"resizing");const o=this.editor.getBlockData(e),r=e.getBoundingClientRect().height;this.editor.updateBlockData(e,{...o,height:r})});this.editor=t,pe.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentBlockElement=null,pe.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disableBlockResize(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${it(t)}-resizer`,()=>new wu(this.editor,{resize:["bottom"]}));e.enableResize(t),e.removeListener("resizing",this.handleResizing),e.removeListener("resized",this.handleResized),e.addListener("resizing",this.handleResizing),e.addListener("resized",this.handleResized),this.currentBlockElement=t}}const not="",_W=S("editor-dialog");function FW(n,t){const e=w("div",["editor-dialog-container"],null),o=w("div",["dialog-header"],e);w("span",["dialog-header-title"],o,t.title);const r=w("span",["close-icon"],o);r.innerHTML=sv,w("div",["dialog-content"],e).appendChild(n);const s=w("div",["dialog-footer"],e);return w("button",["cancel-button"],s,R.t("webpage.dialog.cancelText")),w("button",["submit-button"],s,R.t("webpage.dialog.okText")),e}class PW extends ru{constructor(e,o){super(FW(e,o),o);m(this,"_options");m(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();g(_W,r,"no command bar root");const{width:i,height:s}=r.getBoundingClientRect();return new DOMRect(Math.max(o-i/2,0),Math.max(e-s/2,0),0,0)});m(this,"handleOk",async()=>{var e,o;try{await((o=(e=this._options).onOk)==null?void 0:o.call(e)),this.destroy()}catch{}});m(this,"handleClose",()=>{var e,o;(o=(e=this._options).onClose)==null||o.call(e),this.destroy()});const r=this.content.querySelector(".submit-button"),i=this.content.querySelector(".cancel-button"),s=this.content.querySelector(".close-icon");r==null||r.addEventListener("click",this.handleOk),s==null||s.addEventListener("click",this.handleClose),i==null||i.addEventListener("click",this.handleClose),this._options=o}show(){super.show(document.documentElement,{getReferenceClientRect:this.getReferenceClientRect}),setTimeout(()=>{const e=document.querySelector(`.editor-disable-scroll[data-scroll-id="${this.id}"]`);e&&W(e,"editor-disable-scroll-dark")})}destroy(){const e=this.content.querySelector(".submit-button"),o=this.content.querySelector(".cancel-button"),r=this.content.querySelector(".close-icon");e==null||e.removeEventListener("click",this.handleOk),o==null||o.removeEventListener("click",this.handleClose),r==null||r.removeEventListener("click",this.handleClose),super.destroy()}}const NW=()=>[{name:R.t("webpage.bilibili"),id:"insert-bilibili",icon:RL,group:"thirdParty",subText:pn("insert-bilibili"),value:"bilibili"},{name:R.t("webpage.youku"),id:"insert-youku",icon:OL,group:"thirdParty",subText:pn("insert-youku"),value:"youku"},{name:R.t("webpage.figma"),id:"insert-figma",icon:_L,group:"thirdParty",subText:pn("insert-figma"),value:"figma"},{name:R.t("webpage.modao"),id:"insert-modao",icon:FL,group:"thirdParty",subText:pn("insert-modao"),value:"modao"},{name:R.t("webpage.tencent"),id:"insert-tencent",icon:PL,group:"thirdParty",subText:pn("insert-tencent"),value:"qqVideo"},{id:"insert-webPage",name:R.t("webpage.title"),icon:NL,group:"common",order:1e3,subText:pn("insert-webPage"),value:"url"}];function Zy(n){let t=NW();const e=n.getComponentOptions("webpage");return e!=null&&e.getAllowedWebPages&&(t=e.getAllowedWebPages(t)),t}function H2(n){return n==="insert-webPage"}async function $W(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function HW(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`${window.location.protocol}//${n}`:n}async function jW(n){if(!n)throw new Error(R.t("webpage.dialog.errorEnterUrl"));const t=n;try{new URL(t)}catch{throw new Error(R.t("webpage.dialog.unsupportedUrl"))}}async function UW(n,t){const e=t.item.id,o=Zy(n).find(h=>h.id===e),r=w("div",["webpage-content"],null);if(H2(e)){const h=w("div",["help-container"],r),p=w("div",["help-content"],h),A=w("span",["help-icon"],p);A.innerHTML=uv,w("span",[],p,R.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:a}=_p(r,{required:!0,label:R.t("webpage.dialog.label"),placeholder:R.t("webpage.dialog.placeholder")}),d=n.getComponentOptions("webpage");if(!H2(e)&&!(d!=null&&d.hideHelpLink)){const h=w("div",["help-link-container"],r),p=w("a",["help-link-content"],h);w("span",[],p,R.t("webpage.dialog.helpLink"));const A=w("span",["help-link-icon"],p);A.innerHTML=hv,p.href=(d==null?void 0:d.helpLink)||"",p.target="_blank"}try{const h=await new Promise((v,B)=>{const D=new PW(r,{id:"webpage",title:R.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var M;const _=HW(i());try{await jW(_);const H=await $W(n,_);v((H==null?void 0:H.url)||"")}catch(H){if(((M=H==null?void 0:H.responseData)==null?void 0:M.statusCode)===415)if(H2(e))v(_);else throw s(R.t("webpage.dialog.unsupportedUrl")),H;else throw s(H.message||""),H}},onClose(){n.focus(),B()}});D.addListener("show",l),D.show(),a().addEventListener("keydown",async _=>{if(!_.isComposing){if(_.key==="Enter"){await D.handleOk(),_.preventDefault();return}_.key==="Escape"&&D.handleClose()}})}),p={id:K(),type:"embed",embedType:"webpage",embedData:{src:h}},A=n.insertBlock(t.containerId,t.blockIndex,p);return n.focus(),A}catch{return null}}function zW(n){const t=n.querySelector(".editor-preview-iframe"),e=t.src;t.src="about:blank";const o=setTimeout(()=>{t.src=e,clearTimeout(o)},300);return!0}function VW(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function WW(n,t){const e=T2(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:R.t("webpage.command.refresh"),icon:LL},{id:"open-page",name:R.t("webpage.command.openPage"),icon:hv}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return zW(i);case"open-page":return VW(r,i)}return!1}}),o=`${R.t("webpage.abstract")}`;return{...e,abstract:o}}const qW=S("webpage-embed");function GW(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:a}=s,d=n.addCustom(`webpage-${l}`,()=>new LW(n,e));g(qW,a,"The src from blockData is invalid "),d.create(n,s,t,i),setTimeout(()=>{n.isBlockWritable(i)&&n.addCustom("webpage-resizer",()=>new OW(n))}),e.height&&(i.style.height=`${e.height}px`)}function ZW(n,t,e){const{embedData:o,id:r}=e;return n.getCustom(`webpage-${r}`).update(n,t,o),e.height&&(t.style.height=`${e.height}px`),!0}function QW(n){return{name:"WebPage",insertEmbedCommandItems:Zy(n),handleInsertEmptyEmbed:UW}}function YW(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const Qy={embedType:"webpage",createEmbedContent:GW,getBlockProperties:WW,getOptions:QW,handleUpdateBlock:ZW,convertTo:YW},JW={webpage:{title:"\u7F51\u9875",youku:"\u4F18\u9177\u89C6\u9891",modao:"\u58A8\u5200",tencent:"\u817E\u8BAF\u89C6\u9891",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u56E0\u76EE\u6807\u7F51\u9875\u7684\u9650\u5236\uFF0C\u90E8\u5206\u7F51\u9875\u53EF\u80FD\u65E0\u6CD5\u6210\u529F\u9884\u89C8\u3002",helpLink:"\u5982\u4F55\u83B7\u53D6\u94FE\u63A5",label:"\u7F51\u9875\u5730\u5740",placeholder:"\u8BF7\u8F93\u5165",title:"\u63D2\u5165{name}",errorEnterUrl:"\u8BF7\u8F93\u5165\u7F51\u9875\u5730\u5740",unsupportedUrl:"\u6682\u4E0D\u652F\u6301\u63D2\u5165\u8BE5\u94FE\u63A5\u5185\u5BB9",okText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},abstract:"\u7F51\u9875",command:{refresh:"\u5237\u65B0\u9875\u9762",openPage:"\u6253\u5F00\u539F\u59CB\u9875\u9762"}}},KW={webpage:{title:"Webpage",youku:"Youku",modao:"Modao",tencent:"Tencent Video",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"Due to landing page limitations, some pages may not be properly displayed during preview.",helpLink:"How to get the URL link",label:"Website address",placeholder:"Please enter",title:"Insert {name}",errorEnterUrl:"Please enter website address",unsupportedUrl:"Unsupported URL",okText:"Confirm",cancelText:"Cancel"},abstract:"Webpage",command:{refresh:"Refresh page",openPage:"Open the original page"}}},XW={webpage:{title:"Web \u30DA\u30FC\u30B8",youku:"Youku \u52D5\u753B",modao:"Modao",tencent:"Tencent \u52D5\u753B",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u30A2\u30AF\u30BB\u30B9\u5148\u306E\u5236\u9650\u306B\u3088\u308A\u3001\u4E00\u90E8\u306E\u30DA\u30FC\u30B8\u304C\u8868\u793A\u3067\u304D\u306A\u3044\u5834\u5408\u304C\u3042\u308A\u307E\u3059\u3002",helpLink:"URL \u3092\u53D6\u5F97\u3059\u308B\u65B9\u6CD5",label:"URL",placeholder:"\u5165\u529B",title:"{name}\u3092\u633F\u5165",errorEnterUrl:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",unsupportedUrl:"\u3053\u306E URL \u306F\u633F\u5165\u3067\u304D\u307E\u305B\u3093",okText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB"},abstract:"Web \u30DA\u30FC\u30B8",command:{refresh:"\u30DA\u30FC\u30B8\u3092\u518D\u8AAD\u307F\u8FBC\u3080",openPage:"URL\u3092\u958B\u304F"}}};R.mergeLang({"zh-CN":JW,"en-US":KW,"ja-JP":XW});const oot="";function tq(n){const t=Object.entries(n);for(let e=0;e<t.length;e++){const[o,r]=t[e];if(o.toLocaleLowerCase()==="content-type")return r}return""}async function eq(n,t,e=!0){try{const o=await n.doc.request(t,{method:"get",responseType:"blob",withCredentials:e}),r=new FileReader,i=new Promise((h,p)=>{r.onload=h,r.onerror=p});r.readAsArrayBuffer(o.data),await i;const s=r.result,l=tq(o.headers).toLocaleLowerCase();let a="";if(l){const h=mm.default[l].extensions;h&&h.length>0&&(a=h[0])}return new File([s],`${Date.now()}.${a}`,{type:l})}catch{return null}}async function j2(n,t){return await eq(n,t)}async function Yy(n,t){const e=await j2(n,t);return e?await e.text():null}const nq=n=>{const t=n.getBoundingClientRect();return t.width<=1&&t.height<=1},oq=n=>{var i,s;const t=(i=n.getAttribute("width"))!=null?i:"",e=(s=n.getAttribute("height"))!=null?s:"",o=Number.parseInt(t,10),r=Number.parseInt(e,10);return!o||!r||o<=1&&r<=1},rq=n=>n!=null?n[n.textContent===void 0?"text":"textContent"]:"",Jy={"zh-CN":"zh","zh-TW":"zh-tw","js-JP":"zh"},iq="https://embed.diagrams.net/?embed=1",sq="https://www.draw.io/embed.js",lq="https://cdn.jsdelivr.net/npm/pako@2.0.3/dist/pako.es5.js",cq=`<svg width="48" height="49" viewBox="0 0 48 49" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
598
|
+
</svg>`,$2=S("webpage");class LW{constructor(t,e){m(this,"currentSrc","");m(this,"loading",null);m(this,"handleMaskMouseMove",(t,e)=>{if(!window.isDragging){if(e.target&&e.target instanceof Element){const o=e.target.closest("webpage-mask");o&&(o.style.display="none")}t.domEvents.addEventListener(document,"mousemove",this.handleDocumentMouseMove)}});m(this,"handleDocumentMouseMove",(t,e)=>{if(!e.target||!(e.target instanceof Element))return;const o=this.editor.findBlockById(this.blockData.id);if(o){const r=this.getExistsMask(o);if(r){if(Kt(o,e.target)){r.style.display="none";return}r.style.display=""}}});this.editor=t,this.blockData=e}create(t,e,o,r){const i=e.src,s=w("div",["editor-embed"],null),l=w("iframe",["editor-preview-iframe"],s);this.loading=this.createLoading(s);const a=()=>{g($2,this.loading,"not created"),this.loading.hide(),this.currentSrc=i};t.domEvents.addEventListener(l,"load",a),l.src=i,this.loading.show(),o.append(s),this.createMask(t,r)}update(t,e,o){if(g($2,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");g($2,r,"no exists iframe"),this.loading.show(),r.src=o.src,this.createMask(t,e)}createLoading(t){const e=w("div",["editor-preview-iframe-loading"],null),o=w("span",[],e);return o.innerHTML=SW,{show(){t.append(e)},hide(){const r=t.querySelector(":scope > .editor-preview-iframe-loading");!r||r.remove()}}}getExistsMask(t){return le(t).querySelector(".webpage-mask")}createMask(t,e){const o=le(e);let r=this.getExistsMask(e);if(r){r.style.display="";return}r=w("div",["webpage-mask"],o),t.domEvents.addEventListener(r,"mousemove",this.handleMaskMouseMove)}destroy(){const t=this.editor.findBlockById(this.blockData.id);if(t){const e=this.getExistsMask(t);e&&(this.editor.domEvents.removeEventListener(e,"mousemove",this.handleMaskMouseMove),this.editor.domEvents.removeEventListener(document,"mousemove",this.handleDocumentMouseMove))}}}function G8(n){return n&&Le(n)&&Un(n)==="webpage"}const MW=1e3,RW=100;class OW{constructor(t){m(this,"currentBlockElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&G8(e)&&this.disableBlockResize(e),t&&G8(t)&&this.enableBlockResize(t))});m(this,"handleResizing",(t,e)=>{this.resizing=!0;const o=t.getBlock();if(!o)return;const r=Math.max(Math.min(e.height,MW),RW);o.style.height=`${r}px`,W(o,"resizing")});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;et(e,"resizing");const o=this.editor.getBlockData(e),r=e.getBoundingClientRect().height;this.editor.updateBlockData(e,{...o,height:r})});this.editor=t,pe.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentBlockElement=null,pe.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disableBlockResize(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${it(t)}-resizer`,()=>new wu(this.editor,{resize:["bottom"]}));e.enableResize(t),e.removeListener("resizing",this.handleResizing),e.removeListener("resized",this.handleResized),e.addListener("resizing",this.handleResizing),e.addListener("resized",this.handleResized),this.currentBlockElement=t}}const not="",_W=S("editor-dialog");function FW(n,t){const e=w("div",["editor-dialog-container"],null),o=w("div",["dialog-header"],e);w("span",["dialog-header-title"],o,t.title);const r=w("span",["close-icon"],o);r.innerHTML=sv,w("div",["dialog-content"],e).appendChild(n);const s=w("div",["dialog-footer"],e);return w("button",["cancel-button"],s,R.t("webpage.dialog.cancelText")),w("button",["submit-button"],s,R.t("webpage.dialog.okText")),e}class PW extends ru{constructor(e,o){super(FW(e,o),o);m(this,"_options");m(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();g(_W,r,"no command bar root");const{width:i,height:s}=r.getBoundingClientRect();return new DOMRect(Math.max(o-i/2,0),Math.max(e-s/2,0),0,0)});m(this,"handleOk",async()=>{var e,o;try{await((o=(e=this._options).onOk)==null?void 0:o.call(e)),this.destroy()}catch{}});m(this,"handleClose",()=>{var e,o;(o=(e=this._options).onClose)==null||o.call(e),this.destroy()});const r=this.content.querySelector(".submit-button"),i=this.content.querySelector(".cancel-button"),s=this.content.querySelector(".close-icon");r==null||r.addEventListener("click",this.handleOk),s==null||s.addEventListener("click",this.handleClose),i==null||i.addEventListener("click",this.handleClose),this._options=o}show(){super.show(document.documentElement,{getReferenceClientRect:this.getReferenceClientRect}),setTimeout(()=>{const e=document.querySelector(`.editor-disable-scroll[data-scroll-id="${this.id}"]`);e&&W(e,"editor-disable-scroll-dark")})}destroy(){const e=this.content.querySelector(".submit-button"),o=this.content.querySelector(".cancel-button"),r=this.content.querySelector(".close-icon");e==null||e.removeEventListener("click",this.handleOk),o==null||o.removeEventListener("click",this.handleClose),r==null||r.removeEventListener("click",this.handleClose),super.destroy()}}const NW=()=>[{name:R.t("webpage.bilibili"),id:"insert-bilibili",icon:RL,group:"thirdParty",subText:pn("insert-bilibili"),value:"bilibili"},{name:R.t("webpage.youku"),id:"insert-youku",icon:OL,group:"thirdParty",subText:pn("insert-youku"),value:"youku"},{name:R.t("webpage.figma"),id:"insert-figma",icon:_L,group:"thirdParty",subText:pn("insert-figma"),value:"figma"},{name:R.t("webpage.modao"),id:"insert-modao",icon:FL,group:"thirdParty",subText:pn("insert-modao"),value:"modao"},{name:R.t("webpage.tencent"),id:"insert-tencent",icon:PL,group:"thirdParty",subText:pn("insert-tencent"),value:"qqVideo"},{id:"insert-webPage",name:R.t("webpage.title"),icon:NL,group:"common",order:1e3,subText:pn("insert-webPage"),value:"url"}];function Z8(n){let t=NW();const e=n.getComponentOptions("webpage");return e!=null&&e.getAllowedWebPages&&(t=e.getAllowedWebPages(t)),t}function H2(n){return n==="insert-webPage"}async function $W(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function HW(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`${window.location.protocol}//${n}`:n}async function jW(n){if(!n)throw new Error(R.t("webpage.dialog.errorEnterUrl"));const t=n;try{new URL(t)}catch{throw new Error(R.t("webpage.dialog.unsupportedUrl"))}}async function UW(n,t){const e=t.item.id,o=Z8(n).find(h=>h.id===e),r=w("div",["webpage-content"],null);if(H2(e)){const h=w("div",["help-container"],r),p=w("div",["help-content"],h),A=w("span",["help-icon"],p);A.innerHTML=uv,w("span",[],p,R.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:a}=_p(r,{required:!0,label:R.t("webpage.dialog.label"),placeholder:R.t("webpage.dialog.placeholder")}),d=n.getComponentOptions("webpage");if(!H2(e)&&!(d!=null&&d.hideHelpLink)){const h=w("div",["help-link-container"],r),p=w("a",["help-link-content"],h);w("span",[],p,R.t("webpage.dialog.helpLink"));const A=w("span",["help-link-icon"],p);A.innerHTML=hv,p.href=(d==null?void 0:d.helpLink)||"",p.target="_blank"}try{const h=await new Promise((v,B)=>{const D=new PW(r,{id:"webpage",title:R.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var M;const _=HW(i());try{await jW(_);const H=await $W(n,_);v((H==null?void 0:H.url)||"")}catch(H){if(((M=H==null?void 0:H.responseData)==null?void 0:M.statusCode)===415)if(H2(e))v(_);else throw s(R.t("webpage.dialog.unsupportedUrl")),H;else throw s(H.message||""),H}},onClose(){n.focus(),B()}});D.addListener("show",l),D.show(),a().addEventListener("keydown",async _=>{if(!_.isComposing){if(_.key==="Enter"){await D.handleOk(),_.preventDefault();return}_.key==="Escape"&&D.handleClose()}})}),p={id:K(),type:"embed",embedType:"webpage",embedData:{src:h}},A=n.insertBlock(t.containerId,t.blockIndex,p);return n.focus(),A}catch{return null}}function zW(n){const t=n.querySelector(".editor-preview-iframe"),e=t.src;t.src="about:blank";const o=setTimeout(()=>{t.src=e,clearTimeout(o)},300);return!0}function VW(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function WW(n,t){const e=T2(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:R.t("webpage.command.refresh"),icon:LL},{id:"open-page",name:R.t("webpage.command.openPage"),icon:hv}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return zW(i);case"open-page":return VW(r,i)}return!1}}),o=`${R.t("webpage.abstract")}`;return{...e,abstract:o}}const qW=S("webpage-embed");function GW(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:a}=s,d=n.addCustom(`webpage-${l}`,()=>new LW(n,e));g(qW,a,"The src from blockData is invalid "),d.create(n,s,t,i),setTimeout(()=>{n.isBlockWritable(i)&&n.addCustom("webpage-resizer",()=>new OW(n))}),e.height&&(i.style.height=`${e.height}px`)}function ZW(n,t,e){const{embedData:o,id:r}=e;return n.getCustom(`webpage-${r}`).update(n,t,o),e.height&&(t.style.height=`${e.height}px`),!0}function QW(n){return{name:"WebPage",insertEmbedCommandItems:Z8(n),handleInsertEmptyEmbed:UW}}function YW(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const Q8={embedType:"webpage",createEmbedContent:GW,getBlockProperties:WW,getOptions:QW,handleUpdateBlock:ZW,convertTo:YW},JW={webpage:{title:"\u7F51\u9875",youku:"\u4F18\u9177\u89C6\u9891",modao:"\u58A8\u5200",tencent:"\u817E\u8BAF\u89C6\u9891",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u56E0\u76EE\u6807\u7F51\u9875\u7684\u9650\u5236\uFF0C\u90E8\u5206\u7F51\u9875\u53EF\u80FD\u65E0\u6CD5\u6210\u529F\u9884\u89C8\u3002",helpLink:"\u5982\u4F55\u83B7\u53D6\u94FE\u63A5",label:"\u7F51\u9875\u5730\u5740",placeholder:"\u8BF7\u8F93\u5165",title:"\u63D2\u5165{name}",errorEnterUrl:"\u8BF7\u8F93\u5165\u7F51\u9875\u5730\u5740",unsupportedUrl:"\u6682\u4E0D\u652F\u6301\u63D2\u5165\u8BE5\u94FE\u63A5\u5185\u5BB9",okText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},abstract:"\u7F51\u9875",command:{refresh:"\u5237\u65B0\u9875\u9762",openPage:"\u6253\u5F00\u539F\u59CB\u9875\u9762"}}},KW={webpage:{title:"Webpage",youku:"Youku",modao:"Modao",tencent:"Tencent Video",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"Due to landing page limitations, some pages may not be properly displayed during preview.",helpLink:"How to get the URL link",label:"Website address",placeholder:"Please enter",title:"Insert {name}",errorEnterUrl:"Please enter website address",unsupportedUrl:"Unsupported URL",okText:"Confirm",cancelText:"Cancel"},abstract:"Webpage",command:{refresh:"Refresh page",openPage:"Open the original page"}}},XW={webpage:{title:"Web \u30DA\u30FC\u30B8",youku:"Youku \u52D5\u753B",modao:"Modao",tencent:"Tencent \u52D5\u753B",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u30A2\u30AF\u30BB\u30B9\u5148\u306E\u5236\u9650\u306B\u3088\u308A\u3001\u4E00\u90E8\u306E\u30DA\u30FC\u30B8\u304C\u8868\u793A\u3067\u304D\u306A\u3044\u5834\u5408\u304C\u3042\u308A\u307E\u3059\u3002",helpLink:"URL \u3092\u53D6\u5F97\u3059\u308B\u65B9\u6CD5",label:"URL",placeholder:"\u5165\u529B",title:"{name}\u3092\u633F\u5165",errorEnterUrl:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",unsupportedUrl:"\u3053\u306E URL \u306F\u633F\u5165\u3067\u304D\u307E\u305B\u3093",okText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB"},abstract:"Web \u30DA\u30FC\u30B8",command:{refresh:"\u30DA\u30FC\u30B8\u3092\u518D\u8AAD\u307F\u8FBC\u3080",openPage:"URL\u3092\u958B\u304F"}}};R.mergeLang({"zh-CN":JW,"en-US":KW,"ja-JP":XW});const oot="";function tq(n){const t=Object.entries(n);for(let e=0;e<t.length;e++){const[o,r]=t[e];if(o.toLocaleLowerCase()==="content-type")return r}return""}async function eq(n,t,e=!0){try{const o=await n.doc.request(t,{method:"get",responseType:"blob",withCredentials:e}),r=new FileReader,i=new Promise((h,p)=>{r.onload=h,r.onerror=p});r.readAsArrayBuffer(o.data),await i;const s=r.result,l=tq(o.headers).toLocaleLowerCase();let a="";if(l){const h=mm.default[l].extensions;h&&h.length>0&&(a=h[0])}return new File([s],`${Date.now()}.${a}`,{type:l})}catch{return null}}async function j2(n,t){return await eq(n,t)}async function Y8(n,t){const e=await j2(n,t);return e?await e.text():null}const nq=n=>{const t=n.getBoundingClientRect();return t.width<=1&&t.height<=1},oq=n=>{var i,s;const t=(i=n.getAttribute("width"))!=null?i:"",e=(s=n.getAttribute("height"))!=null?s:"",o=Number.parseInt(t,10),r=Number.parseInt(e,10);return!o||!r||o<=1&&r<=1},rq=n=>n!=null?n[n.textContent===void 0?"text":"textContent"]:"",J8={"zh-CN":"zh","zh-TW":"zh-tw","js-JP":"zh"},iq="https://embed.diagrams.net/?embed=1",sq="https://www.draw.io/embed.js",lq="https://cdn.jsdelivr.net/npm/pako@2.0.3/dist/pako.es5.js",cq=`<svg width="48" height="49" viewBox="0 0 48 49" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
599
599
|
<rect x="27" y="18.5" width="18" height="9" stroke="#C7C7C7" stroke-width="3"/>
|
|
600
600
|
<rect x="12" y="18.5" width="9" height="9" transform="rotate(45 12 18.5)" stroke="#C7C7C7" stroke-width="3"/>
|
|
601
601
|
<rect x="27" y="36.5" width="18" height="9" stroke="#C7C7C7" stroke-width="3"/>
|
|
@@ -715,7 +715,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
715
715
|
<add as="fillColor" value="#ffffff"/>
|
|
716
716
|
</add>
|
|
717
717
|
</mxStylesheet>
|
|
718
|
-
`,
|
|
718
|
+
`,K8=0,uq=30*1e3,X8="editor-empty-drawio",tk="show-full-screen-iframe",Fe=S("embed-block-drawio");function Mc(n){return n.options.componentsOptions.drawIO||{}}function dq(n){const e=Mc(n).lang||"zh-CN";return J8[e]||J8["zh-CN"]}function hq(n){var r;const e=((r=(Mc(n)||{}).cdn)==null?void 0:r.drawioIframe)||iq,o=dq(n);return Tm(e,{spin:1,proto:"json",configure:1,lang:o})}function fq(n){const t=()=>{g(Fe,n,"el does not exist");const o=document.body.clientWidth||document.documentElement.clientWidth,r=document.body.clientHeight||document.documentElement.clientHeight;n.setAttribute("width",`${o-2*K8}`),n.setAttribute("height",`${r-2*K8}`)},e=()=>{window.removeEventListener("resize",t)};return t(),window.addEventListener("resize",t),{disconnect:e}}async function mq(n){const e=(Mc(n)||{}).callbacks||{},{onCreateDrawIoFrame:o,onCloseDrawIoFrame:r}=e;let i=null,s;if(o)i=await o(n),g(Fe,i,"iframe create failed"),s=()=>{g(Fe,i,"iframe does not exist"),g(Fe,r,"missing parameters: onCloseDrawIoFrame"),r(n,i)};else{const l=w("div",["editor-drawio-iframe-container","loading"],document.body);l.setAttribute("data-placeholder",R.t("drawio.loading")),i=w("iframe",["drawio-iframe-element"],l),i.setAttribute("frameborder","0"),W(l,tk);const{disconnect:a}=fq(i);s=()=>{g(Fe,i,"iframe does not exist"),a(),document.body.removeChild(l),et(l,tk)}}return{drawioIframe:i,exit:s}}async function gq(n,t,e,o){var r,i;try{o&&Fe.debug("auto saving drawio data");const s=new Blob([e]),l=new File([s],"drawio.svg",{type:"image/svg+xml"});try{const a=n.findBlockById(it(t));if(a){const d=await n.doc.uploadResource(l),{resourceId:h}=d,A=n.getBlockData(a).embedData,v={src:h,height:A==null?void 0:A.height};n.updateEmbedData(a,v)}else Fe.error("block has been deleted")}catch(a){const d=`failed to upload drawio data: ${a.message}`;Fe.error(d)}}catch(s){const l=`failed to save drawio data: ${s.message}`,a=Mc(n);if((r=a.callbacks)!=null&&r.onError){const d=new Error(l);d.code="SaveDrawIo",(i=a.callbacks)==null||i.onError(n,d)}}}function pq(n,t,e,o,r,i,s){const l=()=>{window.removeEventListener("message",a),i()},a=async d=>{var h,p;if(g(Fe,o.contentWindow,"iframe.contentWindow does not exist"),d.data.length>0){const A=JSON.parse(d.data),v=e.xmlSvg||e.xml,B=document.querySelectorAll(".editor-drawio-iframe-container");switch(A.event){case"configure":o.contentWindow.postMessage(JSON.stringify({action:"configure",config:{defaultFonts:["Humor Sans","Helvetica","Times New Roman"]}}),"*");break;case"init":v!=null&&o.contentWindow.postMessage(JSON.stringify({action:"load",saveAndExit:1,noSaveBtn:1,noExitBtn:0,xml:v}),"*"),r(),B.forEach(T=>{et(T,"loading")});break;case"export":const D=Ud(A.data.substring(A.data.indexOf(",")+1));gq(n,t,D,!!((h=A.message)!=null&&h.autoSave)),(p=A.message)!=null&&p.autoSave||l();break;case"save":o.contentWindow.postMessage(JSON.stringify({action:"export",format:"xmlsvg",spin:"Saving graph"}),"*");break;case"exit":l();break}}};window.addEventListener("message",a)}async function ek(n,t,e,o){if(o)return;o=!0;const r=Mc(n)||{},{callbacks:i}=r;let s;i&&(i==null?void 0:i.onBeginInitDrawIo)&&i.onBeginInitDrawIo(n,t);const{drawioIframe:l,exit:a}=await mq(n);if(K0(n,t),e.src){const A=await Y8(n,n.doc.buildResourceUrl(e.src));A&&(e.xmlSvg=A)}pq(n,t,e,l,()=>{s=setInterval(()=>{!l||!l.contentWindow||l.contentWindow.postMessage(JSON.stringify({action:"export",format:"xmlsvg",spin:"Saving graph",autoSave:!0}),"*")},uq)},()=>{a(),s&&clearInterval(s);const A=n.findBlockById(it(t));A&&X0(n,A)});const p=hq(n);l.setAttribute("src",p)}async function Cq(n){var r,i;const t=Mc(n),e=((r=t.cdn)==null?void 0:r.drawio)||sq,o=((i=t.cdn)==null?void 0:i.pako)||lq;await vs(o,"editor-pako"),await vs(e,"editor-drawio"),await new Promise(s=>{setTimeout(s,100)})}function Aq(n){et(n,X8)}function U2(n){W(n,X8);const t=w("div",["drawio-empty-content"],n);t.innerHTML=cq}function z2(n,t){if(g(Fe,t,"Required data is missing in setGraph"),"src"in t){n.setAttribute("data-src",t.src);return}if("xmlSvg"in t){n.setAttribute("data-xmlsvg",t.xmlSvg);return}if("graph"in t){const{xml:e,graph:o}=t;n.graph=o,n.setAttribute("data-mxfile",e)}}function bq(n){return{src:n.getAttribute("data-src")||"",xmlSvg:n.getAttribute("data-xmlsvg")||"",xml:n.getAttribute("data-mxfile")||""}}function vq(n,t,e){g(Fe,n,"params error: src"),g(Fe,e,"params error: editor");const o=t,r=e.doc.buildResourceUrl(n),i=document.createElement("img");o.innerHTML="",o.appendChild(i),i.src=r,i.draggable=!1,z2(o,{src:n}),i.onload=()=>{nq(i)?U2(t):(i.style.width="100%",i.style.height="100%",Aq(t))}}function yq(n,t,e){g(Fe,e,"parameter missing"),Cq(e).then(()=>{const{mxUtils:o,mxGraph:r,mxCodec:i}=window;g(Fe,o,"External resource loading exception: mxUtils"),g(Fe,r,"External resource loading exception: MxGraph"),g(Fe,i,"External resource loading exception: MxCodec");const s=o.parseXml(n);t.innerHTML="";const l=s.documentElement;g(Fe,l,"Resource parsing exception"),g(Fe,l.nodeName==="mxfile","Resource parsing exception");const a=l.getElementsByTagName("diagram");g(Fe,a.length>0,"Resource parsing exception");let d;const h=a[0];if(h.text||h.textContent){const D=rq(h),T=atob(D),_=window.pako;g(Fe,_,"External resource loading exception: pako");const M=_.inflateRaw(Uint8Array.from(T,z=>z.charCodeAt(0)),{to:"string"}),H=decodeURIComponent(M);d=o.parseXml(H)}else{const D=new XMLSerializer().serializeToString(h.firstChild);d=o.parseXml(D)}const p=new r(t);p.resetViewOnRootChange=!1,p.foldingEnabled=!1,p.setTooltips(!1),p.setEnabled(!1),p.setHtmlLabels(!0);const A=o.parseXml(aq);new i(A).decode(A.documentElement,p.getStylesheet());const B=new i(d);B.decode(B.document.documentElement,p.getModel()),p.maxFitScale=1,p.fit(),p.center(!0,!1),z2(t,{graph:p,xml:n})})}function kq(n,t){t.innerHTML=n,z2(t,{xmlSvg:n});const e=t.querySelectorAll("svg");for(let o=0;o<e.length;o++){const r=e[o];if(!oq(r))return}U2(t)}function wq(n,t){return{...T2(n,t,{handleExecuteCommand:(o,r,i)=>{if(i.id==="edit"){const s=o.getBlockData(r).embedData;return ek(o,r,s,!1),!0}return!1}}),abstract:R.t("drawio.abstract")}}const Bq={"en-US":{drawio:{title:"Flowchart/UML",empty:"Empty graph",loading:"Loading",abstract:"Flowchart/UML"}},"zh-CN":{drawio:{title:"\u6D41\u7A0B\u56FE/UML",empty:"\u7A7A\u56FE\u8868",loading:"\u52A0\u8F7D\u4E2D",abstract:"\u6D41\u7A0B\u56FE/UML"}},"ja-JP":{drawio:{title:"\u30D5\u30ED\u30FC\u30C1\u30E3\u30FC\u30C8/UML",empty:"\u30B0\u30E9\u30D5\u30C7\u30FC\u30BF\u306A\u3057",loading:"\u8AAD\u8FBC\u4E2D",abstract:"\u30D5\u30ED\u30FC\u30C1\u30E3\u30FC\u30C8/UML"}}};R.mergeLang(Bq);const o1=S("embed-block-drawio"),Eq=!1;function xq(n,t,e,o){g(o1,e,`parameter missing: ${e}`),g(o1,n,`parameter missing: ${n}`),ek(n,t,o,Eq)}function nk(n,t,e){const{src:o,xml:r,xmlSvg:i}=e;o?vq(o,t,n):r?yq(r,t,n):i?kq(i,t):U2(t)}function Iq(n,t,e){const o=w("div",["editor-drawio-content","editor-embed"],null);t.appendChild(o),nk(n,o,e),e.height&&(t.style.height=`${e.height}px`,o.style.height=`${e.height-20}px`)}function Tq(n,t,e){const{src:o,xml:r,xmlSvg:i}=e,s=bq(t);if(o!==s.src||(r||"")!==s.xml||(i||"")!==s.xmlSvg){nk(n,t,e);return}const l=t.parentElement;e.height&&e.height!==Number.parseInt(l.style.height,10)&&(l.style.height=`${e.height}px`,t.style.height=`${e.height-20}px`)}function Dq(n,t,e,o,r,i){const s=e.embedData;Iq(n,t,s),Fu.register(n,i)}function Sq(n,t,e){const o=e.embedData,i=Rt(t).querySelector(":scope > .editor-drawio-content");return g(o1,i,"embed should not be null"),Tq(n,i,o),!0}function Lq(){return{name:"UML",insertEmbedCommandItems:[{id:"insert-drawio",name:R.t("drawio.title"),icon:jL,group:"common",order:600,subText:pn("insert-drawio")}],handleInsertEmptyEmbed:async(n,t)=>{const e={src:"",xml:"",xmlSvg:""},o=n.insertEmbed(t.containerId,t.blockIndex,"drawio",e);return setTimeout(()=>{const i=Rt(o).querySelector(":scope > .editor-drawio-content");g(o1,i,"embed should not be null");const s=n.getBlockData(o);xq(n,o,i,s.embedData)},100),o}}}function Mq(n,t,e,o){const{embedData:r}=t,i=r;return o==="html"?i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.xmlSvg?i.xmlSvg:"<p>[drawio]</p>":o==="markdown"?i.src?`})`:i.xmlSvg?i.xmlSvg:"[drawio]":i.src?`[drawio](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:"[drawio]"}const V2={embedType:"drawio",getOptions:Lq,createEmbedContent:Dq,handleUpdateBlock:Sq,getBlockProperties:wq,convertTo:Mq},lot="",cot="",Rq=500,Oq=300,W2=S("code-editor");function _q(n){const t=n.closest(".embed-code-editor-container");return g(W2,t,"code-editor-container non-existent"),t}function Fq(n,t,e){const o=n.target;g(W2,o,"Parameter error: textarea must be an element");const r=o.value;_q(o).remove(),et(t,"editing"),e(r),Rt(t).style.removeProperty("margin-top")}function Pq(n,t){g(W2,n,"Parameter Error: handleCodeUpdate[event]");const e=n.target.value;t(e)}const Nq=He.default(Pq,Rq);function $q(n,t,e,o,r){n.domEvents.addEventListener(t,"blur",(i,s)=>{Fq(s,e,r)}),n.domEvents.addEventListener(t,"keyup",(i,s)=>{const l=s.target;s.key==="Escape"&&l.blur()}),n.domEvents.addEventListener(t,"input",(i,s)=>{Nq(s,o)})}function Hq(n,t,e){const{height:o,codeValue:r,onChange:i,onEnd:s}=e,l=o||Oq,a=Rt(t),d=le(t),h=w("div",["embed-code-editor-container"],d),p=w("textarea",["embed-code-editor-textarea"],h);p.value=r||"",p.setAttribute("spellcheck","false"),h.style.height=`${l}px`,$q(n,p,t,i,s),a.style.marginTop=`${l}px`,W(t,"editing"),window.requestAnimationFrame(()=>{p.setSelectionRange(0,0),p.focus(),p.scrollTop=0})}var q2={exports:{}};/**
|
|
719
719
|
* @license
|
|
720
720
|
* Lodash <https://lodash.com/>
|
|
721
721
|
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
@@ -747,4 +747,4 @@ ${i.mermaidText}
|
|
|
747
747
|
${i.flowchartText}
|
|
748
748
|
\`\`\`\`\`\``}return"[flowchart]"}const lk={embedType:"flowchart",convertFrom:uG,handleUpdateBlock:aG,createEmbedContent:cG,getBlockProperties:dG,convertTo:hG},fG=S("plantuml-helper");function ck(n,t){var l;let o=((l=(n.getComponentOptions("plantuml")||{}).cdn)==null?void 0:l.plantuml)||qq;o.endsWith("/")||(o+="/");const r=GB.default.encode(t);g(fG,r,r),o+=r;const s=new URLSearchParams(document.location.search).get("doc");return Tm(o,{id:`${s}-${K()}`})}async function mG(n,t){try{const e=await j2(n,t);return(await n.doc.uploadResource(e)).resourceId}catch{return Promise.resolve(t)}}class _c extends G2{constructor(t){super(t,"plantuml","plantumlText")}static get(t,e){return t.addCustom(`plantuml-${e.id}`,()=>new _c(t))}code2ObjectUrl(t){return Promise.resolve(ck(this.editor,t))}code2ResourceId(t){const e=ck(this.editor,t);return mG(this.editor,e)}destroy(){}}function gG(n,t,e){_c.get(n,e).createEmbedContent(t,e)}function pG(n,t,e){const o=_c.get(n,e),r=Rt(t);return o.updateEmbedContent(r,e),!0}function CG(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="plantuml"||r!=="```plantuml"||!tt(n,t))return null;const i={src:"",plantumlText:""};return{blockData:{id:K(),type:"embed",embedType:"plantuml",embedData:i},onConverted:(a,d)=>{_c.get(a,a.getBlockData(d)).editGraph(Rt(d))}}}function AG(n,t){return _c.get(n,n.getBlockData(t)).getBlockProperties(t)}function bG(n,t,e,o){const{embedData:r}=t,i=r;if(o==="html")return i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.flowchartText?`<div>${i.flowchartText}</div>`:"<p>[plantuml]</p>";if(o==="markdown"){if(i.src)return`})`;if(i.flowchartText)return`\`\`\`plantuml\`\`\`
|
|
749
749
|
${i.flowchartText}
|
|
750
|
-
\`\`\`\`\`\``}return"[plantuml]"}const ak={embedType:"plantuml",convertFrom:CG,handleUpdateBlock:pG,createEmbedContent:gG,getBlockProperties:AG,convertTo:bG},aot="",vG="hr",yG={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},kG={dividingLine:{type:"Separation line",abstract:"Separation line"}},wG={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};R.mergeLang({"zh-CN":yG,"en-US":kG,"ja-JP":wG});function BG(n,t){const e=w("div",["editor-embed-container"],t);w("hr",["editor-embed-hr"],e)}function EG(n,t,e,o){return o==="html"?"<hr />":o==="markdown"?"---":"------------"}function xG(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:R.t("dividingLine.type"),icon:UL,order:500,group:"common",subText:pn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:o}=t;return n.insertEmbed(e,o,vG,{})}}}function IG(n,t,e){const{data:o}=e;if(!o||o.embedType!=="dividing-line"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"hr",embedData:r}}}function TG(){return{abstract:R.t("dividingLine.abstract")}}const uk={embedType:"hr",createEmbedContent:BG,convertTo:EG,getOptions:xG,convertFrom:IG,getBlockProperties:TG},uot="",dot="",DG={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>'},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"}}},SG={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>'},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"}}},LG={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>'},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"}}};R.mergeLang({"zh-CN":DG,"en-US":SG,"ja-JP":LG});var Vo=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(Vo||{}),Nu=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(Nu||{});const dk=10*1024*1024,MG=["wav","mp3","aac","ogg","webm","flac"],RG=["ogg","mp4","webm"],OG=()=>{};function hk(n){var h,p,A,v,B,D;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:o,callbacks:r}=t,i=(p=e==null?void 0:e.audio)!=null?p:MG,s=(A=e==null?void 0:e.video)!=null?A:RG,l=(v=o==null?void 0:o.audio)!=null?v:dk,a=(B=o==null?void 0:o.video)!=null?B:dk,d=(D=r==null?void 0:r.onError)!=null?D:OG;return{allowedMedias:{audio:i,video:s},maxSize:{audio:l,video:a},callbacks:{onError:d}}}function _G(n,t){const e=i=>i.map(s=>`.${s}`).join(","),{allowedMedias:o}=hk(n),r=o[t];return r?e(r):"*"}function FG(n,t,e){const{maxSize:o,callbacks:r,allowedMedias:i}=hk(t),{[e]:s}=o,{[e]:l}=i;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,r!=null&&r.onError&&(r==null||r.onError(t,d)),d}const a=Aa(n.name);if(l&&!l.includes(a)){const d=new Error(`media file is not allowed: ${a}`);throw d.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(t,d)),d}}function PG(n){return n===Nu.Empty||n===Nu.Error}const Pe=S("media");class NG extends be.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,o)=>{if(!o.target||!(o.target instanceof Node)||!(o.target instanceof Element?o.target:o.target.parentElement))return;const i=ot(o.target);if(!i||!i.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",it(i))});m(this,"handleUploadFile",async e=>{g(Pe,this.abstract,"no abstract"),g(Pe,this.mediaContainer,"The media element not exist");const{editor:o}=this.options,r=ot(this.mediaContainer);g(Pe,r,"The block element not exist");const i=o.getBlockData(r);try{const{resourceId:s}=await o.doc.uploadResource(e,{onProgress:p=>{this.renderProgress(p,e)}}),{name:l,type:a,size:d}=e,h={...i,embedData:{...i.embedData,src:s,fileName:l,fileSize:d,fileType:a}};o.updateBlockData(r,h)}catch(s){Pe.error(s),this.emit("mediaError",o,"upload_error",i.id),this.renderRetry(e)}et(r,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){g(Pe,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){g(Pe,this.abstract,"no abstract");const{editor:e,createMediaElement:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract;g(Pe,this.mediaContainer,"The media element not exist");const s=ot(this.mediaContainer);g(Pe,s,"The block element not exist");const l=e.getBlockData(s),a=l.embedData.src,d=w("div",["media-error","embed-selected-content","embed-hover-content"],null),h=w("span",["media-error-icon"],d);h.innerHTML=r;const p=w("div",[],d);p.innerHTML=R.t("media.load.failed",{name:i}),d.appendChild(p);const A=p.querySelector(".retry-upload");return g(Pe,A,"The element not exist"),e.domEvents.addEventListener(A,"click",(v,B)=>{const D=w("div",["media-element"],null),T=this.getResourceUrl(a),_=o(v,D,l,T);this.unbindMediaEvent(),this.media=_,this.bindMediaEvent(),this.updateMediaContent(D)}),this.setFullScreen(),d}renderRetry(e){g(Pe,this.abstract,"no abstract");const{editor:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract,s=w("div",["media-error","embed-selected-content","embed-hover-content"],null),l=w("span",["media-error-icon"],s);l.innerHTML=r;const a=w("div",[],s);a.innerHTML=R.t("media.upload.failed",{name:i}),s.appendChild(a);const d=a.querySelector(".retry-upload");g(Pe,d,"The element not exist"),o.domEvents.addEventListener(d,"click",()=>{o.readonly||(g(Pe,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(s),this.setFullScreen()}renderProgress(e,o){g(Pe,this.mediaContainer,"The media element not exist");const r=this.mediaContainer.querySelector(":scope .media-progress"),i=e===-1||e===100?100:e;if(r){const{updateProgressElement:s}=this.options;s(r,i)}else{const{createProgressElement:s}=this.options,l=ot(this.mediaContainer);g(Pe,l,"The element not exist"),W(l,"media-block-uploading");const a=w("div",["media-progress"],null);s(a,i,o),this.updateMediaContent(a)}this.setFullScreen()}renderMediaElement(e){g(Pe,this.mediaContainer,"The media element not exist");const o=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:r,updateMediaElement:i,editor:s}=this.options,l=this.getResourceUrl(e.embedData.src);if(o){const a=i(s,o,e,l);this.unbindMediaEvent(),this.media=a,this.bindMediaEvent()}else{const a=w("div",["media-element"],null),d=r(s,a,e,l);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent(),this.updateMediaContent(a)}}renderEmpty(e){g(Pe,this.abstract,"no abstract"),g(Pe,this.mediaContainer,"The media element not exist");const o=w("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);o.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(o);const{editor:r}=this.options;r.findBlockById(e.id)&&this.emit("mediaError",r,"empty",e.id),this.setFullScreen()}getResourceUrl(e){const{editor:o}=this.options;return o.doc.buildResourceUrl(e)}setFullScreen(){g(Pe,this.mediaContainer,"The media element not exist"),W(this.mediaContainer,"full-screen")}removeFullScreen(){g(Pe,this.mediaContainer,"The media element not exist"),et(this.mediaContainer,"full-screen")}updateBlockAlign(e,o){const r=ot(o);g(Pe,r,"The block element not exist");const{align:i}=e;e.embedType==="video"&&(r.hasAttribute("data-style-align")&&r.removeAttribute("data-style-align"),r.setAttribute("data-style-align",i))}render(e,o){const{src:r}=e.embedData;(!this.mediaContainer||!o.contains(this.mediaContainer))&&(this.mediaContainer=w("div",["media"],o)),this.updateBlockAlign(e,o),PG(r)?r===Nu.Empty&&this.renderEmpty(e):this.renderMediaElement(e)}setAbstract(e){this.abstract=e}}S("media-embed");const $G="left";class fk{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var p;const{containerId:o,blockIndex:r}=e;let i;(p=e.data)!=null&&p.file&&(i=e.data.file);const s=_G(t,this.embedType);if(i=i!=null?i:await zl(s,{}),!i)return null;const{mediaType:l}=this.getAbstract();try{FG(i,t,l)}catch{return null}const a={id:K(),type:"embed",embedType:this.embedType,embedData:{src:Nu.Empty}};l==="video"&&(a.align=$G);const d=t.insertBlock(o,r,a);return await this.getMedia(t,a.id).handleUploadFile(i),d})}getMedia(t,e){const o=t.addCustom(`media-${e}`,()=>new NG({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return o.setAbstract({...this.getAbstract()}),o}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:o,order:r,group:i}=this.getAbstract();return{name:o,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:r,group:i,subText:pn(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,o){const{id:r}=o;this.getMedia(t,r).render(o,e)}handleUpdateBlock(t,e,o){const{id:r}=o,i=this.getMedia(t,r),s=Rt(e);return i.render(o,s),!0}handleDeleteBlock(t,e){const o=e.id,r=this.getMedia(t,o);r.removeAllListeners(),r.destroy()}convertTo(t,e,o,r){const i=e.embedData,s=t.doc.buildResourceUrl(i.src,{withToken:!0});return r==="html"?`<${i.type} src="${s}" />`:r==="markdown"?``:s}}function mk(n,t){const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e),r=w("div",["uploading-progress-bar-value"],o);r.style.width=`${t}%`}function gk(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const HG=S("media-audio");class jG extends fk{constructor(){super(...arguments);m(this,"embedType",Vo.AUDIO);m(this,"updateProgressElement",gk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["audio-container","embed-hover-content","embed-selected-content"],o),l=w("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=i,setTimeout(()=>{this.getMedia(e,r.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:$L,mediaName:R.t(`media.${Vo.AUDIO}.menuItem`),menuItem:R.t(`media.${Vo.AUDIO}.menuItem`),order:800,mediaType:Vo.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${R.t(`media.${Vo.AUDIO}.abstract`)}`}}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .audio-container > audio");return g(HG,s,"The media element not exist"),s.src!==i&&(s.src=i),s}createProgressElement(e,o){const r=w("audio",[],e);r.innerHTML="Your browser does not support the <code>audio</code> element.",r.controls=!0,r.src="about:blank",mk(e,o)}}const pk=new jG;S("video-resizer");function Ck(n){return n&&Le(n)&&Un(n)==="video"}const UG=50;class Z2{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&(e&&Ck(e)&&this.disableBlockResize(e),t&&Ck(t))){const o=this.getVideoElement(t);if(!o)return;this.enableBlockResize(t,o)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const o=t.getBlock();if(!o)return;const r=o.getBoundingClientRect().width,i=Math.min(Math.max(e.width,UG),r);this.currentResizableElement.style.width=`${i}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const o=this.editor.getBlockData(e),{width:r}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...o,width:r})});this.editor=t,pe.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,pe.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Rt(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const o=this.editor.addCustom(`${it(t)}-resizer`,()=>new wu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));o.enableResize(t,e),o.removeListener("resizing",this.handleResizing),o.removeListener("resized",this.handleResized),o.addListener("resizing",this.handleResizing),o.addListener("resized",this.handleResized),this.currentResizableElement=e}}const zG=S("video");class VG extends fk{constructor(){super(...arguments);m(this,"embedType",Vo.VIDEO);m(this,"updateProgressElement",gk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["video-container","embed-selected-content","drag-preview-element"],o),l=w("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=i,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new Z2(e)),this.getMedia(e,r.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).removeFullScreen()}),r.width&&(l.style.width=`${r.width}px`),l});m(this,"createProgressElement",(e,o,r)=>{const i=w("video",["progress-video"],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,mk(e,o),Ul(r).then(s=>{const l=e.querySelector(".progress-video");l&&Um(e)&&(l.src=s)})})}getAbstract(){return{mediaName:R.t(`media.${Vo.VIDEO}.menuItem`),mediaIcon:HL,menuItem:R.t(`media.${Vo.VIDEO}.menuItem`),order:700,mediaType:Vo.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`[${R.t(`media.${Vo.VIDEO}.abstract`)}]`}}handleMediaError(e,o,r){const i=e.addCustom("video-resizer",()=>new Z2(e)),s=e.getBlockById(r);i.disableBlockResize(s)}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .video-container > video");g(zG,s,"The media element not exist"),s.src!==i&&(s.src=i),r.width?s.style.width=`${r.width}px`:s.style.width="";const l=e.getBlockById(r.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new Z2(e)).updateResizer(l)}),s}}const Ak=new VG,bk=[Ef,Df,U0,I9],Q2=[V2,Qy,rk,lk,ak,N9,uk,Ak,pk,e8,Uy,Qz],vk=[T0,P2,hy];function WG(n,t,e){var r,i,s;const o=Ha(n,t,{components:{blocks:[...bk,...((r=e==null?void 0:e.components)==null?void 0:r.blocks)||[]],embeds:[...Q2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[...vk,...((s=e.components)==null?void 0:s.boxes)||[]],textRenders:[new C0],options:{...e.componentsOptions}}});return o.readonly=!0,o.addCustom("heading-collapse",()=>new R2(o)),o.addCustom("editor-tooltip",()=>new Af(o)),o.addListener("clickLink",(l,a,d)=>{var p;if((p=e==null?void 0:e.events)!=null&&p.onClickLink){e.events.onClickLink(l,a,d);return}const h=d.getAttribute("link");h&&(l.readonly||a.ctrlKey||a.metaKey)&&window.open(h,"_blank")}),o}class yk{constructor(t){this.createOptions=t,t.lang&&R.setLang(t.lang)}createHistoryEditor(t,e){return WG(t,e,this.createOptions)}}S("create-editor");function kk({root:n,childDoc:t,doc:e}){t.uploadResource=e.uploadResource.bind(e),t.buildResourceUrl=e.buildResourceUrl.bind(e);const o=Ha(n,t,{shortcuts:[Sh],components:{blocks:[Ef,Df],decorators:[new Sf],embeds:[e8,V2,Qy,rk,lk,ak,N9,uk,Ak,pk],boxes:[T0,P2],options:{image:{defaultAlign:"left"}}}});return o.input.addHandler(new xf),o.input.addHandler(new c2(o)),o.input.addHandler(new f2(o)),o.input.addHandler(new tz(o)),o.input.addHandler(new _f),o.addCustom("image-paste-handler",()=>new l2(o)),o}function qG(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),o=new Set;e.forEach(r=>{const i=ot(r);i&&o.add(i)}),o.forEach(r=>{ez(n,r,t)})}class GG{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const o=e.groupId;this.getComments().filter(i=>i.groupId===o).length===0&&qG(this.editor,o)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){var r,i;const o=kk({root:t,childDoc:e,doc:this.doc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new F2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.doc.getUser().userId}}class ZG{constructor(t,e){m(this,"listeners",new Set);this.editor=t,this.localDoc=e}get doc(){return this.localDoc.toJSON()}getComments(){return Object.values(this.doc.comments)}getComment(t){return this.doc.comments[t]}getCommentDoc(t){const e=this.doc.comments[t];return bp(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){var r,i;const o=kk({root:t,childDoc:e,doc:this.localDoc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new F2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const QG={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}"}},YG={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}"}},JG={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"}};R.mergeLang({"zh-CN":QG,"en-US":YG,"ja-JP":JG});const KG="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",XG=()=>Dm(KG);async function tZ(n){return new Promise((t,e)=>{const o=new Image;o.onload=()=>{t({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=e,o.src=n})}async function wk(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};const e=await Ul(new File([t],"",{})),o=await tZ(e);return o.width===void 0||o.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||o.width*n.height/o.height,height:n.height||o.height*n.width/o.width,buffer:t}:{width:o.width,height:o.height,buffer:t}}function eZ(n,t){let e=n.filter(s=>s!=null);const o=t-(e.length-1)*20,r=.87,i=e.reduce((s,l)=>s+l.width,0);return i>o&&(e=e.map(s=>({width:s.width*o/i,height:s.height*o/i,buffer:s.buffer}))),e.map(s=>({width:s.width*r,height:s.height*r,buffer:s.buffer}))}function Bk(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let o;switch(e%3){case 0:o=gt.LevelFormat.DECIMAL;break;case 1:o=gt.LevelFormat.LOWER_LETTER;break;default:o=gt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:o,text:`%${e+1}. `,alignment:gt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(e+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function nZ(){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:gt.LevelFormat.BULLET,text:t,alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function oZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2611",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}function rZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2610",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}var $u=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))($u||{});const iZ=[{levels:Bk(),reference:"number-numbering-reference"},{levels:nZ(),reference:"number-bullet-reference"},{levels:oZ(),reference:"checked-bullet-reference"},{levels:rZ(),reference:"unchecked-bullet-reference"}];function sZ(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 lZ(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 cZ(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 Ek(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},o=e(t[1]),r=e(t[2]),i=e(t[3]);return`${o}${r}${i}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function tn(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 xk(n,t,e){for(let o=0;o<=e;++o){const r=`${t}${o}`;if(tn(n,r))return r}}function r1(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function Y2(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function Ik(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function uZ(n){const t=tn(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const o of e){const r=o.split(":");if(r.length!==2)continue;const i=r[0].trim().toLowerCase(),s=r[1].trim().toLowerCase();i==="font-size"&&r1(n,"inline-style-font-size",s),i==="color"&&r1(n,"inline-style-color",s),i==="background-color"&&r1(n,"inline-style-background-color",s),i==="font-family"&&r1(n,"inline-style-font-family",s)}}function dZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function hZ(n){const t=`${tn(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function fZ(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 mZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function gZ(n){return tn(n,"inline-style-font-family")}function pZ(n){const t=tn(n,"inline-style-background-color");return Ek(t)}function CZ(n){const t=tn(n,"inline-style-color");return Ek(t)}function AZ(n){uZ(n);const t=tn(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!tn(n,"style-code"),link:Ik(tn(n,"link")),size:hZ(n),text:t?mZ(n):fZ(n)||n.insert,bold:!!tn(n,"style-bold"),underline:!!tn(n,"style-underline"),italics:!!tn(n,"style-italic"),strike:!!tn(n,"style-strikethrough"),superScript:!!tn(n,"style-super"),subScript:!!tn(n,"style-sub"),math:tn(n,"type")==="math"?tn(n,"src"):void 0,mention:t,fontFamily:gZ(n),background:pZ(n),color:t?"338fe5":sZ(xk(n,"style-color-",6))||CZ(n),highlight:xk(n,"style-bg-color-",13)}}function bZ(){return[new gt.Paragraph({border:{top:{color:"auto",style:gt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new gt.Paragraph({spacing:{line:0}})]}function vZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function yZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function kZ(n,t){return new gt.Paragraph({children:[new gt.ExternalHyperlink({children:[new gt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function Tk(n){if(n.heading!=null)return`Heading${n.heading}`}function Dk(n){if(n.alignment!=null){if(n.alignment==="center")return gt.AlignmentType.CENTER;if(n.alignment==="right")return gt.AlignmentType.RIGHT;if(n.alignment==="left")return gt.AlignmentType.LEFT}}function wZ(n){if(n.indent)return{left:gt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:gt.convertInchesToTwip(.3*n.padding)}}function BZ(n){return{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function EZ(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function Sk(n,t){let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const o=n.size||t,r=o!=null?Math.floor(o*1.5+.5):void 0;return new gt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:gt.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:r,style:e,font:n.fontFamily?EZ(n.fontFamily):void 0,shading:n.background?BZ(n.background):void 0,color:n.color,highlight:lZ(n.highlight)})}function xZ(n,t){if(n.link)return new gt.ExternalHyperlink({children:[Sk(n,t)],link:n.link})}async function Lk(n,t,e,o,r){const i=await r(n,t,e);if(i==null)return;const s=await wk({width:o||0,height:0,src:e},i);return new gt.ImageRun({data:i,transformation:{width:s.width||100,height:s.height||20}})}function IZ(n){if(n.heading||n.heading)return n.heading}function TZ(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function DZ(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function SZ(n,t){var o;const e=[];if(n.text&&Array.isArray(n.text)){for(let r=0;r<n.text.length;r++){const i=n.text[r];if(((o=i.attributes)==null?void 0:o.box)===!0&&t){const s=await t(i);if(s){n.text.splice(r+1,0,...s);continue}}e.push(AZ(i))}return e}}function LZ(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 MZ(n,t){if(n.type==="embed"&&n.embedType&&Y2(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(o=>{const r=t(o),i=n.embedData[`${r}_width`],s=n.embedData[`${r}_height`];return{src:o,width:i,height:s}})}function RZ(n){if(n.padding)return n.padding}function OZ(n){return!!(n.type==="embed"&&n.embedType&&Y2(n.embedType)&&n.embedData&&n.embedData.src)}async function i1(n,t,e){return{quoted:!!n.quoted,heading:IZ(n),alignment:TZ(n),indent:DZ(n),padding:RZ(n),texts:await SZ(n,e),list:LZ(n),images:MZ(n,t),border:OZ(n)}}async function _Z(n,t,e,o){const r=[];if(!n.children)return[];for(const i of n.children){const s=[];for(const l of t.blocks[i])s.push(await i1(l,e,o));r.push(s)}return r}const FZ=S("to-docx");function PZ(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 NZ(n,t,e,o){const r=!!n.hasColTitle,i=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let a=0;a<t;a++)for(let d=0;d<e;d++)(r&&d===0||i&&a===0||s&&a%2===1)&&(o[a][d].color=l)}function $Z(n){g(FZ,n.children,"no table children");const t=n.rows,e=n.cols,o=n.colsWidth;if(o)for(let s=0;s<o.length;s++)o[s]===0&&(o[s]=100);const r=PZ(t,e);let i=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(r[s][l].originalWidth=o?o[l]:void 0,r[s][l].from!==void 0)continue;const a=n.children[i];i+=1,r[s][l].cellId=a,r[s][l].color=cZ(n[`${a}_background`]),r[s][l].width=o?o[l]:100,r[s][l].align=n[`${a}_align`];const d=n[`${a}_rowSpan`]||1,h=n[`${a}_colSpan`]||1;if(r[s][l].rowSpan=d,r[s][l].colSpan=h,d>1||h>1){let p=0;for(let A=0;A<d;A++)for(let v=0;v<h;v++)A===0&&(p+=o?o[l+v]:80),!(A===0&&v===0)&&(r[s+A][l+v].from=[s,l]);r[s][l].width=p}}return NZ(n,t,e,r),r}async function HZ(n,t,e,o,r,i,s,l,a,d){async function h(v){if(l){const B=await l(r,i,v);if(B){await o.addDoc(n,B,d);return}}if(v.type==="text"||v.textOnly===!0){const B=await i1(v,s,a);await o.addTextBlock(B);return}if(v.type==="code"){const B=await _Z(v,e,s,a);await o.addCodeBlockObject(B);return}if(v.type==="list"&&v.textOnly!==!0){const B=await i1(v,s,a);await o.addListBlockObject(n,B);return}if(v.type==="embed"&&v.embedType){const B=v,D=B.embedData,T=B.embedType;if(Y2(T)){const _=await i1(v,s,a);await o.addImagesBlockObject(v,_,d)}else v.embedType==="hr"?o.addSeparatorBlock():v.embedType==="video"?o.addVideoPlaceholder():v.embedType==="audio"?o.addAudioPlaceholder():v.embedType==="webpage"?o.addHyperlinkParagraph(Ik(D.src),D.title):o.addOtherEmbedBlock(T,v.embedData);return}if(v.type==="table"){let B=[];if(v.colsWidth)B=v.colsWidth;else{const T=v.cols;B=new Array(T);for(let _=0;_<B.length;_++)B[_]=100;v.colsWidth=B}const D=$Z(v);await o.addTableMatrix(B,D,e),o.addEmptyParagraph()}}function p(v){const B=[];for(const{type:D,data:T}of v.embedData.exportSpec){if(D==="text"){const _={id:K(),text:[{insert:T}],type:"text"};B.push(_);continue}if(D==="image"){const _={id:K(),type:"embed",embedType:"image",align:"left",embedData:{src:T}};B.push(_);continue}if(D==="link"){const _={id:K(),type:"embed",embedType:"webpage",embedData:{src:T.url,title:T.title}};B.push(_);continue}}return B}function A(v){var B;return(B=v==null?void 0:v.embedData)!=null&&B.exportSpec?p(v):[v]}for(const v of t)for(const B of A(v))await h(B)}function jZ(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const UZ=S("to-docx");class zZ{constructor(t,e,o,r,i,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=o,this.readImageFunc=r,this.convertBlocksFunc=i,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new gt.Paragraph({heading:Tk(t),alignment:Dk(t),children:await this.paragraphsFromBlockTexts(t),indent:wZ(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new gt.Paragraph({text:`[${R.t("docx.imageExportFailed")}]`,shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=dZ(this.defaultFontSize,t.heading),o=[];for(const r of t.texts){if(r.link){const i=xZ(r,e);i&&o.push(i);continue}if(r.box&&r.box.type&&r.box.type==="br"){o.push(new gt.TextRun({text:"",break:1}));continue}if(r.box&&r.box.type&&r.box.type==="image"){const i=await Lk(this.appId,this.docId,r.box.src,r.box.width,this.readImageFunc);i&&o.push(i);continue}if(r.math){const i=await Lk(this.appId,this.docId,r.math,0,this.readImageFunc);i&&o.push(i);continue}o.push(Sk(r,e))}return o}async addCodeBlockObject(t){for(const e of t)for(const o of e){const r={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new gt.Paragraph({style:"Code",border:{left:{...r},right:{...r},top:{...r},bottom:{...r}},children:await this.paragraphsFromBlockTexts(o)}))}}async addListBlockObject(t,e){if(e.list==null)return;let o;const r=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[r])o=this.state.listInstMap[r];else if(o=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[r]=o,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${o}`,l=Bk([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:o}),this.state.listRefMap[r]=s}else e.list.ordered?this.state.listRefMap[r]=$u.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[r]=$u.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[r]=$u.UNCHECKED:this.state.listRefMap[r]=$u.BULLET;const i=Tk(e);e.texts&&this.paragraphs.push(new gt.Paragraph({heading:i,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[r],level:e.list.level-1,instance:o}}))}imageDimWithBufferToImageRun(t){return new gt.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,o){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:a}=t.embedData;a||this.addEmptyImagePlaceHolder()}return}const r=[],i=await Promise.all(e.images.map(async a=>{const d=await this.readImageFunc(this.appId,this.docId,a.src);if(d)return wk(a,d);r.push(a.src)})),s=eZ(i,o),l={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new gt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:Dk(e)||gt.AlignmentType.CENTER,children:s.map(a=>this.imageDimWithBufferToImageRun(a)).flatMap((a,d,h)=>a==null?[]:h.length-1!==d?[a,new gt.TextRun({text:" "})]:a)})),r.forEach(a=>{this.addHyperlinkParagraph(a)})}addSeparatorBlock(){bZ().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new gt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(vZ())}addAudioPlaceholder(){this.paragraphs.push(yZ())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(kZ(t,e))}async addTableMatrix(t,e,o){const r=t.map(i=>i!==0?i*15:1500);this.paragraphs.push(new gt.Table({rows:await this.generateTableRows(e,o),columnWidths:r}))}async generateRowCells(t,e){const o=[];for(const r of t){const i=r.cellId;if(i===void 0)continue;const s=r.width*.9;o.push(new gt.TableCell({children:await this.convertBlocksFunc(i,e.blocks[i],e,this.appId,this.docId,this.state,s),columnSpan:r.colSpan,rowSpan:r.rowSpan,width:{type:gt.WidthType.DXA,size:r.width*15},shading:r.color?{fill:r.color,type:gt.ShadingType.CLEAR,color:"auto"}:void 0}))}return o}async generateTableRows(t,e){const o=[];for(const r of t)o.push(new gt.TableRow({children:await this.generateRowCells(r,e)}));return o}async addDoc(t,e,o){const r=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,o);r&&(this.paragraphs=this.paragraphs.concat(r))}async addOtherEmbedBlock(){}}class VZ{constructor(t,e,o,r,i,s,l,a){m(this,"convertBlocks",async(t,e,o,r,i,s,l=720)=>{const a=new zZ(r,i,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await HZ(t,e,o,a,r,i,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),a.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=o,this.readImage=r,this.defaultFontSize=i,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=a}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,o){const r=new gt.ImportDotx,i=this.templateData?await r.extract(this.templateData):void 0,s=t.blocks.root;g(UZ,s,"data must have blocks");const l=jZ(),a=await this.convertBlocks("blocks",s,t,e,o,l),d=this.backgroundImageOptions?{default:new gt.Header({children:[new gt.Paragraph({children:[new gt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new gt.Document({numbering:{config:[...iZ,...l.levelConfigs]},sections:[{headers:d,children:a,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:i});return gt.Packer.toBlob(h)}}async function WZ(n,t,e,o){const r=n.doc.buildResourceUrl(o,{withToken:!0});let i=await A7(r);if(!i)return;if(i.type.indexOf("/svg")!==-1){const l=await g7(i);l&&(i=new File([l],i.name))}return await i.arrayBuffer()}async function qZ(n,t,e){const o=n.editorBlocks.getBlockClass(e.type);if(o.toStandardDoc)return o.toStandardDoc(n,e,t)}async function GZ(n,t){const e=t.attributes,o=n.editorBoxes.getBoxClass(e.type);if(o.toStandardText)return o.toStandardText(n,e)}async function ZZ(n,t){let{template:e,download:o,backgroundImageOptions:r}=t!=null?t:{};e||(e=XG());const i=n.doc.toJSON(),s=(p,A,v)=>WZ(n,p,A,v),l=async(p,A,v)=>qZ(n,i,v),a=async p=>GZ(n,p),h=await new VZ(e,i,Fd.default,s,void 0,l,a,r).convert("_appId","_docId");if(o){const p=URL.createObjectURL(h),A=document.createElement("a");A.setAttribute("download",`${C7(n)}.docx`),A.setAttribute("href",`${p}`),A.click(),A.remove()}return h}const J2=S("create-editor");async function QZ(n,t){var s,l,a,d,h,p,A,v,B,D,T,_,M,H;g(J2,n,"app does not exists"),t.lang&&R.setLang(t.lang),Ii.level=(s=t.logLevel)!=null?s:ha.DEBUG;const e=t.onReauth?async()=>{var ft;const z=t.user.userId,q=t.docId,rt=await((ft=t.onReauth)==null?void 0:ft.call(t,z,q,t.permission));return{userId:z,docId:q,permission:t.permission,appId:t.appId,token:rt,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,o={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},r=await Ka.load(o),i=Ha(n,r,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,components:{blocks:[...bk,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...Q2,...((a=t.components)==null?void 0:a.embeds)||[]],boxes:[...vk,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Gp,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new Sf,new yp],insertions:[wg],blockHooks:[new e2,new G7,...((p=t.components)==null?void 0:p.blockHooks)||[]],textRenders:[new iy,new C0],options:{...t.componentsOptions}},shortcuts:[bz,TN,pH,O0,_8,SO,S0,eV,Sh,...t.shortcuts||[]],colors:["#338FE5","#24B47E","#F0A100","#E52727","#9678D3","#2CB2AE","#EB6414","#8AAB3F"]});if(i.editorCommandProviders.registerCommandProvider(new Cr(i)),i.input.addHandler(new WV),i.input.addHandler(new xf),i.input.addHandler(new Z_),i.input.addHandler(new dH),i.input.addHandler(new bu(i,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new Cf(i,(A=t.componentsOptions)==null?void 0:A.quickMenu)),i.input.addHandler(new c2(i)),i.input.addHandler(new f2(i)),i.input.addHandler(new BN),i.input.addHandler(new _f),i.doc.registerCallback(new qV(i)),i.addCustom("remote-cursor",()=>new Jb(i)),i.addCustom("block-menu",z=>new Y7(z)),i.addCustom("editor-tooltip",()=>new Af(i)),t!=null&&t.enableComments&&i.addCustom("editor-comments",z=>new ry(z,new GG(z))),i.addCustom("create-options",()=>new K5(i,t)),i.addCustom("drop-target",()=>new Su(i)),i.addCustom("list-to-mindmap",()=>new df(i)),i.addCustom("list-to-mention",()=>new hW(i)),i.addCustom("mobile-helper",()=>new DW(i)),i.addCustom("code-caret",()=>new wN(i)),i.addCustom("image-paste-handler",()=>new l2(i)),(v=t.componentsOptions)!=null&&v.mention){const z=t.componentsOptions.mention;i.addCustom("mention",()=>new F2(i,z))}if(i.addCustom("heading-collapse",()=>new R2(i)),pc.register(i),Su.register(i),nl.register(i),Xi.register(i),i.addListener("clickLink",(z,q,rt)=>{var Bt;if((Bt=t==null?void 0:t.events)!=null&&Bt.onClickLink){t.events.onClickLink(z,q,rt);return}const ft=rt.getAttribute("link");ft&&(z.readonly||q.ctrlKey||q.metaKey)&&window.open(ft,"_blank")}),(D=(B=t.componentsOptions)==null?void 0:B.remoteCarets)!=null&&D.onUserChanged){const z=(_=(T=t.componentsOptions)==null?void 0:T.remoteCarets)==null?void 0:_.onUserChanged;i.doc.getRemoteUsers().on("change",q=>{z(i,q)})}return(H=(M=t.componentsOptions)==null?void 0:M.templates)!=null&&H.templates.length&&(i.addListener("docChanged",()=>{n1(i)}),i.addListener("resize",()=>{n1(i,{reset:!0})}),setTimeout(()=>{n1(i)},100)),i.doc.registerCallback({onError:async z=>{if(z.code==="ResetDoc"){J2.error(`reset doc: ${z.message}`);const q=await Ka.load(o);i.doc.reset(q)}}}),i}function YZ(n){return n.toJSON!==void 0}async function JZ(n,t,e){var i,s,l,a,d;g(J2,n,"app does not exists");const o=YZ(t)?t:new np(t,{serverUrl:e.serverUrl||""});e.lang&&R.setLang(e.lang);const r=Ha(n,o,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[Ef,Df,U0,I9],commandProviders:[new Gp],decorators:[new Sf,new yp],embeds:[...Q2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[T0,P2,hy,...((s=e.components)==null?void 0:s.boxes)||[]],insertions:[wg],blockHooks:[new e2,...((l=e.components)==null?void 0:l.blockHooks)||[]],textRenders:[new iy,new C0,...((a=e.components)==null?void 0:a.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[O0,_8,S0,Sh]});return r.editorCommandProviders.registerCommandProvider(new Cr(r)),r.input.addHandler(new xf),r.input.addHandler(new bu(r,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),r.input.addHandler(new Cf(r,(d=e.componentsOptions)==null?void 0:d.quickMenu)),r.input.addHandler(new c2(r)),r.input.addHandler(new f2(r)),r.input.addHandler(new _f),r.addCustom("block-menu",h=>new Y7(h)),r.addCustom("editor-tooltip",()=>new Af(r)),r.addCustom("image-paste-handler",()=>new l2(r)),e!=null&&e.enableComments&&r.addCustom("editor-comments",h=>new ry(h,new ZG(h,o))),r.addCustom("heading-collapse",()=>new R2(r)),r.addListener("clickLink",(h,p,A)=>{var B;if((B=e==null?void 0:e.events)!=null&&B.onClickLink){e.events.onClickLink(h,p,A);return}const v=A.getAttribute("link");v&&(h.readonly||p.ctrlKey||p.metaKey)&&window.open(v,"_blank")}),pc.register(r),r}function KZ(n,t){var a;const e=n.doc;if(!((a=e.getVersionHelper)==null?void 0:a.call(e)))throw new Error("the editor does not support to show versions");const r=n.getCustom("create-options");if(!r)throw new Error("the editor does not support to show versions");const i=r.getData(),s=new yk(i),l=n.addCustom("version-dialog",()=>new Dy(n.doc,s));return l.show(t),l}b.tippy=zB,b.AnchorBox=v6,b.AuthError=zh,b.AuthHeader=Ja,b.AutoScroll=Gd,b.BaseURLHeader=Vh,b.BasicCommands=v_,b.BlockExclusiveHook=G7,b.BlockLockerHook=e2,b.BlockLockerPasteHandler=_f,b.BlockResizer=wu,b.BrBox=p6,b.CodeBlock=Df,b.CodeLineBlock=U0,b.CodeTextDecorator=Sf,b.DefaultShortcuts=Sh,b.DocIdError=US,b.DragDrop=hC,b.DrawioEmbed=V2,b.EditorBlocks=y4,b.EditorBoxes=A6,b.EditorCommandProviders=ab,b.EditorComplexBlockPosition=So,b.EditorComplexSelectionRange=or,b.EditorDecorators=B6,b.EditorEmbeds=w4,b.EditorInsertions=w6,b.EditorSimpleBlockPosition=je,b.EditorSimpleSelectionRange=Ze,b.EmbedBlock=E4,b.EmbedBlockResizer=Fu,b.EnforceWithDocumentTitleHandler=bu,b.EventCallbacks=fa,b.FILL_CHAR=dI,b.FileExtError=zS,b.GroupOrder=L9,b.HeadingBlockScrollListener=sW,b.ImageBox=b6,b.InlineBoxCommandProvider=$9,b.InputtingInsertion=y6,b.LocalDoc=np,b.LogLevel=ha,b.Logger=Ii,b.MIN_DISTANCE_THRESHOLD=uC,b.ManualCloseDialog=ru,b.ManualMenu=zs,b.ManualToolbar=ou,b.MarkdownInputHandler=xf,b.MaxUserError=mp,b.Mindmap=f0,b.OnesEditorAutoSuggest=Np,b.OnesEditorCustomDataWrapper=K5,b.OnesEditorExclusiveBlock=Xi,b.OnesEditorHoveringBlock=pe,b.OnesEditorQuickMenu=Cf,b.OnesEditorToc=Pu,b.OnesEditorTocProvider=nl,b.OnesEditorToolbar=pc,b.OnesEditorTooltip=Af,b.OnesEditorVersionsDialog=Dy,b.PermissionError=jS,b.Popup=Xa,b.RemoteCarets=Jb,b.RemoteCaretsDecorator=yp,b.RemoteCaretsInsertion=wg,b.RemoteUsers=_h,b.RequestReloadError=Ya,b.RichText=ln,b.ShareDBDoc=Ka,b.ShareDBDocVersionsProvider=yk,b.SimpleCache=tC,b.StandardEmbedBlockCommands=I2,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=fg,b.TEXT_STYLE_COLOR_PREFIX=hg,b.TableBlock=Ef,b.TableBlockCommandProvider=Gp,b.TableShortcuts=O0,b.TextBlock=In,b.TextBox=g6,b.TextStyleShortcuts=S0,b.TocEmbed=Uy,b.ZERO_WIDTH_SPACE_CHAR=ma,b.abbreviation=Zd,b.addAttribute=uh,b.addClass=W,b.addCommentToBlock=Kf,b.addDays=ME,b.addMetaToDoc=Mh,b.addMonths=LE,b.animateScrollTo=km,b.applyPlaceholderToBlock=If,b.assert=g,b.autoShowHideTemplates=n1,b.blockToDoc=Kg,b.blockToHtml=Ig,b.blockToMarkdown=Tg,b.blockToText=Ah,b.blocksToDoc=DT,b.clearAllSelection=n4,b.clientType=Ke,b.cloneBlock=Fi,b.cloneChildContainer=Ng,b.cloneDoc=$g,b.cloneText=i6,b.commentToShareDbComment=vp,b.compareElement=Hd,b.comparePosition=Xm,b.complexBlockAdjustSelectionPos=nh,b.complexBlockFindNearestChildBlock=D4,b.complexBlockGeFirstSimpleChild=eg,b.complexBlockGetAllChildContainers=En,b.complexBlockGetBottomChildContainers=T4,b.complexBlockGetLastSimpleChild=Vl,b.complexBlockGetSelectedContainers=Os,b.complexBlockGetTopChildContainers=I4,b.containerToDoc=$A,b.continuousScroll=SC,b.convertBlockFrom=Kd,b.convertImageFileToPng=g7,b.convertImageSrcToPng=qP,b.copyBlockAttributes=P6,b.createBlockAnchor=Li,b.createBlockCaretAnchor=R4,b.createBlockContentElement=Ts,b.createBlockElement=WC,b.createBlockSimpleDocRange=mh,b.createBlockSimpleRange=ye,b.createBoxContentElement=ZC,b.createBoxElement=qC,b.createBoxOp=Q4,b.createChildContainer=b4,b.createComplexBlockPosition=fe,b.createComplexDocPos=d6,b.createComplexDocRange=mI,b.createContainer=c6,b.createContainerElement=Gm,b.createDeleteOps=W4,b.createEditor=Ha,b.createEditorSelectionRange=Ue,b.createElement=w,b.createEmptyContainer=Ur,b.createEmptyDoc=jr,b.createEmptyTextBlockData=hh,b.createExpandedRange=Nd,b.createIconButton=Hl,b.createImage=pm,b.createInsertOps=ch,b.createInsertionContentElement=JC,b.createInsertionElement=QC,b.createLocalEditor=JZ,b.createOnesEditor=QZ,b.createRange=eC,b.createRichText=Oi,b.createRootContainer=A4,b.createSimpleBlockPosition=st,b.createSimpleDocPos=u6,b.createTextBlockData=sr,b.createTextButton=Qs,b.createTextOp=lo,b.createTextWithReplaceSoftReturn=ag,b.daysAfter=Rm,b.deleteText=dg,b.diffDays=RE,b.disablePageScroll=BC,b.docToHtml=M6,b.docToHtmlFragment=bh,b.docToMarkdown=Ma,b.docToText=La,b.downloadImageToFile=A7,b.downloadObjectToFile=j2,b.downloadSvgToString=Yy,b.editLink=fu,b.editorAddComment=oz,b.editorAddTextAttribute=Z6,b.editorAutoInsertBlock=N6,b.editorBreakTextBlock=Yl,b.editorClearCompositionText=F6,b.editorClearSelectedContents=Fg,b.editorCopyBlock=Rh,b.editorDeleteBlock=Og,b.editorDeleteBlockText=Mg,b.editorDeleteBlockWithoutChildren=kh,b.editorDeleteChildContainer=cT,b.editorDeleteChildContainers=$6,b.editorFocusToBlock=Pg,b.editorFocusToEnd=PA,b.editorGetBlockData=_i,b.editorGetBlockText=mn,b.editorGetBlockTextEx=ph,b.editorGetBoxData=f6,b.editorHandleKeyboardEvent=zA,b.editorInsertBlock=Ql,b.editorInsertBoxToBlock=O6,b.editorInsertDoc=q6,b.editorInsertDocAt=Hg,b.editorInsertText=Lg,b.editorInsertTextToBlock=R6,b.editorInsertTextToBlockEx=Sg,b.editorMergeTextBlock=H6,b.editorMoveDown=sA,b.editorMoveEnd=pA,b.editorMoveHome=CA,b.editorMoveLeft=oA,b.editorMoveLineEnd=EA,b.editorMoveLineHome=BA,b.editorMovePageDown=LA,b.editorMovePageUp=SA,b.editorMoveRight=rA,b.editorMoveUp=iA,b.editorMoveWordEnd=fA,b.editorMoveWordLeft=hA,b.editorRangeClearColor=Y6,b.editorRangeGetColor=jg,b.editorRangeSetColor=Q6,b.editorRemoveTextAttribute=hT,b.editorReplaceBlockText=Bh,b.editorReplaceContainer=G6,b.editorRunOnce=op,b.editorSelectAll=FA,b.editorSelectContainer=Yg,b.editorSelectDown=lA,b.editorSelectEnd=Zg,b.editorSelectHome=AA,b.editorSelectLeft=cA,b.editorSelectLineEnd=wA,b.editorSelectLineHome=kA,b.editorSelectPageDown=RA,b.editorSelectPageUp=MA,b.editorSelectRight=aA,b.editorSelectUp=uA,b.editorSelectWordEnd=gA,b.editorSelectWordLeft=mA,b.editorSetTextColor=Jl,b.editorShowFindDialog=uU,b.editorToDocx=ZZ,b.editorUpdateBlockData=Eh,b.editorUpdateCompositionText=_6,b.editorUpdateEmbedData=V6,b.enablePageScroll=EC,b.escapeHtmlText=lC,b.escapeRegExp=Pm,b.escapeSpace=gE,b.exclusiveBlock=K0,b.executeBlockCommand=d4,b.executeEmbedBlockCommand=u4,b.executeRangeCommand=cb,b.fileToDataUrl=Ul,b.findAfterOffsetNotType=vg,b.findAllText=Cg,b.findEventTargetBlock=iC,b.findInsertionById=YC,b.findNextOffset=LI,b.findNextVisibleSimpleBlock=mb,b.findPrevOffset=SI,b.findPrevOffsetNotType=bg,b.findPrevSimpleBlockBeforeChildContainer=x4,b.findPrevVisibleSimpleBlock=fb,b.findTarget=jl,b.findWordEnd=kg,b.findWordLeft=yg,b.format=ba,b.formatBytes=LC,b.formatDate=_m,b.fragmentToHtml=xC,b.fromBase64=Ud,b.fromBase64ToBlob=Dm,b.fromBase64ToUint8Array=xE,b.fromDocRange=Si,b.fromNowString=Fm,b.genId=K,b.getAllChildBlocks=og,b.getAllQuickMenuItems=D0,b.getAllSelectedBlocks=Lo,b.getAttributesAt=Ta,b.getBlockBackground=VC,b.getBlockByIndex=Or,b.getBlockCaretRect=To,b.getBlockClass=Qt,b.getBlockClassByType=Ms,b.getBlockClientRects=Ti,b.getBlockCommandsWithHook=Wm,b.getBlockContent=Rt,b.getBlockId=it,b.getBlockIndex=bt,b.getBlockInfo=Iu,b.getBlockKind=Io,b.getBlockMinWidth=r4,b.getBlockNearestRangeFromPoint=M4,b.getBlockOptions=VE,b.getBlockPath=Di,b.getBlockProperties=l4,b.getBlockRangeFromPoint=oh,b.getBlockStyles=zE,b.getBlockTextLength=ut,b.getBlockTools=le,b.getBlockType=Dt,b.getBoxContent=Hm,b.getBoxId=GC,b.getBoxTypeFromElement=va,b.getChildBlockCount=Eo,b.getChildBlocks=ve,b.getChildOffset=Mi,b.getColorFromAttributes=gg,b.getColorFromContent=Qd,b.getComplexBlockClass=jn,b.getContainerBlockPath=g4,b.getContainerBlocks=e4,b.getContainerBlocksElement=th,b.getContainerById=Nr,b.getContainerId=at,b.getContainerMinWidth=Qm,b.getContainerToolsElement=QE,b.getContainerWidth=v4,b.getDistanceSquare=er,b.getElementOffset=ga,b.getElementScale=ys,b.getEmbedType=Un,b.getExistsBlockTools=Jd,b.getExistsContainerById=m4,b.getFileExt=Aa,b.getFirstChildBlock=Se,b.getFirstClientRect=$d,b.getHeadingMenuOptions=B0,b.getHorizontalPadding=Cm,b.getInsertionContent=jm,b.getLastChildBlock=Ge,b.getLastClientRect=bs,b.getListAllNextBrothers=dc,b.getLogger=S,b.getNextBlock=Zt,b.getNextValidOffset=Fs,b.getNextVisibleBlock=Ss,b.getOffsetInfoAfter=Sa,b.getOffsetInfoBefore=Ch,b.getOpAt=K4,b.getOpLength=ah,b.getParentBlock=ot,b.getParentBlockExcludeSelf=Is,b.getParentBox=$m,b.getParentContainer=nt,b.getPrevBlock=ce,b.getPrevValidOffset=Ri,b.getPrevVisibleBlock=Ds,b.getRangeCommands=sb,b.getRootBlock=Vm,b.getScrollContainer=oo,b.getSpecialBlockCommands=c4,b.getStandardEmbedBlockProperties=T2,b.getTextAfterOffset=TI,b.getTextAttributes=Dg,b.getTextBeforeOffset=DI,b.getTextBlockChild=Xd,b.getTextBlockClass=XC,b.getTextBlockContentChildTextLength=so,b.getTextBlockContentChildType=h4,b.getTextBlockContentChildren=nr,b.getTextLength=rn,b.getTextOpLength=rg,b.getTextWidth=Vd,b.getToolbar=sf,b.handleBlockElementUpdated=i4,b.hasAltOnly=yE,b.hasClass=xt,b.hasCtrlOrCmd=bC,b.hasCtrlOrCmdOnly=vE,b.hashCode=NC,b.hideBlock=UC,b.htmlToFragment=zd,b.i18n=R,b.injectDocToHtmlFragment=Lh,b.injectStyle=aC,b.insertEmptyBlock=GE,b.insertEmptyEmbedBlock=qm,b.insertText=Hr,b.intersectionCommands=OD,b.isBackspace=yC,b.isBlock=xs,b.isBlockLocked=Of,b.isBlockLockedByOthers=t2,b.isBlockLockedBySelf=Tu,b.isBlockTools=jC,b.isBox=Nm,b.isCJK=pC,b.isChildContainer=Do,b.isChildNode=Kt,b.isCollapsedRange=fI,b.isComplexBlockPosition=Km,b.isComplexKindBlock=Lt,b.isContainer=_r,b.isContainerSelectedAllChildBlocks=OA,b.isControlEvent=ws,b.isDelete=wE,b.isDraggingFiles=Wd,b.isElementVisible=ym,b.isEmbedBlock=Le,b.isEmptyContainer=Ym,b.isEmptyDoc=Ag,b.isEmptyTextBlock=he,b.isEmptyTextBlockWithoutCompositionText=Au,b.isEnterOnly=vC,b.isEscape=Im,b.isExclusiveBlock=Rf,b.isFirefox=Em,b.isFirstChildBlockInComplexBlock=Ix,b.isHighSurrogate=aE,b.isInBlock=Um,b.isInBlockTools=Ls,b.isLetter=gC,b.isLowSurrogate=gm,b.isMatchShortcut=Rr,b.isMoveForward=AE,b.isNavigationEvent=CE,b.isNavigationKey=AC,b.isNodeRemoved=oC,b.isNumber=mC,b.isPrintableKey=xm,b.isRootBlock=ro,b.isRootContainer=Xt,b.isSafari=CC,b.isSameDay=Om,b.isSecureEnv=j0,b.isShiftEnter=kE,b.isShiftTab=EE,b.isShortcutEvent=bE,b.isSimpleBlock=UE,b.isSimpleBlockPosition=$r,b.isSimplePos=a6,b.isSimpleRange=fh,b.isSpace=jd,b.isTab=BE,b.isTextBlockContentBoxChild=io,b.isTextBlockContentChild=ka,b.isTextBlockContentInsertionChild=Pr,b.isTextBlockContentTextChild=wa,b.isTextKindBlock=tt,b.isTextKindBlockType=ya,b.isToday=MC,b.isValidOffset=sn,b.isVisibleBlock=Yd,b.isYesterday=RC,b.loadJs=rC,b.loadJsPromise=vs,b.lockers=wo,b.mergeCommands=rf,b.mergeDocs=$s,b.mergeOps=ug,b.mergeText=Y4,b.multiSplitText=F4,b.overflowText=OC,b.parseShortcut=kC,b.patchNode=Ca,b.pointInRect=ks,b.rangeAddAttribute=Ia,b.rangeGetTextColor=r6,b.rangeRemoveAttribute=ql,b.rangeSetTextColor=e6,b.rangeTransformText=X4,b.registerDragDrop=wm,b.removeAttribute=mg,b.removeClass=et,b.removeLastBr=rI,b.removePlaceholderFromBlock=l7,b.removeStyle=cC,b.replaceAll=OE,b.replaceAllCaseInsensitive=_E,b.replaceAllText=l6,b.replaceText=dh,b.requestDownload=qd,b.resetListStart=fc,b.scrollable=DC,b.selectFile=zl,b.selectedBlockToDoc=Ih,b.selectionToDoc=Th,b.setAttributes=bm,b.setClipboardData=Mm,b.setClipboardDataByEvent=SE,b.setColorToAttributes=n6,b.setDataset=Am,b.setDefaultCursor=pa,b.setStyles=vm,b.shareDBCommentToDocObject=bp,b.shareDBDocCommentToComment=Qb,b.shortcutToDisplayText=Bo,b.showBlock=zC,b.showDocVersions=KZ,b.splitText=xn,b.splitToThree=ze,b.stringToDataUrl=Sm,b.stringToObjectUrl=Lm,b.subText=P4,b.textNodeOffsetFromPoint=nC,b.titleFromEditor=C7,b.toBase64URL=Bs,b.toMindmap=uf,b.toPlainText=re,b.toPlainTextKeepLength=pg,b.trimChar=Bm,b.unexclusiveBlock=X0,b.unicodeLength=uE,b.unicodeSubstr=dE,b.updateBlockSelection=o4,b.updateOpAttributes=s6,b.updateTextBlockContent=II,b.updateUrl=Tm;for(const n in be)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>be[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
750
|
+
\`\`\`\`\`\``}return"[plantuml]"}const ak={embedType:"plantuml",convertFrom:CG,handleUpdateBlock:pG,createEmbedContent:gG,getBlockProperties:AG,convertTo:bG},aot="",vG="hr",yG={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},kG={dividingLine:{type:"Separation line",abstract:"Separation line"}},wG={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};R.mergeLang({"zh-CN":yG,"en-US":kG,"ja-JP":wG});function BG(n,t){const e=w("div",["editor-embed-container"],t);w("hr",["editor-embed-hr"],e)}function EG(n,t,e,o){return o==="html"?"<hr />":o==="markdown"?"---":"------------"}function xG(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:R.t("dividingLine.type"),icon:UL,order:500,group:"common",subText:pn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:o}=t;return n.insertEmbed(e,o,vG,{})}}}function IG(n,t,e){const{data:o}=e;if(!o||o.embedType!=="dividing-line"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"hr",embedData:r}}}function TG(){return{abstract:R.t("dividingLine.abstract")}}const uk={embedType:"hr",createEmbedContent:BG,convertTo:EG,getOptions:xG,convertFrom:IG,getBlockProperties:TG},uot="",dot="",DG={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>'},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"}}},SG={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>'},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"}}},LG={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>'},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"}}};R.mergeLang({"zh-CN":DG,"en-US":SG,"ja-JP":LG});var Vo=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(Vo||{}),Nu=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(Nu||{});const dk=10*1024*1024,MG=["wav","mp3","aac","ogg","webm","flac"],RG=["ogg","mp4","webm"],OG=()=>{};function hk(n){var h,p,A,v,B,D;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:o,callbacks:r}=t,i=(p=e==null?void 0:e.audio)!=null?p:MG,s=(A=e==null?void 0:e.video)!=null?A:RG,l=(v=o==null?void 0:o.audio)!=null?v:dk,a=(B=o==null?void 0:o.video)!=null?B:dk,d=(D=r==null?void 0:r.onError)!=null?D:OG;return{allowedMedias:{audio:i,video:s},maxSize:{audio:l,video:a},callbacks:{onError:d}}}function _G(n,t){const e=i=>i.map(s=>`.${s}`).join(","),{allowedMedias:o}=hk(n),r=o[t];return r?e(r):"*"}function FG(n,t,e){const{maxSize:o,callbacks:r,allowedMedias:i}=hk(t),{[e]:s}=o,{[e]:l}=i;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,r!=null&&r.onError&&(r==null||r.onError(t,d)),d}const a=Aa(n.name);if(l&&!l.includes(a)){const d=new Error(`media file is not allowed: ${a}`);throw d.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(t,d)),d}}function PG(n){return n===Nu.Empty||n===Nu.Error}const Pe=S("media");class NG extends be.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,o)=>{if(!o.target||!(o.target instanceof Node)||!(o.target instanceof Element?o.target:o.target.parentElement))return;const i=ot(o.target);if(!i||!i.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",it(i))});m(this,"handleUploadFile",async e=>{g(Pe,this.abstract,"no abstract"),g(Pe,this.mediaContainer,"The media element not exist");const{editor:o}=this.options,r=ot(this.mediaContainer);g(Pe,r,"The block element not exist");const i=o.getBlockData(r);try{const{resourceId:s}=await o.doc.uploadResource(e,{onProgress:p=>{this.renderProgress(p,e)}}),{name:l,type:a,size:d}=e,h={...i,embedData:{...i.embedData,src:s,fileName:l,fileSize:d,fileType:a}};o.updateBlockData(r,h)}catch(s){Pe.error(s),this.emit("mediaError",o,"upload_error",i.id),this.renderRetry(e)}et(r,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){g(Pe,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){g(Pe,this.abstract,"no abstract");const{editor:e,createMediaElement:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract;g(Pe,this.mediaContainer,"The media element not exist");const s=ot(this.mediaContainer);g(Pe,s,"The block element not exist");const l=e.getBlockData(s),a=l.embedData.src,d=w("div",["media-error","embed-selected-content","embed-hover-content"],null),h=w("span",["media-error-icon"],d);h.innerHTML=r;const p=w("div",[],d);p.innerHTML=R.t("media.load.failed",{name:i}),d.appendChild(p);const A=p.querySelector(".retry-upload");return g(Pe,A,"The element not exist"),e.domEvents.addEventListener(A,"click",(v,B)=>{const D=w("div",["media-element"],null),T=this.getResourceUrl(a),_=o(v,D,l,T);this.unbindMediaEvent(),this.media=_,this.bindMediaEvent(),this.updateMediaContent(D)}),this.setFullScreen(),d}renderRetry(e){g(Pe,this.abstract,"no abstract");const{editor:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract,s=w("div",["media-error","embed-selected-content","embed-hover-content"],null),l=w("span",["media-error-icon"],s);l.innerHTML=r;const a=w("div",[],s);a.innerHTML=R.t("media.upload.failed",{name:i}),s.appendChild(a);const d=a.querySelector(".retry-upload");g(Pe,d,"The element not exist"),o.domEvents.addEventListener(d,"click",()=>{o.readonly||(g(Pe,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(s),this.setFullScreen()}renderProgress(e,o){g(Pe,this.mediaContainer,"The media element not exist");const r=this.mediaContainer.querySelector(":scope .media-progress"),i=e===-1||e===100?100:e;if(r){const{updateProgressElement:s}=this.options;s(r,i)}else{const{createProgressElement:s}=this.options,l=ot(this.mediaContainer);g(Pe,l,"The element not exist"),W(l,"media-block-uploading");const a=w("div",["media-progress"],null);s(a,i,o),this.updateMediaContent(a)}this.setFullScreen()}renderMediaElement(e){g(Pe,this.mediaContainer,"The media element not exist");const o=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:r,updateMediaElement:i,editor:s}=this.options,l=this.getResourceUrl(e.embedData.src);if(o){const a=i(s,o,e,l);this.unbindMediaEvent(),this.media=a,this.bindMediaEvent()}else{const a=w("div",["media-element"],null),d=r(s,a,e,l);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent(),this.updateMediaContent(a)}}renderEmpty(e){g(Pe,this.abstract,"no abstract"),g(Pe,this.mediaContainer,"The media element not exist");const o=w("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);o.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(o);const{editor:r}=this.options;r.findBlockById(e.id)&&this.emit("mediaError",r,"empty",e.id),this.setFullScreen()}getResourceUrl(e){const{editor:o}=this.options;return o.doc.buildResourceUrl(e)}setFullScreen(){g(Pe,this.mediaContainer,"The media element not exist"),W(this.mediaContainer,"full-screen")}removeFullScreen(){g(Pe,this.mediaContainer,"The media element not exist"),et(this.mediaContainer,"full-screen")}updateBlockAlign(e,o){const r=ot(o);g(Pe,r,"The block element not exist");const{align:i}=e;e.embedType==="video"&&(r.hasAttribute("data-style-align")&&r.removeAttribute("data-style-align"),r.setAttribute("data-style-align",i))}render(e,o){const{src:r}=e.embedData;(!this.mediaContainer||!o.contains(this.mediaContainer))&&(this.mediaContainer=w("div",["media"],o)),this.updateBlockAlign(e,o),PG(r)?r===Nu.Empty&&this.renderEmpty(e):this.renderMediaElement(e)}setAbstract(e){this.abstract=e}}S("media-embed");const $G="left";class fk{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var p;const{containerId:o,blockIndex:r}=e;let i;(p=e.data)!=null&&p.file&&(i=e.data.file);const s=_G(t,this.embedType);if(i=i!=null?i:await zl(s,{}),!i)return null;const{mediaType:l}=this.getAbstract();try{FG(i,t,l)}catch{return null}const a={id:K(),type:"embed",embedType:this.embedType,embedData:{src:Nu.Empty}};l==="video"&&(a.align=$G);const d=t.insertBlock(o,r,a);return await this.getMedia(t,a.id).handleUploadFile(i),d})}getMedia(t,e){const o=t.addCustom(`media-${e}`,()=>new NG({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return o.setAbstract({...this.getAbstract()}),o}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:o,order:r,group:i}=this.getAbstract();return{name:o,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:r,group:i,subText:pn(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,o){const{id:r}=o;this.getMedia(t,r).render(o,e)}handleUpdateBlock(t,e,o){const{id:r}=o,i=this.getMedia(t,r),s=Rt(e);return i.render(o,s),!0}handleDeleteBlock(t,e){const o=e.id,r=this.getMedia(t,o);r.removeAllListeners(),r.destroy()}convertTo(t,e,o,r){const i=e.embedData,s=t.doc.buildResourceUrl(i.src,{withToken:!0});return r==="html"?`<${i.type} src="${s}" />`:r==="markdown"?``:s}}function mk(n,t){const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e),r=w("div",["uploading-progress-bar-value"],o);r.style.width=`${t}%`}function gk(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const HG=S("media-audio");class jG extends fk{constructor(){super(...arguments);m(this,"embedType",Vo.AUDIO);m(this,"updateProgressElement",gk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["audio-container","embed-hover-content","embed-selected-content"],o),l=w("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=i,setTimeout(()=>{this.getMedia(e,r.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:$L,mediaName:R.t(`media.${Vo.AUDIO}.menuItem`),menuItem:R.t(`media.${Vo.AUDIO}.menuItem`),order:800,mediaType:Vo.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${R.t(`media.${Vo.AUDIO}.abstract`)}`}}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .audio-container > audio");return g(HG,s,"The media element not exist"),s.src!==i&&(s.src=i),s}createProgressElement(e,o){const r=w("audio",[],e);r.innerHTML="Your browser does not support the <code>audio</code> element.",r.controls=!0,r.src="about:blank",mk(e,o)}}const pk=new jG;S("video-resizer");function Ck(n){return n&&Le(n)&&Un(n)==="video"}const UG=50;class Z2{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&(e&&Ck(e)&&this.disableBlockResize(e),t&&Ck(t))){const o=this.getVideoElement(t);if(!o)return;this.enableBlockResize(t,o)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const o=t.getBlock();if(!o)return;const r=o.getBoundingClientRect().width,i=Math.min(Math.max(e.width,UG),r);this.currentResizableElement.style.width=`${i}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const o=this.editor.getBlockData(e),{width:r}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...o,width:r})});this.editor=t,pe.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,pe.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Rt(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const o=this.editor.addCustom(`${it(t)}-resizer`,()=>new wu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));o.enableResize(t,e),o.removeListener("resizing",this.handleResizing),o.removeListener("resized",this.handleResized),o.addListener("resizing",this.handleResizing),o.addListener("resized",this.handleResized),this.currentResizableElement=e}}const zG=S("video");class VG extends fk{constructor(){super(...arguments);m(this,"embedType",Vo.VIDEO);m(this,"updateProgressElement",gk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["video-container","embed-selected-content","drag-preview-element"],o),l=w("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=i,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new Z2(e)),this.getMedia(e,r.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).removeFullScreen()}),r.width&&(l.style.width=`${r.width}px`),l});m(this,"createProgressElement",(e,o,r)=>{const i=w("video",["progress-video"],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,mk(e,o),Ul(r).then(s=>{const l=e.querySelector(".progress-video");l&&Um(e)&&(l.src=s)})})}getAbstract(){return{mediaName:R.t(`media.${Vo.VIDEO}.menuItem`),mediaIcon:HL,menuItem:R.t(`media.${Vo.VIDEO}.menuItem`),order:700,mediaType:Vo.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`[${R.t(`media.${Vo.VIDEO}.abstract`)}]`}}handleMediaError(e,o,r){const i=e.addCustom("video-resizer",()=>new Z2(e)),s=e.getBlockById(r);i.disableBlockResize(s)}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .video-container > video");g(zG,s,"The media element not exist"),s.src!==i&&(s.src=i),r.width?s.style.width=`${r.width}px`:s.style.width="";const l=e.getBlockById(r.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new Z2(e)).updateResizer(l)}),s}}const Ak=new VG,bk=[Ef,Df,U0,I9],Q2=[V2,Q8,rk,lk,ak,N9,uk,Ak,pk,ey,U8,Qz],vk=[T0,P2,h8];function WG(n,t,e){var r,i,s;const o=Ha(n,t,{components:{blocks:[...bk,...((r=e==null?void 0:e.components)==null?void 0:r.blocks)||[]],embeds:[...Q2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[...vk,...((s=e.components)==null?void 0:s.boxes)||[]],textRenders:[new C0],options:{...e.componentsOptions}}});return o.readonly=!0,o.addCustom("heading-collapse",()=>new R2(o)),o.addCustom("editor-tooltip",()=>new Af(o)),o.addListener("clickLink",(l,a,d)=>{var p;if((p=e==null?void 0:e.events)!=null&&p.onClickLink){e.events.onClickLink(l,a,d);return}const h=d.getAttribute("link");h&&(l.readonly||a.ctrlKey||a.metaKey)&&window.open(h,"_blank")}),o}class yk{constructor(t){this.createOptions=t,t.lang&&R.setLang(t.lang)}createHistoryEditor(t,e){return WG(t,e,this.createOptions)}}S("create-editor");function kk({root:n,childDoc:t,doc:e}){t.uploadResource=e.uploadResource.bind(e),t.buildResourceUrl=e.buildResourceUrl.bind(e);const o=Ha(n,t,{shortcuts:[Sh],components:{blocks:[Ef,Df],decorators:[new Sf],embeds:[ey,V2,Q8,rk,lk,ak,N9,uk,Ak,pk],boxes:[T0,P2],options:{image:{defaultAlign:"left"}}}});return o.input.addHandler(new xf),o.input.addHandler(new c2(o)),o.input.addHandler(new f2(o)),o.input.addHandler(new tz(o)),o.input.addHandler(new _f),o.addCustom("image-paste-handler",()=>new l2(o)),o}function qG(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),o=new Set;e.forEach(r=>{const i=ot(r);i&&o.add(i)}),o.forEach(r=>{ez(n,r,t)})}class GG{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const o=e.groupId;this.getComments().filter(i=>i.groupId===o).length===0&&qG(this.editor,o)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){var r,i;const o=kk({root:t,childDoc:e,doc:this.doc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new F2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.doc.getUser().userId}}class ZG{constructor(t,e){m(this,"listeners",new Set);this.editor=t,this.localDoc=e}get doc(){return this.localDoc.toJSON()}getComments(){return Object.values(this.doc.comments)}getComment(t){return this.doc.comments[t]}getCommentDoc(t){const e=this.doc.comments[t];return bp(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){var r,i;const o=kk({root:t,childDoc:e,doc:this.localDoc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new F2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const QG={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}"}},YG={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}"}},JG={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"}};R.mergeLang({"zh-CN":QG,"en-US":YG,"ja-JP":JG});const KG="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",XG=()=>Dm(KG);async function tZ(n){return new Promise((t,e)=>{const o=new Image;o.onload=()=>{t({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=e,o.src=n})}async function wk(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};const e=await Ul(new File([t],"",{})),o=await tZ(e);return o.width===void 0||o.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||o.width*n.height/o.height,height:n.height||o.height*n.width/o.width,buffer:t}:{width:o.width,height:o.height,buffer:t}}function eZ(n,t){let e=n.filter(s=>s!=null);const o=t-(e.length-1)*20,r=.87,i=e.reduce((s,l)=>s+l.width,0);return i>o&&(e=e.map(s=>({width:s.width*o/i,height:s.height*o/i,buffer:s.buffer}))),e.map(s=>({width:s.width*r,height:s.height*r,buffer:s.buffer}))}function Bk(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let o;switch(e%3){case 0:o=gt.LevelFormat.DECIMAL;break;case 1:o=gt.LevelFormat.LOWER_LETTER;break;default:o=gt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:o,text:`%${e+1}. `,alignment:gt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(e+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function nZ(){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:gt.LevelFormat.BULLET,text:t,alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function oZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2611",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}function rZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2610",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}var $u=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))($u||{});const iZ=[{levels:Bk(),reference:"number-numbering-reference"},{levels:nZ(),reference:"number-bullet-reference"},{levels:oZ(),reference:"checked-bullet-reference"},{levels:rZ(),reference:"unchecked-bullet-reference"}];function sZ(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 lZ(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 cZ(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 Ek(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},o=e(t[1]),r=e(t[2]),i=e(t[3]);return`${o}${r}${i}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function tn(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 xk(n,t,e){for(let o=0;o<=e;++o){const r=`${t}${o}`;if(tn(n,r))return r}}function r1(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function Y2(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function Ik(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function uZ(n){const t=tn(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const o of e){const r=o.split(":");if(r.length!==2)continue;const i=r[0].trim().toLowerCase(),s=r[1].trim().toLowerCase();i==="font-size"&&r1(n,"inline-style-font-size",s),i==="color"&&r1(n,"inline-style-color",s),i==="background-color"&&r1(n,"inline-style-background-color",s),i==="font-family"&&r1(n,"inline-style-font-family",s)}}function dZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function hZ(n){const t=`${tn(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function fZ(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 mZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function gZ(n){return tn(n,"inline-style-font-family")}function pZ(n){const t=tn(n,"inline-style-background-color");return Ek(t)}function CZ(n){const t=tn(n,"inline-style-color");return Ek(t)}function AZ(n){uZ(n);const t=tn(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!tn(n,"style-code"),link:Ik(tn(n,"link")),size:hZ(n),text:t?mZ(n):fZ(n)||n.insert,bold:!!tn(n,"style-bold"),underline:!!tn(n,"style-underline"),italics:!!tn(n,"style-italic"),strike:!!tn(n,"style-strikethrough"),superScript:!!tn(n,"style-super"),subScript:!!tn(n,"style-sub"),math:tn(n,"type")==="math"?tn(n,"src"):void 0,mention:t,fontFamily:gZ(n),background:pZ(n),color:t?"338fe5":sZ(xk(n,"style-color-",6))||CZ(n),highlight:xk(n,"style-bg-color-",13)}}function bZ(){return[new gt.Paragraph({border:{top:{color:"auto",style:gt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new gt.Paragraph({spacing:{line:0}})]}function vZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function yZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function kZ(n,t){return new gt.Paragraph({children:[new gt.ExternalHyperlink({children:[new gt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function Tk(n){if(n.heading!=null)return`Heading${n.heading}`}function Dk(n){if(n.alignment!=null){if(n.alignment==="center")return gt.AlignmentType.CENTER;if(n.alignment==="right")return gt.AlignmentType.RIGHT;if(n.alignment==="left")return gt.AlignmentType.LEFT}}function wZ(n){if(n.indent)return{left:gt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:gt.convertInchesToTwip(.3*n.padding)}}function BZ(n){return{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function EZ(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function Sk(n,t){let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const o=n.size||t,r=o!=null?Math.floor(o*1.5+.5):void 0;return new gt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:gt.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:r,style:e,font:n.fontFamily?EZ(n.fontFamily):void 0,shading:n.background?BZ(n.background):void 0,color:n.color,highlight:lZ(n.highlight)})}function xZ(n,t){if(n.link)return new gt.ExternalHyperlink({children:[Sk(n,t)],link:n.link})}async function Lk(n,t,e,o,r){const i=await r(n,t,e);if(i==null)return;const s=await wk({width:o||0,height:0,src:e},i);return new gt.ImageRun({data:i,transformation:{width:s.width||100,height:s.height||20}})}function IZ(n){if(n.heading||n.heading)return n.heading}function TZ(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function DZ(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function SZ(n,t){var o;const e=[];if(n.text&&Array.isArray(n.text)){for(let r=0;r<n.text.length;r++){const i=n.text[r];if(((o=i.attributes)==null?void 0:o.box)===!0&&t){const s=await t(i);if(s){n.text.splice(r+1,0,...s);continue}}e.push(AZ(i))}return e}}function LZ(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 MZ(n,t){if(n.type==="embed"&&n.embedType&&Y2(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(o=>{const r=t(o),i=n.embedData[`${r}_width`],s=n.embedData[`${r}_height`];return{src:o,width:i,height:s}})}function RZ(n){if(n.padding)return n.padding}function OZ(n){return!!(n.type==="embed"&&n.embedType&&Y2(n.embedType)&&n.embedData&&n.embedData.src)}async function i1(n,t,e){return{quoted:!!n.quoted,heading:IZ(n),alignment:TZ(n),indent:DZ(n),padding:RZ(n),texts:await SZ(n,e),list:LZ(n),images:MZ(n,t),border:OZ(n)}}async function _Z(n,t,e,o){const r=[];if(!n.children)return[];for(const i of n.children){const s=[];for(const l of t.blocks[i])s.push(await i1(l,e,o));r.push(s)}return r}const FZ=S("to-docx");function PZ(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 NZ(n,t,e,o){const r=!!n.hasColTitle,i=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let a=0;a<t;a++)for(let d=0;d<e;d++)(r&&d===0||i&&a===0||s&&a%2===1)&&(o[a][d].color=l)}function $Z(n){g(FZ,n.children,"no table children");const t=n.rows,e=n.cols,o=n.colsWidth;if(o)for(let s=0;s<o.length;s++)o[s]===0&&(o[s]=100);const r=PZ(t,e);let i=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(r[s][l].originalWidth=o?o[l]:void 0,r[s][l].from!==void 0)continue;const a=n.children[i];i+=1,r[s][l].cellId=a,r[s][l].color=cZ(n[`${a}_background`]),r[s][l].width=o?o[l]:100,r[s][l].align=n[`${a}_align`];const d=n[`${a}_rowSpan`]||1,h=n[`${a}_colSpan`]||1;if(r[s][l].rowSpan=d,r[s][l].colSpan=h,d>1||h>1){let p=0;for(let A=0;A<d;A++)for(let v=0;v<h;v++)A===0&&(p+=o?o[l+v]:80),!(A===0&&v===0)&&(r[s+A][l+v].from=[s,l]);r[s][l].width=p}}return NZ(n,t,e,r),r}async function HZ(n,t,e,o,r,i,s,l,a,d){async function h(v){if(l){const B=await l(r,i,v);if(B){await o.addDoc(n,B,d);return}}if(v.type==="text"||v.textOnly===!0){const B=await i1(v,s,a);await o.addTextBlock(B);return}if(v.type==="code"){const B=await _Z(v,e,s,a);await o.addCodeBlockObject(B);return}if(v.type==="list"&&v.textOnly!==!0){const B=await i1(v,s,a);await o.addListBlockObject(n,B);return}if(v.type==="embed"&&v.embedType){const B=v,D=B.embedData,T=B.embedType;if(Y2(T)){const _=await i1(v,s,a);await o.addImagesBlockObject(v,_,d)}else v.embedType==="hr"?o.addSeparatorBlock():v.embedType==="video"?o.addVideoPlaceholder():v.embedType==="audio"?o.addAudioPlaceholder():v.embedType==="webpage"?o.addHyperlinkParagraph(Ik(D.src),D.title):o.addOtherEmbedBlock(T,v.embedData);return}if(v.type==="table"){let B=[];if(v.colsWidth)B=v.colsWidth;else{const T=v.cols;B=new Array(T);for(let _=0;_<B.length;_++)B[_]=100;v.colsWidth=B}const D=$Z(v);await o.addTableMatrix(B,D,e),o.addEmptyParagraph()}}function p(v){const B=[];for(const{type:D,data:T}of v.embedData.exportSpec){if(D==="text"){const _={id:K(),text:[{insert:T}],type:"text"};B.push(_);continue}if(D==="image"){const _={id:K(),type:"embed",embedType:"image",align:"left",embedData:{src:T}};B.push(_);continue}if(D==="link"){const _={id:K(),type:"embed",embedType:"webpage",embedData:{src:T.url,title:T.title}};B.push(_);continue}}return B}function A(v){var B;return(B=v==null?void 0:v.embedData)!=null&&B.exportSpec?p(v):[v]}for(const v of t)for(const B of A(v))await h(B)}function jZ(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const UZ=S("to-docx");class zZ{constructor(t,e,o,r,i,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=o,this.readImageFunc=r,this.convertBlocksFunc=i,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new gt.Paragraph({heading:Tk(t),alignment:Dk(t),children:await this.paragraphsFromBlockTexts(t),indent:wZ(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new gt.Paragraph({text:`[${R.t("docx.imageExportFailed")}]`,shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=dZ(this.defaultFontSize,t.heading),o=[];for(const r of t.texts){if(r.link){const i=xZ(r,e);i&&o.push(i);continue}if(r.box&&r.box.type&&r.box.type==="br"){o.push(new gt.TextRun({text:"",break:1}));continue}if(r.box&&r.box.type&&r.box.type==="image"){const i=await Lk(this.appId,this.docId,r.box.src,r.box.width,this.readImageFunc);i&&o.push(i);continue}if(r.math){const i=await Lk(this.appId,this.docId,r.math,0,this.readImageFunc);i&&o.push(i);continue}o.push(Sk(r,e))}return o}async addCodeBlockObject(t){for(const e of t)for(const o of e){const r={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new gt.Paragraph({style:"Code",border:{left:{...r},right:{...r},top:{...r},bottom:{...r}},children:await this.paragraphsFromBlockTexts(o)}))}}async addListBlockObject(t,e){if(e.list==null)return;let o;const r=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[r])o=this.state.listInstMap[r];else if(o=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[r]=o,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${o}`,l=Bk([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:o}),this.state.listRefMap[r]=s}else e.list.ordered?this.state.listRefMap[r]=$u.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[r]=$u.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[r]=$u.UNCHECKED:this.state.listRefMap[r]=$u.BULLET;const i=Tk(e);e.texts&&this.paragraphs.push(new gt.Paragraph({heading:i,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[r],level:e.list.level-1,instance:o}}))}imageDimWithBufferToImageRun(t){return new gt.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,o){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:a}=t.embedData;a||this.addEmptyImagePlaceHolder()}return}const r=[],i=await Promise.all(e.images.map(async a=>{const d=await this.readImageFunc(this.appId,this.docId,a.src);if(d)return wk(a,d);r.push(a.src)})),s=eZ(i,o),l={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new gt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:Dk(e)||gt.AlignmentType.CENTER,children:s.map(a=>this.imageDimWithBufferToImageRun(a)).flatMap((a,d,h)=>a==null?[]:h.length-1!==d?[a,new gt.TextRun({text:" "})]:a)})),r.forEach(a=>{this.addHyperlinkParagraph(a)})}addSeparatorBlock(){bZ().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new gt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(vZ())}addAudioPlaceholder(){this.paragraphs.push(yZ())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(kZ(t,e))}async addTableMatrix(t,e,o){const r=t.map(i=>i!==0?i*15:1500);this.paragraphs.push(new gt.Table({rows:await this.generateTableRows(e,o),columnWidths:r}))}async generateRowCells(t,e){const o=[];for(const r of t){const i=r.cellId;if(i===void 0)continue;const s=r.width*.9;o.push(new gt.TableCell({children:await this.convertBlocksFunc(i,e.blocks[i],e,this.appId,this.docId,this.state,s),columnSpan:r.colSpan,rowSpan:r.rowSpan,width:{type:gt.WidthType.DXA,size:r.width*15},shading:r.color?{fill:r.color,type:gt.ShadingType.CLEAR,color:"auto"}:void 0}))}return o}async generateTableRows(t,e){const o=[];for(const r of t)o.push(new gt.TableRow({children:await this.generateRowCells(r,e)}));return o}async addDoc(t,e,o){const r=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,o);r&&(this.paragraphs=this.paragraphs.concat(r))}async addOtherEmbedBlock(){}}class VZ{constructor(t,e,o,r,i,s,l,a){m(this,"convertBlocks",async(t,e,o,r,i,s,l=720)=>{const a=new zZ(r,i,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await HZ(t,e,o,a,r,i,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),a.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=o,this.readImage=r,this.defaultFontSize=i,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=a}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,o){const r=new gt.ImportDotx,i=this.templateData?await r.extract(this.templateData):void 0,s=t.blocks.root;g(UZ,s,"data must have blocks");const l=jZ(),a=await this.convertBlocks("blocks",s,t,e,o,l),d=this.backgroundImageOptions?{default:new gt.Header({children:[new gt.Paragraph({children:[new gt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new gt.Document({numbering:{config:[...iZ,...l.levelConfigs]},sections:[{headers:d,children:a,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:i});return gt.Packer.toBlob(h)}}async function WZ(n,t,e,o){const r=n.doc.buildResourceUrl(o,{withToken:!0});let i=await A7(r);if(!i)return;if(i.type.indexOf("/svg")!==-1){const l=await g7(i);l&&(i=new File([l],i.name))}return await i.arrayBuffer()}async function qZ(n,t,e){const o=n.editorBlocks.getBlockClass(e.type);if(o.toStandardDoc)return o.toStandardDoc(n,e,t)}async function GZ(n,t){const e=t.attributes,o=n.editorBoxes.getBoxClass(e.type);if(o.toStandardText)return o.toStandardText(n,e)}async function ZZ(n,t){let{template:e,download:o,backgroundImageOptions:r}=t!=null?t:{};e||(e=XG());const i=n.doc.toJSON(),s=(p,A,v)=>WZ(n,p,A,v),l=async(p,A,v)=>qZ(n,i,v),a=async p=>GZ(n,p),h=await new VZ(e,i,Fd.default,s,void 0,l,a,r).convert("_appId","_docId");if(o){const p=URL.createObjectURL(h),A=document.createElement("a");A.setAttribute("download",`${C7(n)}.docx`),A.setAttribute("href",`${p}`),A.click(),A.remove()}return h}const J2=S("create-editor");async function QZ(n,t){var s,l,a,d,h,p,A,v,B,D,T,_,M,H;g(J2,n,"app does not exists"),t.lang&&R.setLang(t.lang),Ii.level=(s=t.logLevel)!=null?s:ha.DEBUG;const e=t.onReauth?async()=>{var ft;const z=t.user.userId,q=t.docId,rt=await((ft=t.onReauth)==null?void 0:ft.call(t,z,q,t.permission));return{userId:z,docId:q,permission:t.permission,appId:t.appId,token:rt,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,o={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},r=await Ka.load(o),i=Ha(n,r,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,components:{blocks:[...bk,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...Q2,...((a=t.components)==null?void 0:a.embeds)||[]],boxes:[...vk,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Gp,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new Sf,new yp],insertions:[wg],blockHooks:[new e2,new G7,...((p=t.components)==null?void 0:p.blockHooks)||[]],textRenders:[new i8,new C0],options:{...t.componentsOptions}},shortcuts:[bz,TN,pH,O0,_y,SO,S0,eV,Sh,...t.shortcuts||[]],colors:["#338FE5","#24B47E","#F0A100","#E52727","#9678D3","#2CB2AE","#EB6414","#8AAB3F"]});if(i.editorCommandProviders.registerCommandProvider(new Cr(i)),i.input.addHandler(new WV),i.input.addHandler(new xf),i.input.addHandler(new Z_),i.input.addHandler(new dH),i.input.addHandler(new bu(i,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new Cf(i,(A=t.componentsOptions)==null?void 0:A.quickMenu)),i.input.addHandler(new c2(i)),i.input.addHandler(new f2(i)),i.input.addHandler(new BN),i.input.addHandler(new _f),i.doc.registerCallback(new qV(i)),i.addCustom("remote-cursor",()=>new Jb(i)),i.addCustom("block-menu",z=>new Y7(z)),i.addCustom("editor-tooltip",()=>new Af(i)),t!=null&&t.enableComments&&i.addCustom("editor-comments",z=>new r8(z,new GG(z))),i.addCustom("create-options",()=>new K5(i,t)),i.addCustom("drop-target",()=>new Su(i)),i.addCustom("list-to-mindmap",()=>new df(i)),i.addCustom("list-to-mention",()=>new hW(i)),i.addCustom("mobile-helper",()=>new DW(i)),i.addCustom("code-caret",()=>new wN(i)),i.addCustom("image-paste-handler",()=>new l2(i)),(v=t.componentsOptions)!=null&&v.mention){const z=t.componentsOptions.mention;i.addCustom("mention",()=>new F2(i,z))}if(i.addCustom("heading-collapse",()=>new R2(i)),pc.register(i),Su.register(i),nl.register(i),Xi.register(i),i.addListener("clickLink",(z,q,rt)=>{var Bt;if((Bt=t==null?void 0:t.events)!=null&&Bt.onClickLink){t.events.onClickLink(z,q,rt);return}const ft=rt.getAttribute("link");ft&&(z.readonly||q.ctrlKey||q.metaKey)&&window.open(ft,"_blank")}),(D=(B=t.componentsOptions)==null?void 0:B.remoteCarets)!=null&&D.onUserChanged){const z=(_=(T=t.componentsOptions)==null?void 0:T.remoteCarets)==null?void 0:_.onUserChanged;i.doc.getRemoteUsers().on("change",q=>{z(i,q)})}return(H=(M=t.componentsOptions)==null?void 0:M.templates)!=null&&H.templates.length&&(i.addListener("docChanged",()=>{n1(i)}),i.addListener("resize",()=>{n1(i,{reset:!0})}),setTimeout(()=>{n1(i)},100)),i.doc.registerCallback({onError:async z=>{if(z.code==="ResetDoc"){J2.error(`reset doc: ${z.message}`);const q=await Ka.load(o);i.doc.reset(q)}}}),i}function YZ(n){return n.toJSON!==void 0}async function JZ(n,t,e){var i,s,l,a,d;g(J2,n,"app does not exists");const o=YZ(t)?t:new np(t,{serverUrl:e.serverUrl||""});e.lang&&R.setLang(e.lang);const r=Ha(n,o,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[Ef,Df,U0,I9],commandProviders:[new Gp],decorators:[new Sf,new yp],embeds:[...Q2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[T0,P2,h8,...((s=e.components)==null?void 0:s.boxes)||[]],insertions:[wg],blockHooks:[new e2,...((l=e.components)==null?void 0:l.blockHooks)||[]],textRenders:[new i8,new C0,...((a=e.components)==null?void 0:a.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[O0,_y,S0,Sh]});return r.editorCommandProviders.registerCommandProvider(new Cr(r)),r.input.addHandler(new xf),r.input.addHandler(new bu(r,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),r.input.addHandler(new Cf(r,(d=e.componentsOptions)==null?void 0:d.quickMenu)),r.input.addHandler(new c2(r)),r.input.addHandler(new f2(r)),r.input.addHandler(new _f),r.addCustom("block-menu",h=>new Y7(h)),r.addCustom("editor-tooltip",()=>new Af(r)),r.addCustom("image-paste-handler",()=>new l2(r)),e!=null&&e.enableComments&&r.addCustom("editor-comments",h=>new r8(h,new ZG(h,o))),r.addCustom("heading-collapse",()=>new R2(r)),r.addListener("clickLink",(h,p,A)=>{var B;if((B=e==null?void 0:e.events)!=null&&B.onClickLink){e.events.onClickLink(h,p,A);return}const v=A.getAttribute("link");v&&(h.readonly||p.ctrlKey||p.metaKey)&&window.open(v,"_blank")}),pc.register(r),r}function KZ(n,t){var a;const e=n.doc;if(!((a=e.getVersionHelper)==null?void 0:a.call(e)))throw new Error("the editor does not support to show versions");const r=n.getCustom("create-options");if(!r)throw new Error("the editor does not support to show versions");const i=r.getData(),s=new yk(i),l=n.addCustom("version-dialog",()=>new D8(n.doc,s));return l.show(t),l}b.tippy=zB,b.AnchorBox=v6,b.AuthError=zh,b.AuthHeader=Ja,b.AutoScroll=Gd,b.BaseURLHeader=Vh,b.BasicCommands=v_,b.BlockExclusiveHook=G7,b.BlockLockerHook=e2,b.BlockLockerPasteHandler=_f,b.BlockResizer=wu,b.BrBox=p6,b.CodeBlock=Df,b.CodeLineBlock=U0,b.CodeTextDecorator=Sf,b.DefaultShortcuts=Sh,b.DocIdError=US,b.DragDrop=hC,b.DrawioEmbed=V2,b.EditorBlocks=y4,b.EditorBoxes=A6,b.EditorCommandProviders=ab,b.EditorComplexBlockPosition=So,b.EditorComplexSelectionRange=or,b.EditorDecorators=B6,b.EditorEmbeds=w4,b.EditorInsertions=w6,b.EditorSimpleBlockPosition=je,b.EditorSimpleSelectionRange=Ze,b.EmbedBlock=E4,b.EmbedBlockResizer=Fu,b.EnforceWithDocumentTitleHandler=bu,b.EventCallbacks=fa,b.FILL_CHAR=dI,b.FileExtError=zS,b.GroupOrder=L9,b.HeadingBlockScrollListener=sW,b.ImageBox=b6,b.InlineBoxCommandProvider=$9,b.InputtingInsertion=y6,b.LocalDoc=np,b.LogLevel=ha,b.Logger=Ii,b.MIN_DISTANCE_THRESHOLD=uC,b.ManualCloseDialog=ru,b.ManualMenu=zs,b.ManualToolbar=ou,b.MarkdownInputHandler=xf,b.MaxUserError=mp,b.Mindmap=f0,b.OnesEditorAutoSuggest=Np,b.OnesEditorCustomDataWrapper=K5,b.OnesEditorExclusiveBlock=Xi,b.OnesEditorHoveringBlock=pe,b.OnesEditorQuickMenu=Cf,b.OnesEditorToc=Pu,b.OnesEditorTocProvider=nl,b.OnesEditorToolbar=pc,b.OnesEditorTooltip=Af,b.OnesEditorVersionsDialog=D8,b.PermissionError=jS,b.Popup=Xa,b.RemoteCarets=Jb,b.RemoteCaretsDecorator=yp,b.RemoteCaretsInsertion=wg,b.RemoteUsers=_h,b.RequestReloadError=Ya,b.RichText=ln,b.ShareDBDoc=Ka,b.ShareDBDocVersionsProvider=yk,b.SimpleCache=tC,b.StandardEmbedBlockCommands=I2,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=fg,b.TEXT_STYLE_COLOR_PREFIX=hg,b.TableBlock=Ef,b.TableBlockCommandProvider=Gp,b.TableShortcuts=O0,b.TextBlock=In,b.TextBox=g6,b.TextStyleShortcuts=S0,b.TocEmbed=U8,b.ZERO_WIDTH_SPACE_CHAR=ma,b.abbreviation=Zd,b.addAttribute=uh,b.addClass=W,b.addCommentToBlock=Kf,b.addDays=ME,b.addMetaToDoc=Mh,b.addMonths=LE,b.animateScrollTo=km,b.applyPlaceholderToBlock=If,b.assert=g,b.autoShowHideTemplates=n1,b.blockToDoc=Kg,b.blockToHtml=Ig,b.blockToMarkdown=Tg,b.blockToText=Ah,b.blocksToDoc=DT,b.clearAllSelection=n4,b.clientType=Ke,b.cloneBlock=Fi,b.cloneChildContainer=Ng,b.cloneDoc=$g,b.cloneText=i6,b.commentToShareDbComment=vp,b.compareElement=Hd,b.comparePosition=Xm,b.complexBlockAdjustSelectionPos=nh,b.complexBlockFindNearestChildBlock=D4,b.complexBlockGeFirstSimpleChild=eg,b.complexBlockGetAllChildContainers=En,b.complexBlockGetBottomChildContainers=T4,b.complexBlockGetLastSimpleChild=Vl,b.complexBlockGetSelectedContainers=Os,b.complexBlockGetTopChildContainers=I4,b.containerToDoc=$A,b.continuousScroll=SC,b.convertBlockFrom=Kd,b.convertImageFileToPng=g7,b.convertImageSrcToPng=qP,b.copyBlockAttributes=P6,b.createBlockAnchor=Li,b.createBlockCaretAnchor=R4,b.createBlockContentElement=Ts,b.createBlockElement=WC,b.createBlockSimpleDocRange=mh,b.createBlockSimpleRange=ye,b.createBoxContentElement=ZC,b.createBoxElement=qC,b.createBoxOp=Q4,b.createChildContainer=b4,b.createComplexBlockPosition=fe,b.createComplexDocPos=d6,b.createComplexDocRange=mI,b.createContainer=c6,b.createContainerElement=Gm,b.createDeleteOps=W4,b.createEditor=Ha,b.createEditorSelectionRange=Ue,b.createElement=w,b.createEmptyContainer=Ur,b.createEmptyDoc=jr,b.createEmptyTextBlockData=hh,b.createExpandedRange=Nd,b.createIconButton=Hl,b.createImage=pm,b.createInsertOps=ch,b.createInsertionContentElement=JC,b.createInsertionElement=QC,b.createLocalEditor=JZ,b.createOnesEditor=QZ,b.createRange=eC,b.createRichText=Oi,b.createRootContainer=A4,b.createSimpleBlockPosition=st,b.createSimpleDocPos=u6,b.createTextBlockData=sr,b.createTextButton=Qs,b.createTextOp=lo,b.createTextWithReplaceSoftReturn=ag,b.daysAfter=Rm,b.deleteText=dg,b.diffDays=RE,b.disablePageScroll=BC,b.docToHtml=M6,b.docToHtmlFragment=bh,b.docToMarkdown=Ma,b.docToText=La,b.downloadImageToFile=A7,b.downloadObjectToFile=j2,b.downloadSvgToString=Y8,b.editLink=fu,b.editorAddComment=oz,b.editorAddTextAttribute=Z6,b.editorAutoInsertBlock=N6,b.editorBreakTextBlock=Yl,b.editorClearCompositionText=F6,b.editorClearSelectedContents=Fg,b.editorCopyBlock=Rh,b.editorDeleteBlock=Og,b.editorDeleteBlockText=Mg,b.editorDeleteBlockWithoutChildren=kh,b.editorDeleteChildContainer=cT,b.editorDeleteChildContainers=$6,b.editorFocusToBlock=Pg,b.editorFocusToEnd=PA,b.editorGetBlockData=_i,b.editorGetBlockText=mn,b.editorGetBlockTextEx=ph,b.editorGetBoxData=f6,b.editorHandleKeyboardEvent=zA,b.editorInsertBlock=Ql,b.editorInsertBoxToBlock=O6,b.editorInsertDoc=q6,b.editorInsertDocAt=Hg,b.editorInsertText=Lg,b.editorInsertTextToBlock=R6,b.editorInsertTextToBlockEx=Sg,b.editorMergeTextBlock=H6,b.editorMoveDown=sA,b.editorMoveEnd=pA,b.editorMoveHome=CA,b.editorMoveLeft=oA,b.editorMoveLineEnd=EA,b.editorMoveLineHome=BA,b.editorMovePageDown=LA,b.editorMovePageUp=SA,b.editorMoveRight=rA,b.editorMoveUp=iA,b.editorMoveWordEnd=fA,b.editorMoveWordLeft=hA,b.editorRangeClearColor=Y6,b.editorRangeGetColor=jg,b.editorRangeSetColor=Q6,b.editorRemoveTextAttribute=hT,b.editorReplaceBlockText=Bh,b.editorReplaceContainer=G6,b.editorRunOnce=op,b.editorSelectAll=FA,b.editorSelectContainer=Yg,b.editorSelectDown=lA,b.editorSelectEnd=Zg,b.editorSelectHome=AA,b.editorSelectLeft=cA,b.editorSelectLineEnd=wA,b.editorSelectLineHome=kA,b.editorSelectPageDown=RA,b.editorSelectPageUp=MA,b.editorSelectRight=aA,b.editorSelectUp=uA,b.editorSelectWordEnd=gA,b.editorSelectWordLeft=mA,b.editorSetTextColor=Jl,b.editorShowFindDialog=uU,b.editorToDocx=ZZ,b.editorUpdateBlockData=Eh,b.editorUpdateCompositionText=_6,b.editorUpdateEmbedData=V6,b.enablePageScroll=EC,b.escapeHtmlText=lC,b.escapeRegExp=Pm,b.escapeSpace=gE,b.exclusiveBlock=K0,b.executeBlockCommand=d4,b.executeEmbedBlockCommand=u4,b.executeRangeCommand=cb,b.fileToDataUrl=Ul,b.findAfterOffsetNotType=vg,b.findAllText=Cg,b.findEventTargetBlock=iC,b.findInsertionById=YC,b.findNextOffset=LI,b.findNextVisibleSimpleBlock=mb,b.findPrevOffset=SI,b.findPrevOffsetNotType=bg,b.findPrevSimpleBlockBeforeChildContainer=x4,b.findPrevVisibleSimpleBlock=fb,b.findTarget=jl,b.findWordEnd=kg,b.findWordLeft=yg,b.format=ba,b.formatBytes=LC,b.formatDate=_m,b.fragmentToHtml=xC,b.fromBase64=Ud,b.fromBase64ToBlob=Dm,b.fromBase64ToUint8Array=xE,b.fromDocRange=Si,b.fromNowString=Fm,b.genId=K,b.getAllChildBlocks=og,b.getAllQuickMenuItems=D0,b.getAllSelectedBlocks=Lo,b.getAttributesAt=Ta,b.getBlockBackground=VC,b.getBlockByIndex=Or,b.getBlockCaretRect=To,b.getBlockClass=Qt,b.getBlockClassByType=Ms,b.getBlockClientRects=Ti,b.getBlockCommandsWithHook=Wm,b.getBlockContent=Rt,b.getBlockId=it,b.getBlockIndex=bt,b.getBlockInfo=Iu,b.getBlockKind=Io,b.getBlockMinWidth=r4,b.getBlockNearestRangeFromPoint=M4,b.getBlockOptions=VE,b.getBlockPath=Di,b.getBlockProperties=l4,b.getBlockRangeFromPoint=oh,b.getBlockStyles=zE,b.getBlockTextLength=ut,b.getBlockTools=le,b.getBlockType=Dt,b.getBoxContent=Hm,b.getBoxId=GC,b.getBoxTypeFromElement=va,b.getChildBlockCount=Eo,b.getChildBlocks=ve,b.getChildOffset=Mi,b.getColorFromAttributes=gg,b.getColorFromContent=Qd,b.getComplexBlockClass=jn,b.getContainerBlockPath=g4,b.getContainerBlocks=e4,b.getContainerBlocksElement=th,b.getContainerById=Nr,b.getContainerId=at,b.getContainerMinWidth=Qm,b.getContainerToolsElement=QE,b.getContainerWidth=v4,b.getDistanceSquare=er,b.getElementOffset=ga,b.getElementScale=ys,b.getEmbedType=Un,b.getExistsBlockTools=Jd,b.getExistsContainerById=m4,b.getFileExt=Aa,b.getFirstChildBlock=Se,b.getFirstClientRect=$d,b.getHeadingMenuOptions=B0,b.getHorizontalPadding=Cm,b.getInsertionContent=jm,b.getLastChildBlock=Ge,b.getLastClientRect=bs,b.getListAllNextBrothers=dc,b.getLogger=S,b.getNextBlock=Zt,b.getNextValidOffset=Fs,b.getNextVisibleBlock=Ss,b.getOffsetInfoAfter=Sa,b.getOffsetInfoBefore=Ch,b.getOpAt=K4,b.getOpLength=ah,b.getParentBlock=ot,b.getParentBlockExcludeSelf=Is,b.getParentBox=$m,b.getParentContainer=nt,b.getPrevBlock=ce,b.getPrevValidOffset=Ri,b.getPrevVisibleBlock=Ds,b.getRangeCommands=sb,b.getRootBlock=Vm,b.getScrollContainer=oo,b.getSpecialBlockCommands=c4,b.getStandardEmbedBlockProperties=T2,b.getTextAfterOffset=TI,b.getTextAttributes=Dg,b.getTextBeforeOffset=DI,b.getTextBlockChild=Xd,b.getTextBlockClass=XC,b.getTextBlockContentChildTextLength=so,b.getTextBlockContentChildType=h4,b.getTextBlockContentChildren=nr,b.getTextLength=rn,b.getTextOpLength=rg,b.getTextWidth=Vd,b.getToolbar=sf,b.handleBlockElementUpdated=i4,b.hasAltOnly=yE,b.hasClass=xt,b.hasCtrlOrCmd=bC,b.hasCtrlOrCmdOnly=vE,b.hashCode=NC,b.hideBlock=UC,b.htmlToFragment=zd,b.i18n=R,b.injectDocToHtmlFragment=Lh,b.injectStyle=aC,b.insertEmptyBlock=GE,b.insertEmptyEmbedBlock=qm,b.insertText=Hr,b.intersectionCommands=OD,b.isBackspace=yC,b.isBlock=xs,b.isBlockLocked=Of,b.isBlockLockedByOthers=t2,b.isBlockLockedBySelf=Tu,b.isBlockTools=jC,b.isBox=Nm,b.isCJK=pC,b.isChildContainer=Do,b.isChildNode=Kt,b.isCollapsedRange=fI,b.isComplexBlockPosition=Km,b.isComplexKindBlock=Lt,b.isContainer=_r,b.isContainerSelectedAllChildBlocks=OA,b.isControlEvent=ws,b.isDelete=wE,b.isDraggingFiles=Wd,b.isElementVisible=ym,b.isEmbedBlock=Le,b.isEmptyContainer=Ym,b.isEmptyDoc=Ag,b.isEmptyTextBlock=he,b.isEmptyTextBlockWithoutCompositionText=Au,b.isEnterOnly=vC,b.isEscape=Im,b.isExclusiveBlock=Rf,b.isFirefox=Em,b.isFirstChildBlockInComplexBlock=Ix,b.isHighSurrogate=aE,b.isInBlock=Um,b.isInBlockTools=Ls,b.isLetter=gC,b.isLowSurrogate=gm,b.isMatchShortcut=Rr,b.isMoveForward=AE,b.isNavigationEvent=CE,b.isNavigationKey=AC,b.isNodeRemoved=oC,b.isNumber=mC,b.isPrintableKey=xm,b.isRootBlock=ro,b.isRootContainer=Xt,b.isSafari=CC,b.isSameDay=Om,b.isSecureEnv=j0,b.isShiftEnter=kE,b.isShiftTab=EE,b.isShortcutEvent=bE,b.isSimpleBlock=UE,b.isSimpleBlockPosition=$r,b.isSimplePos=a6,b.isSimpleRange=fh,b.isSpace=jd,b.isTab=BE,b.isTextBlockContentBoxChild=io,b.isTextBlockContentChild=ka,b.isTextBlockContentInsertionChild=Pr,b.isTextBlockContentTextChild=wa,b.isTextKindBlock=tt,b.isTextKindBlockType=ya,b.isToday=MC,b.isValidOffset=sn,b.isVisibleBlock=Yd,b.isYesterday=RC,b.loadJs=rC,b.loadJsPromise=vs,b.lockers=wo,b.mergeCommands=rf,b.mergeDocs=$s,b.mergeOps=ug,b.mergeText=Y4,b.multiSplitText=F4,b.overflowText=OC,b.parseShortcut=kC,b.patchNode=Ca,b.pointInRect=ks,b.rangeAddAttribute=Ia,b.rangeGetTextColor=r6,b.rangeRemoveAttribute=ql,b.rangeSetTextColor=e6,b.rangeTransformText=X4,b.registerDragDrop=wm,b.removeAttribute=mg,b.removeClass=et,b.removeLastBr=rI,b.removePlaceholderFromBlock=l7,b.removeStyle=cC,b.replaceAll=OE,b.replaceAllCaseInsensitive=_E,b.replaceAllText=l6,b.replaceText=dh,b.requestDownload=qd,b.resetListStart=fc,b.scrollable=DC,b.selectFile=zl,b.selectedBlockToDoc=Ih,b.selectionToDoc=Th,b.setAttributes=bm,b.setClipboardData=Mm,b.setClipboardDataByEvent=SE,b.setColorToAttributes=n6,b.setDataset=Am,b.setDefaultCursor=pa,b.setStyles=vm,b.shareDBCommentToDocObject=bp,b.shareDBDocCommentToComment=Qb,b.shortcutToDisplayText=Bo,b.showBlock=zC,b.showDocVersions=KZ,b.splitText=xn,b.splitToThree=ze,b.stringToDataUrl=Sm,b.stringToObjectUrl=Lm,b.subText=P4,b.textNodeOffsetFromPoint=nC,b.titleFromEditor=C7,b.toBase64URL=Bs,b.toMindmap=uf,b.toPlainText=re,b.toPlainTextKeepLength=pg,b.trimChar=Bm,b.unexclusiveBlock=X0,b.unicodeLength=uE,b.unicodeSubstr=dE,b.updateBlockSelection=o4,b.updateOpAttributes=s6,b.updateTextBlockContent=II,b.updateUrl=Tm;for(const n in be)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>be[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|