@ones-editor/editor 1.1.17-beta.4 → 1.1.17-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ Available method signatures are:
28
28
  ${t}
29
29
  \`\`\`
30
30
  `:""}function P1(n){if(!window.isSecureContext||n.selection.range.isCollapsed())return!1;const t=Ma(n);Du(n,t);const e=yu(n,t);Iu(e,t);let r="";if(y2(n)){const i=n.selection.range.getSelectedBlocks()[0],o=rt(i.block);J(o)&&(r=k2(n,ts(n,t)))}else{const i=[];t.blocks.root.forEach((o,s)=>{i.push(_h(n,o,t,[{containerId:"root",blockIndex:s}]))}),i[i.length-1]=i[i.length-1].trimEnd(),r=i.join(`
31
- `)}return ru([{type:"text/plain",data:new Blob([r],{type:"text/plain"})}]),!0}const aO=Object.freeze(Object.defineProperty({__proto__:null,editorHandleEnter:A2,editorHandleDelete:b2,editorHandleBackspace:v2,editorHandleInsertBr:B2,editorHandlePastePlainText:T2,isSelectedCodeTextBlock:y2,getSelectedCodeBlockMarkdown:k2,editorHandleCopyMarkdown:P1},Symbol.toStringTag,{value:"Module"})),Gh={ArrowDown:O5,ArrowUp:U5,ArrowLeft:_5,ArrowRight:M5,"Shift+ArrowDown":N5,"Shift+ArrowUp":K5,"Shift+ArrowLeft":P5,"Shift+ArrowRight":F5,"CtrlOrCmd+ArrowLeft":$5,"CtrlOrCmd+ArrowRight":H5,"CtrlOrCmd+Shift+ArrowLeft":j5,"CtrlOrCmd+Shift+ArrowRight":z5,"CtrlOrCmd+ArrowUp":G5,"CtrlOrCmd+ArrowDown":S1,"CtrlOrCmd+Shift+ArrowUp":W5,"CtrlOrCmd+Shift+ArrowDown":L1,"CtrlOrCmd+A":I1,Home:Z5,End:t2,"Shift+Home":Q5,"Shift+End":J5,PageUp:o2,PageDown:s2,"Shift+PageUp":a2,"Shift+PageDown":c2,"CtrlOrCmd+Z":YU,"CtrlOrCmd+Shift+Z":QU,Enter:A2,Delete:b2,Backspace:v2,"Shift+Enter":B2,"CtrlOrCmd+Shift+V":T2,"CtrlOrCmd+Shift+C":P1};function R2(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function w2(n,t,e){if(t.type==="embed"){const o=t.embedData,s=o.src;if(s&&typeof s=="string"){const l=e.get(s);if(l)o.src=l;else{let c="";s.split("|").forEach(h=>{const C=e.get(h);C&&(c+=c?`|${C}`:`${C}`)}),c&&(o.src=c)}}return}const r=t.text;r&&r.forEach(o=>{if(o.attributes&&o.attributes.src&&typeof o.attributes.src=="string"){const s=e.get(o.attributes.src);s&&(o.attributes.src=s)}});const i=t.children;i&&i.forEach(o=>{n.blocks[o].forEach(l=>{w2(n,l,e)})})}function S2(n,t,e){if(e.size===0)return;t.blocks.root.forEach(i=>{const o=n.editorBlocks.getBlockClass(i.type);o.replaceResources?o.replaceResources(i,e):w2(t,i,e)})}async function cO(n,t){let e=t.filter(s=>s.indexOf(":")===-1);const r=[];e.forEach(s=>{const l=s.split("|");r.push(...l)}),e=Array.from(new Set(r)),e=r;const i=await n.doc.addResources(e),o=new Map;if(e.length!==i.length)return o;for(let s=0;s<e.length;s++)o.set(e[s],i[s]);return o}function uO(n,t){var l,c,d,h;const r=t.meta.serverId;if(!r||typeof r!="string")return!1;const i=(c=(l=n.doc).getServerMeta)==null?void 0:c.call(l);if(!i)return!1;const o=/.*(?=\/)/;return((d=(i.serverId||"").match(o))==null?void 0:d[0])===((h=r.match(o))==null?void 0:h[0])}async function F1(n,t){const r=t.meta.resources;if(!r||Object.keys(r).length===0)return;let i=new Map;if(uO(n,t)){const s=Array.from(Object.keys(r));i=await cO(n,s),S2(n,t,i)}const o=new Map;Object.entries(r).forEach(([s,l])=>{i.get(s)===void 0&&s!==l&&o.set(s,l)}),o.size!==0&&S2(n,t,o)}async function fO(n,t,e){await F1(n,t),n.undoManager.runInGroup(()=>{const{start:r,end:i}=n.selection.range,o=n.getBlockById(r.blockId);if(r.blockId===i.blockId&&ge(o)){const s=rt(o),l=n.getBlockIndex(o),[c]=n.insertDocAt(s,l+1,t,e);c&&n.selection.selectBlock(c,dt(n,c))}else{n.clearSelectedContents();const{block:s,offset:l}=Sa(n);n.insertDoc(s,l,t,e)}})}const dO=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function hO(n){let t;for(const e of dO)if(t=n[e],t)break;return t||null}class mO{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"hookExecutionAttempt",(t,e,r)=>{for(let i=0;i<this.handlers.length;i++){const o=this.handlers[i];if(o.handleBeforeCopy){const s=o.handleBeforeCopy(this.editor,e,r);if(s===!0)return!0;if(typeof s=="object"&&s!=null)return s}}});m(this,"onPasteText",async(t,e)=>{const r=new DataTransfer;r.setData("text/plain",t);const i=await this.editor.dataConverter.fromData(this.editor,r,e);if(i){const o=[];this.pasteDocs(i,null,o)}});m(this,"onBlur",ke.default(()=>{const t=this.editor.selection.range;if(!t.isCollapsed()){let e=null;if(nl(t.anchor)){const r=t.anchor.childContainerId,i=Ur(this.editor,r);e=k3(this.editor,i)}else e=this.editor.getBlockById(t.anchor.blockId);if(e){const r=at(e,0,"normal");this.editor.selection.setSelection(r,void 0,{noScroll:!0})}}this.removeActiveForBlur()},200));m(this,"removeActiveForBlur",ke.default(()=>{ot(this.editor.rootElement,"active")},200));this.editor=t}onInsertText(t,e){if(!nt(this.editor,this.editor.getFocusedBlock()))return;const{containerId:r,blockIndex:i,offset:o}=Sa(this.editor);this.handleBeforeInsertText(r,i,o,e)||(this.defaultInsertText(this.editor,r,i,o,e),this.handleAfterInsertText(r,i,o,e),this.editor.selection.updateLastCaretRect())}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleChanged&&r.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleRemoteChanged&&r.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){if(!nt(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:r,offset:i}=Sa(this.editor);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,r,i)}}onUpdateCompositionText(t,e,r){if(!nt(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText(e,r),this.editor.selection.caret.update();const{containerId:i,blockIndex:o,offset:s}=Sa(this.editor);for(let l=0;l<this.handlers.length;l++){const c=this.handlers[l];c.handleUpdateCompositionText&&c.handleUpdateCompositionText(this.editor,i,o,s,r)}this.editor.selection.updateLastCaretRect()}onCopy(t){oO(this.editor,t,this.hookExecutionAttempt)}onCopyWithoutEvent(){sO(this.editor,this.hookExecutionAttempt)}onCut(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeCut&&i.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const r=this.editor.selection.focusedBlock;ge(r)&&this.editor.deleteBlock(r)}else Ph(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;const e=this.editor.dataConverter.fromData(this.editor,t.clipboardData),r=Array.from(t.clipboardData.files);e.then(async i=>{i&&this.pasteDocs(i,t,r)})}onFocus(){z(this.editor.rootElement,"active"),this.onBlur.cancel(),this.removeActiveForBlur.cancel()}addHandler(t){this.handlers.push(t),this.handlers=this.handlers.sort((e,r)=>{var s,l;const i=(s=e.order)!=null?s:1;return((l=r.order)!=null?l:1)-i})}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,r,i))return!0}return!1}handleAfterInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,r,i))return!0}return!1}handleBeforeKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,r,i,o){h1(this.editor,o)}defaultHandleKeydown(t,e){return R2(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePasteDoc&&await i.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map,boxIdMap:new Map};await fO(this.editor,t,e);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPasteDoc&&await i.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e,r){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforePaste&&await s.handleBeforePaste(this.editor,e,t,r))return}const i=hO(t);if(!!i){await this.pasteDoc(i);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterPaste&&await s.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}forEach(t){this.handlers.forEach(t)}}function gO(n,t,e){const r=zo(t,e);return r.remove(),r}I("copy-dom-attributes");const L2=["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 pO(n,t){for(let l=0;l<L2.length;l++){const c=L2[l];t[c]=n[c]}const e=n.attributes,r=t.attributes,i=[],o=[];for(let l=0;l<e.length;l++){const c=e[l],d=r.getNamedItem(c.name);d?d.value!==c.value&&(d.value=c.value,o.push(c)):i.push(c)}const s=[];for(let l=0;l<r.length;l++){const c=r[l];e.getNamedItem(c.name)||s.push(c)}i.forEach(l=>{t.setAttribute(l.name,l.value)}),o.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function I2(n){const t=Array.from(n.childNodes).filter(e=>!jv(e));return t.forEach(e=>{e.remove()}),t}function D2(n,t,e){var d;const r=n.getContainerById(t),i=zo(r,e),o=qo(i),s=n.doc.getBlockData(t,e),l=Qt(n,i);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,i,s))n.editorBlockRenders.updateBlock(n,o,i,s);else{const h=n.editorBlocks.createBlock(o,r,s),C=I2(h);I2(i),C.forEach(x=>{i.appendChild(x)});const E=oh(h);if(E){const x=oh(i);x&&x.remove(),i.appendChild(E)}pO(h,i)}i3(n,i,s),n.blockHooks.forEach(h=>{var C;(C=h.update)==null||C.call(h,n,o,r,i,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const CO=I("transform-selection");function _2(n,t,e,r){const{range:i}=n.selection,{anchor:o,focus:s}=i;if(o.blockId!==t&&s.blockId!==t)return i;p(CO,o.isSimple()&&s.isSimple(),"invalid text pos type");let l=o;if(o.blockId===t){const d=pn.transformCursor(o.offset,e,r);l=at(t,d,"normal")}let c=s;if(s.blockId===t){const d=pn.transformCursor(s.offset,e,r);c=at(t,d,"normal")}return Ye(n,{anchor:l,focus:c})}const EO=I("handle-block-text-changed");function xO(n,t,e,r,i){const o=n.getContainerById(t),s=zo(o,e),l=n.doc.getBlockData(t,e);if(p(EO,l.text,"no block text"),Kv(n,s).setBlockText(n,s,l.text),!i){const c=_2(n,l.id,r,i);n.selection.setRange(c,{noScroll:!0})}}function AO(n,t){const e=mt.default(n);return t.delete.forEach(i=>{delete e[i]}),{...e,...t.insert}}function M2(n,t,e,r){const i=Qt(n,t);i.handleDeleteBlock&&i.handleDeleteBlock(n,t,e,r),n.emit("blockDeleted",n,t,e,r)}function bO(n,t,e,r){const i=n.getBlockByIndex(t,e);i.querySelectorAll('[data-type="editor-block"]').forEach(o=>{M2(n,o,r,{child:!0})}),M2(n,i,r,{child:!1})}const Hr=I("editor-doc");class vO extends ma{constructor(e,r,i){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=r,this.externalDoc.registerCallback(this),this.registerLocalEvents(i)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var r,i;return(i=(r=this.externalDoc).getVersionHelper)==null?void 0:i.call(r)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}findContainerBlocks(e){return this.externalDoc.findContainerBlocks(e)}getBlockData(e,r){return this.externalDoc.getBlockData(e,r)}verifyBlockWritable(e,r){const i=this.editor.getBlockByIndex(e,r);p(Hr,this.editor.isBlockWritable(i),`block is not writable, ${e}, ${r}`)}localUpdateBlockText(e,r,i,o){p(Hr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const s=this.getBlockData(e,r),l=s.text;p(Hr,l,`no text, ${e}, ${r}`);const c=_2(this.editor,s.id,i,!0),d=pn.apply(l,i);this.localEvents.forEach(C=>C.onBeforeUpdateBlockText(e,s.id,l,d,c.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,r,i);return this.editor.selection.setRange(c,o),h}localUpdateBlockData(e,r,i,o){p(Hr,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,r);if(!this.editor.isBlockWritable(s)){const h=Array.from(i.delete).filter(E=>E!=="comments"),C=Object.keys(i.insert).filter(E=>E!=="comments");(h.length>0||C.length>0)&&p(Hr,!1,`block is not writable, comment supported only, ${JSON.stringify(i)}}`)}const l=mt.default(this.getBlockData(e,r)),c=mt.default(AO(l,i));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,c,o));const d=this.externalDoc.localUpdateBlockData(e,r,i,o);return this.editor.selection.setRange(Xo(this.editor,o)),d}localInsertBlock(e,r,i,o,s){p(Hr,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(c=>c.onBeforeInsertBlock(e,r,i,o));const l=this.externalDoc.localInsertBlock(e,r,i,o);return s!=null&&s.noFocus||this.editor.selection.setRange(Xo(this.editor,o),s),l}localDeleteBlock(e,r,i){p(Hr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const o=mt.default(this.getBlockData(e,r));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,r,o,i));const s=this.externalDoc.localDeleteBlock(e,r,i);return this.editor.selection.setRange(Xo(this.editor,i)),s}localDeleteChildContainers(e){return p(Hr,!this.editor.readonly,"editor is readonly"),e.forEach(r=>{const i=mt.default(this.getContainerBlocks(r));this.localEvents.forEach(o=>o.onBeforeDeleteChildContainer(r,i))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainers(e){p(Hr,!this.editor.readonly,"editor is readonly");const r=mt.default(e);r.forEach(i=>{this.localEvents.forEach(o=>o.onBeforeInsertChildContainer(i.containerId,i.blocks))}),this.externalDoc.localInsertChildContainers(r)}onRequestReload(e){Hr.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(i=>{var o;return(o=i.onRequestReload)==null?void 0:o.call(i,e)});const r=!1;this.editor.emit("docChanged",this.editor,r)}onUpdateBlockText(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,r,i,o)}),xO(this.editor,e,r,i,o),this.editor.emit("docChanged",this.editor,o)}onUpdateBlockData(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,o)}),D2(this.editor,e,r),this.editor.emit("docChanged",this.editor,o)}onInsertBlock(e,r,i,o){this.callbacks.forEach(l=>{var c;return(c=l.onInsertBlock)==null?void 0:c.call(l,e,r,i,o)});const s=this.editor.getContainerById(e);e7(this.editor,s,r,i),this.editor.emit("docChanged",this.editor,o)}onDeleteBlock(e,r,i){bO(this.editor,e,r,i),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,i)});const o=this.editor.getContainerById(e);gO(this.editor,o,r),this.editor.emit("docChanged",this.editor,i)}onInsertChildContainer(e,r,i){this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,e,r,i)})}onDeleteChildContainer(e,r){this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,e)})}onStatusChanged(e){this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)})}onError(e){this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}uploadResource(e,r){return this.externalDoc.uploadResource(e,r)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,r){return this.externalDoc.buildResourceUrl(e,r)}request(e,r){return this.externalDoc.request(e,r)}broadcastMessage(e){return this.externalDoc.broadcastMessage(e)}getUser(){return this.externalDoc.getUser()}getRemoteUsers(){return this.externalDoc.getRemoteUsers()}triggerReAuth(){var e,r;return(r=(e=this.externalDoc).triggerReAuth)==null?void 0:r.call(e)}destroy(){this.externalDoc.destroy(),this.clearCallbacks()}getServerMeta(){var e,r,i;return(i=(r=(e=this.externalDoc).getServerMeta)==null?void 0:r.call(e))!=null?i:{}}reset(e){Hr.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function U2(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 Wh=I("undo-action");class Ua{constructor(t,e,r){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=r}undo(t){return!1}redo(t){return!1}combinable(t){return p(Wh,t,"no other action"),!1}combine(t){p(Wh,!1,"no other")}setAfterRange(t){this.afterRange&&Wh.warn("after range has already set"),this.afterRange=t}findContainerById(t,e){return!!t.doc.findContainerBlocks(e)}findBlockById(t,e){const r=t.doc.findContainerBlocks(this.containerId);return r?r.some(i=>i.id===e):!1}checkBlockData(t,e){if(Array.isArray(e.children)){const r=t.doc.toJSON();for(let i=0;i<e.children.length;i++){const o=e.children[i];if(!r.blocks[o])return Wh.warn(`container (${o}) not found, deleted by others?`),!1}}return!0}}const Oa=I("block-action");class O2 extends Ua{constructor(e,r,i,o,s){super(e,r,s);m(this,"blockData");m(this,"blockIndex");this.blockData=mt.default(o),this.blockIndex=i}deleteBlock(e,r){if(!this.findContainerById(e,this.containerId))return Oa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockData.id))return Oa.warn(`block (${this.blockData.id}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const o=e.getBlockById(this.blockData.id);if(!o)return!1;try{p(Oa,this.blockIndex===vt(o),"invalid block index"),Oh(e,o,Xo(e,r))}catch(s){Oa.warn(s.message),e.selection.selectBlock(o,0)}return!0}insertBlock(e,r){if(!this.findContainerById(e,this.containerId))return Oa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.checkBlockData(e,this.blockData))return!1;try{Ia(e,this.containerId,this.blockIndex,mt.default(this.blockData),r)}catch(i){Oa.warn(i.message);const o=e.doc.getContainerBlocks(this.containerId),s=Math.min(o.length-1,this.blockIndex),l=e.getBlockByIndex(this.containerId,s);e.selection.selectBlock(l,0)}return!0}}I("insert-block-action");class BO extends O2{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class TO extends O2{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class yO extends Ua{constructor(e){super(e,ct(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){U2(this.actions,e),this.afterRange=e.afterRange}undo(e){let r=!1;return this.actions.concat().reverse().forEach(i=>{i.undo(e)&&(r=!0)}),r}redo(e){let r=!1;return this.actions.forEach(i=>{i.redo(e)&&(r=!0)}),r}setAfterRange(e){this.afterRange=e;const r=this.actions[this.actions.length-1];!r||r instanceof Ua&&(r.afterRange||r.setAfterRange(e))}}const is=I("update-block-data-action");class qh extends Ua{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=i,p(is,this.blockId===o.id,"invalid block id"),p(is,this.blockId===s.id,"invalid block id"),this.beforeBlockData=mt.default(o),this.afterBlockData=mt.default(s),p(is,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){if(!e.findBlockById(this.blockId))return is.warn(`block (${this.blockId}) not found, deleted by others?`),!1;const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(is,i,"no container"),Kh(e,r,qh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){if(!e.findBlockById(this.blockId))return is.warn(`block (${this.blockId}) not found, deleted by others?`),!1;p(is,e,"no editor");const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(is,i,"no container"),Kh(e,r,qh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const r=mt.default(e);return delete r.id,delete r.type,r}}const ul=I("update-block-text-action");class _u extends Ua{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=i,this.beforeRichTextData=mt.default(o),this.afterRichTextData=mt.default(s),this.type=_u.calType(o,s)}static calType(e,r){p(ul,e,"no old data"),p(ul,r,"no new data");const o=pn.diff(e,r),s=new Set;let l=!1;const c=h=>gv(h)?`cjk_${h}`:hv(h)?"number":Yd(h)?"space":mv(h)?"letter":"unknown";let d=!1;return o.forEach(h=>{h.insert?h.insert===" "?s.add("insert_letter"):typeof h.insert=="string"&&h.insert.startsWith(" ")&&h.insert.length>1?(l=!0,d=!0,s.add(`insert_${c(h.insert.substr(1))}`)):s.add(`insert_${c(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!this.findContainerById(e,this.containerId))return ul.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return ul.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Fh(e,i,this.beforeRichTextData),!0):!1}redo(e){if(!this.findContainerById(e,this.containerId))return ul.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return ul.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Fh(e,i,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof _u)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const r=e.beforeRange,i=r.anchor;if(!i.isSimple())return!1;const o=this.afterRange;if(!o)return!1;const s=o.anchor;return!(!s.isSimple()||s.blockId!==r.anchor.blockId||s.offset!==i.offset)}combine(e){p(ul,e instanceof _u,"invalid action type");const r=e;this.afterRichTextData=r.afterRichTextData,this.afterRange=e.afterRange}}const N2=I("child-container-action");class P2 extends Ua{constructor(t,e,r){super(t,e,t.selection.range.toDocRange()),this.blocks=r}deleteChildContainer(t){return this.findContainerById(t,this.containerId)?(t.doc.localDeleteChildContainers([this.containerId]),!0):(N2.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}insertChildContainer(t){return this.findContainerById(t,this.containerId)?(N2.warn(`container (${this.containerId}) already exists`),!1):(t.doc.localInsertChildContainers([{containerId:this.containerId,blocks:mt.default(this.blocks)}]),!0)}}class kO extends P2{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class RO extends P2{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const jr=I("undo");class wO{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):(U2(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(p(jr,!this.currentGroup,"current group already exists"),this.currentGroup=new yO(this.editor),this.groupCounter=1):(p(jr,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){p(jr,this.currentGroup,"current group not exists"),p(jr,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?jr.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 jr.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(Xo(this.editor,t.beforeRange))}catch(e){jr.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(Xo(this.editor,e)):jr.warn("no after range")}catch(e){jr.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,r,i,o){this.undoRedoing||(this.prepareSaveUndoState(),pn.diff(r,i).length!==0&&this.addAction(new _u(this.editor,t,e,r,i,o)))}onBeforeUpdateBlockData(t,e,r,i,o){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new qh(this.editor,t,e,r,i,o);this.addAction(s)}onBeforeInsertBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),p(jr,e>=0,"invalid block index"),p(jr,r,"no block data"),this.addAction(new BO(this.editor,t,e,r,i)))}onBeforeDeleteBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new TO(this.editor,t,e,r,i)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new kO(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new RO(this.editor,t,e)))}}class SO{async fromData(t,e){const r=e.getData("text/x-ones-editor-doc");if(r)return{"text/x-ones-editor-doc":JSON.parse(r)}}}class LO{constructor(){m(this,"converters",[]);m(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new SO)}prepareData(t){const e=new DataTransfer;for(let r=0;r<this.converterTypes.length;r++)e.setData(this.converterTypes[r],t.getData(this.converterTypes[r]));return e}async fromData(t,e,r){let i={};const o=this.prepareData(e);for(const s of this.converters){const l=await s.fromData(t,o,r);l&&(i={...i,...l})}return i}addConverter(t){this.converters.push(t)}}function IO(n){n.editorBlocks.registerBlockClass(Nn),n.editorBlocks.registerBlockClass(y3),n.editorBoxes.registerBoxClass(zB),n.editorBoxes.registerBoxClass(GB),n.editorBoxes.registerBoxClass(XB),n.editorBoxes.registerBoxClass(YB),n.editorInsertions.registerInsertionClass(QB),n.editorBlockRenders.registerRender(new Hv)}function DO(n,t){IO(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 Xh=I("range-commands");function F2(n,t){n.forEach(e=>{e.source=t,e.children&&F2(e.children,t)})}function K2(n,t){n.forEach(e=>{e.group=t,e.children&&K2(e.children,t)})}function V2(n,t,e,r){const i=lt(t);p(Xh,i===e.start.blockId,"invalid start range"),p(Xh,i===e.end.blockId,"invalid end range");const o=n.editorCommandProviders.getCommandProviders();let s=[];if(o.forEach(l=>{const c=l.getAvailableCommands(n,t,e);F2(c,r),K2(c,l.id),s.push(...c)}),o.forEach(l=>{if(l.filterCommands){const c=l.filterCommands(n,t,e,s);c&&(s=c)}}),Lt(n,t)){if(!nl(e.start))return s;p(Xh,!e.start.isSimple(),"invalid start pos"),p(Xh,!e.end.isSimple(),"invalid end pos");const l=e.start.childContainerId,c=Ur(n,l),h=fe(c)[0];if(h){const C=dt(n,h),E=Ye(n,{anchor:at(h,0,"home"),focus:at(h,C,"end")}),x=V2(n,h,E,r);s.push(...x)}}return s}function $2(n,t){const e=n.getEditor(),r=n.getSelectedBlocks(),i=[],o=n.isReverse()?r[0]:r[r.length-1],s=Ye(e,{anchor:o.start,focus:o.end});return V2(e,o.block,s,t).forEach(c=>{i.push(c)}),i}function H2(n,t,e,r,i,o){var h;const s=n.editorCommandProviders.getCommandProviders();for(let C=0;C<s.length;C++){const E=s[C];if(E.beforeExecuteCommand&&E.beforeExecuteCommand(n,t,e,r,i))return!1}const l=n.editorCommandProviders.getCommandProvider(r.group),c={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,r,i,{}))return o[lt(t)]=c,!0;let d=!1;return Lt(n,t)&&ba(n,t,e.start,e.end).forEach(E=>{fe(E).forEach(v=>{const R=dt(n,v),w=Ye(n,{anchor:at(v,0,"home"),focus:at(v,R,"end")});H2(n,v,w,r,i,o)&&(d=!0)})}),s.forEach(C=>{C.afterExecuteCommand&&C.afterExecuteCommand(n,t,e,r,i,o)}),d}function j2(n,t,e){const r=n.getEditor(),i={},o=r.editorCommandProviders.getCommandProvider(t.group);return o.executeRangeCommand&&o.executeRangeCommand(r,n,t,e,i)||(n.getSelectedBlocks().forEach(l=>{const c=Ye(r,{anchor:l.start,focus:l.end});H2(r,l.block,c,t,e,i)}),r.focus()),i}const _O=I("command-providers");class z2{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(r=>r.id===t);return p(_O,e,`no command provider, id=${t}`),e}getCommands(t,e){return $2(t,e)}executeCommand(t,e,r){return this.editor.emit("beforeExecCommand",this.editor,e,{source:e.source}),this.editor.undoManager.runInGroup(()=>j2(t,e,r))}getEmptyBlockTextAttributes(t,e){let r={};if(this.providers.forEach(i=>{var s;const o=(s=i.getEmptyBlockTextAttributes)==null?void 0:s.call(i,t,e);o&&(r={...r,...o})}),Object.keys(r).length!==0)return r}}function MO(n,t){const e=rt(t),r=ct(e),i=vt(t);D2(n,r,i)}const G2=I("update-block-text");function UO(n,t,e){const r=n.getBoxById(t.id),i=J(r);p(G2,i,"no parent block"),p(G2,nt(n,i),"not a text block");const o=n.getBlockText(i),s=NB(o,"id",t.id,t);E5(n,i,s,e)}function OO(n,t){for(const e of n.blockHooks)if(e.writable){const r=e.writable(n,t);if(typeof r=="boolean")return r}return!0}function NO(n){if(n.readonly)return!1;const t=Ci(n);return!!n.isBlockWritable(t.map(e=>e.block))}class PO{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 FO{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const r=this.shortcuts;for(const i of r){const o=Object.entries(i);for(const[s,l]of o)if(di(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const so=I("editor");class KO extends ye.TypedEmitter{constructor(e,r,i){var o,s,l,c,d,h,C,E,x;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 FO);m(this,"dataConverter",new LO);m(this,"editorBlocks",new b3(this));m(this,"editorBoxes",new qB(this));m(this,"editorInsertions",new ZB(this));m(this,"editorEmbeds",new B3(this));m(this,"editorDecorators",new t5(this));m(this,"editorCommandProviders",new z2(this));m(this,"editorBlockRenders",new zI(this));m(this,"blockHooks",[]);m(this,"domEvents",new FU(this));m(this,"customs",new Map);m(this,"options");m(this,"version","");m(this,"inputHandlers",new mO(this));m(this,"settingsProvider");m(this,"_readonly",!1);m(this,"getColor",e=>{const r=this.options.colors;return r.length===0?"#FF1A75":r[e%r.length]});so.debug("create editor"),this.setMaxListeners(100),this.options={colors:(o=i==null?void 0:i.colors)!=null?o:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"],componentsOptions:(l=(s=i==null?void 0:i.components)==null?void 0:s.options)!=null?l:{},scrollContainer:i==null?void 0:i.scrollContainer,enableComments:(c=i==null?void 0:i.enableComments)!=null?c:!0,enableContextMenu:(d=i==null?void 0:i.enableContextMenu)!=null?d:!0},this.settingsProvider=(h=i==null?void 0:i.settingsProvider)!=null?h:new PO(this),DO(this,i==null?void 0:i.components),this.blockHooks.push(...(E=(C=i==null?void 0:i.components)==null?void 0:C.blockHooks)!=null?E:[]),this.id=(x=i==null?void 0:i.id)!=null?x:tt(),this.clientId=tt(),this.undoManager=new wO(this),this.doc=new vO(this,r,this.undoManager),this.parent=e,this.rootElement=B("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=B("div",["editor-content"],this.rootElement),this.rootContainerObject=E3(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new rU(this,this.inputHandlers),this.selection=new GU(this),this.selectionHandler=new XU(this),i!=null&&i.shortcuts&&this.shortcuts.shortcuts.push(...i.shortcuts),ie.isMobile&&z(this.rootElement,"mobile"),ie.isSafari&&z(this.rootElement,"safari"),this._readonly&&z(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?z(this.rootElement,"readonly"):ot(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:qe(this.rootContainer)}addCustom(e,r){const i=this.customs.get(e);if(i)return i;const o=r(this);return this.customs.set(e,o),o}getCustom(e){const r=this.customs.get(e);return p(so,r,`${e} does not exists`),r}replaceCustom(e,r){const i=this.customs.get(e);return i&&i.destroy(),this.customs.set(e,r),r}findCustom(e){return this.customs.get(e)}findCustomByType(e){const r=this.customs.values();for(const i of r)if(i instanceof e)return i;return null}destroyCustom(e){const r=this.customs.get(e);r&&(this.customs.delete(e),r.destroy())}getComponentOptions(e){return this.options.componentsOptions[e]}registerLocalEvents(e){this.doc.registerLocalEvents(e)}reload(){this.rootContainerObject.reload(),this.emit("load",this,!0)}createBlock(e,r,i){return this.editorBlocks.createBlock(e,r,i)}createBox(e,r){return this.editorBoxes.createBox(e,r)}createInsertion(e,r){return this.editorInsertions.createInsertion(e,r)}destroy(){so.debug("destroy editor"),this.emit("destroy",this),this.input.destroy(),this.rootContainerObject.destroy(),this.rootElement.remove(),this.doc.destroy(),this.customs.forEach(e=>e.destroy()),this.customs.clear(),this.selection.destroy(),this.domEvents.destroy(),this.removeAllListeners(),this.inputHandlers.destroy()}focus(){this.input.focus()}focusToBlock(e,r){x1(this,e,r)}isWritable(){return NO(this)}isBlockWritable(e){return OO(this,e)}getChildContainerData(e){const r=this.doc.getContainerBlocks(e);return(!r||!Array.isArray(r))&&(p(so,r,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),p(so,Array.isArray(r),`container data is not an array: ${JSON.stringify(r)}`)),r}createChildContainer(e,r,i){return x3(this,e,r,i)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(so,Js(r),"not an valid block element"),r!=null?r:null}findBoxById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(so,sh(r),"not an valid box element"),r!=null?r:null}getBlockById(e){const r=this.findBlockById(e);return p(so,r,`no block, id=${e}`),r}getBoxById(e){const r=this.findBoxById(e);return p(so,r,`no box, id=${e}`),r}getBlockByIndex(e,r){const i=this.getContainerById(e);return zo(i,r)}findBlockByIndex(e,r){const i=this.getContainerById(e);return Pv(i,r)}getBlockIndex(e){if(typeof e=="string"){const r=this.getBlockById(e);return vt(r)}return vt(e)}getContainerById(e){return Ur(this,e)}getParentContainer(e){return rt(e)}reloadBlock(e){MO(this,e)}contains(e){const r=e instanceof Element?e:e.parentElement;return r?r.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,r,i,o,s){const l={blockId:i.id,offset:0},c={anchor:l,focus:l};return Ia(this,e,r,i,o!=null?o:c,s)}insertEmbed(e,r,i,o,s){const l={id:tt(),type:"embed",embedType:i,embedData:o};return this.insertBlock(e,r,l,s)}deleteBlock(e,r){C1(this,e,r)}mergeTextBlock(e,r){return g5(this,e,r)}breakTextBlock(e,r,i){return Da(this,e,r,i).newBlock}getTextPosition(){return Sa(this)}getBlockString(e,r){const i=this.getBlockText(e);return de(i,r)}getBlockData(e){return Zo(this,e)}getBoxData(e){return HB(this,e)}getBlockText(e){return yn(this,e)}setBlockText(e,r){E5(this,e,r)}deleteTextFromBlock(e,r,i,o){return g1(this,e,r,i,o)}insertTextToBlock(e,r,i,o){return c5(this,e,r,i,o)}insertBoxToBlock(e,r,i){return u5(this,e,r,i)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,r,i,o){b5(this,e,r,i,o)}insertDocAt(e,r,i,o){return v1(this,e,r,i,o)}deleteChildContainers(e){m5(this,e)}replaceBlockText(e,r){return Fh(this,e,r)}updateBlockData(e,r,i){const o={...this.getBlockData(e),...r},{id:s,type:l,...c}=o;return Kh(this,e,c,(i!=null?i:this.selection.range).toDocRange())}updateEmbedData(e,r,i){return x5(this,e,r,i)}updateBoxData(e,r){UO(this,e,r)}getSelectedText(){const e=Ma(this);return ts(this,e)}clearSelectedContents(){Ph(this)}insertTextBlock(e,r,i,o){const s=Ai(e!=null?e:"");return h5(this,s,r,i,o==null?void 0:o.newRange,o==null?void 0:o.insertBlockOptions)}updateCompositionText(e,r){if(e&&!r&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!r){m1(this);return}r?(this.compositingText="",Yc()?e||m1(this):h1(this,e)):(this.compositingText=e,f5(this))}}function Mu(n,t,e){return new KO(n,t,e)}function VO(n){const t=(r,i)=>{const o=r.findIndex(l=>l.id===i.id);if(o===-1){r.push(i);return}const s=r[o];if(s.value!==i.value){r.splice(o,1);return}if(!!s.states){if(!i.states){s.states=[];return}s.states=Ng.default(s.states,i.states)}},e=[];return n.forEach(r=>{r.forEach(i=>{t(e,i)})}),e}const $O=["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"];class Uu extends ye.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:$O}setCursor(e){this.addUser(e.user);const r=this.cursors.get(e.user.userId);if(r&&Xc.default(r,e))return;this.cursors.set(e.user.userId,e);const i=new Set([e.range.anchor.blockId,e.range.focus.blockId]),o=new Set(i);r&&new Set([r.range.anchor.blockId,r.range.focus.blockId]).forEach(l=>{i.has(l)||o.add(l)}),this.emit("remote-carets-change",[...o])}addUsers(e){this.addingUser=!0,e.forEach(r=>this.addUser(r)),this.addingUser=!1,this.emit("change",Array.from(this.users.values()))}addUser(e){this.users.set(e.userId,e),this.addingUser||this.emit("change",Array.from(this.users.values()))}findUser(e){var r;return(r=this.users.get(e))!=null?r:null}removeUser(e){this.users.delete(e),this.emit("change",Array.from(this.users.values()));const r=this.cursors.get(e);if(r){const i=new Set(new Set([r==null?void 0:r.range.anchor.blockId,r==null?void 0:r.range.focus.blockId]));this.cursors.delete(e),this.emit("remote-carets-change",[...i])}}updateUsers(e){this.users.forEach(r=>{e.find(i=>i.userId===r.userId)||this.removeUser(r.userId)}),this.users.clear(),this.addingUser=!0;try{e.forEach(r=>{this.addUser(r)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const r=new Map;return Array.from(this.cursors.values()).filter(i=>i.range.anchor.blockId===e&&kh(i.range)).forEach(i=>{const o=i.range.focus.offset;let s=r.get(o);s||(s=[],r.set(o,s)),s.push(i)}),r}getCursors(e){return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e||r.range.focus.blockId===e)}onUpdateBlockText(e,r,i){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(kh(l.range)){const{anchor:c,focus:d}=l.range;c.blockId===e.id&&(c.offset=pn.transformCursor(c.offset,r,i)),d.blockId===e.id&&(d.offset=pn.transformCursor(d.offset,r,i))}})}getFixedUserColor(e,r){let i=0;Array.from(e).forEach(s=>{i+=s.charCodeAt(0)});const o=i%this.colors.length;return this.colors[o]}destroy(){this.removeAllListeners()}}const an=I("local-doc");class K1 extends ma{constructor(e,r){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[Ai("")]}},this.serviceUrl=(r==null?void 0:r.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}findContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,r){const i=this.getContainerBlocks(e);p(an,i,`no container data: ${e}`);const o=i[r];return p(an,o,`no block data: ${r}`),o}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(an,o.text,"no text for data");const s=pn.apply(o.text,i);return o.text=s,p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var c;return(c=l.onUpdateBlockText)==null?void 0:c.call(l,e,r,i,!0)}),s}localUpdateBlockData(e,r,i){const o=this.getBlockData(e,r);return i.delete.forEach(s=>delete o[s]),Object.entries(i.insert).forEach(([s,l])=>{o[s]=l}),p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,!0)}),o}localInsertBlock(e,r,i){const o=this.getContainerBlocks(e);return p(an,o,`no container data: ${e}`),p(an,r>=0&&r<=o.length,`invalid block index: ${r}, ${o.length}`),o.splice(r,0,i),p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,r,i,!0)}),i}localDeleteBlock(e,r){const i=this.getContainerBlocks(e);p(an,i,`no container data: ${e}`),p(an,r>=0&&r<=i.length,`invalid block index: ${r}, ${i.length}`);const o=i[r];return i.splice(r,1),p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,!0)}),o}localInsertChildContainers(e){e.forEach(({containerId:r,blocks:i})=>{this.doc.blocks[r]=i,p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,r,i,!0)})})}localDeleteChildContainers(e){an.debug(`delete child containers: ${e}`),e.forEach(r=>{p(an,this.doc.blocks[r],`no child container: ${r}`),delete this.doc.blocks[r]}),e.forEach(r=>{p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,r,!0)})})}uploadResource(e,r){p(an,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,r){p(an,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new Uu}setDoc(e){this.doc=mt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,"change doc")})}destroy(){this.clearCallbacks()}}class HO{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function V1(n,t,e){n.addCustom(t,()=>{var o;const r=(o=e())!=null?o:void 0;return new HO(r)})}const W2=I("find-block");function q2(n,t){const e=mr(t);if(!e){if(pr(t))return null;const r=Zs(t);return p(W2,r,"no parent block"),q2(n,r)}return Lt(n,e)?va(n,e,{visibleOnly:!0}):e}function X2(n,t){const e=gr(t);if(!e){if(pr(t))return null;const r=Zs(t);return p(W2,r,"no parent block"),X2(n,r)}return Lt(n,e)?Tp(n,e,{visibleOnly:!0}):e}const jO=I("remote-cursor");class zO{constructor(){m(this,"remoteUsers",new Uu)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const r=e;this.handleUpdateUsers(r.users)}else e.type==="caret"?this.handleUpdateCaret(e):jO.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 GO(n){const{blocks:t,meta:e,comments:r,...i}=n;return{rootBlocks:t,meta:e,comments:r,childBlocks:i}}function WO(n){const{blocks:t,meta:e,comments:r}=n,{root:i,...o}=t;return{blocks:i,meta:e,comments:r,...o}}function lo(n){const{childBlocks:t,meta:e,comments:r,rootBlocks:i}=GO(mt.default(n));return{blocks:{root:i,...t},meta:e,comments:r}}function ao(n){return n==="root"?"blocks":n}function Na(n){return n==="blocks"?"root":n}const qO={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new mn.default(n)},apply(n,t){const e=new mn.default(n),r=new mn.default(t);return e.compose(r).ops},compose(n,t){const e=new mn.default(n),r=new mn.default(t);return e.compose(r).ops},diff(n,t){const e=new mn.default(n),r=new mn.default(t);return e.diff(r).ops},transform(n,t,e){const r=new mn.default(n);return new mn.default(t).transform(r,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const r=new mn.default(t),i=this.transformCursor(n.index,r,e),o=this.transformCursor(n.index+n.length,r,e);return{...n,index:i,length:o-i}}}};var os={},$1=Og.default.EventEmitter;os.EventEmitter=$1,os.mixin=XO;function XO(n){for(var t in $1.prototype)n.prototype[t]=$1.prototype[t]}var Y2=["info","warn","error"];function Q2(){var n={};Y2.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var YO=Q2;Q2.prototype.setMethods=function(n){n=n||{};var t=this;Y2.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var QO=YO,JO=new QO,J2=JO;function fl(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,fl):this.stack=new Error().stack}fl.prototype=Object.create(Error.prototype),fl.prototype.constructor=fl,fl.prototype.name="ShareDBError",fl.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_FIXUP_IS_ONLY_VALID_ON_APPLY:"ERR_FIXUP_IS_ONLY_VALID_ON_APPLY",ERR_CANNOT_FIXUP_DELETION:"ERR_CANNOT_FIXUP_DELETION",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_CHANNEL_MISSING:"ERR_QUERY_CHANNEL_MISSING",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE:"ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var Yh=fl,Ou={},Z2=ZO;function ZO(n,t,e,r){var i=function(s,l,c,d){t(c,s,l,"left"),t(d,l,s,"right")},o=n.transformX=function(s,l){e(s),e(l);for(var c=[],d=0;d<l.length;d++){for(var h=l[d],C=[],E=0;E<s.length;){var x=[];if(i(s[E],h,C,x),E++,x.length===1)h=x[0];else if(x.length===0){for(var v=E;v<s.length;v++)r(C,s[v]);h=null;break}else{for(var R=o(s.slice(E),x),w=0;w<R[0].length;w++)r(C,R[0][w]);for(var U=0;U<R[1].length;U++)r(c,R[1][U]);h=null;break}}h!=null&&r(c,h),s=C}return[s,c]};n.transform=function(s,l,c){if(!(c==="left"||c==="right"))throw new Error("type must be 'left' or 'right'");return l.length===0?s:s.length===1&&l.length===1?t([],s[0],l[0],c):c==="left"?o(s,l)[0]:o(l,s)[1]}}var tT={exports:{}},ss=tT.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||""}},H1=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},j1=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")},Qh=function(n){for(var t=0;t<n.length;t++)j1(n[t])};ss.apply=function(n,t){var e;Qh(t);for(var r=0;r<t.length;r++){var i=t[r];if(i.i!=null)n=H1(n,i.p,i.i);else{if(e=n.slice(i.p,i.p+i.d.length),i.d!==e)throw new Error("Delete component '"+i.d+"' does not match deleted text '"+e+"'");n=n.slice(0,i.p)+n.slice(i.p+i.d.length)}}return n};var co=ss._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:H1(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:H1(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};ss.compose=function(n,t){Qh(n),Qh(t);for(var e=n.slice(),r=0;r<t.length;r++)co(e,t[r]);return e},ss.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=0),co(t,r)}return t};var z1=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};ss.transformCursor=function(n,t,e){for(var r=e==="right",i=0;i<t.length;i++)n=z1(n,t[i],r);return n};var tN=ss._tc=function(n,t,e,r){if(j1(t),j1(e),t.i!=null)co(n,{i:t.i,p:z1(t.p,e,r==="right")});else if(e.i!=null){var i=t.d;t.p<e.p&&(co(n,{d:i.slice(0,e.p-t.p),p:t.p}),i=i.slice(e.p-t.p)),i!==""&&co(n,{d:i,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)co(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)co(n,t);else{var o={d:"",p:t.p};t.p<e.p&&(o.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(o.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),c=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(c!==d)throw new Error("Delete ops delete different text in the same region of the document");o.d!==""&&(o.p=z1(o.p,e),co(n,o))}return n},eN=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};ss.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=eN(n[t]);return n},Z2(ss,tN,Qh,co);var Jh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},nN=function(n){return!!n&&n.constructor===Object},zr=function(n){return JSON.parse(JSON.stringify(n))},Dt={name:"json0",uri:"http://sharejs.org/types/JSONv0"},uo={};Dt.registerSubtype=function(n){uo[n.name]=n},Dt.create=function(n){return n===void 0?null:zr(n)},Dt.invertComponent=function(n){var t={p:n.p};return n.t&&uo[n.t]&&(t.t=n.t,t.o=uo[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},Dt.invert=function(n){for(var t=n.slice().reverse(),e=[],r=0;r<t.length;r++)e.push(Dt.invertComponent(t[r]));return e},Dt.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!Jh(n[t].p))throw new Error("Missing path")},Dt.checkList=function(n){if(!Jh(n))throw new Error("Referenced element not a list")},Dt.checkObj=function(n){if(!nN(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function Nu(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 Pu(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}Dt.apply=function(n,t){Dt.checkValidOp(t),t=zr(t);for(var e={data:n},r=0;r<t.length;r++){var i=t[r];(i.si!=null||i.sd!=null)&&Nu(i);for(var o=null,s=e,l="data",c=0;c<i.p.length;c++){var d=i.p[c];if(o=s,s=s[l],l=d,o==null)throw new Error("Path invalid")}if(i.t&&i.o!==void 0&&uo[i.t])s[l]=uo[i.t].apply(s[l],i.o);else if(i.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=i.na}else if(i.li!==void 0&&i.ld!==void 0)Dt.checkList(s),s[l]=i.li;else if(i.li!==void 0)Dt.checkList(s),s.splice(l,0,i.li);else if(i.ld!==void 0)Dt.checkList(s),s.splice(l,1);else if(i.lm!==void 0){if(Dt.checkList(s),i.lm!=l){var h=s[l];s.splice(l,1),s.splice(i.lm,0,h)}}else if(i.oi!==void 0)Dt.checkObj(s),s[l]=i.oi;else if(i.od!==void 0)Dt.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},Dt.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},Dt.incrementalApply=function(n,t,e){for(var r=0;r<t.length;r++){var i=[t[r]];n=Dt.apply(n,i),e(i,n)}return n};var rN=Dt.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var r=0;r<n.length;r++)if(n[r]!==t[r]&&(!e||r!==n.length-1))return!1;return!0};Dt.append=function(n,t){if(t=zr(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)&&(Nu(t),Nu(e)),rN(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&uo[t.t]){if(e.o=uo[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var r=t.p,i=0;i<e.o.length-1;i++)t.o=[e.o.pop()],t.p=r.slice(),Pu(t),n.push(t);Pu(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)&&(Pu(t),Pu(e)),n.push(t)},Dt.compose=function(n,t){Dt.checkValidOp(n),Dt.checkValidOp(t);for(var e=zr(n),r=0;r<t.length;r++)Dt.append(e,t[r]);return e},Dt.normalize=function(n){var t=[];n=Jh(n)?n:[n];for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=[]),Dt.append(t,r)}return t},Dt.commonLengthForOps=function(n,t){var e=n.p.length,r=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&r++,e===0)return-1;if(r===0)return null;e--,r--;for(var i=0;i<e;i++){var o=n.p[i];if(i>=r||o!==t.p[i])return null}return e},Dt.canOpAffectPath=function(n,t){return Dt.commonLengthForOps({p:t},n)!=null},Dt.transformComponent=function(n,t,e,r){t=zr(t);var i=Dt.commonLengthForOps(e,t),o=Dt.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,o!=null&&l>s&&t.p[o]==e.p[o]){if(t.ld!==void 0){var c=zr(e);c.p=c.p.slice(s),t.ld=Dt.apply(zr(t.ld),[c])}else if(t.od!==void 0){var c=zr(e);c.p=c.p.slice(s),t.od=Dt.apply(zr(t.od),[c])}}if(i!=null){var d=s==l,c=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(Nu(t),c=zr(e),Nu(c)),c.t&&uo[c.t]){if(t.t&&t.t===c.t){var h=uo[t.t].transform(t.o,c.o,r);if(t.si!=null||t.sd!=null)for(var C=t.p,E=0;E<h.length;E++)t.o=[h[E]],t.p=C.slice(),Pu(t),Dt.append(n,t);else(!Jh(h)||h.length>0)&&(t.o=h,Dt.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[i]===t.p[i])if(d){if(t.ld!==void 0)if(t.li!==void 0&&r==="left")t.ld=zr(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&d&&t.p[i]===e.p[i]?r==="right"&&t.p[i]++:e.p[i]<=t.p[i]&&t.p[i]++,t.lm!==void 0&&d&&e.p[i]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[i]===t.p[i])return n;var C=e.p[i],x=t.p[i],v=t.lm;(C<v||C===v&&x<v)&&t.lm--}if(e.p[i]<t.p[i])t.p[i]--;else if(e.p[i]===t.p[i]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var x=t.p[i],v=t.lm,R=e.p[i],w=e.lm;if(R!==w)if(x===R)if(r==="left")t.p[i]=w,x===v&&(t.lm=w);else return n;else x>R&&t.p[i]--,x>w?t.p[i]++:x===w&&R>w&&(t.p[i]++,x===v&&t.lm++),(v>R||v===R&&v>x)&&t.lm--,v>w?t.lm++:v===w&&(w>R&&v>x||w<R&&v<x?r==="right"&&t.lm++:v>x?t.lm++:v===R&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var x=e.p[i],v=e.lm;C=t.p[i],C>x&&t.p[i]--,C>v&&t.p[i]++}else{var x=e.p[i],v=e.lm;C=t.p[i],C===x?t.p[i]=v:(C>x&&t.p[i]--,(C>v||C===v&&x>v)&&t.p[i]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[i]===e.p[i])if(t.oi!==void 0&&d){if(r==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[i]===e.p[i])if(r==="left")Dt.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[i]==e.p[i]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return Dt.append(n,t),n},Z2(Dt,Dt.transformComponent,Dt.checkValidOp,Dt.append);var iN=tT.exports;Dt.registerSubtype(iN);var oN=Dt,sN={type:oN};(function(n){n.defaultType=sN.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)})(Ou);var xr={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var r in e)return!0;return!1},n.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e},n.isValidVersion=function(e){return e===null?!0:n.isInteger(e)&&e>=0},n.isValidTimestamp=function(e){return n.isValidVersion(e)},n.MAX_SAFE_INTEGER=9007199254740991,n.dig=function(){for(var e=arguments[0],r=1;r<arguments.length;r++){var i=arguments[r];e=e[i]||(r===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],r=arguments[arguments.length-1],i=1;i<arguments.length-1;i++){var o=arguments[i];e=e[o]||(e[o]=i===arguments.length-2?r():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],r=[e],i=1;i<arguments.length-1;i++){var o=arguments[i];if(!e.hasOwnProperty(o))break;e=e[o],r.push(e)}for(var i=r.length-1;i>=0;i--){var s=r[i],o=arguments[i+1],l=s[o];(i===r.length-1||!n.hasKeys(l))&&delete s[o]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,r){var i=!1;return e.forEach(function(o){o&&(o(r),i=!0)}),i},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];setTimeout(function(){e.apply(null,r)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(xr);var eT=Array.isArray,nT=Object.keys,lN=Object.prototype.hasOwnProperty,aN=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=eT(t),i=eT(e),o,s,l;if(r&&i){if(s=t.length,s!=e.length)return!1;for(o=s;o--!==0;)if(!n(t[o],e[o]))return!1;return!0}if(r!=i)return!1;var c=t instanceof Date,d=e instanceof Date;if(c!=d)return!1;if(c&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,C=e instanceof RegExp;if(h!=C)return!1;if(h&&C)return t.toString()==e.toString();var E=nT(t);if(s=E.length,s!==nT(e).length)return!1;for(o=s;o--!==0;)if(!lN.call(e,E[o]))return!1;for(o=s;o--!==0;)if(l=E[o],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},ls={};ls.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",fixup:"fixup",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var rT=os,cN=J2,tr=Yh,Zh=Ou,Gr=xr,uN=Gr.clone,fN=aN,G1=ls.ACTIONS,Pn=tr.CODES,dN=Kt;function Kt(n,t,e){rT.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}rT.mixin(Kt),Kt.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())})},Kt.prototype._setType=function(n){if(typeof n=="string"&&(n=Zh.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new tr(Pn.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Kt.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Kt.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new tr(Pn.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 tr(Pn.ERR_DOC_MISSING_VERSION,"Cannot ingest snapshot in doc with null version. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}return n.v>this.version?this.fetch(t):t&&t()}if(this.version>n.v)return t&&t();this.version=n.v;var r=n.type===void 0?Zh.defaultType:n.type;this._setType(r),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},Kt.prototype.whenNothingPending=function(n){var t=this;Gr.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Kt.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Kt.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Kt.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Kt.prototype._emitResponseError=function(n,t){if(n&&n.code===Pn.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)},Kt.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var r=this.inflightFetch.shift();if(r&&e.push(r),e.length&&(r=function(i){Gr.callEach(e,i)}),n)return this._emitResponseError(n,r);this.ingestSnapshot(t,r),this._emitNothingPending()},Kt.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var r=this.pendingFetch;this.pendingFetch=[],e.callback&&r.push(e.callback);var i;if(r.length&&(i=function(o){Gr.callEach(r,o)}),n)return this._emitResponseError(n,i);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,i):i&&i(),this._emitNothingPending(),this._flushSubscribe()},Kt.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Pn.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=Fu(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var r=0;r<this.pendingOps.length;r++){var e=Fu(this.pendingOps[r],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}}},Kt.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))},Kt.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()},Kt.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);hN(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Kt.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Kt.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Kt.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,r=e&&e.wantSubscribe===n;if(r){e.callback=mN([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Kt.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;Gr.nextTick(function(){n._handleSubscribe()})}}};function hN(n,t,e){if(t){var r=n.pop();n.push(function(i){r&&r(i),e&&e(i)})}else n.push(e)}function mN(n){return n=n.filter(Gr.truthy),n.length?function(t){Gr.callEach(n,t)}:null}Kt.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function gN(n){delete n.op,delete n.create,delete n.del}function Fu(n,t){if(n.del)return gN(t);if(t.del)return new tr(Pn.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new tr(Pn.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new tr(Pn.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var r=n.type.transform(n.op,t.op,"left"),i=n.type.transform(t.op,n.op,"right");n.op=r,t.op=i}}}Kt.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new tr(Pn.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===Zh.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,r=0;r<n.op.length;r++){var i=n.op[r],o={op:[i]};this.emit("before op",o.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=Fu(this.applyStack[s],o);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,o.op)),this.emit("op",o.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var c=this.data;this._setType(null),this.emit("del",c,t);return}},Kt.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 tr(Pn.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>=Gr.MAX_SAFE_INTEGER)return this.emit("error",new tr(Pn.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)}},Kt.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var r=new tr(Pn.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(r):this.emit("error",r)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(o){return this._hardRollback(o)}var i=this;Gr.nextTick(function(){i.flush()})},Kt.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var r=this._tryCompose(n);if(r){r.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},Kt.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var r=this.pendingOps.splice(e),e=0;e<r.length;e++){var t=r[e],i=this._tryCompose(t);i?i.callbacks=i.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},Kt.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!fN(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}}},Kt.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var r={op:n},i=t&&t.source;this._submit(r,i,e)},Kt.prototype.create=function(n,t,e,r){if(typeof t=="function"?(r=t,e=null,t=null):typeof e=="function"&&(r=e,e=null),t||(t=Zh.defaultType.uri),this.type){var i=new tr(Pn.ERR_DOC_ALREADY_CREATED,"Document already exists");return r?r(i):this.emit("error",i)}var o={create:{type:t,data:n}},s=e&&e.source;this._submit(o,s,r)},Kt.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new tr(Pn.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var r={del:!0},i=n&&n.source;this._submit(r,i,t)},Kt.prototype.pause=function(){this.paused=!0},Kt.prototype.resume=function(){this.paused=!1,this.flush()},Kt.prototype.toSnapshot=function(){return{v:this.version,data:uN(this.data),type:this.type.uri}},Kt.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return cN.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();if(n[G1.fixup])for(var t=0;t<n[G1.fixup].length;t++){for(var e=n[G1.fixup][t],r=0;r<this.pendingOps.length;r++){var i=Fu(this.pendingOps[t],e);if(i)return this._hardRollback(i)}try{this._otApply(e,!1)}catch(o){return this._hardRollback(o)}}this.version++,this._clearInflightOp()},Kt.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var r=Fu(this.pendingOps[e],t);if(r)return this._hardRollback(r)}try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}this._clearInflightOp(n);return}this._hardRollback(n)},Kt.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var r=!!t.length,i=0;i<t.length;i++)r=Gr.callEach(t[i].callbacks,n)&&r;if(n&&!r)return e.emit("error",n)})},Kt.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=Gr.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var iT=os,oT=ls.ACTIONS,pN=xr,CN=Fn;function Fn(n,t,e,r,i,o,s){iT.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=r,this.query=i,this.results=null,o&&o.results&&(this.results=o.results,delete o.results),this.extra=void 0,this.options=o,this.callback=s,this.ready=!1,this.sent=!1}iT.mixin(Fn),Fn.prototype.hasPending=function(){return!this.ready},Fn.prototype.send=function(){if(!!this.connection.canSend){var n={a:this.action,id:this.id,c:this.collection,q:this.query};if(this.options&&(n.o=this.options),this.results){for(var t=[],e=0;e<this.results.length;e++){var r=this.results[e];t.push([r.id,r.version])}n.r=t}this.connection.send(n),this.sent=!0}},Fn.prototype.destroy=function(n){this.connection.canSend&&this.action===oT.querySubscribe&&this.connection.send({a:oT.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&pN.nextTick(n)},Fn.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},Fn.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},Fn.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},Fn.prototype._handleResponse=function(n,t,e){var r=this.callback;if(this.callback=null,n)return this._finishResponse(n,r);if(!t)return this._finishResponse(null,r);var i=this,o=1,s=function(h){if(h)return i._finishResponse(h,r);--o||i._finishResponse(null,r)};if(Array.isArray(t))o+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){o++;var c=t[l],d=this.connection.get(c.c||this.collection,l);d.ingestSnapshot(c,s)}s()},Fn.prototype._ingestSnapshots=function(n,t){for(var e=[],r=0;r<n.length;r++){var i=n[r],o=this.connection.get(i.c||this.collection,i.d);o.ingestSnapshot(i,t),e.push(o)}return e},Fn.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)},Fn.prototype._handleError=function(n){this.emit("error",n)},Fn.prototype._handleDiff=function(n){for(var t=0;t<n.length;t++){var e=n[t];e.type==="insert"&&(e.values=this._ingestSnapshots(e.values))}for(var t=0;t<n.length;t++){var e=n[t];switch(e.type){case"insert":var r=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(r)),this.emit("insert",r,e.index);break;case"remove":var o=e.howMany||1,i=this.results.splice(e.index,o);this.emit("remove",i,e.index);break;case"move":var o=e.howMany||1,s=this.results.splice(e.from,o);Array.prototype.splice.apply(this.results,[e.to,0].concat(s)),this.emit("move",s,e.from,e.to);break}}this.emit("changed",this.results)},Fn.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var sT=os,EN=ls.ACTIONS,xN=xr,lT=vi;function vi(n,t){if(sT.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={}}sT.mixin(vi),vi.prototype.submit=function(n,t){this.value=n,this.send(t)},vi.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},vi.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()})},vi.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},vi.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},vi.prototype._message=function(){return{a:EN.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},vi.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},vi.prototype._callbackOrEmit=function(n,t){if(t)return xN.nextTick(t,n);n&&this.emit("error",n)};var AN=xr,aT=W1;function W1(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}W1.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},W1.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&AN.nextTick(n)};var q1={exports:{}};(function(n,t){(function(e,r){r(t)})(Un,function(e){function r(y,L){L=L|0;for(var _=Math.max(y.length-L,0),N=Array(_),H=0;H<_;H++)N[H]=y[L+H];return N}var i=function(y){var L=r(arguments,1);return function(){var _=r(arguments);return y.apply(null,L.concat(_))}},o=function(y){return function(){var L=r(arguments),_=L.pop();y.call(this,L,_)}};function s(y){var L=typeof y;return y!=null&&(L=="object"||L=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function d(y){setTimeout(y,0)}function h(y){return function(L){var _=r(arguments,1);y(function(){L.apply(null,_)})}}var C;l?C=setImmediate:c?C=process.nextTick:C=d;var E=h(C);function x(y){return o(function(L,_){var N;try{N=y.apply(this,L)}catch(H){return _(H)}s(N)&&typeof N.then=="function"?N.then(function(H){v(_,null,H)},function(H){v(_,H.message?H:new Error(H))}):_(null,N)})}function v(y,L,_){try{y(L,_)}catch(N){E(R,N)}}function R(y){throw y}var w=typeof Symbol=="function";function U(y){return w&&y[Symbol.toStringTag]==="AsyncFunction"}function M(y){return U(y)?x(y):y}function F(y){return function(L){var _=r(arguments,1),N=o(function(H,$){var X=this;return y(L,function(Z,ut){M(Z).apply(X,H.concat(ut))},$)});return _.length?N.apply(this,_):N}}var G=typeof Un=="object"&&Un&&Un.Object===Object&&Un,q=typeof self=="object"&&self&&self.Object===Object&&self,it=G||q||Function("return this")(),st=it.Symbol,Et=Object.prototype,gt=Et.hasOwnProperty,xt=Et.toString,Vt=st?st.toStringTag:void 0;function Gt(y){var L=gt.call(y,Vt),_=y[Vt];try{y[Vt]=void 0;var N=!0}catch{}var H=xt.call(y);return N&&(L?y[Vt]=_:delete y[Vt]),H}var fn=Object.prototype,Be=fn.toString;function Vn(y){return Be.call(y)}var Ui="[object Null]",wn="[object Undefined]",An=st?st.toStringTag:void 0;function Oi(y){return y==null?y===void 0?wn:Ui:An&&An in Object(y)?Gt(y):Vn(y)}var Co="[object AsyncFunction]",Tr="[object Function]",qx="[object GeneratorFunction]",Xx="[object Proxy]";function Yx(y){if(!s(y))return!1;var L=Oi(y);return L==Tr||L==qx||L==Co||L==Xx}var ks=9007199254740991;function Sl(y){return typeof y=="number"&&y>-1&&y%1==0&&y<=ks}function Ll(y){return y!=null&&Sl(y.length)&&!Yx(y)}var Eo={};function jt(){}function Ni(y){return function(){if(y!==null){var L=y;y=null,L.apply(this,arguments)}}}var Rs=typeof Symbol=="function"&&Symbol.iterator,vc=function(y){return Rs&&y[Rs]&&y[Rs]()};function wm(y,L){for(var _=-1,N=Array(y);++_<y;)N[_]=L(_);return N}function bn(y){return y!=null&&typeof y=="object"}var Il="[object Arguments]";function Sm(y){return bn(y)&&Oi(y)==Il}var yr=Object.prototype,Lm=yr.hasOwnProperty,Qx=yr.propertyIsEnumerable,Dl=Sm(function(){return arguments}())?Sm:function(y){return bn(y)&&Lm.call(y,"callee")&&!Qx.call(y,"callee")},we=Array.isArray;function _l(){return!1}var Ml=typeof e=="object"&&e&&!e.nodeType&&e,Im=Ml&&!0&&n&&!n.nodeType&&n,Ul=Im&&Im.exports===Ml,Dm=Ul?it.Buffer:void 0,Ol=Dm?Dm.isBuffer:void 0,ws=Ol||_l,Hf=9007199254740991,jf=/^(?:0|[1-9]\d*)$/;function zf(y,L){var _=typeof y;return L=L==null?Hf:L,!!L&&(_=="number"||_!="symbol"&&jf.test(y))&&y>-1&&y%1==0&&y<L}var Gf="[object Arguments]",Wf="[object Array]",qf="[object Boolean]",Xf="[object Date]",Yf="[object Error]",Qf="[object Function]",Jx="[object Map]",Zx="[object Number]",tA="[object Object]",_m="[object RegExp]",Mm="[object Set]",eA="[object String]",nA="[object WeakMap]",rA="[object ArrayBuffer]",iA="[object DataView]",Um="[object Float32Array]",oA="[object Float64Array]",sA="[object Int8Array]",lA="[object Int16Array]",Jf="[object Int32Array]",aA="[object Uint8Array]",Zf="[object Uint8ClampedArray]",cA="[object Uint16Array]",uA="[object Uint32Array]",he={};he[Um]=he[oA]=he[sA]=he[lA]=he[Jf]=he[aA]=he[Zf]=he[cA]=he[uA]=!0,he[Gf]=he[Wf]=he[rA]=he[qf]=he[iA]=he[Xf]=he[Yf]=he[Qf]=he[Jx]=he[Zx]=he[tA]=he[_m]=he[Mm]=he[eA]=he[nA]=!1;function fA(y){return bn(y)&&Sl(y.length)&&!!he[Oi(y)]}function dA(y){return function(L){return y(L)}}var Om=typeof e=="object"&&e&&!e.nodeType&&e,Nl=Om&&!0&&n&&!n.nodeType&&n,hA=Nl&&Nl.exports===Om,Bc=hA&&G.process,Nm=function(){try{var y=Nl&&Nl.require&&Nl.require("util").types;return y||Bc&&Bc.binding&&Bc.binding("util")}catch{}}(),Pm=Nm&&Nm.isTypedArray,mA=Pm?dA(Pm):fA,gA=Object.prototype,pA=gA.hasOwnProperty;function CA(y,L){var _=we(y),N=!_&&Dl(y),H=!_&&!N&&ws(y),$=!_&&!N&&!H&&mA(y),X=_||N||H||$,Z=X?wm(y.length,String):[],ut=Z.length;for(var At in y)(L||pA.call(y,At))&&!(X&&(At=="length"||H&&(At=="offset"||At=="parent")||$&&(At=="buffer"||At=="byteLength"||At=="byteOffset")||zf(At,ut)))&&Z.push(At);return Z}var Tc=Object.prototype;function EA(y){var L=y&&y.constructor,_=typeof L=="function"&&L.prototype||Tc;return y===_}function yc(y,L){return function(_){return y(L(_))}}var xA=yc(Object.keys,Object),AA=Object.prototype,bA=AA.hasOwnProperty;function Fm(y){if(!EA(y))return xA(y);var L=[];for(var _ in Object(y))bA.call(y,_)&&_!="constructor"&&L.push(_);return L}function kc(y){return Ll(y)?CA(y):Fm(y)}function Km(y){var L=-1,_=y.length;return function(){return++L<_?{value:y[L],key:L}:null}}function vA(y){var L=-1;return function(){var N=y.next();return N.done?null:(L++,{value:N.value,key:L})}}function BA(y){var L=kc(y),_=-1,N=L.length;return function H(){var $=L[++_];return $==="__proto__"?H():_<N?{value:y[$],key:$}:null}}function TA(y){if(Ll(y))return Km(y);var L=vc(y);return L?vA(L):BA(y)}function kr(y){return function(){if(y===null)throw new Error("Callback was already called.");var L=y;y=null,L.apply(this,arguments)}}function Pl(y){return function(L,_,N){if(N=Ni(N||jt),y<=0||!L)return N(null);var H=TA(L),$=!1,X=0,Z=!1;function ut(ft,Bt){if(X-=1,ft)$=!0,N(ft);else{if(Bt===Eo||$&&X<=0)return $=!0,N(null);Z||At()}}function At(){for(Z=!0;X<y&&!$;){var ft=H();if(ft===null){$=!0,X<=0&&N(null);return}X+=1,_(ft.value,ft.key,kr(ut))}Z=!1}At()}}function Pi(y,L,_,N){Pl(L)(y,M(_),N)}function Ge(y,L){return function(_,N,H){return y(_,L,N,H)}}function td(y,L,_){_=Ni(_||jt);var N=0,H=0,$=y.length;$===0&&_(null);function X(Z,ut){Z?_(Z):(++H===$||ut===Eo)&&_(null)}for(;N<$;N++)L(y[N],N,kr(X))}var yA=Ge(Pi,1/0),ri=function(y,L,_){var N=Ll(y)?td:yA;N(y,M(L),_)};function ii(y){return function(L,_,N){return y(ri,L,M(_),N)}}function ed(y,L,_,N){N=N||jt,L=L||[];var H=[],$=0,X=M(_);y(L,function(Z,ut,At){var ft=$++;X(Z,function(Bt,te){H[ft]=te,At(Bt)})},function(Z){N(Z,H)})}var Rc=ii(ed),nd=F(Rc);function xo(y){return function(L,_,N,H){return y(Pl(_),L,M(N),H)}}var Fi=xo(ed),rd=Ge(Fi,1),id=F(rd);function Ss(y,L){for(var _=-1,N=y==null?0:y.length;++_<N&&L(y[_],_,y)!==!1;);return y}function od(y){return function(L,_,N){for(var H=-1,$=Object(L),X=N(L),Z=X.length;Z--;){var ut=X[y?Z:++H];if(_($[ut],ut,$)===!1)break}return L}}var Ls=od();function Is(y,L){return y&&Ls(y,L,kc)}function Vm(y,L,_,N){for(var H=y.length,$=_+(N?1:-1);N?$--:++$<H;)if(L(y[$],$,y))return $;return-1}function kA(y){return y!==y}function $m(y,L,_){for(var N=_-1,H=y.length;++N<H;)if(y[N]===L)return N;return-1}function Fl(y,L,_){return L===L?$m(y,L,_):Vm(y,kA,_)}var wc=function(y,L,_){typeof L=="function"&&(_=L,L=null),_=Ni(_||jt);var N=kc(y),H=N.length;if(!H)return _(null);L||(L=H);var $={},X=0,Z=!1,ut=Object.create(null),At=[],ft=[],Bt={};Is(y,function(Ce,ue){if(!we(Ce)){te(ue,[Ce]),ft.push(ue);return}var Te=Ce.slice(0,Ce.length-1),wr=Te.length;if(wr===0){te(ue,Ce),ft.push(ue);return}Bt[ue]=wr,Ss(Te,function(k){if(!y[k])throw new Error("async.auto task `"+ue+"` has a non-existent dependency `"+k+"` in "+Te.join(", "));dn(k,function(){wr--,wr===0&&te(ue,Ce)})})}),qA(),Pe();function te(Ce,ue){At.push(function(){Rr(Ce,ue)})}function Pe(){if(At.length===0&&X===0)return _(null,$);for(;At.length&&X<L;){var Ce=At.shift();Ce()}}function dn(Ce,ue){var Te=ut[Ce];Te||(Te=ut[Ce]=[]),Te.push(ue)}function jn(Ce){var ue=ut[Ce]||[];Ss(ue,function(Te){Te()}),Pe()}function Rr(Ce,ue){if(!Z){var Te=kr(function(k,$i){if(X--,arguments.length>2&&($i=r(arguments,1)),k){var Us={};Is($,function(zn,$t){Us[$t]=zn}),Us[Ce]=$i,Z=!0,ut=Object.create(null),_(k,Us)}else $[Ce]=$i,jn(Ce)});X++;var wr=M(ue[ue.length-1]);ue.length>1?wr($,Te):wr(Te)}}function qA(){for(var Ce,ue=0;ft.length;)Ce=ft.pop(),ue++,Ss(XA(Ce),function(Te){--Bt[Te]===0&&ft.push(Te)});if(ue!==H)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function XA(Ce){var ue=[];return Is(y,function(Te,wr){we(Te)&&Fl(Te,Ce,0)>=0&&ue.push(wr)}),ue}};function Ao(y,L){for(var _=-1,N=y==null?0:y.length,H=Array(N);++_<N;)H[_]=L(y[_],_,y);return H}var RA="[object Symbol]";function wA(y){return typeof y=="symbol"||bn(y)&&Oi(y)==RA}var SA=1/0,sd=st?st.prototype:void 0,Hm=sd?sd.toString:void 0;function ld(y){if(typeof y=="string")return y;if(we(y))return Ao(y,ld)+"";if(wA(y))return Hm?Hm.call(y):"";var L=y+"";return L=="0"&&1/y==-SA?"-0":L}function LA(y,L,_){var N=-1,H=y.length;L<0&&(L=-L>H?0:H+L),_=_>H?H:_,_<0&&(_+=H),H=L>_?0:_-L>>>0,L>>>=0;for(var $=Array(H);++N<H;)$[N]=y[N+L];return $}function IA(y,L,_){var N=y.length;return _=_===void 0?N:_,!L&&_>=N?y:LA(y,L,_)}function ad(y,L){for(var _=y.length;_--&&Fl(L,y[_],0)>-1;);return _}function DA(y,L){for(var _=-1,N=y.length;++_<N&&Fl(L,y[_],0)>-1;);return _}function _A(y){return y.split("")}var MA="\\ud800-\\udfff",UA="\\u0300-\\u036f",OA="\\ufe20-\\ufe2f",me="\\u20d0-\\u20ff",ce=UA+OA+me,NA="\\ufe0e\\ufe0f",PA="\\u200d",FA=RegExp("["+PA+MA+ce+NA+"]");function KA(y){return FA.test(y)}var jm="\\ud800-\\udfff",VA="\\u0300-\\u036f",zm="\\ufe20-\\ufe2f",$A="\\u20d0-\\u20ff",en=VA+zm+$A,cd="\\ufe0e\\ufe0f",bo="["+jm+"]",Sc="["+en+"]",Kl="\\ud83c[\\udffb-\\udfff]",$n="(?:"+Sc+"|"+Kl+")",ud="[^"+jm+"]",fd="(?:\\ud83c[\\udde6-\\uddff]){2}",dd="[\\ud800-\\udbff][\\udc00-\\udfff]",Gm="\\u200d",hd=$n+"?",md="["+cd+"]?",Sn="(?:"+Gm+"(?:"+[ud,fd,dd].join("|")+")"+md+hd+")*",HA=md+hd+Sn,Hn="(?:"+[ud+Sc+"?",Sc,fd,dd,bo].join("|")+")",jA=RegExp(Kl+"(?="+Kl+")|"+Hn+HA,"g");function Wm(y){return y.match(jA)||[]}function oi(y){return KA(y)?Wm(y):_A(y)}function Lc(y){return y==null?"":ld(y)}var gd=/^\s+|\s+$/g;function pe(y,L,_){if(y=Lc(y),y&&(_||L===void 0))return y.replace(gd,"");if(!y||!(L=ld(L)))return y;var N=oi(y),H=oi(L),$=DA(N,H),X=ad(N,H)+1;return IA(N,$,X).join("")}var Ki=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,pd=/,/,zA=/(=.+)?(\s*)$/,Cd=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function GA(y){return y=y.toString().replace(Cd,""),y=y.match(Ki)[2].replace(" ",""),y=y?y.split(pd):[],y=y.map(function(L){return pe(L.replace(zA,""))}),y}function qm(y,L){var _={};Is(y,function(N,H){var $,X=U(N),Z=!X&&N.length===1||X&&N.length===0;if(we(N))$=N.slice(0,-1),N=N[N.length-1],_[H]=$.concat($.length>0?ut:N);else if(Z)_[H]=N;else{if($=GA(N),N.length===0&&!X&&$.length===0)throw new Error("autoInject task functions require explicit parameters.");X||$.pop(),_[H]=$.concat(ut)}function ut(At,ft){var Bt=Ao($,function(te){return At[te]});Bt.push(ft),M(N).apply(null,Bt)}}),wc(_,L)}function or(){this.head=this.tail=null,this.length=0}function Ed(y,L){y.length=1,y.head=y.tail=L}or.prototype.removeLink=function(y){return y.prev?y.prev.next=y.next:this.head=y.next,y.next?y.next.prev=y.prev:this.tail=y.prev,y.prev=y.next=null,this.length-=1,y},or.prototype.empty=function(){for(;this.head;)this.shift();return this},or.prototype.insertAfter=function(y,L){L.prev=y,L.next=y.next,y.next?y.next.prev=L:this.tail=L,y.next=L,this.length+=1},or.prototype.insertBefore=function(y,L){L.prev=y.prev,L.next=y,y.prev?y.prev.next=L:this.head=L,y.prev=L,this.length+=1},or.prototype.unshift=function(y){this.head?this.insertBefore(this.head,y):Ed(this,y)},or.prototype.push=function(y){this.tail?this.insertAfter(this.tail,y):Ed(this,y)},or.prototype.shift=function(){return this.head&&this.removeLink(this.head)},or.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},or.prototype.toArray=function(){for(var y=Array(this.length),L=this.head,_=0;_<this.length;_++)y[_]=L.data,L=L.next;return y},or.prototype.remove=function(y){for(var L=this.head;L;){var _=L.next;y(L)&&this.removeLink(L),L=_}return this};function Vl(y,L,_){if(L==null)L=1;else if(L===0)throw new Error("Concurrency must not be zero");var N=M(y),H=0,$=[],X=!1;function Z(Bt,te,Pe){if(Pe!=null&&typeof Pe!="function")throw new Error("task callback must be a function");if(ft.started=!0,we(Bt)||(Bt=[Bt]),Bt.length===0&&ft.idle())return E(function(){ft.drain()});for(var dn=0,jn=Bt.length;dn<jn;dn++){var Rr={data:Bt[dn],callback:Pe||jt};te?ft._tasks.unshift(Rr):ft._tasks.push(Rr)}X||(X=!0,E(function(){X=!1,ft.process()}))}function ut(Bt){return function(te){H-=1;for(var Pe=0,dn=Bt.length;Pe<dn;Pe++){var jn=Bt[Pe],Rr=Fl($,jn,0);Rr===0?$.shift():Rr>0&&$.splice(Rr,1),jn.callback.apply(jn,arguments),te!=null&&ft.error(te,jn.data)}H<=ft.concurrency-ft.buffer&&ft.unsaturated(),ft.idle()&&ft.drain(),ft.process()}}var At=!1,ft={_tasks:new or,concurrency:L,payload:_,saturated:jt,unsaturated:jt,buffer:L/4,empty:jt,drain:jt,error:jt,started:!1,paused:!1,push:function(Bt,te){Z(Bt,!1,te)},kill:function(){ft.drain=jt,ft._tasks.empty()},unshift:function(Bt,te){Z(Bt,!0,te)},remove:function(Bt){ft._tasks.remove(Bt)},process:function(){if(!At){for(At=!0;!ft.paused&&H<ft.concurrency&&ft._tasks.length;){var Bt=[],te=[],Pe=ft._tasks.length;ft.payload&&(Pe=Math.min(Pe,ft.payload));for(var dn=0;dn<Pe;dn++){var jn=ft._tasks.shift();Bt.push(jn),$.push(jn),te.push(jn.data)}H+=1,ft._tasks.length===0&&ft.empty(),H===ft.concurrency&&ft.saturated();var Rr=kr(ut(Bt));N(te,Rr)}At=!1}},length:function(){return ft._tasks.length},running:function(){return H},workersList:function(){return $},idle:function(){return ft._tasks.length+H===0},pause:function(){ft.paused=!0},resume:function(){ft.paused!==!1&&(ft.paused=!1,E(ft.process))}};return ft}function vo(y,L){return Vl(y,1,L)}var Ds=Ge(Pi,1);function si(y,L,_,N){N=Ni(N||jt);var H=M(_);Ds(y,function($,X,Z){H(L,$,function(ut,At){L=At,Z(ut)})},function($){N($,L)})}function Ic(){var y=Ao(arguments,M);return function(){var L=r(arguments),_=this,N=L[L.length-1];typeof N=="function"?L.pop():N=jt,si(y,L,function(H,$,X){$.apply(_,H.concat(function(Z){var ut=r(arguments,1);X(Z,ut)}))},function(H,$){N.apply(_,[H].concat($))})}}var Dc=function(){return Ic.apply(null,r(arguments).reverse())},xd=Array.prototype.concat,$l=function(y,L,_,N){N=N||jt;var H=M(_);Fi(y,L,function($,X){H($,function(Z){return Z?X(Z):X(null,r(arguments,1))})},function($,X){for(var Z=[],ut=0;ut<X.length;ut++)X[ut]&&(Z=xd.apply(Z,X[ut]));return N($,Z)})},Xm=Ge($l,1/0),_c=Ge($l,1),Mc=function(){var y=r(arguments),L=[null].concat(y);return function(){var _=arguments[arguments.length-1];return _.apply(this,L)}};function Hl(y){return y}function Bo(y,L){return function(_,N,H,$){$=$||jt;var X=!1,Z;_(N,function(ut,At,ft){H(ut,function(Bt,te){Bt?ft(Bt):y(te)&&!Z?(X=!0,Z=L(!0,ut),ft(null,Eo)):ft()})},function(ut){ut?$(ut):$(null,X?Z:L(!1))})}}function vn(y,L){return L}var _s=ii(Bo(Hl,vn)),li=xo(Bo(Hl,vn)),jl=Ge(li,1);function Ad(y){return function(L){var _=r(arguments,1);_.push(function(N){var H=r(arguments,1);typeof console=="object"&&(N?console.error&&console.error(N):console[y]&&Ss(H,function($){console[y]($)}))}),M(L).apply(null,_)}}var Ym=Ad("dir");function Qm(y,L,_){_=kr(_||jt);var N=M(y),H=M(L);function $(Z){if(Z)return _(Z);var ut=r(arguments,1);ut.push(X),H.apply(this,ut)}function X(Z,ut){if(Z)return _(Z);if(!ut)return _(null);N($)}X(null,!0)}function bd(y,L,_){_=kr(_||jt);var N=M(y),H=function($){if($)return _($);var X=r(arguments,1);if(L.apply(this,X))return N(H);_.apply(null,[null].concat(X))};N(H)}function Jm(y,L,_){bd(y,function(){return!L.apply(this,arguments)},_)}function Zm(y,L,_){_=kr(_||jt);var N=M(L),H=M(y);function $(Z){if(Z)return _(Z);H(X)}function X(Z,ut){if(Z)return _(Z);if(!ut)return _(null);N($)}H(X)}function To(y){return function(L,_,N){return y(L,N)}}function Uc(y,L,_){ri(y,To(M(L)),_)}function zl(y,L,_,N){Pl(L)(y,To(M(_)),N)}var yo=Ge(zl,1);function Oc(y){return U(y)?y:o(function(L,_){var N=!0;L.push(function(){var H=arguments;N?E(function(){_.apply(null,H)}):_.apply(null,H)}),y.apply(this,L),N=!1})}function sr(y){return!y}var ko=ii(Bo(sr,sr)),Gl=xo(Bo(sr,sr)),Nc=Ge(Gl,1);function tg(y){return function(L){return L==null?void 0:L[y]}}function Ms(y,L,_,N){var H=new Array(L.length);y(L,function($,X,Z){_($,function(ut,At){H[X]=!!At,Z(ut)})},function($){if($)return N($);for(var X=[],Z=0;Z<L.length;Z++)H[Z]&&X.push(L[Z]);N(null,X)})}function lr(y,L,_,N){var H=[];y(L,function($,X,Z){_($,function(ut,At){ut?Z(ut):(At&&H.push({index:X,value:$}),Z())})},function($){$?N($):N(null,Ao(H.sort(function(X,Z){return X.index-Z.index}),tg("value")))})}function Pc(y,L,_,N){var H=Ll(L)?Ms:lr;H(y,L,M(_),N||jt)}var Fc=ii(Pc),Wl=xo(Pc),Kc=Ge(Wl,1);function eg(y,L){var _=kr(L||jt),N=M(Oc(y));function H($){if($)return _($);N(H)}H()}var Vc=function(y,L,_,N){N=N||jt;var H=M(_);Fi(y,L,function($,X){H($,function(Z,ut){return Z?X(Z):X(null,{key:ut,val:$})})},function($,X){for(var Z={},ut=Object.prototype.hasOwnProperty,At=0;At<X.length;At++)if(X[At]){var ft=X[At].key,Bt=X[At].val;ut.call(Z,ft)?Z[ft].push(Bt):Z[ft]=[Bt]}return N($,Z)})},Ro=Ge(Vc,1/0),K=Ge(Vc,1),W=Ad("log");function j(y,L,_,N){N=Ni(N||jt);var H={},$=M(_);Pi(y,L,function(X,Z,ut){$(X,Z,function(At,ft){if(At)return ut(At);H[Z]=ft,ut()})},function(X){N(X,H)})}var pt=Ge(j,1/0),St=Ge(j,1);function Xt(y,L){return L in y}function De(y,L){var _=Object.create(null),N=Object.create(null);L=L||Hl;var H=M(y),$=o(function(Z,ut){var At=L.apply(null,Z);Xt(_,At)?E(function(){ut.apply(null,_[At])}):Xt(N,At)?N[At].push(ut):(N[At]=[ut],H.apply(null,Z.concat(function(){var ft=r(arguments);_[At]=ft;var Bt=N[At];delete N[At];for(var te=0,Pe=Bt.length;te<Pe;te++)Bt[te].apply(null,ft)})))});return $.memo=_,$.unmemoized=y,$}var Zt;c?Zt=process.nextTick:l?Zt=setImmediate:Zt=d;var $c=h(Zt);function vd(y,L,_){_=_||jt;var N=Ll(L)?[]:{};y(L,function(H,$,X){M(H)(function(Z,ut){arguments.length>2&&(ut=r(arguments,1)),N[$]=ut,X(Z)})},function(H){_(H,N)})}function Ln(y,L){vd(ri,y,L)}function ql(y,L,_){vd(Pl(L),y,_)}var Bd=function(y,L){var _=M(y);return Vl(function(N,H){_(N[0],H)},L,1)},wo=function(y,L){var _=Bd(y,L);return _.push=function(N,H,$){if($==null&&($=jt),typeof $!="function")throw new Error("task callback must be a function");if(_.started=!0,we(N)||(N=[N]),N.length===0)return E(function(){_.drain()});H=H||0;for(var X=_._tasks.head;X&&H>=X.priority;)X=X.next;for(var Z=0,ut=N.length;Z<ut;Z++){var At={data:N[Z],priority:H,callback:$};X?_._tasks.insertBefore(X,At):_._tasks.push(At)}E(_.process)},delete _.unshift,_};function Xl(y,L){if(L=Ni(L||jt),!we(y))return L(new TypeError("First argument to race must be an array of functions"));if(!y.length)return L();for(var _=0,N=y.length;_<N;_++)M(y[_])(L)}function So(y,L,_,N){var H=r(y).reverse();si(H,L,_,N)}function Yt(y){var L=M(y);return o(function(N,H){return N.push(function(X,Z){if(X)H(null,{error:X});else{var ut;arguments.length<=2?ut=Z:ut=r(arguments,1),H(null,{value:ut})}}),L.apply(this,N)})}function ng(y){var L;return we(y)?L=Ao(y,Yt):(L={},Is(y,function(_,N){L[N]=Yt.call(this,_)})),L}function Td(y,L,_,N){Pc(y,L,function(H,$){_(H,function(X,Z){$(X,!Z)})},N)}var Yl=ii(Td),yd=xo(Td),rg=Ge(yd,1);function ig(y){return function(){return y}}function Lo(y,L,_){var N=5,H=0,$={times:N,intervalFunc:ig(H)};function X(ft,Bt){if(typeof Bt=="object")ft.times=+Bt.times||N,ft.intervalFunc=typeof Bt.interval=="function"?Bt.interval:ig(+Bt.interval||H),ft.errorFilter=Bt.errorFilter;else if(typeof Bt=="number"||typeof Bt=="string")ft.times=+Bt||N;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof y=="function"?(_=L||jt,L=y):(X($,y),_=_||jt),typeof L!="function")throw new Error("Invalid arguments for async.retry");var Z=M(L),ut=1;function At(){Z(function(ft){ft&&ut++<$.times&&(typeof $.errorFilter!="function"||$.errorFilter(ft))?setTimeout(At,$.intervalFunc(ut)):_.apply(null,arguments)})}At()}var ai=function(y,L){L||(L=y,y=null);var _=M(L);return o(function(N,H){function $(X){_.apply(null,N.concat(X))}y?Lo(y,$,H):Lo($,H)})};function Ql(y,L){vd(Ds,y,L)}var Jl=ii(Bo(Boolean,Hl)),Vi=xo(Bo(Boolean,Hl)),Zl=Ge(Vi,1);function kd(y,L,_){var N=M(L);Rc(y,function($,X){N($,function(Z,ut){if(Z)return X(Z);X(null,{value:$,criteria:ut})})},function($,X){if($)return _($);_(null,Ao(X.sort(H),tg("value")))});function H($,X){var Z=$.criteria,ut=X.criteria;return Z<ut?-1:Z>ut?1:0}}function ta(y,L,_){var N=M(y);return o(function(H,$){var X=!1,Z;function ut(){var At=y.name||"anonymous",ft=new Error('Callback function "'+At+'" timed out.');ft.code="ETIMEDOUT",_&&(ft.info=_),X=!0,$(ft)}H.push(function(){X||($.apply(null,arguments),clearTimeout(Z))}),Z=setTimeout(ut,L),N.apply(null,H)})}var og=Math.ceil,ea=Math.max;function Io(y,L,_,N){for(var H=-1,$=ea(og((L-y)/(_||1)),0),X=Array($);$--;)X[N?$:++H]=y,y+=_;return X}function Do(y,L,_,N){var H=M(_);Fi(Io(0,y,1),L,H,N)}var sg=Ge(Do,1/0),lg=Ge(Do,1);function ag(y,L,_,N){arguments.length<=3&&(N=_,_=L,L=we(y)?[]:{}),N=Ni(N||jt);var H=M(_);ri(y,function($,X,Z){H(L,$,X,Z)},function($){N($,L)})}function na(y,L){var _=null,N;L=L||jt,yo(y,function(H,$){M(H)(function(X,Z){arguments.length>2?N=r(arguments,1):N=Z,_=X,$(!X)})},function(){L(_,N)})}function ra(y){return function(){return(y.unmemoized||y).apply(null,arguments)}}function ia(y,L,_){_=kr(_||jt);var N=M(L);if(!y())return _(null);var H=function($){if($)return _($);if(y())return N(H);var X=r(arguments,1);_.apply(null,[null].concat(X))};N(H)}function cg(y,L,_){ia(function(){return!y.apply(this,arguments)},L,_)}var Rd=function(y,L){if(L=Ni(L||jt),!we(y))return L(new Error("First argument to waterfall must be an array of functions"));if(!y.length)return L();var _=0;function N($){var X=M(y[_++]);$.push(kr(H)),X.apply(null,$)}function H($){if($||_===y.length)return L.apply(null,arguments);N(r(arguments,1))}N([])},WA={apply:i,applyEach:nd,applyEachSeries:id,asyncify:x,auto:wc,autoInject:qm,cargo:vo,compose:Dc,concat:Xm,concatLimit:$l,concatSeries:_c,constant:Mc,detect:_s,detectLimit:li,detectSeries:jl,dir:Ym,doDuring:Qm,doUntil:Jm,doWhilst:bd,during:Zm,each:Uc,eachLimit:zl,eachOf:ri,eachOfLimit:Pi,eachOfSeries:Ds,eachSeries:yo,ensureAsync:Oc,every:ko,everyLimit:Gl,everySeries:Nc,filter:Fc,filterLimit:Wl,filterSeries:Kc,forever:eg,groupBy:Ro,groupByLimit:Vc,groupBySeries:K,log:W,map:Rc,mapLimit:Fi,mapSeries:rd,mapValues:pt,mapValuesLimit:j,mapValuesSeries:St,memoize:De,nextTick:$c,parallel:Ln,parallelLimit:ql,priorityQueue:wo,queue:Bd,race:Xl,reduce:si,reduceRight:So,reflect:Yt,reflectAll:ng,reject:Yl,rejectLimit:yd,rejectSeries:rg,retry:Lo,retryable:ai,seq:Ic,series:Ql,setImmediate:E,some:Jl,someLimit:Vi,someSeries:Zl,sortBy:kd,timeout:ta,times:sg,timesLimit:Do,timesSeries:lg,transform:ag,tryEach:na,unmemoize:ra,until:cg,waterfall:Rd,whilst:ia,all:ko,allLimit:Gl,allSeries:Nc,any:Jl,anyLimit:Vi,anySeries:Zl,find:_s,findLimit:li,findSeries:jl,forEach:Uc,forEachSeries:yo,forEachLimit:zl,forEachOf:ri,forEachOfSeries:Ds,forEachOfLimit:Pi,inject:si,foldl:si,foldr:So,select:Fc,selectLimit:Wl,selectSeries:Kc,wrapSync:x};e.default=WA,e.apply=i,e.applyEach=nd,e.applyEachSeries=id,e.asyncify=x,e.auto=wc,e.autoInject=qm,e.cargo=vo,e.compose=Dc,e.concat=Xm,e.concatLimit=$l,e.concatSeries=_c,e.constant=Mc,e.detect=_s,e.detectLimit=li,e.detectSeries=jl,e.dir=Ym,e.doDuring=Qm,e.doUntil=Jm,e.doWhilst=bd,e.during=Zm,e.each=Uc,e.eachLimit=zl,e.eachOf=ri,e.eachOfLimit=Pi,e.eachOfSeries=Ds,e.eachSeries=yo,e.ensureAsync=Oc,e.every=ko,e.everyLimit=Gl,e.everySeries=Nc,e.filter=Fc,e.filterLimit=Wl,e.filterSeries=Kc,e.forever=eg,e.groupBy=Ro,e.groupByLimit=Vc,e.groupBySeries=K,e.log=W,e.map=Rc,e.mapLimit=Fi,e.mapSeries=rd,e.mapValues=pt,e.mapValuesLimit=j,e.mapValuesSeries=St,e.memoize=De,e.nextTick=$c,e.parallel=Ln,e.parallelLimit=ql,e.priorityQueue=wo,e.queue=Bd,e.race=Xl,e.reduce=si,e.reduceRight=So,e.reflect=Yt,e.reflectAll=ng,e.reject=Yl,e.rejectLimit=yd,e.rejectSeries=rg,e.retry=Lo,e.retryable=ai,e.seq=Ic,e.series=Ql,e.setImmediate=E,e.some=Jl,e.someLimit=Vi,e.someSeries=Zl,e.sortBy=kd,e.timeout=ta,e.times=sg,e.timesLimit=Do,e.timesSeries=lg,e.transform=ag,e.tryEach=na,e.unmemoize=ra,e.until=cg,e.waterfall=Rd,e.whilst=ia,e.all=ko,e.allLimit=Gl,e.allSeries=Nc,e.any=Jl,e.anyLimit=Vi,e.anySeries=Zl,e.find=_s,e.findLimit=li,e.findSeries=jl,e.forEach=Uc,e.forEachSeries=yo,e.forEachLimit=zl,e.forEachOf=ri,e.forEachOfSeries=Ds,e.forEachOfLimit=Pi,e.inject=si,e.foldl=si,e.foldr=So,e.select=Fc,e.selectLimit=Wl,e.selectSeries=Kc,e.wrapSync=x,Object.defineProperty(e,"__esModule",{value:!0})})})(q1,q1.exports);var cT={exports:{}},X1=cT.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),r=2;e===1/0;r*=2)e=Math.log(Math.pow(2,n/r))/Math.log(t)*r;for(var i=e-Math.floor(e),o="",r=0;r<Math.floor(e);r++){var s=Math.floor(Math.random()*t).toString(t);o=s+o}if(i){var l=Math.pow(t,i),s=Math.floor(Math.random()*l).toString(t);o=s+o}var c=parseInt(o,t);return c!==1/0&&c>=Math.pow(2,n)?X1(n,t):o};X1.rack=function(n,t,e){var r=function(o){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=X1(n,t)}while(Object.hasOwnProperty.call(i,l));return i[l]=o,l},i=r.hats={};return r.get=function(o){return r.hats[o]},r.set=function(o,s){return r.hats[o]=s,r},r.bits=n||128,r.base=t||16,r};var uT=os,bN=lT,vN=aT,t0=xr,Y1=q1.exports,BN=cT.exports,fT=ls.ACTIONS,dT=$e;function $e(n,t){if(uT.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}uT.mixin($e),$e.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},$e.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},$e.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||BN();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},$e.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(r){if(r)return t._callbackOrEmit(r,n);var i=Object.keys(t._remotePresenceInstances);Y1.parallel([function(o){Y1.each(e,function(s,l){t.localPresences[s].destroy(l)},o)},function(o){if(!t._wantsDestroy)return o();Y1.each(i,function(s,l){t._remotePresenceInstances[s].destroy(l)},o)}],function(o){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(o,n)})})},$e.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?fT.presenceSubscribe:fT.presenceUnsubscribe,r=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[r]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,r,this)},$e.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},$e.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},$e.prototype._receiveUpdate=function(n,t){var e=t0.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var r=this,i=t0.digOrCreate(this._remotePresenceInstances,t.id,function(){return r._createRemotePresence(t.id)});i.receiveUpdate(t)},$e.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},$e.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()}},$e.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},$e.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},$e.prototype._resubscribe=function(){var n=[];for(var t in this._subscriptionCallbacksBySeq){var e=this._subscriptionCallback(t);n.push(e)}if(!this.wantSubscribe)return this._callEachOrEmit(n);var r=this;this.subscribe(function(i){r._callEachOrEmit(n,i)})},$e.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},$e.prototype._callbackOrEmit=function(n,t){if(t)return t0.nextTick(t,n);n&&this.emit("error",n)},$e.prototype._createLocalPresence=function(n){return new bN(this,n)},$e.prototype._createRemotePresence=function(n){return new vN(this,n)},$e.prototype._callEachOrEmit=function(n,t){var e=t0.callEach(n,t);!e&&t&&this.emit("error",t)};var Ku=lT,hT=Yh,TN=xr,mT=hT.CODES,yN=Wr;function Wr(n,t){Ku.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._isSending=!1,this._docDataVersionByPresenceVersion={},this._opHandler=this._transformAgainstOp.bind(this),this._createOrDelHandler=this._handleCreateOrDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._destroyHandler=this.destroy.bind(this),this._registerWithDoc()}Wr.prototype=Object.create(Ku.prototype),Wr.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:mT.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,Ku.prototype.submit.call(this,n,t)},Wr.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),this._emitter.removeEventListener(this._doc,"destroy",this._destroyHandler),Ku.prototype.destroy.call(this,n)},Wr.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={})})}},Wr.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler),this._emitter.addEventListener(this._doc,"destroy",this._destroyHandler)},Wr.prototype._transformAgainstOp=function(n,t){var e=this,r=this._doc._dataStateVersion;this._pendingMessages.forEach(function(i){var o=e._docDataVersionByPresenceVersion[i.pv];if(!(o>=r))try{i.p=e._transformPresence(i.p,n,t),e._docDataVersionByPresenceVersion[i.pv]=r}catch(l){var s=e._getCallback(i.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(i){this.emit("error",i)}},Wr.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},Wr.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},Wr.prototype._message=function(){var n=Ku.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},Wr.prototype._transformPresence=function(n,t,e){var r=this._doc.type;if(!TN.supportsPresence(r))throw new hT(mT.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+r.name);return r.transformPresence(n,t,e)};var gT={};(function(n){var t=Ou,e=Yh,r=xr,i=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var c=l.create.type;if(typeof c!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[c];if(d==null||typeof d!="object")return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(i.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(i.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(i.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,c){if(typeof l!="object")return new e(i.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&c.v!=null&&l.v!==c.v)return new e(i.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(c.create){if(l.type)return new e(i.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=c.create,h=t.map[d.type];if(!h)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(E){return E}}else if(c.del)l.data=void 0,l.type=null,l.v++;else if("op"in c){var C=o(l,c.op);if(C)return C;l.v++}else l.v++};function o(l,c){if(!l.type)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(c===void 0)return new e(i.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,c)}catch(h){return new e(i.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,c,d){if(c.v!=null&&c.v!==d.v)return new e(i.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(c.create||"op"in c)return new e(i.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in c||c.create||c.del)||"op"in d&&c.create)return new e(i.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in c){if(!l)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{c.op=l.transform(c.op,d.op,"left")}catch(h){return h}}}c.v!=null&&c.v++},n.applyOps=function(l,c,d){d=d||{};for(var h=0;h<c.length;h++){var C=c[h];if(d._normalizeLegacyJson0Ops)try{s(l,C)}catch{return new e(i.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=C.v;var E=n.apply(l,C);if(E)return E}},n.transformPresence=function(l,c,d){var h=this.checkOp(c);if(h)return h;var C=l.t;if(typeof C=="string"&&(C=t.map[C]),!C)return{code:i.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!r.supportsPresence(C))return{code:i.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(c.create||c.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:C.transformPresence(l.p,c.op,d)}catch(E){return{code:i.ERR_PRESENCE_TRANSFORM_FAILED,message:E.message||E}}l.v++};function s(l,c){if(l.type===t.defaultType.uri){var d=c.op;if(!!d){var h=l.data;d.length>1&&(h=r.clone(h));for(var C=0;C<d.length;C++){var E=d[C];typeof E.lm=="string"&&(E.lm=+E.lm);for(var x=E.p,v=h,R=0;R<x.length;R++){var w=x[R];Object.prototype.toString.call(v)=="[object Array]"?x[R]=+w:v.constructor===Object&&(x[R]=w.toString()),v=v[w]}C<d.length-1&&(h=t.defaultType.apply(h,[E]))}}}}})(gT);var Vu=aT,kN=gT,RN=Ar;function Ar(n,t){Vu.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this.src=null,this.presenceVersion=null,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._pending=null,this._opCache=null,this._pendingSetPending=!1,this._opHandler=this._handleOp.bind(this),this._createDelHandler=this._handleCreateDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._registerWithDoc()}Ar.prototype=Object.create(Vu.prototype),Ar.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},Ar.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),Vu.prototype.destroy.call(this,n)},Ar.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createDelHandler),this._emitter.addEventListener(this._doc,"del",this._createDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler)},Ar.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))}})}},Ar.prototype._handleOp=function(n,t,e){var r=e===this.src;this._transformAgainstOp(n,r),this._cacheOp(n,r),this._setPendingPresence()},Vu.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},Vu.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},Ar.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)}},Ar.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++):kN.transformPresence(this._pending,t,e)}var r=this._pending.v>=this._doc.version;return r&&this._stopCachingOps(),r},Ar.prototype._startCachingOps=function(){this._opCache=[]},Ar.prototype._stopCachingOps=function(){this._opCache=null},Ar.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var pT=dT,wN=yN,SN=RN;function Pa(n,t,e){var r=Pa.channel(t,e);pT.call(this,n,r),this.collection=t,this.id=e}var LN=Pa;Pa.prototype=Object.create(pT.prototype),Pa.channel=function(n,t){return n+"."+t},Pa.prototype._createLocalPresence=function(n){return new wN(this,n)},Pa.prototype._createRemotePresence=function(n){return new SN(this,n)};var IN=DN;function DN(n,t,e,r,i){this.id=n,this.v=t,this.type=e,this.data=r,this.m=i}var _N=IN,CT=os,ET=$u;function $u(n,t,e,r,i){if(CT.EventEmitter.call(this),typeof i!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=r,this.collection=e,this.callback=i,this.sent=!1}CT.mixin($u),$u.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},$u.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},$u.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,r=new _N(this.id,t.v,t.type,t.data,e);this.callback(null,r)};var xT=ET,MN=xr,UN=ls.ACTIONS,ON=Q1;function Q1(n,t,e,r,i,o){if(xT.call(this,n,t,e,r,o),!MN.isValidVersion(i))throw new Error("Snapshot version must be a positive integer or null");this.version=i}Q1.prototype=Object.create(xT.prototype),Q1.prototype._message=function(){return{a:UN.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var AT=ET,NN=xr,PN=ls.ACTIONS,FN=J1;function J1(n,t,e,r,i,o){if(AT.call(this,n,t,e,r,o),!NN.isValidTimestamp(i))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=i}J1.prototype=Object.create(AT.prototype),J1.prototype._message=function(){return{a:PN.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var Bi=xr,KN=Og.default.EventEmitter,VN=["create","del","destroy","load","op"],$N=Hu;function Hu(){this._docs={},this._forwarders={},this._emitters={}}Hu.prototype.addEventListener=function(n,t,e){this._registerDoc(n);var r=Bi.dig(this._emitters,n.collection,n.id);r.on(t,e)},Hu.prototype.removeEventListener=function(n,t,e){var r=Bi.dig(this._emitters,n.collection,n.id);!r||(r.off(t,e),r._eventsCount===1&&this._unregisterDoc(n))},Hu.prototype._registerDoc=function(n){var t=!0;if(Bi.digOrCreate(this._docs,n.collection,n.id,function(){return t=!1,n}),!t){var e=Bi.digOrCreate(this._emitters,n.collection,n.id,function(){var i=new KN;return i.setMaxListeners(1e3),i}),r=this;VN.forEach(function(i){var o=Bi.digOrCreate(r._forwarders,n.collection,n.id,i,function(){return e.emit.bind(e,i)});n.on(i,o)}),this.addEventListener(n,"destroy",this._unregisterDoc.bind(this,n))}},Hu.prototype._unregisterDoc=function(n){var t=Bi.dig(this._forwarders,n.collection,n.id);for(var e in t)n.off(e,t[e]);var r=Bi.dig(this._emitters,n.collection,n.id);r.removeAllListeners(),Bi.digAndRemove(this._forwarders,n.collection,n.id),Bi.digAndRemove(this._emitters,n.collection,n.id),Bi.digAndRemove(this._docs,n.collection,n.id)};var HN=dN,jN=CN,zN=dT,bT=LN,GN=ON,WN=FN,vT=os,Fa=Yh,le=ls.ACTIONS,BT=Ou,qr=xr,ju=J2,qN=$N,zu=Fa.CODES;function TT(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var XN=wt;function wt(n){vT.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._docPresenceEmitter=new qN,this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=TT(n),this.bindToSocket(n)}vT.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=TT(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(r){try{var i=typeof r.data=="string"?JSON.parse(r.data):r.data}catch{ju.warn("Failed to parse message",r);return}e.debug&&ju.info("RECV",JSON.stringify(i));var o={data:i};if(e.emit("receive",o),!!o.data)try{e.handleMessage(o.data)}catch(s){qr.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(r){e.emit("connection error",r)},n.onclose=function(r){r==="closed"||r==="Closed"?e._setState("closed",r):r==="stopped"||r==="Stopped by server"?e._setState("stopped",r):e._setState("disconnected",r)}},wt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=yT(n.error,n),delete n.error),n.a){case le.initLegacy:return this._handleLegacyInit(n);case le.handshake:return this._handleHandshake(t,n);case le.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case le.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case le.queryUnsubscribe:return;case le.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 le.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case le.bulkSubscribe:case le.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case le.snapshotFetch:case le.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case le.fetch:var r=this.getExisting(n.c,n.d);r&&r._handleFetch(t,n.data);return;case le.subscribe:case le.unsubscribe:var r=this.getExisting(n.c,n.d);r&&r._handleSubscribe(t,n.data);return;case le.op:var r=this.getExisting(n.c,n.d);r&&r._handleOp(t,n);return;case le.presence:return this._handlePresence(t,n);case le.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case le.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case le.presenceRequest:return this._handlePresenceRequest(t,n);case le.pingPong:return this._handlePingPong(t);default:ju.warn("Ignoring unrecognized message",n)}};function yT(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 r in t.data){var i=t.data[r],o=this.getExisting(t.c,r);o&&(n?o[e](n):i.error?o[e](yT(i.error)):o[e](null,i))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var r=t.b[s],o=this.getExisting(t.c,r);o&&o[e](n)}else if(t.b)for(var r in t.b){var o=this.getExisting(t.c,r);o&&o[e](n)}else ju.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 Fa(zu.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var r in this.queries){var i=this.queries[r];i._onConnectionStateChanged()}for(var o in this.collections){var s=this.collections[o];for(var r in s)s[r]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var r in this._snapshotRequests){var c=this._snapshotRequests[r];c._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},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 r=[],i={},o=0,s;for(var l in e){var c=e[l];c==null?r.push(l):(i[l]=c,s=l,o++)}if(r.length===1){var l=r[0];this.send({a:n,c:t,d:l})}else r.length&&this.send({a:"b"+n,c:t,b:r});if(o===1){var d=i[s];this.send({a:n,c:t,d:s,v:d})}else o&&this.send({a:"b"+n,c:t,b:i})}},wt.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var r=this.bulk[t.collection]||(this.bulk[t.collection]={}),i=r[n]||(r[n]={}),o=i.hasOwnProperty(t.id);return i[t.id]=e,o}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},wt.prototype.sendFetch=function(n){return this._sendActions(le.fetch,n,n.version)},wt.prototype.sendSubscribe=function(n){return this._sendActions(le.subscribe,n,n.version)},wt.prototype.sendUnsubscribe=function(n){return this._sendActions(le.unsubscribe,n)},wt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:le.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&&ju.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},wt.prototype.ping=function(){if(!this.canSend)throw new Fa(zu.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:le.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]={}),r=e[t];return r||(r=e[t]=new HN(this,n,t),this.emit("doc",r)),r._wantsDestroy=!1,r},wt.prototype._destroyDoc=function(n){!n._wantsDestroy||(qr.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,r,i){var o=this.nextQueryId++,s=new jN(n,this,o,t,e,r,i);return this.queries[o]=s,s.send(),s},wt.prototype._destroyQuery=function(n){delete this.queries[n.id]},wt.prototype.createFetchQuery=function(n,t,e,r){return this._createQuery(le.queryFetch,n,t,e,r)},wt.prototype.createSubscribeQuery=function(n,t,e,r){return this._createQuery(le.querySubscribe,n,t,e,r)},wt.prototype.hasPending=function(){return!!(this._firstDoc(e0)||this._firstQuery(e0)||this._firstSnapshotRequest())};function e0(n){return n.hasPending()}wt.prototype.hasWritePending=function(){return!!this._firstDoc(YN)};function YN(n){return n.hasWritePending()}wt.prototype.whenNothingPending=function(n){var t=this._firstDoc(e0);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(e0);if(e){e.once("ready",this._nothingPendingRetry(n));return}var r=this._firstSnapshotRequest();if(r){r.once("ready",this._nothingPendingRetry(n));return}qr.nextTick(n)},wt.prototype._nothingPendingRetry=function(n){var t=this;return function(){qr.nextTick(function(){t.whenNothingPending(n)})}},wt.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var r in e){var i=e[r];if(n(i))return i}}},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,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new GN(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},wt.prototype.fetchSnapshotByTimestamp=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new WN(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.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:le.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 Fa(zu.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(BT.map[n.type]!==BT.defaultType)return this.emit("error",new Fa(zu.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new Fa(zu.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=qr.digOrCreate(this._presences,n,function(){return new zN(t,n)});return e._wantsDestroy=!1,e},wt.prototype.getDocPresence=function(n,t){var e=bT.channel(n,t),r=this,i=qr.digOrCreate(this._presences,e,function(){return new bT(r,n,t)});return i._wantsDestroy=!1,i},wt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var r={a:n,ch:e.channel,seq:t};return this.send(r),r.seq},wt.prototype._addPresence=function(n){qr.digOrCreate(this._presences,n.channel,function(){return n})},wt.prototype._handlePresenceSubscribe=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},wt.prototype._handlePresenceUnsubscribe=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},wt.prototype._handlePresence=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},wt.prototype._handlePresenceRequest=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var kT=XN,QN=Ou;const Gu={err:1001,msg:"user auth error",name:"AuthError"},n0={err:1002,msg:"you don't have required permission",name:"PermissionError"},Z1={err:1003,msg:"Too many user connected",name:"MaxUserError"},Wu={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},JN={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},ZN={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},dl="x-live-editor-token",Ka="x-live-editor-base-url",Cn=I("auth-connection");function tP(n){try{n()}catch(t){Cn.error(t)}}class eP{constructor(t,e){m(this,"enabled",!0);m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new Kb.EventEmitter);m(this,"token",null);m(this,"resourceToken",null);m(this,"pingOptions",{interval:5e4,timeout:15e4});m(this,"reAuth",async()=>{if(this.connection&&this.reauthFunc){const t=await this.reauthFunc();await this.auth(t);const e=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:e}})}}});this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return hi(this.getBaseURL())}async auth(t){p(Cn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,r=await window.fetch(e,{method:"GET",headers:{[dl]:t.token,[Ka]:this.getBase64BaseURL()},credentials:"include"});return r.status,this.enabled?(this.token=t.token,await r.json()):{read:"",user:""}}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[Ka]:hi(this.getBaseURL())}})}async init(t){const e=await this.auth(t);if(!this.enabled)return;this.resourceToken=e.read,this.ws=new v9.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(kT.prototype),p(Cn,this.connection,"no this.connection");const r=this.ws,i=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:i}}),this._ping==null&&(this._ping=window.setInterval(()=>{var d;const c=Date.now();c-((d=this.lastReceiveTime)!=null?d:0)>i.interval&&this.send({a:"ping",id:this.id,ts:c}),this.lastReceiveTime&&c-this.lastReceiveTime>i.timeout&&r&&r.readyState===r.OPEN&&(r.reconnect(),this.lastReceiveTime=Date.now())},1e3))};const o=this.connection.handleMessage.bind(this.connection);let s=!1;this.connection.handleMessage=l=>{var d;const c=l;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in c||c.a==="pong")s=!1,this.handleMessage(c);else{Object.prototype.hasOwnProperty.call(c,"a")&&c.a==="hs"&&this.retryCount>=5&&(s?(Cn.info("retrying re-auth success"),s=!1,this.emitAuthRecover()):s=!0),Object.prototype.hasOwnProperty.call(c,"a")&&c.a!=="init"&&c.a!=="hs"&&(this.retryCount=0);try{o(c)}catch(h){if((h==null?void 0:h.type)==="writeConflict"){this.emitWriteConflictError(h,c);return}if((d=h==null?void 0:h.message)!=null&&d.startsWith("Cannot invert subtype")){this.emitWriteConflictError(h,c);return}throw h}}},kT.apply(this.connection,[this.ws])}async reConnect(t){var r,i;(r=this.ws)==null||r.close();const e=this.pingOptions;if(this.connection&&this.reauthFunc){const o=await this.reauthFunc();await this.auth(o),(i=this.ws)==null||i.reconnect(),this.connection._initializeHandshake=function(){t&&(o.token=t),this.send({a:"hs",id:this.id,auth:o,options:{ping:e}})}}}async handleAuthError(){var t,e;if(this.reauthFunc){if(!this.enabled)return;(t=this.ws)==null||t.close(),this.retryCount+=1,Cn.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const r=await this.reauthFunc();if(window.isReauthError)throw new Error("reauth error");await this.auth(r);const i=this.pingOptions;(e=this.ws)==null||e.reconnect(),this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:r,options:{ping:i}})}}}catch(r){Cn.error(r),this.retryCount>=5&&(Cn.warn("retry auth times exceed 5, broadcast auth error"),this.emitAuthError());const i=30*1e3;setTimeout(()=>this.handleAuthError(),Math.min(2*this.retryCount*1e3,i))}}}emitPermissionError(){const t=new Error(n0.msg);t.code=n0.err,this.events.emit("error",t)}emitAuthRecover(){this.events.emit("authRecover")}emitAuthError(){const t=new Error(Gu.msg);t.code=Gu.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Wu.msg);t.code=Wu.err,this.events.emit("requestReloadError",t)}emitWriteConflictError(t,e){t.orgMsg=e,this.events.emit("writeConflictError",t)}emitMaxUsersError(){this.events.emit("maxUsersError"),this.end(!1)}handleMessage(t){const e=t;if(e.a==="pong")return;const r=e.err;if(r===Gu.err)Cn.warn("auth error"),this.handleAuthError();else if(r===Z1.err)Cn.warn(Z1.msg),this.emitMaxUsersError();else if(r===Wu.err){Cn.warn(Wu.msg);try{this.emitRequestReloadError()}catch(i){Cn.error(`error occurred while process reload error: ${JSON.stringify(i)}`)}finally{this.end(!1)}}else r===n0.err?this.emitPermissionError():(Cn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError())}get(t,e){return p(Cn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(p(Cn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onAuthError(t){this.events.addListener("error",t)}onAuthRecover(t){this.events.addListener("authRecover",t)}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){p(Cn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){p(Cn,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e,r;this.enabled=!1,this.reauthFunc=void 0,this.events.removeAllListeners(),tP(()=>{var i;return(i=this.connection)==null?void 0:i.close()}),(e=this.connection)!=null&&e._ping&&window.clearInterval(this.connection._ping),this.connection=void 0,(r=this.ws)==null||r.close(),this.ws=void 0,t&&this.logout()}}I("utils/file");function nP(){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}nP();async function rP(n){const e=n.size,r=Math.floor((e+102400-1)/102400),i=new B9.Hash;for(let s=0;s<r;s++){const l=s*102400;let c=l+102400;c>e&&(c=e);const h=await n.slice(l,c,n.type).arrayBuffer();i.update(new Uint8Array(h))}const o=i.digest();return hi(o)}const Ti=I("sharedb-doc/client"),iP=Vb.default.create();class oP{constructor(t,e,r){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",tt());m(this,"getDoc",async()=>{const t=r=>new Promise((i,o)=>{r.fetch(s=>{s?o(s):i()})});p(Ti,!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),Ti.debug(e),e});this.auth=t;const i=`${e}/${this.auth.appId}/${this.auth.docId}`;QN.register(Pd.type),this.connection=new eP(i,r),this.reauthFunc=r}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(Ti,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,r=>{(t==="error"||this.doc)&&e(r)})}onAuthError(t){this.connection.onAuthError(t)}onAuthRecover(t){this.connection.onAuthRecover(t)}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,r,i,o){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...o},data:{name:r,size:i}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const r=`${this.apiServer()}/resources`;try{const i=`${r}/hash`,o=await this.request(i,{method:"post",headers:{[dl]:this.connection.token},data:{resources:t}});return o.data&&Array.isArray(o.data)?o.data:[]}catch{return[]}}async uploadFile(t,e,r,i,o){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=x=>{Ti.info(`on progress: ${x.loaded}`);let v=x.loaded*100/s;v>100&&(v=100),i(v)},c=await rP(e),d=await this.getFileUrlByHash(t,c,e.name,e.size,r);if(d)return i(-1),d;let h=t;o!=null&&o.thumbnail&&(h+="/thumbnail");const C=new FormData;C.append("file-size",`${e.size}`),C.append("file-hash",c),C.append("file",e,e.name);const E=await this.request(h,{method:"post",data:C,withCredentials:!0,headers:{...r},onUploadProgress:l});return Ti.info(E),i(100),Array.isArray(E.data)?E.data[0]:E.data}async uploadResource(t,e=()=>{},r){const o=`${this.apiServer()}/resources`;p(Ti,this.connection.token,"no connection token");const s=await this.uploadFile(o,t,{[dl]:this.connection.token},e,r);return p(Ti,s,"no result"),s}async request(t,e){var o,s;let r=this.connection.token,i;for(let l=0;l<2;l++){const c=e||{};c.url=t,c.headers||(c.headers={}),p(Ti,r,"no token"),c.headers={...c.headers,[dl]:r,[Ka]:this.connection.getBase64BaseURL()};try{return await iP(t,c)}catch(d){if(i=d,((o=d==null?void 0:d.response)==null?void 0:o.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;r=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw p(Ti,i,"no error"),i}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=$b.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(Ti,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const r=`${this.apiServer()}/resources/external/${hi(t)}`;return(await this.request(r)).data}getResourceId(t){const e=/\/resources\/([^?]+)/,r=t.match(e);return r&&r.length>=2?r[1]:""}buildResourceUrl(t,e){var s,l;if(!t)return"";if(t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;const r=this.apiServer();if(t.startsWith("http:")||t.startsWith("https:")){const c=r.replace(/\/[^/]*$/,"");if(c&&t.includes(c)){const d=this.auth.docId,h=`${c}/`,C="/resources",E=t.indexOf(h),x=t.indexOf(C,E+h.length);if(E!==-1&&x!==-1){const v=t.substring(E+h.length,x);if(v!==d){let R=t.replace(v,d);const w=new URL(R),U="token";(s=w.searchParams)==null||s.delete(U),R=w.toString();const M=this.getResourceId(R);return e!=null&&e.syncNewResources&&((l=e==null?void 0:e.syncNewResources)==null||l.call(e,M,R)),R}return t}return t}return t}let i=`${r}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken&&o.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const c=o.join("&");i+=`?${c}`}return i}reAuth(){this.connection.reAuth()}}function sP(){return{blocks:[{id:tt(),type:"text",text:[]}],comments:{},meta:{}}}const tC=I("block-ids");class lP{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((i,o)=>o-i);for(let i=0;i<e.length;i++){const o=e[i];if(o>=t){const s=this.ids.get(o);p(tC,s!==void 0,"old id is not exists"),this.ids.delete(o),this.ids.set(o+1,s)}}const r=tt();this.ids.set(t,r)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((r,i)=>r-i);for(let r=0;r<e.length;r++){const i=e[r];if(i>t){const o=this.ids.get(i);p(tC,o!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i-1,o)}}}getId(t){let e=this.ids.get(t);return e||(e=tt(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class aP{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new lP,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let r=0;r<e.length;r++){const i=e[r],o=i[1].getById(t);if(o)return{containerId:i[0],blockIndex:o[0]}}return p(tC,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class RT{constructor(t=new Set,e=new Map){this.deletedKeys=t,this.insertedValues=e}insert(t,e){this.insertedValues.set(t,e)}delete(t){this.deletedKeys.add(t)}toDocBlockDelta(){const t={};return this.insertedValues.forEach((e,r)=>{t[r]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const eC=I("op-parse-handler");class cP{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const r={...t,containerId:(i=>i==="blocks"?"root":i)(t.containerId)};this.actions.push(r)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,r){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:r})}onDeleteBlockData(t,e,r){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:r})}onInsertBlockData(t,e,r,i){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:r,value:i})}onUpdateBlockText(t,e,r){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:r})}onDeleteContainer(t){this.pushActions({type:"deleteContainer",containerId:t})}onCreateContainer(t,e){this.pushActions({type:"createContainer",containerId:t,data:e})}onDeleteComment(t){this.pushActions({type:"deleteComment",commentId:t})}onCreateComment(t){this.pushActions({type:"createComment",commentId:t})}onUpdateComment(t){this.pushActions({type:"updateComment",commentId:t})}end(){const t=this.actions,e=new Set,r=new Map,i=new aP,o=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of o)if(s.type==="deleteBlock"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);i.onDeleteBlock(l.containerId,l.blockIndex);const d=r.get(c);d&&(eC.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),r.delete(c));const h=`${l.containerId}-${l.blockIndex}`;e.add(h),this.outerHandler.onDeleteBlock(l.containerId,l.blockIndex,this.local)}else if(s.type==="deleteBlockData"){const l=s,c=`${l.containerId}-${l.blockIndex}`;if(e.has(c)){eC.warn("delete block data after delete block, ignore it");continue}const d=i.getBlockId(l.containerId,l.blockIndex);let h=r.get(d);h||(h=new RT,r.set(d,h)),h.delete(l.key)}else p(eC,!1,`invalid action type, ${s.type}`);this.actions.forEach(s=>{if(s.type==="deleteContainer"){const l=s;this.outerHandler.onDeleteContainer(l.containerId,this.local)}else if(s.type==="deleteComment"){const l=s;this.outerHandler.onDeleteComment(l.commentId,this.local)}}),this.actions.forEach(s=>{if(s.type==="createContainer"){const l=s;this.outerHandler.onCreateContainer(l.containerId,l.data,this.local)}}),this.actions.forEach(s=>{if(s.type==="insertBlock"){const l=s;this.outerHandler.onInsertBlock(l.containerId,l.blockIndex,l.data,this.local)}else if(s.type==="insertBlockData"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);let d=r.get(c);d||(d=new RT,r.set(c,d)),d.insert(l.key,l.value)}else if(s.type==="updateBlockText"){const l=s;this.outerHandler.onUpdateBlockText(l.containerId,l.blockIndex,l.richTextData,this.local)}else if(s.type==="createComment"){const l=s;this.outerHandler.onCreateComment(l.commentId,this.local)}else if(s.type==="updateComment"){const l=s;this.outerHandler.onUpdateComment(l.commentId,this.local)}}),Array.from(r.entries()).forEach(([s,l])=>{const{containerId:c,blockIndex:d}=i.getBlockIndexById(s);this.outerHandler.onUpdateBlockData(c,d,l.toDocBlockDelta(),this.local)})}}const He=I("op-parser");class wT{}class nC{constructor(t){m(this,"key");this.key=t}}function uP(n,t,e){const r=t.concat(),i=r[0];if(typeof i!="number"||(r.shift(),r.length===1))return!1;const o=r[0];if(typeof o!="object"||!o.i||Object.keys(o).length!==1)return!1;for(let l=1;l<r.length;l++){const c=r[l];if(!Array.isArray(c)||c.length!==2||typeof c[0]!="string")return!1;const h=c[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=o.i;p(He,s.id,"block id is required"),p(He,s.type,"block type is required");for(let l=1;l<r.length;l++){const c=r[l],d=c[0],h=c[1];s[d]=h.i}return e.onInsertBlock(n,i,s),!0}function rC(n,t,e,r){if(e==="upsert"&&uP(n,t,r))return;p(He,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const i=t.concat(),o=i[0];i.shift();const s=[];for(;i.length>0;){const l=i[0];if(l==="text"){const c=i[1];if(p(He,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),p(He,c.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),i.splice(0,2),e==="upsert"){const h=c.e;r.onUpdateBlockText(n,o,h)}p(He,i.length===0,`invalid block ops.length !== 0, ${JSON.stringify(i)}`)}else if(Array.isArray(l)){p(He,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];p(He,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const d=l[1];if(c==="text"){if(p(He,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&r.onInsertBlockData(n,o,c,d.i),d.r&&e==="remove"&&r.onDeleteBlockData(n,o,c),d.et==="rich-text"&&e==="upsert"){const C=d.e;r.onUpdateBlockText(n,o,C)}}else e==="remove"&&d.r&&s.push(new nC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i);i.shift()}else if(typeof l=="object"){const c=l;e==="remove"&&c.r&&s.push(new wT),e==="upsert"&&c.i&&r.onInsertBlock(n,o,c.i),i.shift()}else{p(He,typeof l=="string","data is not string"),p(He,l!=="text","data !== 'text'"),p(He,i.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(i)}`);const c=l,d=i[1];e==="remove"&&d.r&&s.push(new nC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i),i.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof wT?r.onDeleteBlock(n,o):l instanceof nC?r.onDeleteBlockData(n,o,l.key):p(He,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function fP(n,t,e){He.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function dP(n,t,e){const r=n[1],i=n[2];p(He,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),p(He,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?He.error(`unknown comment op, ${JSON.stringify(n)}`):i.i&&i.r?t==="upsert"&&e.onUpdateComment(r):i.i?t==="upsert"&&e.onCreateComment(r):i.r?t==="remove"&&e.onDeleteComment(r):He.error(`unknown comment op, ${JSON.stringify(n)}`)}function iC(n,t,e){const r=n[0];if(Array.isArray(r)){r.forEach(s=>{iC(s,t,e)});return}const i=r;if(p(He,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){fP(n);return}if(i==="comments"){dP(n,t,e);return}const o=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{rC(o,s,t,e)}):n.slice(1).forEach(s=>{rC(o,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(o),s.i&&t==="upsert"&&e.onCreateContainer(o,s.i)}else p(He,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),rC(o,n.slice(1),t,e)}function oC(n,t,e){const r=new cP(t,e);for(let i=0;i<2;i++){const o=i===0?"remove":"upsert",s=mt.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{iC(c,o,r)}):iC(s,o,r)}r.end()}const hP=I("sharedb-comments");function sC(n){const t=n.blocks;p(hP,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([r,i])=>{Array.isArray(i)&&(e.blocks[r]=i)}),mt.default(e)}function ST(n){const{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}=n;return{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}}function lC(n,t){const e=WO(t),{comments:r,meta:i,blocks:o,...s}=e,l={...n,blocks:o,...s},c=mt.default(l);return delete c.children,c}const ae=I("sharedb-doc/doc-container"),LT="ot-json1";Pd.type.registerSubtype(qO.type),Pd.type.name=LT,Pd.type.invert=null;class qu extends ma{constructor(e,r,i=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new zO);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)})});m(this,"handleReset",async e=>{const r=new Error(`reset doc: ${e}`);r.code="ResetDoc",this.callbacks.forEach(i=>{var o;return(o=i.onError)==null?void 0:o.call(i,r)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,r,i)=>{const o=[e,r,{i}];return this.submitOp(o)});m(this,"deleteObject",async(e,r)=>{const i=[e,r,{r:!0}];return this.submitOp(i)});m(this,"replaceObject",async(e,r,i)=>{const o=[e,r,{r:!0,i}];return this.submitOp(o)});m(this,"updateObject",async(e,r,i)=>{const o=this.data()[e][r],s=[e,r];return Object.entries(i).forEach(([l,c])=>{if(!Xc.default(o[l],c))if(o[l]===void 0){if(c!=null){const d={i:c};s.push([l,d])}}else if(c==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:c};s.push([l,d])}}),Object.entries(o).forEach(([l,c])=>{if((i[l]===void 0||i[l]===null)&&c!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const r={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(r)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((r,i)=>{if(this.destroyed){ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},o=>{o?(ae.error(`invalid op, ${o.message}, ${JSON.stringify(e)}`),i(o),ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):r()}),this.doc.data||(ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((r,i)=>{this.doc.create(e,LT,o=>{o?i(o):r()})}));m(this,"submitInsertChildContainers",async e=>{if(e.length===0)return Promise.resolve();const r=e.map(({containerId:i,blocks:o})=>[ao(i),{i:o}]);return this.submitOp([r])});m(this,"submitDeleteChildContainer",async e=>{const r=[ao(e),{r:!0}];return this.submitOp(r)});m(this,"submitInsertBlock",async(e,r,i)=>{const o=[ao(e),r,{i}];return this.submitOp(o)});m(this,"submitDeleteBlock",async(e,r)=>{const i=[ao(e),r,{r:!0}];return this.submitOp(i)});m(this,"submitUpdateBlockData",async(e,r,i)=>{if(i.delete.length===0&&Object.keys(i.insert).length===0)return Promise.resolve();const o=[ao(e),r],s=new Set(i.delete);Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c)){const h={r:!0,i:d};o.push([c,h])}});const l=new Set(Object.keys(i.insert));return i.delete.forEach(c=>{if(l.has(c))return;const d={r:!0};o.push([c,d])}),Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c))return;const h={i:d};o.push([c,h])}),this.submitOp(o)});m(this,"submitUpdateRichText",async(e,r,i)=>{const o=[ao(e),r,"text",{e:i,et:"rich-text"}];return this.submitOp(o)});m(this,"handleOp",(e,r,i)=>{if(this.destroyed){ae.warn("handleOp: destroyed");return}try{oC(e,this,!!r)}catch(o){throw ae.error(o),o}});this.client=e,this.doc=r,this.doc.preventCompose=!0,this.disableLogout=i,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,p(ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const r=new oP(e.auth,e.serverUrl,e.reauthFunc),i=await r.getDoc(),o=new qu(r,i,e.disableLogout);if(i.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await o.createDoc(e.templateData||sP())}return await o.initPresence(),await o.subscribe(),o.initEvents(),o}catch(r){throw ae.error(r),ae.error(`failed to load doc: ${JSON.stringify(r)}`),r}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onAuthError(e=>{this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}),this.client.onAuthRecover(()=>{this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,r)=>{if(this.localPresence)e();else{const i=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);i.on("receive",(o,s)=>{this.onCustomMessage(s)}),i.subscribe(o=>{o?r(o):(this.localPresence=i.create(tt()),e())})}})}subscribe(){return new Promise((e,r)=>{this.doc.subscribe(i=>{i?r(i):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return lo(this.data())}getContainerBlocks(e){const r=this.data();p(ae,r,"no doc data");const i=r[ao(e)];return p(ae,i,`no container data: ${e}`),mt.default(i)}findContainerBlocks(e){const r=this.data();p(ae,r,"no doc data");const i=r[ao(e)];return i!=null?i:null}getBlockData(e,r){const i=this.data();p(ae,i,"no doc data");const o=i[ao(e)];p(ae,o,`no container data: ${e}`);const s=o[r];return p(ae,s,`no block data: ${r}`),mt.default(s)}localInsertBlock(e,r,i){return this.submitInsertBlock(e,r,i),this.getBlockData(e,r)}localDeleteBlock(e,r){const i=this.getBlockData(e,r);return this.submitDeleteBlock(e,r),i}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(ae,o.text,"no block text");const s=mt.default(o.text);this.submitUpdateRichText(e,r,i);const l=pn.apply(s,i);return p(ae,l,"no block text"),l}localUpdateBlockData(e,r,i){const o=mt.default(this.getBlockData(e,r));return this.submitUpdateBlockData(e,r,i),o}localInsertChildContainers(e){this.submitInsertChildContainers(e)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(r=>{this.submitDeleteChildContainer(r)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(r=>ST(r))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const r=this.data().comments[e];return sC(r)}localCreateComment(e,r){const i=lC(e,r),s=["comments",i.id,{i}];return this.submitOp(s)}localDeleteComment(e){const r=["comments",e,{r:!0}];return this.submitOp(r)}localUpdateComment(e,r){const i=lC(e,r),o=["comments",e.id,{r:!0,i}];return this.submitOp(o)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,r,i){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onDeleteBlock)==null?void 0:s.call(o,Na(e),r,i)})}onInsertBlock(e,r,i,o){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Na(e),r,i,o)})}onUpdateBlockData(e,r,i,o){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Na(e),r,i,o)})}onUpdateBlockText(e,r,i,o){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Na(e),r,i,o)})}onDeleteContainer(e,r){p(ae,this.callbacks.length>0,"no callbacks"),p(ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,Na(e),r)})}onCreateContainer(e,r,i){p(ae,this.callbacks.length>0,"no callbacks"),p(ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,Na(e),r,i)})}onDeleteComment(e,r){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteComment)==null?void 0:o.call(i,e,r)})}onCreateComment(e,r){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onCreateComment)==null?void 0:o.call(i,e,r)})}onUpdateComment(e,r){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onUpdateComment)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){const r=e;(r==null?void 0:r.type)==="custom"&&(r==null?void 0:r.clientId)!==this.client.clientId?this.callbacks.forEach(i=>{var o;return(o=i.onCustomMessage)==null?void 0:o.call(i,r.data)}):(r==null?void 0:r.type)==="onlineUsers"&&setTimeout(()=>{const i={type:"custom",data:e,clientId:"-"};this.onCustomMessage(i)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}async addResources(e){let r=[];return e.forEach(o=>{const s=o.split("|");r.push(...s)}),r=Array.from(new Set(r)),await this.client.getFileUrlsByHashes(r)}async uploadResource(e,r){var o;return{resourceId:await this.client.uploadResource(e,(o=r==null?void 0:r.onProgress)!=null?o:()=>{})}}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}request(e,r){return this.client.request(e,r)}getUser(){const e=this.client.clientId,{permission:r,userId:i,displayName:o,avatarUrl:s}=this.client.auth;return{permission:r,clientId:e,userId:i,displayName:o,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return lo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return lo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:lo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:lo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,r){oC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}triggerReAuth(){this.client.reAuth()}}I("remote-cursor");class IT{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",ke.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const r=this.editor.findBlockById(e);r&&this.editor.reloadBlock(r)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const DT=I("remote-cursor-decorator");class aC{decorateText(t,e,r){const i=t.doc.getRemoteUsers();if(!i)return{};const o=new Map,{containerId:s,blockIndex:l}=e[e.length-1];p(DT,typeof s=="string","invalid path containerId"),p(DT,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),d=gn(r);return i.getSimpleCursors(c.id).forEach((C,E)=>{E>d&&(E=d);const x=C.map(R=>({id:tt(),type:"remote-cursor",name:R.user.displayName,time:R.time,rainbowIndex:R.user.rainbowIndex})),v=o.get(E);v?v.push(...x):o.set(E,x)}),{insertions:o}}}const cC=I("sharedb-doc/share-db-server"),mP=Vb.default.create();class gP{constructor(t,e){m(this,"auth");m(this,"clientId",tt());this.serverUrl=e,this.auth=t}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(cC,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}apiServer(){const t=`${this.serverUrl}/${this.auth.appId}/${this.auth.docId}`;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}getBaseURL(){const t=new URL(this.apiServer());return`${t.protocol}//${t.host}${t.pathname}`}getBase64BaseURL(){return hi(this.getBaseURL())}async request(t,e){var o;const r=this.auth.token,i=e||{};i.url=t,i.headers||(i.headers={}),p(cC,r,"no token"),i.headers={...i.headers,[dl]:r,[Ka]:this.getBase64BaseURL()};try{return await mP(t,i)}catch(s){throw(o=s.response)!=null&&o.data&&(s.responseData=s.response.data),s}}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=$b.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(cC,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}buildResourceUrl(t,e){if(!t)return"";if(t.startsWith("https:")||t.startsWith("http:")||t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;let i=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken,e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const s=o.join("&");i+=`?${s}`}return i}}const pP=I("sharedb-doc/share-db-server");function _T(n){const t=new URL(n);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}function CP(n){return hi(_T(n))}class r0 extends ma{constructor(e){super();m(this,"remoteUsers",new Uu);m(this,"client");this.options=e,this.client=new gP(e.auth,e.serverUrl)}destroy(){}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}getRemoteUsers(){return this.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return lo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return lo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:lo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:lo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}parseHistoryData(e,r){oC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}static async auth(e,r){p(pP,e.token,"no auth token");const i=`${_T(r)}/auth`,o=await window.fetch(i,{method:"GET",headers:{[dl]:e.token,[Ka]:CP(r)},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return await o.json()}static async load(e){const r=`${e.serverUrl}/${e.auth.appId}/${e.auth.docId}`;return await this.auth(e.auth,r),new r0(e)}}class MT extends ye.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,r){if(qt(Ur(this.editor,t)))return;const i=this.editor.getBlockByIndex(t,e),o=J(this.editor.getContainerById(t));o&&this.emit("change",this.editor,{containerId:t,blockIndex:e},o,i,r)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}onInsertBlock(t,e){qt(Ur(this.editor,t))||this.emit("insert",this.editor,{containerId:t,blockIndex:e})}onDeleteBlock(t,e){this.handleChild(t,e,"remove")}destroy(){this.editor.doc.unregisterCallback(this)}}function UT(n,t){const e=n.addCustom("child-block-tracker",()=>new MT(n));e.addListener("change",t),e.addListener("insert",t)}function OT(n,t){const e=n.addCustom("child-block-tracker",()=>new MT(n));e.removeListener("change",t),e.removeListener("insert",t)}const Fct="",EP={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"}},xP={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},AP={colorPalette:{colorDesc:"\u30D5\u30A9\u30F3\u30C8\u306E\u8272",name:"\u30C6\u30AD\u30B9\u30C8\u306E\u8272",backgroundDesc:"\u80CC\u666F\u8272",reset:"\u30C7\u30D5\u30A9\u30EB\u30C8\u306B\u623B\u3059"},search:{emptyTips:"\u691C\u7D22\u7D50\u679C\u304C\u3042\u308A\u307E\u305B\u3093"}};D.mergeLang({"zh-CN":EP,"en-US":xP,"ja-JP":AP});const Kct="";I("button");function br(n,t,e,r,i){const o=B("button",["editor-button"],null);return o.setAttribute("data-button-id",n),i&&o.setAttribute(`data-editor-tooltip-${i}`,t),e?typeof e=="string"?e.startsWith("<")?o.innerHTML=e:o.innerText=e:o.appendChild(e):o.innerText=t,r&&(r.indexOf("checked")!==-1&&z(o,"checked"),r.indexOf("disabled")!==-1&&(o.disabled=!0),r.indexOf("primary")!==-1&&z(o,"primary")),o}const Vct="",i0=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
31
+ `)}return ru([{type:"text/plain",data:new Blob([r],{type:"text/plain"})}]),!0}const aO=Object.freeze(Object.defineProperty({__proto__:null,editorHandleEnter:A2,editorHandleDelete:b2,editorHandleBackspace:v2,editorHandleInsertBr:B2,editorHandlePastePlainText:T2,isSelectedCodeTextBlock:y2,getSelectedCodeBlockMarkdown:k2,editorHandleCopyMarkdown:P1},Symbol.toStringTag,{value:"Module"})),Gh={ArrowDown:O5,ArrowUp:U5,ArrowLeft:_5,ArrowRight:M5,"Shift+ArrowDown":N5,"Shift+ArrowUp":K5,"Shift+ArrowLeft":P5,"Shift+ArrowRight":F5,"CtrlOrCmd+ArrowLeft":$5,"CtrlOrCmd+ArrowRight":H5,"CtrlOrCmd+Shift+ArrowLeft":j5,"CtrlOrCmd+Shift+ArrowRight":z5,"CtrlOrCmd+ArrowUp":G5,"CtrlOrCmd+ArrowDown":S1,"CtrlOrCmd+Shift+ArrowUp":W5,"CtrlOrCmd+Shift+ArrowDown":L1,"CtrlOrCmd+A":I1,Home:Z5,End:t2,"Shift+Home":Q5,"Shift+End":J5,PageUp:o2,PageDown:s2,"Shift+PageUp":a2,"Shift+PageDown":c2,"CtrlOrCmd+Z":YU,"CtrlOrCmd+Shift+Z":QU,Enter:A2,Delete:b2,Backspace:v2,"Shift+Enter":B2,"CtrlOrCmd+Shift+V":T2,"CtrlOrCmd+Shift+C":P1};function R2(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function w2(n,t,e){if(t.type==="embed"){const o=t.embedData,s=o.src;if(s&&typeof s=="string"){const l=e.get(s);if(l)o.src=l;else{let c="";s.split("|").forEach(h=>{const C=e.get(h);C&&(c+=c?`|${C}`:`${C}`)}),c&&(o.src=c)}}return}const r=t.text;r&&r.forEach(o=>{if(o.attributes&&o.attributes.src&&typeof o.attributes.src=="string"){const s=e.get(o.attributes.src);s&&(o.attributes.src=s)}});const i=t.children;i&&i.forEach(o=>{n.blocks[o].forEach(l=>{w2(n,l,e)})})}function S2(n,t,e){if(e.size===0)return;t.blocks.root.forEach(i=>{const o=n.editorBlocks.getBlockClass(i.type);o.replaceResources?o.replaceResources(i,e):w2(t,i,e)})}async function cO(n,t){let e=t.filter(s=>s.indexOf(":")===-1);const r=[];e.forEach(s=>{const l=s.split("|");r.push(...l)}),e=Array.from(new Set(r)),e=r;const i=await n.doc.addResources(e),o=new Map;if(e.length!==i.length)return o;for(let s=0;s<e.length;s++)o.set(e[s],i[s]);return o}function uO(n,t){var l,c,d,h;const r=t.meta.serverId;if(!r||typeof r!="string")return!1;const i=(c=(l=n.doc).getServerMeta)==null?void 0:c.call(l);if(!i)return!1;const o=/.*(?=\/)/;return((d=(i.serverId||"").match(o))==null?void 0:d[0])===((h=r.match(o))==null?void 0:h[0])}async function F1(n,t){const r=t.meta.resources;if(!r||Object.keys(r).length===0)return;let i=new Map;if(uO(n,t)){const s=Array.from(Object.keys(r));i=await cO(n,s),S2(n,t,i)}const o=new Map;Object.entries(r).forEach(([s,l])=>{i.get(s)===void 0&&s!==l&&o.set(s,l)}),o.size!==0&&S2(n,t,o)}async function fO(n,t,e){await F1(n,t),n.undoManager.runInGroup(()=>{const{start:r,end:i}=n.selection.range,o=n.getBlockById(r.blockId);if(r.blockId===i.blockId&&ge(o)){const s=rt(o),l=n.getBlockIndex(o),[c]=n.insertDocAt(s,l+1,t,e);c&&n.selection.selectBlock(c,dt(n,c))}else{n.clearSelectedContents();const{block:s,offset:l}=Sa(n);n.insertDoc(s,l,t,e)}})}const dO=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function hO(n){let t;for(const e of dO)if(t=n[e],t)break;return t||null}class mO{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"hookExecutionAttempt",(t,e,r)=>{for(let i=0;i<this.handlers.length;i++){const o=this.handlers[i];if(o.handleBeforeCopy){const s=o.handleBeforeCopy(this.editor,e,r);if(s===!0)return!0;if(typeof s=="object"&&s!=null)return s}}});m(this,"onPasteText",async(t,e)=>{const r=new DataTransfer;r.setData("text/plain",t);const i=await this.editor.dataConverter.fromData(this.editor,r,e);if(i){const o=[];this.pasteDocs(i,null,o)}});m(this,"onBlur",ke.default(()=>{const t=this.editor.selection.range;if(!t.isCollapsed()){let e=null;if(nl(t.anchor)){const r=t.anchor.childContainerId,i=Ur(this.editor,r);e=k3(this.editor,i)}else e=this.editor.getBlockById(t.anchor.blockId);if(e){let r=t.start;t.isSimple()||(r=at(e,0,"normal")),this.editor.selection.setSelection(r,void 0,{noScroll:!0})}}this.removeActiveForBlur()},200));m(this,"removeActiveForBlur",ke.default(()=>{ot(this.editor.rootElement,"active")},200));this.editor=t}onInsertText(t,e){if(!nt(this.editor,this.editor.getFocusedBlock()))return;const{containerId:r,blockIndex:i,offset:o}=Sa(this.editor);this.handleBeforeInsertText(r,i,o,e)||(this.defaultInsertText(this.editor,r,i,o,e),this.handleAfterInsertText(r,i,o,e),this.editor.selection.updateLastCaretRect())}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleChanged&&r.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const r=this.handlers[e];r.handleRemoteChanged&&r.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){if(!nt(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:r,offset:i}=Sa(this.editor);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,r,i)}}onUpdateCompositionText(t,e,r){if(!nt(this.editor,this.editor.getFocusedBlock()))return;this.editor.updateCompositionText(e,r),this.editor.selection.caret.update();const{containerId:i,blockIndex:o,offset:s}=Sa(this.editor);for(let l=0;l<this.handlers.length;l++){const c=this.handlers[l];c.handleUpdateCompositionText&&c.handleUpdateCompositionText(this.editor,i,o,s,r)}this.editor.selection.updateLastCaretRect()}onCopy(t){oO(this.editor,t,this.hookExecutionAttempt)}onCopyWithoutEvent(){sO(this.editor,this.hookExecutionAttempt)}onCut(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeCut&&i.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const r=this.editor.selection.focusedBlock;ge(r)&&this.editor.deleteBlock(r)}else Ph(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;const e=this.editor.dataConverter.fromData(this.editor,t.clipboardData),r=Array.from(t.clipboardData.files);e.then(async i=>{i&&this.pasteDocs(i,t,r)})}onFocus(){z(this.editor.rootElement,"active"),this.onBlur.cancel(),this.removeActiveForBlur.cancel()}addHandler(t){this.handlers.push(t),this.handlers=this.handlers.sort((e,r)=>{var s,l;const i=(s=e.order)!=null?s:1;return((l=r.order)!=null?l:1)-i})}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,r,i))return!0}return!1}handleAfterInsertText(t,e,r,i){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,r,i))return!0}return!1}handleBeforeKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforeKeyDown&&i.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterKeyDown&&i.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,r,i,o){h1(this.editor,o)}defaultHandleKeydown(t,e){return R2(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePasteDoc&&await i.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map,boxIdMap:new Map};await fO(this.editor,t,e);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPasteDoc&&await i.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e,r){for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleBeforePaste&&await s.handleBeforePaste(this.editor,e,t,r))return}const i=hO(t);if(!!i){await this.pasteDoc(i);for(let o=0;o<this.handlers.length;o++){const s=this.handlers[o];if(s.handleAfterPaste&&await s.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}forEach(t){this.handlers.forEach(t)}}function gO(n,t,e){const r=zo(t,e);return r.remove(),r}I("copy-dom-attributes");const L2=["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 pO(n,t){for(let l=0;l<L2.length;l++){const c=L2[l];t[c]=n[c]}const e=n.attributes,r=t.attributes,i=[],o=[];for(let l=0;l<e.length;l++){const c=e[l],d=r.getNamedItem(c.name);d?d.value!==c.value&&(d.value=c.value,o.push(c)):i.push(c)}const s=[];for(let l=0;l<r.length;l++){const c=r[l];e.getNamedItem(c.name)||s.push(c)}i.forEach(l=>{t.setAttribute(l.name,l.value)}),o.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function I2(n){const t=Array.from(n.childNodes).filter(e=>!jv(e));return t.forEach(e=>{e.remove()}),t}function D2(n,t,e){var d;const r=n.getContainerById(t),i=zo(r,e),o=qo(i),s=n.doc.getBlockData(t,e),l=Qt(n,i);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,i,s))n.editorBlockRenders.updateBlock(n,o,i,s);else{const h=n.editorBlocks.createBlock(o,r,s),C=I2(h);I2(i),C.forEach(x=>{i.appendChild(x)});const E=oh(h);if(E){const x=oh(i);x&&x.remove(),i.appendChild(E)}pO(h,i)}i3(n,i,s),n.blockHooks.forEach(h=>{var C;(C=h.update)==null||C.call(h,n,o,r,i,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const CO=I("transform-selection");function _2(n,t,e,r){const{range:i}=n.selection,{anchor:o,focus:s}=i;if(o.blockId!==t&&s.blockId!==t)return i;p(CO,o.isSimple()&&s.isSimple(),"invalid text pos type");let l=o;if(o.blockId===t){const d=pn.transformCursor(o.offset,e,r);l=at(t,d,"normal")}let c=s;if(s.blockId===t){const d=pn.transformCursor(s.offset,e,r);c=at(t,d,"normal")}return Ye(n,{anchor:l,focus:c})}const EO=I("handle-block-text-changed");function xO(n,t,e,r,i){const o=n.getContainerById(t),s=zo(o,e),l=n.doc.getBlockData(t,e);if(p(EO,l.text,"no block text"),Kv(n,s).setBlockText(n,s,l.text),!i){const c=_2(n,l.id,r,i);n.selection.setRange(c,{noScroll:!0})}}function AO(n,t){const e=mt.default(n);return t.delete.forEach(i=>{delete e[i]}),{...e,...t.insert}}function M2(n,t,e,r){const i=Qt(n,t);i.handleDeleteBlock&&i.handleDeleteBlock(n,t,e,r),n.emit("blockDeleted",n,t,e,r)}function bO(n,t,e,r){const i=n.getBlockByIndex(t,e);i.querySelectorAll('[data-type="editor-block"]').forEach(o=>{M2(n,o,r,{child:!0})}),M2(n,i,r,{child:!1})}const Hr=I("editor-doc");class vO extends ma{constructor(e,r,i){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=r,this.externalDoc.registerCallback(this),this.registerLocalEvents(i)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var r,i;return(i=(r=this.externalDoc).getVersionHelper)==null?void 0:i.call(r)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}findContainerBlocks(e){return this.externalDoc.findContainerBlocks(e)}getBlockData(e,r){return this.externalDoc.getBlockData(e,r)}verifyBlockWritable(e,r){const i=this.editor.getBlockByIndex(e,r);p(Hr,this.editor.isBlockWritable(i),`block is not writable, ${e}, ${r}`)}localUpdateBlockText(e,r,i,o){p(Hr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const s=this.getBlockData(e,r),l=s.text;p(Hr,l,`no text, ${e}, ${r}`);const c=_2(this.editor,s.id,i,!0),d=pn.apply(l,i);this.localEvents.forEach(C=>C.onBeforeUpdateBlockText(e,s.id,l,d,c.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,r,i);return this.editor.selection.setRange(c,o),h}localUpdateBlockData(e,r,i,o){p(Hr,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,r);if(!this.editor.isBlockWritable(s)){const h=Array.from(i.delete).filter(E=>E!=="comments"),C=Object.keys(i.insert).filter(E=>E!=="comments");(h.length>0||C.length>0)&&p(Hr,!1,`block is not writable, comment supported only, ${JSON.stringify(i)}}`)}const l=mt.default(this.getBlockData(e,r)),c=mt.default(AO(l,i));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,c,o));const d=this.externalDoc.localUpdateBlockData(e,r,i,o);return this.editor.selection.setRange(Xo(this.editor,o)),d}localInsertBlock(e,r,i,o,s){p(Hr,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(c=>c.onBeforeInsertBlock(e,r,i,o));const l=this.externalDoc.localInsertBlock(e,r,i,o);return s!=null&&s.noFocus||this.editor.selection.setRange(Xo(this.editor,o),s),l}localDeleteBlock(e,r,i){p(Hr,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,r);const o=mt.default(this.getBlockData(e,r));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,r,o,i));const s=this.externalDoc.localDeleteBlock(e,r,i);return this.editor.selection.setRange(Xo(this.editor,i)),s}localDeleteChildContainers(e){return p(Hr,!this.editor.readonly,"editor is readonly"),e.forEach(r=>{const i=mt.default(this.getContainerBlocks(r));this.localEvents.forEach(o=>o.onBeforeDeleteChildContainer(r,i))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainers(e){p(Hr,!this.editor.readonly,"editor is readonly");const r=mt.default(e);r.forEach(i=>{this.localEvents.forEach(o=>o.onBeforeInsertChildContainer(i.containerId,i.blocks))}),this.externalDoc.localInsertChildContainers(r)}onRequestReload(e){Hr.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(i=>{var o;return(o=i.onRequestReload)==null?void 0:o.call(i,e)});const r=!1;this.editor.emit("docChanged",this.editor,r)}onUpdateBlockText(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,r,i,o)}),xO(this.editor,e,r,i,o),this.editor.emit("docChanged",this.editor,o)}onUpdateBlockData(e,r,i,o){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,o)}),D2(this.editor,e,r),this.editor.emit("docChanged",this.editor,o)}onInsertBlock(e,r,i,o){this.callbacks.forEach(l=>{var c;return(c=l.onInsertBlock)==null?void 0:c.call(l,e,r,i,o)});const s=this.editor.getContainerById(e);e7(this.editor,s,r,i),this.editor.emit("docChanged",this.editor,o)}onDeleteBlock(e,r,i){bO(this.editor,e,r,i),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,i)});const o=this.editor.getContainerById(e);gO(this.editor,o,r),this.editor.emit("docChanged",this.editor,i)}onInsertChildContainer(e,r,i){this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,e,r,i)})}onDeleteChildContainer(e,r){this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,e)})}onStatusChanged(e){this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)})}onError(e){this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}uploadResource(e,r){return this.externalDoc.uploadResource(e,r)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,r){return this.externalDoc.buildResourceUrl(e,r)}request(e,r){return this.externalDoc.request(e,r)}broadcastMessage(e){return this.externalDoc.broadcastMessage(e)}getUser(){return this.externalDoc.getUser()}getRemoteUsers(){return this.externalDoc.getRemoteUsers()}triggerReAuth(){var e,r;return(r=(e=this.externalDoc).triggerReAuth)==null?void 0:r.call(e)}destroy(){this.externalDoc.destroy(),this.clearCallbacks()}getServerMeta(){var e,r,i;return(i=(r=(e=this.externalDoc).getServerMeta)==null?void 0:r.call(e))!=null?i:{}}reset(e){Hr.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function U2(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 Wh=I("undo-action");class Ua{constructor(t,e,r){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=r}undo(t){return!1}redo(t){return!1}combinable(t){return p(Wh,t,"no other action"),!1}combine(t){p(Wh,!1,"no other")}setAfterRange(t){this.afterRange&&Wh.warn("after range has already set"),this.afterRange=t}findContainerById(t,e){return!!t.doc.findContainerBlocks(e)}findBlockById(t,e){const r=t.doc.findContainerBlocks(this.containerId);return r?r.some(i=>i.id===e):!1}checkBlockData(t,e){if(Array.isArray(e.children)){const r=t.doc.toJSON();for(let i=0;i<e.children.length;i++){const o=e.children[i];if(!r.blocks[o])return Wh.warn(`container (${o}) not found, deleted by others?`),!1}}return!0}}const Oa=I("block-action");class O2 extends Ua{constructor(e,r,i,o,s){super(e,r,s);m(this,"blockData");m(this,"blockIndex");this.blockData=mt.default(o),this.blockIndex=i}deleteBlock(e,r){if(!this.findContainerById(e,this.containerId))return Oa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockData.id))return Oa.warn(`block (${this.blockData.id}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const o=e.getBlockById(this.blockData.id);if(!o)return!1;try{p(Oa,this.blockIndex===vt(o),"invalid block index"),Oh(e,o,Xo(e,r))}catch(s){Oa.warn(s.message),e.selection.selectBlock(o,0)}return!0}insertBlock(e,r){if(!this.findContainerById(e,this.containerId))return Oa.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.checkBlockData(e,this.blockData))return!1;try{Ia(e,this.containerId,this.blockIndex,mt.default(this.blockData),r)}catch(i){Oa.warn(i.message);const o=e.doc.getContainerBlocks(this.containerId),s=Math.min(o.length-1,this.blockIndex),l=e.getBlockByIndex(this.containerId,s);e.selection.selectBlock(l,0)}return!0}}I("insert-block-action");class BO extends O2{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class TO extends O2{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class yO extends Ua{constructor(e){super(e,ct(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){U2(this.actions,e),this.afterRange=e.afterRange}undo(e){let r=!1;return this.actions.concat().reverse().forEach(i=>{i.undo(e)&&(r=!0)}),r}redo(e){let r=!1;return this.actions.forEach(i=>{i.redo(e)&&(r=!0)}),r}setAfterRange(e){this.afterRange=e;const r=this.actions[this.actions.length-1];!r||r instanceof Ua&&(r.afterRange||r.setAfterRange(e))}}const is=I("update-block-data-action");class qh extends Ua{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=i,p(is,this.blockId===o.id,"invalid block id"),p(is,this.blockId===s.id,"invalid block id"),this.beforeBlockData=mt.default(o),this.afterBlockData=mt.default(s),p(is,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){if(!e.findBlockById(this.blockId))return is.warn(`block (${this.blockId}) not found, deleted by others?`),!1;const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(is,i,"no container"),Kh(e,r,qh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){if(!e.findBlockById(this.blockId))return is.warn(`block (${this.blockId}) not found, deleted by others?`),!1;p(is,e,"no editor");const r=e.getBlockById(this.blockId);if(!r||!this.checkBlockData(e,this.beforeBlockData))return!1;const i=e.getContainerById(this.containerId);return p(is,i,"no container"),Kh(e,r,qh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const r=mt.default(e);return delete r.id,delete r.type,r}}const ul=I("update-block-text-action");class _u extends Ua{constructor(e,r,i,o,s,l){super(e,r,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=i,this.beforeRichTextData=mt.default(o),this.afterRichTextData=mt.default(s),this.type=_u.calType(o,s)}static calType(e,r){p(ul,e,"no old data"),p(ul,r,"no new data");const o=pn.diff(e,r),s=new Set;let l=!1;const c=h=>gv(h)?`cjk_${h}`:hv(h)?"number":Yd(h)?"space":mv(h)?"letter":"unknown";let d=!1;return o.forEach(h=>{h.insert?h.insert===" "?s.add("insert_letter"):typeof h.insert=="string"&&h.insert.startsWith(" ")&&h.insert.length>1?(l=!0,d=!0,s.add(`insert_${c(h.insert.substr(1))}`)):s.add(`insert_${c(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!this.findContainerById(e,this.containerId))return ul.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return ul.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Fh(e,i,this.beforeRichTextData),!0):!1}redo(e){if(!this.findContainerById(e,this.containerId))return ul.warn(`container (${this.containerId}) not found, deleted by others?`),!1;if(!this.findBlockById(e,this.blockId))return ul.warn(`block (${this.blockId}) not found, deleted by others?`),!1;if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockId);return i?(Fh(e,i,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof _u)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const r=e.beforeRange,i=r.anchor;if(!i.isSimple())return!1;const o=this.afterRange;if(!o)return!1;const s=o.anchor;return!(!s.isSimple()||s.blockId!==r.anchor.blockId||s.offset!==i.offset)}combine(e){p(ul,e instanceof _u,"invalid action type");const r=e;this.afterRichTextData=r.afterRichTextData,this.afterRange=e.afterRange}}const N2=I("child-container-action");class P2 extends Ua{constructor(t,e,r){super(t,e,t.selection.range.toDocRange()),this.blocks=r}deleteChildContainer(t){return this.findContainerById(t,this.containerId)?(t.doc.localDeleteChildContainers([this.containerId]),!0):(N2.warn(`container (${this.containerId}) not found, deleted by others?`),!1)}insertChildContainer(t){return this.findContainerById(t,this.containerId)?(N2.warn(`container (${this.containerId}) already exists`),!1):(t.doc.localInsertChildContainers([{containerId:this.containerId,blocks:mt.default(this.blocks)}]),!0)}}class kO extends P2{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class RO extends P2{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const jr=I("undo");class wO{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):(U2(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(p(jr,!this.currentGroup,"current group already exists"),this.currentGroup=new yO(this.editor),this.groupCounter=1):(p(jr,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){p(jr,this.currentGroup,"current group not exists"),p(jr,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?jr.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 jr.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(Xo(this.editor,t.beforeRange))}catch(e){jr.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(Xo(this.editor,e)):jr.warn("no after range")}catch(e){jr.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,r,i,o){this.undoRedoing||(this.prepareSaveUndoState(),pn.diff(r,i).length!==0&&this.addAction(new _u(this.editor,t,e,r,i,o)))}onBeforeUpdateBlockData(t,e,r,i,o){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new qh(this.editor,t,e,r,i,o);this.addAction(s)}onBeforeInsertBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),p(jr,e>=0,"invalid block index"),p(jr,r,"no block data"),this.addAction(new BO(this.editor,t,e,r,i)))}onBeforeDeleteBlock(t,e,r,i){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new TO(this.editor,t,e,r,i)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new kO(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new RO(this.editor,t,e)))}}class SO{async fromData(t,e){const r=e.getData("text/x-ones-editor-doc");if(r)return{"text/x-ones-editor-doc":JSON.parse(r)}}}class LO{constructor(){m(this,"converters",[]);m(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new SO)}prepareData(t){const e=new DataTransfer;for(let r=0;r<this.converterTypes.length;r++)e.setData(this.converterTypes[r],t.getData(this.converterTypes[r]));return e}async fromData(t,e,r){let i={};const o=this.prepareData(e);for(const s of this.converters){const l=await s.fromData(t,o,r);l&&(i={...i,...l})}return i}addConverter(t){this.converters.push(t)}}function IO(n){n.editorBlocks.registerBlockClass(Nn),n.editorBlocks.registerBlockClass(y3),n.editorBoxes.registerBoxClass(zB),n.editorBoxes.registerBoxClass(GB),n.editorBoxes.registerBoxClass(XB),n.editorBoxes.registerBoxClass(YB),n.editorInsertions.registerInsertionClass(QB),n.editorBlockRenders.registerRender(new Hv)}function DO(n,t){IO(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 Xh=I("range-commands");function F2(n,t){n.forEach(e=>{e.source=t,e.children&&F2(e.children,t)})}function K2(n,t){n.forEach(e=>{e.group=t,e.children&&K2(e.children,t)})}function V2(n,t,e,r){const i=lt(t);p(Xh,i===e.start.blockId,"invalid start range"),p(Xh,i===e.end.blockId,"invalid end range");const o=n.editorCommandProviders.getCommandProviders();let s=[];if(o.forEach(l=>{const c=l.getAvailableCommands(n,t,e);F2(c,r),K2(c,l.id),s.push(...c)}),o.forEach(l=>{if(l.filterCommands){const c=l.filterCommands(n,t,e,s);c&&(s=c)}}),Lt(n,t)){if(!nl(e.start))return s;p(Xh,!e.start.isSimple(),"invalid start pos"),p(Xh,!e.end.isSimple(),"invalid end pos");const l=e.start.childContainerId,c=Ur(n,l),h=fe(c)[0];if(h){const C=dt(n,h),E=Ye(n,{anchor:at(h,0,"home"),focus:at(h,C,"end")}),x=V2(n,h,E,r);s.push(...x)}}return s}function $2(n,t){const e=n.getEditor(),r=n.getSelectedBlocks(),i=[],o=n.isReverse()?r[0]:r[r.length-1],s=Ye(e,{anchor:o.start,focus:o.end});return V2(e,o.block,s,t).forEach(c=>{i.push(c)}),i}function H2(n,t,e,r,i,o){var h;const s=n.editorCommandProviders.getCommandProviders();for(let C=0;C<s.length;C++){const E=s[C];if(E.beforeExecuteCommand&&E.beforeExecuteCommand(n,t,e,r,i))return!1}const l=n.editorCommandProviders.getCommandProvider(r.group),c={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,r,i,{}))return o[lt(t)]=c,!0;let d=!1;return Lt(n,t)&&ba(n,t,e.start,e.end).forEach(E=>{fe(E).forEach(v=>{const R=dt(n,v),w=Ye(n,{anchor:at(v,0,"home"),focus:at(v,R,"end")});H2(n,v,w,r,i,o)&&(d=!0)})}),s.forEach(C=>{C.afterExecuteCommand&&C.afterExecuteCommand(n,t,e,r,i,o)}),d}function j2(n,t,e){const r=n.getEditor(),i={},o=r.editorCommandProviders.getCommandProvider(t.group);return o.executeRangeCommand&&o.executeRangeCommand(r,n,t,e,i)||(n.getSelectedBlocks().forEach(l=>{const c=Ye(r,{anchor:l.start,focus:l.end});H2(r,l.block,c,t,e,i)}),r.focus()),i}const _O=I("command-providers");class z2{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(r=>r.id===t);return p(_O,e,`no command provider, id=${t}`),e}getCommands(t,e){return $2(t,e)}executeCommand(t,e,r){return this.editor.emit("beforeExecCommand",this.editor,e,{source:e.source}),this.editor.undoManager.runInGroup(()=>j2(t,e,r))}getEmptyBlockTextAttributes(t,e){let r={};if(this.providers.forEach(i=>{var s;const o=(s=i.getEmptyBlockTextAttributes)==null?void 0:s.call(i,t,e);o&&(r={...r,...o})}),Object.keys(r).length!==0)return r}}function MO(n,t){const e=rt(t),r=ct(e),i=vt(t);D2(n,r,i)}const G2=I("update-block-text");function UO(n,t,e){const r=n.getBoxById(t.id),i=J(r);p(G2,i,"no parent block"),p(G2,nt(n,i),"not a text block");const o=n.getBlockText(i),s=NB(o,"id",t.id,t);E5(n,i,s,e)}function OO(n,t){for(const e of n.blockHooks)if(e.writable){const r=e.writable(n,t);if(typeof r=="boolean")return r}return!0}function NO(n){if(n.readonly)return!1;const t=Ci(n);return!!n.isBlockWritable(t.map(e=>e.block))}class PO{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 FO{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const r=this.shortcuts;for(const i of r){const o=Object.entries(i);for(const[s,l]of o)if(di(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const so=I("editor");class KO extends ye.TypedEmitter{constructor(e,r,i){var o,s,l,c,d,h,C,E,x;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 FO);m(this,"dataConverter",new LO);m(this,"editorBlocks",new b3(this));m(this,"editorBoxes",new qB(this));m(this,"editorInsertions",new ZB(this));m(this,"editorEmbeds",new B3(this));m(this,"editorDecorators",new t5(this));m(this,"editorCommandProviders",new z2(this));m(this,"editorBlockRenders",new zI(this));m(this,"blockHooks",[]);m(this,"domEvents",new FU(this));m(this,"customs",new Map);m(this,"options");m(this,"version","");m(this,"inputHandlers",new mO(this));m(this,"settingsProvider");m(this,"_readonly",!1);m(this,"getColor",e=>{const r=this.options.colors;return r.length===0?"#FF1A75":r[e%r.length]});so.debug("create editor"),this.setMaxListeners(100),this.options={colors:(o=i==null?void 0:i.colors)!=null?o:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"],componentsOptions:(l=(s=i==null?void 0:i.components)==null?void 0:s.options)!=null?l:{},scrollContainer:i==null?void 0:i.scrollContainer,enableComments:(c=i==null?void 0:i.enableComments)!=null?c:!0,enableContextMenu:(d=i==null?void 0:i.enableContextMenu)!=null?d:!0},this.settingsProvider=(h=i==null?void 0:i.settingsProvider)!=null?h:new PO(this),DO(this,i==null?void 0:i.components),this.blockHooks.push(...(E=(C=i==null?void 0:i.components)==null?void 0:C.blockHooks)!=null?E:[]),this.id=(x=i==null?void 0:i.id)!=null?x:tt(),this.clientId=tt(),this.undoManager=new wO(this),this.doc=new vO(this,r,this.undoManager),this.parent=e,this.rootElement=B("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=B("div",["editor-content"],this.rootElement),this.rootContainerObject=E3(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new rU(this,this.inputHandlers),this.selection=new GU(this),this.selectionHandler=new XU(this),i!=null&&i.shortcuts&&this.shortcuts.shortcuts.push(...i.shortcuts),ie.isMobile&&z(this.rootElement,"mobile"),ie.isSafari&&z(this.rootElement,"safari"),this._readonly&&z(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?z(this.rootElement,"readonly"):ot(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:qe(this.rootContainer)}addCustom(e,r){const i=this.customs.get(e);if(i)return i;const o=r(this);return this.customs.set(e,o),o}getCustom(e){const r=this.customs.get(e);return p(so,r,`${e} does not exists`),r}replaceCustom(e,r){const i=this.customs.get(e);return i&&i.destroy(),this.customs.set(e,r),r}findCustom(e){return this.customs.get(e)}findCustomByType(e){const r=this.customs.values();for(const i of r)if(i instanceof e)return i;return null}destroyCustom(e){const r=this.customs.get(e);r&&(this.customs.delete(e),r.destroy())}getComponentOptions(e){return this.options.componentsOptions[e]}registerLocalEvents(e){this.doc.registerLocalEvents(e)}reload(){this.rootContainerObject.reload(),this.emit("load",this,!0)}createBlock(e,r,i){return this.editorBlocks.createBlock(e,r,i)}createBox(e,r){return this.editorBoxes.createBox(e,r)}createInsertion(e,r){return this.editorInsertions.createInsertion(e,r)}destroy(){so.debug("destroy editor"),this.emit("destroy",this),this.input.destroy(),this.rootContainerObject.destroy(),this.rootElement.remove(),this.doc.destroy(),this.customs.forEach(e=>e.destroy()),this.customs.clear(),this.selection.destroy(),this.domEvents.destroy(),this.removeAllListeners(),this.inputHandlers.destroy()}focus(){this.input.focus()}focusToBlock(e,r){x1(this,e,r)}isWritable(){return NO(this)}isBlockWritable(e){return OO(this,e)}getChildContainerData(e){const r=this.doc.getContainerBlocks(e);return(!r||!Array.isArray(r))&&(p(so,r,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),p(so,Array.isArray(r),`container data is not an array: ${JSON.stringify(r)}`)),r}createChildContainer(e,r,i){return x3(this,e,r,i)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(so,Js(r),"not an valid block element"),r!=null?r:null}findBoxById(e){const r=this.rootContainer.querySelector(`#${e}`);return r&&p(so,sh(r),"not an valid box element"),r!=null?r:null}getBlockById(e){const r=this.findBlockById(e);return p(so,r,`no block, id=${e}`),r}getBoxById(e){const r=this.findBoxById(e);return p(so,r,`no box, id=${e}`),r}getBlockByIndex(e,r){const i=this.getContainerById(e);return zo(i,r)}findBlockByIndex(e,r){const i=this.getContainerById(e);return Pv(i,r)}getBlockIndex(e){if(typeof e=="string"){const r=this.getBlockById(e);return vt(r)}return vt(e)}getContainerById(e){return Ur(this,e)}getParentContainer(e){return rt(e)}reloadBlock(e){MO(this,e)}contains(e){const r=e instanceof Element?e:e.parentElement;return r?r.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,r,i,o,s){const l={blockId:i.id,offset:0},c={anchor:l,focus:l};return Ia(this,e,r,i,o!=null?o:c,s)}insertEmbed(e,r,i,o,s){const l={id:tt(),type:"embed",embedType:i,embedData:o};return this.insertBlock(e,r,l,s)}deleteBlock(e,r){C1(this,e,r)}mergeTextBlock(e,r){return g5(this,e,r)}breakTextBlock(e,r,i){return Da(this,e,r,i).newBlock}getTextPosition(){return Sa(this)}getBlockString(e,r){const i=this.getBlockText(e);return de(i,r)}getBlockData(e){return Zo(this,e)}getBoxData(e){return HB(this,e)}getBlockText(e){return yn(this,e)}setBlockText(e,r){E5(this,e,r)}deleteTextFromBlock(e,r,i,o){return g1(this,e,r,i,o)}insertTextToBlock(e,r,i,o){return c5(this,e,r,i,o)}insertBoxToBlock(e,r,i){return u5(this,e,r,i)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,r,i,o){b5(this,e,r,i,o)}insertDocAt(e,r,i,o){return v1(this,e,r,i,o)}deleteChildContainers(e){m5(this,e)}replaceBlockText(e,r){return Fh(this,e,r)}updateBlockData(e,r,i){const o={...this.getBlockData(e),...r},{id:s,type:l,...c}=o;return Kh(this,e,c,(i!=null?i:this.selection.range).toDocRange())}updateEmbedData(e,r,i){return x5(this,e,r,i)}updateBoxData(e,r){UO(this,e,r)}getSelectedText(){const e=Ma(this);return ts(this,e)}clearSelectedContents(){Ph(this)}insertTextBlock(e,r,i,o){const s=Ai(e!=null?e:"");return h5(this,s,r,i,o==null?void 0:o.newRange,o==null?void 0:o.insertBlockOptions)}updateCompositionText(e,r){if(e&&!r&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!r){m1(this);return}r?(this.compositingText="",Yc()?e||m1(this):h1(this,e)):(this.compositingText=e,f5(this))}}function Mu(n,t,e){return new KO(n,t,e)}function VO(n){const t=(r,i)=>{const o=r.findIndex(l=>l.id===i.id);if(o===-1){r.push(i);return}const s=r[o];if(s.value!==i.value){r.splice(o,1);return}if(!!s.states){if(!i.states){s.states=[];return}s.states=Ng.default(s.states,i.states)}},e=[];return n.forEach(r=>{r.forEach(i=>{t(e,i)})}),e}const $O=["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"];class Uu extends ye.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:$O}setCursor(e){this.addUser(e.user);const r=this.cursors.get(e.user.userId);if(r&&Xc.default(r,e))return;this.cursors.set(e.user.userId,e);const i=new Set([e.range.anchor.blockId,e.range.focus.blockId]),o=new Set(i);r&&new Set([r.range.anchor.blockId,r.range.focus.blockId]).forEach(l=>{i.has(l)||o.add(l)}),this.emit("remote-carets-change",[...o])}addUsers(e){this.addingUser=!0,e.forEach(r=>this.addUser(r)),this.addingUser=!1,this.emit("change",Array.from(this.users.values()))}addUser(e){this.users.set(e.userId,e),this.addingUser||this.emit("change",Array.from(this.users.values()))}findUser(e){var r;return(r=this.users.get(e))!=null?r:null}removeUser(e){this.users.delete(e),this.emit("change",Array.from(this.users.values()));const r=this.cursors.get(e);if(r){const i=new Set(new Set([r==null?void 0:r.range.anchor.blockId,r==null?void 0:r.range.focus.blockId]));this.cursors.delete(e),this.emit("remote-carets-change",[...i])}}updateUsers(e){this.users.forEach(r=>{e.find(i=>i.userId===r.userId)||this.removeUser(r.userId)}),this.users.clear(),this.addingUser=!0;try{e.forEach(r=>{this.addUser(r)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const r=new Map;return Array.from(this.cursors.values()).filter(i=>i.range.anchor.blockId===e&&kh(i.range)).forEach(i=>{const o=i.range.focus.offset;let s=r.get(o);s||(s=[],r.set(o,s)),s.push(i)}),r}getCursors(e){return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e||r.range.focus.blockId===e)}onUpdateBlockText(e,r,i){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(kh(l.range)){const{anchor:c,focus:d}=l.range;c.blockId===e.id&&(c.offset=pn.transformCursor(c.offset,r,i)),d.blockId===e.id&&(d.offset=pn.transformCursor(d.offset,r,i))}})}getFixedUserColor(e,r){let i=0;Array.from(e).forEach(s=>{i+=s.charCodeAt(0)});const o=i%this.colors.length;return this.colors[o]}destroy(){this.removeAllListeners()}}const an=I("local-doc");class K1 extends ma{constructor(e,r){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[Ai("")]}},this.serviceUrl=(r==null?void 0:r.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}findContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,r){const i=this.getContainerBlocks(e);p(an,i,`no container data: ${e}`);const o=i[r];return p(an,o,`no block data: ${r}`),o}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(an,o.text,"no text for data");const s=pn.apply(o.text,i);return o.text=s,p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var c;return(c=l.onUpdateBlockText)==null?void 0:c.call(l,e,r,i,!0)}),s}localUpdateBlockData(e,r,i){const o=this.getBlockData(e,r);return i.delete.forEach(s=>delete o[s]),Object.entries(i.insert).forEach(([s,l])=>{o[s]=l}),p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,r,i,!0)}),o}localInsertBlock(e,r,i){const o=this.getContainerBlocks(e);return p(an,o,`no container data: ${e}`),p(an,r>=0&&r<=o.length,`invalid block index: ${r}, ${o.length}`),o.splice(r,0,i),p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,r,i,!0)}),i}localDeleteBlock(e,r){const i=this.getContainerBlocks(e);p(an,i,`no container data: ${e}`),p(an,r>=0&&r<=i.length,`invalid block index: ${r}, ${i.length}`);const o=i[r];return i.splice(r,1),p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,r,!0)}),o}localInsertChildContainers(e){e.forEach(({containerId:r,blocks:i})=>{this.doc.blocks[r]=i,p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,r,i,!0)})})}localDeleteChildContainers(e){an.debug(`delete child containers: ${e}`),e.forEach(r=>{p(an,this.doc.blocks[r],`no child container: ${r}`),delete this.doc.blocks[r]}),e.forEach(r=>{p(an,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,r,!0)})})}uploadResource(e,r){p(an,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,r){p(an,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new Uu}setDoc(e){this.doc=mt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,"change doc")})}destroy(){this.clearCallbacks()}}class HO{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function V1(n,t,e){n.addCustom(t,()=>{var o;const r=(o=e())!=null?o:void 0;return new HO(r)})}const W2=I("find-block");function q2(n,t){const e=mr(t);if(!e){if(pr(t))return null;const r=Zs(t);return p(W2,r,"no parent block"),q2(n,r)}return Lt(n,e)?va(n,e,{visibleOnly:!0}):e}function X2(n,t){const e=gr(t);if(!e){if(pr(t))return null;const r=Zs(t);return p(W2,r,"no parent block"),X2(n,r)}return Lt(n,e)?Tp(n,e,{visibleOnly:!0}):e}const jO=I("remote-cursor");class zO{constructor(){m(this,"remoteUsers",new Uu)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const r=e;this.handleUpdateUsers(r.users)}else e.type==="caret"?this.handleUpdateCaret(e):jO.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 GO(n){const{blocks:t,meta:e,comments:r,...i}=n;return{rootBlocks:t,meta:e,comments:r,childBlocks:i}}function WO(n){const{blocks:t,meta:e,comments:r}=n,{root:i,...o}=t;return{blocks:i,meta:e,comments:r,...o}}function lo(n){const{childBlocks:t,meta:e,comments:r,rootBlocks:i}=GO(mt.default(n));return{blocks:{root:i,...t},meta:e,comments:r}}function ao(n){return n==="root"?"blocks":n}function Na(n){return n==="blocks"?"root":n}const qO={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new mn.default(n)},apply(n,t){const e=new mn.default(n),r=new mn.default(t);return e.compose(r).ops},compose(n,t){const e=new mn.default(n),r=new mn.default(t);return e.compose(r).ops},diff(n,t){const e=new mn.default(n),r=new mn.default(t);return e.diff(r).ops},transform(n,t,e){const r=new mn.default(n);return new mn.default(t).transform(r,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const r=new mn.default(t),i=this.transformCursor(n.index,r,e),o=this.transformCursor(n.index+n.length,r,e);return{...n,index:i,length:o-i}}}};var os={},$1=Og.default.EventEmitter;os.EventEmitter=$1,os.mixin=XO;function XO(n){for(var t in $1.prototype)n.prototype[t]=$1.prototype[t]}var Y2=["info","warn","error"];function Q2(){var n={};Y2.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var YO=Q2;Q2.prototype.setMethods=function(n){n=n||{};var t=this;Y2.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var QO=YO,JO=new QO,J2=JO;function fl(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,fl):this.stack=new Error().stack}fl.prototype=Object.create(Error.prototype),fl.prototype.constructor=fl,fl.prototype.name="ShareDBError",fl.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_FIXUP_IS_ONLY_VALID_ON_APPLY:"ERR_FIXUP_IS_ONLY_VALID_ON_APPLY",ERR_CANNOT_FIXUP_DELETION:"ERR_CANNOT_FIXUP_DELETION",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_CHANNEL_MISSING:"ERR_QUERY_CHANNEL_MISSING",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE:"ERR_TYPE_DOES_NOT_SUPPORT_COMPOSE",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var Yh=fl,Ou={},Z2=ZO;function ZO(n,t,e,r){var i=function(s,l,c,d){t(c,s,l,"left"),t(d,l,s,"right")},o=n.transformX=function(s,l){e(s),e(l);for(var c=[],d=0;d<l.length;d++){for(var h=l[d],C=[],E=0;E<s.length;){var x=[];if(i(s[E],h,C,x),E++,x.length===1)h=x[0];else if(x.length===0){for(var v=E;v<s.length;v++)r(C,s[v]);h=null;break}else{for(var R=o(s.slice(E),x),w=0;w<R[0].length;w++)r(C,R[0][w]);for(var U=0;U<R[1].length;U++)r(c,R[1][U]);h=null;break}}h!=null&&r(c,h),s=C}return[s,c]};n.transform=function(s,l,c){if(!(c==="left"||c==="right"))throw new Error("type must be 'left' or 'right'");return l.length===0?s:s.length===1&&l.length===1?t([],s[0],l[0],c):c==="left"?o(s,l)[0]:o(l,s)[1]}}var tT={exports:{}},ss=tT.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||""}},H1=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},j1=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")},Qh=function(n){for(var t=0;t<n.length;t++)j1(n[t])};ss.apply=function(n,t){var e;Qh(t);for(var r=0;r<t.length;r++){var i=t[r];if(i.i!=null)n=H1(n,i.p,i.i);else{if(e=n.slice(i.p,i.p+i.d.length),i.d!==e)throw new Error("Delete component '"+i.d+"' does not match deleted text '"+e+"'");n=n.slice(0,i.p)+n.slice(i.p+i.d.length)}}return n};var co=ss._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:H1(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:H1(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};ss.compose=function(n,t){Qh(n),Qh(t);for(var e=n.slice(),r=0;r<t.length;r++)co(e,t[r]);return e},ss.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=0),co(t,r)}return t};var z1=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};ss.transformCursor=function(n,t,e){for(var r=e==="right",i=0;i<t.length;i++)n=z1(n,t[i],r);return n};var tN=ss._tc=function(n,t,e,r){if(j1(t),j1(e),t.i!=null)co(n,{i:t.i,p:z1(t.p,e,r==="right")});else if(e.i!=null){var i=t.d;t.p<e.p&&(co(n,{d:i.slice(0,e.p-t.p),p:t.p}),i=i.slice(e.p-t.p)),i!==""&&co(n,{d:i,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)co(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)co(n,t);else{var o={d:"",p:t.p};t.p<e.p&&(o.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(o.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),c=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(c!==d)throw new Error("Delete ops delete different text in the same region of the document");o.d!==""&&(o.p=z1(o.p,e),co(n,o))}return n},eN=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};ss.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=eN(n[t]);return n},Z2(ss,tN,Qh,co);var Jh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},nN=function(n){return!!n&&n.constructor===Object},zr=function(n){return JSON.parse(JSON.stringify(n))},Dt={name:"json0",uri:"http://sharejs.org/types/JSONv0"},uo={};Dt.registerSubtype=function(n){uo[n.name]=n},Dt.create=function(n){return n===void 0?null:zr(n)},Dt.invertComponent=function(n){var t={p:n.p};return n.t&&uo[n.t]&&(t.t=n.t,t.o=uo[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},Dt.invert=function(n){for(var t=n.slice().reverse(),e=[],r=0;r<t.length;r++)e.push(Dt.invertComponent(t[r]));return e},Dt.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!Jh(n[t].p))throw new Error("Missing path")},Dt.checkList=function(n){if(!Jh(n))throw new Error("Referenced element not a list")},Dt.checkObj=function(n){if(!nN(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function Nu(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 Pu(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}Dt.apply=function(n,t){Dt.checkValidOp(t),t=zr(t);for(var e={data:n},r=0;r<t.length;r++){var i=t[r];(i.si!=null||i.sd!=null)&&Nu(i);for(var o=null,s=e,l="data",c=0;c<i.p.length;c++){var d=i.p[c];if(o=s,s=s[l],l=d,o==null)throw new Error("Path invalid")}if(i.t&&i.o!==void 0&&uo[i.t])s[l]=uo[i.t].apply(s[l],i.o);else if(i.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=i.na}else if(i.li!==void 0&&i.ld!==void 0)Dt.checkList(s),s[l]=i.li;else if(i.li!==void 0)Dt.checkList(s),s.splice(l,0,i.li);else if(i.ld!==void 0)Dt.checkList(s),s.splice(l,1);else if(i.lm!==void 0){if(Dt.checkList(s),i.lm!=l){var h=s[l];s.splice(l,1),s.splice(i.lm,0,h)}}else if(i.oi!==void 0)Dt.checkObj(s),s[l]=i.oi;else if(i.od!==void 0)Dt.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},Dt.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},Dt.incrementalApply=function(n,t,e){for(var r=0;r<t.length;r++){var i=[t[r]];n=Dt.apply(n,i),e(i,n)}return n};var rN=Dt.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var r=0;r<n.length;r++)if(n[r]!==t[r]&&(!e||r!==n.length-1))return!1;return!0};Dt.append=function(n,t){if(t=zr(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)&&(Nu(t),Nu(e)),rN(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&uo[t.t]){if(e.o=uo[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var r=t.p,i=0;i<e.o.length-1;i++)t.o=[e.o.pop()],t.p=r.slice(),Pu(t),n.push(t);Pu(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)&&(Pu(t),Pu(e)),n.push(t)},Dt.compose=function(n,t){Dt.checkValidOp(n),Dt.checkValidOp(t);for(var e=zr(n),r=0;r<t.length;r++)Dt.append(e,t[r]);return e},Dt.normalize=function(n){var t=[];n=Jh(n)?n:[n];for(var e=0;e<n.length;e++){var r=n[e];r.p==null&&(r.p=[]),Dt.append(t,r)}return t},Dt.commonLengthForOps=function(n,t){var e=n.p.length,r=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&r++,e===0)return-1;if(r===0)return null;e--,r--;for(var i=0;i<e;i++){var o=n.p[i];if(i>=r||o!==t.p[i])return null}return e},Dt.canOpAffectPath=function(n,t){return Dt.commonLengthForOps({p:t},n)!=null},Dt.transformComponent=function(n,t,e,r){t=zr(t);var i=Dt.commonLengthForOps(e,t),o=Dt.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,o!=null&&l>s&&t.p[o]==e.p[o]){if(t.ld!==void 0){var c=zr(e);c.p=c.p.slice(s),t.ld=Dt.apply(zr(t.ld),[c])}else if(t.od!==void 0){var c=zr(e);c.p=c.p.slice(s),t.od=Dt.apply(zr(t.od),[c])}}if(i!=null){var d=s==l,c=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(Nu(t),c=zr(e),Nu(c)),c.t&&uo[c.t]){if(t.t&&t.t===c.t){var h=uo[t.t].transform(t.o,c.o,r);if(t.si!=null||t.sd!=null)for(var C=t.p,E=0;E<h.length;E++)t.o=[h[E]],t.p=C.slice(),Pu(t),Dt.append(n,t);else(!Jh(h)||h.length>0)&&(t.o=h,Dt.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[i]===t.p[i])if(d){if(t.ld!==void 0)if(t.li!==void 0&&r==="left")t.ld=zr(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&d&&t.p[i]===e.p[i]?r==="right"&&t.p[i]++:e.p[i]<=t.p[i]&&t.p[i]++,t.lm!==void 0&&d&&e.p[i]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[i]===t.p[i])return n;var C=e.p[i],x=t.p[i],v=t.lm;(C<v||C===v&&x<v)&&t.lm--}if(e.p[i]<t.p[i])t.p[i]--;else if(e.p[i]===t.p[i]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var x=t.p[i],v=t.lm,R=e.p[i],w=e.lm;if(R!==w)if(x===R)if(r==="left")t.p[i]=w,x===v&&(t.lm=w);else return n;else x>R&&t.p[i]--,x>w?t.p[i]++:x===w&&R>w&&(t.p[i]++,x===v&&t.lm++),(v>R||v===R&&v>x)&&t.lm--,v>w?t.lm++:v===w&&(w>R&&v>x||w<R&&v<x?r==="right"&&t.lm++:v>x?t.lm++:v===R&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var x=e.p[i],v=e.lm;C=t.p[i],C>x&&t.p[i]--,C>v&&t.p[i]++}else{var x=e.p[i],v=e.lm;C=t.p[i],C===x?t.p[i]=v:(C>x&&t.p[i]--,(C>v||C===v&&x>v)&&t.p[i]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[i]===e.p[i])if(t.oi!==void 0&&d){if(r==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[i]===e.p[i])if(r==="left")Dt.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[i]==e.p[i]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return Dt.append(n,t),n},Z2(Dt,Dt.transformComponent,Dt.checkValidOp,Dt.append);var iN=tT.exports;Dt.registerSubtype(iN);var oN=Dt,sN={type:oN};(function(n){n.defaultType=sN.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)})(Ou);var xr={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var r in e)return!0;return!1},n.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e},n.isValidVersion=function(e){return e===null?!0:n.isInteger(e)&&e>=0},n.isValidTimestamp=function(e){return n.isValidVersion(e)},n.MAX_SAFE_INTEGER=9007199254740991,n.dig=function(){for(var e=arguments[0],r=1;r<arguments.length;r++){var i=arguments[r];e=e[i]||(r===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],r=arguments[arguments.length-1],i=1;i<arguments.length-1;i++){var o=arguments[i];e=e[o]||(e[o]=i===arguments.length-2?r():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],r=[e],i=1;i<arguments.length-1;i++){var o=arguments[i];if(!e.hasOwnProperty(o))break;e=e[o],r.push(e)}for(var i=r.length-1;i>=0;i--){var s=r[i],o=arguments[i+1],l=s[o];(i===r.length-1||!n.hasKeys(l))&&delete s[o]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,r){var i=!1;return e.forEach(function(o){o&&(o(r),i=!0)}),i},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];setTimeout(function(){e.apply(null,r)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(xr);var eT=Array.isArray,nT=Object.keys,lN=Object.prototype.hasOwnProperty,aN=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=eT(t),i=eT(e),o,s,l;if(r&&i){if(s=t.length,s!=e.length)return!1;for(o=s;o--!==0;)if(!n(t[o],e[o]))return!1;return!0}if(r!=i)return!1;var c=t instanceof Date,d=e instanceof Date;if(c!=d)return!1;if(c&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,C=e instanceof RegExp;if(h!=C)return!1;if(h&&C)return t.toString()==e.toString();var E=nT(t);if(s=E.length,s!==nT(e).length)return!1;for(o=s;o--!==0;)if(!lN.call(e,E[o]))return!1;for(o=s;o--!==0;)if(l=E[o],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},ls={};ls.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",fixup:"fixup",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var rT=os,cN=J2,tr=Yh,Zh=Ou,Gr=xr,uN=Gr.clone,fN=aN,G1=ls.ACTIONS,Pn=tr.CODES,dN=Kt;function Kt(n,t,e){rT.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}rT.mixin(Kt),Kt.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())})},Kt.prototype._setType=function(n){if(typeof n=="string"&&(n=Zh.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new tr(Pn.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Kt.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Kt.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new tr(Pn.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 tr(Pn.ERR_DOC_MISSING_VERSION,"Cannot ingest snapshot in doc with null version. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}return n.v>this.version?this.fetch(t):t&&t()}if(this.version>n.v)return t&&t();this.version=n.v;var r=n.type===void 0?Zh.defaultType:n.type;this._setType(r),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},Kt.prototype.whenNothingPending=function(n){var t=this;Gr.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Kt.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Kt.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Kt.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Kt.prototype._emitResponseError=function(n,t){if(n&&n.code===Pn.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)},Kt.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var r=this.inflightFetch.shift();if(r&&e.push(r),e.length&&(r=function(i){Gr.callEach(e,i)}),n)return this._emitResponseError(n,r);this.ingestSnapshot(t,r),this._emitNothingPending()},Kt.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var r=this.pendingFetch;this.pendingFetch=[],e.callback&&r.push(e.callback);var i;if(r.length&&(i=function(o){Gr.callEach(r,o)}),n)return this._emitResponseError(n,i);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,i):i&&i(),this._emitNothingPending(),this._flushSubscribe()},Kt.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Pn.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=Fu(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var r=0;r<this.pendingOps.length;r++){var e=Fu(this.pendingOps[r],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}}},Kt.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))},Kt.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()},Kt.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);hN(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Kt.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Kt.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Kt.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,r=e&&e.wantSubscribe===n;if(r){e.callback=mN([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Kt.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;Gr.nextTick(function(){n._handleSubscribe()})}}};function hN(n,t,e){if(t){var r=n.pop();n.push(function(i){r&&r(i),e&&e(i)})}else n.push(e)}function mN(n){return n=n.filter(Gr.truthy),n.length?function(t){Gr.callEach(n,t)}:null}Kt.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function gN(n){delete n.op,delete n.create,delete n.del}function Fu(n,t){if(n.del)return gN(t);if(t.del)return new tr(Pn.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new tr(Pn.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new tr(Pn.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var r=n.type.transform(n.op,t.op,"left"),i=n.type.transform(t.op,n.op,"right");n.op=r,t.op=i}}}Kt.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new tr(Pn.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===Zh.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,r=0;r<n.op.length;r++){var i=n.op[r],o={op:[i]};this.emit("before op",o.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=Fu(this.applyStack[s],o);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,o.op)),this.emit("op",o.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var c=this.data;this._setType(null),this.emit("del",c,t);return}},Kt.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 tr(Pn.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>=Gr.MAX_SAFE_INTEGER)return this.emit("error",new tr(Pn.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)}},Kt.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var r=new tr(Pn.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(r):this.emit("error",r)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(o){return this._hardRollback(o)}var i=this;Gr.nextTick(function(){i.flush()})},Kt.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var r=this._tryCompose(n);if(r){r.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},Kt.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var r=this.pendingOps.splice(e),e=0;e<r.length;e++){var t=r[e],i=this._tryCompose(t);i?i.callbacks=i.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},Kt.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!fN(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}}},Kt.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var r={op:n},i=t&&t.source;this._submit(r,i,e)},Kt.prototype.create=function(n,t,e,r){if(typeof t=="function"?(r=t,e=null,t=null):typeof e=="function"&&(r=e,e=null),t||(t=Zh.defaultType.uri),this.type){var i=new tr(Pn.ERR_DOC_ALREADY_CREATED,"Document already exists");return r?r(i):this.emit("error",i)}var o={create:{type:t,data:n}},s=e&&e.source;this._submit(o,s,r)},Kt.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new tr(Pn.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var r={del:!0},i=n&&n.source;this._submit(r,i,t)},Kt.prototype.pause=function(){this.paused=!0},Kt.prototype.resume=function(){this.paused=!1,this.flush()},Kt.prototype.toSnapshot=function(){return{v:this.version,data:uN(this.data),type:this.type.uri}},Kt.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return cN.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();if(n[G1.fixup])for(var t=0;t<n[G1.fixup].length;t++){for(var e=n[G1.fixup][t],r=0;r<this.pendingOps.length;r++){var i=Fu(this.pendingOps[t],e);if(i)return this._hardRollback(i)}try{this._otApply(e,!1)}catch(o){return this._hardRollback(o)}}this.version++,this._clearInflightOp()},Kt.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var r=Fu(this.pendingOps[e],t);if(r)return this._hardRollback(r)}try{this._otApply(t,!1)}catch(i){return this._hardRollback(i)}this._clearInflightOp(n);return}this._hardRollback(n)},Kt.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var r=!!t.length,i=0;i<t.length;i++)r=Gr.callEach(t[i].callbacks,n)&&r;if(n&&!r)return e.emit("error",n)})},Kt.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=Gr.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var iT=os,oT=ls.ACTIONS,pN=xr,CN=Fn;function Fn(n,t,e,r,i,o,s){iT.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=r,this.query=i,this.results=null,o&&o.results&&(this.results=o.results,delete o.results),this.extra=void 0,this.options=o,this.callback=s,this.ready=!1,this.sent=!1}iT.mixin(Fn),Fn.prototype.hasPending=function(){return!this.ready},Fn.prototype.send=function(){if(!!this.connection.canSend){var n={a:this.action,id:this.id,c:this.collection,q:this.query};if(this.options&&(n.o=this.options),this.results){for(var t=[],e=0;e<this.results.length;e++){var r=this.results[e];t.push([r.id,r.version])}n.r=t}this.connection.send(n),this.sent=!0}},Fn.prototype.destroy=function(n){this.connection.canSend&&this.action===oT.querySubscribe&&this.connection.send({a:oT.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&pN.nextTick(n)},Fn.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},Fn.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},Fn.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},Fn.prototype._handleResponse=function(n,t,e){var r=this.callback;if(this.callback=null,n)return this._finishResponse(n,r);if(!t)return this._finishResponse(null,r);var i=this,o=1,s=function(h){if(h)return i._finishResponse(h,r);--o||i._finishResponse(null,r)};if(Array.isArray(t))o+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){o++;var c=t[l],d=this.connection.get(c.c||this.collection,l);d.ingestSnapshot(c,s)}s()},Fn.prototype._ingestSnapshots=function(n,t){for(var e=[],r=0;r<n.length;r++){var i=n[r],o=this.connection.get(i.c||this.collection,i.d);o.ingestSnapshot(i,t),e.push(o)}return e},Fn.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)},Fn.prototype._handleError=function(n){this.emit("error",n)},Fn.prototype._handleDiff=function(n){for(var t=0;t<n.length;t++){var e=n[t];e.type==="insert"&&(e.values=this._ingestSnapshots(e.values))}for(var t=0;t<n.length;t++){var e=n[t];switch(e.type){case"insert":var r=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(r)),this.emit("insert",r,e.index);break;case"remove":var o=e.howMany||1,i=this.results.splice(e.index,o);this.emit("remove",i,e.index);break;case"move":var o=e.howMany||1,s=this.results.splice(e.from,o);Array.prototype.splice.apply(this.results,[e.to,0].concat(s)),this.emit("move",s,e.from,e.to);break}}this.emit("changed",this.results)},Fn.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var sT=os,EN=ls.ACTIONS,xN=xr,lT=vi;function vi(n,t){if(sT.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={}}sT.mixin(vi),vi.prototype.submit=function(n,t){this.value=n,this.send(t)},vi.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},vi.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()})},vi.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},vi.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},vi.prototype._message=function(){return{a:EN.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},vi.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},vi.prototype._callbackOrEmit=function(n,t){if(t)return xN.nextTick(t,n);n&&this.emit("error",n)};var AN=xr,aT=W1;function W1(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}W1.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},W1.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&AN.nextTick(n)};var q1={exports:{}};(function(n,t){(function(e,r){r(t)})(Un,function(e){function r(y,L){L=L|0;for(var _=Math.max(y.length-L,0),N=Array(_),H=0;H<_;H++)N[H]=y[L+H];return N}var i=function(y){var L=r(arguments,1);return function(){var _=r(arguments);return y.apply(null,L.concat(_))}},o=function(y){return function(){var L=r(arguments),_=L.pop();y.call(this,L,_)}};function s(y){var L=typeof y;return y!=null&&(L=="object"||L=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function d(y){setTimeout(y,0)}function h(y){return function(L){var _=r(arguments,1);y(function(){L.apply(null,_)})}}var C;l?C=setImmediate:c?C=process.nextTick:C=d;var E=h(C);function x(y){return o(function(L,_){var N;try{N=y.apply(this,L)}catch(H){return _(H)}s(N)&&typeof N.then=="function"?N.then(function(H){v(_,null,H)},function(H){v(_,H.message?H:new Error(H))}):_(null,N)})}function v(y,L,_){try{y(L,_)}catch(N){E(R,N)}}function R(y){throw y}var w=typeof Symbol=="function";function U(y){return w&&y[Symbol.toStringTag]==="AsyncFunction"}function M(y){return U(y)?x(y):y}function F(y){return function(L){var _=r(arguments,1),N=o(function(H,$){var X=this;return y(L,function(Z,ut){M(Z).apply(X,H.concat(ut))},$)});return _.length?N.apply(this,_):N}}var G=typeof Un=="object"&&Un&&Un.Object===Object&&Un,q=typeof self=="object"&&self&&self.Object===Object&&self,it=G||q||Function("return this")(),st=it.Symbol,Et=Object.prototype,gt=Et.hasOwnProperty,xt=Et.toString,Vt=st?st.toStringTag:void 0;function Gt(y){var L=gt.call(y,Vt),_=y[Vt];try{y[Vt]=void 0;var N=!0}catch{}var H=xt.call(y);return N&&(L?y[Vt]=_:delete y[Vt]),H}var fn=Object.prototype,Be=fn.toString;function Vn(y){return Be.call(y)}var Ui="[object Null]",wn="[object Undefined]",An=st?st.toStringTag:void 0;function Oi(y){return y==null?y===void 0?wn:Ui:An&&An in Object(y)?Gt(y):Vn(y)}var Co="[object AsyncFunction]",Tr="[object Function]",qx="[object GeneratorFunction]",Xx="[object Proxy]";function Yx(y){if(!s(y))return!1;var L=Oi(y);return L==Tr||L==qx||L==Co||L==Xx}var ks=9007199254740991;function Sl(y){return typeof y=="number"&&y>-1&&y%1==0&&y<=ks}function Ll(y){return y!=null&&Sl(y.length)&&!Yx(y)}var Eo={};function jt(){}function Ni(y){return function(){if(y!==null){var L=y;y=null,L.apply(this,arguments)}}}var Rs=typeof Symbol=="function"&&Symbol.iterator,vc=function(y){return Rs&&y[Rs]&&y[Rs]()};function wm(y,L){for(var _=-1,N=Array(y);++_<y;)N[_]=L(_);return N}function bn(y){return y!=null&&typeof y=="object"}var Il="[object Arguments]";function Sm(y){return bn(y)&&Oi(y)==Il}var yr=Object.prototype,Lm=yr.hasOwnProperty,Qx=yr.propertyIsEnumerable,Dl=Sm(function(){return arguments}())?Sm:function(y){return bn(y)&&Lm.call(y,"callee")&&!Qx.call(y,"callee")},we=Array.isArray;function _l(){return!1}var Ml=typeof e=="object"&&e&&!e.nodeType&&e,Im=Ml&&!0&&n&&!n.nodeType&&n,Ul=Im&&Im.exports===Ml,Dm=Ul?it.Buffer:void 0,Ol=Dm?Dm.isBuffer:void 0,ws=Ol||_l,Hf=9007199254740991,jf=/^(?:0|[1-9]\d*)$/;function zf(y,L){var _=typeof y;return L=L==null?Hf:L,!!L&&(_=="number"||_!="symbol"&&jf.test(y))&&y>-1&&y%1==0&&y<L}var Gf="[object Arguments]",Wf="[object Array]",qf="[object Boolean]",Xf="[object Date]",Yf="[object Error]",Qf="[object Function]",Jx="[object Map]",Zx="[object Number]",tA="[object Object]",_m="[object RegExp]",Mm="[object Set]",eA="[object String]",nA="[object WeakMap]",rA="[object ArrayBuffer]",iA="[object DataView]",Um="[object Float32Array]",oA="[object Float64Array]",sA="[object Int8Array]",lA="[object Int16Array]",Jf="[object Int32Array]",aA="[object Uint8Array]",Zf="[object Uint8ClampedArray]",cA="[object Uint16Array]",uA="[object Uint32Array]",he={};he[Um]=he[oA]=he[sA]=he[lA]=he[Jf]=he[aA]=he[Zf]=he[cA]=he[uA]=!0,he[Gf]=he[Wf]=he[rA]=he[qf]=he[iA]=he[Xf]=he[Yf]=he[Qf]=he[Jx]=he[Zx]=he[tA]=he[_m]=he[Mm]=he[eA]=he[nA]=!1;function fA(y){return bn(y)&&Sl(y.length)&&!!he[Oi(y)]}function dA(y){return function(L){return y(L)}}var Om=typeof e=="object"&&e&&!e.nodeType&&e,Nl=Om&&!0&&n&&!n.nodeType&&n,hA=Nl&&Nl.exports===Om,Bc=hA&&G.process,Nm=function(){try{var y=Nl&&Nl.require&&Nl.require("util").types;return y||Bc&&Bc.binding&&Bc.binding("util")}catch{}}(),Pm=Nm&&Nm.isTypedArray,mA=Pm?dA(Pm):fA,gA=Object.prototype,pA=gA.hasOwnProperty;function CA(y,L){var _=we(y),N=!_&&Dl(y),H=!_&&!N&&ws(y),$=!_&&!N&&!H&&mA(y),X=_||N||H||$,Z=X?wm(y.length,String):[],ut=Z.length;for(var At in y)(L||pA.call(y,At))&&!(X&&(At=="length"||H&&(At=="offset"||At=="parent")||$&&(At=="buffer"||At=="byteLength"||At=="byteOffset")||zf(At,ut)))&&Z.push(At);return Z}var Tc=Object.prototype;function EA(y){var L=y&&y.constructor,_=typeof L=="function"&&L.prototype||Tc;return y===_}function yc(y,L){return function(_){return y(L(_))}}var xA=yc(Object.keys,Object),AA=Object.prototype,bA=AA.hasOwnProperty;function Fm(y){if(!EA(y))return xA(y);var L=[];for(var _ in Object(y))bA.call(y,_)&&_!="constructor"&&L.push(_);return L}function kc(y){return Ll(y)?CA(y):Fm(y)}function Km(y){var L=-1,_=y.length;return function(){return++L<_?{value:y[L],key:L}:null}}function vA(y){var L=-1;return function(){var N=y.next();return N.done?null:(L++,{value:N.value,key:L})}}function BA(y){var L=kc(y),_=-1,N=L.length;return function H(){var $=L[++_];return $==="__proto__"?H():_<N?{value:y[$],key:$}:null}}function TA(y){if(Ll(y))return Km(y);var L=vc(y);return L?vA(L):BA(y)}function kr(y){return function(){if(y===null)throw new Error("Callback was already called.");var L=y;y=null,L.apply(this,arguments)}}function Pl(y){return function(L,_,N){if(N=Ni(N||jt),y<=0||!L)return N(null);var H=TA(L),$=!1,X=0,Z=!1;function ut(ft,Bt){if(X-=1,ft)$=!0,N(ft);else{if(Bt===Eo||$&&X<=0)return $=!0,N(null);Z||At()}}function At(){for(Z=!0;X<y&&!$;){var ft=H();if(ft===null){$=!0,X<=0&&N(null);return}X+=1,_(ft.value,ft.key,kr(ut))}Z=!1}At()}}function Pi(y,L,_,N){Pl(L)(y,M(_),N)}function Ge(y,L){return function(_,N,H){return y(_,L,N,H)}}function td(y,L,_){_=Ni(_||jt);var N=0,H=0,$=y.length;$===0&&_(null);function X(Z,ut){Z?_(Z):(++H===$||ut===Eo)&&_(null)}for(;N<$;N++)L(y[N],N,kr(X))}var yA=Ge(Pi,1/0),ri=function(y,L,_){var N=Ll(y)?td:yA;N(y,M(L),_)};function ii(y){return function(L,_,N){return y(ri,L,M(_),N)}}function ed(y,L,_,N){N=N||jt,L=L||[];var H=[],$=0,X=M(_);y(L,function(Z,ut,At){var ft=$++;X(Z,function(Bt,te){H[ft]=te,At(Bt)})},function(Z){N(Z,H)})}var Rc=ii(ed),nd=F(Rc);function xo(y){return function(L,_,N,H){return y(Pl(_),L,M(N),H)}}var Fi=xo(ed),rd=Ge(Fi,1),id=F(rd);function Ss(y,L){for(var _=-1,N=y==null?0:y.length;++_<N&&L(y[_],_,y)!==!1;);return y}function od(y){return function(L,_,N){for(var H=-1,$=Object(L),X=N(L),Z=X.length;Z--;){var ut=X[y?Z:++H];if(_($[ut],ut,$)===!1)break}return L}}var Ls=od();function Is(y,L){return y&&Ls(y,L,kc)}function Vm(y,L,_,N){for(var H=y.length,$=_+(N?1:-1);N?$--:++$<H;)if(L(y[$],$,y))return $;return-1}function kA(y){return y!==y}function $m(y,L,_){for(var N=_-1,H=y.length;++N<H;)if(y[N]===L)return N;return-1}function Fl(y,L,_){return L===L?$m(y,L,_):Vm(y,kA,_)}var wc=function(y,L,_){typeof L=="function"&&(_=L,L=null),_=Ni(_||jt);var N=kc(y),H=N.length;if(!H)return _(null);L||(L=H);var $={},X=0,Z=!1,ut=Object.create(null),At=[],ft=[],Bt={};Is(y,function(Ce,ue){if(!we(Ce)){te(ue,[Ce]),ft.push(ue);return}var Te=Ce.slice(0,Ce.length-1),wr=Te.length;if(wr===0){te(ue,Ce),ft.push(ue);return}Bt[ue]=wr,Ss(Te,function(k){if(!y[k])throw new Error("async.auto task `"+ue+"` has a non-existent dependency `"+k+"` in "+Te.join(", "));dn(k,function(){wr--,wr===0&&te(ue,Ce)})})}),qA(),Pe();function te(Ce,ue){At.push(function(){Rr(Ce,ue)})}function Pe(){if(At.length===0&&X===0)return _(null,$);for(;At.length&&X<L;){var Ce=At.shift();Ce()}}function dn(Ce,ue){var Te=ut[Ce];Te||(Te=ut[Ce]=[]),Te.push(ue)}function jn(Ce){var ue=ut[Ce]||[];Ss(ue,function(Te){Te()}),Pe()}function Rr(Ce,ue){if(!Z){var Te=kr(function(k,$i){if(X--,arguments.length>2&&($i=r(arguments,1)),k){var Us={};Is($,function(zn,$t){Us[$t]=zn}),Us[Ce]=$i,Z=!0,ut=Object.create(null),_(k,Us)}else $[Ce]=$i,jn(Ce)});X++;var wr=M(ue[ue.length-1]);ue.length>1?wr($,Te):wr(Te)}}function qA(){for(var Ce,ue=0;ft.length;)Ce=ft.pop(),ue++,Ss(XA(Ce),function(Te){--Bt[Te]===0&&ft.push(Te)});if(ue!==H)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function XA(Ce){var ue=[];return Is(y,function(Te,wr){we(Te)&&Fl(Te,Ce,0)>=0&&ue.push(wr)}),ue}};function Ao(y,L){for(var _=-1,N=y==null?0:y.length,H=Array(N);++_<N;)H[_]=L(y[_],_,y);return H}var RA="[object Symbol]";function wA(y){return typeof y=="symbol"||bn(y)&&Oi(y)==RA}var SA=1/0,sd=st?st.prototype:void 0,Hm=sd?sd.toString:void 0;function ld(y){if(typeof y=="string")return y;if(we(y))return Ao(y,ld)+"";if(wA(y))return Hm?Hm.call(y):"";var L=y+"";return L=="0"&&1/y==-SA?"-0":L}function LA(y,L,_){var N=-1,H=y.length;L<0&&(L=-L>H?0:H+L),_=_>H?H:_,_<0&&(_+=H),H=L>_?0:_-L>>>0,L>>>=0;for(var $=Array(H);++N<H;)$[N]=y[N+L];return $}function IA(y,L,_){var N=y.length;return _=_===void 0?N:_,!L&&_>=N?y:LA(y,L,_)}function ad(y,L){for(var _=y.length;_--&&Fl(L,y[_],0)>-1;);return _}function DA(y,L){for(var _=-1,N=y.length;++_<N&&Fl(L,y[_],0)>-1;);return _}function _A(y){return y.split("")}var MA="\\ud800-\\udfff",UA="\\u0300-\\u036f",OA="\\ufe20-\\ufe2f",me="\\u20d0-\\u20ff",ce=UA+OA+me,NA="\\ufe0e\\ufe0f",PA="\\u200d",FA=RegExp("["+PA+MA+ce+NA+"]");function KA(y){return FA.test(y)}var jm="\\ud800-\\udfff",VA="\\u0300-\\u036f",zm="\\ufe20-\\ufe2f",$A="\\u20d0-\\u20ff",en=VA+zm+$A,cd="\\ufe0e\\ufe0f",bo="["+jm+"]",Sc="["+en+"]",Kl="\\ud83c[\\udffb-\\udfff]",$n="(?:"+Sc+"|"+Kl+")",ud="[^"+jm+"]",fd="(?:\\ud83c[\\udde6-\\uddff]){2}",dd="[\\ud800-\\udbff][\\udc00-\\udfff]",Gm="\\u200d",hd=$n+"?",md="["+cd+"]?",Sn="(?:"+Gm+"(?:"+[ud,fd,dd].join("|")+")"+md+hd+")*",HA=md+hd+Sn,Hn="(?:"+[ud+Sc+"?",Sc,fd,dd,bo].join("|")+")",jA=RegExp(Kl+"(?="+Kl+")|"+Hn+HA,"g");function Wm(y){return y.match(jA)||[]}function oi(y){return KA(y)?Wm(y):_A(y)}function Lc(y){return y==null?"":ld(y)}var gd=/^\s+|\s+$/g;function pe(y,L,_){if(y=Lc(y),y&&(_||L===void 0))return y.replace(gd,"");if(!y||!(L=ld(L)))return y;var N=oi(y),H=oi(L),$=DA(N,H),X=ad(N,H)+1;return IA(N,$,X).join("")}var Ki=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,pd=/,/,zA=/(=.+)?(\s*)$/,Cd=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function GA(y){return y=y.toString().replace(Cd,""),y=y.match(Ki)[2].replace(" ",""),y=y?y.split(pd):[],y=y.map(function(L){return pe(L.replace(zA,""))}),y}function qm(y,L){var _={};Is(y,function(N,H){var $,X=U(N),Z=!X&&N.length===1||X&&N.length===0;if(we(N))$=N.slice(0,-1),N=N[N.length-1],_[H]=$.concat($.length>0?ut:N);else if(Z)_[H]=N;else{if($=GA(N),N.length===0&&!X&&$.length===0)throw new Error("autoInject task functions require explicit parameters.");X||$.pop(),_[H]=$.concat(ut)}function ut(At,ft){var Bt=Ao($,function(te){return At[te]});Bt.push(ft),M(N).apply(null,Bt)}}),wc(_,L)}function or(){this.head=this.tail=null,this.length=0}function Ed(y,L){y.length=1,y.head=y.tail=L}or.prototype.removeLink=function(y){return y.prev?y.prev.next=y.next:this.head=y.next,y.next?y.next.prev=y.prev:this.tail=y.prev,y.prev=y.next=null,this.length-=1,y},or.prototype.empty=function(){for(;this.head;)this.shift();return this},or.prototype.insertAfter=function(y,L){L.prev=y,L.next=y.next,y.next?y.next.prev=L:this.tail=L,y.next=L,this.length+=1},or.prototype.insertBefore=function(y,L){L.prev=y.prev,L.next=y,y.prev?y.prev.next=L:this.head=L,y.prev=L,this.length+=1},or.prototype.unshift=function(y){this.head?this.insertBefore(this.head,y):Ed(this,y)},or.prototype.push=function(y){this.tail?this.insertAfter(this.tail,y):Ed(this,y)},or.prototype.shift=function(){return this.head&&this.removeLink(this.head)},or.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},or.prototype.toArray=function(){for(var y=Array(this.length),L=this.head,_=0;_<this.length;_++)y[_]=L.data,L=L.next;return y},or.prototype.remove=function(y){for(var L=this.head;L;){var _=L.next;y(L)&&this.removeLink(L),L=_}return this};function Vl(y,L,_){if(L==null)L=1;else if(L===0)throw new Error("Concurrency must not be zero");var N=M(y),H=0,$=[],X=!1;function Z(Bt,te,Pe){if(Pe!=null&&typeof Pe!="function")throw new Error("task callback must be a function");if(ft.started=!0,we(Bt)||(Bt=[Bt]),Bt.length===0&&ft.idle())return E(function(){ft.drain()});for(var dn=0,jn=Bt.length;dn<jn;dn++){var Rr={data:Bt[dn],callback:Pe||jt};te?ft._tasks.unshift(Rr):ft._tasks.push(Rr)}X||(X=!0,E(function(){X=!1,ft.process()}))}function ut(Bt){return function(te){H-=1;for(var Pe=0,dn=Bt.length;Pe<dn;Pe++){var jn=Bt[Pe],Rr=Fl($,jn,0);Rr===0?$.shift():Rr>0&&$.splice(Rr,1),jn.callback.apply(jn,arguments),te!=null&&ft.error(te,jn.data)}H<=ft.concurrency-ft.buffer&&ft.unsaturated(),ft.idle()&&ft.drain(),ft.process()}}var At=!1,ft={_tasks:new or,concurrency:L,payload:_,saturated:jt,unsaturated:jt,buffer:L/4,empty:jt,drain:jt,error:jt,started:!1,paused:!1,push:function(Bt,te){Z(Bt,!1,te)},kill:function(){ft.drain=jt,ft._tasks.empty()},unshift:function(Bt,te){Z(Bt,!0,te)},remove:function(Bt){ft._tasks.remove(Bt)},process:function(){if(!At){for(At=!0;!ft.paused&&H<ft.concurrency&&ft._tasks.length;){var Bt=[],te=[],Pe=ft._tasks.length;ft.payload&&(Pe=Math.min(Pe,ft.payload));for(var dn=0;dn<Pe;dn++){var jn=ft._tasks.shift();Bt.push(jn),$.push(jn),te.push(jn.data)}H+=1,ft._tasks.length===0&&ft.empty(),H===ft.concurrency&&ft.saturated();var Rr=kr(ut(Bt));N(te,Rr)}At=!1}},length:function(){return ft._tasks.length},running:function(){return H},workersList:function(){return $},idle:function(){return ft._tasks.length+H===0},pause:function(){ft.paused=!0},resume:function(){ft.paused!==!1&&(ft.paused=!1,E(ft.process))}};return ft}function vo(y,L){return Vl(y,1,L)}var Ds=Ge(Pi,1);function si(y,L,_,N){N=Ni(N||jt);var H=M(_);Ds(y,function($,X,Z){H(L,$,function(ut,At){L=At,Z(ut)})},function($){N($,L)})}function Ic(){var y=Ao(arguments,M);return function(){var L=r(arguments),_=this,N=L[L.length-1];typeof N=="function"?L.pop():N=jt,si(y,L,function(H,$,X){$.apply(_,H.concat(function(Z){var ut=r(arguments,1);X(Z,ut)}))},function(H,$){N.apply(_,[H].concat($))})}}var Dc=function(){return Ic.apply(null,r(arguments).reverse())},xd=Array.prototype.concat,$l=function(y,L,_,N){N=N||jt;var H=M(_);Fi(y,L,function($,X){H($,function(Z){return Z?X(Z):X(null,r(arguments,1))})},function($,X){for(var Z=[],ut=0;ut<X.length;ut++)X[ut]&&(Z=xd.apply(Z,X[ut]));return N($,Z)})},Xm=Ge($l,1/0),_c=Ge($l,1),Mc=function(){var y=r(arguments),L=[null].concat(y);return function(){var _=arguments[arguments.length-1];return _.apply(this,L)}};function Hl(y){return y}function Bo(y,L){return function(_,N,H,$){$=$||jt;var X=!1,Z;_(N,function(ut,At,ft){H(ut,function(Bt,te){Bt?ft(Bt):y(te)&&!Z?(X=!0,Z=L(!0,ut),ft(null,Eo)):ft()})},function(ut){ut?$(ut):$(null,X?Z:L(!1))})}}function vn(y,L){return L}var _s=ii(Bo(Hl,vn)),li=xo(Bo(Hl,vn)),jl=Ge(li,1);function Ad(y){return function(L){var _=r(arguments,1);_.push(function(N){var H=r(arguments,1);typeof console=="object"&&(N?console.error&&console.error(N):console[y]&&Ss(H,function($){console[y]($)}))}),M(L).apply(null,_)}}var Ym=Ad("dir");function Qm(y,L,_){_=kr(_||jt);var N=M(y),H=M(L);function $(Z){if(Z)return _(Z);var ut=r(arguments,1);ut.push(X),H.apply(this,ut)}function X(Z,ut){if(Z)return _(Z);if(!ut)return _(null);N($)}X(null,!0)}function bd(y,L,_){_=kr(_||jt);var N=M(y),H=function($){if($)return _($);var X=r(arguments,1);if(L.apply(this,X))return N(H);_.apply(null,[null].concat(X))};N(H)}function Jm(y,L,_){bd(y,function(){return!L.apply(this,arguments)},_)}function Zm(y,L,_){_=kr(_||jt);var N=M(L),H=M(y);function $(Z){if(Z)return _(Z);H(X)}function X(Z,ut){if(Z)return _(Z);if(!ut)return _(null);N($)}H(X)}function To(y){return function(L,_,N){return y(L,N)}}function Uc(y,L,_){ri(y,To(M(L)),_)}function zl(y,L,_,N){Pl(L)(y,To(M(_)),N)}var yo=Ge(zl,1);function Oc(y){return U(y)?y:o(function(L,_){var N=!0;L.push(function(){var H=arguments;N?E(function(){_.apply(null,H)}):_.apply(null,H)}),y.apply(this,L),N=!1})}function sr(y){return!y}var ko=ii(Bo(sr,sr)),Gl=xo(Bo(sr,sr)),Nc=Ge(Gl,1);function tg(y){return function(L){return L==null?void 0:L[y]}}function Ms(y,L,_,N){var H=new Array(L.length);y(L,function($,X,Z){_($,function(ut,At){H[X]=!!At,Z(ut)})},function($){if($)return N($);for(var X=[],Z=0;Z<L.length;Z++)H[Z]&&X.push(L[Z]);N(null,X)})}function lr(y,L,_,N){var H=[];y(L,function($,X,Z){_($,function(ut,At){ut?Z(ut):(At&&H.push({index:X,value:$}),Z())})},function($){$?N($):N(null,Ao(H.sort(function(X,Z){return X.index-Z.index}),tg("value")))})}function Pc(y,L,_,N){var H=Ll(L)?Ms:lr;H(y,L,M(_),N||jt)}var Fc=ii(Pc),Wl=xo(Pc),Kc=Ge(Wl,1);function eg(y,L){var _=kr(L||jt),N=M(Oc(y));function H($){if($)return _($);N(H)}H()}var Vc=function(y,L,_,N){N=N||jt;var H=M(_);Fi(y,L,function($,X){H($,function(Z,ut){return Z?X(Z):X(null,{key:ut,val:$})})},function($,X){for(var Z={},ut=Object.prototype.hasOwnProperty,At=0;At<X.length;At++)if(X[At]){var ft=X[At].key,Bt=X[At].val;ut.call(Z,ft)?Z[ft].push(Bt):Z[ft]=[Bt]}return N($,Z)})},Ro=Ge(Vc,1/0),K=Ge(Vc,1),W=Ad("log");function j(y,L,_,N){N=Ni(N||jt);var H={},$=M(_);Pi(y,L,function(X,Z,ut){$(X,Z,function(At,ft){if(At)return ut(At);H[Z]=ft,ut()})},function(X){N(X,H)})}var pt=Ge(j,1/0),St=Ge(j,1);function Xt(y,L){return L in y}function De(y,L){var _=Object.create(null),N=Object.create(null);L=L||Hl;var H=M(y),$=o(function(Z,ut){var At=L.apply(null,Z);Xt(_,At)?E(function(){ut.apply(null,_[At])}):Xt(N,At)?N[At].push(ut):(N[At]=[ut],H.apply(null,Z.concat(function(){var ft=r(arguments);_[At]=ft;var Bt=N[At];delete N[At];for(var te=0,Pe=Bt.length;te<Pe;te++)Bt[te].apply(null,ft)})))});return $.memo=_,$.unmemoized=y,$}var Zt;c?Zt=process.nextTick:l?Zt=setImmediate:Zt=d;var $c=h(Zt);function vd(y,L,_){_=_||jt;var N=Ll(L)?[]:{};y(L,function(H,$,X){M(H)(function(Z,ut){arguments.length>2&&(ut=r(arguments,1)),N[$]=ut,X(Z)})},function(H){_(H,N)})}function Ln(y,L){vd(ri,y,L)}function ql(y,L,_){vd(Pl(L),y,_)}var Bd=function(y,L){var _=M(y);return Vl(function(N,H){_(N[0],H)},L,1)},wo=function(y,L){var _=Bd(y,L);return _.push=function(N,H,$){if($==null&&($=jt),typeof $!="function")throw new Error("task callback must be a function");if(_.started=!0,we(N)||(N=[N]),N.length===0)return E(function(){_.drain()});H=H||0;for(var X=_._tasks.head;X&&H>=X.priority;)X=X.next;for(var Z=0,ut=N.length;Z<ut;Z++){var At={data:N[Z],priority:H,callback:$};X?_._tasks.insertBefore(X,At):_._tasks.push(At)}E(_.process)},delete _.unshift,_};function Xl(y,L){if(L=Ni(L||jt),!we(y))return L(new TypeError("First argument to race must be an array of functions"));if(!y.length)return L();for(var _=0,N=y.length;_<N;_++)M(y[_])(L)}function So(y,L,_,N){var H=r(y).reverse();si(H,L,_,N)}function Yt(y){var L=M(y);return o(function(N,H){return N.push(function(X,Z){if(X)H(null,{error:X});else{var ut;arguments.length<=2?ut=Z:ut=r(arguments,1),H(null,{value:ut})}}),L.apply(this,N)})}function ng(y){var L;return we(y)?L=Ao(y,Yt):(L={},Is(y,function(_,N){L[N]=Yt.call(this,_)})),L}function Td(y,L,_,N){Pc(y,L,function(H,$){_(H,function(X,Z){$(X,!Z)})},N)}var Yl=ii(Td),yd=xo(Td),rg=Ge(yd,1);function ig(y){return function(){return y}}function Lo(y,L,_){var N=5,H=0,$={times:N,intervalFunc:ig(H)};function X(ft,Bt){if(typeof Bt=="object")ft.times=+Bt.times||N,ft.intervalFunc=typeof Bt.interval=="function"?Bt.interval:ig(+Bt.interval||H),ft.errorFilter=Bt.errorFilter;else if(typeof Bt=="number"||typeof Bt=="string")ft.times=+Bt||N;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof y=="function"?(_=L||jt,L=y):(X($,y),_=_||jt),typeof L!="function")throw new Error("Invalid arguments for async.retry");var Z=M(L),ut=1;function At(){Z(function(ft){ft&&ut++<$.times&&(typeof $.errorFilter!="function"||$.errorFilter(ft))?setTimeout(At,$.intervalFunc(ut)):_.apply(null,arguments)})}At()}var ai=function(y,L){L||(L=y,y=null);var _=M(L);return o(function(N,H){function $(X){_.apply(null,N.concat(X))}y?Lo(y,$,H):Lo($,H)})};function Ql(y,L){vd(Ds,y,L)}var Jl=ii(Bo(Boolean,Hl)),Vi=xo(Bo(Boolean,Hl)),Zl=Ge(Vi,1);function kd(y,L,_){var N=M(L);Rc(y,function($,X){N($,function(Z,ut){if(Z)return X(Z);X(null,{value:$,criteria:ut})})},function($,X){if($)return _($);_(null,Ao(X.sort(H),tg("value")))});function H($,X){var Z=$.criteria,ut=X.criteria;return Z<ut?-1:Z>ut?1:0}}function ta(y,L,_){var N=M(y);return o(function(H,$){var X=!1,Z;function ut(){var At=y.name||"anonymous",ft=new Error('Callback function "'+At+'" timed out.');ft.code="ETIMEDOUT",_&&(ft.info=_),X=!0,$(ft)}H.push(function(){X||($.apply(null,arguments),clearTimeout(Z))}),Z=setTimeout(ut,L),N.apply(null,H)})}var og=Math.ceil,ea=Math.max;function Io(y,L,_,N){for(var H=-1,$=ea(og((L-y)/(_||1)),0),X=Array($);$--;)X[N?$:++H]=y,y+=_;return X}function Do(y,L,_,N){var H=M(_);Fi(Io(0,y,1),L,H,N)}var sg=Ge(Do,1/0),lg=Ge(Do,1);function ag(y,L,_,N){arguments.length<=3&&(N=_,_=L,L=we(y)?[]:{}),N=Ni(N||jt);var H=M(_);ri(y,function($,X,Z){H(L,$,X,Z)},function($){N($,L)})}function na(y,L){var _=null,N;L=L||jt,yo(y,function(H,$){M(H)(function(X,Z){arguments.length>2?N=r(arguments,1):N=Z,_=X,$(!X)})},function(){L(_,N)})}function ra(y){return function(){return(y.unmemoized||y).apply(null,arguments)}}function ia(y,L,_){_=kr(_||jt);var N=M(L);if(!y())return _(null);var H=function($){if($)return _($);if(y())return N(H);var X=r(arguments,1);_.apply(null,[null].concat(X))};N(H)}function cg(y,L,_){ia(function(){return!y.apply(this,arguments)},L,_)}var Rd=function(y,L){if(L=Ni(L||jt),!we(y))return L(new Error("First argument to waterfall must be an array of functions"));if(!y.length)return L();var _=0;function N($){var X=M(y[_++]);$.push(kr(H)),X.apply(null,$)}function H($){if($||_===y.length)return L.apply(null,arguments);N(r(arguments,1))}N([])},WA={apply:i,applyEach:nd,applyEachSeries:id,asyncify:x,auto:wc,autoInject:qm,cargo:vo,compose:Dc,concat:Xm,concatLimit:$l,concatSeries:_c,constant:Mc,detect:_s,detectLimit:li,detectSeries:jl,dir:Ym,doDuring:Qm,doUntil:Jm,doWhilst:bd,during:Zm,each:Uc,eachLimit:zl,eachOf:ri,eachOfLimit:Pi,eachOfSeries:Ds,eachSeries:yo,ensureAsync:Oc,every:ko,everyLimit:Gl,everySeries:Nc,filter:Fc,filterLimit:Wl,filterSeries:Kc,forever:eg,groupBy:Ro,groupByLimit:Vc,groupBySeries:K,log:W,map:Rc,mapLimit:Fi,mapSeries:rd,mapValues:pt,mapValuesLimit:j,mapValuesSeries:St,memoize:De,nextTick:$c,parallel:Ln,parallelLimit:ql,priorityQueue:wo,queue:Bd,race:Xl,reduce:si,reduceRight:So,reflect:Yt,reflectAll:ng,reject:Yl,rejectLimit:yd,rejectSeries:rg,retry:Lo,retryable:ai,seq:Ic,series:Ql,setImmediate:E,some:Jl,someLimit:Vi,someSeries:Zl,sortBy:kd,timeout:ta,times:sg,timesLimit:Do,timesSeries:lg,transform:ag,tryEach:na,unmemoize:ra,until:cg,waterfall:Rd,whilst:ia,all:ko,allLimit:Gl,allSeries:Nc,any:Jl,anyLimit:Vi,anySeries:Zl,find:_s,findLimit:li,findSeries:jl,forEach:Uc,forEachSeries:yo,forEachLimit:zl,forEachOf:ri,forEachOfSeries:Ds,forEachOfLimit:Pi,inject:si,foldl:si,foldr:So,select:Fc,selectLimit:Wl,selectSeries:Kc,wrapSync:x};e.default=WA,e.apply=i,e.applyEach=nd,e.applyEachSeries=id,e.asyncify=x,e.auto=wc,e.autoInject=qm,e.cargo=vo,e.compose=Dc,e.concat=Xm,e.concatLimit=$l,e.concatSeries=_c,e.constant=Mc,e.detect=_s,e.detectLimit=li,e.detectSeries=jl,e.dir=Ym,e.doDuring=Qm,e.doUntil=Jm,e.doWhilst=bd,e.during=Zm,e.each=Uc,e.eachLimit=zl,e.eachOf=ri,e.eachOfLimit=Pi,e.eachOfSeries=Ds,e.eachSeries=yo,e.ensureAsync=Oc,e.every=ko,e.everyLimit=Gl,e.everySeries=Nc,e.filter=Fc,e.filterLimit=Wl,e.filterSeries=Kc,e.forever=eg,e.groupBy=Ro,e.groupByLimit=Vc,e.groupBySeries=K,e.log=W,e.map=Rc,e.mapLimit=Fi,e.mapSeries=rd,e.mapValues=pt,e.mapValuesLimit=j,e.mapValuesSeries=St,e.memoize=De,e.nextTick=$c,e.parallel=Ln,e.parallelLimit=ql,e.priorityQueue=wo,e.queue=Bd,e.race=Xl,e.reduce=si,e.reduceRight=So,e.reflect=Yt,e.reflectAll=ng,e.reject=Yl,e.rejectLimit=yd,e.rejectSeries=rg,e.retry=Lo,e.retryable=ai,e.seq=Ic,e.series=Ql,e.setImmediate=E,e.some=Jl,e.someLimit=Vi,e.someSeries=Zl,e.sortBy=kd,e.timeout=ta,e.times=sg,e.timesLimit=Do,e.timesSeries=lg,e.transform=ag,e.tryEach=na,e.unmemoize=ra,e.until=cg,e.waterfall=Rd,e.whilst=ia,e.all=ko,e.allLimit=Gl,e.allSeries=Nc,e.any=Jl,e.anyLimit=Vi,e.anySeries=Zl,e.find=_s,e.findLimit=li,e.findSeries=jl,e.forEach=Uc,e.forEachSeries=yo,e.forEachLimit=zl,e.forEachOf=ri,e.forEachOfSeries=Ds,e.forEachOfLimit=Pi,e.inject=si,e.foldl=si,e.foldr=So,e.select=Fc,e.selectLimit=Wl,e.selectSeries=Kc,e.wrapSync=x,Object.defineProperty(e,"__esModule",{value:!0})})})(q1,q1.exports);var cT={exports:{}},X1=cT.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),r=2;e===1/0;r*=2)e=Math.log(Math.pow(2,n/r))/Math.log(t)*r;for(var i=e-Math.floor(e),o="",r=0;r<Math.floor(e);r++){var s=Math.floor(Math.random()*t).toString(t);o=s+o}if(i){var l=Math.pow(t,i),s=Math.floor(Math.random()*l).toString(t);o=s+o}var c=parseInt(o,t);return c!==1/0&&c>=Math.pow(2,n)?X1(n,t):o};X1.rack=function(n,t,e){var r=function(o){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=X1(n,t)}while(Object.hasOwnProperty.call(i,l));return i[l]=o,l},i=r.hats={};return r.get=function(o){return r.hats[o]},r.set=function(o,s){return r.hats[o]=s,r},r.bits=n||128,r.base=t||16,r};var uT=os,bN=lT,vN=aT,t0=xr,Y1=q1.exports,BN=cT.exports,fT=ls.ACTIONS,dT=$e;function $e(n,t){if(uT.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}uT.mixin($e),$e.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},$e.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},$e.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||BN();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},$e.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(r){if(r)return t._callbackOrEmit(r,n);var i=Object.keys(t._remotePresenceInstances);Y1.parallel([function(o){Y1.each(e,function(s,l){t.localPresences[s].destroy(l)},o)},function(o){if(!t._wantsDestroy)return o();Y1.each(i,function(s,l){t._remotePresenceInstances[s].destroy(l)},o)}],function(o){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(o,n)})})},$e.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?fT.presenceSubscribe:fT.presenceUnsubscribe,r=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[r]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,r,this)},$e.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},$e.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},$e.prototype._receiveUpdate=function(n,t){var e=t0.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var r=this,i=t0.digOrCreate(this._remotePresenceInstances,t.id,function(){return r._createRemotePresence(t.id)});i.receiveUpdate(t)},$e.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},$e.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()}},$e.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},$e.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},$e.prototype._resubscribe=function(){var n=[];for(var t in this._subscriptionCallbacksBySeq){var e=this._subscriptionCallback(t);n.push(e)}if(!this.wantSubscribe)return this._callEachOrEmit(n);var r=this;this.subscribe(function(i){r._callEachOrEmit(n,i)})},$e.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},$e.prototype._callbackOrEmit=function(n,t){if(t)return t0.nextTick(t,n);n&&this.emit("error",n)},$e.prototype._createLocalPresence=function(n){return new bN(this,n)},$e.prototype._createRemotePresence=function(n){return new vN(this,n)},$e.prototype._callEachOrEmit=function(n,t){var e=t0.callEach(n,t);!e&&t&&this.emit("error",t)};var Ku=lT,hT=Yh,TN=xr,mT=hT.CODES,yN=Wr;function Wr(n,t){Ku.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._isSending=!1,this._docDataVersionByPresenceVersion={},this._opHandler=this._transformAgainstOp.bind(this),this._createOrDelHandler=this._handleCreateOrDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._destroyHandler=this.destroy.bind(this),this._registerWithDoc()}Wr.prototype=Object.create(Ku.prototype),Wr.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:mT.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,Ku.prototype.submit.call(this,n,t)},Wr.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),this._emitter.removeEventListener(this._doc,"destroy",this._destroyHandler),Ku.prototype.destroy.call(this,n)},Wr.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={})})}},Wr.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"del",this._createOrDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler),this._emitter.addEventListener(this._doc,"destroy",this._destroyHandler)},Wr.prototype._transformAgainstOp=function(n,t){var e=this,r=this._doc._dataStateVersion;this._pendingMessages.forEach(function(i){var o=e._docDataVersionByPresenceVersion[i.pv];if(!(o>=r))try{i.p=e._transformPresence(i.p,n,t),e._docDataVersionByPresenceVersion[i.pv]=r}catch(l){var s=e._getCallback(i.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(i){this.emit("error",i)}},Wr.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},Wr.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},Wr.prototype._message=function(){var n=Ku.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},Wr.prototype._transformPresence=function(n,t,e){var r=this._doc.type;if(!TN.supportsPresence(r))throw new hT(mT.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+r.name);return r.transformPresence(n,t,e)};var gT={};(function(n){var t=Ou,e=Yh,r=xr,i=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var c=l.create.type;if(typeof c!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[c];if(d==null||typeof d!="object")return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(i.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(i.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(i.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(i.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(i.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(i.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,c){if(typeof l!="object")return new e(i.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&c.v!=null&&l.v!==c.v)return new e(i.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(c.create){if(l.type)return new e(i.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=c.create,h=t.map[d.type];if(!h)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(E){return E}}else if(c.del)l.data=void 0,l.type=null,l.v++;else if("op"in c){var C=o(l,c.op);if(C)return C;l.v++}else l.v++};function o(l,c){if(!l.type)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(c===void 0)return new e(i.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,c)}catch(h){return new e(i.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,c,d){if(c.v!=null&&c.v!==d.v)return new e(i.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(c.create||"op"in c)return new e(i.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in c||c.create||c.del)||"op"in d&&c.create)return new e(i.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in c){if(!l)return new e(i.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(i.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{c.op=l.transform(c.op,d.op,"left")}catch(h){return h}}}c.v!=null&&c.v++},n.applyOps=function(l,c,d){d=d||{};for(var h=0;h<c.length;h++){var C=c[h];if(d._normalizeLegacyJson0Ops)try{s(l,C)}catch{return new e(i.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=C.v;var E=n.apply(l,C);if(E)return E}},n.transformPresence=function(l,c,d){var h=this.checkOp(c);if(h)return h;var C=l.t;if(typeof C=="string"&&(C=t.map[C]),!C)return{code:i.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!r.supportsPresence(C))return{code:i.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(c.create||c.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:C.transformPresence(l.p,c.op,d)}catch(E){return{code:i.ERR_PRESENCE_TRANSFORM_FAILED,message:E.message||E}}l.v++};function s(l,c){if(l.type===t.defaultType.uri){var d=c.op;if(!!d){var h=l.data;d.length>1&&(h=r.clone(h));for(var C=0;C<d.length;C++){var E=d[C];typeof E.lm=="string"&&(E.lm=+E.lm);for(var x=E.p,v=h,R=0;R<x.length;R++){var w=x[R];Object.prototype.toString.call(v)=="[object Array]"?x[R]=+w:v.constructor===Object&&(x[R]=w.toString()),v=v[w]}C<d.length-1&&(h=t.defaultType.apply(h,[E]))}}}}})(gT);var Vu=aT,kN=gT,RN=Ar;function Ar(n,t){Vu.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this.src=null,this.presenceVersion=null,this._doc=this.connection.get(this.collection,this.id),this._emitter=this.connection._docPresenceEmitter,this._pending=null,this._opCache=null,this._pendingSetPending=!1,this._opHandler=this._handleOp.bind(this),this._createDelHandler=this._handleCreateDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._registerWithDoc()}Ar.prototype=Object.create(Vu.prototype),Ar.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},Ar.prototype.destroy=function(n){this._emitter.removeEventListener(this._doc,"op",this._opHandler),this._emitter.removeEventListener(this._doc,"create",this._createDelHandler),this._emitter.removeEventListener(this._doc,"del",this._createDelHandler),this._emitter.removeEventListener(this._doc,"load",this._loadHandler),Vu.prototype.destroy.call(this,n)},Ar.prototype._registerWithDoc=function(){this._emitter.addEventListener(this._doc,"op",this._opHandler),this._emitter.addEventListener(this._doc,"create",this._createDelHandler),this._emitter.addEventListener(this._doc,"del",this._createDelHandler),this._emitter.addEventListener(this._doc,"load",this._loadHandler)},Ar.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))}})}},Ar.prototype._handleOp=function(n,t,e){var r=e===this.src;this._transformAgainstOp(n,r),this._cacheOp(n,r),this._setPendingPresence()},Vu.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},Vu.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},Ar.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)}},Ar.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++):kN.transformPresence(this._pending,t,e)}var r=this._pending.v>=this._doc.version;return r&&this._stopCachingOps(),r},Ar.prototype._startCachingOps=function(){this._opCache=[]},Ar.prototype._stopCachingOps=function(){this._opCache=null},Ar.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var pT=dT,wN=yN,SN=RN;function Pa(n,t,e){var r=Pa.channel(t,e);pT.call(this,n,r),this.collection=t,this.id=e}var LN=Pa;Pa.prototype=Object.create(pT.prototype),Pa.channel=function(n,t){return n+"."+t},Pa.prototype._createLocalPresence=function(n){return new wN(this,n)},Pa.prototype._createRemotePresence=function(n){return new SN(this,n)};var IN=DN;function DN(n,t,e,r,i){this.id=n,this.v=t,this.type=e,this.data=r,this.m=i}var _N=IN,CT=os,ET=$u;function $u(n,t,e,r,i){if(CT.EventEmitter.call(this),typeof i!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=r,this.collection=e,this.callback=i,this.sent=!1}CT.mixin($u),$u.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},$u.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},$u.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,r=new _N(this.id,t.v,t.type,t.data,e);this.callback(null,r)};var xT=ET,MN=xr,UN=ls.ACTIONS,ON=Q1;function Q1(n,t,e,r,i,o){if(xT.call(this,n,t,e,r,o),!MN.isValidVersion(i))throw new Error("Snapshot version must be a positive integer or null");this.version=i}Q1.prototype=Object.create(xT.prototype),Q1.prototype._message=function(){return{a:UN.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var AT=ET,NN=xr,PN=ls.ACTIONS,FN=J1;function J1(n,t,e,r,i,o){if(AT.call(this,n,t,e,r,o),!NN.isValidTimestamp(i))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=i}J1.prototype=Object.create(AT.prototype),J1.prototype._message=function(){return{a:PN.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var Bi=xr,KN=Og.default.EventEmitter,VN=["create","del","destroy","load","op"],$N=Hu;function Hu(){this._docs={},this._forwarders={},this._emitters={}}Hu.prototype.addEventListener=function(n,t,e){this._registerDoc(n);var r=Bi.dig(this._emitters,n.collection,n.id);r.on(t,e)},Hu.prototype.removeEventListener=function(n,t,e){var r=Bi.dig(this._emitters,n.collection,n.id);!r||(r.off(t,e),r._eventsCount===1&&this._unregisterDoc(n))},Hu.prototype._registerDoc=function(n){var t=!0;if(Bi.digOrCreate(this._docs,n.collection,n.id,function(){return t=!1,n}),!t){var e=Bi.digOrCreate(this._emitters,n.collection,n.id,function(){var i=new KN;return i.setMaxListeners(1e3),i}),r=this;VN.forEach(function(i){var o=Bi.digOrCreate(r._forwarders,n.collection,n.id,i,function(){return e.emit.bind(e,i)});n.on(i,o)}),this.addEventListener(n,"destroy",this._unregisterDoc.bind(this,n))}},Hu.prototype._unregisterDoc=function(n){var t=Bi.dig(this._forwarders,n.collection,n.id);for(var e in t)n.off(e,t[e]);var r=Bi.dig(this._emitters,n.collection,n.id);r.removeAllListeners(),Bi.digAndRemove(this._forwarders,n.collection,n.id),Bi.digAndRemove(this._emitters,n.collection,n.id),Bi.digAndRemove(this._docs,n.collection,n.id)};var HN=dN,jN=CN,zN=dT,bT=LN,GN=ON,WN=FN,vT=os,Fa=Yh,le=ls.ACTIONS,BT=Ou,qr=xr,ju=J2,qN=$N,zu=Fa.CODES;function TT(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var XN=wt;function wt(n){vT.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._docPresenceEmitter=new qN,this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=TT(n),this.bindToSocket(n)}vT.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=TT(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(r){try{var i=typeof r.data=="string"?JSON.parse(r.data):r.data}catch{ju.warn("Failed to parse message",r);return}e.debug&&ju.info("RECV",JSON.stringify(i));var o={data:i};if(e.emit("receive",o),!!o.data)try{e.handleMessage(o.data)}catch(s){qr.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(r){e.emit("connection error",r)},n.onclose=function(r){r==="closed"||r==="Closed"?e._setState("closed",r):r==="stopped"||r==="Stopped by server"?e._setState("stopped",r):e._setState("disconnected",r)}},wt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=yT(n.error,n),delete n.error),n.a){case le.initLegacy:return this._handleLegacyInit(n);case le.handshake:return this._handleHandshake(t,n);case le.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case le.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case le.queryUnsubscribe:return;case le.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 le.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case le.bulkSubscribe:case le.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case le.snapshotFetch:case le.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case le.fetch:var r=this.getExisting(n.c,n.d);r&&r._handleFetch(t,n.data);return;case le.subscribe:case le.unsubscribe:var r=this.getExisting(n.c,n.d);r&&r._handleSubscribe(t,n.data);return;case le.op:var r=this.getExisting(n.c,n.d);r&&r._handleOp(t,n);return;case le.presence:return this._handlePresence(t,n);case le.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case le.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case le.presenceRequest:return this._handlePresenceRequest(t,n);case le.pingPong:return this._handlePingPong(t);default:ju.warn("Ignoring unrecognized message",n)}};function yT(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 r in t.data){var i=t.data[r],o=this.getExisting(t.c,r);o&&(n?o[e](n):i.error?o[e](yT(i.error)):o[e](null,i))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var r=t.b[s],o=this.getExisting(t.c,r);o&&o[e](n)}else if(t.b)for(var r in t.b){var o=this.getExisting(t.c,r);o&&o[e](n)}else ju.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 Fa(zu.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var r in this.queries){var i=this.queries[r];i._onConnectionStateChanged()}for(var o in this.collections){var s=this.collections[o];for(var r in s)s[r]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var r in this._snapshotRequests){var c=this._snapshotRequests[r];c._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},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 r=[],i={},o=0,s;for(var l in e){var c=e[l];c==null?r.push(l):(i[l]=c,s=l,o++)}if(r.length===1){var l=r[0];this.send({a:n,c:t,d:l})}else r.length&&this.send({a:"b"+n,c:t,b:r});if(o===1){var d=i[s];this.send({a:n,c:t,d:s,v:d})}else o&&this.send({a:"b"+n,c:t,b:i})}},wt.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var r=this.bulk[t.collection]||(this.bulk[t.collection]={}),i=r[n]||(r[n]={}),o=i.hasOwnProperty(t.id);return i[t.id]=e,o}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},wt.prototype.sendFetch=function(n){return this._sendActions(le.fetch,n,n.version)},wt.prototype.sendSubscribe=function(n){return this._sendActions(le.subscribe,n,n.version)},wt.prototype.sendUnsubscribe=function(n){return this._sendActions(le.unsubscribe,n)},wt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:le.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&&ju.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},wt.prototype.ping=function(){if(!this.canSend)throw new Fa(zu.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:le.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]={}),r=e[t];return r||(r=e[t]=new HN(this,n,t),this.emit("doc",r)),r._wantsDestroy=!1,r},wt.prototype._destroyDoc=function(n){!n._wantsDestroy||(qr.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,r,i){var o=this.nextQueryId++,s=new jN(n,this,o,t,e,r,i);return this.queries[o]=s,s.send(),s},wt.prototype._destroyQuery=function(n){delete this.queries[n.id]},wt.prototype.createFetchQuery=function(n,t,e,r){return this._createQuery(le.queryFetch,n,t,e,r)},wt.prototype.createSubscribeQuery=function(n,t,e,r){return this._createQuery(le.querySubscribe,n,t,e,r)},wt.prototype.hasPending=function(){return!!(this._firstDoc(e0)||this._firstQuery(e0)||this._firstSnapshotRequest())};function e0(n){return n.hasPending()}wt.prototype.hasWritePending=function(){return!!this._firstDoc(YN)};function YN(n){return n.hasWritePending()}wt.prototype.whenNothingPending=function(n){var t=this._firstDoc(e0);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(e0);if(e){e.once("ready",this._nothingPendingRetry(n));return}var r=this._firstSnapshotRequest();if(r){r.once("ready",this._nothingPendingRetry(n));return}qr.nextTick(n)},wt.prototype._nothingPendingRetry=function(n){var t=this;return function(){qr.nextTick(function(){t.whenNothingPending(n)})}},wt.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var r in e){var i=e[r];if(n(i))return i}}},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,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new GN(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.send()},wt.prototype.fetchSnapshotByTimestamp=function(n,t,e,r){typeof e=="function"&&(r=e,e=null);var i=this.nextSnapshotRequestId++,o=new WN(this,i,n,t,e,r);this._snapshotRequests[o.requestId]=o,o.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:le.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 Fa(zu.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(BT.map[n.type]!==BT.defaultType)return this.emit("error",new Fa(zu.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new Fa(zu.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=qr.digOrCreate(this._presences,n,function(){return new zN(t,n)});return e._wantsDestroy=!1,e},wt.prototype.getDocPresence=function(n,t){var e=bT.channel(n,t),r=this,i=qr.digOrCreate(this._presences,e,function(){return new bT(r,n,t)});return i._wantsDestroy=!1,i},wt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var r={a:n,ch:e.channel,seq:t};return this.send(r),r.seq},wt.prototype._addPresence=function(n){qr.digOrCreate(this._presences,n.channel,function(){return n})},wt.prototype._handlePresenceSubscribe=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},wt.prototype._handlePresenceUnsubscribe=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},wt.prototype._handlePresence=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},wt.prototype._handlePresenceRequest=function(n,t){var e=qr.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var kT=XN,QN=Ou;const Gu={err:1001,msg:"user auth error",name:"AuthError"},n0={err:1002,msg:"you don't have required permission",name:"PermissionError"},Z1={err:1003,msg:"Too many user connected",name:"MaxUserError"},Wu={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},JN={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},ZN={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},dl="x-live-editor-token",Ka="x-live-editor-base-url",Cn=I("auth-connection");function tP(n){try{n()}catch(t){Cn.error(t)}}class eP{constructor(t,e){m(this,"enabled",!0);m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new Kb.EventEmitter);m(this,"token",null);m(this,"resourceToken",null);m(this,"pingOptions",{interval:5e4,timeout:15e4});m(this,"reAuth",async()=>{if(this.connection&&this.reauthFunc){const t=await this.reauthFunc();await this.auth(t);const e=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:e}})}}});this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return hi(this.getBaseURL())}async auth(t){p(Cn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,r=await window.fetch(e,{method:"GET",headers:{[dl]:t.token,[Ka]:this.getBase64BaseURL()},credentials:"include"});return r.status,this.enabled?(this.token=t.token,await r.json()):{read:"",user:""}}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[Ka]:hi(this.getBaseURL())}})}async init(t){const e=await this.auth(t);if(!this.enabled)return;this.resourceToken=e.read,this.ws=new v9.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(kT.prototype),p(Cn,this.connection,"no this.connection");const r=this.ws,i=this.pingOptions;this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t,options:{ping:i}}),this._ping==null&&(this._ping=window.setInterval(()=>{var d;const c=Date.now();c-((d=this.lastReceiveTime)!=null?d:0)>i.interval&&this.send({a:"ping",id:this.id,ts:c}),this.lastReceiveTime&&c-this.lastReceiveTime>i.timeout&&r&&r.readyState===r.OPEN&&(r.reconnect(),this.lastReceiveTime=Date.now())},1e3))};const o=this.connection.handleMessage.bind(this.connection);let s=!1;this.connection.handleMessage=l=>{var d;const c=l;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in c||c.a==="pong")s=!1,this.handleMessage(c);else{Object.prototype.hasOwnProperty.call(c,"a")&&c.a==="hs"&&this.retryCount>=5&&(s?(Cn.info("retrying re-auth success"),s=!1,this.emitAuthRecover()):s=!0),Object.prototype.hasOwnProperty.call(c,"a")&&c.a!=="init"&&c.a!=="hs"&&(this.retryCount=0);try{o(c)}catch(h){if((h==null?void 0:h.type)==="writeConflict"){this.emitWriteConflictError(h,c);return}if((d=h==null?void 0:h.message)!=null&&d.startsWith("Cannot invert subtype")){this.emitWriteConflictError(h,c);return}throw h}}},kT.apply(this.connection,[this.ws])}async reConnect(t){var r,i;(r=this.ws)==null||r.close();const e=this.pingOptions;if(this.connection&&this.reauthFunc){const o=await this.reauthFunc();await this.auth(o),(i=this.ws)==null||i.reconnect(),this.connection._initializeHandshake=function(){t&&(o.token=t),this.send({a:"hs",id:this.id,auth:o,options:{ping:e}})}}}async handleAuthError(){var t,e;if(this.reauthFunc){if(!this.enabled)return;(t=this.ws)==null||t.close(),this.retryCount+=1,Cn.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const r=await this.reauthFunc();if(window.isReauthError)throw new Error("reauth error");await this.auth(r);const i=this.pingOptions;(e=this.ws)==null||e.reconnect(),this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:r,options:{ping:i}})}}}catch(r){Cn.error(r),this.retryCount>=5&&(Cn.warn("retry auth times exceed 5, broadcast auth error"),this.emitAuthError());const i=30*1e3;setTimeout(()=>this.handleAuthError(),Math.min(2*this.retryCount*1e3,i))}}}emitPermissionError(){const t=new Error(n0.msg);t.code=n0.err,this.events.emit("error",t)}emitAuthRecover(){this.events.emit("authRecover")}emitAuthError(){const t=new Error(Gu.msg);t.code=Gu.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Wu.msg);t.code=Wu.err,this.events.emit("requestReloadError",t)}emitWriteConflictError(t,e){t.orgMsg=e,this.events.emit("writeConflictError",t)}emitMaxUsersError(){this.events.emit("maxUsersError"),this.end(!1)}handleMessage(t){const e=t;if(e.a==="pong")return;const r=e.err;if(r===Gu.err)Cn.warn("auth error"),this.handleAuthError();else if(r===Z1.err)Cn.warn(Z1.msg),this.emitMaxUsersError();else if(r===Wu.err){Cn.warn(Wu.msg);try{this.emitRequestReloadError()}catch(i){Cn.error(`error occurred while process reload error: ${JSON.stringify(i)}`)}finally{this.end(!1)}}else r===n0.err?this.emitPermissionError():(Cn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError())}get(t,e){return p(Cn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(p(Cn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onAuthError(t){this.events.addListener("error",t)}onAuthRecover(t){this.events.addListener("authRecover",t)}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){p(Cn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){p(Cn,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e,r;this.enabled=!1,this.reauthFunc=void 0,this.events.removeAllListeners(),tP(()=>{var i;return(i=this.connection)==null?void 0:i.close()}),(e=this.connection)!=null&&e._ping&&window.clearInterval(this.connection._ping),this.connection=void 0,(r=this.ws)==null||r.close(),this.ws=void 0,t&&this.logout()}}I("utils/file");function nP(){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}nP();async function rP(n){const e=n.size,r=Math.floor((e+102400-1)/102400),i=new B9.Hash;for(let s=0;s<r;s++){const l=s*102400;let c=l+102400;c>e&&(c=e);const h=await n.slice(l,c,n.type).arrayBuffer();i.update(new Uint8Array(h))}const o=i.digest();return hi(o)}const Ti=I("sharedb-doc/client"),iP=Vb.default.create();class oP{constructor(t,e,r){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",tt());m(this,"getDoc",async()=>{const t=r=>new Promise((i,o)=>{r.fetch(s=>{s?o(s):i()})});p(Ti,!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),Ti.debug(e),e});this.auth=t;const i=`${e}/${this.auth.appId}/${this.auth.docId}`;QN.register(Pd.type),this.connection=new eP(i,r),this.reauthFunc=r}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(Ti,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,r=>{(t==="error"||this.doc)&&e(r)})}onAuthError(t){this.connection.onAuthError(t)}onAuthRecover(t){this.connection.onAuthRecover(t)}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,r,i,o){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...o},data:{name:r,size:i}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const r=`${this.apiServer()}/resources`;try{const i=`${r}/hash`,o=await this.request(i,{method:"post",headers:{[dl]:this.connection.token},data:{resources:t}});return o.data&&Array.isArray(o.data)?o.data:[]}catch{return[]}}async uploadFile(t,e,r,i,o){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=x=>{Ti.info(`on progress: ${x.loaded}`);let v=x.loaded*100/s;v>100&&(v=100),i(v)},c=await rP(e),d=await this.getFileUrlByHash(t,c,e.name,e.size,r);if(d)return i(-1),d;let h=t;o!=null&&o.thumbnail&&(h+="/thumbnail");const C=new FormData;C.append("file-size",`${e.size}`),C.append("file-hash",c),C.append("file",e,e.name);const E=await this.request(h,{method:"post",data:C,withCredentials:!0,headers:{...r},onUploadProgress:l});return Ti.info(E),i(100),Array.isArray(E.data)?E.data[0]:E.data}async uploadResource(t,e=()=>{},r){const o=`${this.apiServer()}/resources`;p(Ti,this.connection.token,"no connection token");const s=await this.uploadFile(o,t,{[dl]:this.connection.token},e,r);return p(Ti,s,"no result"),s}async request(t,e){var o,s;let r=this.connection.token,i;for(let l=0;l<2;l++){const c=e||{};c.url=t,c.headers||(c.headers={}),p(Ti,r,"no token"),c.headers={...c.headers,[dl]:r,[Ka]:this.connection.getBase64BaseURL()};try{return await iP(t,c)}catch(d){if(i=d,((o=d==null?void 0:d.response)==null?void 0:o.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;r=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw p(Ti,i,"no error"),i}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=$b.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(Ti,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const r=`${this.apiServer()}/resources/external/${hi(t)}`;return(await this.request(r)).data}getResourceId(t){const e=/\/resources\/([^?]+)/,r=t.match(e);return r&&r.length>=2?r[1]:""}buildResourceUrl(t,e){var s,l;if(!t)return"";if(t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;const r=this.apiServer();if(t.startsWith("http:")||t.startsWith("https:")){const c=r.replace(/\/[^/]*$/,"");if(c&&t.includes(c)){const d=this.auth.docId,h=`${c}/`,C="/resources",E=t.indexOf(h),x=t.indexOf(C,E+h.length);if(E!==-1&&x!==-1){const v=t.substring(E+h.length,x);if(v!==d){let R=t.replace(v,d);const w=new URL(R),U="token";(s=w.searchParams)==null||s.delete(U),R=w.toString();const M=this.getResourceId(R);return e!=null&&e.syncNewResources&&((l=e==null?void 0:e.syncNewResources)==null||l.call(e,M,R)),R}return t}return t}return t}let i=`${r}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken&&o.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const c=o.join("&");i+=`?${c}`}return i}reAuth(){this.connection.reAuth()}}function sP(){return{blocks:[{id:tt(),type:"text",text:[]}],comments:{},meta:{}}}const tC=I("block-ids");class lP{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((i,o)=>o-i);for(let i=0;i<e.length;i++){const o=e[i];if(o>=t){const s=this.ids.get(o);p(tC,s!==void 0,"old id is not exists"),this.ids.delete(o),this.ids.set(o+1,s)}}const r=tt();this.ids.set(t,r)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((r,i)=>r-i);for(let r=0;r<e.length;r++){const i=e[r];if(i>t){const o=this.ids.get(i);p(tC,o!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i-1,o)}}}getId(t){let e=this.ids.get(t);return e||(e=tt(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class aP{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new lP,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let r=0;r<e.length;r++){const i=e[r],o=i[1].getById(t);if(o)return{containerId:i[0],blockIndex:o[0]}}return p(tC,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class RT{constructor(t=new Set,e=new Map){this.deletedKeys=t,this.insertedValues=e}insert(t,e){this.insertedValues.set(t,e)}delete(t){this.deletedKeys.add(t)}toDocBlockDelta(){const t={};return this.insertedValues.forEach((e,r)=>{t[r]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const eC=I("op-parse-handler");class cP{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const r={...t,containerId:(i=>i==="blocks"?"root":i)(t.containerId)};this.actions.push(r)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,r){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:r})}onDeleteBlockData(t,e,r){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:r})}onInsertBlockData(t,e,r,i){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:r,value:i})}onUpdateBlockText(t,e,r){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:r})}onDeleteContainer(t){this.pushActions({type:"deleteContainer",containerId:t})}onCreateContainer(t,e){this.pushActions({type:"createContainer",containerId:t,data:e})}onDeleteComment(t){this.pushActions({type:"deleteComment",commentId:t})}onCreateComment(t){this.pushActions({type:"createComment",commentId:t})}onUpdateComment(t){this.pushActions({type:"updateComment",commentId:t})}end(){const t=this.actions,e=new Set,r=new Map,i=new aP,o=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of o)if(s.type==="deleteBlock"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);i.onDeleteBlock(l.containerId,l.blockIndex);const d=r.get(c);d&&(eC.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),r.delete(c));const h=`${l.containerId}-${l.blockIndex}`;e.add(h),this.outerHandler.onDeleteBlock(l.containerId,l.blockIndex,this.local)}else if(s.type==="deleteBlockData"){const l=s,c=`${l.containerId}-${l.blockIndex}`;if(e.has(c)){eC.warn("delete block data after delete block, ignore it");continue}const d=i.getBlockId(l.containerId,l.blockIndex);let h=r.get(d);h||(h=new RT,r.set(d,h)),h.delete(l.key)}else p(eC,!1,`invalid action type, ${s.type}`);this.actions.forEach(s=>{if(s.type==="deleteContainer"){const l=s;this.outerHandler.onDeleteContainer(l.containerId,this.local)}else if(s.type==="deleteComment"){const l=s;this.outerHandler.onDeleteComment(l.commentId,this.local)}}),this.actions.forEach(s=>{if(s.type==="createContainer"){const l=s;this.outerHandler.onCreateContainer(l.containerId,l.data,this.local)}}),this.actions.forEach(s=>{if(s.type==="insertBlock"){const l=s;this.outerHandler.onInsertBlock(l.containerId,l.blockIndex,l.data,this.local)}else if(s.type==="insertBlockData"){const l=s,c=i.getBlockId(l.containerId,l.blockIndex);let d=r.get(c);d||(d=new RT,r.set(c,d)),d.insert(l.key,l.value)}else if(s.type==="updateBlockText"){const l=s;this.outerHandler.onUpdateBlockText(l.containerId,l.blockIndex,l.richTextData,this.local)}else if(s.type==="createComment"){const l=s;this.outerHandler.onCreateComment(l.commentId,this.local)}else if(s.type==="updateComment"){const l=s;this.outerHandler.onUpdateComment(l.commentId,this.local)}}),Array.from(r.entries()).forEach(([s,l])=>{const{containerId:c,blockIndex:d}=i.getBlockIndexById(s);this.outerHandler.onUpdateBlockData(c,d,l.toDocBlockDelta(),this.local)})}}const He=I("op-parser");class wT{}class nC{constructor(t){m(this,"key");this.key=t}}function uP(n,t,e){const r=t.concat(),i=r[0];if(typeof i!="number"||(r.shift(),r.length===1))return!1;const o=r[0];if(typeof o!="object"||!o.i||Object.keys(o).length!==1)return!1;for(let l=1;l<r.length;l++){const c=r[l];if(!Array.isArray(c)||c.length!==2||typeof c[0]!="string")return!1;const h=c[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=o.i;p(He,s.id,"block id is required"),p(He,s.type,"block type is required");for(let l=1;l<r.length;l++){const c=r[l],d=c[0],h=c[1];s[d]=h.i}return e.onInsertBlock(n,i,s),!0}function rC(n,t,e,r){if(e==="upsert"&&uP(n,t,r))return;p(He,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const i=t.concat(),o=i[0];i.shift();const s=[];for(;i.length>0;){const l=i[0];if(l==="text"){const c=i[1];if(p(He,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),p(He,c.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),i.splice(0,2),e==="upsert"){const h=c.e;r.onUpdateBlockText(n,o,h)}p(He,i.length===0,`invalid block ops.length !== 0, ${JSON.stringify(i)}`)}else if(Array.isArray(l)){p(He,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];p(He,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const d=l[1];if(c==="text"){if(p(He,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&r.onInsertBlockData(n,o,c,d.i),d.r&&e==="remove"&&r.onDeleteBlockData(n,o,c),d.et==="rich-text"&&e==="upsert"){const C=d.e;r.onUpdateBlockText(n,o,C)}}else e==="remove"&&d.r&&s.push(new nC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i);i.shift()}else if(typeof l=="object"){const c=l;e==="remove"&&c.r&&s.push(new wT),e==="upsert"&&c.i&&r.onInsertBlock(n,o,c.i),i.shift()}else{p(He,typeof l=="string","data is not string"),p(He,l!=="text","data !== 'text'"),p(He,i.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(i)}`);const c=l,d=i[1];e==="remove"&&d.r&&s.push(new nC(c)),e==="upsert"&&d.i&&r.onInsertBlockData(n,o,c,d.i),i.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof wT?r.onDeleteBlock(n,o):l instanceof nC?r.onDeleteBlockData(n,o,l.key):p(He,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function fP(n,t,e){He.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function dP(n,t,e){const r=n[1],i=n[2];p(He,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),p(He,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?He.error(`unknown comment op, ${JSON.stringify(n)}`):i.i&&i.r?t==="upsert"&&e.onUpdateComment(r):i.i?t==="upsert"&&e.onCreateComment(r):i.r?t==="remove"&&e.onDeleteComment(r):He.error(`unknown comment op, ${JSON.stringify(n)}`)}function iC(n,t,e){const r=n[0];if(Array.isArray(r)){r.forEach(s=>{iC(s,t,e)});return}const i=r;if(p(He,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){fP(n);return}if(i==="comments"){dP(n,t,e);return}const o=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{rC(o,s,t,e)}):n.slice(1).forEach(s=>{rC(o,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(o),s.i&&t==="upsert"&&e.onCreateContainer(o,s.i)}else p(He,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),rC(o,n.slice(1),t,e)}function oC(n,t,e){const r=new cP(t,e);for(let i=0;i<2;i++){const o=i===0?"remove":"upsert",s=mt.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{iC(c,o,r)}):iC(s,o,r)}r.end()}const hP=I("sharedb-comments");function sC(n){const t=n.blocks;p(hP,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([r,i])=>{Array.isArray(i)&&(e.blocks[r]=i)}),mt.default(e)}function ST(n){const{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}=n;return{id:t,groupId:e,userId:r,displayName:i,avatarUrl:o,abstract:s,created:l,modified:c}}function lC(n,t){const e=WO(t),{comments:r,meta:i,blocks:o,...s}=e,l={...n,blocks:o,...s},c=mt.default(l);return delete c.children,c}const ae=I("sharedb-doc/doc-container"),LT="ot-json1";Pd.type.registerSubtype(qO.type),Pd.type.name=LT,Pd.type.invert=null;class qu extends ma{constructor(e,r,i=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new zO);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)})});m(this,"handleReset",async e=>{const r=new Error(`reset doc: ${e}`);r.code="ResetDoc",this.callbacks.forEach(i=>{var o;return(o=i.onError)==null?void 0:o.call(i,r)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,r,i)=>{const o=[e,r,{i}];return this.submitOp(o)});m(this,"deleteObject",async(e,r)=>{const i=[e,r,{r:!0}];return this.submitOp(i)});m(this,"replaceObject",async(e,r,i)=>{const o=[e,r,{r:!0,i}];return this.submitOp(o)});m(this,"updateObject",async(e,r,i)=>{const o=this.data()[e][r],s=[e,r];return Object.entries(i).forEach(([l,c])=>{if(!Xc.default(o[l],c))if(o[l]===void 0){if(c!=null){const d={i:c};s.push([l,d])}}else if(c==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:c};s.push([l,d])}}),Object.entries(o).forEach(([l,c])=>{if((i[l]===void 0||i[l]===null)&&c!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const r={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(r)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((r,i)=>{if(this.destroyed){ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},o=>{o?(ae.error(`invalid op, ${o.message}, ${JSON.stringify(e)}`),i(o),ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):r()}),this.doc.data||(ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((r,i)=>{this.doc.create(e,LT,o=>{o?i(o):r()})}));m(this,"submitInsertChildContainers",async e=>{if(e.length===0)return Promise.resolve();const r=e.map(({containerId:i,blocks:o})=>[ao(i),{i:o}]);return this.submitOp([r])});m(this,"submitDeleteChildContainer",async e=>{const r=[ao(e),{r:!0}];return this.submitOp(r)});m(this,"submitInsertBlock",async(e,r,i)=>{const o=[ao(e),r,{i}];return this.submitOp(o)});m(this,"submitDeleteBlock",async(e,r)=>{const i=[ao(e),r,{r:!0}];return this.submitOp(i)});m(this,"submitUpdateBlockData",async(e,r,i)=>{if(i.delete.length===0&&Object.keys(i.insert).length===0)return Promise.resolve();const o=[ao(e),r],s=new Set(i.delete);Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c)){const h={r:!0,i:d};o.push([c,h])}});const l=new Set(Object.keys(i.insert));return i.delete.forEach(c=>{if(l.has(c))return;const d={r:!0};o.push([c,d])}),Object.entries(i.insert).forEach(([c,d])=>{if(s.has(c))return;const h={i:d};o.push([c,h])}),this.submitOp(o)});m(this,"submitUpdateRichText",async(e,r,i)=>{const o=[ao(e),r,"text",{e:i,et:"rich-text"}];return this.submitOp(o)});m(this,"handleOp",(e,r,i)=>{if(this.destroyed){ae.warn("handleOp: destroyed");return}try{oC(e,this,!!r)}catch(o){throw ae.error(o),o}});this.client=e,this.doc=r,this.doc.preventCompose=!0,this.disableLogout=i,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,p(ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const r=new oP(e.auth,e.serverUrl,e.reauthFunc),i=await r.getDoc(),o=new qu(r,i,e.disableLogout);if(i.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await o.createDoc(e.templateData||sP())}return await o.initPresence(),await o.subscribe(),o.initEvents(),o}catch(r){throw ae.error(r),ae.error(`failed to load doc: ${JSON.stringify(r)}`),r}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(r=>{var i;return(i=r.onStatusChanged)==null?void 0:i.call(r,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onAuthError(e=>{this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,e)})}),this.client.onAuthRecover(()=>{this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,r)=>{if(this.localPresence)e();else{const i=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);i.on("receive",(o,s)=>{this.onCustomMessage(s)}),i.subscribe(o=>{o?r(o):(this.localPresence=i.create(tt()),e())})}})}subscribe(){return new Promise((e,r)=>{this.doc.subscribe(i=>{i?r(i):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return lo(this.data())}getContainerBlocks(e){const r=this.data();p(ae,r,"no doc data");const i=r[ao(e)];return p(ae,i,`no container data: ${e}`),mt.default(i)}findContainerBlocks(e){const r=this.data();p(ae,r,"no doc data");const i=r[ao(e)];return i!=null?i:null}getBlockData(e,r){const i=this.data();p(ae,i,"no doc data");const o=i[ao(e)];p(ae,o,`no container data: ${e}`);const s=o[r];return p(ae,s,`no block data: ${r}`),mt.default(s)}localInsertBlock(e,r,i){return this.submitInsertBlock(e,r,i),this.getBlockData(e,r)}localDeleteBlock(e,r){const i=this.getBlockData(e,r);return this.submitDeleteBlock(e,r),i}localUpdateBlockText(e,r,i){const o=this.getBlockData(e,r);p(ae,o.text,"no block text");const s=mt.default(o.text);this.submitUpdateRichText(e,r,i);const l=pn.apply(s,i);return p(ae,l,"no block text"),l}localUpdateBlockData(e,r,i){const o=mt.default(this.getBlockData(e,r));return this.submitUpdateBlockData(e,r,i),o}localInsertChildContainers(e){this.submitInsertChildContainers(e)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(r=>{this.submitDeleteChildContainer(r)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(r=>ST(r))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const r=this.data().comments[e];return sC(r)}localCreateComment(e,r){const i=lC(e,r),s=["comments",i.id,{i}];return this.submitOp(s)}localDeleteComment(e){const r=["comments",e,{r:!0}];return this.submitOp(r)}localUpdateComment(e,r){const i=lC(e,r),o=["comments",e.id,{r:!0,i}];return this.submitOp(o)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,r,i){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(o=>{var s;return(s=o.onDeleteBlock)==null?void 0:s.call(o,Na(e),r,i)})}onInsertBlock(e,r,i,o){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Na(e),r,i,o)})}onUpdateBlockData(e,r,i,o){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Na(e),r,i,o)})}onUpdateBlockText(e,r,i,o){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Na(e),r,i,o)})}onDeleteContainer(e,r){p(ae,this.callbacks.length>0,"no callbacks"),p(ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteChildContainer)==null?void 0:o.call(i,Na(e),r)})}onCreateContainer(e,r,i){p(ae,this.callbacks.length>0,"no callbacks"),p(ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(o=>{var s;return(s=o.onInsertChildContainer)==null?void 0:s.call(o,Na(e),r,i)})}onDeleteComment(e,r){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onDeleteComment)==null?void 0:o.call(i,e,r)})}onCreateComment(e,r){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onCreateComment)==null?void 0:o.call(i,e,r)})}onUpdateComment(e,r){p(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var o;return(o=i.onUpdateComment)==null?void 0:o.call(i,e,r)})}onCustomMessage(e){const r=e;(r==null?void 0:r.type)==="custom"&&(r==null?void 0:r.clientId)!==this.client.clientId?this.callbacks.forEach(i=>{var o;return(o=i.onCustomMessage)==null?void 0:o.call(i,r.data)}):(r==null?void 0:r.type)==="onlineUsers"&&setTimeout(()=>{const i={type:"custom",data:e,clientId:"-"};this.onCustomMessage(i)})}onAuthRecover(){this.callbacks.forEach(e=>{var r;return(r=e.onAuthRecover)==null?void 0:r.call(e)})}async addResources(e){let r=[];return e.forEach(o=>{const s=o.split("|");r.push(...s)}),r=Array.from(new Set(r)),await this.client.getFileUrlsByHashes(r)}async uploadResource(e,r){var o;return{resourceId:await this.client.uploadResource(e,(o=r==null?void 0:r.onProgress)!=null?o:()=>{})}}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}request(e,r){return this.client.request(e,r)}getUser(){const e=this.client.clientId,{permission:r,userId:i,displayName:o,avatarUrl:s}=this.client.auth;return{permission:r,clientId:e,userId:i,displayName:o,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return lo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return lo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:lo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:lo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,r){oC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}triggerReAuth(){this.client.reAuth()}}I("remote-cursor");class IT{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",ke.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const r=this.editor.findBlockById(e);r&&this.editor.reloadBlock(r)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const DT=I("remote-cursor-decorator");class aC{decorateText(t,e,r){const i=t.doc.getRemoteUsers();if(!i)return{};const o=new Map,{containerId:s,blockIndex:l}=e[e.length-1];p(DT,typeof s=="string","invalid path containerId"),p(DT,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),d=gn(r);return i.getSimpleCursors(c.id).forEach((C,E)=>{E>d&&(E=d);const x=C.map(R=>({id:tt(),type:"remote-cursor",name:R.user.displayName,time:R.time,rainbowIndex:R.user.rainbowIndex})),v=o.get(E);v?v.push(...x):o.set(E,x)}),{insertions:o}}}const cC=I("sharedb-doc/share-db-server"),mP=Vb.default.create();class gP{constructor(t,e){m(this,"auth");m(this,"clientId",tt());this.serverUrl=e,this.auth=t}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return p(cC,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}apiServer(){const t=`${this.serverUrl}/${this.auth.appId}/${this.auth.docId}`;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}getBaseURL(){const t=new URL(this.apiServer());return`${t.protocol}//${t.host}${t.pathname}`}getBase64BaseURL(){return hi(this.getBaseURL())}async request(t,e){var o;const r=this.auth.token,i=e||{};i.url=t,i.headers||(i.headers={}),p(cC,r,"no token"),i.headers={...i.headers,[dl]:r,[Ka]:this.getBase64BaseURL()};try{return await mP(t,i)}catch(s){throw(o=s.response)!=null&&o.data&&(s.responseData=s.response.data),s}}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,i=(await this.request(e)).data.versions;return i.forEach(o=>{o.extra&&(o.extra=JSON.parse(o.extra))}),i}async getVersion(t){const r=`${this.apiServer()}/versions/${t}`,i=await this.request(r);return JSON.parse(i.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,r=await this.request(e);return JSON.parse(r.data.data)}async getVersionOps(t,e){let i=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(i+=`&from=${e}`);const o=await this.request(i),s=o.data.ops,l=$b.default(s,h=>!!h.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let d;return c?(p(cC,c.create,"no createDoc.create"),d=c.create.data):d=JSON.parse(o.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:o.data.ops}}async updateVersionExtra(t,e,r){const o=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(o,{method:"post",data:{extra:JSON.stringify(r)}})}async revertVersion(t){const r=`${this.apiServer()}/versions/revert/${t}`;await this.request(r,{method:"post",data:{}})}async createVersion(t,e){const i=`${this.apiServer()}/versions`;return(await this.request(i,{method:"post",data:{publish:e,tag:t}})).data}buildResourceUrl(t,e){if(!t)return"";if(t.startsWith("https:")||t.startsWith("http:")||t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;let i=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const o=[];if(e!=null&&e.withToken,e!=null&&e.downloadFileName&&o.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),o.length>0){const s=o.join("&");i+=`?${s}`}return i}}const pP=I("sharedb-doc/share-db-server");function _T(n){const t=new URL(n);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}function CP(n){return hi(_T(n))}class r0 extends ma{constructor(e){super();m(this,"remoteUsers",new Uu);m(this,"client");this.options=e,this.client=new gP(e.auth,e.serverUrl)}destroy(){}buildResourceUrl(e,r){return this.client.buildResourceUrl(e,r)}getRemoteUsers(){return this.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const r=await this.client.getVersion(e);return lo(r)}async getLatestVersion(){const e=await this.client.getLatestVersion();return lo(e)}async getHistoryData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r),s=o.map(l=>({user:l.meta.createdBy,data:l}));return{doc:lo(i),historyData:s}}async getVersionData(e,r){const{doc:i,ops:o}=await this.client.getVersionOps(e,r);return{doc:lo(i),versionData:o}}async updateVersionExtra(e,r,i){await this.client.updateVersionExtra(e,r,i)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,r){return this.client.createVersion(e,r)}parseHistoryData(e,r){oC(e.data.op,r,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}static async auth(e,r){p(pP,e.token,"no auth token");const i=`${_T(r)}/auth`,o=await window.fetch(i,{method:"GET",headers:{[dl]:e.token,[Ka]:CP(r)},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return await o.json()}static async load(e){const r=`${e.serverUrl}/${e.auth.appId}/${e.auth.docId}`;return await this.auth(e.auth,r),new r0(e)}}class MT extends ye.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,r){if(qt(Ur(this.editor,t)))return;const i=this.editor.getBlockByIndex(t,e),o=J(this.editor.getContainerById(t));o&&this.emit("change",this.editor,{containerId:t,blockIndex:e},o,i,r)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}onInsertBlock(t,e){qt(Ur(this.editor,t))||this.emit("insert",this.editor,{containerId:t,blockIndex:e})}onDeleteBlock(t,e){this.handleChild(t,e,"remove")}destroy(){this.editor.doc.unregisterCallback(this)}}function UT(n,t){const e=n.addCustom("child-block-tracker",()=>new MT(n));e.addListener("change",t),e.addListener("insert",t)}function OT(n,t){const e=n.addCustom("child-block-tracker",()=>new MT(n));e.removeListener("change",t),e.removeListener("insert",t)}const Fct="",EP={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"}},xP={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},AP={colorPalette:{colorDesc:"\u30D5\u30A9\u30F3\u30C8\u306E\u8272",name:"\u30C6\u30AD\u30B9\u30C8\u306E\u8272",backgroundDesc:"\u80CC\u666F\u8272",reset:"\u30C7\u30D5\u30A9\u30EB\u30C8\u306B\u623B\u3059"},search:{emptyTips:"\u691C\u7D22\u7D50\u679C\u304C\u3042\u308A\u307E\u305B\u3093"}};D.mergeLang({"zh-CN":EP,"en-US":xP,"ja-JP":AP});const Kct="";I("button");function br(n,t,e,r,i){const o=B("button",["editor-button"],null);return o.setAttribute("data-button-id",n),i&&o.setAttribute(`data-editor-tooltip-${i}`,t),e?typeof e=="string"?e.startsWith("<")?o.innerHTML=e:o.innerText=e:o.appendChild(e):o.innerText=t,r&&(r.indexOf("checked")!==-1&&z(o,"checked"),r.indexOf("disabled")!==-1&&(o.disabled=!0),r.indexOf("primary")!==-1&&z(o,"primary")),o}const Vct="",i0=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
32
32
  <path d="M8.00874 7.89952L12.9497 2.94975M8.00874 7.89952L12.9497 12.8492M8.00874 7.89952L3.05025 12.8492M8.00874 7.89952L3.05025 2.94975" stroke="currentColor" stroke-linejoin="round"/>
33
33
  </svg>
34
34
  `,NT=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -959,4 +959,4 @@ ${o.mermaidText}
959
959
  ${o.flowchartText}
960
960
  \`\`\`\`\`\``}return""}const Ptt={embedType:"flowchart",convertFrom:Utt,handleUpdateBlock:Mtt,createEmbedContent:_tt,getBlockProperties:Ott,convertTo:Ntt},Ftt=I("plantuml-helper");function YS(n,t){var l;let r=((l=(n.getComponentOptions("plantuml")||{}).cdn)==null?void 0:l.plantuml)||ptt;r.endsWith("/")||(r+="/");const i=S9.default.encode(t);p(Ftt,i,i),r+=i;const s=new URLSearchParams(document.location.search).get("doc");return Xg(r,{id:`${s}-${tt()}`})}async function Ktt(n,t){try{const e=await Nx(n,t);return(await n.doc.uploadResource(e)).resourceId}catch{return Promise.resolve(t)}}class Ac extends Vx{constructor(t){super(t,"plantuml","plantumlText")}static get(t,e){return t.addCustom(`plantuml-${e.id}`,()=>new Ac(t))}code2ObjectUrl(t){return Promise.resolve(YS(this.editor,t))}code2ResourceId(t){const e=YS(this.editor,t);return Ktt(this.editor,e)}destroy(){}}function Vtt(n,t,e){Ac.get(n,e).createEmbedContent(t,e)}function $tt(n,t,e){const r=Ac.get(n,e),i=Ot(t);return r.updateEmbedContent(i,e),!0}function Htt(n,t,e){const{data:r}=e,i=n.getBlockString(t).trim();if(!r||r.embedType!=="plantuml"||i!=="```plantuml"||!nt(n,t))return null;const o={src:"",plantumlText:""};return{blockData:{id:tt(),type:"embed",embedType:"plantuml",embedData:o},onConverted:(c,d)=>{Ac.get(c,c.getBlockData(d)).editGraph(Ot(d))}}}function jtt(n,t){return Ac.get(n,n.getBlockData(t)).getBlockProperties(t)}function ztt(n,t,e,r){const{embedData:i}=t,o=i;if(r==="html")return o.src?`<img src="${n.doc.buildResourceUrl(o.src,{withToken:!0})}" />`:o.flowchartText?`<div>${o.flowchartText}</div>`:"<p>[plantuml]</p>";if(r==="markdown"){if(o.src)return`![plantuml](${n.doc.buildResourceUrl(o.src,{withToken:!0})})`;if(o.flowchartText)return`\`\`\`plantuml\`\`\`
961
961
  ${o.flowchartText}
962
- \`\`\`\`\`\``}return""}const Gtt={embedType:"plantuml",convertFrom:Htt,handleUpdateBlock:$tt,createEmbedContent:Vtt,getBlockProperties:jtt,convertTo:ztt},Qut="",Wtt="hr",qtt={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},Xtt={dividingLine:{type:"Dividing-Line",abstract:"Dividing-Line"}},Ytt={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};D.mergeLang({"zh-CN":qtt,"en-US":Xtt,"ja-JP":Ytt});function Qtt(n,t){const e=B("div",["editor-embed-container"],t);B("hr",["editor-embed-hr"],e)}function Jtt(n,t,e,r){return r==="html"?"<hr />":r==="markdown"?"---":"------------"}function Ztt(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:D.t("dividingLine.type"),icon:fy,order:500,group:"common",subText:kn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:r}=t;return n.insertEmbed(e,r,Wtt,{})}}}function tet(n,t,e){const{data:r}=e;if(!r||r.embedType!=="dividing-line"||!nt(n,t))return null;const i={};return{blockData:{id:tt(),type:"embed",embedType:"hr",embedData:i}}}function eet(){return{abstract:D.t("dividingLine.abstract")}}const net={embedType:"hr",createEmbedContent:Qtt,convertTo:Jtt,getOptions:Ztt,convertFrom:tet,getBlockProperties:eet},Jut="",Zut="",ret={media:{upload:{failed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>',maxSizeFailed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u6587\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6</div>'},load:{failed:'<div class="line-1">{name}\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},iet={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>',maxSizeFailed:'<div class="line-1">{name} upload failed</div><div class="line-2">The file size exceeds limit. Please choose another file.</div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}},oet={media:{upload:{failed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>',maxSizeFailed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u30D5\u30A1\u30A4\u30EB\u306E\u30B5\u30A4\u30BA\u304C\u4E0A\u9650\u3092\u8D85\u3048\u3066\u3044\u308B\u305F\u3081\u3001\u4ED6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044</div>'},load:{failed:'<div class="line-1">{name}\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},audio:{menuItem:"\u97F3\u58F0",abstract:"\u97F3\u58F0"},video:{menuItem:"\u52D5\u753B",abstract:"\u52D5\u753B"}}};D.mergeLang({"zh-CN":ret,"en-US":iet,"ja-JP":oet});var ni=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(ni||{}),Vf=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(Vf||{});const QS=10*1024*1024,set=["wav","mp3","aac","ogg","webm","flac"],aet=["ogg","mp4","webm"],cet=()=>{};function JS(n){var h,C,E,x,v,R;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:r,callbacks:i}=t,o=(C=e==null?void 0:e.audio)!=null?C:set,s=(E=e==null?void 0:e.video)!=null?E:aet,l=(x=r==null?void 0:r.audio)!=null?x:QS,c=(v=r==null?void 0:r.video)!=null?v:QS,d=(R=i==null?void 0:i.onError)!=null?R:cet;return{allowedMedias:{audio:o,video:s},maxSize:{audio:l,video:c},callbacks:{onError:d}}}function uet(n,t){const e=o=>o.map(s=>`.${s}`).join(","),{allowedMedias:r}=JS(n),i=r[t];return i?e(i):"*"}function fet(n,t,e){const{maxSize:r,callbacks:i,allowedMedias:o}=JS(t),{[e]:s}=r,{[e]:l}=o;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,i!=null&&i.onError&&(i==null||i.onError(t,d)),d}const c=iu(n.name);if(l&&!l.includes(c.toLowerCase())){const d=new Error(`media file is not allowed: ${c}`);throw d.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(t,d)),d}}function det(n){return n===Vf.Empty||n===Vf.Error}const tn=I("media");class het extends ye.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,r)=>{if(!r.target||!(r.target instanceof Node)||!(r.target instanceof Element?r.target:r.target.parentElement))return;const o=J(r.target);if(!o||!o.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",lt(o))});m(this,"handleUploadFile",async e=>{p(tn,this.abstract,"no abstract"),p(tn,this.mediaContainer,"The media element not exist");const{editor:r}=this.options,i=J(this.mediaContainer);p(tn,i,"The block element not exist");const o=r.getBlockData(i);try{const{resourceId:s}=await r.doc.uploadResource(e,{onProgress:C=>{this.renderProgress(C,e)}}),{name:l,type:c,size:d}=e,h={...o,embedData:{...o.embedData,src:s,fileName:l,fileSize:d,fileType:c}};r.updateBlockData(i,h)}catch(s){tn.error(s),this.emit("mediaError",r,"upload_error",o.id),this.renderRetry(e,s)}ot(i,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){p(tn,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){p(tn,this.abstract,"no abstract");const{editor:e,createMediaElement:r}=this.options,{mediaIcon:i,mediaName:o}=this.abstract;p(tn,this.mediaContainer,"The media element not exist");const s=J(this.mediaContainer);p(tn,s,"The block element not exist");const l=e.getBlockData(s),c=B("div",["media-error","embed-selected-content","embed-hover-content"],null),d=B("span",["media-error-icon"],c);d.innerHTML=i;const h=B("div",[],c);h.innerHTML=D.t("media.load.failed",{name:o}),c.appendChild(h);const C=h.querySelector(".retry-upload");return p(tn,C,"The element not exist"),e.domEvents.addEventListener(C,"click",(E,x)=>{const v=B("div",["media-element"],null),R=this.getResourceUrl(l),w=r(E,v,l,R);this.unbindMediaEvent(),this.media=w,this.bindMediaEvent(),this.updateMediaContent(v)}),this.setFullScreen(),c}renderRetry(e,r){var E,x;p(tn,this.abstract,"no abstract");const{editor:i}=this.options,{mediaIcon:o,mediaName:s}=this.abstract,l=B("div",["media-error","embed-selected-content","embed-hover-content"],null),c=B("span",["media-error-icon"],l);c.innerHTML=o;const d=B("div",[],l);let h=D.t("media.upload.failed",{name:s});(((E=r.response)==null?void 0:E.status)===420||((x=r.response)==null?void 0:x.status)===413)&&(h=D.t("media.upload.maxSizeFailed",{name:s})),d.innerHTML=h,l.appendChild(d);const C=d.querySelector(".retry-upload");C&&i.domEvents.addEventListener(C,"click",()=>{i.readonly||(p(tn,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(l),this.setFullScreen()}renderProgress(e,r){p(tn,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope .media-progress"),o=e===-1||e===100?100:e;if(i){const{updateProgressElement:s}=this.options;s(i,o)}else{const{createProgressElement:s}=this.options,l=J(this.mediaContainer);p(tn,l,"The element not exist"),z(l,"media-block-uploading");const c=B("div",["media-progress"],null);s(c,o,r),this.updateMediaContent(c)}this.setFullScreen()}renderMediaElement(e,r){p(tn,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:o,updateMediaElement:s,editor:l}=this.options,c=this.getResourceUrl(e,r);if(i){const d=s(l,i,e,c);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent()}else{const d=B("div",["media-element"],null),h=o(l,d,e,c);this.unbindMediaEvent(),this.media=h,this.bindMediaEvent(),this.updateMediaContent(d)}}renderEmpty(e){p(tn,this.abstract,"no abstract"),p(tn,this.mediaContainer,"The media element not exist");const r=B("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);r.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(r);const{editor:i}=this.options;i.findBlockById(e.id)&&this.emit("mediaError",i,"empty",e.id),this.setFullScreen()}getResourceUrl(e,r){const{src:i}=e.embedData,{editor:o}=this.options;return o.doc.buildResourceUrl(i,{syncNewResources:async(s,l)=>{var d,h;if(!r)return;await o.doc.addResources([s]);const c=(h=(d=o.doc).getServerMeta)==null?void 0:h.call(d).appId;if(l!==e.embedData.src&&c&&e.embedData.src.includes(c)){const C=J(r);if(C&&!o.readonly&&o.isBlockWritable(C)){const E=mt.default(e);E.embedData.src=s,o.updateBlockData(C,E)}}}})}setFullScreen(){p(tn,this.mediaContainer,"The media element not exist"),z(this.mediaContainer,"full-screen")}removeFullScreen(){p(tn,this.mediaContainer,"The media element not exist"),ot(this.mediaContainer,"full-screen")}updateBlockAlign(e,r){const i=J(r);p(tn,i,"The block element not exist");const{align:o}=e;e.embedType==="video"&&(i.hasAttribute("data-style-align")&&i.removeAttribute("data-style-align"),i.setAttribute("data-style-align",o))}render(e,r){const{src:i}=e.embedData;(!this.mediaContainer||!r.contains(this.mediaContainer))&&(this.mediaContainer=B("div",["media"],r)),this.updateBlockAlign(e,r),det(i)?i===Vf.Empty&&this.renderEmpty(e):this.renderMediaElement(e,r)}setAbstract(e){this.abstract=e}}I("media-embed");const met="left";class ZS{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var C;const{containerId:r,blockIndex:i}=e;let o;(C=e.data)!=null&&C.file&&(o=e.data.file);const s=uet(t,this.embedType);if(o=o!=null?o:await Ea(s,{}),!o)return null;const{mediaType:l}=this.getAbstract();try{fet(o,t,l)}catch{return null}const c={id:tt(),type:"embed",embedType:this.embedType,embedData:{src:Vf.Empty}};l==="video"&&(c.align=met);const d=t.insertBlock(r,i,c);return await this.getMedia(t,c.id).handleUploadFile(o),d})}getMedia(t,e){const r=t.addCustom(`media-${e}`,()=>new het({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return r.setAbstract({...this.getAbstract()}),r}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:r,order:i,group:o}=this.getAbstract();return{name:r,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:i,group:o,subText:kn(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,r){const{id:i}=r;this.getMedia(t,i).render(r,e)}handleUpdateBlock(t,e,r){const{id:i}=r,o=this.getMedia(t,i),s=Ot(e);return o.render(r,s),!0}handleDeleteBlock(t,e){const r=e.id,i=this.getMedia(t,r);i.removeAllListeners(),i.destroy()}convertTo(t,e,r,i){const o=e.embedData,s=t.doc.buildResourceUrl(o.src,{withToken:!0});return i==="html"?`<${o.type} src="${s}" />`:i==="markdown"?`![${o.src}](${s})`:s}}function tL(n,t){const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e),i=B("div",["uploading-progress-bar-value"],r);i.style.width=`${t}%`}function eL(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const get=I("media-audio");class pet extends ZS{constructor(){super(...arguments);m(this,"embedType",ni.AUDIO);m(this,"updateProgressElement",eL);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["audio-container","embed-hover-content","embed-selected-content"],r),l=B("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=o,setTimeout(()=>{this.getMedia(e,i.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:ay,mediaName:D.t(`media.${ni.AUDIO}.menuItem`),menuItem:D.t(`media.${ni.AUDIO}.menuItem`),order:800,mediaType:ni.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${ni.AUDIO}.abstract`)}`}}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .audio-container > audio");return p(get,s,"The media element not exist"),s.src!==o&&(s.src=o),s}createProgressElement(e,r){const i=B("audio",[],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,i.src="about:blank",tL(e,r)}}const Cet=new pet;I("video-resizer");function nL(n){return n&&ge(n)&&Ve(n)==="video"}const Eet=50;class $x{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&nL(e)&&this.disableBlockResize(e),t&&nL(t)&&this.editor.isBlockWritable(t))){const r=this.getVideoElement(t);if(!r)return;this.enableBlockResize(t,r)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const r=t.getBlock();if(!r)return;const i=r.getBoundingClientRect().width,o=Math.min(Math.max(e.width,Eet),i);this.currentResizableElement.style.width=`${o}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const r=this.editor.getBlockData(e),{width:i}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...r,width:i})});this.editor=t,Re.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,Re.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Ot(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${lt(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${lt(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const r=this.editor.addCustom(`${lt(t)}-resizer`,()=>new xf(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));r.enableResize(t,e),r.removeListener("resizing",this.handleResizing),r.removeListener("resized",this.handleResized),r.addListener("resizing",this.handleResizing),r.addListener("resized",this.handleResized),this.currentResizableElement=e}}const xet=I("video");class Aet extends ZS{constructor(){super(...arguments);m(this,"embedType",ni.VIDEO);m(this,"updateProgressElement",eL);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["video-container","embed-selected-content","drag-preview-element"],r),l=B("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=o,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new $x(e)),this.getMedia(e,i.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).removeFullScreen()}),i.width&&(l.style.width=`${i.width}px`),l});m(this,"createProgressElement",(e,r,i)=>{const o=B("video",["progress-video"],e);o.innerHTML="Your browser does not support the <code>audio</code> element.",o.controls=!0,tL(e,r),Ca(i).then(s=>{const l=e.querySelector(".progress-video");l&&hp(e)&&(l.src=s)})})}getAbstract(){return{mediaName:D.t(`media.${ni.VIDEO}.menuItem`),mediaIcon:cy,menuItem:D.t(`media.${ni.VIDEO}.menuItem`),order:700,mediaType:ni.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${ni.VIDEO}.abstract`)}`}}handleMediaError(e,r,i){const o=e.addCustom("video-resizer",()=>new $x(e)),s=e.getBlockById(i);o.disableBlockResize(s)}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .video-container > video");p(xet,s,"The media element not exist"),s.src!==o&&(s.src=o),i.width?s.style.width=`${i.width}px`:s.style.width="";const l=e.getBlockById(i.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new $x(e)).updateResizer(l)}),s}}const bet=new Aet,rL=[RE,UE,OE,Jk],Hx=[GS,bZ,Stt,Ptt,Gtt,L$,net,bet,Cet,DW,BS,hQ],iL=[uR,kS,X4,gR];function vet(n,t,e){var i,o,s,l;_r.level=(i=e.logLevel)!=null?i:Ho.DEBUG;const r=Mu(n,t,{components:{blocks:[...rL,...((o=e==null?void 0:e.components)==null?void 0:o.blocks)||[]],embeds:[...Hx,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[...iL,...((l=e.components)==null?void 0:l.boxes)||[]],textRenders:[new aE],options:{...e.componentsOptions}}});return r.readonly=!0,r.addCustom("heading-collapse",()=>new wx(r)),r.addCustom("editor-tooltip",()=>new ff(r)),r.addListener("clickLink",(c,d,h)=>{var E;if((E=e==null?void 0:e.events)!=null&&E.onClickLink){e.events.onClickLink(c,d,h);return}const C=h.getAttribute("link");C&&(c.readonly||d.ctrlKey||d.metaKey)&&window.open(C,"_blank")}),r}class oL{constructor(t){this.createOptions=t,t.lang&&D.setLang(t.lang)}createHistoryEditor(t,e){return vet(t,e,this.createOptions)}}function sL(n,{root:t,childDoc:e,doc:r}){var h,C;e.uploadResource=r.uploadResource.bind(r),e.buildResourceUrl=r.buildResourceUrl.bind(r);const i=n.getComponentOptions("comment"),o={image:{defaultAlign:"left"},table:{locatingContainer:t,hideCellMenu:!0,hideToolbar:!0},...i==null?void 0:i.componentsOptions},s=[];n.editorBlocks.forEach(E=>{E.blockType==="text"||E.blockType==="embed"||s.push(E)});const l=[];n.editorEmbeds.forEach(E=>{l.push(E)});const c=[];n.editorBoxes.forEach(E=>{E.boxType==="text"||E.boxType==="br"||E.boxType==="image"||E.boxType==="anchor"||c.push(E)});const d=Mu(t,e,{shortcuts:[Gh],components:{blocks:s,commandProviders:[new T0],decorators:[new Q0],embeds:l,boxes:c,options:o}});if(d.input.addHandler(new Z0),d.input.addHandler(new ex(d)),d.input.addHandler(new lx(d)),d.input.addHandler(new BY(d)),d.input.addHandler(new rm),d.addCustom("image-paste-handler",()=>new tx(d)),ie.isMobile||d.addCustom("editor-tooltip",()=>new ff(d)),n.options.enableContextMenu!==!1&&d.addCustom("editor-context-menu",E=>new ux(E)),(h=n.options.componentsOptions)!=null&&h.mention){const E=n.options.componentsOptions.mention;d.addCustom("mention",()=>new yS(d,{...E}))}if((C=n.options.componentsOptions)!=null&&C.comment){const E=n.options.componentsOptions.comment;E.onCommentEditorClick&&d.addListener("click",E.onCommentEditorClick)}return d}function Bet(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),r=new Set;e.forEach(i=>{const o=J(i);o&&r.add(o)}),r.forEach(i=>{TY(n,i,t)})}class Tet{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const r=e.groupId;this.getComments().filter(o=>o.groupId===r).length===0&&Bet(this.editor,r)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){return sL(this.editor,{root:t,childDoc:e,doc:this.doc})}allowEdit(t){return t.userId===this.doc.getUser().userId}}class yet{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 sC(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){return sL(this.editor,{root:t,childDoc:e,doc:this.localDoc})}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const ket={placeholder:{common:{title:"\u8BF7\u8F93\u5165\u6807\u9898",readonlyTitle:"\u8BF7\u8F93\u5165\u6807\u9898",content:"\u70B9\u51FB + \uFF0C\u6216\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6",contentInTable:"\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6"},local:{readonlyTitle:"\u672A\u547D\u540D"}},copyCutProperty:{copy:"\u590D\u5236",cut:"\u526A\u5207",unsafeEnvTips:"\u7531\u4E8E\u5F53\u524D http \u8BBF\u95EE\u73AF\u5883\u4E0B\u7684\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528\u5FEB\u6377\u952E({shortCut}) {operation}",limitedEnvTips:"\u7531\u4E8E\u6D4F\u89C8\u5668\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528 {shortCut} \u7C98\u8D34"}},Ret={placeholder:{common:{title:"Enter a title",readonlyTitle:"Enter a title",content:'Click "+", or enter "/" to insert components quickly',contentInTable:'Enter "/" to insert components quickly'},local:{readonlyTitle:"Untitled"}},copyCutProperty:{copy:"Copy",cut:"Cut",unsafeEnvTips:"Due to the limitations of the current http access environment, please use the shortcut ({shortCut}) {operation}",limitedEnvTips:"Press {shortCut} to paste due to browser restrictions"}},wet={placeholder:{common:{title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",readonlyTitle:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",content:"\u300C+\u300D\u3092\u30AF\u30EA\u30C3\u30AF\u3059\u308B\u304B\u3001\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059",contentInTable:"\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059"},local:{readonlyTitle:"\u7121\u984C"}},copyCutProperty:{copy:"\u8907\u88FD",cut:"\u5207\u308B",unsafeEnvTips:"HTTP\u74B0\u5883\u306E\u5236\u7D04\u306B\u3088\u308A\u3001{operation}\u3059\u308B\u306B\u306F\u3001\u30B7\u30E7\u30FC\u30C8\u30AB\u30C3\u30C8({shortCut}) \u3092\u3054\u4F7F\u7528\u304F\u3060\u3055\u3044",limitedEnvTips:"\u30D6\u30E9\u30A6\u30B6\u30FC\u306E\u5236\u9650\u306B\u3088\u308A\u3001\u300C{shortCut}\u300D\u3092\u4F7F\u7528\u3057\u3066\u8CBC\u308A\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044"}};D.mergeLang({"zh-CN":ket,"en-US":Ret,"ja-JP":wet});const Let="UEsDBBQABgAIAAAAIQBk9WPugQEAACkGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAIQDlI7CA9QMAAKALAAARAAAAAAAAAAAAAAAAAKcWAAB3b3JkL3NldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQBAwf/xOQEAACMDAAAUAAAAAAAAAAAAAAAAAMsaAAB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQA520VMuQUAACdaAAASAAAAAAAAAAAAAAAAADYcAAB3b3JkL251bWJlcmluZy54bWxQSwECLQAUAAYACAAAACEA+JXI7/wOAADzmQAADwAAAAAAAAAAAAAAAAAfIgAAd29yZC9zdHlsZXMueG1sUEsBAi0AFAAGAAgAAAAhAMySUFR9AQAA8QIAABEAAAAAAAAAAAAAAAAASDEAAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhACJREfHVAQAA3gMAABAAAAAAAAAAAAAAAAAA/DMAAGRvY1Byb3BzL2FwcC54bWxQSwECLQAUAAYACAAAACEAiD+lv+EAAABVAQAAGAAAAAAAAAAAAAAAAAAHNwAAY3VzdG9tWG1sL2l0ZW1Qcm9wczEueG1sUEsBAi0AFAAGAAgAAAAhAMEnywi2AAAAIQEAABMAAAAAAAAAAAAAAAAARjgAAGN1c3RvbVhtbC9pdGVtMS54bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAABVOQAAY3VzdG9tWG1sL19yZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAOuAYExTAwAAjw4AABIAAAAAAAAAAAAAAAAAWzsAAHdvcmQvZm9udFRhYmxlLnhtbFBLBQYAAAAADwAPANQDAADePgAAAAA=",Iet=()=>Yg(Let),Det=I("image-to-docx");async function _et(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function lL(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};try{const e=await Ca(new File([t],"",{})),r=await _et(e);return r.width===void 0||r.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||r.width*n.height/r.height,height:n.height||r.height*n.width/r.width,buffer:t}:{width:r.width,height:r.height,buffer:t}}catch(e){Det.error(e);return}}function Met(n,t){let e=n.filter(s=>s!=null);const r=t-(e.length-1)*20,i=.87,o=e.reduce((s,l)=>s+l.width,0);return o>r&&(e=e.map(s=>({width:s.width*r/o,height:s.height*r/o,buffer:s.buffer}))),e.map(s=>({width:s.width*i,height:s.height*i,buffer:s.buffer}))}function Uet(n,t,e){if(!e||typeof e!="object")return;const r=e,i=n.filter(s=>s!=null),o=t-(i.length-1)*20;i.forEach((s,l)=>{if(i.length===1&&r.widthPercent){const d=r.widthPercent,h=s.width;s.width=o*(d/100),s.height*=s.width/h;return}const c=`${l}_flex`;if(r[c]){const d=r[c],h=s.width;s.width=o*d,s.height*=s.width/h}})}function aL(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let r;switch(e%3){case 0:r=Ct.LevelFormat.DECIMAL;break;case 1:r=Ct.LevelFormat.LOWER_LETTER;break;default:r=Ct.LevelFormat.LOWER_ROMAN;break}return{level:e,format:r,text:`%${e+1}. `,alignment:Ct.AlignmentType.START,start:t,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(e+1)),hanging:Ct.convertInchesToTwip(.2)}}}}})}function Oet(){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:Ct.LevelFormat.BULLET,text:t,alignment:Ct.AlignmentType.START,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(n+1)),hanging:Ct.convertInchesToTwip(.2)}}}}})}function Net(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Ct.LevelFormat.BULLET,text:"\u2611",alignment:Ct.AlignmentType.START,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(n+1)),hanging:Ct.convertInchesToTwip(.2)}}}}))}function Pet(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Ct.LevelFormat.BULLET,text:"\u2610",alignment:Ct.AlignmentType.START,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(n+1)),hanging:Ct.convertInchesToTwip(.2)}}}}))}var $f=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))($f||{});const Fet=[{levels:aL(),reference:"number-numbering-reference"},{levels:Oet(),reference:"number-bullet-reference"},{levels:Net(),reference:"checked-bullet-reference"},{levels:Pet(),reference:"unchecked-bullet-reference"}];function Ket(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 Vet(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 $et(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 Het=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function cL(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(Het);if(t){const e=s=>{let l=Number(s).toString(16);return l.length<2&&(l=`0${l}`),l},r=e(t[1]),i=e(t[2]),o=e(t[3]);return`${r}${i}${o}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function un(n,t){if(n&&n.attributes&&n.attributes[t])return n.attributes[t];if(n&&n.attributes&&n.attributes.box&&n.attributes.inputType&&t==="style-underline")return!0}function uL(n,t,e){for(let r=0;r<=e;++r){const i=`${t}${r}`;if(un(n,i))return i}}function km(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function jx(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function fL(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function jet(n){const t=un(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const r of e){const i=r.split(":");if(i.length!==2)continue;const o=i[0].trim().toLowerCase(),s=i[1].trim().toLowerCase();o==="font-size"&&km(n,"inline-style-font-size",s),o==="color"&&km(n,"inline-style-color",s),o==="background-color"&&km(n,"inline-style-background-color",s),o==="font-family"&&km(n,"inline-style-font-family",s)}}function zet(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function Get(n){const t=`${un(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function Wet(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 qet(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function Xet(n){return un(n,"inline-style-font-family")}function Yet(n){const t=un(n,"inline-style-background-color");return cL(t)}function Qet(n){const t=un(n,"inline-style-color");return cL(t)}function Jet(n){jet(n);const t=un(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!un(n,"style-code"),link:fL(un(n,"link")),size:Get(n),text:t?qet(n):Wet(n)||n.insert,bold:!!un(n,"style-bold"),underline:!!un(n,"style-underline"),italics:!!un(n,"style-italic"),strike:!!un(n,"style-strikethrough"),superScript:!!un(n,"style-super"),subScript:!!un(n,"style-sub"),math:un(n,"type")==="math"?un(n,"src"):void 0,mention:t,fontFamily:Xet(n),background:Yet(n),color:t?"338fe5":Ket(uL(n,"style-color-",6))||Qet(n),highlight:uL(n,"style-bg-color-",13)}}function Zet(){return[new Ct.Paragraph({border:{top:{color:"auto",style:Ct.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new Ct.Paragraph({spacing:{line:0}})]}function tnt(){return new Ct.Paragraph({children:[new Ct.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function ent(){return new Ct.Paragraph({children:[new Ct.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function nnt(n,t){return new Ct.Paragraph({children:[new Ct.ExternalHyperlink({children:[new Ct.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function dL(n){if(n.heading!=null)return`Heading${n.heading}`}function hL(n){if(n.alignment!=null){if(n.alignment==="center")return Ct.AlignmentType.CENTER;if(n.alignment==="right")return Ct.AlignmentType.RIGHT;if(n.alignment==="left")return Ct.AlignmentType.LEFT}}function rnt(n){if(n.indent)return{left:Ct.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:Ct.convertInchesToTwip(.3*n.padding)}}function int(n){return{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function ont(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function mL(n,t){let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const r=n.size||t,i=r!=null?Math.floor(r*1.5+.5):void 0;return new Ct.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:Ct.UnderlineType.SINGLE}:void 0,italics:n.italics||void 0,strike:n.strike||void 0,superScript:n.superScript||void 0,subScript:n.subScript||void 0,size:i,style:e,font:n.fontFamily?ont(n.fontFamily):void 0,shading:n.background?int(n.background):void 0,color:n.color,highlight:Vet(n.highlight)})}function snt(n,t){if(n.link)return new Ct.ExternalHyperlink({children:[mL(n,t)],link:n.link})}async function gL(n,t,e,r,i){const[o]=await i(n,t,e);if(o==null)return;const s=await lL({width:r||0,height:0,src:e},o);return new Ct.ImageRun({data:o,transformation:{width:(s==null?void 0:s.width)||100,height:(s==null?void 0:s.height)||20}})}function lnt(n){if(n.heading||n.heading)return n.heading}function ant(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function cnt(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function unt(n,t){var r;const e=[];if(n.text&&Array.isArray(n.text)){for(let i=0;i<n.text.length;i++){const o=n.text[i];if(((r=o.attributes)==null?void 0:r.box)===!0&&t){const s=await t(o);if(s){n.text.splice(i+1,0,...s);continue}}e.push(Jet(o))}return e}}function fnt(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 dnt(n,t){if(n.type==="embed"&&n.embedType&&jx(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(r=>{const i=t(r),o=n.embedData[`${i}_width`],s=n.embedData[`${i}_height`];return{src:r,width:o,height:s}})}function hnt(n){if(n.padding)return n.padding}function mnt(n){return!!(n.type==="embed"&&n.embedType&&jx(n.embedType)&&n.embedData&&n.embedData.src)}async function Rm(n,t,e){return{quoted:!!n.quoted,heading:lnt(n),alignment:ant(n),indent:cnt(n),padding:hnt(n),texts:await unt(n,e),list:fnt(n),images:dnt(n,t),border:mnt(n)}}async function gnt(n,t,e,r){const i=[];if(!n.children)return[];for(const o of n.children){const s=[];for(const l of t.blocks[o])s.push(await Rm(l,e,r));i.push(s)}return i}const pnt=I("to-docx");function Cnt(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 Ent(n,t,e,r){const i=!!n.hasColTitle,o=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let c=0;c<t;c++)for(let d=0;d<e;d++)(i&&d===0||o&&c===0||s&&c%2===1)&&(r[c][d].color=l)}function xnt(n){p(pnt,n.children,"no table children");const t=n.rows,e=n.cols,r=n.colsWidth;if(r)for(let s=0;s<r.length;s++)r[s]===0&&(r[s]=100);const i=Cnt(t,e);let o=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(i[s][l].originalWidth=r?r[l]:void 0,i[s][l].from!==void 0)continue;const c=n.children[o];o+=1,i[s][l].cellId=c,i[s][l].color=$et(n[`${c}_background`]),i[s][l].width=r?r[l]:100,i[s][l].align=n[`${c}_align`];const d=n[`${c}_rowSpan`]||1,h=n[`${c}_colSpan`]||1;if(i[s][l].rowSpan=d,i[s][l].colSpan=h,d>1||h>1){let C=0;for(let E=0;E<d;E++)for(let x=0;x<h;x++)E===0&&(C+=r?r[l+x]:80),!(E===0&&x===0)&&(i[s+E][l+x].from=[s,l]);i[s][l].width=C}}return Ent(n,t,e,i),i}async function Ant(n,t,e,r,i,o,s,l,c,d){async function h(E){if(l&&E.type!=="_exportVirtualBlock"){const x=await l(i,o,E);if(x){await r.addDoc(n,x,d);return}}if(E.type==="text"||E.textOnly===!0){const x=await Rm(E,s,c);await r.addTextBlock(x);return}if(E.type==="code"){const x=await gnt(E,e,s,c);await r.addCodeBlockObject(x);return}if(E.type==="list"&&E.textOnly!==!0){const x=await Rm(E,s,c);await r.addListBlockObject(n,x);return}if(E.type==="embed"&&E.embedType){const x=E,v=x.embedData,R=x.embedType;if(jx(R)){const w=await Rm(E,s,c);await r.addImagesBlockObject(E,w,d)}else E.embedType==="hr"?r.addSeparatorBlock():E.embedType==="video"?r.addVideoPlaceholder():E.embedType==="audio"?r.addAudioPlaceholder():E.embedType==="webpage"?r.addHyperlinkParagraph(fL(v.src),v.title):r.addOtherEmbedBlock(R,E.embedData);return}if(E.type==="table"){let x=[];if(E.colsWidth)x=E.colsWidth;else{const R=E.cols;x=new Array(R);for(let w=0;w<x.length;w++)x[w]=100;E.colsWidth=x}const v=xnt(E);await r.addTableMatrix(x,v,e),r.addEmptyParagraph()}E.type==="_exportVirtualBlock"&&await r.addVirtualBlock(E.id,e,d)}function C(E){var R;const x=((R=E==null?void 0:E.embedData)==null?void 0:R.exportSpec)||(E==null?void 0:E.exportSpec);if(!x)return[E];const v=[];for(const{type:w,data:U}of x){if(w==="text"){const M={id:tt(),text:[{insert:U}],type:"text"};v.push(M);continue}if(w==="image"){const M={id:tt(),type:"embed",embedType:"image",align:"left",embedData:{src:U}};v.push(M);continue}if(w==="link"){const M={id:tt(),type:"embed",embedType:"webpage",embedData:{src:U.url,title:U.title}};v.push(M);continue}if(w==="block")for(const M of U){if(!e.blocks[M])continue;const G={id:M,type:"_exportVirtualBlock"};v.push(G)}}return v}for(const E of t)for(const x of C(E))!x||await h(x)}function bnt(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const vnt=I("to-docx");class Bnt{constructor(t,e,r,i,o,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=r,this.readImageFunc=i,this.convertBlocksFunc=o,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new Ct.Paragraph({heading:dL(t),alignment:hL(t),children:await this.paragraphsFromBlockTexts(t),indent:rnt(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new Ct.Paragraph({text:`[${D.t("docx.imageExportFailed")}]`,shading:{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=zet(this.defaultFontSize,t.heading),r=[];for(const i of t.texts){if(i.link){const o=snt(i,e);o&&r.push(o);continue}if(i.box&&i.box.type&&i.box.type==="br"){r.push(new Ct.TextRun({text:"",break:1}));continue}if(i.box&&i.box.type&&i.box.type==="image"){const o=await gL(this.appId,this.docId,i.box.src,i.box.width,this.readImageFunc);o&&r.push(o);continue}if(i.math){const o=await gL(this.appId,this.docId,i.math,0,this.readImageFunc);o&&r.push(o);continue}r.push(mL(i,e))}return r}async addCodeBlockObject(t){for(const e of t)for(const r of e){const i={style:Ct.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new Ct.Paragraph({style:"Code",border:{left:{...i},right:{...i},top:{...i},bottom:{...i}},children:await this.paragraphsFromBlockTexts(r)}))}}async addListBlockObject(t,e){if(e.list==null)return;let r;const i=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[i])r=this.state.listInstMap[i];else if(r=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[i]=r,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${r}`,l=aL([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:r}),this.state.listRefMap[i]=s}else e.list.ordered?this.state.listRefMap[i]=$f.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[i]=$f.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[i]=$f.UNCHECKED:this.state.listRefMap[i]=$f.BULLET;const o=dL(e);e.texts&&this.paragraphs.push(new Ct.Paragraph({heading:o,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[i],level:e.list.level-1,instance:r}}))}imageDimWithBufferToImageRun(t){return new Ct.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,r){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:c}=t.embedData;c||this.addEmptyImagePlaceHolder()}return}const i=[],o=await Promise.all(e.images.map(async c=>{const[d,h]=await this.readImageFunc(this.appId,this.docId,c.src);if(d){const C=await lL(c,d);if(C)return C}i.push(h)}));Uet(o,r,t.embedData);const s=Met(o,r),l={style:Ct.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new Ct.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:hL(e)||Ct.AlignmentType.CENTER,children:s.map(c=>this.imageDimWithBufferToImageRun(c)).flatMap((c,d,h)=>c==null?[]:h.length-1!==d?[c,new Ct.TextRun({text:" "})]:c)})),i.forEach(c=>{this.addHyperlinkParagraph(c)})}addSeparatorBlock(){Zet().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new Ct.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(tnt())}addAudioPlaceholder(){this.paragraphs.push(ent())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(nnt(t,e))}async addTableMatrix(t,e,r){const i=t.map(o=>o!==0?o*15:1500);this.paragraphs.push(new Ct.Table({rows:await this.generateTableRows(e,r),columnWidths:i}))}async generateRowCells(t,e){const r=[];for(const i of t){const o=i.cellId;if(o===void 0)continue;const s=i.width*.9;r.push(new Ct.TableCell({children:await this.convertBlocksFunc(o,e.blocks[o],e,this.appId,this.docId,this.state,s),columnSpan:i.colSpan,rowSpan:i.rowSpan,width:{type:Ct.WidthType.DXA,size:i.width*15},shading:i.color?{fill:i.color,type:Ct.ShadingType.CLEAR,color:"auto"}:void 0}))}return r}async generateTableRows(t,e){const r=[];for(const i of t)r.push(new Ct.TableRow({children:await this.generateRowCells(i,e)}));return r}async addDoc(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,r);i&&(this.paragraphs=this.paragraphs.concat(i))}async addVirtualBlock(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks[t],e,this.appId,this.docId,this.state,r);this.paragraphs.push(...i)}async addOtherEmbedBlock(){}}class Tnt{constructor(t,e,r,i,o,s,l,c){m(this,"convertBlocks",async(t,e,r,i,o,s,l=720)=>{const c=new Bnt(i,o,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await Ant(t,e,r,c,i,o,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),c.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=r,this.readImage=i,this.defaultFontSize=o,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=c}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,r){const i=new Ct.ImportDotx,o=this.templateData?await i.extract(this.templateData):void 0,s=t.blocks.root;p(vnt,s,"data must have blocks");const l=bnt(),c=await this.convertBlocks("blocks",s,t,e,r,l),d=this.backgroundImageOptions?{default:new Ct.Header({children:[new Ct.Paragraph({children:[new Ct.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new Ct.Document({numbering:{config:[...Fet,...l.levelConfigs]},sections:[{headers:d,children:c,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:o});return Ct.Packer.toBlob(h)}}async function ynt(n,t,e,r){const i=n.doc.buildResourceUrl(r,{withToken:!0});let o=await _S(i);if(!o)return[void 0,i];if(o.type.indexOf("/svg")!==-1){const l=await LS(o);l&&(o=new File([l],o.name))}return[await o.arrayBuffer(),i]}async function knt(n,t,e){const r=n.editorBlocks.getBlockClass(e.type);if(r.toStandardDoc)return r.toStandardDoc(n,e,t)}async function Rnt(n,t){const e=t.attributes,r=n.editorBoxes.getBoxClass(e.type);if(r.toStandardText)return r.toStandardText(n,e)}async function wnt(n,t){let{template:e,download:r,backgroundImageOptions:i}=t!=null?t:{};e||(e=Iet());const o=n.doc.toJSON(),s=(C,E,x)=>ynt(n,C,E,x),l=async(C,E,x)=>knt(n,o,x),c=async C=>Rnt(n,C),h=await new Tnt(e,o,Fd.default,s,void 0,l,c,i).convert("_appId","_docId");if(r){const C=URL.createObjectURL(h),E=document.createElement("a");E.setAttribute("download",`${DS(n)}.docx`),E.setAttribute("href",`${C}`),E.click(),E.remove()}return h}const zx=I("create-editor");async function Snt(n,t){var s,l,c,d,h,C,E,x,v,R,w,U,M,F;p(zx,n,"app does not exists"),t.lang&&D.setLang(t.lang),_r.level=(s=t.logLevel)!=null?s:Ho.DEBUG;const e=t.onReauth?async()=>{var st;const G=t.user.userId,q=t.docId,it=await((st=t.onReauth)==null?void 0:st.call(t,G,q,t.permission));return{userId:G,docId:q,permission:t.permission,appId:t.appId,token:it,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,r={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout},i=await qu.load(r),o=Mu(n,i,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,enableContextMenu:t==null?void 0:t.enableContextMenu,components:{blocks:[...rL,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...Hx,...((c=t.components)==null?void 0:c.embeds)||[]],boxes:[...iL,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new T0,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new Q0,new aC],insertions:[l1],blockHooks:[new XE,new Tw,...((C=t.components)==null?void 0:C.blockHooks)||[]],textRenders:[new V4,new aE],options:{...t.componentsOptions}},shortcuts:[UY,uz,vW,wE,h4,pV,vE,xQ,Gh,cV,...t.shortcuts||[]],colors:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"]});if(o.editorCommandProviders.registerCommandProvider(new Di(o)),o.input.addHandler(new aJ),o.input.addHandler(new Z0),o.input.addHandler(new U$),o.input.addHandler(new mW),o.input.addHandler(new NE(o,{hideTitle:t.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),o.input.addHandler(new j0(o,(E=t.componentsOptions)==null?void 0:E.quickMenu)),o.input.addHandler(new ex(o)),o.input.addHandler(new lx(o)),o.input.addHandler(new rm),o.doc.registerCallback(new cJ(o)),o.addCustom("remote-cursor",()=>new IT(o)),o.addCustom("block-menu",G=>new Rw(G)),ie.isMobile||o.addCustom("editor-tooltip",()=>new ff(o)),t!=null&&t.enableComments&&o.addCustom("editor-comments",G=>new K4(G,new Tet(G))),t.enableContextMenu!==!1&&o.addCustom("editor-context-menu",G=>new ux(G)),o.addCustom("create-options",()=>new Wb(o,t)),o.addCustom("drop-target",()=>new Sf(o)),o.addCustom("list-to-mindmap",()=>new N0(o)),o.addCustom("list-to-mention",()=>new LJ(o)),o.addCustom("mobile-helper",()=>new ZJ(o)),o.addCustom("code-caret",()=>new sz(o)),o.addCustom("image-paste-handler",()=>new tx(o)),(x=t.componentsOptions)!=null&&x.mention){const G=t.componentsOptions.mention;o.addCustom("mention",()=>new yS(o,G))}if(o.addCustom("heading-collapse",()=>new wx(o)),o.addCustom(Tm,G=>new Mx(G)),ic.register(o),Sf.register(o),ys.register(o),xs.register(o),o.addListener("clickLink",(G,q,it)=>{var Et;if((Et=t==null?void 0:t.events)!=null&&Et.onClickLink){t.events.onClickLink(G,q,it);return}const st=it.getAttribute("link");st&&(G.readonly||q.ctrlKey||q.metaKey)&&window.open(st,"_blank")}),(R=(v=t.componentsOptions)==null?void 0:v.remoteCarets)!=null&&R.onUserChanged){const G=(U=(w=t.componentsOptions)==null?void 0:w.remoteCarets)==null?void 0:U.onUserChanged;o.doc.getRemoteUsers().on("change",q=>{G(o,q)})}return(F=(M=t.componentsOptions)==null?void 0:M.templates)!=null&&F.templates.length&&(o.addListener("docChanged",()=>{Bm(o)}),o.addListener("resize",()=>{Bm(o,{reset:!0})}),setTimeout(()=>{Bm(o)},100)),o.doc.registerCallback({onError:async G=>{if(G.code==="ResetDoc"){zx.error(`reset doc: ${G.message}`);const q=await qu.load(r);o.doc.reset(q)}}}),o.version="1.1.17-beta.4",_r.level===Ho.DEBUG&&(window.setReauthFail=G=>{window.isReauthError=G},window.reConnect=G=>o.doc.externalDoc.client.connection.reConnect(G)),o}function Lnt(n){return n.toJSON!==void 0}async function Int(n,t,e){var o,s,l,c,d,h,C,E;p(zx,n,"app does not exists");const r=Lnt(t)?t:new K1(t,{serverUrl:e.serverUrl||""});e.lang&&D.setLang(e.lang),_r.level=(o=e.logLevel)!=null?o:Ho.DEBUG;const i=Mu(n,r,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[RE,UE,OE,Jk,...(l=(s=e.components)==null?void 0:s.blocks)!=null?l:[]],commandProviders:[new T0],decorators:[new Q0,new aC],embeds:[...Hx,...((c=e.components)==null?void 0:c.embeds)||[]],boxes:[uR,kS,X4,gR,...((d=e.components)==null?void 0:d.boxes)||[]],insertions:[l1],blockHooks:[new XE,...((h=e.components)==null?void 0:h.blockHooks)||[]],textRenders:[new V4,new aE,...((C=e.components)==null?void 0:C.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[wE,h4,vE,Gh]});return i.editorCommandProviders.registerCommandProvider(new Di(i)),i.input.addHandler(new Z0),i.input.addHandler(new NE(i,{hideTitle:e.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new j0(i,(E=e.componentsOptions)==null?void 0:E.quickMenu)),i.input.addHandler(new ex(i)),i.input.addHandler(new lx(i)),i.input.addHandler(new rm),i.addCustom("block-menu",x=>new Rw(x)),ie.isMobile||i.addCustom("editor-tooltip",()=>new ff(i)),i.addCustom("image-paste-handler",()=>new tx(i)),e!=null&&e.enableComments&&i.addCustom("editor-comments",x=>new K4(x,new yet(x,r))),e.enableContextMenu!==!1&&i.addCustom("editor-context-menu",x=>new ux(x)),i.addCustom("heading-collapse",()=>new wx(i)),i.addListener("clickLink",(x,v,R)=>{var U;if((U=e==null?void 0:e.events)!=null&&U.onClickLink){e.events.onClickLink(x,v,R);return}const w=R.getAttribute("link");w&&(x.readonly||v.ctrlKey||v.metaKey)&&window.open(w,"_blank")}),i.addCustom(Tm,x=>new Mx(x)),ic.register(i),i.version="1.1.17-beta.4",i}async function Dnt(n,t,e){var h;const r=n.doc.externalDoc.client.auth,i=await r0.load({auth:r,serverUrl:e});if(!((h=i.getVersionHelper)==null?void 0:h.call(i)))throw new Error("the editor does not support to show versions");const s=n.getCustom("create-options");if(!s)throw new Error("the editor does not support to show versions");const l=s.getData(),c=new oL(l),d=n.addCustom("version-dialog",()=>new fS(i,c));return d.show(t),d}b.tippy=y9,b.AnchorBox=YB,b.AuthError=Gu,b.AuthHeader=dl,b.AutoScroll=nh,b.BaseURLHeader=Ka,b.BasicCommands=r$,b.BlockExclusiveHook=Tw,b.BlockLockerHook=XE,b.BlockLockerPasteHandler=rm,b.BlockResizer=xf,b.BrBox=GB,b.CodeBlock=UE,b.CodeLineBlock=OE,b.CodeTextDecorator=Q0,b.DOC_RE_AUTH_KEYS=Tm,b.DefaultShortcuts=Gh,b.DocIdError=JN,b.DocReAuthCallbacks=Mx,b.DragDrop=fv,b.DrawioEmbed=GS,b.EditorBlocks=b3,b.EditorBoxes=qB,b.EditorCommandProviders=z2,b.EditorComplexBlockPosition=Kr,b.EditorComplexSelectionRange=pi,b.EditorDecorators=t5,b.EditorEmbeds=B3,b.EditorInsertions=ZB,b.EditorSimpleBlockPosition=Xe,b.EditorSimpleSelectionRange=nn,b.EmbedBlock=y3,b.EmbedBlockResizer=Nf,b.EnforceWithDocumentTitleHandler=NE,b.EventCallbacks=ma,b.FILL_CHAR=vM,b.FileExtError=ZN,b.GroupOrder=nR,b.HeadingBlockScrollListener=BJ,b.ImageBox=XB,b.InlineBoxCommandProvider=pR,b.InputtingInsertion=QB,b.LocalDoc=K1,b.LogLevel=Ho,b.Logger=_r,b.MIN_DISTANCE_THRESHOLD=cv,b.ManualCloseDialog=Yu,b.ManualMenu=as,b.ManualToolbar=Xu,b.MarkdownInputHandler=Z0,b.MaxUserError=Z1,b.Mindmap=O0,b.OnesEditorAutoSuggest=SC,b.OnesEditorCustomDataWrapper=Wb,b.OnesEditorExclusiveBlock=xs,b.OnesEditorHoveringBlock=Re,b.OnesEditorIcons=PP,b.OnesEditorQuickMenu=j0,b.OnesEditorToc=Kf,b.OnesEditorTocProvider=ys,b.OnesEditorToolbar=ic,b.OnesEditorTooltip=ff,b.OnesEditorVersionsDialog=fS,b.PermissionError=n0,b.Popup=ja,b.ReAuthToolbar=MS,b.RemoteCarets=IT,b.RemoteCaretsDecorator=aC,b.RemoteCaretsInsertion=l1,b.RemoteUsers=Uu,b.RequestReloadError=Wu,b.RichText=pn,b.ShareDBDoc=qu,b.ShareDBDocVersionsProvider=oL,b.ShareDBServer=r0,b.SimpleCache=ev,b.StandardEmbedBlockCommands=Ax,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=Kp,b.TEXT_STYLE_COLOR_PREFIX=Fp,b.TableBlock=RE,b.TableBlockCommandProvider=T0,b.TableShortcuts=wE,b.TextBlock=Nn,b.TextBox=zB,b.TextColorItem=Xy,b.TextStyleShortcuts=vE,b.TocEmbed=BS,b.ZERO_WIDTH_SPACE_CHAR=Zc,b.abbreviation=rh,b.addAttribute=Ch,b.addClass=z,b.addCommentToBlock=Of,b.addDays=MI,b.addMetaToDoc=Du,b.addMonths=_I,b.animateScrollTo=Ws,b.applyPlaceholderToBlock=Cf,b.assert=p,b.autoShowHideTemplates=Bm,b.bindKeyDownEvent=qd,b.blockToDoc=M1,b.blockToHtml=u1,b.blockToMarkdown=_h,b.blockToText=Dh,b.blocksToDoc=m2,b.clearAllSelection=e3,b.clientType=ie,b.cloneBlock=es,b.cloneChildContainer=A1,b.cloneDoc=b1,b.cloneText=OB,b.commentToShareDbComment=lC,b.compareElement=Gd,b.comparePosition=vp,b.complexBlockAdjustSelectionPos=ch,b.complexBlockFindNearestChildBlock=D7,b.complexBlockGetAllChildContainers=ln,b.complexBlockGetBottomChildContainers=S3,b.complexBlockGetDeepFirstChild=k3,b.complexBlockGetFirstSimpleChild=Tp,b.complexBlockGetLastSimpleChild=va,b.complexBlockGetSelectedContainers=ba,b.complexBlockGetTopChildContainers=w3,b.containerToDoc=g2,b.continuousScroll=Rv,b.convertBlockFrom=lh,b.convertImageFileToPng=LS,b.convertImageSrcToPng=WJ,b.converterIntercept=J0,b.copyBlockAttributes=d5,b.copyResourcesFromDoc=F1,b.createBlockAnchor=Zi,b.createBlockCaretAnchor=I3,b.createBlockContentElement=tl,b.createBlockElement=Gv,b.createBlockSimpleDocRange=Rh,b.createBlockSimpleRange=be,b.createBoxContentElement=Xv,b.createBoxElement=Wv,b.createBoxOp=UB,b.createChildContainer=x3,b.createComplexBlockPosition=Ee,b.createComplexDocPos=VB,b.createComplexDocRange=yM,b.createContainer=PB,b.createContainerElement=sp,b.createDeleteOps=IB,b.createEditor=Mu,b.createEditorSelectionRange=Ye,b.createElement=B,b.createEmptyContainer=oo,b.createEmptyDoc=io,b.createEmptyTextBlockData=yh,b.createExpandedRange=jd,b.createIconButton=js,b.createImage=Kg,b.createInsertOps=Bh,b.createInsertionContentElement=Jv,b.createInsertionElement=Yv,b.createLocalEditor=Int,b.createOnesEditor=Snt,b.createRange=nv,b.createRichText=al,b.createRootContainer=E3,b.createSimpleBlockPosition=at,b.createSimpleDocPos=KB,b.createTextBlockData=Ai,b.createTextButton=bl,b.createTextOp=Er,b.createTextWithReplaceSoftReturn=Jp,b.daysAfter=ep,b.deleteText=t1,b.diffDays=UI,b.disablePageScroll=Jg,b.docToHtml=l5,b.docToHtmlFragment=yu,b.docToMarkdown=a5,b.docToText=ts,b.downloadImageToFile=_S,b.downloadObjectToFile=Nx,b.downloadSvgToString=NS,b.editLink=af,b.editorAddComment=kY,b.editorAddTextAttribute=B5,b.editorAutoInsertBlock=h5,b.editorBreakTextBlock=Da,b.editorClearCompositionText=m1,b.editorClearSelectedContents=Ph,b.editorCopyBlock=N1,b.editorCopyDoc=zh,b.editorDeleteBlock=C1,b.editorDeleteBlockText=g1,b.editorDeleteBlockWithoutChildren=Oh,b.editorDeleteChildContainer=BU,b.editorDeleteChildContainers=m5,b.editorFocusToBlock=x1,b.editorFocusToEnd=$U,b.editorGetBlockData=Zo,b.editorGetBlockText=yn,b.editorGetBlockTextEx=Sh,b.editorGetBoxData=HB,b.editorHandleKeyboardEvent=R2,b.editorInsertBlock=Ia,b.editorInsertBoxToBlock=u5,b.editorInsertDoc=b5,b.editorInsertDocAt=v1,b.editorInsertText=h1,b.editorInsertTextToBlock=c5,b.editorInsertTextToBlockEx=d1,b.editorMergeTextBlock=g5,b.editorMoveDown=O5,b.editorMoveEnd=S1,b.editorMoveHome=G5,b.editorMoveLeft=_5,b.editorMoveLineEnd=t2,b.editorMoveLineHome=Z5,b.editorMovePageDown=s2,b.editorMovePageUp=o2,b.editorMoveRight=M5,b.editorMoveUp=U5,b.editorMoveWordEnd=H5,b.editorMoveWordLeft=$5,b.editorRangeClearColor=y5,b.editorRangeGetColor=k5,b.editorRangeSetColor=T5,b.editorRemoveTextAttribute=RU,b.editorReplaceBlockText=Fh,b.editorReplaceContainer=v5,b.editorRunOnce=V1,b.editorSelectAll=I1,b.editorSelectContainer=$h,b.editorSelectDown=N5,b.editorSelectEnd=L1,b.editorSelectHome=W5,b.editorSelectLeft=P5,b.editorSelectLineEnd=J5,b.editorSelectLineHome=Q5,b.editorSelectPageDown=c2,b.editorSelectPageUp=a2,b.editorSelectRight=F5,b.editorSelectUp=K5,b.editorSelectWordEnd=z5,b.editorSelectWordLeft=j5,b.editorSetTextColor=_a,b.editorShowFindDialog=EX,b.editorToDocx=wnt,b.editorUpdateBlockData=Kh,b.editorUpdateCompositionText=f5,b.editorUpdateEmbedData=x5,b.enablePageScroll=Zg,b.escapeHtmlText=Xd,b.escapeRegExp=op,b.escapeSpace=pI,b.exclusiveBlock=GE,b.executeBlockCommand=u3,b.executeEmbedBlockCommand=c3,b.executeRangeCommand=j2,b.fileToDataUrl=Ca,b.findAfterOffsetNotType=i1,b.findAllText=D1,b.findBlockByIndex=Pv,b.findEventTargetBlock=ov,b.findInsertionById=Qv,b.findNextOffset=zM,b.findNextVisibleSimpleBlock=X2,b.findPrevOffset=jM,b.findPrevOffsetNotType=r1,b.findPrevSimpleBlockBeforeChildContainer=R3,b.findPrevVisibleSimpleBlock=q2,b.findTarget=pa,b.findWordEnd=s1,b.findWordLeft=o1,b.format=ou,b.formatBytes=wv,b.formatDate=rp,b.fragmentToHtml=vv,b.fromBase64=eu,b.fromBase64ToBlob=Yg,b.fromBase64ToUint8Array=RI,b.fromDocRange=Xo,b.fromNowString=ip,b.genId=tt,b.getAllChildBlocks=wp,b.getAllQuickMenuItems=bE,b.getAllSelectedBlocks=Ci,b.getAttributesAt=ka,b.getBlockBackground=cp,b.getBlockByIndex=zo,b.getBlockCaretRect=Wo,b.getBlockClass=Qt,b.getBlockClassByType=Qs,b.getBlockClientRects=Yi,b.getBlockCommandsWithHook=pp,b.getBlockContent=Ot,b.getBlockHeading=uu,b.getBlockId=lt,b.getBlockIndex=vt,b.getBlockInfo=Tf,b.getBlockKind=Nr,b.getBlockMinWidth=r3,b.getBlockNearestRangeFromPoint=kp,b.getBlockOptions=qI,b.getBlockPath=qo,b.getBlockProperties=s3,b.getBlockRangeFromPoint=uh,b.getBlockStyles=WI,b.getBlockTextLength=dt,b.getBlockTools=oe,b.getBlockType=It,b.getBoxContent=fp,b.getBoxId=qv,b.getBoxTypeFromElement=cu,b.getChildBlockCount=Or,b.getChildBlocks=fe,b.getChildOffset=Qo,b.getColorFromAttributes=$p,b.getColorFromContent=ih,b.getComplexBlockClass=hr,b.getContainerBlockPath=g3,b.getContainerBlocks=t3,b.getContainerBlocksElement=lu,b.getContainerById=Ur,b.getContainerId=ct,b.getContainerMinWidth=Ap,b.getContainerToolsElement=jI,b.getContainerWidth=A3,b.getDistanceSquare=jo,b.getElementFromPoint=xe,b.getElementOffset=Jc,b.getElementScale=dr,b.getEmbedType=Ve,b.getExistsBlockTools=oh,b.getExistsContainerById=su,b.getFileExt=iu,b.getFirstChildBlock=Ae,b.getFirstClientRect=zd,b.getHeadingBlockChildren=Aa,b.getHeadingMenuOptions=gE,b.getHorizontalPadding=$g,b.getInsertionContent=dp,b.getLastChildBlock=Ue,b.getLastClientRect=zs,b.getListAllNextBrothers=Za,b.getLogger=I,b.getNextBlock=Jt,b.getNextHiddenBlocks=h3,b.getNextValidOffset=sl,b.getNextVisibleBlock=gr,b.getOffsetFromPoint=Vg,b.getOffsetInfoAfter=vu,b.getOffsetInfoBefore=Lh,b.getOpAt=fB,b.getOpLength=ph,b.getParentBlock=J,b.getParentBlockExcludeSelf=Zs,b.getParentBox=up,b.getParentContainer=rt,b.getPrevBlock=Oe,b.getPrevValidOffset=Jo,b.getPrevVisibleBlock=mr,b.getRangeCommands=$2,b.getReferenceClientRect=wk,b.getRootBlock=gp,b.getScrollContainer=qe,b.getSpecialBlockCommands=l3,b.getStandardEmbedBlockProperties=bx,b.getTextAfterOffset=$M,b.getTextAttributes=f1,b.getTextBeforeOffset=HM,b.getTextBlockChild=hu,b.getTextBlockClass=Kv,b.getTextBlockContentChildTextLength=Cr,b.getTextBlockContentChildType=m3,b.getTextBlockContentChildren=gi,b.getTextLength=gn,b.getTextOpLength=Pp,b.getTextWidth=Zd,b.getToolbar=L0,b.handleBlockElementUpdated=i3,b.hasAltOnly=vI,b.hasClass=Rt,b.hasCtrlOrCmd=Cv,b.hasCtrlOrCmdOnly=bI,b.hashCode=Uv,b.hideBlock=zv,b.htmlToFragment=Jd,b.i18n=D,b.includeBigTable=mF,b.injectDocToHtmlFragment=Iu,b.injectStyle=av,b.inputActions=aO,b.insertEmptyBlock=QI,b.insertEmptyEmbedBlock=Cp,b.insertText=ro,b.intersectionCommands=VO,b.isBackspace=xv,b.isBlock=Js,b.isBlockLocked=nm,b.isBlockLockedByOthers=qE,b.isBlockLockedBySelf=yf,b.isBlockTools=jv,b.isBox=sh,b.isBoxOp=to,b.isCJK=gv,b.isChildContainer=Fr,b.isChildNode=re,b.isCodeBlock=Zr,b.isCollapsedHeadingBlock=mi,b.isCollapsedRange=TM,b.isComplexBlockPosition=nl,b.isComplexKindBlock=Lt,b.isContainer=Xi,b.isContainerSelectedAllChildBlocks=u2,b.isControlEvent=Xs,b.isDelete=TI,b.isDraggingFiles=th,b.isElementVisible=zg,b.isEmbedBlock=ge,b.isEmptyContainer=mu,b.isEmptyDoc=e1,b.isEmptyTextBlock=se,b.isEmptyTextBlockWithoutCompositionText=pf,b.isEnterOnly=Ev,b.isEscape=Qd,b.isExclusiveBlock=Bf,b.isExpandedHeadingBlock=d3,b.isFirefox=Yc,b.isFirstChildBlockInComplexBlock=I7,b.isHeadingBlock=sn,b.isHighSurrogate=dI,b.isInBlock=hp,b.isInBlockTools=xa,b.isLetter=mv,b.isLowSurrogate=hI,b.isMatchShortcut=di,b.isMoveForward=xI,b.isNavigationEvent=EI,b.isNavigationKey=pv,b.isNodeRemoved=Qc,b.isNumber=hv,b.isPrintableKey=qg,b.isRootBlock=pr,b.isRootContainer=qt,b.isSafari=Hs,b.isSameDay=np,b.isSelectBoxOnly=Jr,b.isShiftEnter=BI,b.isShiftTab=kI,b.isShortcutEvent=AI,b.isSimpleBlock=GI,b.isSimpleBlockPosition=Vr,b.isSimplePos=FB,b.isSimpleRange=kh,b.isSpace=Yd,b.isTab=yI,b.isTextBlockContentBoxChild=Qn,b.isTextBlockContentChild=fu,b.isTextBlockContentInsertionChild=Ji,b.isTextBlockContentTextChild=du,b.isTextKindBlock=nt,b.isTextKindBlockType=au,b.isTitleBlock=qi,b.isToday=Sv,b.isValidOffset=On,b.isVisibleBlock=Go,b.isYesterday=Lv,b.loadJs=iv,b.loadJsPromise=Gs,b.lockers=Mr,b.mergeCommands=S0,b.mergeDocs=cl,b.mergeOps=Zp,b.mergeText=AM,b.multiSplitText=hB,b.overflowText=Iv,b.parseShortcut=Av,b.patchNode=nu,b.pointInRect=qs,b.rangeAddAttribute=xu,b.rangeGetTextColor=AB,b.rangeRemoveAttribute=ya,b.rangeSetTextColor=CB,b.rangeTransformText=gB,b.registerDragDrop=Gg,b.removeAttribute=Vp,b.removeClass=ot,b.removeLastBr=pM,b.removePlaceholderFromBlock=YR,b.removeStyle=lv,b.replaceAll=OI,b.replaceAllCaseInsensitive=NI,b.replaceAllText=d2,b.replaceText=Th,b.requestDownload=eh,b.resetListStart=ec,b.scrollIntoView=Tu,b.scrollable=kv,b.selectFile=Ea,b.selectedBlockToDoc=Hh,b.selectionToDoc=Ma,b.setAttributes=Wd,b.setClipboardData=ru,b.setClipboardDataByEvent=LI,b.setColorToAttributes=EB,b.setDataset=Hg,b.setDefaultCursor=tu,b.setStyles=jg,b.shareDBCommentToDocObject=sC,b.shareDBDocCommentToComment=ST,b.shortcutToDisplayText=We,b.showBlock=ap,b.showDocVersions=Dnt,b.splitText=Mn,b.splitToThree=Qe,b.stringToDataUrl=Qg,b.stringToObjectUrl=tp,b.subText=mB,b.textNodeOffsetFromPoint=rv,b.titleFromEditor=DS,b.toBase64URL=hi,b.toMindmap=U0,b.toPlainText=de,b.toPlainTextKeepLength=n1,b.trimChar=Wg,b.unexclusiveBlock=WE,b.unicodeLength=mI,b.unicodeSubstr=gI,b.updateBlockSelection=n3,b.updateOpAttributes=NB,b.updateTextBlockContent=VM,b.updateUrl=Xg;for(const n in ye)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>ye[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
962
+ \`\`\`\`\`\``}return""}const Gtt={embedType:"plantuml",convertFrom:Htt,handleUpdateBlock:$tt,createEmbedContent:Vtt,getBlockProperties:jtt,convertTo:ztt},Qut="",Wtt="hr",qtt={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},Xtt={dividingLine:{type:"Dividing-Line",abstract:"Dividing-Line"}},Ytt={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};D.mergeLang({"zh-CN":qtt,"en-US":Xtt,"ja-JP":Ytt});function Qtt(n,t){const e=B("div",["editor-embed-container"],t);B("hr",["editor-embed-hr"],e)}function Jtt(n,t,e,r){return r==="html"?"<hr />":r==="markdown"?"---":"------------"}function Ztt(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:D.t("dividingLine.type"),icon:fy,order:500,group:"common",subText:kn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:r}=t;return n.insertEmbed(e,r,Wtt,{})}}}function tet(n,t,e){const{data:r}=e;if(!r||r.embedType!=="dividing-line"||!nt(n,t))return null;const i={};return{blockData:{id:tt(),type:"embed",embedType:"hr",embedData:i}}}function eet(){return{abstract:D.t("dividingLine.abstract")}}const net={embedType:"hr",createEmbedContent:Qtt,convertTo:Jtt,getOptions:Ztt,convertFrom:tet,getBlockProperties:eet},Jut="",Zut="",ret={media:{upload:{failed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>',maxSizeFailed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u6587\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6</div>'},load:{failed:'<div class="line-1">{name}\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},iet={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>',maxSizeFailed:'<div class="line-1">{name} upload failed</div><div class="line-2">The file size exceeds limit. Please choose another file.</div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}},oet={media:{upload:{failed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>',maxSizeFailed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u30D5\u30A1\u30A4\u30EB\u306E\u30B5\u30A4\u30BA\u304C\u4E0A\u9650\u3092\u8D85\u3048\u3066\u3044\u308B\u305F\u3081\u3001\u4ED6\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044</div>'},load:{failed:'<div class="line-1">{name}\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},audio:{menuItem:"\u97F3\u58F0",abstract:"\u97F3\u58F0"},video:{menuItem:"\u52D5\u753B",abstract:"\u52D5\u753B"}}};D.mergeLang({"zh-CN":ret,"en-US":iet,"ja-JP":oet});var ni=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(ni||{}),Vf=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(Vf||{});const QS=10*1024*1024,set=["wav","mp3","aac","ogg","webm","flac"],aet=["ogg","mp4","webm"],cet=()=>{};function JS(n){var h,C,E,x,v,R;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:r,callbacks:i}=t,o=(C=e==null?void 0:e.audio)!=null?C:set,s=(E=e==null?void 0:e.video)!=null?E:aet,l=(x=r==null?void 0:r.audio)!=null?x:QS,c=(v=r==null?void 0:r.video)!=null?v:QS,d=(R=i==null?void 0:i.onError)!=null?R:cet;return{allowedMedias:{audio:o,video:s},maxSize:{audio:l,video:c},callbacks:{onError:d}}}function uet(n,t){const e=o=>o.map(s=>`.${s}`).join(","),{allowedMedias:r}=JS(n),i=r[t];return i?e(i):"*"}function fet(n,t,e){const{maxSize:r,callbacks:i,allowedMedias:o}=JS(t),{[e]:s}=r,{[e]:l}=o;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,i!=null&&i.onError&&(i==null||i.onError(t,d)),d}const c=iu(n.name);if(l&&!l.includes(c.toLowerCase())){const d=new Error(`media file is not allowed: ${c}`);throw d.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(t,d)),d}}function det(n){return n===Vf.Empty||n===Vf.Error}const tn=I("media");class het extends ye.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,r)=>{if(!r.target||!(r.target instanceof Node)||!(r.target instanceof Element?r.target:r.target.parentElement))return;const o=J(r.target);if(!o||!o.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",lt(o))});m(this,"handleUploadFile",async e=>{p(tn,this.abstract,"no abstract"),p(tn,this.mediaContainer,"The media element not exist");const{editor:r}=this.options,i=J(this.mediaContainer);p(tn,i,"The block element not exist");const o=r.getBlockData(i);try{const{resourceId:s}=await r.doc.uploadResource(e,{onProgress:C=>{this.renderProgress(C,e)}}),{name:l,type:c,size:d}=e,h={...o,embedData:{...o.embedData,src:s,fileName:l,fileSize:d,fileType:c}};r.updateBlockData(i,h)}catch(s){tn.error(s),this.emit("mediaError",r,"upload_error",o.id),this.renderRetry(e,s)}ot(i,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){p(tn,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){p(tn,this.abstract,"no abstract");const{editor:e,createMediaElement:r}=this.options,{mediaIcon:i,mediaName:o}=this.abstract;p(tn,this.mediaContainer,"The media element not exist");const s=J(this.mediaContainer);p(tn,s,"The block element not exist");const l=e.getBlockData(s),c=B("div",["media-error","embed-selected-content","embed-hover-content"],null),d=B("span",["media-error-icon"],c);d.innerHTML=i;const h=B("div",[],c);h.innerHTML=D.t("media.load.failed",{name:o}),c.appendChild(h);const C=h.querySelector(".retry-upload");return p(tn,C,"The element not exist"),e.domEvents.addEventListener(C,"click",(E,x)=>{const v=B("div",["media-element"],null),R=this.getResourceUrl(l),w=r(E,v,l,R);this.unbindMediaEvent(),this.media=w,this.bindMediaEvent(),this.updateMediaContent(v)}),this.setFullScreen(),c}renderRetry(e,r){var E,x;p(tn,this.abstract,"no abstract");const{editor:i}=this.options,{mediaIcon:o,mediaName:s}=this.abstract,l=B("div",["media-error","embed-selected-content","embed-hover-content"],null),c=B("span",["media-error-icon"],l);c.innerHTML=o;const d=B("div",[],l);let h=D.t("media.upload.failed",{name:s});(((E=r.response)==null?void 0:E.status)===420||((x=r.response)==null?void 0:x.status)===413)&&(h=D.t("media.upload.maxSizeFailed",{name:s})),d.innerHTML=h,l.appendChild(d);const C=d.querySelector(".retry-upload");C&&i.domEvents.addEventListener(C,"click",()=>{i.readonly||(p(tn,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(l),this.setFullScreen()}renderProgress(e,r){p(tn,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope .media-progress"),o=e===-1||e===100?100:e;if(i){const{updateProgressElement:s}=this.options;s(i,o)}else{const{createProgressElement:s}=this.options,l=J(this.mediaContainer);p(tn,l,"The element not exist"),z(l,"media-block-uploading");const c=B("div",["media-progress"],null);s(c,o,r),this.updateMediaContent(c)}this.setFullScreen()}renderMediaElement(e,r){p(tn,this.mediaContainer,"The media element not exist");const i=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:o,updateMediaElement:s,editor:l}=this.options,c=this.getResourceUrl(e,r);if(i){const d=s(l,i,e,c);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent()}else{const d=B("div",["media-element"],null),h=o(l,d,e,c);this.unbindMediaEvent(),this.media=h,this.bindMediaEvent(),this.updateMediaContent(d)}}renderEmpty(e){p(tn,this.abstract,"no abstract"),p(tn,this.mediaContainer,"The media element not exist");const r=B("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);r.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(r);const{editor:i}=this.options;i.findBlockById(e.id)&&this.emit("mediaError",i,"empty",e.id),this.setFullScreen()}getResourceUrl(e,r){const{src:i}=e.embedData,{editor:o}=this.options;return o.doc.buildResourceUrl(i,{syncNewResources:async(s,l)=>{var d,h;if(!r)return;await o.doc.addResources([s]);const c=(h=(d=o.doc).getServerMeta)==null?void 0:h.call(d).appId;if(l!==e.embedData.src&&c&&e.embedData.src.includes(c)){const C=J(r);if(C&&!o.readonly&&o.isBlockWritable(C)){const E=mt.default(e);E.embedData.src=s,o.updateBlockData(C,E)}}}})}setFullScreen(){p(tn,this.mediaContainer,"The media element not exist"),z(this.mediaContainer,"full-screen")}removeFullScreen(){p(tn,this.mediaContainer,"The media element not exist"),ot(this.mediaContainer,"full-screen")}updateBlockAlign(e,r){const i=J(r);p(tn,i,"The block element not exist");const{align:o}=e;e.embedType==="video"&&(i.hasAttribute("data-style-align")&&i.removeAttribute("data-style-align"),i.setAttribute("data-style-align",o))}render(e,r){const{src:i}=e.embedData;(!this.mediaContainer||!r.contains(this.mediaContainer))&&(this.mediaContainer=B("div",["media"],r)),this.updateBlockAlign(e,r),det(i)?i===Vf.Empty&&this.renderEmpty(e):this.renderMediaElement(e,r)}setAbstract(e){this.abstract=e}}I("media-embed");const met="left";class ZS{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var C;const{containerId:r,blockIndex:i}=e;let o;(C=e.data)!=null&&C.file&&(o=e.data.file);const s=uet(t,this.embedType);if(o=o!=null?o:await Ea(s,{}),!o)return null;const{mediaType:l}=this.getAbstract();try{fet(o,t,l)}catch{return null}const c={id:tt(),type:"embed",embedType:this.embedType,embedData:{src:Vf.Empty}};l==="video"&&(c.align=met);const d=t.insertBlock(r,i,c);return await this.getMedia(t,c.id).handleUploadFile(o),d})}getMedia(t,e){const r=t.addCustom(`media-${e}`,()=>new het({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return r.setAbstract({...this.getAbstract()}),r}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:r,order:i,group:o}=this.getAbstract();return{name:r,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:i,group:o,subText:kn(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,r){const{id:i}=r;this.getMedia(t,i).render(r,e)}handleUpdateBlock(t,e,r){const{id:i}=r,o=this.getMedia(t,i),s=Ot(e);return o.render(r,s),!0}handleDeleteBlock(t,e){const r=e.id,i=this.getMedia(t,r);i.removeAllListeners(),i.destroy()}convertTo(t,e,r,i){const o=e.embedData,s=t.doc.buildResourceUrl(o.src,{withToken:!0});return i==="html"?`<${o.type} src="${s}" />`:i==="markdown"?`![${o.src}](${s})`:s}}function tL(n,t){const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e),i=B("div",["uploading-progress-bar-value"],r);i.style.width=`${t}%`}function eL(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const get=I("media-audio");class pet extends ZS{constructor(){super(...arguments);m(this,"embedType",ni.AUDIO);m(this,"updateProgressElement",eL);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["audio-container","embed-hover-content","embed-selected-content"],r),l=B("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=o,setTimeout(()=>{this.getMedia(e,i.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:ay,mediaName:D.t(`media.${ni.AUDIO}.menuItem`),menuItem:D.t(`media.${ni.AUDIO}.menuItem`),order:800,mediaType:ni.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${ni.AUDIO}.abstract`)}`}}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .audio-container > audio");return p(get,s,"The media element not exist"),s.src!==o&&(s.src=o),s}createProgressElement(e,r){const i=B("audio",[],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,i.src="about:blank",tL(e,r)}}const Cet=new pet;I("video-resizer");function nL(n){return n&&ge(n)&&Ve(n)==="video"}const Eet=50;class $x{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&nL(e)&&this.disableBlockResize(e),t&&nL(t)&&this.editor.isBlockWritable(t))){const r=this.getVideoElement(t);if(!r)return;this.enableBlockResize(t,r)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const r=t.getBlock();if(!r)return;const i=r.getBoundingClientRect().width,o=Math.min(Math.max(e.width,Eet),i);this.currentResizableElement.style.width=`${o}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const r=this.editor.getBlockData(e),{width:i}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...r,width:i})});this.editor=t,Re.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,Re.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Ot(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${lt(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${lt(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const r=this.editor.addCustom(`${lt(t)}-resizer`,()=>new xf(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));r.enableResize(t,e),r.removeListener("resizing",this.handleResizing),r.removeListener("resized",this.handleResized),r.addListener("resizing",this.handleResizing),r.addListener("resized",this.handleResized),this.currentResizableElement=e}}const xet=I("video");class Aet extends ZS{constructor(){super(...arguments);m(this,"embedType",ni.VIDEO);m(this,"updateProgressElement",eL);m(this,"createMediaElement",(e,r,i,o)=>{const s=B("div",["video-container","embed-selected-content","drag-preview-element"],r),l=B("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=o,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new $x(e)),this.getMedia(e,i.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,i.id).removeFullScreen()}),i.width&&(l.style.width=`${i.width}px`),l});m(this,"createProgressElement",(e,r,i)=>{const o=B("video",["progress-video"],e);o.innerHTML="Your browser does not support the <code>audio</code> element.",o.controls=!0,tL(e,r),Ca(i).then(s=>{const l=e.querySelector(".progress-video");l&&hp(e)&&(l.src=s)})})}getAbstract(){return{mediaName:D.t(`media.${ni.VIDEO}.menuItem`),mediaIcon:cy,menuItem:D.t(`media.${ni.VIDEO}.menuItem`),order:700,mediaType:ni.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`${D.t(`media.${ni.VIDEO}.abstract`)}`}}handleMediaError(e,r,i){const o=e.addCustom("video-resizer",()=>new $x(e)),s=e.getBlockById(i);o.disableBlockResize(s)}updateMediaElement(e,r,i,o){const s=r.querySelector(":scope .video-container > video");p(xet,s,"The media element not exist"),s.src!==o&&(s.src=o),i.width?s.style.width=`${i.width}px`:s.style.width="";const l=e.getBlockById(i.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new $x(e)).updateResizer(l)}),s}}const bet=new Aet,rL=[RE,UE,OE,Jk],Hx=[GS,bZ,Stt,Ptt,Gtt,L$,net,bet,Cet,DW,BS,hQ],iL=[uR,kS,X4,gR];function vet(n,t,e){var i,o,s,l;_r.level=(i=e.logLevel)!=null?i:Ho.DEBUG;const r=Mu(n,t,{components:{blocks:[...rL,...((o=e==null?void 0:e.components)==null?void 0:o.blocks)||[]],embeds:[...Hx,...((s=e.components)==null?void 0:s.embeds)||[]],boxes:[...iL,...((l=e.components)==null?void 0:l.boxes)||[]],textRenders:[new aE],options:{...e.componentsOptions}}});return r.readonly=!0,r.addCustom("heading-collapse",()=>new wx(r)),r.addCustom("editor-tooltip",()=>new ff(r)),r.addListener("clickLink",(c,d,h)=>{var E;if((E=e==null?void 0:e.events)!=null&&E.onClickLink){e.events.onClickLink(c,d,h);return}const C=h.getAttribute("link");C&&(c.readonly||d.ctrlKey||d.metaKey)&&window.open(C,"_blank")}),r}class oL{constructor(t){this.createOptions=t,t.lang&&D.setLang(t.lang)}createHistoryEditor(t,e){return vet(t,e,this.createOptions)}}function sL(n,{root:t,childDoc:e,doc:r}){var h,C;e.uploadResource=r.uploadResource.bind(r),e.buildResourceUrl=r.buildResourceUrl.bind(r);const i=n.getComponentOptions("comment"),o={image:{defaultAlign:"left"},table:{locatingContainer:t,hideCellMenu:!0,hideToolbar:!0},...i==null?void 0:i.componentsOptions},s=[];n.editorBlocks.forEach(E=>{E.blockType==="text"||E.blockType==="embed"||s.push(E)});const l=[];n.editorEmbeds.forEach(E=>{l.push(E)});const c=[];n.editorBoxes.forEach(E=>{E.boxType==="text"||E.boxType==="br"||E.boxType==="image"||E.boxType==="anchor"||c.push(E)});const d=Mu(t,e,{shortcuts:[Gh],components:{blocks:s,commandProviders:[new T0],decorators:[new Q0],embeds:l,boxes:c,options:o}});if(d.input.addHandler(new Z0),d.input.addHandler(new ex(d)),d.input.addHandler(new lx(d)),d.input.addHandler(new BY(d)),d.input.addHandler(new rm),d.addCustom("image-paste-handler",()=>new tx(d)),ie.isMobile||d.addCustom("editor-tooltip",()=>new ff(d)),n.options.enableContextMenu!==!1&&d.addCustom("editor-context-menu",E=>new ux(E)),(h=n.options.componentsOptions)!=null&&h.mention){const E=n.options.componentsOptions.mention;d.addCustom("mention",()=>new yS(d,{...E}))}if((C=n.options.componentsOptions)!=null&&C.comment){const E=n.options.componentsOptions.comment;E.onCommentEditorClick&&d.addListener("click",E.onCommentEditorClick)}return d}function Bet(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),r=new Set;e.forEach(i=>{const o=J(i);o&&r.add(o)}),r.forEach(i=>{TY(n,i,t)})}class Tet{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const r=e.groupId;this.getComments().filter(o=>o.groupId===r).length===0&&Bet(this.editor,r)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(r=>r.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){return sL(this.editor,{root:t,childDoc:e,doc:this.doc})}allowEdit(t){return t.userId===this.doc.getUser().userId}}class yet{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 sC(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){return sL(this.editor,{root:t,childDoc:e,doc:this.localDoc})}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const ket={placeholder:{common:{title:"\u8BF7\u8F93\u5165\u6807\u9898",readonlyTitle:"\u8BF7\u8F93\u5165\u6807\u9898",content:"\u70B9\u51FB + \uFF0C\u6216\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6",contentInTable:"\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6"},local:{readonlyTitle:"\u672A\u547D\u540D"}},copyCutProperty:{copy:"\u590D\u5236",cut:"\u526A\u5207",unsafeEnvTips:"\u7531\u4E8E\u5F53\u524D http \u8BBF\u95EE\u73AF\u5883\u4E0B\u7684\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528\u5FEB\u6377\u952E({shortCut}) {operation}",limitedEnvTips:"\u7531\u4E8E\u6D4F\u89C8\u5668\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528 {shortCut} \u7C98\u8D34"}},Ret={placeholder:{common:{title:"Enter a title",readonlyTitle:"Enter a title",content:'Click "+", or enter "/" to insert components quickly',contentInTable:'Enter "/" to insert components quickly'},local:{readonlyTitle:"Untitled"}},copyCutProperty:{copy:"Copy",cut:"Cut",unsafeEnvTips:"Due to the limitations of the current http access environment, please use the shortcut ({shortCut}) {operation}",limitedEnvTips:"Press {shortCut} to paste due to browser restrictions"}},wet={placeholder:{common:{title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",readonlyTitle:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",content:"\u300C+\u300D\u3092\u30AF\u30EA\u30C3\u30AF\u3059\u308B\u304B\u3001\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059",contentInTable:"\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059"},local:{readonlyTitle:"\u7121\u984C"}},copyCutProperty:{copy:"\u8907\u88FD",cut:"\u5207\u308B",unsafeEnvTips:"HTTP\u74B0\u5883\u306E\u5236\u7D04\u306B\u3088\u308A\u3001{operation}\u3059\u308B\u306B\u306F\u3001\u30B7\u30E7\u30FC\u30C8\u30AB\u30C3\u30C8({shortCut}) \u3092\u3054\u4F7F\u7528\u304F\u3060\u3055\u3044",limitedEnvTips:"\u30D6\u30E9\u30A6\u30B6\u30FC\u306E\u5236\u9650\u306B\u3088\u308A\u3001\u300C{shortCut}\u300D\u3092\u4F7F\u7528\u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ABMAAAAAAAAAAAAAAAAARjgAAGN1c3RvbVhtbC9pdGVtMS54bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAABVOQAAY3VzdG9tWG1sL19yZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAOuAYExTAwAAjw4AABIAAAAAAAAAAAAAAAAAWzsAAHdvcmQvZm9udFRhYmxlLnhtbFBLBQYAAAAADwAPANQDAADePgAAAAA=",Iet=()=>Yg(Let),Det=I("image-to-docx");async function _et(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function lL(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};try{const e=await Ca(new File([t],"",{})),r=await _et(e);return r.width===void 0||r.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||r.width*n.height/r.height,height:n.height||r.height*n.width/r.width,buffer:t}:{width:r.width,height:r.height,buffer:t}}catch(e){Det.error(e);return}}function Met(n,t){let e=n.filter(s=>s!=null);const r=t-(e.length-1)*20,i=.87,o=e.reduce((s,l)=>s+l.width,0);return o>r&&(e=e.map(s=>({width:s.width*r/o,height:s.height*r/o,buffer:s.buffer}))),e.map(s=>({width:s.width*i,height:s.height*i,buffer:s.buffer}))}function Uet(n,t,e){if(!e||typeof e!="object")return;const r=e,i=n.filter(s=>s!=null),o=t-(i.length-1)*20;i.forEach((s,l)=>{if(i.length===1&&r.widthPercent){const d=r.widthPercent,h=s.width;s.width=o*(d/100),s.height*=s.width/h;return}const c=`${l}_flex`;if(r[c]){const d=r[c],h=s.width;s.width=o*d,s.height*=s.width/h}})}function aL(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let r;switch(e%3){case 0:r=Ct.LevelFormat.DECIMAL;break;case 1:r=Ct.LevelFormat.LOWER_LETTER;break;default:r=Ct.LevelFormat.LOWER_ROMAN;break}return{level:e,format:r,text:`%${e+1}. `,alignment:Ct.AlignmentType.START,start:t,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(e+1)),hanging:Ct.convertInchesToTwip(.2)}}}}})}function Oet(){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:Ct.LevelFormat.BULLET,text:t,alignment:Ct.AlignmentType.START,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(n+1)),hanging:Ct.convertInchesToTwip(.2)}}}}})}function Net(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Ct.LevelFormat.BULLET,text:"\u2611",alignment:Ct.AlignmentType.START,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(n+1)),hanging:Ct.convertInchesToTwip(.2)}}}}))}function Pet(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:Ct.LevelFormat.BULLET,text:"\u2610",alignment:Ct.AlignmentType.START,style:{paragraph:{indent:{left:Ct.convertInchesToTwip(.3*(n+1)),hanging:Ct.convertInchesToTwip(.2)}}}}))}var $f=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))($f||{});const Fet=[{levels:aL(),reference:"number-numbering-reference"},{levels:Oet(),reference:"number-bullet-reference"},{levels:Net(),reference:"checked-bullet-reference"},{levels:Pet(),reference:"unchecked-bullet-reference"}];function Ket(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 Vet(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 $et(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 Het=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function cL(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(Het);if(t){const e=s=>{let l=Number(s).toString(16);return l.length<2&&(l=`0${l}`),l},r=e(t[1]),i=e(t[2]),o=e(t[3]);return`${r}${i}${o}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function un(n,t){if(n&&n.attributes&&n.attributes[t])return n.attributes[t];if(n&&n.attributes&&n.attributes.box&&n.attributes.inputType&&t==="style-underline")return!0}function uL(n,t,e){for(let r=0;r<=e;++r){const i=`${t}${r}`;if(un(n,i))return i}}function km(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function jx(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function fL(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function jet(n){const t=un(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const r of e){const i=r.split(":");if(i.length!==2)continue;const o=i[0].trim().toLowerCase(),s=i[1].trim().toLowerCase();o==="font-size"&&km(n,"inline-style-font-size",s),o==="color"&&km(n,"inline-style-color",s),o==="background-color"&&km(n,"inline-style-background-color",s),o==="font-family"&&km(n,"inline-style-font-family",s)}}function zet(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function Get(n){const t=`${un(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function Wet(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 qet(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function Xet(n){return un(n,"inline-style-font-family")}function Yet(n){const t=un(n,"inline-style-background-color");return cL(t)}function Qet(n){const t=un(n,"inline-style-color");return cL(t)}function Jet(n){jet(n);const t=un(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!un(n,"style-code"),link:fL(un(n,"link")),size:Get(n),text:t?qet(n):Wet(n)||n.insert,bold:!!un(n,"style-bold"),underline:!!un(n,"style-underline"),italics:!!un(n,"style-italic"),strike:!!un(n,"style-strikethrough"),superScript:!!un(n,"style-super"),subScript:!!un(n,"style-sub"),math:un(n,"type")==="math"?un(n,"src"):void 0,mention:t,fontFamily:Xet(n),background:Yet(n),color:t?"338fe5":Ket(uL(n,"style-color-",6))||Qet(n),highlight:uL(n,"style-bg-color-",13)}}function Zet(){return[new Ct.Paragraph({border:{top:{color:"auto",style:Ct.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new Ct.Paragraph({spacing:{line:0}})]}function tnt(){return new Ct.Paragraph({children:[new Ct.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function ent(){return new Ct.Paragraph({children:[new Ct.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function nnt(n,t){return new Ct.Paragraph({children:[new Ct.ExternalHyperlink({children:[new Ct.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function dL(n){if(n.heading!=null)return`Heading${n.heading}`}function hL(n){if(n.alignment!=null){if(n.alignment==="center")return Ct.AlignmentType.CENTER;if(n.alignment==="right")return Ct.AlignmentType.RIGHT;if(n.alignment==="left")return Ct.AlignmentType.LEFT}}function rnt(n){if(n.indent)return{left:Ct.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:Ct.convertInchesToTwip(.3*n.padding)}}function int(n){return{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function ont(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function mL(n,t){let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const r=n.size||t,i=r!=null?Math.floor(r*1.5+.5):void 0;return new Ct.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:Ct.UnderlineType.SINGLE}:void 0,italics:n.italics||void 0,strike:n.strike||void 0,superScript:n.superScript||void 0,subScript:n.subScript||void 0,size:i,style:e,font:n.fontFamily?ont(n.fontFamily):void 0,shading:n.background?int(n.background):void 0,color:n.color,highlight:Vet(n.highlight)})}function snt(n,t){if(n.link)return new Ct.ExternalHyperlink({children:[mL(n,t)],link:n.link})}async function gL(n,t,e,r,i){const[o]=await i(n,t,e);if(o==null)return;const s=await lL({width:r||0,height:0,src:e},o);return new Ct.ImageRun({data:o,transformation:{width:(s==null?void 0:s.width)||100,height:(s==null?void 0:s.height)||20}})}function lnt(n){if(n.heading||n.heading)return n.heading}function ant(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function cnt(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function unt(n,t){var r;const e=[];if(n.text&&Array.isArray(n.text)){for(let i=0;i<n.text.length;i++){const o=n.text[i];if(((r=o.attributes)==null?void 0:r.box)===!0&&t){const s=await t(o);if(s){n.text.splice(i+1,0,...s);continue}}e.push(Jet(o))}return e}}function fnt(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 dnt(n,t){if(n.type==="embed"&&n.embedType&&jx(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(r=>{const i=t(r),o=n.embedData[`${i}_width`],s=n.embedData[`${i}_height`];return{src:r,width:o,height:s}})}function hnt(n){if(n.padding)return n.padding}function mnt(n){return!!(n.type==="embed"&&n.embedType&&jx(n.embedType)&&n.embedData&&n.embedData.src)}async function Rm(n,t,e){return{quoted:!!n.quoted,heading:lnt(n),alignment:ant(n),indent:cnt(n),padding:hnt(n),texts:await unt(n,e),list:fnt(n),images:dnt(n,t),border:mnt(n)}}async function gnt(n,t,e,r){const i=[];if(!n.children)return[];for(const o of n.children){const s=[];for(const l of t.blocks[o])s.push(await Rm(l,e,r));i.push(s)}return i}const pnt=I("to-docx");function Cnt(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 Ent(n,t,e,r){const i=!!n.hasColTitle,o=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let c=0;c<t;c++)for(let d=0;d<e;d++)(i&&d===0||o&&c===0||s&&c%2===1)&&(r[c][d].color=l)}function xnt(n){p(pnt,n.children,"no table children");const t=n.rows,e=n.cols,r=n.colsWidth;if(r)for(let s=0;s<r.length;s++)r[s]===0&&(r[s]=100);const i=Cnt(t,e);let o=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(i[s][l].originalWidth=r?r[l]:void 0,i[s][l].from!==void 0)continue;const c=n.children[o];o+=1,i[s][l].cellId=c,i[s][l].color=$et(n[`${c}_background`]),i[s][l].width=r?r[l]:100,i[s][l].align=n[`${c}_align`];const d=n[`${c}_rowSpan`]||1,h=n[`${c}_colSpan`]||1;if(i[s][l].rowSpan=d,i[s][l].colSpan=h,d>1||h>1){let C=0;for(let E=0;E<d;E++)for(let x=0;x<h;x++)E===0&&(C+=r?r[l+x]:80),!(E===0&&x===0)&&(i[s+E][l+x].from=[s,l]);i[s][l].width=C}}return Ent(n,t,e,i),i}async function Ant(n,t,e,r,i,o,s,l,c,d){async function h(E){if(l&&E.type!=="_exportVirtualBlock"){const x=await l(i,o,E);if(x){await r.addDoc(n,x,d);return}}if(E.type==="text"||E.textOnly===!0){const x=await Rm(E,s,c);await r.addTextBlock(x);return}if(E.type==="code"){const x=await gnt(E,e,s,c);await r.addCodeBlockObject(x);return}if(E.type==="list"&&E.textOnly!==!0){const x=await Rm(E,s,c);await r.addListBlockObject(n,x);return}if(E.type==="embed"&&E.embedType){const x=E,v=x.embedData,R=x.embedType;if(jx(R)){const w=await Rm(E,s,c);await r.addImagesBlockObject(E,w,d)}else E.embedType==="hr"?r.addSeparatorBlock():E.embedType==="video"?r.addVideoPlaceholder():E.embedType==="audio"?r.addAudioPlaceholder():E.embedType==="webpage"?r.addHyperlinkParagraph(fL(v.src),v.title):r.addOtherEmbedBlock(R,E.embedData);return}if(E.type==="table"){let x=[];if(E.colsWidth)x=E.colsWidth;else{const R=E.cols;x=new Array(R);for(let w=0;w<x.length;w++)x[w]=100;E.colsWidth=x}const v=xnt(E);await r.addTableMatrix(x,v,e),r.addEmptyParagraph()}E.type==="_exportVirtualBlock"&&await r.addVirtualBlock(E.id,e,d)}function C(E){var R;const x=((R=E==null?void 0:E.embedData)==null?void 0:R.exportSpec)||(E==null?void 0:E.exportSpec);if(!x)return[E];const v=[];for(const{type:w,data:U}of x){if(w==="text"){const M={id:tt(),text:[{insert:U}],type:"text"};v.push(M);continue}if(w==="image"){const M={id:tt(),type:"embed",embedType:"image",align:"left",embedData:{src:U}};v.push(M);continue}if(w==="link"){const M={id:tt(),type:"embed",embedType:"webpage",embedData:{src:U.url,title:U.title}};v.push(M);continue}if(w==="block")for(const M of U){if(!e.blocks[M])continue;const G={id:M,type:"_exportVirtualBlock"};v.push(G)}}return v}for(const E of t)for(const x of C(E))!x||await h(x)}function bnt(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const vnt=I("to-docx");class Bnt{constructor(t,e,r,i,o,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=r,this.readImageFunc=i,this.convertBlocksFunc=o,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new Ct.Paragraph({heading:dL(t),alignment:hL(t),children:await this.paragraphsFromBlockTexts(t),indent:rnt(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new Ct.Paragraph({text:`[${D.t("docx.imageExportFailed")}]`,shading:{type:Ct.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=zet(this.defaultFontSize,t.heading),r=[];for(const i of t.texts){if(i.link){const o=snt(i,e);o&&r.push(o);continue}if(i.box&&i.box.type&&i.box.type==="br"){r.push(new Ct.TextRun({text:"",break:1}));continue}if(i.box&&i.box.type&&i.box.type==="image"){const o=await gL(this.appId,this.docId,i.box.src,i.box.width,this.readImageFunc);o&&r.push(o);continue}if(i.math){const o=await gL(this.appId,this.docId,i.math,0,this.readImageFunc);o&&r.push(o);continue}r.push(mL(i,e))}return r}async addCodeBlockObject(t){for(const e of t)for(const r of e){const i={style:Ct.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new Ct.Paragraph({style:"Code",border:{left:{...i},right:{...i},top:{...i},bottom:{...i}},children:await this.paragraphsFromBlockTexts(r)}))}}async addListBlockObject(t,e){if(e.list==null)return;let r;const i=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[i])r=this.state.listInstMap[i];else if(r=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[i]=r,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${r}`,l=aL([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:r}),this.state.listRefMap[i]=s}else e.list.ordered?this.state.listRefMap[i]=$f.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[i]=$f.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[i]=$f.UNCHECKED:this.state.listRefMap[i]=$f.BULLET;const o=dL(e);e.texts&&this.paragraphs.push(new Ct.Paragraph({heading:o,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[i],level:e.list.level-1,instance:r}}))}imageDimWithBufferToImageRun(t){return new Ct.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,r){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:c}=t.embedData;c||this.addEmptyImagePlaceHolder()}return}const i=[],o=await Promise.all(e.images.map(async c=>{const[d,h]=await this.readImageFunc(this.appId,this.docId,c.src);if(d){const C=await lL(c,d);if(C)return C}i.push(h)}));Uet(o,r,t.embedData);const s=Met(o,r),l={style:Ct.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new Ct.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:hL(e)||Ct.AlignmentType.CENTER,children:s.map(c=>this.imageDimWithBufferToImageRun(c)).flatMap((c,d,h)=>c==null?[]:h.length-1!==d?[c,new Ct.TextRun({text:" "})]:c)})),i.forEach(c=>{this.addHyperlinkParagraph(c)})}addSeparatorBlock(){Zet().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new Ct.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(tnt())}addAudioPlaceholder(){this.paragraphs.push(ent())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(nnt(t,e))}async addTableMatrix(t,e,r){const i=t.map(o=>o!==0?o*15:1500);this.paragraphs.push(new Ct.Table({rows:await this.generateTableRows(e,r),columnWidths:i}))}async generateRowCells(t,e){const r=[];for(const i of t){const o=i.cellId;if(o===void 0)continue;const s=i.width*.9;r.push(new Ct.TableCell({children:await this.convertBlocksFunc(o,e.blocks[o],e,this.appId,this.docId,this.state,s),columnSpan:i.colSpan,rowSpan:i.rowSpan,width:{type:Ct.WidthType.DXA,size:i.width*15},shading:i.color?{fill:i.color,type:Ct.ShadingType.CLEAR,color:"auto"}:void 0}))}return r}async generateTableRows(t,e){const r=[];for(const i of t)r.push(new Ct.TableRow({children:await this.generateRowCells(i,e)}));return r}async addDoc(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,r);i&&(this.paragraphs=this.paragraphs.concat(i))}async addVirtualBlock(t,e,r){const i=await this.convertBlocksFunc(t,e.blocks[t],e,this.appId,this.docId,this.state,r);this.paragraphs.push(...i)}async addOtherEmbedBlock(){}}class Tnt{constructor(t,e,r,i,o,s,l,c){m(this,"convertBlocks",async(t,e,r,i,o,s,l=720)=>{const c=new Bnt(i,o,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await Ant(t,e,r,c,i,o,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),c.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=r,this.readImage=i,this.defaultFontSize=o,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=c}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,r){const i=new Ct.ImportDotx,o=this.templateData?await i.extract(this.templateData):void 0,s=t.blocks.root;p(vnt,s,"data must have blocks");const l=bnt(),c=await this.convertBlocks("blocks",s,t,e,r,l),d=this.backgroundImageOptions?{default:new Ct.Header({children:[new Ct.Paragraph({children:[new Ct.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new Ct.Document({numbering:{config:[...Fet,...l.levelConfigs]},sections:[{headers:d,children:c,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:o});return Ct.Packer.toBlob(h)}}async function ynt(n,t,e,r){const i=n.doc.buildResourceUrl(r,{withToken:!0});let o=await _S(i);if(!o)return[void 0,i];if(o.type.indexOf("/svg")!==-1){const l=await LS(o);l&&(o=new File([l],o.name))}return[await o.arrayBuffer(),i]}async function knt(n,t,e){const r=n.editorBlocks.getBlockClass(e.type);if(r.toStandardDoc)return r.toStandardDoc(n,e,t)}async function Rnt(n,t){const e=t.attributes,r=n.editorBoxes.getBoxClass(e.type);if(r.toStandardText)return r.toStandardText(n,e)}async function wnt(n,t){let{template:e,download:r,backgroundImageOptions:i}=t!=null?t:{};e||(e=Iet());const o=n.doc.toJSON(),s=(C,E,x)=>ynt(n,C,E,x),l=async(C,E,x)=>knt(n,o,x),c=async C=>Rnt(n,C),h=await new Tnt(e,o,Fd.default,s,void 0,l,c,i).convert("_appId","_docId");if(r){const C=URL.createObjectURL(h),E=document.createElement("a");E.setAttribute("download",`${DS(n)}.docx`),E.setAttribute("href",`${C}`),E.click(),E.remove()}return h}const zx=I("create-editor");async function Snt(n,t){var s,l,c,d,h,C,E,x,v,R,w,U,M,F;p(zx,n,"app does not exists"),t.lang&&D.setLang(t.lang),_r.level=(s=t.logLevel)!=null?s:Ho.DEBUG;const e=t.onReauth?async()=>{var st;const G=t.user.userId,q=t.docId,it=await((st=t.onReauth)==null?void 0:st.call(t,G,q,t.permission));return{userId:G,docId:q,permission:t.permission,appId:t.appId,token:it,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,r={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout},i=await qu.load(r),o=Mu(n,i,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,enableContextMenu:t==null?void 0:t.enableContextMenu,components:{blocks:[...rL,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...Hx,...((c=t.components)==null?void 0:c.embeds)||[]],boxes:[...iL,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new T0,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new Q0,new aC],insertions:[l1],blockHooks:[new XE,new Tw,...((C=t.components)==null?void 0:C.blockHooks)||[]],textRenders:[new V4,new aE],options:{...t.componentsOptions}},shortcuts:[UY,uz,vW,wE,h4,pV,vE,xQ,Gh,cV,...t.shortcuts||[]],colors:["#0064FF","#EB3723","#F59300","#00A865","#F25A0A","#70A310","#009CAD","#0990D9","#8851ED","#D62069"]});if(o.editorCommandProviders.registerCommandProvider(new Di(o)),o.input.addHandler(new aJ),o.input.addHandler(new Z0),o.input.addHandler(new U$),o.input.addHandler(new mW),o.input.addHandler(new NE(o,{hideTitle:t.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),o.input.addHandler(new j0(o,(E=t.componentsOptions)==null?void 0:E.quickMenu)),o.input.addHandler(new ex(o)),o.input.addHandler(new lx(o)),o.input.addHandler(new rm),o.doc.registerCallback(new cJ(o)),o.addCustom("remote-cursor",()=>new IT(o)),o.addCustom("block-menu",G=>new Rw(G)),ie.isMobile||o.addCustom("editor-tooltip",()=>new ff(o)),t!=null&&t.enableComments&&o.addCustom("editor-comments",G=>new K4(G,new Tet(G))),t.enableContextMenu!==!1&&o.addCustom("editor-context-menu",G=>new ux(G)),o.addCustom("create-options",()=>new Wb(o,t)),o.addCustom("drop-target",()=>new Sf(o)),o.addCustom("list-to-mindmap",()=>new N0(o)),o.addCustom("list-to-mention",()=>new LJ(o)),o.addCustom("mobile-helper",()=>new ZJ(o)),o.addCustom("code-caret",()=>new sz(o)),o.addCustom("image-paste-handler",()=>new tx(o)),(x=t.componentsOptions)!=null&&x.mention){const G=t.componentsOptions.mention;o.addCustom("mention",()=>new yS(o,G))}if(o.addCustom("heading-collapse",()=>new wx(o)),o.addCustom(Tm,G=>new Mx(G)),ic.register(o),Sf.register(o),ys.register(o),xs.register(o),o.addListener("clickLink",(G,q,it)=>{var Et;if((Et=t==null?void 0:t.events)!=null&&Et.onClickLink){t.events.onClickLink(G,q,it);return}const st=it.getAttribute("link");st&&(G.readonly||q.ctrlKey||q.metaKey)&&window.open(st,"_blank")}),(R=(v=t.componentsOptions)==null?void 0:v.remoteCarets)!=null&&R.onUserChanged){const G=(U=(w=t.componentsOptions)==null?void 0:w.remoteCarets)==null?void 0:U.onUserChanged;o.doc.getRemoteUsers().on("change",q=>{G(o,q)})}return(F=(M=t.componentsOptions)==null?void 0:M.templates)!=null&&F.templates.length&&(o.addListener("docChanged",()=>{Bm(o)}),o.addListener("resize",()=>{Bm(o,{reset:!0})}),setTimeout(()=>{Bm(o)},100)),o.doc.registerCallback({onError:async G=>{if(G.code==="ResetDoc"){zx.error(`reset doc: ${G.message}`);const q=await qu.load(r);o.doc.reset(q)}}}),o.version="1.1.17-beta.5",_r.level===Ho.DEBUG&&(window.setReauthFail=G=>{window.isReauthError=G},window.reConnect=G=>o.doc.externalDoc.client.connection.reConnect(G)),o}function Lnt(n){return n.toJSON!==void 0}async function Int(n,t,e){var o,s,l,c,d,h,C,E;p(zx,n,"app does not exists");const r=Lnt(t)?t:new K1(t,{serverUrl:e.serverUrl||""});e.lang&&D.setLang(e.lang),_r.level=(o=e.logLevel)!=null?o:Ho.DEBUG;const i=Mu(n,r,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[RE,UE,OE,Jk,...(l=(s=e.components)==null?void 0:s.blocks)!=null?l:[]],commandProviders:[new T0],decorators:[new Q0,new aC],embeds:[...Hx,...((c=e.components)==null?void 0:c.embeds)||[]],boxes:[uR,kS,X4,gR,...((d=e.components)==null?void 0:d.boxes)||[]],insertions:[l1],blockHooks:[new XE,...((h=e.components)==null?void 0:h.blockHooks)||[]],textRenders:[new V4,new aE,...((C=e.components)==null?void 0:C.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[wE,h4,vE,Gh]});return i.editorCommandProviders.registerCommandProvider(new Di(i)),i.input.addHandler(new Z0),i.input.addHandler(new NE(i,{hideTitle:e.hideTitle,headingLevel:1,titlePlaceholder:D.t("placeholder.common.title"),contentPlaceholder:D.t("placeholder.common.content"),readonlyTitlePlaceholder:D.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new j0(i,(E=e.componentsOptions)==null?void 0:E.quickMenu)),i.input.addHandler(new ex(i)),i.input.addHandler(new lx(i)),i.input.addHandler(new rm),i.addCustom("block-menu",x=>new Rw(x)),ie.isMobile||i.addCustom("editor-tooltip",()=>new ff(i)),i.addCustom("image-paste-handler",()=>new tx(i)),e!=null&&e.enableComments&&i.addCustom("editor-comments",x=>new K4(x,new yet(x,r))),e.enableContextMenu!==!1&&i.addCustom("editor-context-menu",x=>new ux(x)),i.addCustom("heading-collapse",()=>new wx(i)),i.addListener("clickLink",(x,v,R)=>{var U;if((U=e==null?void 0:e.events)!=null&&U.onClickLink){e.events.onClickLink(x,v,R);return}const w=R.getAttribute("link");w&&(x.readonly||v.ctrlKey||v.metaKey)&&window.open(w,"_blank")}),i.addCustom(Tm,x=>new Mx(x)),ic.register(i),i.version="1.1.17-beta.5",i}async function Dnt(n,t,e){var h;const r=n.doc.externalDoc.client.auth,i=await r0.load({auth:r,serverUrl:e});if(!((h=i.getVersionHelper)==null?void 0:h.call(i)))throw new Error("the editor does not support to show versions");const s=n.getCustom("create-options");if(!s)throw new Error("the editor does not support to show versions");const l=s.getData(),c=new oL(l),d=n.addCustom("version-dialog",()=>new fS(i,c));return d.show(t),d}b.tippy=y9,b.AnchorBox=YB,b.AuthError=Gu,b.AuthHeader=dl,b.AutoScroll=nh,b.BaseURLHeader=Ka,b.BasicCommands=r$,b.BlockExclusiveHook=Tw,b.BlockLockerHook=XE,b.BlockLockerPasteHandler=rm,b.BlockResizer=xf,b.BrBox=GB,b.CodeBlock=UE,b.CodeLineBlock=OE,b.CodeTextDecorator=Q0,b.DOC_RE_AUTH_KEYS=Tm,b.DefaultShortcuts=Gh,b.DocIdError=JN,b.DocReAuthCallbacks=Mx,b.DragDrop=fv,b.DrawioEmbed=GS,b.EditorBlocks=b3,b.EditorBoxes=qB,b.EditorCommandProviders=z2,b.EditorComplexBlockPosition=Kr,b.EditorComplexSelectionRange=pi,b.EditorDecorators=t5,b.EditorEmbeds=B3,b.EditorInsertions=ZB,b.EditorSimpleBlockPosition=Xe,b.EditorSimpleSelectionRange=nn,b.EmbedBlock=y3,b.EmbedBlockResizer=Nf,b.EnforceWithDocumentTitleHandler=NE,b.EventCallbacks=ma,b.FILL_CHAR=vM,b.FileExtError=ZN,b.GroupOrder=nR,b.HeadingBlockScrollListener=BJ,b.ImageBox=XB,b.InlineBoxCommandProvider=pR,b.InputtingInsertion=QB,b.LocalDoc=K1,b.LogLevel=Ho,b.Logger=_r,b.MIN_DISTANCE_THRESHOLD=cv,b.ManualCloseDialog=Yu,b.ManualMenu=as,b.ManualToolbar=Xu,b.MarkdownInputHandler=Z0,b.MaxUserError=Z1,b.Mindmap=O0,b.OnesEditorAutoSuggest=SC,b.OnesEditorCustomDataWrapper=Wb,b.OnesEditorExclusiveBlock=xs,b.OnesEditorHoveringBlock=Re,b.OnesEditorIcons=PP,b.OnesEditorQuickMenu=j0,b.OnesEditorToc=Kf,b.OnesEditorTocProvider=ys,b.OnesEditorToolbar=ic,b.OnesEditorTooltip=ff,b.OnesEditorVersionsDialog=fS,b.PermissionError=n0,b.Popup=ja,b.ReAuthToolbar=MS,b.RemoteCarets=IT,b.RemoteCaretsDecorator=aC,b.RemoteCaretsInsertion=l1,b.RemoteUsers=Uu,b.RequestReloadError=Wu,b.RichText=pn,b.ShareDBDoc=qu,b.ShareDBDocVersionsProvider=oL,b.ShareDBServer=r0,b.SimpleCache=ev,b.StandardEmbedBlockCommands=Ax,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=Kp,b.TEXT_STYLE_COLOR_PREFIX=Fp,b.TableBlock=RE,b.TableBlockCommandProvider=T0,b.TableShortcuts=wE,b.TextBlock=Nn,b.TextBox=zB,b.TextColorItem=Xy,b.TextStyleShortcuts=vE,b.TocEmbed=BS,b.ZERO_WIDTH_SPACE_CHAR=Zc,b.abbreviation=rh,b.addAttribute=Ch,b.addClass=z,b.addCommentToBlock=Of,b.addDays=MI,b.addMetaToDoc=Du,b.addMonths=_I,b.animateScrollTo=Ws,b.applyPlaceholderToBlock=Cf,b.assert=p,b.autoShowHideTemplates=Bm,b.bindKeyDownEvent=qd,b.blockToDoc=M1,b.blockToHtml=u1,b.blockToMarkdown=_h,b.blockToText=Dh,b.blocksToDoc=m2,b.clearAllSelection=e3,b.clientType=ie,b.cloneBlock=es,b.cloneChildContainer=A1,b.cloneDoc=b1,b.cloneText=OB,b.commentToShareDbComment=lC,b.compareElement=Gd,b.comparePosition=vp,b.complexBlockAdjustSelectionPos=ch,b.complexBlockFindNearestChildBlock=D7,b.complexBlockGetAllChildContainers=ln,b.complexBlockGetBottomChildContainers=S3,b.complexBlockGetDeepFirstChild=k3,b.complexBlockGetFirstSimpleChild=Tp,b.complexBlockGetLastSimpleChild=va,b.complexBlockGetSelectedContainers=ba,b.complexBlockGetTopChildContainers=w3,b.containerToDoc=g2,b.continuousScroll=Rv,b.convertBlockFrom=lh,b.convertImageFileToPng=LS,b.convertImageSrcToPng=WJ,b.converterIntercept=J0,b.copyBlockAttributes=d5,b.copyResourcesFromDoc=F1,b.createBlockAnchor=Zi,b.createBlockCaretAnchor=I3,b.createBlockContentElement=tl,b.createBlockElement=Gv,b.createBlockSimpleDocRange=Rh,b.createBlockSimpleRange=be,b.createBoxContentElement=Xv,b.createBoxElement=Wv,b.createBoxOp=UB,b.createChildContainer=x3,b.createComplexBlockPosition=Ee,b.createComplexDocPos=VB,b.createComplexDocRange=yM,b.createContainer=PB,b.createContainerElement=sp,b.createDeleteOps=IB,b.createEditor=Mu,b.createEditorSelectionRange=Ye,b.createElement=B,b.createEmptyContainer=oo,b.createEmptyDoc=io,b.createEmptyTextBlockData=yh,b.createExpandedRange=jd,b.createIconButton=js,b.createImage=Kg,b.createInsertOps=Bh,b.createInsertionContentElement=Jv,b.createInsertionElement=Yv,b.createLocalEditor=Int,b.createOnesEditor=Snt,b.createRange=nv,b.createRichText=al,b.createRootContainer=E3,b.createSimpleBlockPosition=at,b.createSimpleDocPos=KB,b.createTextBlockData=Ai,b.createTextButton=bl,b.createTextOp=Er,b.createTextWithReplaceSoftReturn=Jp,b.daysAfter=ep,b.deleteText=t1,b.diffDays=UI,b.disablePageScroll=Jg,b.docToHtml=l5,b.docToHtmlFragment=yu,b.docToMarkdown=a5,b.docToText=ts,b.downloadImageToFile=_S,b.downloadObjectToFile=Nx,b.downloadSvgToString=NS,b.editLink=af,b.editorAddComment=kY,b.editorAddTextAttribute=B5,b.editorAutoInsertBlock=h5,b.editorBreakTextBlock=Da,b.editorClearCompositionText=m1,b.editorClearSelectedContents=Ph,b.editorCopyBlock=N1,b.editorCopyDoc=zh,b.editorDeleteBlock=C1,b.editorDeleteBlockText=g1,b.editorDeleteBlockWithoutChildren=Oh,b.editorDeleteChildContainer=BU,b.editorDeleteChildContainers=m5,b.editorFocusToBlock=x1,b.editorFocusToEnd=$U,b.editorGetBlockData=Zo,b.editorGetBlockText=yn,b.editorGetBlockTextEx=Sh,b.editorGetBoxData=HB,b.editorHandleKeyboardEvent=R2,b.editorInsertBlock=Ia,b.editorInsertBoxToBlock=u5,b.editorInsertDoc=b5,b.editorInsertDocAt=v1,b.editorInsertText=h1,b.editorInsertTextToBlock=c5,b.editorInsertTextToBlockEx=d1,b.editorMergeTextBlock=g5,b.editorMoveDown=O5,b.editorMoveEnd=S1,b.editorMoveHome=G5,b.editorMoveLeft=_5,b.editorMoveLineEnd=t2,b.editorMoveLineHome=Z5,b.editorMovePageDown=s2,b.editorMovePageUp=o2,b.editorMoveRight=M5,b.editorMoveUp=U5,b.editorMoveWordEnd=H5,b.editorMoveWordLeft=$5,b.editorRangeClearColor=y5,b.editorRangeGetColor=k5,b.editorRangeSetColor=T5,b.editorRemoveTextAttribute=RU,b.editorReplaceBlockText=Fh,b.editorReplaceContainer=v5,b.editorRunOnce=V1,b.editorSelectAll=I1,b.editorSelectContainer=$h,b.editorSelectDown=N5,b.editorSelectEnd=L1,b.editorSelectHome=W5,b.editorSelectLeft=P5,b.editorSelectLineEnd=J5,b.editorSelectLineHome=Q5,b.editorSelectPageDown=c2,b.editorSelectPageUp=a2,b.editorSelectRight=F5,b.editorSelectUp=K5,b.editorSelectWordEnd=z5,b.editorSelectWordLeft=j5,b.editorSetTextColor=_a,b.editorShowFindDialog=EX,b.editorToDocx=wnt,b.editorUpdateBlockData=Kh,b.editorUpdateCompositionText=f5,b.editorUpdateEmbedData=x5,b.enablePageScroll=Zg,b.escapeHtmlText=Xd,b.escapeRegExp=op,b.escapeSpace=pI,b.exclusiveBlock=GE,b.executeBlockCommand=u3,b.executeEmbedBlockCommand=c3,b.executeRangeCommand=j2,b.fileToDataUrl=Ca,b.findAfterOffsetNotType=i1,b.findAllText=D1,b.findBlockByIndex=Pv,b.findEventTargetBlock=ov,b.findInsertionById=Qv,b.findNextOffset=zM,b.findNextVisibleSimpleBlock=X2,b.findPrevOffset=jM,b.findPrevOffsetNotType=r1,b.findPrevSimpleBlockBeforeChildContainer=R3,b.findPrevVisibleSimpleBlock=q2,b.findTarget=pa,b.findWordEnd=s1,b.findWordLeft=o1,b.format=ou,b.formatBytes=wv,b.formatDate=rp,b.fragmentToHtml=vv,b.fromBase64=eu,b.fromBase64ToBlob=Yg,b.fromBase64ToUint8Array=RI,b.fromDocRange=Xo,b.fromNowString=ip,b.genId=tt,b.getAllChildBlocks=wp,b.getAllQuickMenuItems=bE,b.getAllSelectedBlocks=Ci,b.getAttributesAt=ka,b.getBlockBackground=cp,b.getBlockByIndex=zo,b.getBlockCaretRect=Wo,b.getBlockClass=Qt,b.getBlockClassByType=Qs,b.getBlockClientRects=Yi,b.getBlockCommandsWithHook=pp,b.getBlockContent=Ot,b.getBlockHeading=uu,b.getBlockId=lt,b.getBlockIndex=vt,b.getBlockInfo=Tf,b.getBlockKind=Nr,b.getBlockMinWidth=r3,b.getBlockNearestRangeFromPoint=kp,b.getBlockOptions=qI,b.getBlockPath=qo,b.getBlockProperties=s3,b.getBlockRangeFromPoint=uh,b.getBlockStyles=WI,b.getBlockTextLength=dt,b.getBlockTools=oe,b.getBlockType=It,b.getBoxContent=fp,b.getBoxId=qv,b.getBoxTypeFromElement=cu,b.getChildBlockCount=Or,b.getChildBlocks=fe,b.getChildOffset=Qo,b.getColorFromAttributes=$p,b.getColorFromContent=ih,b.getComplexBlockClass=hr,b.getContainerBlockPath=g3,b.getContainerBlocks=t3,b.getContainerBlocksElement=lu,b.getContainerById=Ur,b.getContainerId=ct,b.getContainerMinWidth=Ap,b.getContainerToolsElement=jI,b.getContainerWidth=A3,b.getDistanceSquare=jo,b.getElementFromPoint=xe,b.getElementOffset=Jc,b.getElementScale=dr,b.getEmbedType=Ve,b.getExistsBlockTools=oh,b.getExistsContainerById=su,b.getFileExt=iu,b.getFirstChildBlock=Ae,b.getFirstClientRect=zd,b.getHeadingBlockChildren=Aa,b.getHeadingMenuOptions=gE,b.getHorizontalPadding=$g,b.getInsertionContent=dp,b.getLastChildBlock=Ue,b.getLastClientRect=zs,b.getListAllNextBrothers=Za,b.getLogger=I,b.getNextBlock=Jt,b.getNextHiddenBlocks=h3,b.getNextValidOffset=sl,b.getNextVisibleBlock=gr,b.getOffsetFromPoint=Vg,b.getOffsetInfoAfter=vu,b.getOffsetInfoBefore=Lh,b.getOpAt=fB,b.getOpLength=ph,b.getParentBlock=J,b.getParentBlockExcludeSelf=Zs,b.getParentBox=up,b.getParentContainer=rt,b.getPrevBlock=Oe,b.getPrevValidOffset=Jo,b.getPrevVisibleBlock=mr,b.getRangeCommands=$2,b.getReferenceClientRect=wk,b.getRootBlock=gp,b.getScrollContainer=qe,b.getSpecialBlockCommands=l3,b.getStandardEmbedBlockProperties=bx,b.getTextAfterOffset=$M,b.getTextAttributes=f1,b.getTextBeforeOffset=HM,b.getTextBlockChild=hu,b.getTextBlockClass=Kv,b.getTextBlockContentChildTextLength=Cr,b.getTextBlockContentChildType=m3,b.getTextBlockContentChildren=gi,b.getTextLength=gn,b.getTextOpLength=Pp,b.getTextWidth=Zd,b.getToolbar=L0,b.handleBlockElementUpdated=i3,b.hasAltOnly=vI,b.hasClass=Rt,b.hasCtrlOrCmd=Cv,b.hasCtrlOrCmdOnly=bI,b.hashCode=Uv,b.hideBlock=zv,b.htmlToFragment=Jd,b.i18n=D,b.includeBigTable=mF,b.injectDocToHtmlFragment=Iu,b.injectStyle=av,b.inputActions=aO,b.insertEmptyBlock=QI,b.insertEmptyEmbedBlock=Cp,b.insertText=ro,b.intersectionCommands=VO,b.isBackspace=xv,b.isBlock=Js,b.isBlockLocked=nm,b.isBlockLockedByOthers=qE,b.isBlockLockedBySelf=yf,b.isBlockTools=jv,b.isBox=sh,b.isBoxOp=to,b.isCJK=gv,b.isChildContainer=Fr,b.isChildNode=re,b.isCodeBlock=Zr,b.isCollapsedHeadingBlock=mi,b.isCollapsedRange=TM,b.isComplexBlockPosition=nl,b.isComplexKindBlock=Lt,b.isContainer=Xi,b.isContainerSelectedAllChildBlocks=u2,b.isControlEvent=Xs,b.isDelete=TI,b.isDraggingFiles=th,b.isElementVisible=zg,b.isEmbedBlock=ge,b.isEmptyContainer=mu,b.isEmptyDoc=e1,b.isEmptyTextBlock=se,b.isEmptyTextBlockWithoutCompositionText=pf,b.isEnterOnly=Ev,b.isEscape=Qd,b.isExclusiveBlock=Bf,b.isExpandedHeadingBlock=d3,b.isFirefox=Yc,b.isFirstChildBlockInComplexBlock=I7,b.isHeadingBlock=sn,b.isHighSurrogate=dI,b.isInBlock=hp,b.isInBlockTools=xa,b.isLetter=mv,b.isLowSurrogate=hI,b.isMatchShortcut=di,b.isMoveForward=xI,b.isNavigationEvent=EI,b.isNavigationKey=pv,b.isNodeRemoved=Qc,b.isNumber=hv,b.isPrintableKey=qg,b.isRootBlock=pr,b.isRootContainer=qt,b.isSafari=Hs,b.isSameDay=np,b.isSelectBoxOnly=Jr,b.isShiftEnter=BI,b.isShiftTab=kI,b.isShortcutEvent=AI,b.isSimpleBlock=GI,b.isSimpleBlockPosition=Vr,b.isSimplePos=FB,b.isSimpleRange=kh,b.isSpace=Yd,b.isTab=yI,b.isTextBlockContentBoxChild=Qn,b.isTextBlockContentChild=fu,b.isTextBlockContentInsertionChild=Ji,b.isTextBlockContentTextChild=du,b.isTextKindBlock=nt,b.isTextKindBlockType=au,b.isTitleBlock=qi,b.isToday=Sv,b.isValidOffset=On,b.isVisibleBlock=Go,b.isYesterday=Lv,b.loadJs=iv,b.loadJsPromise=Gs,b.lockers=Mr,b.mergeCommands=S0,b.mergeDocs=cl,b.mergeOps=Zp,b.mergeText=AM,b.multiSplitText=hB,b.overflowText=Iv,b.parseShortcut=Av,b.patchNode=nu,b.pointInRect=qs,b.rangeAddAttribute=xu,b.rangeGetTextColor=AB,b.rangeRemoveAttribute=ya,b.rangeSetTextColor=CB,b.rangeTransformText=gB,b.registerDragDrop=Gg,b.removeAttribute=Vp,b.removeClass=ot,b.removeLastBr=pM,b.removePlaceholderFromBlock=YR,b.removeStyle=lv,b.replaceAll=OI,b.replaceAllCaseInsensitive=NI,b.replaceAllText=d2,b.replaceText=Th,b.requestDownload=eh,b.resetListStart=ec,b.scrollIntoView=Tu,b.scrollable=kv,b.selectFile=Ea,b.selectedBlockToDoc=Hh,b.selectionToDoc=Ma,b.setAttributes=Wd,b.setClipboardData=ru,b.setClipboardDataByEvent=LI,b.setColorToAttributes=EB,b.setDataset=Hg,b.setDefaultCursor=tu,b.setStyles=jg,b.shareDBCommentToDocObject=sC,b.shareDBDocCommentToComment=ST,b.shortcutToDisplayText=We,b.showBlock=ap,b.showDocVersions=Dnt,b.splitText=Mn,b.splitToThree=Qe,b.stringToDataUrl=Qg,b.stringToObjectUrl=tp,b.subText=mB,b.textNodeOffsetFromPoint=rv,b.titleFromEditor=DS,b.toBase64URL=hi,b.toMindmap=U0,b.toPlainText=de,b.toPlainTextKeepLength=n1,b.trimChar=Wg,b.unexclusiveBlock=WE,b.unicodeLength=mI,b.unicodeSubstr=gI,b.updateBlockSelection=n3,b.updateOpAttributes=NB,b.updateTextBlockContent=VM,b.updateUrl=Xg;for(const n in ye)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>ye[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});